]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
keybinds for opening bag/belt & context logic for opening storage window (#22238)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Fri, 8 Dec 2023 18:43:37 +0000 (13:43 -0500)
committerGitHub <noreply@github.com>
Fri, 8 Dec 2023 18:43:37 +0000 (12:43 -0600)
* keybinds for opening bag/belt & context logic for opening storage window

* no error por favor

Content.Client/Input/ContentContexts.cs
Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs
Content.Client/Storage/StorageBoundUserInterface.cs
Content.Client/Storage/Systems/StorageSystem.cs
Content.Client/UserInterface/Systems/Storage/Controls/StorageContainer.cs
Content.Server/Storage/EntitySystems/StorageSystem.cs
Content.Shared/Input/ContentKeyFunctions.cs
Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs
Content.Shared/Storage/StorageComponent.cs
Resources/Locale/en-US/escape-menu/ui/options-menu.ftl
Resources/keybinds.yml

index 82388cb75b3cc0b48d7fb4d9666fe862fafd25b4..03f4f3f38b7e34d4af20a73c993e508392feebc3 100644 (file)
@@ -65,6 +65,8 @@ namespace Content.Client.Input
             human.AddFunction(ContentKeyFunctions.OpenInventoryMenu);
             human.AddFunction(ContentKeyFunctions.SmartEquipBackpack);
             human.AddFunction(ContentKeyFunctions.SmartEquipBelt);
+            human.AddFunction(ContentKeyFunctions.OpenBackpack);
+            human.AddFunction(ContentKeyFunctions.OpenBelt);
             human.AddFunction(ContentKeyFunctions.MouseMiddle);
             human.AddFunction(ContentKeyFunctions.ArcadeUp);
             human.AddFunction(ContentKeyFunctions.ArcadeDown);
index 18872d16b5e8a9489243d025f53d0de956c6cd53..d8ca500486d7ed2689e68aae4f6c4a1f84d481d9 100644 (file)
@@ -188,6 +188,8 @@ namespace Content.Client.Options.UI.Tabs
             AddHeader("ui-options-header-interaction-adv");
             AddButton(ContentKeyFunctions.SmartEquipBackpack);
             AddButton(ContentKeyFunctions.SmartEquipBelt);
+            AddButton(ContentKeyFunctions.OpenBackpack);
+            AddButton(ContentKeyFunctions.OpenBelt);
             AddButton(ContentKeyFunctions.ThrowItemInHand);
             AddButton(ContentKeyFunctions.TryPullObject);
             AddButton(ContentKeyFunctions.MovePulledObject);
index 88de528ff6d38e4028ae15b89bb6faa8391b6725..f7fdbb83675ad1f8d5852142010968b40115c0c6 100644 (file)
@@ -17,21 +17,24 @@ public sealed class StorageBoundUserInterface : BoundUserInterface
         _storage = _entManager.System<StorageSystem>();
     }
 
-    protected override void Open()
-    {
-        base.Open();
-
-        if (_entManager.TryGetComponent<StorageComponent>(Owner, out var comp))
-            _storage.OpenStorageUI(Owner, comp);
-    }
-
     protected override void Dispose(bool disposing)
     {
         base.Dispose(disposing);
         if (!disposing)
             return;
 
-        _storage.CloseStorageUI(Owner);
+        _storage.CloseStorageWindow(Owner);
+    }
+
+    protected override void ReceiveMessage(BoundUserInterfaceMessage message)
+    {
+        base.ReceiveMessage(message);
+
+        if (message is StorageModifyWindowMessage)
+        {
+            if (_entManager.TryGetComponent<StorageComponent>(Owner, out var comp))
+                _storage.OpenStorageWindow((Owner, comp));
+        }
     }
 }
 
index 56d0810dd5b5f009433445ea51893e1b29b9fe09..ce0a6bf1ca4883ccdef3b117dc4f8e62cdc817ea 100644 (file)
@@ -35,18 +35,38 @@ public sealed class StorageSystem : SharedStorageSystem
             StorageUpdated?.Invoke((entity, entity.Comp));
     }
 
