Implement gridinv, proper (#703)

* Implement gridinv, 1500 squashed commits :elp:

* Me when

* Linter errors

* Fix katana belts
This commit is contained in:
Debug
2024-01-21 19:58:28 +01:00
committed by GitHub
parent 5727e2797b
commit 18f0af1f68
431 changed files with 9769 additions and 2290 deletions
@@ -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)
@@ -92,7 +101,7 @@ public sealed partial class StorageSystem : SharedStorageSystem
if (!_uiSystem.IsUiOpen(uid, args.UiKey))
{
storageComp.IsUiOpen = false;
UpdateStorageVisualization(uid, storageComp);
UpdateAppearance((uid, storageComp, null));
if (storageComp.StorageCloseSound is not null)
Audio.PlayEntity(storageComp.StorageCloseSound, Filter.Pvs(uid, entityManager: EntityManager), uid, true, storageComp.StorageCloseSound.Params);
@@ -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);
}
}