From 2825621d0a7a7bd5cf6f661d2163afe929045590 Mon Sep 17 00:00:00 2001 From: Samuel Bouchet Date: Tue, 10 Mar 2026 20:01:11 +0100 Subject: [PATCH] Group duplicate boxes and inventory items with count display Box selection and inventory now show "Boite pas ouf (x4)" instead of listing each instance separately. Picks the first instance of the selected type when opening. --- src/OpenTheBox/Program.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/OpenTheBox/Program.cs b/src/OpenTheBox/Program.cs index f325ea3..15ab677 100644 --- a/src/OpenTheBox/Program.cs +++ b/src/OpenTheBox/Program.cs @@ -212,13 +212,19 @@ public static class Program return; } - var boxNames = boxes.Select(b => GetLocalizedName(b.DefinitionId)).ToList(); + // Group boxes by type so the list isn't bloated with duplicates + var grouped = boxes.GroupBy(b => b.DefinitionId).ToList(); + var boxNames = grouped.Select(g => + { + var name = GetLocalizedName(g.Key); + return g.Count() > 1 ? $"{name} (x{g.Count()})" : name; + }).ToList(); boxNames.Add(_loc.Get("menu.back")); int choice = _renderer.ShowSelection(_loc.Get("prompt.choose_box"), boxNames); - if (choice >= boxes.Count) return; + if (choice >= grouped.Count) return; - var boxInstance = boxes[choice]; + var boxInstance = grouped[choice].First(); var openAction = new OpenBoxAction(boxInstance.Id) { @@ -322,8 +328,9 @@ public static class Program { var def = _registry.GetItem(g.Key); var bDef = def is null ? _registry.GetBox(g.Key) : null; + var baseName = GetLocalizedName(g.Key); return ( - name: GetLocalizedName(g.Key), + name: g.Count() > 1 ? $"{baseName} (x{g.Count()})" : baseName, rarity: (def?.Rarity ?? bDef?.Rarity ?? ItemRarity.Common).ToString(), category: (def?.Category ?? ItemCategory.Box).ToString() );