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.
This commit is contained in:
Samuel Bouchet 2026-03-10 20:01:11 +01:00
parent d09bf72a90
commit 2825621d0a

View file

@ -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()
);