mirror of
https://github.com/wega-team/ss14-wega.git
synced 2026-02-15 03:31:44 +01:00
77 lines
2.8 KiB
C#
77 lines
2.8 KiB
C#
using Content.Client.Items;
|
|
using Content.Client.Message;
|
|
using Content.Client.Stylesheets;
|
|
using Content.Shared.Charges.Components;
|
|
using Content.Shared.Charges.Systems;
|
|
using Content.Shared.Crayon;
|
|
using Content.Shared.Hands;
|
|
using Robust.Client.GameObjects; // Corvax-Wega-Add
|
|
using Robust.Client.Graphics; // Corvax-Wega-Add
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Client.Crayon;
|
|
|
|
public sealed class CrayonSystem : SharedCrayonSystem
|
|
{
|
|
[Dependency] private readonly SharedChargesSystem _charges = default!;
|
|
[Dependency] private readonly EntityManager _entityManager = default!;
|
|
[Dependency] private readonly IOverlayManager _overlay = default!; // Corvax-Wega-Add
|
|
[Dependency] private readonly SpriteSystem _sprite = default!; // Corvax-Wega-Add
|
|
|
|
private CrayonPreviewOverlay? _previewOverlay; // Corvax-Wega-Add
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
Subs.ItemStatus<CrayonComponent>(ent => new StatusControl(ent, _charges, _entityManager));
|
|
SubscribeLocalEvent<CrayonComponent, HandSelectedEvent>(OnCrayonSelected);
|
|
SubscribeLocalEvent<CrayonComponent, HandDeselectedEvent>(OnCrayonDeselected);
|
|
}
|
|
|
|
private void OnCrayonSelected(EntityUid uid, CrayonComponent component, HandSelectedEvent args)
|
|
{
|
|
_previewOverlay ??= new CrayonPreviewOverlay(_sprite);
|
|
_overlay.AddOverlay(_previewOverlay);
|
|
}
|
|
|
|
private void OnCrayonDeselected(EntityUid uid, CrayonComponent component, HandDeselectedEvent args)
|
|
{
|
|
if (_previewOverlay != null)
|
|
{
|
|
_overlay.RemoveOverlay(_previewOverlay);
|
|
_previewOverlay = null;
|
|
}
|
|
}
|
|
|
|
private sealed class StatusControl : Control
|
|
{
|
|
private readonly Entity<CrayonComponent> _crayon;
|
|
private readonly SharedChargesSystem _charges;
|
|
private readonly RichTextLabel _label;
|
|
private readonly int _capacity;
|
|
|
|
public StatusControl(Entity<CrayonComponent> crayon, SharedChargesSystem charges, EntityManager entityManager)
|
|
{
|
|
_crayon = crayon;
|
|
_charges = charges;
|
|
_capacity = entityManager.GetComponent<LimitedChargesComponent>(_crayon.Owner).MaxCharges;
|
|
_label = new RichTextLabel { StyleClasses = { StyleClass.ItemStatus } };
|
|
AddChild(_label);
|
|
}
|
|
|
|
protected override void FrameUpdate(FrameEventArgs args)
|
|
{
|
|
base.FrameUpdate(args);
|
|
|
|
_label.SetMarkup(Robust.Shared.Localization.Loc.GetString("crayon-drawing-label",
|
|
("color", _crayon.Comp.Color),
|
|
("state", _crayon.Comp.SelectedState),
|
|
("charges", _charges.GetCurrentCharges(_crayon.Owner)),
|
|
("capacity", _capacity)));
|
|
}
|
|
}
|
|
}
|