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:
Exp
2020-09-21 11:39:17 +02:00
committed by GitHub
parent 6ec2939f15
commit 8238a89190
6 changed files with 113 additions and 8 deletions

View File

@@ -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;
}
}
}
}
}

View File

@@ -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;

View File

@@ -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,
}
}

View File

@@ -15,3 +15,8 @@
interfaces:
- key: enum.GasAnalyzerUiKey.Key
type: GasAnalyzerBoundUserInterface
- type: Appearance
visuals:
- type: GasAnalyzerVisualizer
state_off: icon
state_working: working

View File

@@ -15,7 +15,7 @@
]
},
{
"name": "atmos2",
"name": "working",
"directions": 1,
"delays": [
[

View File

Before

Width:  |  Height:  |  Size: 1019 B

After

Width:  |  Height:  |  Size: 1019 B