diff --git a/Content.Client/Construction/ConstructionGhostComponent.cs b/Content.Client/Construction/ConstructionGhostComponent.cs index 4411a7701c..f15f23fd38 100644 --- a/Content.Client/Construction/ConstructionGhostComponent.cs +++ b/Content.Client/Construction/ConstructionGhostComponent.cs @@ -1,40 +1,15 @@ using Content.Shared.Construction.Prototypes; -using Content.Shared.Examine; using Robust.Shared.GameObjects; -using Robust.Shared.IoC; -using Robust.Shared.Localization; -using Robust.Shared.Prototypes; -using Robust.Shared.Utility; using Robust.Shared.ViewVariables; namespace Content.Client.Construction { [RegisterComponent] - public class ConstructionGhostComponent : Component, IExamine + public class ConstructionGhostComponent : Component { - [Dependency] private readonly IPrototypeManager _prototypeManager = default!; - public override string Name => "ConstructionGhost"; [ViewVariables] public ConstructionPrototype? Prototype { get; set; } [ViewVariables] public int GhostId { get; set; } - - void IExamine.Examine(FormattedMessage message, bool inDetailsRange) - { - if (Prototype == null) return; - - message.AddMarkup(Loc.GetString("construction-ghost-examine-message", ("name", Prototype.Name))); - - if (!_prototypeManager.TryIndex(Prototype.Graph, out ConstructionGraphPrototype? graph)) return; - var startNode = graph.Nodes[Prototype.StartNode]; - - if (!graph.TryPath(Prototype.StartNode, Prototype.TargetNode, out var path) || - !startNode.TryGetEdge(path[0].Name, out var edge)) - { - return; - } - - edge.Steps[0].DoExamine(message, inDetailsRange); - } } } diff --git a/Content.Client/Construction/ConstructionSystem.cs b/Content.Client/Construction/ConstructionSystem.cs index e3524212dc..1ec62280ea 100644 --- a/Content.Client/Construction/ConstructionSystem.cs +++ b/Content.Client/Construction/ConstructionSystem.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using Content.Shared.Construction; using Content.Shared.Construction.Prototypes; +using Content.Shared.Examine; using Content.Shared.Input; using Content.Shared.Interaction.Helpers; using JetBrains.Annotations; @@ -11,8 +12,10 @@ using Robust.Shared.GameObjects; using Robust.Shared.Input; using Robust.Shared.Input.Binding; using Robust.Shared.IoC; +using Robust.Shared.Localization; using Robust.Shared.Map; using Robust.Shared.Maths; +using Robust.Shared.Prototypes; namespace Content.Client.Construction @@ -24,6 +27,8 @@ namespace Content.Client.Construction public class ConstructionSystem : SharedConstructionSystem { [Dependency] private readonly IPlayerManager _playerManager = default!; + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + private readonly Dictionary _ghosts = new(); private int _nextId; @@ -44,6 +49,8 @@ namespace Content.Client.Construction .Bind(EngineKeyFunctions.Use, new PointerInputCmdHandler(HandleUse)) .Register(); + + SubscribeLocalEvent(HandleConstructionGhostExamined); } /// @@ -54,6 +61,28 @@ namespace Content.Client.Construction CommandBinds.Unregister(); } + private void HandleConstructionGhostExamined(EntityUid uid, ConstructionGhostComponent component, ExaminedEvent args) + { + if (component.Prototype == null) return; + + args.Message.AddMarkup(Loc.GetString( + "construction-ghost-examine-message", + ("name", component.Prototype.Name))); + + if (!_prototypeManager.TryIndex(component.Prototype.Graph, out ConstructionGraphPrototype? graph)) + return; + + var startNode = graph.Nodes[component.Prototype.StartNode]; + + if (!graph.TryPath(component.Prototype.StartNode, component.Prototype.TargetNode, out var path) || + !startNode.TryGetEdge(path[0].Name, out var edge)) + { + return; + } + + edge.Steps[0].DoExamine(args); + } + public event EventHandler? CraftingAvailabilityChanged; public event EventHandler? ToggleCraftingWindow; diff --git a/Content.Server/Construction/Components/ConstructionComponent.cs b/Content.Server/Construction/Components/ConstructionComponent.cs index ffed8940c0..e124f00980 100644 --- a/Content.Server/Construction/Components/ConstructionComponent.cs +++ b/Content.Server/Construction/Components/ConstructionComponent.cs @@ -9,24 +9,21 @@ using Content.Server.Tools.Components; using Content.Shared.Construction; using Content.Shared.Construction.Prototypes; using Content.Shared.Construction.Steps; -using Content.Shared.Examine; using Content.Shared.Interaction; using Content.Shared.Tool; using Robust.Shared.Containers; using Robust.Shared.GameObjects; using Robust.Shared.IoC; -using Robust.Shared.Localization; using Robust.Shared.Log; using Robust.Shared.Physics; using Robust.Shared.Prototypes; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; using Robust.Shared.ViewVariables; namespace Content.Server.Construction.Components { [RegisterComponent] - public partial class ConstructionComponent : Component, IExamine, IInteractUsing + public partial class ConstructionComponent : Component, IInteractUsing { [Dependency] private readonly IPrototypeManager _prototypeManager = default!; @@ -45,7 +42,7 @@ namespace Content.Server.Construction.Components [ViewVariables] private HashSet _containers = new(); [ViewVariables] - private List>? _edgeNestedStepProgress = null; + public List>? EdgeNestedStepProgress = null; private ConstructionGraphNode? _target = null; @@ -298,14 +295,14 @@ namespace Content.Server.Construction.Components break; case NestedConstructionGraphStep nestedStep: - if(_edgeNestedStepProgress == null) - _edgeNestedStepProgress = new List>(nestedStep.Steps); + if(EdgeNestedStepProgress == null) + EdgeNestedStepProgress = new List>(nestedStep.Steps); - foreach (var list in _edgeNestedStepProgress.ToArray()) + foreach (var list in EdgeNestedStepProgress.ToArray()) { if (list.Count == 0) { - _edgeNestedStepProgress.Remove(list); + EdgeNestedStepProgress.Remove(list); continue; } @@ -315,10 +312,10 @@ namespace Content.Server.Construction.Components // We check again... if (list.Count == 0) - _edgeNestedStepProgress.Remove(list); + EdgeNestedStepProgress.Remove(list); } - if (_edgeNestedStepProgress.Count == 0) + if (EdgeNestedStepProgress.Count == 0) handled = true; break; @@ -390,7 +387,7 @@ namespace Content.Server.Construction.Components public void ResetEdge() { - _edgeNestedStepProgress = null; + EdgeNestedStepProgress = null; TargetNextEdge = null; Edge = null; EdgeStep = 0; @@ -531,51 +528,5 @@ namespace Content.Server.Construction.Components await HandleEntityChange(graphNode); } - - void IExamine.Examine(FormattedMessage message, bool inDetailsRange) - { - if(Target != null) - message.AddMarkup(Loc.GetString("construction-component-to-create-header",("targetName", Target.Name)) + "\n"); - - if (Edge == null && TargetNextEdge != null) - { - var preventStepExamine = false; - - foreach (var condition in TargetNextEdge.Conditions) - { - preventStepExamine |= condition.DoExamine(Owner, message, inDetailsRange); - } - - if(!preventStepExamine) - TargetNextEdge.Steps[0].DoExamine(message, inDetailsRange); - return; - } - - if (Edge != null) - { - var preventStepExamine = false; - - foreach (var condition in Edge.Conditions) - { - preventStepExamine |= condition.DoExamine(Owner, message, inDetailsRange); - } - - if (preventStepExamine) return; - } - - if (_edgeNestedStepProgress == null) - { - if(EdgeStep < Edge?.Steps.Count) - Edge.Steps[EdgeStep].DoExamine(message, inDetailsRange); - return; - } - - foreach (var list in _edgeNestedStepProgress) - { - if(list.Count == 0) continue; - - list[0].DoExamine(message, inDetailsRange); - } - } } } diff --git a/Content.Server/Construction/ConstructionSystem.cs b/Content.Server/Construction/ConstructionSystem.cs index 8ce2d9d247..65275a5cad 100644 --- a/Content.Server/Construction/ConstructionSystem.cs +++ b/Content.Server/Construction/ConstructionSystem.cs @@ -14,6 +14,7 @@ using Content.Shared.Construction; using Content.Shared.Construction.Prototypes; using Content.Shared.Construction.Steps; using Content.Shared.Coordinates; +using Content.Shared.Examine; using Content.Shared.Interaction.Events; using Content.Shared.Interaction.Helpers; using Content.Shared.Notification.Managers; @@ -50,6 +51,59 @@ namespace Content.Server.Construction SubscribeNetworkEvent(HandleStartStructureConstruction); SubscribeNetworkEvent(HandleStartItemConstruction); + SubscribeLocalEvent(HandleConstructionExamined); + } + + private void HandleConstructionExamined(EntityUid uid, ConstructionComponent component, ExaminedEvent args) + { + if (component.Target != null) + { + args.Message.AddMarkup( + Loc.GetString( + "construction-component-to-create-header", + ("targetName", component.Target.Name)) + "\n"); + } + + if (component.Edge == null && component.TargetNextEdge != null) + { + var preventStepExamine = false; + + foreach (var condition in component.TargetNextEdge.Conditions) + { + preventStepExamine |= condition.DoExamine(args); + } + + if (!preventStepExamine) + component.TargetNextEdge.Steps[0].DoExamine(args); + return; + } + + if (component.Edge != null) + { + var preventStepExamine = false; + + foreach (var condition in component.Edge.Conditions) + { + preventStepExamine |= condition.DoExamine(args); + } + + if (preventStepExamine) return; + } + + if (component.EdgeNestedStepProgress == null) + { + if (component.EdgeStep < component.Edge?.Steps.Count) + component.Edge.Steps[component.EdgeStep].DoExamine(args); + return; + } + + foreach (var list in component.EdgeNestedStepProgress) + { + if(list.Count == 0) continue; + + list[0].DoExamine(args); + } + } private IEnumerable EnumerateNearby(IEntity user) diff --git a/Content.Shared/Construction/IGraphCondition.cs b/Content.Shared/Construction/IGraphCondition.cs index 18a09984b8..ee6f929f0d 100644 --- a/Content.Shared/Construction/IGraphCondition.cs +++ b/Content.Shared/Construction/IGraphCondition.cs @@ -1,12 +1,12 @@ using System.Threading.Tasks; +using Content.Shared.Examine; using Robust.Shared.GameObjects; -using Robust.Shared.Utility; namespace Content.Shared.Construction { public interface IGraphCondition { Task Condition(IEntity entity); - bool DoExamine(IEntity entity, FormattedMessage message, bool inExamineRange) { return false; } + bool DoExamine(ExaminedEvent examinedEvent) { return false; } } } diff --git a/Content.Shared/Construction/Steps/ArbitraryInsertConstructionGraphStep.cs b/Content.Shared/Construction/Steps/ArbitraryInsertConstructionGraphStep.cs index 16aab18b29..e5341affbf 100644 --- a/Content.Shared/Construction/Steps/ArbitraryInsertConstructionGraphStep.cs +++ b/Content.Shared/Construction/Steps/ArbitraryInsertConstructionGraphStep.cs @@ -1,4 +1,5 @@ -using Robust.Shared.Localization; +using Content.Shared.Examine; +using Robust.Shared.Localization; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; @@ -10,10 +11,12 @@ namespace Content.Shared.Construction.Steps [DataField("icon")] public SpriteSpecifier Icon { get; private set; } = SpriteSpecifier.Invalid; - public override void DoExamine(FormattedMessage message, bool inDetailsRange) + public override void DoExamine(ExaminedEvent examinedEvent) { - if (string.IsNullOrEmpty(Name)) return; - message.AddMarkup(Loc.GetString("construction-insert-arbitrary-entity", ("stepName", Name))); + if (string.IsNullOrEmpty(Name)) + return; + + examinedEvent.Message.AddMarkup(Loc.GetString("construction-insert-arbitrary-entity", ("stepName", Name))); } } } diff --git a/Content.Shared/Construction/Steps/ComponentConstructionGraphStep.cs b/Content.Shared/Construction/Steps/ComponentConstructionGraphStep.cs index 55d8908fe0..139c790162 100644 --- a/Content.Shared/Construction/Steps/ComponentConstructionGraphStep.cs +++ b/Content.Shared/Construction/Steps/ComponentConstructionGraphStep.cs @@ -1,7 +1,7 @@ -using Robust.Shared.GameObjects; +using Content.Shared.Examine; +using Robust.Shared.GameObjects; using Robust.Shared.Localization; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; namespace Content.Shared.Construction.Steps { @@ -21,9 +21,9 @@ namespace Content.Shared.Construction.Steps return false; } - public override void DoExamine(FormattedMessage message, bool inDetailsRange) + public override void DoExamine(ExaminedEvent examinedEvent) { - message.AddMarkup(string.IsNullOrEmpty(Name) + examinedEvent.Message.AddMarkup(string.IsNullOrEmpty(Name) ? Loc.GetString( "construction-insert-entity-with-component", ("componentName", Component))// Terrible. diff --git a/Content.Shared/Construction/Steps/ConstructionGraphStep.cs b/Content.Shared/Construction/Steps/ConstructionGraphStep.cs index e9e6e5aba9..84f2e5c885 100644 --- a/Content.Shared/Construction/Steps/ConstructionGraphStep.cs +++ b/Content.Shared/Construction/Steps/ConstructionGraphStep.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; +using Content.Shared.Examine; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; namespace Content.Shared.Construction.Steps { @@ -15,6 +15,6 @@ namespace Content.Shared.Construction.Steps public IReadOnlyList Completed => _completed; - public abstract void DoExamine(FormattedMessage message, bool inDetailsRange); + public abstract void DoExamine(ExaminedEvent examinedEvent); } } diff --git a/Content.Shared/Construction/Steps/MaterialConstructionGraphStep.cs b/Content.Shared/Construction/Steps/MaterialConstructionGraphStep.cs index 98e71b3ce7..7af699d078 100644 --- a/Content.Shared/Construction/Steps/MaterialConstructionGraphStep.cs +++ b/Content.Shared/Construction/Steps/MaterialConstructionGraphStep.cs @@ -1,11 +1,11 @@ using System.Diagnostics.CodeAnalysis; +using Content.Shared.Examine; using Content.Shared.Stacks; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Prototypes; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; namespace Content.Shared.Construction.Steps { @@ -21,9 +21,9 @@ namespace Content.Shared.Construction.Steps public StackPrototype MaterialPrototype => IoCManager.Resolve().Index(MaterialPrototypeId); - public override void DoExamine(FormattedMessage message, bool inDetailsRange) + public override void DoExamine(ExaminedEvent examinedEvent) { - message.AddMarkup(Loc.GetString("construction-insert-material-entity", ("amount", Amount), ("materialName", MaterialPrototype.Name))); + examinedEvent.Message.AddMarkup(Loc.GetString("construction-insert-material-entity", ("amount", Amount), ("materialName", MaterialPrototype.Name))); } public override bool EntityValid(IEntity entity) diff --git a/Content.Shared/Construction/Steps/NestedConstructionGraphStep.cs b/Content.Shared/Construction/Steps/NestedConstructionGraphStep.cs index cf42bd333b..592f339ddb 100644 --- a/Content.Shared/Construction/Steps/NestedConstructionGraphStep.cs +++ b/Content.Shared/Construction/Steps/NestedConstructionGraphStep.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Content.Shared.Examine; using Robust.Shared.Serialization; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; namespace Content.Shared.Construction.Steps { @@ -20,7 +20,7 @@ namespace Content.Shared.Construction.Steps } } - public override void DoExamine(FormattedMessage message, bool inDetailsRange) + public override void DoExamine(ExaminedEvent examinedEvent) { } } diff --git a/Content.Shared/Construction/Steps/PrototypeConstructionGraphStep.cs b/Content.Shared/Construction/Steps/PrototypeConstructionGraphStep.cs index 548ea9b203..2a86c46ecf 100644 --- a/Content.Shared/Construction/Steps/PrototypeConstructionGraphStep.cs +++ b/Content.Shared/Construction/Steps/PrototypeConstructionGraphStep.cs @@ -1,7 +1,7 @@ -using Robust.Shared.GameObjects; +using Content.Shared.Examine; +using Robust.Shared.GameObjects; using Robust.Shared.Localization; using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.Utility; namespace Content.Shared.Construction.Steps { @@ -15,9 +15,9 @@ namespace Content.Shared.Construction.Steps return entity.Prototype?.ID == Prototype; } - public override void DoExamine(FormattedMessage message, bool inDetailsRange) + public override void DoExamine(ExaminedEvent examinedEvent) { - message.AddMarkup(string.IsNullOrEmpty(Name) + examinedEvent.Message.AddMarkup(string.IsNullOrEmpty(Name) ? Loc.GetString( "construction-insert-prototype-no-name", ("prototypeName", Prototype) // Terrible. diff --git a/Content.Shared/Construction/Steps/ToolConstructionGraphStep.cs b/Content.Shared/Construction/Steps/ToolConstructionGraphStep.cs index dd0fae8999..2a0d7ba78e 100644 --- a/Content.Shared/Construction/Steps/ToolConstructionGraphStep.cs +++ b/Content.Shared/Construction/Steps/ToolConstructionGraphStep.cs @@ -1,3 +1,4 @@ +using Content.Shared.Examine; using Content.Shared.Tool; using Robust.Shared.Localization; using Robust.Shared.Serialization.Manager.Attributes; @@ -14,15 +15,15 @@ namespace Content.Shared.Construction.Steps [DataField("examine")] public string ExamineOverride { get; } = string.Empty; - public override void DoExamine(FormattedMessage message, bool inDetailsRange) + public override void DoExamine(ExaminedEvent examinedEvent) { if (!string.IsNullOrEmpty(ExamineOverride)) { - message.AddMarkup(Loc.GetString(ExamineOverride)); + examinedEvent.Message.AddMarkup(Loc.GetString(ExamineOverride)); return; } - message.AddMarkup(Loc.GetString("construction-use-tool-entity", ("toolName", Tool.GetToolName()))); + examinedEvent.Message.AddMarkup(Loc.GetString("construction-use-tool-entity", ("toolName", Tool.GetToolName()))); } } }