From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Fri, 8 Dec 2023 18:43:37 +0000 (-0500) Subject: keybinds for opening bag/belt & context logic for opening storage window (#22238) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=736300d505d72d1302392df2f474624c4087e440;p=space-station-14.git keybinds for opening bag/belt & context logic for opening storage window (#22238) * keybinds for opening bag/belt & context logic for opening storage window * no error por favor --- diff --git a/Content.Client/Input/ContentContexts.cs b/Content.Client/Input/ContentContexts.cs index 82388cb75b..03f4f3f38b 100644 --- a/Content.Client/Input/ContentContexts.cs +++ b/Content.Client/Input/ContentContexts.cs @@ -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); diff --git a/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs b/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs index 18872d16b5..d8ca500486 100644 --- a/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs +++ b/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs @@ -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); diff --git a/Content.Client/Storage/StorageBoundUserInterface.cs b/Content.Client/Storage/StorageBoundUserInterface.cs index 88de528ff6..f7fdbb8367 100644 --- a/Content.Client/Storage/StorageBoundUserInterface.cs +++ b/Content.Client/Storage/StorageBoundUserInterface.cs @@ -17,21 +17,24 @@ public sealed class StorageBoundUserInterface : BoundUserInterface _storage = _entManager.System(); } - protected override void Open() - { - base.Open(); - - if (_entManager.TryGetComponent(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(Owner, out var comp)) + _storage.OpenStorageWindow((Owner, comp)); + } } } diff --git a/Content.Client/Storage/Systems/StorageSystem.cs b/Content.Client/Storage/Systems/StorageSystem.cs index 56d0810dd5..ce0a6bf1ca 100644 --- a/Content.Client/Storage/Systems/StorageSystem.cs +++ b/Content.Client/Storage/Systems/StorageSystem.cs @@ -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 entity) { - if (_openStorages.Contains((uid, component))) + if (_openStorages.Contains(entity)) + { + if (_openStorages.LastOrDefault() == entity) + { + CloseStorageWindow((entity, entity.Comp)); + } + else + { + var storages = new ValueList>(_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? last = _openStorages.LastOrDefault(); StorageOrderChanged?.Invoke(last); } - public void CloseStorageUI(Entity entity) + public void CloseStorageWindow(Entity entity) { if (!Resolve(entity, ref entity.Comp)) return; @@ -99,7 +119,7 @@ public sealed class StorageSystem : SharedStorageSystem private void OnShutdown(Entity ent, ref ComponentShutdown args) { - CloseStorageUI((ent, ent.Comp)); + CloseStorageWindow((ent, ent.Comp)); } /// diff --git a/Content.Client/UserInterface/Systems/Storage/Controls/StorageContainer.cs b/Content.Client/UserInterface/Systems/Storage/Controls/StorageContainer.cs index d79edb2e79..bc35c29cf5 100644 --- a/Content.Client/UserInterface/Systems/Storage/Controls/StorageContainer.cs +++ b/Content.Client/UserInterface/Systems/Storage/Controls/StorageContainer.cs @@ -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().CloseStorageUI(StorageEntity.Value); + _entity.System().CloseStorageWindow(StorageEntity.Value); } } diff --git a/Content.Server/Storage/EntitySystems/StorageSystem.cs b/Content.Server/Storage/EntitySystems/StorageSystem.cs index 2afd57ca1f..3223cbf60c 100644 --- a/Content.Server/Storage/EntitySystems/StorageSystem.cs +++ b/Content.Server/Storage/EntitySystems/StorageSystem.cs @@ -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(OnExploded); SubscribeLocalEvent(OnStorageFillMapInit); + + CommandBinds.Builder + .Bind(ContentKeyFunctions.OpenBackpack, InputCmdHandler.FromDelegate(HandleOpenBackpack)) + .Bind(ContentKeyFunctions.OpenBelt, InputCmdHandler.FromDelegate(HandleOpenBelt)) + .Register(); } private void AddUiVerb(EntityUid uid, StorageComponent component, GetVerbsEvent args) @@ -110,7 +119,7 @@ public sealed partial class StorageSystem : SharedStorageSystem /// The entity to open the UI for 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()); } /// @@ -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); + } } diff --git a/Content.Shared/Input/ContentKeyFunctions.cs b/Content.Shared/Input/ContentKeyFunctions.cs index 7a5a6e82d8..ee4a4e9023 100644 --- a/Content.Shared/Input/ContentKeyFunctions.cs +++ b/Content.Shared/Input/ContentKeyFunctions.cs @@ -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"; diff --git a/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs b/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs index 32ce24a971..0b93b9b762 100644 --- a/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs +++ b/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs @@ -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); diff --git a/Content.Shared/Storage/StorageComponent.cs b/Content.Shared/Storage/StorageComponent.cs index 99677cc6c1..f150a3e8fb 100644 --- a/Content.Shared/Storage/StorageComponent.cs +++ b/Content.Shared/Storage/StorageComponent.cs @@ -170,6 +170,15 @@ namespace Content.Shared.Storage } } + /// + /// An extra BUI message that either opens, closes, or focuses the storage window based on context. + /// + [Serializable, NetSerializable] + public sealed class StorageModifyWindowMessage : BoundUserInterfaceMessage + { + + } + [NetSerializable] [Serializable] public enum StorageVisuals : byte diff --git a/Resources/Locale/en-US/escape-menu/ui/options-menu.ftl b/Resources/Locale/en-US/escape-menu/ui/options-menu.ftl index 535e52d295..bcfa5a16a4 100644 --- a/Resources/Locale/en-US/escape-menu/ui/options-menu.ftl +++ b/Resources/Locale/en-US/escape-menu/ui/options-menu.ftl @@ -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 diff --git a/Resources/keybinds.yml b/Resources/keybinds.yml index 28bbb9f3d0..897506623c 100644 --- a/Resources/keybinds.yml +++ b/Resources/keybinds.yml @@ -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