From 5a69c4e660a128f06a51a4b87ac467afe1cc8d2e Mon Sep 17 00:00:00 2001 From: RedFoxIV <38788538+RedFoxIV@users.noreply.github.com> Date: Sat, 8 Mar 2025 22:20:19 +0300 Subject: [PATCH] weed eater (#297) --- Content.Client/Crayon/CrayonSystem.cs | 66 ++++++++++--------- .../_White/Overlays/CrayonPreviewOverlay.cs | 41 ++++-------- Content.Server/Crayon/CrayonSystem.cs | 2 +- 3 files changed, 50 insertions(+), 59 deletions(-) diff --git a/Content.Client/Crayon/CrayonSystem.cs b/Content.Client/Crayon/CrayonSystem.cs index 5555b67e9c..8e025924fc 100644 --- a/Content.Client/Crayon/CrayonSystem.cs +++ b/Content.Client/Crayon/CrayonSystem.cs @@ -33,12 +33,13 @@ public sealed class CrayonSystem : SharedCrayonSystem base.Initialize(); // SubscribeLocalEvent(OnCrayonHandleState); // WWDP EDIT - DEFUNCT - Moved to using AutoState system. Subs.ItemStatus(ent => new StatusControl(ent)); - - // WWDP EDIT START + + // WWDP EDIT START + _overlay.AddOverlay(new CrayonPreviewOverlay(_sprite, _hands)); SubscribeLocalEvent(CrayonAfterAutoState); SubscribeLocalEvent(CrayonAfterInteract); - SubscribeLocalEvent(CrayonRemoved); - SubscribeLocalEvent(CrayonEntRemoved); + //SubscribeLocalEvent(CrayonRemoved); + //SubscribeLocalEvent(CrayonEntRemoved); // WWDP EDIT END } @@ -49,39 +50,42 @@ public sealed class CrayonSystem : SharedCrayonSystem _ui.CloseUi(uid, CrayonComponent.CrayonUiKey.Key, args.User); } - private void CrayonRemoved(EntityUid uid, CrayonComponent comp, ComponentRemove args) - { - if (_player.LocalEntity is not EntityUid player || - uid != _hands.GetActiveItem(player)) - return; - _overlay.RemoveOverlay(); - } - - private void CrayonEntRemoved(EntityUid uid, CrayonComponent comp, EntityTerminatingEvent args) - { - if (_player.LocalEntity is not EntityUid player || - uid != _hands.GetActiveItem(player)) - return; - _overlay.RemoveOverlay(); - } + // Some interactions involve removing an item from active hand without raising HandDeselectedEvent on the item first. + // I do not want to hunt down all the possible instances of this behaviour, so i am plugging the hole by making the + // overlay always on. + //private void CrayonRemoved(EntityUid uid, CrayonComponent comp, ComponentRemove args) + //{ + // if (_player.LocalEntity is not EntityUid player || + // uid != _hands.GetActiveItem(player)) + // return; + // _overlay.RemoveOverlay(); + //} + // + //private void CrayonEntRemoved(EntityUid uid, CrayonComponent comp, EntityTerminatingEvent args) + //{ + // if (_player.LocalEntity is not EntityUid player || + // uid != _hands.GetActiveItem(player)) + // return; + // _overlay.RemoveOverlay(); + //} private void CrayonAfterAutoState(EntityUid uid, CrayonComponent comp, AfterAutoHandleStateEvent args) { comp.UIUpdateNeeded = true; } - protected override void OnCrayonHandSelected(EntityUid uid, CrayonComponent component, HandSelectedEvent args) // WWDP EDIT - { - base.OnCrayonHandSelected(uid, component, args); - _overlay.RemoveOverlay(); // if i still fucked up somewhere and did not remove the event when i should've, this will catch it. - _overlay.AddOverlay(new CrayonPreviewOverlay(_sprite, component)); - } - - protected override void OnCrayonHandDeselected(EntityUid uid, CrayonComponent component, HandDeselectedEvent args) // WWDP EDIT - { - base.OnCrayonHandDeselected(uid, component, args); - _overlay.RemoveOverlay(); - } + //protected override void OnCrayonHandSelected(EntityUid uid, CrayonComponent component, HandSelectedEvent args) // WWDP EDIT + //{ + // base.OnCrayonHandSelected(uid, component, args); + // _overlay.RemoveOverlay(); // if i still fucked up somewhere and did not remove the event when i should've, this will catch it. + // _overlay.AddOverlay(new CrayonPreviewOverlay(_sprite, component)); + //} + // + //protected override void OnCrayonHandDeselected(EntityUid uid, CrayonComponent component, HandDeselectedEvent args) // WWDP EDIT + //{ + // base.OnCrayonHandDeselected(uid, component, args); + // _overlay.RemoveOverlay(); + //} // WWDP EDIT END private sealed class StatusControl : Control diff --git a/Content.Client/_White/Overlays/CrayonPreviewOverlay.cs b/Content.Client/_White/Overlays/CrayonPreviewOverlay.cs index e50d2c5d48..69af8fd2ec 100644 --- a/Content.Client/_White/Overlays/CrayonPreviewOverlay.cs +++ b/Content.Client/_White/Overlays/CrayonPreviewOverlay.cs @@ -1,4 +1,5 @@ using Content.Client.Crayon; +using Content.Client.Hands.Systems; using Content.Shared._White.Hands.Components; using Content.Shared.Crayon; using Content.Shared.Decals; @@ -23,58 +24,44 @@ public sealed class CrayonPreviewOverlay : Overlay [Dependency] private readonly IEntityManager _entMan = default!; [Dependency] private readonly IPrototypeManager _proto = default!; - private readonly CrayonComponent _crayonComp; - private readonly EntityUid _crayonUid; - private string _currentState; - - private Texture _tex; + private readonly HandsSystem _hands; private readonly SpriteSystem _sprite; - public CrayonPreviewOverlay(SpriteSystem sprite, CrayonComponent comp) + public CrayonPreviewOverlay(SpriteSystem sprite, HandsSystem hands) { IoCManager.InjectDependencies(this); _sprite = sprite; - - _crayonComp = comp; - _crayonUid = comp.Owner; - _currentState = comp.SelectedState; - if (_proto.TryIndex(_currentState, out var proto)) - _tex = _sprite.Frame0(proto.Sprite); - else - _tex = Texture.Transparent; + _hands = hands; } protected override void Draw(in OverlayDrawArgs args) { - if (!_entMan.EntityExists(_crayonUid) || // failsafe - _player.LocalEntity is not EntityUid playerUid || + if (_player.LocalEntity is not EntityUid playerUid || + !_entMan.TryGetComponent(_hands.GetActiveItem(playerUid), out var crayon) || _entMan.HasComponent(playerUid)) return; var handle = args.WorldHandle; - if (_currentState != _crayonComp.SelectedState) - { - _currentState = _crayonComp.SelectedState; - if (_proto.TryIndex(_currentState, out var proto)) - _tex = _sprite.Frame0(proto.Sprite); - else - _tex = Texture.Transparent; - } + Texture tex; + if (_proto.TryIndex(crayon.SelectedState, out var proto)) + tex = _sprite.Frame0(proto.Sprite); + else + tex = Texture.Transparent; var mouseScreenPos = _input.MouseScreenPosition.Position; - var angle = _crayonComp.Angle - _eye.CurrentEye.Rotation; + var angle = crayon.Angle - _eye.CurrentEye.Rotation; var mouseMapPos = _eye.ScreenToMap(mouseScreenPos); var playerMapPos = _entMan.GetComponent(playerUid).MapPosition; float alpha = 0.6f; if ((mouseMapPos.Position - playerMapPos.Position).LengthSquared() > SharedInteractionSystem.InteractionRangeSquared) - alpha = 0.1f; + alpha = 0.15f; #pragma warning disable RA0002 // ffs - handle.DrawTexture(_tex, mouseMapPos.Position - new Vector2(0.5f, 0.5f), angle, _crayonComp.Color.WithAlpha(alpha)); + handle.DrawTexture(tex, mouseMapPos.Position - new Vector2(0.5f, 0.5f), angle, crayon.Color.WithAlpha(alpha)); #pragma warning restore RA0002 } } diff --git a/Content.Server/Crayon/CrayonSystem.cs b/Content.Server/Crayon/CrayonSystem.cs index 6cda725ca3..073aa74224 100644 --- a/Content.Server/Crayon/CrayonSystem.cs +++ b/Content.Server/Crayon/CrayonSystem.cs @@ -133,7 +133,7 @@ public sealed class CrayonSystem : SharedCrayonSystem private void UseUpCrayon(EntityUid uid, EntityUid user) { - _popup.PopupEntity(Loc.GetString("crayon-interact-used-up-text", ("owner", uid)), user, user); + _popup.PopupEntity(Loc.GetString("crayon-interact-used-up-text", ("owner", user)), user, user); // WWDP EDIT EntityManager.QueueDeleteEntity(uid); } }