Improve layout

This commit is contained in:
Zeffuro
2025-12-20 09:21:44 +01:00
parent 659c295c16
commit 592fa392bf
10 changed files with 449 additions and 65 deletions
+67 -19
View File
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Numerics;
using AetherBags.Extensions;
using AetherBags.Inventory;
using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
using FFXIVClientStructs.FFXIV.Component.GUI;
using KamiToolKit.Classes;
@@ -14,6 +15,15 @@ public class InventoryCategoryNode : SimpleComponentNode
{
private readonly TextNode _categoryNameTextNode;
private readonly HybridDirectionalFlexNode<DragDropNode> _itemGridNode;
private const float ItemSize = 40;
private const float ItemHorizontalPadding = 6;
private const float ItemVerticalPadding = 6;
private const float HeaderHeight = 16;
private const float MinWidth = 40;
private float? _fixedWidth = null;
public InventoryCategoryNode()
{
_categoryNameTextNode = new TextNode
@@ -25,63 +35,101 @@ public class InventoryCategoryNode : SimpleComponentNode
_itemGridNode = new HybridDirectionalFlexNode<DragDropNode>
{
Position = new Vector2(0, 16),
Position = new Vector2(0, HeaderHeight),
Size = new Vector2(240, 100),
FillRowsFirst = true,
ItemsPerLine = 10,
HorizontalPadding = 6,
VerticalPadding = 6,
HorizontalPadding = ItemHorizontalPadding,
VerticalPadding = ItemVerticalPadding,
};
_itemGridNode.AttachNode(this);
}
public required CategoryInfo Category
public required CategorizedInventory CategorizedInventory
{
get;
set
{
field = value;
_categoryNameTextNode.String = value.Name;
_categoryNameTextNode.TextColor = value.Color;
_categoryNameTextNode.TooltipString = value.Description;
_categoryNameTextNode.String = value.Category.Name;
_categoryNameTextNode.TextColor = value.Category.Color;
_categoryNameTextNode.TooltipString = value.Category.Description;
UpdateItemGrid();
RecalculateSize();
}
}
public required List<ItemInfo> Items
public void SetItemsPerLine(int itemsPerLine)
{
get;
set
{
field = value;
_itemGridNode.ItemsPerLine = itemsPerLine;
RecalculateSize();
}
UpdateItemGrid();
public void SetFixedWidth(float width)
{
_fixedWidth = width;
RecalculateSize();
}
private void RecalculateSize()
{
int itemCount = CategorizedInventory.Items.Count;
if (itemCount == 0)
{
float width = _fixedWidth ?? MinWidth;
Size = new Vector2(width, HeaderHeight);
_categoryNameTextNode.Size = _categoryNameTextNode.Size with { X = width };
return;
}
int itemsPerLine = Math.Max(1, _itemGridNode.ItemsPerLine);
int rows = (int)Math.Ceiling((float)itemCount / itemsPerLine);
float calculatedWidth;
if (_fixedWidth. HasValue)
{
calculatedWidth = _fixedWidth.Value;
}
else
{
int actualColumns = Math.Min(itemCount, itemsPerLine);
calculatedWidth = actualColumns * ItemSize + (actualColumns - 1) * ItemHorizontalPadding;
calculatedWidth = Math.Max(calculatedWidth, MinWidth);
}
float height = HeaderHeight + rows * ItemSize + (rows - 1) * ItemVerticalPadding;
Size = new Vector2(calculatedWidth, height);
_itemGridNode.Size = new Vector2(calculatedWidth, height - HeaderHeight);
_categoryNameTextNode.Size = _categoryNameTextNode.Size with { X = calculatedWidth };
}
private bool UpdateItemGrid()
{
var listUpdated = _itemGridNode.SyncWithListData(Items, node => node.ItemInfo, data => CreateInventoryDragDropNode(data));
var listUpdated = _itemGridNode.SyncWithListData(CategorizedInventory.Items, node => node.ItemInfo, CreateInventoryDragDropNode);
return listUpdated;
}
private unsafe InventoryDragDropNode CreateInventoryDragDropNode(ItemInfo data)
private InventoryDragDropNode CreateInventoryDragDropNode(ItemInfo data)
{
InventoryItem item = data.Item;
InventoryDragDropNode node = new InventoryDragDropNode
{
Size = new Vector2(40),
IsVisible = true,
IconId = data.IconId,
IconId = item.IconId,
AcceptedType = DragDropType.Nothing,
IsDraggable = false,
Payload = new DragDropPayload
{
Type = DragDropType.Item,
Int1 = (int)data.Item.Container,
Int2 = (int)data.Item.ItemId,
Int1 = (int)item.Container,
Int2 = (int)item.ItemId,
},
IsClickable = true,
OnRollOver = node => node.ShowInventoryItemTooltip(data.Item.Container, data.Item.Slot),
OnRollOver = node => node.ShowInventoryItemTooltip(item.Container, item.Slot),
OnRollOut = node => node.HideTooltip(),
ItemInfo = data
};