Move MultipleTool to shared (#9964)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,48 @@
|
||||
using Content.Client.Items;
|
||||
using Content.Client.Tools.Components;
|
||||
using Content.Shared.Tools;
|
||||
using Content.Shared.Tools.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Client.Tools
|
||||
{
|
||||
public sealed class ToolSystem : EntitySystem
|
||||
public sealed class ToolSystem : SharedToolSystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<WelderComponent, ComponentHandleState>(OnWelderHandleState);
|
||||
SubscribeLocalEvent<MultipleToolComponent, ItemStatusCollectMessage>(OnGetStatusMessage);
|
||||
}
|
||||
|
||||
public override void SetMultipleTool(EntityUid uid,
|
||||
SharedMultipleToolComponent? multiple = null,
|
||||
ToolComponent? tool = null,
|
||||
bool playSound = false,
|
||||
EntityUid? user = null)
|
||||
{
|
||||
if (!Resolve(uid, ref multiple))
|
||||
return;
|
||||
|
||||
base.SetMultipleTool(uid, multiple, tool, playSound, user);
|
||||
((MultipleToolComponent)multiple).UiUpdateNeeded = true;
|
||||
|
||||
// TODO replace this with appearance + visualizer
|
||||
// in order to convert this to a specifier, the manner in which the sprite is specified in yaml needs to be updated.
|
||||
|
||||
if (multiple.Entries.Length > multiple.CurrentEntry && TryComp(uid, out SpriteComponent? sprite))
|
||||
{
|
||||
var current = multiple.Entries[multiple.CurrentEntry];
|
||||
if (current.Sprite != null)
|
||||
sprite.LayerSetSprite(0, current.Sprite);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGetStatusMessage(EntityUid uid, MultipleToolComponent welder, ItemStatusCollectMessage args)
|
||||
{
|
||||
args.Controls.Add(new MultipleToolStatusControl(welder));
|
||||
}
|
||||
|
||||
private void OnWelderHandleState(EntityUid uid, WelderComponent welder, ref ComponentHandleState args)
|
||||
|
||||
Reference in New Issue
Block a user