-    public void OpenStorageUI(EntityUid uid, StorageComponent component)
+    public void OpenStorageWindow(Entity<StorageComponent> entity)
     {
-        if (_openStorages.Contains((uid, component)))
+        if (_openStorages.Contains(entity))
+        {
+            if (_openStorages.LastOrDefault() == entity)
+            {
+                CloseStorageWindow((entity, entity.Comp));
+            }
+            else
+            {
+                var storages = new ValueList<Entity<StorageComponent>>(_openStorages);
+                var reverseStorages = storages.Reverse();
+
+                foreach (var storageEnt in reverseStorages)
+                {
+                    if (storageEnt == entity)
+                        break;
+
+                    CloseStorageBoundUserInterface(storageEnt.Owner);
+                    _openStorages.Remove(entity);
+                }
+            }
             return;
+        }
 
-        ClearNonParentStorages(uid);
-        _openStorages.Add((uid, component));
+        ClearNonParentStorages(entity);
+        _openStorages.Add(entity);
         Entity<StorageComponent>? last = _openStorages.LastOrDefault();
         StorageOrderChanged?.Invoke(last);
     }
 
-    public void CloseStorageUI(Entity<StorageComponent?> entity)
+    public void CloseStorageWindow(Entity<StorageComponent?> entity)
     {
         if (!Resolve(entity, ref entity.Comp))
             return;
@@ -99,7 +119,7 @@ public sealed class StorageSystem : SharedStorageSystem
 
     private void OnShutdown(Entity<StorageComponent> ent, ref ComponentShutdown args)
     {
-        CloseStorageUI((ent, ent.Comp));
+        CloseStorageWindow((ent, ent.Comp));
     }
 
     /// <inheritdoc />
index d79edb2e79853544b575c8fb560f783c6932ee8d..bc35c29cf509dca22954fa9ab3070298d5a57b75 100644 (file)
@@ -12,7 +12,6 @@ using Robust.Client.UserInterface;
 using Robust.Client.UserInterface.Controls;
 using Robust.Client.UserInterface.CustomControls;
 using Robust.Shared.Timing;
-using Robust.Shared.Utility;
 
 namespace Content.Client.UserInterface.Systems.Storage.Controls;
 
@@ -156,6 +155,15 @@ public sealed class StorageContainer : BaseWindow
         {
             Close();
         };
+        exitButton.OnKeyBindDown += args =>
+        {
+            // it just makes sense...
+            if (!args.Handled && args.Function == ContentKeyFunctions.ActivateItemInWorld)
+            {
+                Close();
+                args.Handle();
+            }
+        };
         var exitContainer = new BoxContainer
         {
             Children =
@@ -448,6 +456,6 @@ public sealed class StorageContainer : BaseWindow
         if (StorageEntity == null)
             return;
 
-        _entity.System<StorageSystem>().CloseStorageUI(StorageEntity.Value);
+        _entity.System<StorageSystem>().CloseStorageWindow(StorageEntity.Value);
     }
 }
index 2afd57ca1f664e52d0cbd012f497539739b0de4b..3223cbf60c2e1cde3f8897ac40100569d3653e48 100644 (file)
@@ -3,6 +3,8 @@ using Content.Shared.Administration;
 using Content.Shared.Explosion;
 using Content.Shared.Ghost;
 using Content.Shared.Hands;
+using Content.Shared.Input;
+using Content.Shared.Inventory;
 using Content.Shared.Lock;
 using Content.Shared.Storage;
 using Content.Shared.Storage.Components;
@@ -10,6 +12,7 @@ using Content.Shared.Storage.EntitySystems;
 using Content.Shared.Timing;
 using Content.Shared.Verbs;
 using Robust.Server.GameObjects;
+using Robust.Shared.Input.Binding;
 using Robust.Shared.Map;
 using Robust.Shared.Player;
 using Robust.Shared.Prototypes;
