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:
parent
d09bf72a90
commit
2825621d0a
1 changed files with 11 additions and 4 deletions
|
|
@ -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()
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue