using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.CustomControls;
-using YamlDotNet.Core;
namespace Content.Client.UserInterface.Systems.Storage.Controls;
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);
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
{
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()
SubscribeAllEvent<StorageInteractWithItemEvent>(OnInteractWithItem);
SubscribeAllEvent<StorageSetItemLocationEvent>(OnSetItemLocation);
SubscribeAllEvent<StorageInsertItemIntoLocationEvent>(OnInsertItemIntoLocation);
+ SubscribeAllEvent<StorageRemoveItemEvent>(OnRemoveItem);
}
private void OnComponentInit(EntityUid uid, StorageComponent storageComp, ComponentInit args)
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)