CatStation/Content.Client/Pointing/PointingSystem.cs
Evаn Summers c1b3a6ab0e
Pointing at inventory items with mouse binding (#43747)
* Pointing at inventory items with mouse binding

* Make it work for items in containers too

* Deduplicate

* documentation and minor change

* more documentation

* caes switch

---------

Co-authored-by: Tayrtahn <tayrtahn@gmail.com>
Co-authored-by: jessicamaybe <jessica@jessicamaybe.com>
2026-07-01 06:40:02 +00:00

91 lines
3.2 KiB
C#

using Content.Client.Pointing.Components;
using Content.Shared.Pointing;
using Content.Shared.Verbs;
using Robust.Client.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Utility;
using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
namespace Content.Client.Pointing;
public sealed partial class PointingSystem
{
[Dependency] private SpriteSystem _sprite = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<GetVerbsEvent<Verb>>(AddPointingVerb);
SubscribeLocalEvent<PointingArrowComponent, ComponentStartup>(OnArrowStartup);
SubscribeLocalEvent<RoguePointingArrowComponent, ComponentStartup>(OnRogueArrowStartup);
SubscribeLocalEvent<PointingArrowComponent, ComponentHandleState>(HandleCompState);
InitializeVisualizer();
}
private void AddPointingVerb(GetVerbsEvent<Verb> args)
{
if (IsClientSide(args.Target))
return;
// Really this could probably be a properly predicted event, but that requires reworking pointing. For now
// I'm just adding this verb exclusively to clients so that the verb-loading pop-in on the verb menu isn't
// as bad. Important for this verb seeing as its usually an option on just about any entity.
// this is a pointing arrow. no pointing here...
if (HasComp<PointingArrowComponent>(args.Target))
return;
if (!CanPoint(args.User))
return;
// We won't check in range or visibility, as this verb is currently only executable via the context menu,
// and that should already have checked that, as well as handling the FOV-toggle stuff.
Verb verb = new()
{
Text = Loc.GetString("pointing-verb-get-data-text"),
Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/point.svg.192dpi.png")),
ClientExclusive = true,
Act = () => TryPointAtEntity(GetNetEntity(args.Target))
};
args.Verbs.Add(verb);
}
/// <summary>
/// Tries to point at a target entity
/// </summary>
/// <param name="target">The target to point at</param>
public void TryPointAtEntity(NetEntity target)
{
RaiseNetworkEvent(new PointingAttemptEvent(target));
}
private void OnArrowStartup(EntityUid uid, PointingArrowComponent component, ComponentStartup args)
{
if (TryComp<SpriteComponent>(uid, out var sprite))
_sprite.SetDrawDepth((uid, sprite), (int)DrawDepth.Overlays);
BeginPointAnimation(uid, component.StartPosition, component.Offset, component.AnimationKey);
}
private void OnRogueArrowStartup(EntityUid uid, RoguePointingArrowComponent arrow, ComponentStartup args)
{
if (TryComp<SpriteComponent>(uid, out var sprite))
{
_sprite.SetDrawDepth((uid, sprite), (int)DrawDepth.Overlays);
sprite.NoRotation = false;
}
}
private void HandleCompState(Entity<PointingArrowComponent> entity, ref ComponentHandleState args)
{
if (args.Current is not SharedPointingArrowComponentState state)
return;
entity.Comp.StartPosition = state.StartPosition;
entity.Comp.EndTime = state.EndTime;
}
}