105 lines
4.5 KiB
C#
105 lines
4.5 KiB
C#
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
namespace TKS.OutGame
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 화면 글자 표(로컬라이징 키 → 언어 칸 · PD 2026-11-17 「화면의 모든 메뉴 = 버튼 UI · 보이는 글자 = 전부 로컬라이징 데이터로 교체 가능 · 통 이미지 금지」) —
|
|||
|
|
/// 게임에 로컬라이징 시스템이 아직 없어 가장 작은 형태로 둔다: 표(Resources TextAsset · 열 s_key · ko · en … · note)를 읽어 키 → 언어 글자.
|
|||
|
|
/// 언어 = <see cref="Lang"/>(기본 ko) · 그 칸이 비면 ko · 키가 없으면 키 그대로(빠진 키가 화면에 드러남). 바뀌는 값 = {0} {1} 자리.
|
|||
|
|
/// 첫 사용처 = 연무장 허브(UI/Yeonmu/yeonmu_text) · 다른 화면도 표를 <see cref="Use"/> 로 더하면 같은 방식.
|
|||
|
|
/// </summary>
|
|||
|
|
public static class UiText
|
|||
|
|
{
|
|||
|
|
public const string Fallback = "ko";
|
|||
|
|
|
|||
|
|
/// <summary>표시 언어 칸 이름(표 머리 줄의 열 이름).</summary>
|
|||
|
|
public static string Lang = Fallback;
|
|||
|
|
|
|||
|
|
static readonly Dictionary<string, Dictionary<string, string>> texts = new Dictionary<string, Dictionary<string, string>>();
|
|||
|
|
static readonly HashSet<string> loaded = new HashSet<string>();
|
|||
|
|
static readonly HashSet<string> warned = new HashSet<string>();
|
|||
|
|
|
|||
|
|
/// <summary>글자 표 하나를 더한다(같은 경로는 한 번만 · 없으면 false).</summary>
|
|||
|
|
public static bool Use(string resourcePath)
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrEmpty(resourcePath)) return false;
|
|||
|
|
if (loaded.Contains(resourcePath)) return true;
|
|||
|
|
var rows = Rows(resourcePath);
|
|||
|
|
if (rows == null) return false;
|
|||
|
|
foreach (var r in rows)
|
|||
|
|
{
|
|||
|
|
string key;
|
|||
|
|
if (!r.TryGetValue("s_key", out key) || key.Length == 0) continue;
|
|||
|
|
texts[key] = r;
|
|||
|
|
}
|
|||
|
|
loaded.Add(resourcePath);
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>표를 다시 읽게 비운다(테스트 · 표 교체).</summary>
|
|||
|
|
public static void Reset()
|
|||
|
|
{
|
|||
|
|
texts.Clear();
|
|||
|
|
loaded.Clear();
|
|||
|
|
warned.Clear();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static bool Has(string key)
|
|||
|
|
{
|
|||
|
|
return !string.IsNullOrEmpty(key) && texts.ContainsKey(key);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>키 → 지금 언어 글자(빈 칸 = ko · 키 없음 = 키 그대로).</summary>
|
|||
|
|
public static string T(string key)
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrEmpty(key)) return "";
|
|||
|
|
Dictionary<string, string> r;
|
|||
|
|
if (!texts.TryGetValue(key, out r))
|
|||
|
|
{
|
|||
|
|
if (warned.Add(key)) Debug.LogWarning("[TKS] 글자 표에 키 없음: " + key);
|
|||
|
|
return key;
|
|||
|
|
}
|
|||
|
|
string v;
|
|||
|
|
if (r.TryGetValue(Lang, out v) && v.Length > 0) return v;
|
|||
|
|
return r.TryGetValue(Fallback, out v) ? v : key;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>키 → 글자 + {0} {1} … 자리에 값(값이 모자라면 그 자리는 그대로).</summary>
|
|||
|
|
public static string F(string key, IList<string> args)
|
|||
|
|
{
|
|||
|
|
var s = T(key);
|
|||
|
|
if (args == null) return s;
|
|||
|
|
for (int i = 0; i < args.Count; i++) s = s.Replace("{" + i + "}", args[i] ?? "");
|
|||
|
|
return s;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// UI 표 읽기(공용) — Resources TextAsset CSV · # 주석 줄 · 빈 줄 건너뜀 · 첫 줄 = 머리(열 이름) · 따옴표 칸 지원(SkillVfx.SplitCsv) · 없으면 null.
|
|||
|
|
/// </summary>
|
|||
|
|
public static List<Dictionary<string, string>> Rows(string resourcePath)
|
|||
|
|
{
|
|||
|
|
var ta = Resources.Load<TextAsset>(resourcePath);
|
|||
|
|
if (ta == null) return null;
|
|||
|
|
var list = new List<Dictionary<string, string>>();
|
|||
|
|
string[] head = null;
|
|||
|
|
foreach (var raw in ta.text.Replace("\r", "").Split('\n'))
|
|||
|
|
{
|
|||
|
|
var line = raw.TrimStart('');
|
|||
|
|
if (line.Trim().Length == 0 || line.TrimStart().StartsWith("#")) continue;
|
|||
|
|
var cells = SkillVfx.SplitCsv(line);
|
|||
|
|
if (head == null)
|
|||
|
|
{
|
|||
|
|
head = cells;
|
|||
|
|
for (int i = 0; i < head.Length; i++) head[i] = head[i].Trim();
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
var r = new Dictionary<string, string>();
|
|||
|
|
for (int i = 0; i < head.Length; i++) r[head[i]] = i < cells.Length ? cells[i].Trim() : "";
|
|||
|
|
list.Add(r);
|
|||
|
|
}
|
|||
|
|
return list;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|