using Robust.Shared.Audio; using Robust.Shared.GameStates; namespace Content.Shared.Item.ItemToggle.Components; /// /// Handles generic item toggles, like a welder turning on and off, or an e-sword. /// /// /// If you need extended functionality (e.g. requiring power) then add a new component and use events: /// ItemToggleActivateAttemptEvent, ItemToggleDeactivateAttemptEvent, ItemToggledEvent. /// [RegisterComponent, NetworkedComponent, AutoGenerateComponentState] public sealed partial class ItemToggleComponent : Component { /// /// The item's toggle state. /// [DataField, AutoNetworkedField] public bool Activated = false; /// /// Can the entity be activated in the world. /// [DataField] public bool OnActivate = true; /// /// If this is set to false then the item can't be toggled by pressing Z. /// Use another system to do it then. /// [DataField] public bool OnUse = true; /// /// The localized text to display in the verb to activate. /// [DataField] public string VerbToggleOn = "item-toggle-activate"; /// /// The localized text to display in the verb to de-activate. /// [DataField] public string VerbToggleOff = "item-toggle-deactivate"; /// /// Whether the item's toggle can be predicted by the client. /// /// /// /// If server-side systems affect the item's toggle, like charge/fuel systems, then the item is not predictable. /// [ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField] public bool Predictable = true; /// /// The noise this item makes when it is toggled on. /// [ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField] public SoundSpecifier? SoundActivate; /// /// The noise this item makes when it is toggled off. /// [ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField] public SoundSpecifier? SoundDeactivate; /// /// The noise this item makes when it is toggled on. /// [ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField] public SoundSpecifier? SoundFailToActivate; } /// /// Raised directed on an entity when its ItemToggle is attempted to be activated. /// [ByRefEvent] public record struct ItemToggleActivateAttemptEvent(EntityUid? User) { public bool Cancelled = false; public readonly EntityUid? User = User; /// /// Pop-up that gets shown to users explaining why the attempt was cancelled. /// public string? Popup { get; set; } } /// /// Raised directed on an entity when its ItemToggle is attempted to be deactivated. /// [ByRefEvent] public record struct ItemToggleDeactivateAttemptEvent(EntityUid? User) { public bool Cancelled = false; public readonly EntityUid? User = User; } /// /// Raised directed on an entity any sort of toggle is complete. /// [ByRefEvent] public readonly record struct ItemToggledEvent(bool Predicted, bool Activated, EntityUid? User) { public readonly bool Predicted = Predicted; public readonly bool Activated = Activated; public readonly EntityUid? User = User; }