1
0

PointingSystem.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using Content.Client.Pointing.Components;
  2. using Content.Shared.Pointing;
  3. using Content.Shared.Verbs;
  4. using Robust.Client.GameObjects;
  5. using Robust.Shared.GameStates;
  6. using Robust.Shared.Utility;
  7. using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
  8. namespace Content.Client.Pointing;
  9. public sealed partial class PointingSystem : SharedPointingSystem
  10. {
  11. public override void Initialize()
  12. {
  13. base.Initialize();
  14. SubscribeLocalEvent<GetVerbsEvent<Verb>>(AddPointingVerb);
  15. SubscribeLocalEvent<PointingArrowComponent, ComponentStartup>(OnArrowStartup);
  16. SubscribeLocalEvent<RoguePointingArrowComponent, ComponentStartup>(OnRogueArrowStartup);
  17. SubscribeLocalEvent<PointingArrowComponent, ComponentHandleState>(HandleCompState);
  18. InitializeVisualizer();
  19. }
  20. private void AddPointingVerb(GetVerbsEvent<Verb> args)
  21. {
  22. if (IsClientSide(args.Target))
  23. return;
  24. // Really this could probably be a properly predicted event, but that requires reworking pointing. For now
  25. // I'm just adding this verb exclusively to clients so that the verb-loading pop-in on the verb menu isn't
  26. // as bad. Important for this verb seeing as its usually an option on just about any entity.
  27. // this is a pointing arrow. no pointing here...
  28. if (HasComp<PointingArrowComponent>(args.Target))
  29. return;
  30. if (!CanPoint(args.User))
  31. return;
  32. // We won't check in range or visibility, as this verb is currently only executable via the context menu,
  33. // and that should already have checked that, as well as handling the FOV-toggle stuff.
  34. Verb verb = new()
  35. {
  36. Text = Loc.GetString("pointing-verb-get-data-text"),
  37. Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/point.svg.192dpi.png")),
  38. ClientExclusive = true,
  39. Act = () => RaiseNetworkEvent(new PointingAttemptEvent(GetNetEntity(args.Target)))
  40. };
  41. args.Verbs.Add(verb);
  42. }
  43. private void OnArrowStartup(EntityUid uid, PointingArrowComponent component, ComponentStartup args)
  44. {
  45. if (TryComp<SpriteComponent>(uid, out var sprite))
  46. sprite.DrawDepth = (int) DrawDepth.Overlays;
  47. BeginPointAnimation(uid, component.StartPosition, component.Offset, component.AnimationKey);
  48. }
  49. private void OnRogueArrowStartup(EntityUid uid, RoguePointingArrowComponent arrow, ComponentStartup args)
  50. {
  51. if (TryComp<SpriteComponent>(uid, out var sprite))
  52. {
  53. sprite.DrawDepth = (int) DrawDepth.Overlays;
  54. sprite.NoRotation = false;
  55. }
  56. }
  57. private void HandleCompState(Entity<PointingArrowComponent> entity, ref ComponentHandleState args)
  58. {
  59. if (args.Current is not SharedPointingArrowComponentState state)
  60. return;
  61. entity.Comp.StartPosition = state.StartPosition;
  62. entity.Comp.EndTime = state.EndTime;
  63. }
  64. }