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
@@ -0,0 +1,5 @@
using System.Collections.Generic;
namespace AetherBags.Inventory;
public readonly record struct CategorizedInventory(CategoryInfo Category, List<ItemInfo> Items);
+48
View File
@@ -3,6 +3,7 @@ using System.Linq;
using Dalamud.Game.Inventory;
using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
using Lumina.Excel.Sheets;
namespace AetherBags.Inventory;
@@ -34,6 +35,22 @@ public static unsafe class InventoryState
public static bool Contains(this List<InventoryType> inventoryTypes, GameInventoryType type)
=> inventoryTypes.Contains((InventoryType)type);
public static List<CategorizedInventory> GetInventoryItemCategories()
{
var items = GetInventoryItems();
return items
.GroupBy(GetItemUiCategoryKey)
.OrderBy(g => g.Key)
.Select(g =>
{
var category = GetCategoryInfoForKey(g.Key, g.FirstOrDefault());
var list = g.OrderByDescending(i => i.ItemCount).ToList();
return new CategorizedInventory(category, list);
})
.ToList();
}
public static List<ItemInfo> GetInventoryItems() {
List<InventoryType> inventories = [ InventoryType.Inventory1, InventoryType.Inventory2, InventoryType.Inventory3, InventoryType.Inventory4 ];
List<InventoryItem> items = [];
@@ -60,4 +77,35 @@ public static unsafe class InventoryState
return itemInfos;
}
public static List<ItemInfo> GetInventoryItems(string filterString, bool invert = false)
=> GetInventoryItems().Where(item => item.IsRegexMatch(filterString) != invert).ToList();
private static uint GetItemUiCategoryKey(ItemInfo info)
=> info.UiCategory.RowId;
private static CategoryInfo GetCategoryInfoForKey(uint key, ItemInfo? sample)
{
if (key == 0)
{
return new CategoryInfo
{
Name = "Misc",
Description = "Uncategorized items",
};
}
var uiCat = sample?.UiCategory.Value;
var name = uiCat?.Name.ToString();
if (string.IsNullOrWhiteSpace(name))
name = $"Category\\ {key}";
return new CategoryInfo
{
Name = name,
};
}
}
+2 -1
View File
@@ -3,6 +3,7 @@ using System.Numerics;
using System.Text.RegularExpressions;
using AetherBags.Extensions;
using FFXIVClientStructs.FFXIV.Client.Game;
using Lumina.Excel;
using Lumina.Excel.Sheets;
namespace AetherBags.Inventory;
@@ -25,7 +26,7 @@ public class ItemInfo : IEquatable<ItemInfo> {
public int Rarity => ItemData.Rarity;
public int UiCategory => (int) ItemData.ItemUICategory.RowId;
public RowRef<ItemUICategory> UiCategory => ItemData.ItemUICategory;
private string Description => ItemData.Description.ToString();