Gives the gas analyzer visual clues that it's open (#2110)
* Gives the gas analyzer visual clues that it's open * Read Visualizer states from yaml
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
#nullable enable
|
#nullable enable
|
||||||
using System.Collections.Generic;
|
|
||||||
using Content.Server.GameObjects.EntitySystems;
|
using Content.Server.GameObjects.EntitySystems;
|
||||||
using Content.Server.Interfaces.GameObjects.Components.Items;
|
using Content.Server.Interfaces.GameObjects.Components.Items;
|
||||||
using Content.Server.Utility;
|
using Content.Server.Utility;
|
||||||
using Content.Shared.Atmos;
|
using Content.Shared.Atmos;
|
||||||
using Content.Shared.GameObjects.Components;
|
using Content.Shared.GameObjects.Components;
|
||||||
|
using Content.Shared.GameObjects.Components.Atmos;
|
||||||
using Content.Shared.GameObjects.EntitySystems;
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Content.Shared.Interfaces;
|
using Content.Shared.Interfaces;
|
||||||
using Content.Shared.Interfaces.GameObjects.Components;
|
using Content.Shared.Interfaces.GameObjects.Components;
|
||||||
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Server.GameObjects.Components.UserInterface;
|
using Robust.Server.GameObjects.Components.UserInterface;
|
||||||
using Robust.Server.Interfaces.GameObjects;
|
using Robust.Server.Interfaces.GameObjects;
|
||||||
using Robust.Server.Interfaces.Player;
|
using Robust.Server.Interfaces.Player;
|
||||||
@@ -18,6 +19,7 @@ using Robust.Shared.IoC;
|
|||||||
using Robust.Shared.Localization;
|
using Robust.Shared.Localization;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.ViewVariables;
|
using Robust.Shared.ViewVariables;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Content.Server.GameObjects.Components.Atmos
|
namespace Content.Server.GameObjects.Components.Atmos
|
||||||
{
|
{
|
||||||
@@ -31,6 +33,7 @@ namespace Content.Server.GameObjects.Components.Atmos
|
|||||||
private const float TimeBetweenSyncs = 2f;
|
private const float TimeBetweenSyncs = 2f;
|
||||||
private bool _checkPlayer = false; // Check at the player pos or at some other tile?
|
private bool _checkPlayer = false; // Check at the player pos or at some other tile?
|
||||||
private EntityCoordinates? _position; // The tile that we scanned
|
private EntityCoordinates? _position; // The tile that we scanned
|
||||||
|
private AppearanceComponent? _appearance;
|
||||||
|
|
||||||
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(GasAnalyzerUiKey.Key);
|
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(GasAnalyzerUiKey.Key);
|
||||||
|
|
||||||
@@ -41,7 +44,10 @@ namespace Content.Server.GameObjects.Components.Atmos
|
|||||||
if (UserInterface != null)
|
if (UserInterface != null)
|
||||||
{
|
{
|
||||||
UserInterface.OnReceiveMessage += UserInterfaceOnReceiveMessage;
|
UserInterface.OnReceiveMessage += UserInterfaceOnReceiveMessage;
|
||||||
|
UserInterface.OnClosed += UserInterfaceOnClose;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Owner.TryGetComponent(out _appearance);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override ComponentState GetComponentState()
|
public override ComponentState GetComponentState()
|
||||||
@@ -58,8 +64,9 @@ namespace Content.Server.GameObjects.Components.Atmos
|
|||||||
{
|
{
|
||||||
_checkPlayer = true;
|
_checkPlayer = true;
|
||||||
_position = null;
|
_position = null;
|
||||||
UserInterface?.Toggle(session);
|
UserInterface?.Open(session);
|
||||||
UpdateUserInterface();
|
UpdateUserInterface();
|
||||||
|
UpdateAppearance(true);
|
||||||
Resync();
|
Resync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,18 +80,42 @@ namespace Content.Server.GameObjects.Components.Atmos
|
|||||||
{
|
{
|
||||||
_checkPlayer = false;
|
_checkPlayer = false;
|
||||||
_position = pos;
|
_position = pos;
|
||||||
UserInterface?.Toggle(session);
|
UserInterface?.Open(session);
|
||||||
UpdateUserInterface();
|
UpdateUserInterface();
|
||||||
|
UpdateAppearance(true);
|
||||||
Resync();
|
Resync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ToggleInterface(IPlayerSession session)
|
||||||
|
{
|
||||||
|
if (UserInterface == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (UserInterface.SessionHasOpen(session))
|
||||||
|
CloseInterface(session);
|
||||||
|
else
|
||||||
|
OpenInterface(session);
|
||||||
|
}
|
||||||
|
|
||||||
public void CloseInterface(IPlayerSession session)
|
public void CloseInterface(IPlayerSession session)
|
||||||
{
|
{
|
||||||
_position = null;
|
_position = null;
|
||||||
UserInterface?.Close(session);
|
UserInterface?.Close(session);
|
||||||
|
// Our OnClose will do the appearance stuff
|
||||||
Resync();
|
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)
|
public void Update(float frameTime)
|
||||||
{
|
{
|
||||||
_timeSinceSync += frameTime;
|
_timeSinceSync += frameTime;
|
||||||
@@ -234,7 +265,6 @@ namespace Content.Server.GameObjects.Components.Atmos
|
|||||||
if (eventArgs.User.TryGetComponent(out IActorComponent? actor))
|
if (eventArgs.User.TryGetComponent(out IActorComponent? actor))
|
||||||
{
|
{
|
||||||
OpenInterface(actor.playerSession, eventArgs.ClickLocation);
|
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))
|
if (eventArgs.User.TryGetComponent(out IActorComponent? actor))
|
||||||
{
|
{
|
||||||
CloseInterface(actor.playerSession);
|
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))
|
if (eventArgs.User.TryGetComponent(out IActorComponent? actor))
|
||||||
{
|
{
|
||||||
OpenInterface(actor.playerSession);
|
ToggleInterface(actor.playerSession);
|
||||||
//TODO: show other sprite when ui open?
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -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,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,3 +15,8 @@
|
|||||||
interfaces:
|
interfaces:
|
||||||
- key: enum.GasAnalyzerUiKey.Key
|
- key: enum.GasAnalyzerUiKey.Key
|
||||||
type: GasAnalyzerBoundUserInterface
|
type: GasAnalyzerBoundUserInterface
|
||||||
|
- type: Appearance
|
||||||
|
visuals:
|
||||||
|
- type: GasAnalyzerVisualizer
|
||||||
|
state_off: icon
|
||||||
|
state_working: working
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "atmos2",
|
"name": "working",
|
||||||
"directions": 1,
|
"directions": 1,
|
||||||
"delays": [
|
"delays": [
|
||||||
[
|
[
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1019 B After Width: | Height: | Size: 1019 B |
Reference in New Issue
Block a user