2021-06-09 22:19:39 +02:00
|
|
|
using Content.Client.Items.Components;
|
|
|
|
|
using Content.Client.Message;
|
|
|
|
|
using Content.Client.Stylesheets;
|
2021-10-07 13:01:27 +02:00
|
|
|
using Content.Shared.Tools.Components;
|
2020-01-09 00:27:52 +01:00
|
|
|
using Robust.Client.UserInterface;
|
|
|
|
|
using Robust.Client.UserInterface.Controls;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-07-12 01:32:10 -07:00
|
|
|
using Robust.Shared.GameStates;
|
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;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.Tools.Components
|
2020-01-09 00:27:52 +01:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
2021-10-07 13:01:27 +02:00
|
|
|
public class MultipleToolComponent : SharedMultipleToolComponent, IItemStatus
|
2020-01-09 00:27:52 +01:00
|
|
|
{
|
2021-10-07 13:01:27 +02:00
|
|
|
private string? _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-10-07 13:01:27 +02:00
|
|
|
[ViewVariables] public string? Behavior => _behavior;
|
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);
|
|
|
|
|
|
2021-10-07 13:01:27 +02:00
|
|
|
if (curState is not MultipleToolComponentState tool) return;
|
2020-01-09 00:27:52 +01:00
|
|
|
|
2021-10-07 13:01:27 +02:00
|
|
|
_behavior = tool.QualityName;
|
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
|
|
|
|
|
{
|
2021-10-07 13:01:27 +02:00
|
|
|
private readonly MultipleToolComponent _parent;
|
2020-01-09 00:27:52 +01:00
|
|
|
private readonly RichTextLabel _label;
|
|
|
|
|
|
2021-10-07 13:01:27 +02:00
|
|
|
public StatusControl(MultipleToolComponent 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-10-07 13:01:27 +02:00
|
|
|
_label.SetMarkup(_parent.StatusShowBehavior ? _parent.Behavior ?? string.Empty : string.Empty);
|
2020-01-09 00:27:52 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|