From 1c55904cd272acc98cf301b8d2053227434bf2d6 Mon Sep 17 00:00:00 2001 From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Date: Thu, 6 Apr 2023 15:49:27 -0700 Subject: [PATCH] Add Alt-click insertion to ItemSlots (#15094) --- .../Containers/ItemSlot/ItemSlotsSystem.cs | 53 ++++++++++++++++++- .../Objects/Specific/Janitorial/janitor.yml | 2 + 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/Content.Shared/Containers/ItemSlot/ItemSlotsSystem.cs b/Content.Shared/Containers/ItemSlot/ItemSlotsSystem.cs index 4af573425a..f04c4f4b84 100644 --- a/Content.Shared/Containers/ItemSlot/ItemSlotsSystem.cs +++ b/Content.Shared/Containers/ItemSlot/ItemSlotsSystem.cs @@ -43,7 +43,7 @@ namespace Content.Shared.Containers.ItemSlots SubscribeLocalEvent(OnInteractHand); SubscribeLocalEvent(OnUseInHand); - SubscribeLocalEvent>(AddEjectVerbs); + SubscribeLocalEvent>(AddAlternativeVerbs); SubscribeLocalEvent>(AddInteractionVerbsVerbs); SubscribeLocalEvent(OnBreak); @@ -405,13 +405,62 @@ namespace Content.Shared.Containers.ItemSlots #endregion #region Verbs - private void AddEjectVerbs(EntityUid uid, ItemSlotsComponent itemSlots, GetVerbsEvent args) + private void AddAlternativeVerbs(EntityUid uid, ItemSlotsComponent itemSlots, GetVerbsEvent args) { if (args.Hands == null || !args.CanAccess ||!args.CanInteract) { return; } + // Add the insert-item verbs + if (args.Using != null && _actionBlockerSystem.CanDrop(args.User)) + { + var canInsertAny = false; + foreach (var slot in itemSlots.Slots.Values) + { + // Disable slot insert if InsertOnInteract is true + if (slot.InsertOnInteract || !CanInsert(uid, args.Using.Value, slot)) + continue; + + var verbSubject = slot.Name != string.Empty + ? Loc.GetString(slot.Name) + : Name(args.Using.Value) ?? string.Empty; + + AlternativeVerb verb = new(); + verb.IconEntity = args.Using; + verb.Act = () => Insert(uid, slot, args.Using.Value, args.User, excludeUserAudio: true); + + if (slot.InsertVerbText != null) + { + verb.Text = Loc.GetString(slot.InsertVerbText); + verb.Icon = new SpriteSpecifier.Texture( + new ResourcePath("/Textures/Interface/VerbIcons/insert.svg.192dpi.png")); + } + else if (slot.EjectOnInteract) + { + // Inserting/ejecting is a primary interaction for this entity. Instead of using the insert + // category, we will use a single "Place " verb. + verb.Text = Loc.GetString("place-item-verb-text", ("subject", verbSubject)); + verb.Icon = new SpriteSpecifier.Texture( + new ResourcePath("/Textures/Interface/VerbIcons/drop.svg.192dpi.png")); + } + else + { + verb.Category = VerbCategory.Insert; + verb.Text = verbSubject; + } + + verb.Priority = slot.Priority; + args.Verbs.Add(verb); + canInsertAny = true; + } + + // If can insert then insert. Don't run eject verbs. + if (canInsertAny) + return; + } + + // Add the eject-item verbs foreach (var slot in itemSlots.Slots.Values) { if (slot.EjectOnInteract) diff --git a/Resources/Prototypes/Entities/Objects/Specific/Janitorial/janitor.yml b/Resources/Prototypes/Entities/Objects/Specific/Janitorial/janitor.yml index bc2bd24b95..7595028cb0 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/Janitorial/janitor.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/Janitorial/janitor.yml @@ -165,11 +165,13 @@ tags: - Mop insertOnInteract: false # or it conflicts with bucket logic + priority: 4 # Higher than trash bag slot trashbag_slot: name: Bag whitelist: tags: - TrashBag + priority: 3 # Higher than drinking priority - type: Fixtures fixtures: - shape: -- 2.51.2