Fix box name lookups falling back to raw IDs instead of localization
GetItem() returns null for box definition IDs, causing [MISSING:box_*] display. Added GetLocalizedName() helper that checks both item and box registries before resolving the localization key.
This commit is contained in:
parent
9c4fd0d73a
commit
f88a3cc3f6
1 changed files with 24 additions and 7 deletions
|
|
@ -212,8 +212,7 @@ public static class Program
|
|||
return;
|
||||
}
|
||||
|
||||
var boxNames = boxes.Select(b =>
|
||||
_loc.Get(_registry.GetItem(b.DefinitionId)?.NameKey ?? b.DefinitionId)).ToList();
|
||||
var boxNames = boxes.Select(b => GetLocalizedName(b.DefinitionId)).ToList();
|
||||
boxNames.Add(_loc.Get("menu.back"));
|
||||
|
||||
int choice = _renderer.ShowSelection(_loc.Get("prompt.choose_box"), boxNames);
|
||||
|
|
@ -246,11 +245,12 @@ public static class Program
|
|||
case ItemReceivedEvent itemEvt:
|
||||
_state.AddItem(itemEvt.Item);
|
||||
var itemDef = _registry.GetItem(itemEvt.Item.DefinitionId);
|
||||
var itemBoxDef = itemDef is null ? _registry.GetBox(itemEvt.Item.DefinitionId) : null;
|
||||
_renderer.ShowLootReveal(
|
||||
[
|
||||
(
|
||||
_loc.Get(itemDef?.NameKey ?? itemEvt.Item.DefinitionId),
|
||||
(itemDef?.Rarity ?? ItemRarity.Common).ToString(),
|
||||
GetLocalizedName(itemEvt.Item.DefinitionId),
|
||||
(itemDef?.Rarity ?? itemBoxDef?.Rarity ?? ItemRarity.Common).ToString(),
|
||||
(itemDef?.Category ?? ItemCategory.Box).ToString()
|
||||
)
|
||||
]);
|
||||
|
|
@ -321,9 +321,10 @@ public static class Program
|
|||
.Select(g =>
|
||||
{
|
||||
var def = _registry.GetItem(g.Key);
|
||||
var bDef = def is null ? _registry.GetBox(g.Key) : null;
|
||||
return (
|
||||
name: _loc.Get(def?.NameKey ?? g.Key),
|
||||
rarity: (def?.Rarity ?? ItemRarity.Common).ToString(),
|
||||
name: GetLocalizedName(g.Key),
|
||||
rarity: (def?.Rarity ?? bDef?.Rarity ?? ItemRarity.Common).ToString(),
|
||||
category: (def?.Category ?? ItemCategory.Box).ToString()
|
||||
);
|
||||
})
|
||||
|
|
@ -404,7 +405,7 @@ public static class Program
|
|||
var options = cosmeticItems.Select(i =>
|
||||
{
|
||||
var def = _registry.GetItem(i.DefinitionId);
|
||||
return $"[{def?.CosmeticSlot}] {_loc.Get(def?.NameKey ?? i.DefinitionId)}";
|
||||
return $"[{def?.CosmeticSlot}] {GetLocalizedName(i.DefinitionId)}";
|
||||
}).ToList();
|
||||
options.Add(_loc.Get("menu.back"));
|
||||
|
||||
|
|
@ -431,6 +432,22 @@ public static class Program
|
|||
_renderer.WaitForKeyPress(_loc.Get("prompt.press_key"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the localized display name for any definition ID (item or box).
|
||||
/// </summary>
|
||||
private static string GetLocalizedName(string definitionId)
|
||||
{
|
||||
var itemDef = _registry.GetItem(definitionId);
|
||||
if (itemDef is not null)
|
||||
return _loc.Get(itemDef.NameKey);
|
||||
|
||||
var boxDef = _registry.GetBox(definitionId);
|
||||
if (boxDef is not null)
|
||||
return _loc.Get(boxDef.NameKey);
|
||||
|
||||
return _loc.Get(definitionId);
|
||||
}
|
||||
|
||||
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
|
||||
private static void PlayMelody()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue