地图系统
This commit is contained in:
@@ -4,6 +4,7 @@ using TMPro;
|
||||
using System.Collections.Generic;
|
||||
using BaseGames.Core;
|
||||
using BaseGames.Core.Events;
|
||||
using BaseGames.Localization;
|
||||
|
||||
namespace BaseGames.World.Map
|
||||
{
|
||||
@@ -88,7 +89,7 @@ namespace BaseGames.World.Map
|
||||
float progress = _mapSvc.GetExplorationProgress();
|
||||
try
|
||||
{
|
||||
_globalProgressText.text = string.Format(_globalFormat, progress);
|
||||
_globalProgressText.text = string.Format(ResolveFormat(_globalFormat, "{0:P0}"), progress);
|
||||
}
|
||||
catch (System.FormatException)
|
||||
{
|
||||
@@ -111,7 +112,7 @@ namespace BaseGames.World.Map
|
||||
string regionDisplayName = ResolveRegionDisplayName(_currentRegionId);
|
||||
try
|
||||
{
|
||||
_regionProgressText.text = string.Format(_regionFormat, regionProgress, regionDisplayName);
|
||||
_regionProgressText.text = string.Format(ResolveFormat(_regionFormat, "{1} {0:P0}"), regionProgress, regionDisplayName);
|
||||
}
|
||||
catch (System.FormatException)
|
||||
{
|
||||
@@ -124,6 +125,21 @@ namespace BaseGames.World.Map
|
||||
|
||||
// ── 辅助方法 ──────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// 将格式串字段解析为本地化格式串,并保证始终含 {0} 占位符:
|
||||
/// ① 字段填本地化 Key(如 "MAP_PROGRESS_GLOBAL")→ 返回本地化值(如 "已探索 {0:P0}");
|
||||
/// ② 字段直接是格式串 → Get 原样返回(向后兼容);
|
||||
/// ③ 本地化服务缺失 / Key 未命中(返回值无 {0})→ 回退到 <paramref name="fallback"/>,
|
||||
/// 确保即使本地化未就绪也不丢失百分比数值。
|
||||
/// </summary>
|
||||
private static string ResolveFormat(string keyOrFormat, string fallback)
|
||||
{
|
||||
if (string.IsNullOrEmpty(keyOrFormat)) return fallback;
|
||||
string s = LocalizationManager.Get(keyOrFormat, LocalizationTable.UI);
|
||||
// 检测 "{0"(兼容 "{0}"、"{0:P0}"、"{0:F1}" 等格式说明符);缺占位符视为未解析,用回退
|
||||
return (!string.IsNullOrEmpty(s) && s.Contains("{0")) ? s : fallback;
|
||||
}
|
||||
|
||||
/// <summary>预建 RegionId → Entry 字典,O(1) 查询。</summary>
|
||||
private void BuildRegionDict()
|
||||
=> _regionDict = MapServiceExtensions.BuildRegionDict(_regionNames);
|
||||
|
||||
Reference in New Issue
Block a user