@@ -21,6 +24,7 @@ public sealed partial class StorageSystem : SharedStorageSystem
 {
     [Dependency] private readonly IAdminManager _admin = default!;
     [Dependency] private readonly IPrototypeManager _prototype = default!;
+    [Dependency] private readonly InventorySystem _inventory = default!;
     [Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
 
     public override void Initialize()
@@ -31,6 +35,11 @@ public sealed partial class StorageSystem : SharedStorageSystem
         SubscribeLocalEvent<StorageComponent, BeforeExplodeEvent>(OnExploded);
 
         SubscribeLocalEvent<StorageFillComponent, MapInitEvent>(OnStorageFillMapInit);
+
+        CommandBinds.Builder
+            .Bind(ContentKeyFunctions.OpenBackpack, InputCmdHandler.FromDelegate(HandleOpenBackpack))
+            .Bind(ContentKeyFunctions.OpenBelt, InputCmdHandler.FromDelegate(HandleOpenBelt))
+            .Register<StorageSystem>();
     }
 
     private void AddUiVerb(EntityUid uid, StorageComponent component, GetVerbsEvent<ActivationVerb> args)
@@ -110,7 +119,7 @@ public sealed partial class StorageSystem : SharedStorageSystem
     /// <param name="entity">The entity to open the UI for</param>
     public override void OpenStorageUI(EntityUid uid, EntityUid entity, StorageComponent? storageComp = null, bool silent = false)
     {
-        if (!Resolve(uid, ref storageComp) || !TryComp(entity, out ActorComponent? player))
+        if (!Resolve(uid, ref storageComp, false) || !TryComp(entity, out ActorComponent? player))
             return;
 
         // prevent spamming bag open / honkerton honk sound
@@ -125,8 +134,10 @@ public sealed partial class StorageSystem : SharedStorageSystem
         Log.Debug($"Storage (UID {uid}) \"used\" by player session (UID {player.PlayerSession.AttachedEntity}).");
 
         var bui = _uiSystem.GetUiOrNull(uid, StorageComponent.StorageUiKey.Key);
-        if (bui != null)
-            _uiSystem.OpenUi(bui, player.PlayerSession);
+        if (bui == null)
+            return;
+        _uiSystem.OpenUi(bui, player.PlayerSession);
+        _uiSystem.SendUiMessage(bui, new StorageModifyWindowMessage());
     }
 
     /// <inheritdoc />
@@ -162,4 +173,31 @@ public sealed partial class StorageSystem : SharedStorageSystem
             }
         }
     }
+
+    private void HandleOpenBackpack(ICommonSession? session)
+    {
+        HandleOpenSlotUI(session, "back");
+    }
+
+    private void HandleOpenBelt(ICommonSession? session)
+    {
+        HandleOpenSlotUI(session, "belt");
+    }
+
+    private void HandleOpenSlotUI(ICommonSession? session, string slot)
+    {
+        if (session is not { } playerSession)
+            return;
+
+        if (playerSession.AttachedEntity is not {Valid: true} playerEnt || !Exists(playerEnt))
+            return;
+
+        if (!_inventory.TryGetSlotEntity(playerEnt, slot, out var storageEnt))
+            return;
+
+        if (!ActionBlocker.CanInteract(playerEnt, storageEnt))
+            return;
+
+        OpenStorageUI(storageEnt.Value, playerEnt);
+    }
 }
index 7a5a6e82d82ca1dd311ade5ea484eb9207276d21..ee4a4e9023bc7c346ef3c8b357bdb7a027de1a8f 100644 (file)
@@ -30,6 +30,8 @@ namespace Content.Shared.Input
         public static readonly BoundKeyFunction OpenInventoryMenu = "OpenInventoryMenu";
         public static readonly BoundKeyFunction SmartEquipBackpack = "SmartEquipBackpack";
         public static readonly BoundKeyFunction SmartEquipBelt = "SmartEquipBelt";
+        public static readonly BoundKeyFunction OpenBackpack = "OpenBackpack";
+        public static readonly BoundKeyFunction OpenBelt = "OpenBelt";
         public static readonly BoundKeyFunction OpenAHelp = "OpenAHelp";
         public static readonly BoundKeyFunction SwapHands = "SwapHands";
         public static readonly BoundKeyFunction MoveStoredItem = "MoveStoredItem";
