Grid Inventory (#21931)

* Grid Inventory

* oh boy we keep cracking on

* auto insertion is kinda working? gross, too!

* pieces and proper layouts

* fix the sprites

* mousing over grid pieces... finally

* dragging deez nuts all over the screen

* eek!

* dragging is 90% less horrendous

* auto-rotating

* flatten

* Rotation at last

* fix rotation and change keybind for removing items.

* rebinding and keybinding

* wow! look at that! configurable with a button! cool!

* dragging is a bit cooler, eh?

* hover insert, my beloved

* add some grids for storage, fix 1x1 storages, fix multiple inputs at once

* el navigation

* oh yeah some stuff i forgor

* more fixes and QOL stuff

* the griddening

* the last of it (yippee)

* sloth review :)
This commit is contained in:
Nemanja
2023-12-04 18:04:39 -05:00
committed by GitHub
parent 4221ed2d4b
commit cc8984d096
99 changed files with 2014 additions and 619 deletions

View File

@@ -1,24 +1,30 @@
using Content.Client.Animations;
using System.Linq;
using Content.Client.Animations;
using Content.Shared.Hands;
using Content.Shared.Storage;
using Content.Shared.Storage.EntitySystems;
using Robust.Shared.Collections;
using Robust.Shared.Map;
using Robust.Shared.Timing;
namespace Content.Client.Storage.Systems;
// TODO kill this is all horrid.
public sealed class StorageSystem : SharedStorageSystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly EntityPickupAnimationSystem _entityPickupAnimation = default!;
public event Action<EntityUid, StorageComponent>? StorageUpdated;
private readonly List<Entity<StorageComponent>> _openStorages = new();
public int OpenStorageAmount => _openStorages.Count;
public event Action<Entity<StorageComponent>>? StorageUpdated;
public event Action<Entity<StorageComponent>?>? StorageOrderChanged;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<StorageComponent, ComponentShutdown>(OnShutdown);
SubscribeNetworkEvent<PickupAnimationEvent>(HandlePickupAnimation);
SubscribeNetworkEvent<AnimateInsertingEntitiesEvent>(HandleAnimatingInsertingEntities);
}
@@ -26,7 +32,74 @@ public sealed class StorageSystem : SharedStorageSystem
public override void UpdateUI(Entity<StorageComponent?> entity)
{
if (Resolve(entity.Owner, ref entity.Comp))
StorageUpdated?.Invoke(entity.Owner, entity.Comp);
StorageUpdated?.Invoke((entity, entity.Comp));
}
public void OpenStorageUI(EntityUid uid, StorageComponent component)
{
if (_openStorages.Contains((uid, component)))
return;
ClearNonParentStorages(uid);
_openStorages.Add((uid, component));
Entity<StorageComponent>? last = _openStorages.LastOrDefault();
StorageOrderChanged?.Invoke(last);
}
public void CloseStorageUI(Entity<StorageComponent?> entity)
{
if (!Resolve(entity, ref entity.Comp))
return;
if (!_openStorages.Contains((entity, entity.Comp)))
return;
var storages = new ValueList<Entity<StorageComponent>>(_openStorages);
var reverseStorages = storages.Reverse();
foreach (var storage in reverseStorages)
{
CloseStorageBoundUserInterface(storage.Owner);
_openStorages.Remove(storage);
if (storage.Owner == entity.Owner)
break;
}
Entity<StorageComponent>? last = null;
if (_openStorages.Any())
last = _openStorages.LastOrDefault();
StorageOrderChanged?.Invoke(last);
}
private void ClearNonParentStorages(EntityUid uid)
{
var storages = new ValueList<Entity<StorageComponent>>(_openStorages);
var reverseStorages = storages.Reverse();
foreach (var storage in reverseStorages)
{
if (storage.Comp.Container.Contains(uid))
break;
CloseStorageBoundUserInterface(storage.Owner);
_openStorages.Remove(storage);
}
}
private void CloseStorageBoundUserInterface(Entity<UserInterfaceComponent?> entity)
{
if (!Resolve(entity, ref entity.Comp, false))
return;
if (entity.Comp.OpenInterfaces.GetValueOrDefault(StorageComponent.StorageUiKey.Key) is not { } bui)
return;
bui.Close();
}
private void OnShutdown(Entity<StorageComponent> ent, ref ComponentShutdown args)
{
CloseStorageUI((ent, ent.Comp));
}
/// <inheritdoc />
@@ -49,14 +122,14 @@ public sealed class StorageSystem : SharedStorageSystem
if (!_timing.IsFirstTimePredicted)
return;
if (finalCoords.InRange(EntityManager, _transform, initialCoords, 0.1f) ||
if (finalCoords.InRange(EntityManager, TransformSystem, initialCoords, 0.1f) ||
!Exists(initialCoords.EntityId) || !Exists(finalCoords.EntityId))
{
return;
}
var finalMapPos = finalCoords.ToMapPos(EntityManager, _transform);
var finalPos = _transform.GetInvWorldMatrix(initialCoords.EntityId).Transform(finalMapPos);
var finalMapPos = finalCoords.ToMapPos(EntityManager, TransformSystem);
var finalPos = TransformSystem.GetInvWorldMatrix(initialCoords.EntityId).Transform(finalMapPos);
_entityPickupAnimation.AnimateEntityPickup(item, initialCoords, finalPos, initialAngle);
}
@@ -74,7 +147,7 @@ public sealed class StorageSystem : SharedStorageSystem
var entity = GetEntity(msg.StoredEntities[i]);
var initialPosition = msg.EntityPositions[i];
if (EntityManager.EntityExists(entity) && transformComp != null)
if (Exists(entity) && transformComp != null)
{
_entityPickupAnimation.AnimateEntityPickup(entity, GetCoordinates(initialPosition), transformComp.LocalPosition, msg.EntityAngles[i]);
}