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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user