]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Miscellaneous inventory tweaks (#22371)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Tue, 12 Dec 2023 07:49:37 +0000 (02:49 -0500)
committerGitHub <noreply@github.com>
Tue, 12 Dec 2023 07:49:37 +0000 (00:49 -0700)
* pt 1

* Miscellaneous gridinv UX

Content.Client/UserInterface/Systems/Storage/Controls/ItemGridPiece.cs
Content.Client/UserInterface/Systems/Storage/Controls/StorageContainer.cs
Content.Client/UserInterface/Systems/Storage/StorageUIController.cs
Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs
Content.Shared/Storage/StorageComponent.cs

index a7298213e862e2b718791f85b3d74c442c1d1ad8..0ca1797965fa1deb3d63600bbb7955cc17ef98a2 100644 (file)
@@ -6,7 +6,6 @@ using Robust.Client.GameObjects;
 using Robust.Client.Graphics;
 using Robust.Client.UserInterface;
 using Robust.Client.UserInterface.CustomControls;
-using YamlDotNet.Core;
 
 namespace Content.Client.UserInterface.Systems.Storage.Controls;
 
@@ -103,7 +102,7 @@ public sealed class ItemGridPiece : Control
             return;
         }
 
-        if (_storageController.IsDragging && _storageController.CurrentlyDragging == this)
+        if (_storageController.IsDragging && _storageController.DraggingGhost?.Entity == Entity && _storageController.DraggingGhost != this)
             return;
 
         var adjustedShape = _entityManager.System<ItemSystem>().GetAdjustedItemShape((Entity, itemComponent), Location.Rotation, Vector2i.Zero);
@@ -177,7 +176,7 @@ public sealed class ItemGridPiece : Control
             handle.SetTransform(pos, iconRotation);
             var box = new UIBox2(root, root + sprite.Size * scale);
             handle.DrawTextureRect(sprite, box);
-            handle.SetTransform(Matrix3.Identity);
+            handle.SetTransform(GlobalPixelPosition, Angle.Zero);
         }
         else
         {
index f40a20f2d29bfd3a30d52c3e69e620a167c81fe9..8dfe2fff63b307a5b2012244f75f5592e28de57e 100644 (file)
@@ -445,6 +445,7 @@ public sealed class StorageContainer : BaseWindow
                         _entity.GetNetEntity(handEntity),
                         _entity.GetNetEntity(StorageEntity.Value),
                         insertLocation));
+                    _storageController.DraggingRotation = Angle.Zero;
                     args.Handle();
                 }
             }
