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
This commit is contained in:
Nemanja
2023-12-08 13:43:37 -05:00
committed by GitHub
parent dbdb9bc3ff
commit 736300d505
11 changed files with 118 additions and 25 deletions

View File

@@ -65,6 +65,8 @@ namespace Content.Client.Input
human.AddFunction(ContentKeyFunctions.OpenInventoryMenu); human.AddFunction(ContentKeyFunctions.OpenInventoryMenu);
human.AddFunction(ContentKeyFunctions.SmartEquipBackpack); human.AddFunction(ContentKeyFunctions.SmartEquipBackpack);
human.AddFunction(ContentKeyFunctions.SmartEquipBelt); human.AddFunction(ContentKeyFunctions.SmartEquipBelt);
human.AddFunction(ContentKeyFunctions.OpenBackpack);
human.AddFunction(ContentKeyFunctions.OpenBelt);
human.AddFunction(ContentKeyFunctions.MouseMiddle); human.AddFunction(ContentKeyFunctions.MouseMiddle);
human.AddFunction(ContentKeyFunctions.ArcadeUp); human.AddFunction(ContentKeyFunctions.ArcadeUp);
human.AddFunction(ContentKeyFunctions.ArcadeDown); human.AddFunction(ContentKeyFunctions.ArcadeDown);

View File

@@ -188,6 +188,8 @@ namespace Content.Client.Options.UI.Tabs
AddHeader("ui-options-header-interaction-adv"); AddHeader("ui-options-header-interaction-adv");
AddButton(ContentKeyFunctions.SmartEquipBackpack); AddButton(ContentKeyFunctions.SmartEquipBackpack);
AddButton(ContentKeyFunctions.SmartEquipBelt); AddButton(ContentKeyFunctions.SmartEquipBelt);
AddButton(ContentKeyFunctions.OpenBackpack);
AddButton(ContentKeyFunctions.OpenBelt);
AddButton(ContentKeyFunctions.ThrowItemInHand); AddButton(ContentKeyFunctions.ThrowItemInHand);
AddButton(ContentKeyFunctions.TryPullObject); AddButton(ContentKeyFunctions.TryPullObject);
AddButton(ContentKeyFunctions.MovePulledObject); AddButton(ContentKeyFunctions.MovePulledObject);

View File

@@ -17,21 +17,24 @@ public sealed class StorageBoundUserInterface : BoundUserInterface
_storage = _entManager.System<StorageSystem>(); _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) protected override void Dispose(bool disposing)
{ {
base.Dispose(disposing); base.Dispose(disposing);
if (!disposing) if (!disposing)
return; 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));
}
} }
} }

View File

@@ -35,18 +35,38 @@ public sealed class StorageSystem : SharedStorageSystem
StorageUpdated?.Invoke((entity, entity.Comp)); 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))
return; {
if (_openStorages.LastOrDefault() == entity)
{
CloseStorageWindow((entity, entity.Comp));
}
else
{
var storages = new ValueList<Entity<StorageComponent>>(_openStorages);
var reverseStorages = storages.Reverse();
ClearNonParentStorages(uid); foreach (var storageEnt in reverseStorages)
_openStorages.Add((uid, component)); {
if (storageEnt == entity)
break;
CloseStorageBoundUserInterface(storageEnt.Owner);
_openStorages.Remove(entity);
}
}
return;
}
ClearNonParentStorages(entity);
_openStorages.Add(entity);
Entity<StorageComponent>? last = _openStorages.LastOrDefault(); Entity<StorageComponent>? last = _openStorages.LastOrDefault();
StorageOrderChanged?.Invoke(last); StorageOrderChanged?.Invoke(last);
} }
public void CloseStorageUI(Entity<StorageComponent?> entity) public void CloseStorageWindow(Entity<StorageComponent?> entity)
{ {
if (!Resolve(entity, ref entity.Comp)) if (!Resolve(entity, ref entity.Comp))
return; return;
@@ -99,7 +119,7 @@ public sealed class StorageSystem : SharedStorageSystem
private void OnShutdown(Entity<StorageComponent> ent, ref ComponentShutdown args) private void OnShutdown(Entity<StorageComponent> ent, ref ComponentShutdown args)
{ {
CloseStorageUI((ent, ent.Comp)); CloseStorageWindow((ent, ent.Comp));
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@@ -12,7 +12,6 @@ using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Timing; using Robust.Shared.Timing;
using Robust.Shared.Utility;
namespace Content.Client.UserInterface.Systems.Storage.Controls; namespace Content.Client.UserInterface.Systems.Storage.Controls;
@@ -156,6 +155,15 @@ public sealed class StorageContainer : BaseWindow
{ {
Close(); Close();
}; };
exitButton.OnKeyBindDown += args =>
{
// it just makes sense...
if (!args.Handled && args.Function == ContentKeyFunctions.ActivateItemInWorld)
{
Close();
args.Handle();
}
};
var exitContainer = new BoxContainer var exitContainer = new BoxContainer
{ {
Children = Children =
@@ -448,6 +456,6 @@ public sealed class StorageContainer : BaseWindow
if (StorageEntity == null) if (StorageEntity == null)
return; return;
_entity.System<StorageSystem>().CloseStorageUI(StorageEntity.Value); _entity.System<StorageSystem>().CloseStorageWindow(StorageEntity.Value);
} }
} }

View File

@@ -3,6 +3,8 @@ using Content.Shared.Administration;
using Content.Shared.Explosion; using Content.Shared.Explosion;
using Content.Shared.Ghost; using Content.Shared.Ghost;
using Content.Shared.Hands; using Content.Shared.Hands;
using Content.Shared.Input;
using Content.Shared.Inventory;
using Content.Shared.Lock; using Content.Shared.Lock;
using Content.Shared.Storage; using Content.Shared.Storage;
using Content.Shared.Storage.Components; using Content.Shared.Storage.Components;
@@ -10,6 +12,7 @@ using Content.Shared.Storage.EntitySystems;
using Content.Shared.Timing; using Content.Shared.Timing;
using Content.Shared.Verbs; using Content.Shared.Verbs;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Input.Binding;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Player; using Robust.Shared.Player;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
@@ -21,6 +24,7 @@ public sealed partial class StorageSystem : SharedStorageSystem
{ {
[Dependency] private readonly IAdminManager _admin = default!; [Dependency] private readonly IAdminManager _admin = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!; [Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!; [Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
public override void Initialize() public override void Initialize()
@@ -31,6 +35,11 @@ public sealed partial class StorageSystem : SharedStorageSystem
SubscribeLocalEvent<StorageComponent, BeforeExplodeEvent>(OnExploded); SubscribeLocalEvent<StorageComponent, BeforeExplodeEvent>(OnExploded);
SubscribeLocalEvent<StorageFillComponent, MapInitEvent>(OnStorageFillMapInit); 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) 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> /// <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) 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; return;
// prevent spamming bag open / honkerton honk sound // 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})."); Log.Debug($"Storage (UID {uid}) \"used\" by player session (UID {player.PlayerSession.AttachedEntity}).");
var bui = _uiSystem.GetUiOrNull(uid, StorageComponent.StorageUiKey.Key); var bui = _uiSystem.GetUiOrNull(uid, StorageComponent.StorageUiKey.Key);
if (bui != null) if (bui == null)
_uiSystem.OpenUi(bui, player.PlayerSession); return;
_uiSystem.OpenUi(bui, player.PlayerSession);
_uiSystem.SendUiMessage(bui, new StorageModifyWindowMessage());
} }
/// <inheritdoc /> /// <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);
}
} }

