Files
OldThink/Content.Client/GameObjects/Components/Interactable/MultiToolComponent.cs

78 lines
2.4 KiB
C#
Raw Normal View History

using Content.Client.UserInterface.Stylesheets;
2020-01-09 00:27:52 +01:00
using Content.Client.Utility;
2020-05-19 13:55:52 +02:00
using Content.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Interactable;
2020-01-09 00:27:52 +01:00
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
2020-01-09 00:27:52 +01:00
using Robust.Shared.Timing;
using Robust.Shared.ViewVariables;
namespace Content.Client.GameObjects.Components.Interactable
2020-01-09 00:27:52 +01:00
{
[RegisterComponent]
2020-05-19 13:55:52 +02:00
public class MultiToolComponent : Component, IItemStatus
2020-01-09 00:27:52 +01:00
{
2020-05-19 13:55:52 +02:00
private ToolQuality _behavior;
private bool _statusShowBehavior;
2020-05-11 15:26:07 +02:00
2020-05-11 15:40:33 +02:00
[ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded;
[ViewVariables] public bool StatusShowBehavior => _statusShowBehavior;
2020-05-19 13:55:52 +02:00
[ViewVariables] public ToolQuality Behavior => _behavior;
public override string Name => "MultiTool";
public override uint? NetID => ContentNetIDs.MULTITOOLS;
2020-01-09 00:27:52 +01:00
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
2020-05-19 13:55:52 +02:00
serializer.DataField(ref _statusShowBehavior, "statusShowBehavior", true);
}
2020-01-09 00:27:52 +01:00
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
{
2020-05-19 13:55:52 +02:00
if (!(curState is MultiToolComponentState tool)) return;
2020-01-09 00:27:52 +01:00
2020-05-19 13:55:52 +02:00
_behavior = tool.Quality;
2020-01-09 00:27:52 +01:00
_uiUpdateNeeded = true;
2020-05-11 15:26:07 +02:00
2020-01-09 00:27:52 +01:00
}
public Control MakeControl() => new StatusControl(this);
private sealed class StatusControl : Control
{
2020-05-19 13:55:52 +02:00
private readonly MultiToolComponent _parent;
2020-01-09 00:27:52 +01:00
private readonly RichTextLabel _label;
2020-05-19 13:55:52 +02:00
public StatusControl(MultiToolComponent parent)
2020-01-09 00:27:52 +01:00
{
_parent = parent;
_label = new RichTextLabel {StyleClasses = {StyleNano.StyleClassItemStatus}};
2020-01-09 00:27:52 +01:00
AddChild(_label);
parent._uiUpdateNeeded = true;
}
protected override void Update(FrameEventArgs args)
{
base.Update(args);
if (!_parent._uiUpdateNeeded)
{
return;
}
_parent._uiUpdateNeeded = false;
2020-05-11 15:26:07 +02:00
if(!_parent.StatusShowBehavior)
_label.SetMarkup(string.Empty);
else
2020-05-11 15:26:07 +02:00
_label.SetMarkup(_parent.Behavior.ToString());
2020-01-09 00:27:52 +01:00
}
}
}
}