diff --git a/Content.Client/Lathe/LatheSystem.cs b/Content.Client/Lathe/LatheSystem.cs index 71e43a4c2e6..26587b1af24 100644 --- a/Content.Client/Lathe/LatheSystem.cs +++ b/Content.Client/Lathe/LatheSystem.cs @@ -3,6 +3,8 @@ using Content.Shared.Power; using Content.Client.Power; using Content.Shared.Research.Prototypes; +using Content.Client._Ganimed.Systems; // Ganimed edit +using Content.Shared._Ganimed.Components; // Ganimed edit namespace Content.Client.Lathe; @@ -10,6 +12,7 @@ public sealed class LatheSystem : SharedLatheSystem { [Dependency] private readonly SharedAppearanceSystem _appearance = default!; [Dependency] private readonly SpriteSystem _sprite = default!; + [Dependency] private readonly LatheAlertLevelRestrictionSystem _alertLevelRestriction = default!; // Ganimed edit public override void Initialize() { @@ -57,6 +60,19 @@ protected override bool HasRecipe(EntityUid uid, LatheRecipePrototype recipe, La { return true; } + + // Ganimed edit start + public override bool CanProduce(EntityUid uid, LatheRecipePrototype recipe, int amount = 1, LatheComponent? component = null) + { + if (!base.CanProduce(uid, recipe, amount, component)) + return false; + + if (HasComp(uid) && !_alertLevelRestriction.IsRecipeAvailable(uid, recipe)) + return false; + + return true; + } + // Ganimed edit end } public enum LatheVisualLayers : byte diff --git a/Content.Client/Lathe/UI/LatheBoundUserInterface.cs b/Content.Client/Lathe/UI/LatheBoundUserInterface.cs index 4c354417b86..f658377d677 100644 --- a/Content.Client/Lathe/UI/LatheBoundUserInterface.cs +++ b/Content.Client/Lathe/UI/LatheBoundUserInterface.cs @@ -1,8 +1,11 @@ +using Content.Shared._Ganimed.Components; // Ganimed edit using Content.Shared.ADT.Salvage; // ADT using Content.Shared.Lathe; using Content.Shared.Research.Components; using JetBrains.Annotations; +using Robust.Client.GameObjects; using Robust.Client.UserInterface; +using Robust.Shared.IoC; namespace Content.Client.Lathe.UI { @@ -11,8 +14,12 @@ public sealed class LatheBoundUserInterface : BoundUserInterface { [ViewVariables] private LatheMenu? _menu; + + private readonly IEntityManager _entityManager; // Ganimed edit + public LatheBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { + _entityManager = IoCManager.Resolve(); // Ganimed edit } protected override void Open() @@ -43,7 +50,16 @@ protected override void UpdateState(BoundUserInterfaceState state) { case LatheUpdateState msg: if (_menu != null) + { _menu.Recipes = msg.Recipes; + // Ganimed edit start + + if (_entityManager.TryGetComponent(Owner, out var restrictionComp)) + { + restrictionComp.CurrentAlertLevel = msg.CurrentAlertLevel; + } + } + // Ganimed edit end _menu?.PopulateRecipes(); _menu?.UpdateCategories(); _menu?.PopulateQueueList(msg.Queue); diff --git a/Content.Client/Lathe/UI/LatheMenu.xaml.cs b/Content.Client/Lathe/UI/LatheMenu.xaml.cs index 41343493927..176534072b7 100644 --- a/Content.Client/Lathe/UI/LatheMenu.xaml.cs +++ b/Content.Client/Lathe/UI/LatheMenu.xaml.cs @@ -189,6 +189,42 @@ private string GenerateTooltipText(LatheRecipePrototype prototype) StringBuilder sb = new(); var multiplier = _entityManager.GetComponent(Entity).MaterialUseMultiplier; + // Ganimed edit start: Show current and required alert level + if (!string.IsNullOrEmpty(prototype.RequiredAlertLevel)) + { + // Get required level name + var requiredLevelNameKey = $"lathe-menu-alert-level-{prototype.RequiredAlertLevel}"; + var requiredLevelName = Loc.GetString(requiredLevelNameKey); + if (requiredLevelName == requiredLevelNameKey) + { + var alertLevelKey = $"alert-level-{prototype.RequiredAlertLevel}"; + requiredLevelName = Loc.GetString(alertLevelKey); + if (requiredLevelName == alertLevelKey) + requiredLevelName = prototype.RequiredAlertLevel; + } + + // Get current level name + var currentLevelName = "???"; + if (_entityManager.TryGetComponent(Entity, out Content.Shared._Ganimed.Components.LatheAlertLevelRestrictionComponent? restrictionComp) + && !string.IsNullOrEmpty(restrictionComp.CurrentAlertLevel)) + { + var currentLevelNameKey = $"lathe-menu-alert-level-{restrictionComp.CurrentAlertLevel}"; + currentLevelName = Loc.GetString(currentLevelNameKey); + if (currentLevelName == currentLevelNameKey) + { + var alertLevelKey = $"alert-level-{restrictionComp.CurrentAlertLevel}"; + currentLevelName = Loc.GetString(alertLevelKey); + if (currentLevelName == alertLevelKey) + currentLevelName = restrictionComp.CurrentAlertLevel; + } + } + + sb.AppendLine(Loc.GetString("lathe-menu-alert-level-required", ("level", requiredLevelName))); + sb.AppendLine(Loc.GetString("lathe-menu-alert-level-current", ("level", currentLevelName))); + sb.AppendLine(); + } + // Ganimed edit end + foreach (var (id, amount) in prototype.Materials) { if (!_prototypeManager.TryIndex(id, out var proto)) @@ -237,7 +273,8 @@ public void UpdateCategories() var currentCategories = new List>(); foreach (var recipeId in Recipes) { - var recipe = _prototypeManager.Index(recipeId); + if (!_prototypeManager.TryIndex(recipeId, out var recipe)) + continue; if (recipe.Categories.Count <= 0) continue; @@ -281,7 +318,9 @@ public void PopulateQueueList(IReadOnlyCollection> var idx = 1; foreach (var recipeProto in queue) { - var recipe = _prototypeManager.Index(recipeProto); + if (!_prototypeManager.TryIndex(recipeProto, out var recipe)) + continue; + var queuedRecipeBox = new BoxContainer(); queuedRecipeBox.Orientation = BoxContainer.LayoutOrientation.Horizontal; @@ -301,7 +340,8 @@ public void SetQueueInfo(ProtoId? recipeProto) if (recipeProto == null) return; - var recipe = _prototypeManager.Index(recipeProto.Value); + if (!_prototypeManager.TryIndex(recipeProto.Value, out var recipe)) + return; FabricatingDisplayContainer.Children.Clear(); FabricatingDisplayContainer.AddChild(GetRecipeDisplayControl(recipe)); diff --git a/Content.Client/Lathe/UI/RecipeControl.xaml b/Content.Client/Lathe/UI/RecipeControl.xaml index 1105ab478ff..2e41ba888ff 100644 --- a/Content.Client/Lathe/UI/RecipeControl.xaml +++ b/Content.Client/Lathe/UI/RecipeControl.xaml @@ -13,6 +13,14 @@ MinSize="32 32" />