2021-03-26 17:10:31 -07:00
|
|
|
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;
|
2020-04-29 13:43:07 +02:00
|
|
|
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;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-01-09 00:27:52 +01:00
|
|
|
using Robust.Shared.Timing;
|
|
|
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
|
|
2020-04-29 13:43:07 +02:00
|
|
|
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;
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("statusShowBehavior")]
|
|
|
|
|
private bool _statusShowBehavior = true;
|
2020-05-11 15:26:07 +02:00
|
|
|
|
2020-05-11 15:40:33 +02:00
|
|
|
[ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded;
|
2020-04-29 13:43:07 +02:00
|
|
|
[ViewVariables] public bool StatusShowBehavior => _statusShowBehavior;
|
2021-03-16 15:50:20 +01:00
|
|
|
[ViewVariables] public ToolQuality? Behavior => _behavior;
|
2020-05-19 13:55:52 +02:00
|
|
|
|
|
|
|
|
public override string Name => "MultiTool";
|
|
|
|
|
public override uint? NetID => ContentNetIDs.MULTITOOLS;
|
2020-01-09 00:27:52 +01:00
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
2020-01-09 00:27:52 +01:00
|
|
|
{
|
2020-11-26 14:33:31 +01:00
|
|
|
base.HandleComponentState(curState, nextState);
|
|
|
|
|
|
|
|
|
|
if (curState is not 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;
|
2020-04-04 15:10:51 +02:00
|
|
|
_label = new RichTextLabel {StyleClasses = {StyleNano.StyleClassItemStatus}};
|
2020-01-09 00:27:52 +01:00
|
|
|
AddChild(_label);
|
|
|
|
|
|
|
|
|
|
parent._uiUpdateNeeded = true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-26 17:10:31 -07:00
|
|
|
protected override void FrameUpdate(FrameEventArgs args)
|
2020-01-09 00:27:52 +01:00
|
|
|
{
|
2021-03-26 17:10:31 -07:00
|
|
|
base.FrameUpdate(args);
|
2020-01-09 00:27:52 +01:00
|
|
|
|
|
|
|
|
if (!_parent._uiUpdateNeeded)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_parent._uiUpdateNeeded = false;
|
|
|
|
|
|
2021-03-16 15:50:20 +01:00
|
|
|
_label.SetMarkup(_parent.StatusShowBehavior ? _parent.Behavior.ToString() ?? string.Empty : string.Empty);
|
2020-01-09 00:27:52 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|