ItemToggleComponent.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using Robust.Shared.Audio;
  2. using Robust.Shared.GameStates;
  3. namespace Content.Shared.Item.ItemToggle.Components;
  4. /// <summary>
  5. /// Handles generic item toggles, like a welder turning on and off, or an e-sword.
  6. /// </summary>
  7. /// <remarks>
  8. /// If you need extended functionality (e.g. requiring power) then add a new component and use events:
  9. /// ItemToggleActivateAttemptEvent, ItemToggleDeactivateAttemptEvent, ItemToggledEvent.
  10. /// </remarks>
  11. [RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
  12. public sealed partial class ItemToggleComponent : Component
  13. {
  14. /// <summary>
  15. /// The item's toggle state.
  16. /// </summary>
  17. [DataField, AutoNetworkedField]
  18. public bool Activated = false;
  19. /// <summary>
  20. /// Can the entity be activated in the world.
  21. /// </summary>
  22. [DataField]
  23. public bool OnActivate = true;
  24. /// <summary>
  25. /// If this is set to false then the item can't be toggled by pressing Z.
  26. /// Use another system to do it then.
  27. /// </summary>
  28. [DataField]
  29. public bool OnUse = true;
  30. /// <summary>
  31. /// The localized text to display in the verb to activate.
  32. /// </summary>
  33. [DataField]
  34. public string VerbToggleOn = "item-toggle-activate";
  35. /// <summary>
  36. /// The localized text to display in the verb to de-activate.
  37. /// </summary>
  38. [DataField]
  39. public string VerbToggleOff = "item-toggle-deactivate";
  40. /// <summary>
  41. /// Whether the item's toggle can be predicted by the client.
  42. /// </summary>
  43. /// /// <remarks>
  44. /// If server-side systems affect the item's toggle, like charge/fuel systems, then the item is not predictable.
  45. /// </remarks>
  46. [ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
  47. public bool Predictable = true;
  48. /// <summary>
  49. /// The noise this item makes when it is toggled on.
  50. /// </summary>
  51. [ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
  52. public SoundSpecifier? SoundActivate;
  53. /// <summary>
  54. /// The noise this item makes when it is toggled off.
  55. /// </summary>
  56. [ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
  57. public SoundSpecifier? SoundDeactivate;
  58. /// <summary>
  59. /// The noise this item makes when it is toggled on.
  60. /// </summary>
  61. [ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
  62. public SoundSpecifier? SoundFailToActivate;
  63. }
  64. /// <summary>
  65. /// Raised directed on an entity when its ItemToggle is attempted to be activated.
  66. /// </summary>
  67. [ByRefEvent]
  68. public record struct ItemToggleActivateAttemptEvent(EntityUid? User)
  69. {
  70. public bool Cancelled = false;
  71. public readonly EntityUid? User = User;
  72. /// <summary>
  73. /// Pop-up that gets shown to users explaining why the attempt was cancelled.
  74. /// </summary>
  75. public string? Popup { get; set; }
  76. }
  77. /// <summary>
  78. /// Raised directed on an entity when its ItemToggle is attempted to be deactivated.
  79. /// </summary>
  80. [ByRefEvent]
  81. public record struct ItemToggleDeactivateAttemptEvent(EntityUid? User)
  82. {
  83. public bool Cancelled = false;
  84. public readonly EntityUid? User = User;
  85. }
  86. /// <summary>
  87. /// Raised directed on an entity any sort of toggle is complete.
  88. /// </summary>
  89. [ByRefEvent]
  90. public readonly record struct ItemToggledEvent(bool Predicted, bool Activated, EntityUid? User)
  91. {
  92. public readonly bool Predicted = Predicted;
  93. public readonly bool Activated = Activated;
  94. public readonly EntityUid? User = User;
  95. }