diff --git a/Content.Client/GameObjects/Components/Atmos/GasAnalyzerVisualizer.cs b/Content.Client/GameObjects/Components/Atmos/GasAnalyzerVisualizer.cs new file mode 100644 index 0000000000..1557891e68 --- /dev/null +++ b/Content.Client/GameObjects/Components/Atmos/GasAnalyzerVisualizer.cs @@ -0,0 +1,52 @@ +using Content.Shared.GameObjects.Components.Atmos; +using Robust.Client.GameObjects; +using Robust.Client.Interfaces.GameObjects.Components; +using Robust.Shared.Utility; +using YamlDotNet.RepresentationModel; + +namespace Content.Client.GameObjects.Components.Atmos +{ + public class GasAnalyzerVisualizer : AppearanceVisualizer + { + private string _stateOff; + private string _stateWorking; + + public override void LoadData(YamlMappingNode node) + { + base.LoadData(node); + + _stateOff = node.GetNode("state_off").AsString(); + _stateWorking = node.GetNode("state_working").AsString(); + } + + public override void OnChangeData(AppearanceComponent component) + { + base.OnChangeData(component); + + if (component.Deleted) + { + return; + } + + if (!component.Owner.TryGetComponent(out ISpriteComponent sprite)) + { + return; + } + + if (component.TryGetData(GasAnalyzerVisuals.VisualState, out GasAnalyzerVisualState visualState)) + { + switch (visualState) + { + case GasAnalyzerVisualState.Off: + sprite.LayerSetState(0, _stateOff); + break; + case GasAnalyzerVisualState.Working: + sprite.LayerSetState(0, _stateWorking); + break; + default: + break; + } + } + } + } +} diff --git a/Content.Server/GameObjects/Components/Atmos/GasAnalyzerComponent.cs b/Content.Server/GameObjects/Components/Atmos/GasAnalyzerComponent.cs index 3b7511c6ae..fc594dd9ac 100644 --- a/Content.Server/GameObjects/Components/Atmos/GasAnalyzerComponent.cs +++ b/Content.Server/GameObjects/Components/Atmos/GasAnalyzerComponent.cs @@ -1,13 +1,14 @@ #nullable enable -using System.Collections.Generic; using Content.Server.GameObjects.EntitySystems; using Content.Server.Interfaces.GameObjects.Components.Items; using Content.Server.Utility; using Content.Shared.Atmos; using Content.Shared.GameObjects.Components; +using Content.Shared.GameObjects.Components.Atmos; using Content.Shared.GameObjects.EntitySystems; using Content.Shared.Interfaces; using Content.Shared.Interfaces.GameObjects.Components; +using Robust.Server.GameObjects; using Robust.Server.GameObjects.Components.UserInterface; using Robust.Server.Interfaces.GameObjects; using Robust.Server.Interfaces.Player; @@ -18,6 +19,7 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Map; using Robust.Shared.ViewVariables; +using System.Collections.Generic; namespace Content.Server.GameObjects.Components.Atmos { @@ -31,6 +33,7 @@ namespace Content.Server.GameObjects.Components.Atmos private const float TimeBetweenSyncs = 2f; private bool _checkPlayer = false; // Check at the player pos or at some other tile? private EntityCoordinates? _position; // The tile that we scanned + private AppearanceComponent? _appearance; [ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(GasAnalyzerUiKey.Key); @@ -41,7 +44,10 @@ namespace Content.Server.GameObjects.Components.Atmos if (UserInterface != null) { UserInterface.OnReceiveMessage += UserInterfaceOnReceiveMessage; + UserInterface.OnClosed += UserInterfaceOnClose; } + + Owner.TryGetComponent(out _appearance); } public override ComponentState GetComponentState() @@ -58,8 +64,9 @@ namespace Content.Server.GameObjects.Components.Atmos { _checkPlayer = true; _position = null; - UserInterface?.Toggle(session); + UserInterface?.Open(session); UpdateUserInterface(); + UpdateAppearance(true); Resync(); } @@ -73,18 +80,42 @@ namespace Content.Server.GameObjects.Components.Atmos { _checkPlayer = false; _position = pos; - UserInterface?.Toggle(session); + UserInterface?.Open(session); UpdateUserInterface(); + UpdateAppearance(true); Resync(); } + public void ToggleInterface(IPlayerSession session) + { + if (UserInterface == null) + return; + + if (UserInterface.SessionHasOpen(session)) + CloseInterface(session); + else + OpenInterface(session); + } + public void CloseInterface(IPlayerSession session) { _position = null; UserInterface?.Close(session); + // Our OnClose will do the appearance stuff Resync(); } + private void UserInterfaceOnClose(IPlayerSession obj) + { + UpdateAppearance(false); + } + + private void UpdateAppearance(bool open) + { + _appearance?.SetData(GasAnalyzerVisuals.VisualState, + open ? GasAnalyzerVisualState.Working : GasAnalyzerVisualState.Off); + } + public void Update(float frameTime) { _timeSinceSync += frameTime; @@ -234,7 +265,6 @@ namespace Content.Server.GameObjects.Components.Atmos if (eventArgs.User.TryGetComponent(out IActorComponent? actor)) { OpenInterface(actor.playerSession, eventArgs.ClickLocation); - //TODO: show other sprite when ui open? } } @@ -245,7 +275,6 @@ namespace Content.Server.GameObjects.Components.Atmos if (eventArgs.User.TryGetComponent(out IActorComponent? actor)) { CloseInterface(actor.playerSession); - //TODO: if other sprite is shown, change again } } @@ -253,8 +282,7 @@ namespace Content.Server.GameObjects.Components.Atmos { if (eventArgs.User.TryGetComponent(out IActorComponent? actor)) { - OpenInterface(actor.playerSession); - //TODO: show other sprite when ui open? + ToggleInterface(actor.playerSession); return true; } return false; diff --git a/Content.Shared/GameObjects/Components/Atmos/SharedGasAnalyzerComponent.cs b/Content.Shared/GameObjects/Components/Atmos/SharedGasAnalyzerComponent.cs new file mode 100644 index 0000000000..7b43d646c6 --- /dev/null +++ b/Content.Shared/GameObjects/Components/Atmos/SharedGasAnalyzerComponent.cs @@ -0,0 +1,20 @@ +using Robust.Shared.Serialization; +using System; + +namespace Content.Shared.GameObjects.Components.Atmos +{ + [NetSerializable] + [Serializable] + public enum GasAnalyzerVisuals + { + VisualState, + } + + [NetSerializable] + [Serializable] + public enum GasAnalyzerVisualState + { + Off, + Working, + } +} diff --git a/Resources/Prototypes/Entities/Objects/Specific/atmos.yml b/Resources/Prototypes/Entities/Objects/Specific/atmos.yml index 7dce8b5aa0..1e36174408 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/atmos.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/atmos.yml @@ -15,3 +15,8 @@ interfaces: - key: enum.GasAnalyzerUiKey.Key type: GasAnalyzerBoundUserInterface + - type: Appearance + visuals: + - type: GasAnalyzerVisualizer + state_off: icon + state_working: working diff --git a/Resources/Textures/Objects/Specific/Atmos/gasanalyzer.rsi/meta.json b/Resources/Textures/Objects/Specific/Atmos/gasanalyzer.rsi/meta.json index 97925d64e5..e1dd064c9a 100644 --- a/Resources/Textures/Objects/Specific/Atmos/gasanalyzer.rsi/meta.json +++ b/Resources/Textures/Objects/Specific/Atmos/gasanalyzer.rsi/meta.json @@ -15,7 +15,7 @@ ] }, { - "name": "atmos2", + "name": "working", "directions": 1, "delays": [ [ diff --git a/Resources/Textures/Objects/Specific/Atmos/gasanalyzer.rsi/atmos2.png b/Resources/Textures/Objects/Specific/Atmos/gasanalyzer.rsi/working.png similarity index 100% rename from Resources/Textures/Objects/Specific/Atmos/gasanalyzer.rsi/atmos2.png rename to Resources/Textures/Objects/Specific/Atmos/gasanalyzer.rsi/working.png