From 6a9d3576ecc2e232776de66d7eb549167d5847a9 Mon Sep 17 00:00:00 2001 From: Alkheemist Date: Mon, 20 Jan 2025 03:12:46 +1100 Subject: [PATCH 1/2] Add alt verb to toggle accents from clothing (#2648) * Add alt verb to toggle accents from clothing * Update Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs Co-authored-by: Dvir <39403717+dvir001@users.noreply.github.com> * Update Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs Co-authored-by: Dvir <39403717+dvir001@users.noreply.github.com> * Add toggling accents to AccentPickupSystem, and also fixed accent pickup system to trigger correctly * Edit comments * component datafield visibility edit * Adjust frontier comments Co-authored-by: Whatstone <166147148+whatston3@users.noreply.github.com> * add suggested changes to pickupevent * switched to using EntityUid.Invalid * changed namespace of pickupevent * missed an include, whoops * migrate AddAccentPickup under _NF (oops) * PickedUpEvent vs. GettingPickedUp, no Has then Rem --------- Co-authored-by: Dvir <39403717+dvir001@users.noreply.github.com> Co-authored-by: Whatstone <166147148+whatston3@users.noreply.github.com> Co-authored-by: Whatstone --- .../Components/AddAccentClothingComponent.cs | 5 ++ .../EntitySystems/AddAccentClothingSystem.cs | 52 ++++++++++++++++ .../Components/AddAccentPickupComponent.cs | 9 ++- .../EntitySystems/AddAccentPickupSystem.cs | 60 ++++++++++++++++--- .../EntitySystems/SharedHandsSystem.Pickup.cs | 2 + Content.Shared/_NF/Item/PickupEvent.cs | 16 +++++ Resources/Locale/en-US/_NF/accent/accents.ftl | 5 +- 7 files changed, 139 insertions(+), 10 deletions(-) rename Content.Server/{ => _NF}/Speech/Components/AddAccentPickupComponent.cs (78%) create mode 100644 Content.Shared/_NF/Item/PickupEvent.cs diff --git a/Content.Server/Speech/Components/AddAccentClothingComponent.cs b/Content.Server/Speech/Components/AddAccentClothingComponent.cs index 9d93b55368c..eb3679332e8 100644 --- a/Content.Server/Speech/Components/AddAccentClothingComponent.cs +++ b/Content.Server/Speech/Components/AddAccentClothingComponent.cs @@ -25,4 +25,9 @@ public sealed partial class AddAccentClothingComponent : Component /// Is that clothing is worn and affecting someones accent? /// public bool IsActive = false; + + /// + /// Who is currently wearing the item? + /// + public EntityUid Wearer; // Frontier } diff --git a/Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs b/Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs index 897cd061f42..96cb28d9e1e 100644 --- a/Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs +++ b/Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs @@ -1,5 +1,6 @@ using Content.Server.Speech.Components; using Content.Shared.Clothing; +using Content.Shared.Verbs; // Frontier namespace Content.Server.Speech.EntitySystems; @@ -12,6 +13,7 @@ public override void Initialize() base.Initialize(); SubscribeLocalEvent(OnGotEquipped); SubscribeLocalEvent(OnGotUnequipped); + SubscribeLocalEvent>(OnGetAltVerbs); // Frontier } private void OnGotEquipped(EntityUid uid, AddAccentClothingComponent component, ref ClothingGotEquippedEvent args) @@ -30,10 +32,12 @@ private void OnGotEquipped(EntityUid uid, AddAccentClothingComponent component, rep.Accent = component.ReplacementPrototype!; component.IsActive = true; + component.Wearer = args.Wearer; // Frontier } private void OnGotUnequipped(EntityUid uid, AddAccentClothingComponent component, ref ClothingGotUnequippedEvent args) { + component.Wearer = EntityUid.Invalid; // Frontier: prevent alt verb if (!component.IsActive) return; @@ -46,4 +50,52 @@ private void OnGotUnequipped(EntityUid uid, AddAccentClothingComponent component component.IsActive = false; } + + // Frontier: togglable accents + /// + /// Adds an alt verb allowing for the accent to be toggled easily. + /// + private void OnGetAltVerbs(EntityUid uid, AddAccentClothingComponent component, GetVerbsEvent args) + { + if (!args.CanInteract || args.User != component.Wearer) //only the wearer can toggle the effect + return; + + AlternativeVerb verb = new() + { + Text = Loc.GetString("accent-clothing-component-toggle"), + Act = () => ToggleAccent(uid, component) + }; + args.Verbs.Add(verb); + } + + private void ToggleAccent(EntityUid uid, AddAccentClothingComponent component) + { + if (component.IsActive) + { + // try to remove the accent if it's enabled + var componentType = _componentFactory.GetRegistration(component.Accent).Type; + RemComp(component.Wearer, componentType); + component.IsActive = false; + // we don't wipe out wearer in this case + } + else + { + // try to add the accent as if we are equipping this item again + // does the user already has this accent? + var componentType = _componentFactory.GetRegistration(component.Accent).Type; + if (HasComp(component.Wearer, componentType)) + return; + + // add accent to the user + var accentComponent = (Component)_componentFactory.GetComponent(componentType); + AddComp(component.Wearer, accentComponent); + + // snowflake case for replacement accent + if (accentComponent is ReplacementAccentComponent rep) + rep.Accent = component.ReplacementPrototype!; + + component.IsActive = true; + } + } + // End Frontier: togglable accents } diff --git a/Content.Server/Speech/Components/AddAccentPickupComponent.cs b/Content.Server/_NF/Speech/Components/AddAccentPickupComponent.cs similarity index 78% rename from Content.Server/Speech/Components/AddAccentPickupComponent.cs rename to Content.Server/_NF/Speech/Components/AddAccentPickupComponent.cs index 020deca65b1..93a52d6debb 100644 --- a/Content.Server/Speech/Components/AddAccentPickupComponent.cs +++ b/Content.Server/_NF/Speech/Components/AddAccentPickupComponent.cs @@ -4,7 +4,7 @@ namespace Content.Server._NF.Speech.Components; /// -/// Applies accent to user while they wear entity as a clothing. +/// Applies accent to user while they hold the entity. /// [RegisterComponent] public sealed partial class AddAccentPickupComponent : Component @@ -23,7 +23,12 @@ public sealed partial class AddAccentPickupComponent : Component public string? ReplacementPrototype; /// - /// Is that clothing is worn and affecting someones accent? + /// Is the entity held and affecting someones accent? /// public bool IsActive = false; + + /// + /// Who is currently holding the item? + /// + public EntityUid Holder; // Frontier } diff --git a/Content.Server/_NF/Speech/EntitySystems/AddAccentPickupSystem.cs b/Content.Server/_NF/Speech/EntitySystems/AddAccentPickupSystem.cs index fa71e1bfc3f..6401b0bccf8 100644 --- a/Content.Server/_NF/Speech/EntitySystems/AddAccentPickupSystem.cs +++ b/Content.Server/_NF/Speech/EntitySystems/AddAccentPickupSystem.cs @@ -1,7 +1,8 @@ using Content.Server._NF.Speech.Components; using Content.Server.Speech.Components; using Content.Shared.Interaction.Events; -using Content.Shared.Item; +using Content.Shared._NF.Item; +using Content.Shared.Verbs; namespace Content.Server._NF.Speech.EntitySystems; @@ -12,11 +13,12 @@ public sealed class AddAccentPickupSystem : EntitySystem public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(OnPickup); + SubscribeLocalEvent(OnPickup); SubscribeLocalEvent(OnDropped); + SubscribeLocalEvent>(OnGetAltVerbs); } - private void OnPickup(EntityUid uid, AddAccentPickupComponent component, ref GettingPickedUpAttemptEvent args) + private void OnPickup(EntityUid uid, AddAccentPickupComponent component, ref PickedUpEvent args) { // does the user already has this accent? var componentType = _componentFactory.GetRegistration(component.Accent).Type; @@ -24,7 +26,7 @@ private void OnPickup(EntityUid uid, AddAccentPickupComponent component, ref Get return; // add accent to the user - var accentComponent = (Component) _componentFactory.GetComponent(componentType); + var accentComponent = (Component)_componentFactory.GetComponent(componentType); AddComp(args.User, accentComponent); // snowflake case for replacement accent @@ -32,20 +34,64 @@ private void OnPickup(EntityUid uid, AddAccentPickupComponent component, ref Get rep.Accent = component.ReplacementPrototype!; component.IsActive = true; + component.Holder = args.User; } private void OnDropped(EntityUid uid, AddAccentPickupComponent component, DroppedEvent args) { + component.Holder = EntityUid.Invalid; // prevent alt verb if (!component.IsActive) return; // try to remove accent var componentType = _componentFactory.GetRegistration(component.Accent).Type; - if (EntityManager.HasComponent(args.User, componentType)) + RemComp(args.User, componentType); + + component.IsActive = false; + } + + /// + /// Adds an alt verb allowing for the accent to be toggled easily. + /// + private void OnGetAltVerbs(EntityUid uid, AddAccentPickupComponent component, GetVerbsEvent args) + { + if (!args.CanInteract || args.User != component.Holder) //only the holder can toggle the effect + return; + + AlternativeVerb verb = new() { - EntityManager.RemoveComponent(args.User, componentType); + Text = Loc.GetString("accent-clothing-component-toggle"), + Act = () => ToggleAccent(uid, component) + }; + args.Verbs.Add(verb); + } + + private void ToggleAccent(EntityUid uid, AddAccentPickupComponent component) + { + var componentType = _componentFactory.GetRegistration(component.Accent).Type; + if (component.IsActive) + { + // try to remove the accent if it's enabled + RemComp(component.Holder, componentType); + component.IsActive = false; + // we don't wipe out Holder in this case } + else + { + // try to add the accent as if we are equipping this item again + // does the user already has this accent? + if (HasComp(component.Holder, componentType)) + return; - component.IsActive = false; + // add accent to the user + var accentComponent = (Component)_componentFactory.GetComponent(componentType); + AddComp(component.Holder, accentComponent); + + // snowflake case for replacement accent + if (accentComponent is ReplacementAccentComponent rep) + rep.Accent = component.ReplacementPrototype!; + + component.IsActive = true; + } } } diff --git a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs index dea7081553e..845d2baff64 100644 --- a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs +++ b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs @@ -1,4 +1,5 @@ using Content.Shared._NF.LoggingExtensions; // Frontier +using Content.Shared._NF.Item; // Frontier using Content.Shared.Clothing.Components; using Content.Shared.Database; using Content.Shared.Hands.Components; @@ -235,6 +236,7 @@ public virtual void DoPickup(EntityUid uid, Hand hand, EntityUid entity, HandsCo Log.Error($"Failed to insert {ToPrettyString(entity)} into users hand container when picking up. User: {ToPrettyString(uid)}. Hand: {hand.Name}."); return; } + RaiseLocalEvent(entity, new PickedUpEvent(uid, entity), false); // Frontier if (log) { diff --git a/Content.Shared/_NF/Item/PickupEvent.cs b/Content.Shared/_NF/Item/PickupEvent.cs new file mode 100644 index 00000000000..4808e3e9d8a --- /dev/null +++ b/Content.Shared/_NF/Item/PickupEvent.cs @@ -0,0 +1,16 @@ +namespace Content.Shared._NF.Item; + +/// +/// Raised directed at entity being picked after someone picks it up sucessfully. +/// +public sealed class PickedUpEvent : EntityEventArgs +{ + public readonly EntityUid User; + public readonly EntityUid Item; + + public PickedUpEvent(EntityUid user, EntityUid item) + { + User = user; + Item = item; + } +} diff --git a/Resources/Locale/en-US/_NF/accent/accents.ftl b/Resources/Locale/en-US/_NF/accent/accents.ftl index 49941b4141a..8383381cc5a 100644 --- a/Resources/Locale/en-US/_NF/accent/accents.ftl +++ b/Resources/Locale/en-US/_NF/accent/accents.ftl @@ -31,4 +31,7 @@ accent-words-fox-2 = Yap! accent-words-fox-3 = Ruff! accent-words-fox-4 = Wraaah! accent-words-fox-5 = Aaaaagh! -accent-words-fox-6 = Screeee! \ No newline at end of file +accent-words-fox-6 = Screeee! + +# Accent Toggle +accent-clothing-component-toggle = Toggle Accent From 6ba285e1a1df3ce1373f24ebf95b546e2370ad69 Mon Sep 17 00:00:00 2001 From: FrontierATC Date: Sun, 19 Jan 2025 16:13:12 +0000 Subject: [PATCH 2/2] Automatic Changelog (#2648) --- Resources/Changelog/Frontier.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Resources/Changelog/Frontier.yml b/Resources/Changelog/Frontier.yml index 02bb48a35a8..db6216b1c26 100644 --- a/Resources/Changelog/Frontier.yml +++ b/Resources/Changelog/Frontier.yml @@ -6490,3 +6490,11 @@ Entries: message: Emergency lights should properly turn off when resetting to green state. id: 5669 time: '2025-01-19T11:42:46.0000000+00:00' +- author: Alkheemist + changes: + - type: Tweak + message: >- + Clothing and items that apply accents can be toggled with alt click, so + you can dress in style without worrying about intelligibility. + id: 5670 + time: '2025-01-19T16:12:47.0000000+00:00'