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:
@@ -0,0 +1,220 @@
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Content.Client.Items.Systems;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Storage;
|
||||
using Content.Shared.Storage.EntitySystems;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
|
||||
namespace Content.Client.UserInterface.Systems.Storage.Controls;
|
||||
|
||||
public sealed class ItemGridPiece : Control
|
||||
{
|
||||
private readonly ItemSystem _itemSystem;
|
||||
private readonly SpriteSystem _spriteSystem;
|
||||
private readonly StorageUIController _storageController;
|
||||
|
||||
private readonly List<(Texture, Vector2)> _texturesPositions = new();
|
||||
|
||||
public readonly EntityUid Entity;
|
||||
public ItemStorageLocation Location;
|
||||
|
||||
public event Action<GUIBoundKeyEventArgs, ItemGridPiece>? OnPiecePressed;
|
||||
public event Action<GUIBoundKeyEventArgs, ItemGridPiece>? OnPieceUnpressed;
|
||||
|
||||
#region Textures
|
||||
private readonly string _centerTexturePath = "Storage/piece_center";
|
||||
private Texture? _centerTexture;
|
||||
private readonly string _topTexturePath = "Storage/piece_top";
|
||||
private Texture? _topTexture;
|
||||
private readonly string _bottomTexturePath = "Storage/piece_bottom";
|
||||
private Texture? _bottomTexture;
|
||||
private readonly string _leftTexturePath = "Storage/piece_left";
|
||||
private Texture? _leftTexture;
|
||||
private readonly string _rightTexturePath = "Storage/piece_right";
|
||||
private Texture? _rightTexture;
|
||||
private readonly string _topLeftTexturePath = "Storage/piece_topLeft";
|
||||
private Texture? _topLeftTexture;
|
||||
private readonly string _topRightTexturePath = "Storage/piece_topRight";
|
||||
private Texture? _topRightTexture;
|
||||
private readonly string _bottomLeftTexturePath = "Storage/piece_bottomLeft";
|
||||
private Texture? _bottomLeftTexture;
|
||||
private readonly string _bottomRightTexturePath = "Storage/piece_bottomRight";
|
||||
private Texture? _bottomRightTexture;
|
||||
#endregion
|
||||
|
||||
public ItemGridPiece(Entity<ItemComponent> entity, ItemStorageLocation location, IEntityManager entityManager)
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
_itemSystem = entityManager.System<ItemSystem>();
|
||||
_spriteSystem = entityManager.System<SpriteSystem>();
|
||||
_storageController = UserInterfaceManager.GetUIController<StorageUIController>();
|
||||
|
||||
Entity = entity.Owner;
|
||||
Location = location;
|
||||
|
||||
Visible = true;
|
||||
MouseFilter = MouseFilterMode.Pass;
|
||||
|
||||
OnThemeUpdated();
|
||||
}
|
||||
|
||||
protected override void OnThemeUpdated()
|
||||
{
|
||||
base.OnThemeUpdated();
|
||||
|
||||
_centerTexture = Theme.ResolveTextureOrNull(_centerTexturePath)?.Texture;
|
||||
_topTexture = Theme.ResolveTextureOrNull(_topTexturePath)?.Texture;
|
||||
_bottomTexture = Theme.ResolveTextureOrNull(_bottomTexturePath)?.Texture;
|
||||
_leftTexture = Theme.ResolveTextureOrNull(_leftTexturePath)?.Texture;
|
||||
_rightTexture = Theme.ResolveTextureOrNull(_rightTexturePath)?.Texture;
|
||||
_topLeftTexture = Theme.ResolveTextureOrNull(_topLeftTexturePath)?.Texture;
|
||||
_topRightTexture = Theme.ResolveTextureOrNull(_topRightTexturePath)?.Texture;
|
||||
_bottomLeftTexture = Theme.ResolveTextureOrNull(_bottomLeftTexturePath)?.Texture;
|
||||
_bottomRightTexture = Theme.ResolveTextureOrNull(_bottomRightTexturePath)?.Texture;
|
||||
}
|
||||
|
||||
protected override void Draw(DrawingHandleScreen handle)
|
||||
{
|
||||
base.Draw(handle);
|
||||
|
||||
if (_storageController.IsDragging && _storageController.CurrentlyDragging == this)
|
||||
return;
|
||||
|
||||
var adjustedShape = _itemSystem.GetAdjustedItemShape((Entity, null), Location.Rotation, Vector2i.Zero);
|
||||
var boundingGrid = adjustedShape.GetBoundingBox();
|
||||
var size = _centerTexture!.Size * 2 * UIScale;
|
||||
|
||||
var hovering = !_storageController.IsDragging && UserInterfaceManager.CurrentlyHovered == this;
|
||||
//yeah, this coloring is kinda hardcoded. deal with it. B)
|
||||
Color? colorModulate = hovering ? null : Color.FromHex("#a8a8a8");
|
||||
|
||||
_texturesPositions.Clear();
|
||||
for (var y = boundingGrid.Bottom; y <= boundingGrid.Top; y++)
|
||||
{
|
||||
for (var x = boundingGrid.Left; x <= boundingGrid.Right; x++)
|
||||
{
|
||||
if (!adjustedShape.Contains(x, y))
|
||||
continue;
|
||||
|
||||
var offset = size * 2 * new Vector2(x - boundingGrid.Left, y - boundingGrid.Bottom);
|
||||
var topLeft = PixelPosition + offset.Floored();
|
||||
|
||||
if (GetTexture(adjustedShape, new Vector2i(x, y), Direction.NorthEast) is {} neTexture)
|
||||
{
|
||||
var neOffset = new Vector2(size.X, 0);
|
||||
handle.DrawTextureRect(neTexture, new UIBox2(topLeft + neOffset, topLeft + neOffset + size), colorModulate);
|
||||
}
|
||||
if (GetTexture(adjustedShape, new Vector2i(x, y), Direction.NorthWest) is {} nwTexture)
|
||||
{
|
||||
_texturesPositions.Add((nwTexture, Position + offset / UIScale));
|
||||
handle.DrawTextureRect(nwTexture, new UIBox2(topLeft, topLeft + size), colorModulate);
|
||||
}
|
||||
if (GetTexture(adjustedShape, new Vector2i(x, y), Direction.SouthEast) is {} seTexture)
|
||||
{
|
||||
var seOffset = size;
|
||||
handle.DrawTextureRect(seTexture, new UIBox2(topLeft + seOffset, topLeft + seOffset + size), colorModulate);
|
||||
}
|
||||
if (GetTexture(adjustedShape, new Vector2i(x, y), Direction.SouthWest) is {} swTexture)
|
||||
{
|
||||
var swOffset = new Vector2(0, size.Y);
|
||||
handle.DrawTextureRect(swTexture, new UIBox2(topLeft + swOffset, topLeft + swOffset + size), colorModulate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// typically you'd divide by two, but since the textures are half a tile, this is done implicitly
|
||||
var iconOffset = new Vector2((boundingGrid.Width + 1) * size.X ,
|
||||
(boundingGrid.Height + 1) * size.Y);
|
||||
|
||||
_spriteSystem.ForceUpdate(Entity);
|
||||
handle.DrawEntity(Entity,
|
||||
PixelPosition + iconOffset,
|
||||
Vector2.One * 2 * UIScale,
|
||||
Angle.Zero,
|
||||
overrideDirection: Direction.South);
|
||||
}
|
||||
|
||||
protected override bool HasPoint(Vector2 point)
|
||||
{
|
||||
foreach (var (texture, position) in _texturesPositions)
|
||||
{
|
||||
if (!new Box2(position, position + texture.Size * 4).Contains(point))
|
||||
continue;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override void KeyBindDown(GUIBoundKeyEventArgs args)
|
||||
{
|
||||
base.KeyBindDown(args);
|
||||
|
||||
OnPiecePressed?.Invoke(args, this);
|
||||
}
|
||||
|
||||
protected override void KeyBindUp(GUIBoundKeyEventArgs args)
|
||||
{
|
||||
base.KeyBindUp(args);
|
||||
|
||||
OnPieceUnpressed?.Invoke(args, this);
|
||||
}
|
||||
|
||||
private Texture? GetTexture(IReadOnlyList<Box2i> boxes, Vector2i position, Direction corner)
|
||||
{
|
||||
var top = !boxes.Contains(position - Vector2i.Up);
|
||||
var bottom = !boxes.Contains(position - Vector2i.Down);
|
||||
var left = !boxes.Contains(position + Vector2i.Left);
|
||||
var right = !boxes.Contains(position + Vector2i.Right);
|
||||
|
||||
switch (corner)
|
||||
{
|
||||
case Direction.NorthEast:
|
||||
if (top && right)
|
||||
return _topRightTexture;
|
||||
if (top)
|
||||
return _topTexture;
|
||||
if (right)
|
||||
return _rightTexture;
|
||||
return _centerTexture;
|
||||
case Direction.NorthWest:
|
||||
if (top && left)
|
||||
return _topLeftTexture;
|
||||
if (top)
|
||||
return _topTexture;
|
||||
if (left)
|
||||
return _leftTexture;
|
||||
return _centerTexture;
|
||||
case Direction.SouthEast:
|
||||
if (bottom && right)
|
||||
return _bottomRightTexture;
|
||||
if (bottom)
|
||||
return _bottomTexture;
|
||||
if (right)
|
||||
return _rightTexture;
|
||||
return _centerTexture;
|
||||
case Direction.SouthWest:
|
||||
if (bottom && left)
|
||||
return _bottomLeftTexture;
|
||||
if (bottom)
|
||||
return _bottomTexture;
|
||||
if (left)
|
||||
return _leftTexture;
|
||||
return _centerTexture;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector2 GetCenterOffset(Entity<ItemComponent?> entity, ItemStorageLocation location, IEntityManager entMan)
|
||||
{
|
||||
var boxSize = entMan.System<ItemSystem>().GetAdjustedItemShape(entity, location).GetBoundingBox().Size;
|
||||
var actualSize = new Vector2(boxSize.X + 1, boxSize.Y + 1);
|
||||
return actualSize * new Vector2i(8, 8);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,431 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Content.Client.Hands.Systems;
|
||||
using Content.Client.Items.Systems;
|
||||
using Content.Client.Storage.Systems;
|
||||
using Content.Shared.Input;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Storage;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.UserInterface.Systems.Storage.Controls;
|
||||
|
||||
public sealed class StorageContainer : BaseWindow
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entity = default!;
|
||||
private readonly StorageUIController _storageController;
|
||||
|
||||
public EntityUid? StorageEntity;
|
||||
|
||||
private readonly GridContainer _pieceGrid;
|
||||
private readonly GridContainer _backgroundGrid;
|
||||
private readonly GridContainer _sidebar;
|
||||
|
||||
public event Action<GUIBoundKeyEventArgs, ItemGridPiece>? OnPiecePressed;
|
||||
public event Action<GUIBoundKeyEventArgs, ItemGridPiece>? OnPieceUnpressed;
|
||||
|
||||
private readonly string _emptyTexturePath = "Storage/tile_empty";
|
||||
private Texture? _emptyTexture;
|
||||
private readonly string _blockedTexturePath = "Storage/tile_blocked";
|
||||
private Texture? _blockedTexture;
|
||||
private readonly string _exitTexturePath = "Storage/exit";
|
||||
private Texture? _exitTexture;
|
||||
private readonly string _backTexturePath = "Storage/back";
|
||||
private Texture? _backTexture;
|
||||
private readonly string _sidebarTopTexturePath = "Storage/sidebar_top";
|
||||
private Texture? _sidebarTopTexture;
|
||||
private readonly string _sidebarMiddleTexturePath = "Storage/sidebar_mid";
|
||||
private Texture? _sidebarMiddleTexture;
|
||||
private readonly string _sidebarBottomTexturePath = "Storage/sidebar_bottom";
|
||||
private Texture? _sidebarBottomTexture;
|
||||
private readonly string _sidebarFatTexturePath = "Storage/sidebar_fat";
|
||||
private Texture? _sidebarFatTexture;
|
||||
|
||||
public StorageContainer()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
_storageController = UserInterfaceManager.GetUIController<StorageUIController>();
|
||||
|
||||
OnThemeUpdated();
|
||||
|
||||
MouseFilter = MouseFilterMode.Stop;
|
||||
|
||||
_sidebar = new GridContainer
|
||||
{
|
||||
HSeparationOverride = 0,
|
||||
VSeparationOverride = 0,
|
||||
Columns = 1
|
||||
};
|
||||
|
||||
_pieceGrid = new GridContainer
|
||||
{
|
||||
HSeparationOverride = 0,
|
||||
VSeparationOverride = 0
|
||||
};
|
||||
|
||||
_backgroundGrid = new GridContainer
|
||||
{
|
||||
HSeparationOverride = 0,
|
||||
VSeparationOverride = 0
|
||||
};
|
||||
|
||||
var container = new BoxContainer
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Vertical,
|
||||
Children =
|
||||
{
|
||||
new BoxContainer
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Horizontal,
|
||||
Children =
|
||||
{
|
||||
_sidebar,
|
||||
new Control
|
||||
{
|
||||
Children =
|
||||
{
|
||||
_backgroundGrid,
|
||||
_pieceGrid
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
AddChild(container);
|
||||
}
|
||||
|
||||
protected override void OnThemeUpdated()
|
||||
{
|
||||
base.OnThemeUpdated();
|
||||
|
||||
_emptyTexture = Theme.ResolveTextureOrNull(_emptyTexturePath)?.Texture;
|
||||
_blockedTexture = Theme.ResolveTextureOrNull(_blockedTexturePath)?.Texture;
|
||||
_exitTexture = Theme.ResolveTextureOrNull(_exitTexturePath)?.Texture;
|
||||
_backTexture = Theme.ResolveTextureOrNull(_backTexturePath)?.Texture;
|
||||
_sidebarTopTexture = Theme.ResolveTextureOrNull(_sidebarTopTexturePath)?.Texture;
|
||||
_sidebarMiddleTexture = Theme.ResolveTextureOrNull(_sidebarMiddleTexturePath)?.Texture;
|
||||
_sidebarBottomTexture = Theme.ResolveTextureOrNull(_sidebarBottomTexturePath)?.Texture;
|
||||
_sidebarFatTexture = Theme.ResolveTextureOrNull(_sidebarFatTexturePath)?.Texture;
|
||||
}
|
||||
|
||||
public void UpdateContainer(Entity<StorageComponent>? entity)
|
||||
{
|
||||
Visible = entity != null;
|
||||
StorageEntity = entity;
|
||||
if (entity == null)
|
||||
return;
|
||||
|
||||
BuildGridRepresentation(entity.Value);
|
||||
}
|
||||
|
||||
private void BuildGridRepresentation(Entity<StorageComponent> entity)
|
||||
{
|
||||
var comp = entity.Comp;
|
||||
if (!comp.Grid.Any())
|
||||
return;
|
||||
|
||||
var boundingGrid = comp.Grid.GetBoundingBox();
|
||||
|
||||
_backgroundGrid.Children.Clear();
|
||||
_backgroundGrid.Rows = boundingGrid.Height + 1;
|
||||
_backgroundGrid.Columns = boundingGrid.Width + 1;
|
||||
for (var y = boundingGrid.Bottom; y <= boundingGrid.Top; y++)
|
||||
{
|
||||
for (var x = boundingGrid.Left; x <= boundingGrid.Right; x++)
|
||||
{
|
||||
var texture = comp.Grid.Contains(x, y)
|
||||
? _emptyTexture
|
||||
: _blockedTexture;
|
||||
|
||||
_backgroundGrid.AddChild(new TextureRect
|
||||
{
|
||||
Texture = texture,
|
||||
TextureScale = new Vector2(2, 2)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#region Sidebar
|
||||
_sidebar.Children.Clear();
|
||||
_sidebar.Rows = boundingGrid.Height + 1;
|
||||
var exitButton = new TextureButton
|
||||
{
|
||||
TextureNormal = _entity.System<StorageSystem>().OpenStorageAmount == 1
|
||||
?_exitTexture
|
||||
: _backTexture,
|
||||
Scale = new Vector2(2, 2),
|
||||
};
|
||||
exitButton.OnPressed += _ =>
|
||||
{
|
||||
Close();
|
||||
};
|
||||
var exitContainer = new BoxContainer
|
||||
{
|
||||
Children =
|
||||
{
|
||||
new TextureRect
|
||||
{
|
||||
Texture = boundingGrid.Height != 0
|
||||
? _sidebarTopTexture
|
||||
: _sidebarFatTexture,
|
||||
TextureScale = new Vector2(2, 2),
|
||||
Children =
|
||||
{
|
||||
exitButton
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
_sidebar.AddChild(exitContainer);
|
||||
for (var i = 0; i < boundingGrid.Height - 1; i++)
|
||||
{
|
||||
_sidebar.AddChild(new TextureRect
|
||||
{
|
||||
Texture = _sidebarMiddleTexture,
|
||||
TextureScale = new Vector2(2, 2),
|
||||
});
|
||||
}
|
||||
|
||||
if (boundingGrid.Height > 0)
|
||||
{
|
||||
_sidebar.AddChild(new TextureRect
|
||||
{
|
||||
Texture = _sidebarBottomTexture,
|
||||
TextureScale = new Vector2(2, 2),
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
BuildItemPieces();
|
||||
}
|
||||
|
||||
public void BuildItemPieces()
|
||||
{
|
||||
if (!_entity.TryGetComponent<StorageComponent>(StorageEntity, out var storageComp))
|
||||
return;
|
||||
|
||||
if (!storageComp.Grid.Any())
|
||||
return;
|
||||
|
||||
var boundingGrid = storageComp.Grid.GetBoundingBox();
|
||||
var size = _emptyTexture!.Size * 2;
|
||||
|
||||
//todo. at some point, we may want to only rebuild the pieces that have actually received new data.
|
||||
|
||||
_pieceGrid.Children.Clear();
|
||||
_pieceGrid.Rows = boundingGrid.Height + 1;
|
||||
_pieceGrid.Columns = boundingGrid.Width + 1;
|
||||
for (var y = boundingGrid.Bottom; y <= boundingGrid.Top; y++)
|
||||
{
|
||||
for (var x = boundingGrid.Left; x <= boundingGrid.Right; x++)
|
||||
{
|
||||
var currentPosition = new Vector2i(x, y);
|
||||
var item = storageComp.StoredItems
|
||||
.Where(pair => pair.Value.Position == currentPosition)
|
||||
.FirstOrNull();
|
||||
|
||||
var control = new Control
|
||||
{
|
||||
MinSize = size
|
||||
};
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
var itemEnt = _entity.GetEntity(item.Value.Key);
|
||||
|
||||
if (_entity.TryGetComponent<ItemComponent>(itemEnt, out var itemEntComponent))
|
||||
{
|
||||
var gridPiece = new ItemGridPiece((itemEnt, itemEntComponent), item.Value.Value, _entity)
|
||||
{
|
||||
MinSize = size,
|
||||
};
|
||||
gridPiece.OnPiecePressed += OnPiecePressed;
|
||||
gridPiece.OnPieceUnpressed += OnPieceUnpressed;
|
||||
|
||||
control.AddChild(gridPiece);
|
||||
}
|
||||
}
|
||||
|
||||
_pieceGrid.AddChild(control);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void FrameUpdate(FrameEventArgs args)
|
||||
{
|
||||
base.FrameUpdate(args);
|
||||
|
||||
if (!IsOpen)
|
||||
return;
|
||||
|
||||
var itemSystem = _entity.System<ItemSystem>();
|
||||
var storageSystem = _entity.System<StorageSystem>();
|
||||
var handsSystem = _entity.System<HandsSystem>();
|
||||
|
||||
foreach (var child in _backgroundGrid.Children)
|
||||
{
|
||||
child.ModulateSelfOverride = Color.FromHex("#222222");
|
||||
}
|
||||
|
||||
if (UserInterfaceManager.CurrentlyHovered is StorageContainer con && con != this)
|
||||
return;
|
||||
|
||||
if (!_entity.TryGetComponent<StorageComponent>(StorageEntity, out var storageComponent))
|
||||
return;
|
||||
|
||||
EntityUid currentEnt;
|
||||
ItemStorageLocation currentLocation;
|
||||
var usingInHand = false;
|
||||
if (_storageController.IsDragging && _storageController.DraggingGhost is { } dragging)
|
||||
{
|
||||
currentEnt = dragging.Entity;
|
||||
currentLocation = dragging.Location;
|
||||
}
|
||||
else if (handsSystem.GetActiveHandEntity() is { } handEntity &&
|
||||
storageSystem.CanInsert(StorageEntity.Value, handEntity, out _, storageComp: storageComponent, ignoreLocation: true))
|
||||
{
|
||||
currentEnt = handEntity;
|
||||
currentLocation = new ItemStorageLocation(_storageController.DraggingRotation, Vector2i.Zero);
|
||||
usingInHand = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_entity.TryGetComponent<ItemComponent>(currentEnt, out var itemComp))
|
||||
return;
|
||||
|
||||
var origin = GetMouseGridPieceLocation((currentEnt, itemComp), currentLocation);
|
||||
|
||||
var itemShape = itemSystem.GetAdjustedItemShape(
|
||||
(currentEnt, itemComp),
|
||||
currentLocation.Rotation,
|
||||
origin);
|
||||
var itemBounding = itemShape.GetBoundingBox();
|
||||
|
||||
var validLocation = storageSystem.ItemFitsInGridLocation(
|
||||
(currentEnt, itemComp),
|
||||
(StorageEntity.Value, storageComponent),
|
||||
origin,
|
||||
currentLocation.Rotation);
|
||||
|
||||
var validColor = usingInHand ? Color.Goldenrod : Color.Green;
|
||||
|
||||
for (var y = itemBounding.Bottom; y <= itemBounding.Top; y++)
|
||||
{
|
||||
for (var x = itemBounding.Left; x <= itemBounding.Right; x++)
|
||||
{
|
||||
if (TryGetBackgroundCell(x, y, out var cell) && itemShape.Contains(x, y))
|
||||
{
|
||||
cell.ModulateSelfOverride = validLocation ? validColor : Color.Red;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override DragMode GetDragModeFor(Vector2 relativeMousePos)
|
||||
{
|
||||
if (_storageController.StaticStorageUIEnabled)
|
||||
return DragMode.None;
|
||||
|
||||
if (_sidebar.SizeBox.Contains(relativeMousePos - _sidebar.Position))
|
||||
{
|
||||
return DragMode.Move;
|
||||
}
|
||||
|
||||
return DragMode.None;
|
||||
}
|
||||
|
||||
public Vector2i GetMouseGridPieceLocation(Entity<ItemComponent?> entity, ItemStorageLocation location)
|
||||
{
|
||||
var origin = Vector2i.Zero;
|
||||
|
||||
if (StorageEntity != null)
|
||||
origin = _entity.GetComponent<StorageComponent>(StorageEntity.Value).Grid.GetBoundingBox().BottomLeft;
|
||||
|
||||
var textureSize = (Vector2) _emptyTexture!.Size * 2;
|
||||
var position = ((UserInterfaceManager.MousePositionScaled.Position
|
||||
- _backgroundGrid.GlobalPosition
|
||||
- ItemGridPiece.GetCenterOffset(entity, location, _entity) * 2
|
||||
+ textureSize / 2f)
|
||||
/ textureSize).Floored() + origin;
|
||||
return position;
|
||||
}
|
||||
|
||||
public bool TryGetBackgroundCell(int x, int y, [NotNullWhen(true)] out Control? cell)
|
||||
{
|
||||
cell = null;
|
||||
|
||||
if (!_entity.TryGetComponent<StorageComponent>(StorageEntity, out var storageComponent))
|
||||
return false;
|
||||
var boundingBox = storageComponent.Grid.GetBoundingBox();
|
||||
x -= boundingBox.Left;
|
||||
y -= boundingBox.Bottom;
|
||||
|
||||
if (x < 0 ||
|
||||
x >= _backgroundGrid.Columns ||
|
||||
y < 0 ||
|
||||
y >= _backgroundGrid.Rows)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
cell = _backgroundGrid.GetChild(y * _backgroundGrid.Columns + x);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void KeyBindDown(GUIBoundKeyEventArgs args)
|
||||
{
|
||||
base.KeyBindDown(args);
|
||||
|
||||
if (!IsOpen)
|
||||
return;
|
||||
|
||||
var storageSystem = _entity.System<StorageSystem>();
|
||||
var handsSystem = _entity.System<HandsSystem>();
|
||||
|
||||
if (args.Function == ContentKeyFunctions.MoveStoredItem && StorageEntity != null)
|
||||
{
|
||||
if (handsSystem.GetActiveHandEntity() is { } handEntity &&
|
||||
storageSystem.CanInsert(StorageEntity.Value, handEntity, out _))
|
||||
{
|
||||
var pos = GetMouseGridPieceLocation((handEntity, null),
|
||||
new ItemStorageLocation(_storageController.DraggingRotation, Vector2i.Zero));
|
||||
|
||||
var insertLocation = new ItemStorageLocation(_storageController.DraggingRotation, pos);
|
||||
if (storageSystem.ItemFitsInGridLocation(
|
||||
(handEntity, null),
|
||||
(StorageEntity.Value, null),
|
||||
insertLocation))
|
||||
{
|
||||
_entity.RaisePredictiveEvent(new StorageInsertItemIntoLocationEvent(
|
||||
_entity.GetNetEntity(handEntity),
|
||||
_entity.GetNetEntity(StorageEntity.Value),
|
||||
insertLocation));
|
||||
args.Handle();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
base.Close();
|
||||
|
||||
if (StorageEntity == null)
|
||||
return;
|
||||
|
||||
_entity.System<StorageSystem>().CloseStorageUI(StorageEntity.Value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user