From 0f73ebfee55ddf3f750e1cd648f7621c18202426 Mon Sep 17 00:00:00 2001 From: VMSolidus Date: Thu, 17 Oct 2024 16:39:25 -0400 Subject: [PATCH] Cherry-Pick Wizden PR #27960 (#1067) * fix orphaned storage grid pieces getting stuck to the cursor * instead of denying it, update it smartly # Description This cherry-picks https://github.com/space-wizards/space-station-14/pull/27960 Which should fix our storage UI bugs. Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> --- .../Storage/Controls/StorageContainer.cs | 33 ++++++++++++------- .../Systems/Storage/StorageUIController.cs | 3 +- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Content.Client/UserInterface/Systems/Storage/Controls/StorageContainer.cs b/Content.Client/UserInterface/Systems/Storage/Controls/StorageContainer.cs index e39ac5d322d..a9d7e098265 100644 --- a/Content.Client/UserInterface/Systems/Storage/Controls/StorageContainer.cs +++ b/Content.Client/UserInterface/Systems/Storage/Controls/StorageContainer.cs @@ -254,7 +254,7 @@ public void BuildItemPieces() //todo. at some point, we may want to only rebuild the pieces that have actually received new data. - _pieceGrid.Children.Clear(); + _pieceGrid.RemoveAllChildren(); _pieceGrid.Rows = boundingGrid.Height + 1; _pieceGrid.Columns = boundingGrid.Width + 1; for (var y = boundingGrid.Bottom; y <= boundingGrid.Top; y++) @@ -275,18 +275,29 @@ public void BuildItemPieces() if (_entity.TryGetComponent(itemEnt, out var itemEntComponent)) { - var gridPiece = new ItemGridPiece((itemEnt, itemEntComponent), itemPos, _entity) + ItemGridPiece gridPiece; + + if (_storageController.CurrentlyDragging?.Entity is { } dragging + && dragging == itemEnt) + { + _storageController.CurrentlyDragging.Orphan(); + gridPiece = _storageController.CurrentlyDragging; + } + else { - MinSize = size, - Marked = Array.IndexOf(containedEntities, itemEnt) switch + gridPiece = new ItemGridPiece((itemEnt, itemEntComponent), itemPos, _entity) { - 0 => ItemGridPieceMarks.First, - 1 => ItemGridPieceMarks.Second, - _ => null, - } - }; - gridPiece.OnPiecePressed += OnPiecePressed; - gridPiece.OnPieceUnpressed += OnPieceUnpressed; + MinSize = size, + Marked = Array.IndexOf(containedEntities, itemEnt) switch + { + 0 => ItemGridPieceMarks.First, + 1 => ItemGridPieceMarks.Second, + _ => null, + } + }; + gridPiece.OnPiecePressed += OnPiecePressed; + gridPiece.OnPieceUnpressed += OnPieceUnpressed; + } control.AddChild(gridPiece); } diff --git a/Content.Client/UserInterface/Systems/Storage/StorageUIController.cs b/Content.Client/UserInterface/Systems/Storage/StorageUIController.cs index 346469d29da..97c9d8b7959 100644 --- a/Content.Client/UserInterface/Systems/Storage/StorageUIController.cs +++ b/Content.Client/UserInterface/Systems/Storage/StorageUIController.cs @@ -314,15 +314,16 @@ private void OnPieceUnpressed(GUIBoundKeyEventArgs args, ItemGridPiece control) _entity.GetNetEntity(storageEnt))); } + _menuDragHelper.EndDrag(); _container?.BuildItemPieces(); } else //if we just clicked, then take it out of the bag. { + _menuDragHelper.EndDrag(); _entity.RaisePredictiveEvent(new StorageInteractWithItemEvent( _entity.GetNetEntity(control.Entity), _entity.GetNetEntity(storageEnt))); } - _menuDragHelper.EndDrag(); args.Handle(); }