Move MultipleTool to shared (#9964)

This commit is contained in:
Leon Friedrich
2022-08-16 22:19:54 +12:00
committed by GitHub
parent 3c3a44ec49
commit cf8ad5f815
7 changed files with 188 additions and 186 deletions

View File

@@ -1,72 +1,50 @@
using Content.Client.Items.Components;
using Content.Client.Message;
using Content.Client.Stylesheets;
using Content.Shared.Tools.Components;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Timing;
using Robust.Shared.ViewVariables;
namespace Content.Client.Tools.Components
{
[RegisterComponent]
public sealed class MultipleToolComponent : SharedMultipleToolComponent, IItemStatus
[ComponentReference(typeof(SharedMultipleToolComponent))]
public sealed class MultipleToolComponent : SharedMultipleToolComponent
{
private string? _behavior;
[ViewVariables(VVAccess.ReadWrite)]
public bool UiUpdateNeeded;
[DataField("statusShowBehavior")]
private bool _statusShowBehavior = true;
public bool StatusShowBehavior = true;
}
[ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded;
[ViewVariables] public bool StatusShowBehavior => _statusShowBehavior;
[ViewVariables] public string? Behavior => _behavior;
public sealed class MultipleToolStatusControl : Control
{
private readonly MultipleToolComponent _parent;
private readonly RichTextLabel _label;
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
public MultipleToolStatusControl(MultipleToolComponent parent)
{
base.HandleComponentState(curState, nextState);
if (curState is not MultipleToolComponentState tool) return;
_behavior = tool.QualityName;
_uiUpdateNeeded = true;
_parent = parent;
_label = new RichTextLabel { StyleClasses = { StyleNano.StyleClassItemStatus } };
_label.SetMarkup(_parent.StatusShowBehavior ? _parent.CurrentQualityName : string.Empty);
AddChild(_label);
}
public Control MakeControl() => new StatusControl(this);
private sealed class StatusControl : Control
protected override void FrameUpdate(FrameEventArgs args)
{
private readonly MultipleToolComponent _parent;
private readonly RichTextLabel _label;
base.FrameUpdate(args);
public StatusControl(MultipleToolComponent parent)
if (_parent.UiUpdateNeeded)
{
_parent = parent;
_label = new RichTextLabel {StyleClasses = {StyleNano.StyleClassItemStatus}};
AddChild(_label);
UpdateDraw();
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (!_parent._uiUpdateNeeded)
{
return;
}
_parent.UiUpdateNeeded = false;
Update();
}
}
public void Update()
{
_parent._uiUpdateNeeded = false;
_label.SetMarkup(_parent.StatusShowBehavior ? _parent.Behavior ?? string.Empty : string.Empty);
}
public void Update()
{
_label.SetMarkup(_parent.StatusShowBehavior ? _parent.CurrentQualityName : string.Empty);
}
}
}