weed eater (#297)

This commit is contained in:
RedFoxIV
2025-03-08 22:20:19 +03:00
committed by GitHub
parent a9b9224ca1
commit 5a69c4e660
3 changed files with 50 additions and 59 deletions

View File

@@ -33,12 +33,13 @@ public sealed class CrayonSystem : SharedCrayonSystem
base.Initialize();
// SubscribeLocalEvent<CrayonComponent, ComponentHandleState>(OnCrayonHandleState); // WWDP EDIT - DEFUNCT - Moved to using AutoState system.
Subs.ItemStatus<CrayonComponent>(ent => new StatusControl(ent));
// WWDP EDIT START
// WWDP EDIT START
_overlay.AddOverlay(new CrayonPreviewOverlay(_sprite, _hands));
SubscribeLocalEvent<CrayonComponent, AfterAutoHandleStateEvent>(CrayonAfterAutoState);
SubscribeLocalEvent<CrayonComponent, AfterInteractEvent>(CrayonAfterInteract);
SubscribeLocalEvent<CrayonComponent, ComponentRemove>(CrayonRemoved);
SubscribeLocalEvent<CrayonComponent, EntityTerminatingEvent>(CrayonEntRemoved);
//SubscribeLocalEvent<CrayonComponent, ComponentRemove>(CrayonRemoved);
//SubscribeLocalEvent<CrayonComponent, EntityTerminatingEvent>(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<CrayonPreviewOverlay>();
}
private void CrayonEntRemoved(EntityUid uid, CrayonComponent comp, EntityTerminatingEvent args)
{
if (_player.LocalEntity is not EntityUid player ||
uid != _hands.GetActiveItem(player))
return;
_overlay.RemoveOverlay<CrayonPreviewOverlay>();
}
// 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<CrayonPreviewOverlay>();
//}
//
//private void CrayonEntRemoved(EntityUid uid, CrayonComponent comp, EntityTerminatingEvent args)
//{
// if (_player.LocalEntity is not EntityUid player ||
// uid != _hands.GetActiveItem(player))
// return;
// _overlay.RemoveOverlay<CrayonPreviewOverlay>();
//}
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<CrayonPreviewOverlay>(); // 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<CrayonPreviewOverlay>();
}
//protected override void OnCrayonHandSelected(EntityUid uid, CrayonComponent component, HandSelectedEvent args) // WWDP EDIT
//{
// base.OnCrayonHandSelected(uid, component, args);
// _overlay.RemoveOverlay<CrayonPreviewOverlay>(); // 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<CrayonPreviewOverlay>();
//}
// WWDP EDIT END
private sealed class StatusControl : Control

View File

@@ -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<DecalPrototype>(_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<CrayonComponent>(_hands.GetActiveItem(playerUid), out var crayon) ||
_entMan.HasComponent<HoldingDropComponent>(playerUid))
return;
var handle = args.WorldHandle;
if (_currentState != _crayonComp.SelectedState)
{
_currentState = _crayonComp.SelectedState;
if (_proto.TryIndex<DecalPrototype>(_currentState, out var proto))
_tex = _sprite.Frame0(proto.Sprite);
else
_tex = Texture.Transparent;
}
Texture tex;
if (_proto.TryIndex<DecalPrototype>(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<TransformComponent>(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
}
}

View File

@@ -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);
}
}