fix orphaned storage grid pieces getting stuck to the cursor (#27960)

* fix orphaned storage grid pieces getting stuck to the cursor

* instead of denying it, update it smartly
This commit is contained in:
Nemanja
2024-05-17 03:51:28 -04:00
committed by GitHub
parent 157c57a94f
commit 868b6c202d
2 changed files with 24 additions and 12 deletions

View File

@@ -254,7 +254,7 @@ public sealed class StorageContainer : BaseWindow
//todo. at some point, we may want to only rebuild the pieces that have actually received new data. //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.Rows = boundingGrid.Height + 1;
_pieceGrid.Columns = boundingGrid.Width + 1; _pieceGrid.Columns = boundingGrid.Width + 1;
for (var y = boundingGrid.Bottom; y <= boundingGrid.Top; y++) for (var y = boundingGrid.Bottom; y <= boundingGrid.Top; y++)
@@ -275,18 +275,29 @@ public sealed class StorageContainer : BaseWindow
if (_entity.TryGetComponent<ItemComponent>(itemEnt, out var itemEntComponent)) if (_entity.TryGetComponent<ItemComponent>(itemEnt, out var itemEntComponent))
{ {
var gridPiece = new ItemGridPiece((itemEnt, itemEntComponent), itemPos, _entity) ItemGridPiece gridPiece;
if (_storageController.CurrentlyDragging?.Entity is { } dragging
&& dragging == itemEnt)
{ {
MinSize = size, _storageController.CurrentlyDragging.Orphan();
Marked = Array.IndexOf(containedEntities, itemEnt) switch gridPiece = _storageController.CurrentlyDragging;
}
else
{
gridPiece = new ItemGridPiece((itemEnt, itemEntComponent), itemPos, _entity)
{ {
0 => ItemGridPieceMarks.First, MinSize = size,
1 => ItemGridPieceMarks.Second, Marked = Array.IndexOf(containedEntities, itemEnt) switch
_ => null, {
} 0 => ItemGridPieceMarks.First,
}; 1 => ItemGridPieceMarks.Second,
gridPiece.OnPiecePressed += OnPiecePressed; _ => null,
gridPiece.OnPieceUnpressed += OnPieceUnpressed; }
};
gridPiece.OnPiecePressed += OnPiecePressed;
gridPiece.OnPieceUnpressed += OnPieceUnpressed;
}
control.AddChild(gridPiece); control.AddChild(gridPiece);
} }

View File

@@ -314,15 +314,16 @@ public sealed class StorageUIController : UIController, IOnSystemChanged<Storage
_entity.GetNetEntity(storageEnt))); _entity.GetNetEntity(storageEnt)));
} }
_menuDragHelper.EndDrag();
_container?.BuildItemPieces(); _container?.BuildItemPieces();
} }
else //if we just clicked, then take it out of the bag. else //if we just clicked, then take it out of the bag.
{ {
_menuDragHelper.EndDrag();
_entity.RaisePredictiveEvent(new StorageInteractWithItemEvent( _entity.RaisePredictiveEvent(new StorageInteractWithItemEvent(
_entity.GetNetEntity(control.Entity), _entity.GetNetEntity(control.Entity),
_entity.GetNetEntity(storageEnt))); _entity.GetNetEntity(storageEnt)));
} }
_menuDragHelper.EndDrag();
args.Handle(); args.Handle();
} }