diff --git a/Content.Client/Construction/ConstructionSystem.cs b/Content.Client/Construction/ConstructionSystem.cs index f909b23423db1c..25c6b877de5430 100644 --- a/Content.Client/Construction/ConstructionSystem.cs +++ b/Content.Client/Construction/ConstructionSystem.cs @@ -1,20 +1,23 @@ using System.Diagnostics.CodeAnalysis; +using System.Linq; using Content.Client.Popups; using Content.Shared.Construction; using Content.Shared.Construction.Prototypes; -using Content.Shared.Construction.Steps; using Content.Shared.Examine; using Content.Shared.Input; -using Content.Shared.Interaction; +using Content.Shared.Prototypes; using Content.Shared.Wall; using JetBrains.Annotations; using Robust.Client.GameObjects; +using Robust.Client.Graphics; using Robust.Client.Player; +using Robust.Client.Utility; using Robust.Shared.Input; using Robust.Shared.Input.Binding; using Robust.Shared.Map; using Robust.Shared.Player; using Robust.Shared.Prototypes; +using Robust.Shared.Utility; namespace Content.Client.Construction { @@ -32,14 +35,20 @@ public sealed class ConstructionSystem : SharedConstructionSystem private readonly Dictionary _ghosts = new(); private readonly Dictionary _guideCache = new(); + private Dictionary? _recipeMetadataCache; public bool CraftingEnabled { get; private set; } + public bool IsRecipesCacheWarmed { get; private set; } + /// public override void Initialize() { base.Initialize(); + SubscribeNetworkEvent(OnResponseConstructionRecipes); + RaiseNetworkEvent(new RequestConstructionRecipes()); + UpdatesOutsidePrediction = true; SubscribeLocalEvent(HandlePlayerAttached); SubscribeNetworkEvent(HandleAckStructure); @@ -57,6 +66,45 @@ public override void Initialize() SubscribeLocalEvent(HandleConstructionGhostExamined); } + public event EventHandler? OnConstructionRecipesUpdated; + private void OnResponseConstructionRecipes(ResponseConstructionRecipes ev) + { + if (_recipeMetadataCache is null) + { + _recipeMetadataCache = new(); + + foreach (var (constructionProtoId, targetProtoId) in ev.Metadata) + { + if (!_prototypeManager.TryIndex(constructionProtoId, out ConstructionPrototype? recipe)) + continue; + + if (!_prototypeManager.TryIndex(targetProtoId, out var proto)) + continue; + + var name = recipe.NameLocId.HasValue ? Loc.GetString(recipe.NameLocId) : proto.Name; + var desc = recipe.DescLocId.HasValue ? Loc.GetString(recipe.DescLocId) : proto.Description; + + recipe.Name = name; + recipe.Description = desc; + + _recipeMetadataCache.Add(constructionProtoId, targetProtoId); + } + + IsRecipesCacheWarmed = true; + } + + OnConstructionRecipesUpdated?.Invoke(this, EventArgs.Empty); + } + + public bool TryGetRecipePrototype(string constructionProtoId, [NotNullWhen(true)] out string? targetProtoId) + { + if (_recipeMetadataCache is not null && _recipeMetadataCache.TryGetValue(constructionProtoId, out targetProtoId)) + return true; + + targetProtoId = null; + return false; + } + private void OnConstructionGuideReceived(ResponseConstructionGuide ev) { _guideCache[ev.ConstructionId] = ev.Guide; @@ -89,7 +137,7 @@ private void HandleConstructionGhostExamined(EntityUid uid, ConstructionGhostCom { args.PushMarkup(Loc.GetString( "construction-ghost-examine-message", - ("name", component.Prototype.Name))); + ("name", component.Prototype.Name!))); if (!_prototypeManager.TryIndex(component.Prototype.Graph, out ConstructionGraphPrototype? graph)) return; @@ -210,14 +258,6 @@ public bool TrySpawnGhost( var sprite = EntityManager.GetComponent(ghost.Value); sprite.Color = new Color(48, 255, 48, 128); - for (int i = 0; i < prototype.Layers.Count; i++) - { - sprite.AddBlankLayer(i); // There is no way to actually check if this already exists, so we blindly insert a new one - sprite.LayerSetSprite(i, prototype.Layers[i]); - sprite.LayerSetShader(i, "unshaded"); - sprite.LayerSetVisible(i, true); - } - if (prototype.CanBuildInImpassable) EnsureComp(ghost.Value).Arc = new(Math.Tau); diff --git a/Content.Client/Construction/UI/ConstructionMenu.xaml b/Content.Client/Construction/UI/ConstructionMenu.xaml index 6e4438cf6fdc6c..4d10371c18de98 100644 --- a/Content.Client/Construction/UI/ConstructionMenu.xaml +++ b/Content.Client/Construction/UI/ConstructionMenu.xaml @@ -1,11 +1,12 @@ - + - +