Grid inventory fixes (#22161)

* Gridinv fixes

* eek

* oh yeah this too

* eek
This commit is contained in:
Nemanja
2023-12-05 18:38:10 -05:00
committed by GitHub
parent 000ac6f63d
commit 9ca84ac3fb
10 changed files with 136 additions and 46 deletions

View File

@@ -1,9 +1,7 @@
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;
@@ -12,8 +10,7 @@ namespace Content.Client.UserInterface.Systems.Storage.Controls;
public sealed class ItemGridPiece : Control
{
private readonly ItemSystem _itemSystem;
private readonly SpriteSystem _spriteSystem;
private readonly IEntityManager _entityManager;
private readonly StorageUIController _storageController;
private readonly List<(Texture, Vector2)> _texturesPositions = new();
@@ -49,8 +46,7 @@ public sealed class ItemGridPiece : Control
{
IoCManager.InjectDependencies(this);
_itemSystem = entityManager.System<ItemSystem>();
_spriteSystem = entityManager.System<SpriteSystem>();
_entityManager = entityManager;
_storageController = UserInterfaceManager.GetUIController<StorageUIController>();
Entity = entity.Owner;
@@ -81,10 +77,17 @@ public sealed class ItemGridPiece : Control
{
base.Draw(handle);
// really just an "oh shit" catch.
if (!_entityManager.EntityExists(Entity))
{
Dispose();
return;
}
if (_storageController.IsDragging && _storageController.CurrentlyDragging == this)
return;
var adjustedShape = _itemSystem.GetAdjustedItemShape((Entity, null), Location.Rotation, Vector2i.Zero);
var adjustedShape = _entityManager.System<ItemSystem>().GetAdjustedItemShape((Entity, null), Location.Rotation, Vector2i.Zero);
var boundingGrid = adjustedShape.GetBoundingBox();
var size = _centerTexture!.Size * 2 * UIScale;
@@ -130,7 +133,7 @@ public sealed class ItemGridPiece : Control
var iconOffset = new Vector2((boundingGrid.Width + 1) * size.X ,
(boundingGrid.Height + 1) * size.Y);
_spriteSystem.ForceUpdate(Entity);
_entityManager.System<SpriteSystem>().ForceUpdate(Entity);
handle.DrawEntity(Entity,
PixelPosition + iconOffset,
Vector2.One * 2 * UIScale,

View File

@@ -34,6 +34,10 @@ public sealed class StorageContainer : BaseWindow
private Texture? _emptyTexture;
private readonly string _blockedTexturePath = "Storage/tile_blocked";
private Texture? _blockedTexture;
private readonly string _emptyOpaqueTexturePath = "Storage/tile_empty_opaque";
private Texture? _emptyOpaqueTexture;
private readonly string _blockedOpaqueTexturePath = "Storage/tile_blocked_opaque";
private Texture? _blockedOpaqueTexture;
private readonly string _exitTexturePath = "Storage/exit";
private Texture? _exitTexture;
private readonly string _backTexturePath = "Storage/back";
@@ -109,6 +113,8 @@ public sealed class StorageContainer : BaseWindow
_emptyTexture = Theme.ResolveTextureOrNull(_emptyTexturePath)?.Texture;
_blockedTexture = Theme.ResolveTextureOrNull(_blockedTexturePath)?.Texture;
_emptyOpaqueTexture = Theme.ResolveTextureOrNull(_emptyOpaqueTexturePath)?.Texture;
_blockedOpaqueTexture = Theme.ResolveTextureOrNull(_blockedOpaqueTexturePath)?.Texture;
_exitTexture = Theme.ResolveTextureOrNull(_exitTexturePath)?.Texture;
_backTexture = Theme.ResolveTextureOrNull(_backTexturePath)?.Texture;
_sidebarTopTexture = Theme.ResolveTextureOrNull(_sidebarTopTexturePath)?.Texture;
@@ -124,35 +130,17 @@ public sealed class StorageContainer : BaseWindow
if (entity == null)
return;
BuildGridRepresentation(entity.Value);
BuildGridRepresentation();
}
private void BuildGridRepresentation(Entity<StorageComponent> entity)
private void BuildGridRepresentation()
{
var comp = entity.Comp;
if (!comp.Grid.Any())
if (!_entity.TryGetComponent<StorageComponent>(StorageEntity, out var comp) || !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)
});
}
}
BuildBackground();
#region Sidebar
_sidebar.Children.Clear();
@@ -209,6 +197,40 @@ public sealed class StorageContainer : BaseWindow
BuildItemPieces();
}
public void BuildBackground()
{
if (!_entity.TryGetComponent<StorageComponent>(StorageEntity, out var comp) || !comp.Grid.Any())
return;
var boundingGrid = comp.Grid.GetBoundingBox();
var emptyTexture = _storageController.OpaqueStorageWindow
? _emptyOpaqueTexture
: _emptyTexture;
var blockedTexture = _storageController.OpaqueStorageWindow
? _blockedOpaqueTexture
: _blockedTexture;
_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)
});
}
}
}
public void BuildItemPieces()
{
if (!_entity.TryGetComponent<StorageComponent>(StorageEntity, out var storageComp))
@@ -320,7 +342,7 @@ public sealed class StorageContainer : BaseWindow
origin,
currentLocation.Rotation);
var validColor = usingInHand ? Color.Goldenrod : Color.Green;
var validColor = usingInHand ? Color.Goldenrod : Color.FromHex("#1E8000");
for (var y = itemBounding.Bottom; y <= itemBounding.Top; y++)
{
@@ -328,7 +350,7 @@ public sealed class StorageContainer : BaseWindow
{
if (TryGetBackgroundCell(x, y, out var cell) && itemShape.Contains(x, y))
{
cell.ModulateSelfOverride = validLocation ? validColor : Color.Red;
cell.ModulateSelfOverride = validLocation ? validColor : Color.FromHex("#B40046");
}
}
}