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.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);

View 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);

View 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));
}
}
}

View 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)))
return;
if (_openStorages.Contains(entity))
{
if (_openStorages.LastOrDefault() == entity)
{
CloseStorageWindow((entity, entity.Comp));
}
else
{
var storages = new ValueList<Entity<StorageComponent>>(_openStorages);
var reverseStorages = storages.Reverse();
ClearNonParentStorages(uid);
_openStorages.Add((uid, component));
foreach (var storageEnt in reverseStorages)
{
if (storageEnt == entity)
break;
CloseStorageBoundUserInterface(storageEnt.Owner);
_openStorages.Remove(entity);
}
}
return;
}
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 />

View 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);
}
}