index 85631f1aa82fe6dbebe1186bd0e4f35ec3f9089c..c83a80b4a5eeca828d91a609d50d68307defaa16 100644 (file)
@@ -263,29 +263,55 @@ public sealed class StorageUIController : UIController, IOnSystemChanged<Storage
 
     private void OnPieceUnpressed(GUIBoundKeyEventArgs args, ItemGridPiece control)
     {
-        if (_container?.StorageEntity is not { } storageEnt)
+        if (args.Function != ContentKeyFunctions.MoveStoredItem)
             return;
 
-        if (args.Function == ContentKeyFunctions.MoveStoredItem)
+        if (_container?.StorageEntity is not { } storageEnt|| !_entity.TryGetComponent<StorageComponent>(storageEnt, out var storageComp))
+            return;
+
+        if (DraggingGhost is { } draggingGhost)
         {
-            if (DraggingGhost is { } draggingGhost)
+            var dragEnt = draggingGhost.Entity;
+            var dragLoc = draggingGhost.Location;
+            var itemSys = _entity.System<SharedItemSystem>();
+
+            var position = _container.GetMouseGridPieceLocation(dragEnt, dragLoc);
+            var itemBounding = itemSys.GetAdjustedItemShape(dragEnt, dragLoc).GetBoundingBox();
+            var gridBounding = storageComp.Grid.GetBoundingBox();
+
+            // The extended bounding box for if this is out of the window is the grid bounding box dimensions combined
+            // with the item shape bounding box dimensions. Plus 1 on the left for the sidebar. This makes it so that.
+            // dropping an item on the floor requires dragging it all the way out of the window.
+            var left = gridBounding.Left - itemBounding.Width - 1;
+            var bottom = gridBounding.Bottom - itemBounding.Height;
+            var top = gridBounding.Top;
+            var right = gridBounding.Right;
+            var lenientBounding = new Box2i(left, bottom, right, top);
+
+            if (lenientBounding.Contains(position))
             {
-                var position = _container.GetMouseGridPieceLocation(draggingGhost.Entity, draggingGhost.Location);
                 _entity.RaisePredictiveEvent(new StorageSetItemLocationEvent(
                     _entity.GetNetEntity(draggingGhost.Entity),
                     _entity.GetNetEntity(storageEnt),
                     new ItemStorageLocation(DraggingRotation, position)));
-                _container?.BuildItemPieces();
             }
-            else //if we just clicked, then take it out of the bag.
+            else
             {
-                _entity.RaisePredictiveEvent(new StorageInteractWithItemEvent(
-                    _entity.GetNetEntity(control.Entity),
+                _entity.RaisePredictiveEvent(new StorageRemoveItemEvent(
+                    _entity.GetNetEntity(draggingGhost.Entity),
                     _entity.GetNetEntity(storageEnt)));
             }
-            _menuDragHelper.EndDrag();
-            args.Handle();
+
+            _container?.BuildItemPieces();
+        }
+        else //if we just clicked, then take it out of the bag.
+        {
+            _entity.RaisePredictiveEvent(new StorageInteractWithItemEvent(
+                _entity.GetNetEntity(control.Entity),
+                _entity.GetNetEntity(storageEnt)));
         }
+        _menuDragHelper.EndDrag();
+        args.Handle();
     }
 
     private bool OnMenuBeginDrag()
index 57b25e0dd6c7b13ea137403bc0336a69475e43eb..c5a130495d573f788edc4914e4fc2158a43c2797 100644 (file)
@@ -83,6 +83,7 @@ public abstract class SharedStorageSystem : EntitySystem
         SubscribeAllEvent<StorageInteractWithItemEvent>(OnInteractWithItem);
         SubscribeAllEvent<StorageSetItemLocationEvent>(OnSetItemLocation);
         SubscribeAllEvent<StorageInsertItemIntoLocationEvent>(OnInsertItemIntoLocation);
+        SubscribeAllEvent<StorageRemoveItemEvent>(OnRemoveItem);
     }
 
     private void OnComponentInit(EntityUid uid, StorageComponent storageComp, ComponentInit args)
@@ -385,6 +386,34 @@ public abstract class SharedStorageSystem : EntitySystem
         TrySetItemStorageLocation((itemEnt, null), (storageEnt, storageComp), msg.Location);
     }
 
+    private void OnRemoveItem(StorageRemoveItemEvent msg, EntitySessionEventArgs args)
+    {
+        if (args.SenderSession.AttachedEntity is not { } player)
+            return;
+
+        var storageEnt = GetEntity(msg.StorageEnt);
+        var itemEnt = GetEntity(msg.ItemEnt);
+
+        if (!TryComp<StorageComponent>(storageEnt, out var storageComp))
+            return;
+
+        if (!_ui.TryGetUi(storageEnt, StorageComponent.StorageUiKey.Key, out var bui) ||
+            !bui.SubscribedSessions.Contains(args.SenderSession))
+            return;
+
+        if (!Exists(itemEnt))
+        {
+            Log.Error($"Player {args.SenderSession} set location of non-existent item {msg.ItemEnt} stored in {ToPrettyString(storageEnt)}");
+            return;
+        }
+
+        if (!ActionBlocker.CanInteract(player, itemEnt))
+            return;
+
+        TransformSystem.DropNextTo(itemEnt, player);
+        Audio.PlayPredicted(storageComp.StorageRemoveSound, storageEnt, player);
+    }
+
     private void OnInsertItemIntoLocation(StorageInsertItemIntoLocationEvent msg, EntitySessionEventArgs args)
     {
         if (args.SenderSession.AttachedEntity is not { } player)
index f150a3e8fb573635b2c7d134b15f01e385c7c31d..e3287b20ad753f54583ff320f1078c6358d760d1 100644 (file)
@@ -132,6 +132,20 @@ namespace Content.Shared.Storage
         }
     }
 
+    [Serializable, NetSerializable]
+    public sealed class StorageRemoveItemEvent : EntityEventArgs
+    {
+        public readonly NetEntity ItemEnt;
+
+        public readonly NetEntity StorageEnt;
+
+        public StorageRemoveItemEvent(NetEntity itemEnt, NetEntity storageEnt)
+        {
+            ItemEnt = itemEnt;
+            StorageEnt = storageEnt;
+        }
+    }
+
     [Serializable, NetSerializable]
     public sealed class StorageInsertItemIntoLocationEvent : EntityEventArgs
     {