| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- using Content.Client.Items;
- using Content.Client.Message;
- using Content.Client.Stylesheets;
- using Content.Shared.Crayon;
- using Robust.Client.UserInterface;
- using Robust.Client.UserInterface.Controls;
- using Robust.Shared.GameObjects;
- using Robust.Shared.GameStates;
- using Robust.Shared.Localization;
- using Robust.Shared.Timing;
- namespace Content.Client.Crayon;
- public sealed class CrayonSystem : SharedCrayonSystem
- {
- // Didn't do in shared because I don't think most of the server stuff can be predicted.
- public override void Initialize()
- {
- base.Initialize();
- SubscribeLocalEvent<CrayonComponent, ComponentHandleState>(OnCrayonHandleState);
- Subs.ItemStatus<CrayonComponent>(ent => new StatusControl(ent));
- }
- private static void OnCrayonHandleState(EntityUid uid, CrayonComponent component, ref ComponentHandleState args)
- {
- if (args.Current is not CrayonComponentState state) return;
- component.Color = state.Color;
- component.SelectedState = state.State;
- component.Charges = state.Charges;
- component.Capacity = state.Capacity;
- component.UIUpdateNeeded = true;
- }
- private sealed class StatusControl : Control
- {
- private readonly CrayonComponent _parent;
- private readonly RichTextLabel _label;
- public StatusControl(CrayonComponent parent)
- {
- _parent = parent;
- _label = new RichTextLabel { StyleClasses = { StyleNano.StyleClassItemStatus } };
- AddChild(_label);
- parent.UIUpdateNeeded = true;
- }
- protected override void FrameUpdate(FrameEventArgs args)
- {
- base.FrameUpdate(args);
- if (!_parent.UIUpdateNeeded)
- {
- return;
- }
- _parent.UIUpdateNeeded = false;
- _label.SetMarkup(Robust.Shared.Localization.Loc.GetString("crayon-drawing-label",
- ("color",_parent.Color),
- ("state",_parent.SelectedState),
- ("charges", _parent.Charges),
- ("capacity",_parent.Capacity)));
- }
- }
- }
|