View File

@@ -30,6 +30,8 @@ namespace Content.Shared.Input
public static readonly BoundKeyFunction OpenInventoryMenu = "OpenInventoryMenu"; public static readonly BoundKeyFunction OpenInventoryMenu = "OpenInventoryMenu";
public static readonly BoundKeyFunction SmartEquipBackpack = "SmartEquipBackpack"; public static readonly BoundKeyFunction SmartEquipBackpack = "SmartEquipBackpack";
public static readonly BoundKeyFunction SmartEquipBelt = "SmartEquipBelt"; 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 OpenAHelp = "OpenAHelp";
public static readonly BoundKeyFunction SwapHands = "SwapHands"; public static readonly BoundKeyFunction SwapHands = "SwapHands";
public static readonly BoundKeyFunction MoveStoredItem = "MoveStoredItem"; public static readonly BoundKeyFunction MoveStoredItem = "MoveStoredItem";

View File

@@ -37,7 +37,7 @@ public abstract class SharedStorageSystem : EntitySystem
[Dependency] protected readonly SharedItemSystem ItemSystem = default!; [Dependency] protected readonly SharedItemSystem ItemSystem = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!; [Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly SharedHandsSystem _sharedHandsSystem = 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] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] protected readonly SharedAudioSystem Audio = default!; [Dependency] protected readonly SharedAudioSystem Audio = default!;
[Dependency] private readonly SharedCombatModeSystem _combatMode = default!; [Dependency] private readonly SharedCombatModeSystem _combatMode = default!;
@@ -334,7 +334,7 @@ public abstract class SharedStorageSystem : EntitySystem
return; return;
} }
if (!_actionBlockerSystem.CanInteract(player, entity) || !storageComp.Container.Contains(entity)) if (!ActionBlocker.CanInteract(player, entity) || !storageComp.Container.Contains(entity))
return; return;
// Does the player have hands? // Does the player have hands?
@@ -377,7 +377,7 @@ public abstract class SharedStorageSystem : EntitySystem
return; return;
} }
if (!_actionBlockerSystem.CanInteract(player, itemEnt)) if (!ActionBlocker.CanInteract(player, itemEnt))
return; return;
TrySetItemStorageLocation((itemEnt, null), (storageEnt, storageComp), msg.Location); TrySetItemStorageLocation((itemEnt, null), (storageEnt, storageComp), msg.Location);
@@ -404,7 +404,7 @@ public abstract class SharedStorageSystem : EntitySystem
return; return;
} }
if (!_actionBlockerSystem.CanInteract(player, itemEnt) || !_sharedHandsSystem.IsHolding(player, itemEnt, out _)) if (!ActionBlocker.CanInteract(player, itemEnt) || !_sharedHandsSystem.IsHolding(player, itemEnt, out _))
return; return;
InsertAt((storageEnt, storageComp), (itemEnt, null), msg.Location, out _, player, stackAutomatically: false); InsertAt((storageEnt, storageComp), (itemEnt, null), msg.Location, out _, player, stackAutomatically: false);

View 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] [NetSerializable]
[Serializable] [Serializable]
public enum StorageVisuals : byte public enum StorageVisuals : byte

View 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-backpack = Smart-equip to backpack
ui-options-function-smart-equip-belt = Smart-equip to belt 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-throw-item-in-hand = Throw item
ui-options-function-try-pull-object = Pull object ui-options-function-try-pull-object = Pull object
ui-options-function-move-pulled-object = Move pulled object ui-options-function-move-pulled-object = Move pulled object

View File

@@ -244,6 +244,13 @@ binds:
type: State type: State
key: E key: E
mod1: Shift mod1: Shift
- function: OpenBackpack
type: State
key: V
- function: OpenBelt
type: State
key: V
mod1: Shift
- function: ShowDebugConsole - function: ShowDebugConsole
type: State type: State
key: Tilde key: Tilde