diff --git a/src/TerraSharp/UI/ItemGrid.cs b/src/TerraSharp/UI/ItemGrid.cs index 46c8209..9597f1b 100644 --- a/src/TerraSharp/UI/ItemGrid.cs +++ b/src/TerraSharp/UI/ItemGrid.cs @@ -25,17 +25,30 @@ public abstract class ItemGrid(string id, string title, Vector2 position, int wi static readonly IItemEntryFilter Weapon = new ItemFilters.Weapon(); - // Journey duplication filters paired with Infinite_Icons frame indices. - static readonly (IItemEntryFilter Filter, int Icon)[] Filters = [(new ItemFilters.Tools(), 6), (new ItemFilters.Armor(), 2), (new ItemFilters.Vanity(), 8), (new ItemFilters.Accessories(), 1), (new ItemFilters.MiscAccessories(), 9), (new ItemFilters.Consumables(), 3), (new ItemFilters.BuildingBlock(), 4), (new ItemFilters.Furniture(), 7), (new ItemFilters.Materials(), 10)]; + // Journey duplication filters paired with Infinite_Icons frame indices; a part without a test holds the rest. + static readonly (IItemEntryFilter Filter, int Icon, (string Name, Func? Fits)[]? Parts)[] Filters = + [ + (new ItemFilters.Tools(), 6, [("Pickaxes", item => item.pick > 0), ("Axes", item => item.axe > 0), ("Hammers", item => item.hammer > 0), ("Fishing", item => item.fishingPole > 0), ("Other", null)]), + (new ItemFilters.Armor(), 2, null), + (new ItemFilters.Vanity(), 8, null), + (new ItemFilters.Accessories(), 1, [("Wings", item => item.wingSlot > 0), ("Boots", item => item.shoeSlot > 0), ("Shields", item => item.shieldSlot > 0), ("Other", null)]), + (new ItemFilters.MiscAccessories(), 9, [("Pets", item => item.buffType > 0 && Main.vanityPet[item.buffType]), ("Light Pets", item => item.buffType > 0 && Main.lightPet[item.buffType]), ("Minecarts", item => item.mountType >= 0 && MountID.Sets.Cart[item.mountType]), ("Mounts", item => item.mountType >= 0 && !MountID.Sets.Cart[item.mountType]), ("Hooks", item => Main.projHook[item.shoot])]), + (new ItemFilters.Consumables(), 3, null), + (new ItemFilters.BuildingBlock(), 4, null), + (new ItemFilters.Furniture(), 7, null), + (new ItemFilters.Materials(), 10, null), + ]; static BrowserCategory[] Categories() => [ new("All", _ => true), new(Language.GetTextValue(Weapon.GetDisplayNameKey()), type => Fits(Weapon, type), 0, [.. Enum.GetValues(typeof(WeaponClass)).Cast().Select(weaponClass => new BrowserCategory(weaponClass.ToString(), type => ContentSample(type) is { } item && ClassOf(item) == weaponClass)), new("Ammo", type => ContentSample(type) is { ammo: > 0 })]), - .. Filters.Select(entry => new BrowserCategory(Language.GetTextValue(entry.Filter.GetDisplayNameKey()), type => Fits(entry.Filter, type), entry.Icon)), + .. Filters.Select(entry => new BrowserCategory(Language.GetTextValue(entry.Filter.GetDisplayNameKey()), type => Fits(entry.Filter, type), entry.Icon, entry.Parts is null ? null : Split(entry.Filter, entry.Parts))), new(Language.GetTextValue("CreativePowers.TabMisc"), type => !Fits(Weapon, type) && !Filters.Any(entry => Fits(entry.Filter, type)), 5), ]; + static BrowserCategory[] Split(IItemEntryFilter filter, (string Name, Func? Fits)[] parts) => [.. parts.Select(part => new BrowserCategory(part.Name, type => ContentSample(type) is { } item && filter.FitsFilter(item) && (part.Fits?.Invoke(item) ?? !parts.Any(other => other.Fits?.Invoke(item) ?? false))))]; + static readonly BrowserSort[] Sorts = [new("Rarity", (a, b) => RarityRank(b).CompareTo(RarityRank(a))), new("Value", (a, b) => (ContentSample(b)?.value ?? 0).CompareTo(ContentSample(a)?.value ?? 0))]; // Expert (-12) and Master (-13) rank above Purple (11); Quest and Gray stay at the bottom.