index 32ce24a97159e63b1e3747d042859363133bd130..0b93b9b76291fc4cfe034886be8d0b36756d3f54 100644 (file)
@@ -37,7 +37,7 @@ public abstract class SharedStorageSystem : EntitySystem
     [Dependency] protected readonly SharedItemSystem ItemSystem = default!;
     [Dependency] private   readonly SharedPopupSystem _popupSystem = default!;
     [Dependency] private   readonly SharedHandsSystem _sharedHandsSystem = default!;
-    [Dependency] private   readonly ActionBlockerSystem _actionBlockerSystem = default!;
+    [Dependency] protected readonly ActionBlockerSystem ActionBlocker = default!;
     [Dependency] private   readonly SharedAppearanceSystem _appearance = default!;
     [Dependency] protected readonly SharedAudioSystem Audio = default!;
     [Dependency] private   readonly SharedCombatModeSystem _combatMode = default!;
@@ -334,7 +334,7 @@ public abstract class SharedStorageSystem : EntitySystem
             return;
         }
 
-        if (!_actionBlockerSystem.CanInteract(player, entity) || !storageComp.Container.Contains(entity))
+        if (!ActionBlocker.CanInteract(player, entity) || !storageComp.Container.Contains(entity))
             return;
 
         // Does the player have hands?
@@ -377,7 +377,7 @@ public abstract class SharedStorageSystem : EntitySystem
             return;
         }
 
-        if (!_actionBlockerSystem.CanInteract(player, itemEnt))
+        if (!ActionBlocker.CanInteract(player, itemEnt))
             return;
 
         TrySetItemStorageLocation((itemEnt, null), (storageEnt, storageComp), msg.Location);
@@ -404,7 +404,7 @@ public abstract class SharedStorageSystem : EntitySystem
             return;
         }
 
-        if (!_actionBlockerSystem.CanInteract(player, itemEnt) || !_sharedHandsSystem.IsHolding(player, itemEnt, out _))
+        if (!ActionBlocker.CanInteract(player, itemEnt) || !_sharedHandsSystem.IsHolding(player, itemEnt, out _))
             return;
 
         InsertAt((storageEnt, storageComp), (itemEnt, null), msg.Location, out _, player, stackAutomatically: false);
index 99677cc6c176e7e55340ed926b07b4d63f217ef8..f150a3e8fb573635b2c7d134b15f01e385c7c31d 100644 (file)
@@ -170,6 +170,15 @@ namespace Content.Shared.Storage
         }
     }
 
+    /// <summary>
+    /// An extra BUI message that either opens, closes, or focuses the storage window based on context.
+    /// </summary>
+    [Serializable, NetSerializable]
+    public sealed class StorageModifyWindowMessage : BoundUserInterfaceMessage
+    {
+
+    }
+
     [NetSerializable]
     [Serializable]
     public enum StorageVisuals : byte
index 535e52d295db0d0e41a4b19868ba37ae598de353..bcfa5a16a412bbd193c6a89ea04488e30a421395 100644 (file)
@@ -118,6 +118,8 @@ ui-options-static-storage-ui = Static storage UI
 
 ui-options-function-smart-equip-backpack = Smart-equip to backpack
 ui-options-function-smart-equip-belt = Smart-equip to belt
+ui-options-function-open-backpack = Open backpack
+ui-options-function-open-belt = Open belt
 ui-options-function-throw-item-in-hand = Throw item
 ui-options-function-try-pull-object = Pull object
 ui-options-function-move-pulled-object = Move pulled object
index 28bbb9f3d0ceb6880b1628a1388c1adda208b4e7..897506623c6ce254c0995ca124da5868a45dd80f 100644 (file)
@@ -244,6 +244,13 @@ binds:
   type: State
   key: E
   mod1: Shift
+- function: OpenBackpack
+  type: State
+  key: V
+- function: OpenBelt
+  type: State
+  key: V
+  mod1: Shift
 - function: ShowDebugConsole
   type: State
   key: Tilde