ThreeKingdomsSlingshot/Assets/Scripts/OutGame/Arena/ArenaHub.cs

665 lines
31 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Globalization;
using UnityEngine;
using UnityEngine.UI;
namespace TKS.OutGame
{
/// <summary>
/// 연무장 첫 페이지 = 성 안 풍경 허브(PD 2026-11-18 「게임 내 연무장 메뉴에 해당 리소스를 반영」 · 개발 요청서 컨텐츠모드 2026-11-17 「기능은 지금 화면 구조로 · 그림이 확정되면 배경과 누르는 자리(납품 좌표 표)를 바꿔 끼운다」).
/// 배경 그림 + 장소 버튼(누름 칸 + 이름표 = 명패 · 이름 · 상태 줄 · 새 소식 점 · 자물쇠) + 장식 유닛(대기 숨) + 앞 층(울타리 · 진열대 · 건초) + 고삐 줄 — 모양 = 시안 mk_mock.py.
/// 표(Resources/UI/Yeonmu · C45): 허브 설정 yeonmu_hub(키 · 값 · 장소 → 모드 연결 open 포함) · 장소 yeonmu_spots(납품 표 그대로) · 유닛 yeonmu_actors(시안 UNITS) ·
/// 글자 yeonmu_text(납품 표 그대로 · UiText) · 앞 층 layers/*.json(납품 그대로). 그림을 바꾸면 이 폴더의 파일만 바꿔 끼운다.
/// 층(P41 · 프로젝트 CLAUDE.md 「UI 캔버스·아틀라스 구조」): 화면(Event) → Hub(끌기 판 · 위 띠 · 안내 띠) → Content(좌우 스크롤 · Frame) →
/// Art(배경 · Static) · Scene(그림자 · 유닛 · 앞 층 · 고삐 · Frame) · Tags(누름 칸 · 이름표 = 아틀라스 부품 · Event · 레이캐스터).
/// 연출(PD 2026-11-18 · 표 키 scene = yeonmu_scene · ArenaHubFx) = Art 뒤 AmbBack(깃발 · 풀꽃 · 등불) · Scene 뒤 Fx(구름 그림자 · 화살 · 불똥 · z) · AmbFront(새 · 꽃잎) · Clouds(구름) — 모두 Frame · Tags 아래.
/// </summary>
public class ArenaHub
{
public const string HubTable = "UI/Yeonmu/yeonmu_hub";
/// <summary>장소 1곳(yeonmu_spots 한 줄 · 좌표 = 캔버스 px · 왼쪽 위 0,0 · 아래로 +).</summary>
public class Spot
{
public string id = "";
public Vector2 press;
public Vector2 pressSize;
public bool hasTag;
public Vector2 tag;
public readonly List<Vector2> feet = new List<Vector2>();
public string nameKey = "";
public string statusKey = "";
public string[] args = new string[0];
public bool dot;
public bool locked;
/// <summary>누르면 열 곳(허브 표 open · tower · supply · league · raid · scenario · soon · later · 빈 = 누름 없음).</summary>
public string open = "";
}
/// <summary>장식 유닛 1명(yeonmu_actors 한 줄).</summary>
public class Actor
{
public string spot = "";
public int slot;
public string art = "";
public string clip = "";
public bool flip;
/// <summary>키 = 캔버스 px(그림 대기 첫 프레임 불투명 높이 charHeightPx 를 이 높이로 · 시안 bbox 기준과 같음).</summary>
public float h;
}
[System.Serializable]
class LayerJson
{
public float x;
public float y;
public float w;
public float h;
public float sort_y = float.NaN;
}
class Item
{
public float y;
public float x;
public Actor actor;
public Vector2 foot;
public string layer;
public LayerJson rect;
}
readonly ArenaScreen screen;
readonly Dictionary<string, List<string>> kv = new Dictionary<string, List<string>>();
public readonly List<Spot> Spots = new List<Spot>();
public readonly List<Actor> Actors = new List<Actor>();
readonly Dictionary<string, Text> statusText = new Dictionary<string, Text>();
readonly Dictionary<string, RectTransform> statusPill = new Dictionary<string, RectTransform>();
readonly Dictionary<string, RectTransform> tagRoot = new Dictionary<string, RectTransform>();
readonly Dictionary<string, Text> nameText = new Dictionary<string, Text>();
readonly Dictionary<string, RectTransform> actorRt = new Dictionary<string, RectTransform>();
public RectTransform View { get; private set; }
public RectTransform Content { get; private set; }
public RectTransform Art { get; private set; }
public RectTransform Scene { get; private set; }
public RectTransform Tags { get; private set; }
public ScrollRect Scroll { get; private set; }
public ArenaHubView Fitter { get; private set; }
/// <summary>연출(대련 · 활쏘기 · z · 불똥 · 건초 · 구름 · 깃발 · 풀꽃 · 등불 · 새 · 꽃잎) · 표가 없으면 null.</summary>
public ArenaHubFx Fx { get; private set; }
public bool Built { get; private set; }
/// <summary>세운 유닛 수 · 앞 층 수(표 = 폴더 json 수) · 이름표 수(테스트).</summary>
public int ActorCount { get; private set; }
public int LayerCount { get; private set; }
public int LayerRows { get; private set; }
public int TagCount { get; private set; }
ArenaHub(ArenaScreen s)
{
screen = s;
}
// ---------- 표 ----------
/// <summary>허브 표 · 장소 표 · 유닛 표 · 글자 표를 읽는다(그림은 아직 · 화면을 처음 열 때 Show). 표가 없으면 null(호출 쪽 = 예전 모드 카드).</summary>
public static ArenaHub Load(ArenaScreen s)
{
var rows = UiText.Rows(HubTable);
if (rows == null) return null;
var hub = new ArenaHub(s);
foreach (var r in rows)
{
string k, v;
if (!r.TryGetValue("s_key", out k) || k.Length == 0) continue;
r.TryGetValue("s_value", out v);
List<string> l;
if (!hub.kv.TryGetValue(k, out l)) hub.kv[k] = l = new List<string>();
l.Add(v ?? "");
}
UiText.Use(hub.S("texts"));
if (!hub.LoadSpots() || !UiText.Has(hub.S("title_key"))) return null;
hub.LoadActors();
return hub;
}
public string S(string key, string def = "")
{
List<string> l;
return kv.TryGetValue(key, out l) && l.Count > 0 && l[0].Length > 0 ? l[0] : def;
}
string[] L(string key)
{
return S(key).Split('|');
}
List<string[]> All(string key)
{
var list = new List<string[]>();
List<string> l;
if (kv.TryGetValue(key, out l))
foreach (var v in l)
list.Add(v.Split('|'));
return list;
}
static float F(string v, float def = 0f)
{
float f;
return v != null && float.TryParse(v.Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out f) ? f : def;
}
static float At(string[] a, int i, float def = 0f)
{
return a != null && i < a.Length ? F(a[i], def) : def;
}
static string Str(string[] a, int i)
{
return a != null && i < a.Length ? a[i].Trim() : "";
}
static Color Col(string[] a, int i, Color def)
{
Color c;
return a != null && i < a.Length && ColorUtility.TryParseHtmlString(a[i].Trim(), out c) ? c : def;
}
static string Cell(Dictionary<string, string> r, string k)
{
string v;
return r.TryGetValue(k, out v) ? v : "";
}
bool LoadSpots()
{
var rows = UiText.Rows(S("spots"));
if (rows == null) return false;
foreach (var r in rows)
{
var s = new Spot { id = Cell(r, "s_id") };
if (s.id.Length == 0) continue;
s.press = new Vector2(F(Cell(r, "f_x")), F(Cell(r, "f_y")));
s.pressSize = new Vector2(F(Cell(r, "f_w")), F(Cell(r, "f_h")));
s.hasTag = Cell(r, "f_tag_x").Length > 0 && Cell(r, "f_tag_y").Length > 0;
s.tag = new Vector2(F(Cell(r, "f_tag_x")), F(Cell(r, "f_tag_y")));
foreach (var p in Cell(r, "s_unit_slots").Split(';'))
{
var xy = p.Split(':');
if (xy.Length == 2) s.feet.Add(new Vector2(F(xy[0]), F(xy[1])));
}
s.nameKey = Cell(r, "s_name_key");
s.statusKey = Cell(r, "s_status_key");
var args = Cell(r, "s_status_args");
s.args = args.Length > 0 ? args.Split('|') : new string[0];
var flags = Cell(r, "s_flags");
s.dot = flags.Contains("dot");
s.locked = flags.Contains("lock");
Spots.Add(s);
}
foreach (var o in All("open"))
{
var s = SpotOf(Str(o, 0));
if (s != null) s.open = Str(o, 1);
}
return Spots.Count > 0;
}
void LoadActors()
{
var rows = UiText.Rows(S("actors"));
if (rows == null) return;
foreach (var r in rows)
{
var a = new Actor
{
spot = Cell(r, "s_spot"),
slot = (int)F(Cell(r, "i_slot")),
art = Cell(r, "s_art"),
clip = Cell(r, "s_clip"),
flip = Cell(r, "i_flip") == "1",
h = F(Cell(r, "f_h")),
};
if (a.spot.Length > 0 && a.art.Length > 0) Actors.Add(a);
}
}
public Spot SpotOf(string id)
{
foreach (var s in Spots)
if (s.id == id)
return s;
return null;
}
// ---------- 화면 ----------
/// <summary>slot(화면 전체 · 헤더·본문 뒤)에 허브를 처음 한 번 만들고 상태 줄을 갱신 · 배경 그림이 없으면 false(호출 쪽 = 예전 카드).</summary>
public bool Show(RectTransform slot)
{
if (!Built && !Build(slot)) return false;
RefreshStatus();
return true;
}
bool Build(RectTransform slot)
{
var bgSp = Resources.Load<Sprite>(S("bg"));
if (bgSp == null)
{
Debug.LogWarning("[TKS] 연무장 허브 배경 없음: " + S("bg"));
return false;
}
var cv = L("canvas");
var cs = new Vector2(At(cv, 0, bgSp.rect.width), At(cv, 1, bgSp.rect.height)); // 좌표계 = 표 크기(그림 해상도와 무관)
var bx = L("box");
var box = new Rect(At(bx, 0), At(bx, 1), At(bx, 2, cs.x), At(bx, 3, cs.y));
View = slot;
// 끌기 판(화면 전체 · 투명) — 빈 곳을 끌어도 좌우 스크롤
var drag = View.gameObject.AddComponent<Image>();
drag.color = new Color(1f, 1f, 1f, 0f);
drag.canvasRenderer.cullTransparentMesh = true; // 누름만 · 그리지 않음
drag.raycastTarget = true;
Content = UiKit.Rect("Content", View, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, cs);
UiLayer.Nest(Content.gameObject, UiRate.Frame, false); // 스크롤로 움직임(ScrollGrid 내용과 같은 등급)
Art = UiLayer.Group("Art", Content, UiRate.Static);
var bg = Art.gameObject.AddComponent<Image>();
bg.sprite = bgSp;
bg.raycastTarget = false;
Scene = UiLayer.Group("Scene", Content, UiRate.Frame);
Tags = UiLayer.Group("Tags", Content, UiRate.Event, true);
BuildScene();
BuildTags();
Fx = ArenaHubFx.Build(this, S("scene"), cs); // 연출(PD 2026-11-18 · 표 yeonmu_scene · 없으면 연출 없음)
Scroll = View.gameObject.AddComponent<ScrollRect>();
Scroll.viewport = View;
Scroll.content = Content;
Scroll.horizontal = true;
Scroll.vertical = false;
Scroll.movementType = ScrollRect.MovementType.Clamped;
Scroll.scrollSensitivity = 60f; // UiKit.ScrollGrid 와 같음
// 재화 바 뒤 띠(시안 = 어두운 띠 · 다른 화면 BgTop 과 같은 색) · 아래 안내 띠(탭 바 위 · 화면 고정)
UiKit.Paint(UiKit.TopBand("TopBand", View, 0f, OutGameRoot.TopBarH), UiKit.Col("band_top", UiKit.Bg), false);
BuildHint();
Fitter = View.gameObject.AddComponent<ArenaHubView>();
Fitter.content = Content;
Fitter.scroll = Scroll;
Fitter.canvasSize = cs;
Fitter.box = box;
Fitter.Fit(true);
Built = true;
return true;
}
void BuildScene()
{
var items = new List<Item>();
foreach (var a in Actors)
{
var s = SpotOf(a.spot);
if (s == null || a.slot < 0 || a.slot >= s.feet.Count) continue;
var f = s.feet[a.slot];
items.Add(new Item { y = f.y, x = f.x, actor = a, foot = f });
}
// 앞 층 = 발 줄 순서로 유닛과 섞어 그림(sort_y · 없으면 y + h − 패딩 = 시안과 같음)
float pad = F(S("layer_sort_pad"));
string folder = S("layers");
var jsons = folder.Length > 0 ? Resources.LoadAll<TextAsset>(folder) : new TextAsset[0];
LayerRows = jsons.Length;
foreach (var ta in jsons)
{
var j = new LayerJson();
try
{
JsonUtility.FromJsonOverwrite(ta.text, j);
}
catch (System.Exception e)
{
Debug.LogWarning("[TKS] 연무장 앞 층 json 해석 실패 " + ta.name + ": " + e.Message);
continue;
}
items.Add(new Item { y = float.IsNaN(j.sort_y) ? j.y + j.h - pad : j.sort_y, x = j.x, layer = folder + "/" + ta.name, rect = j });
}
items.Sort((p, q) => p.y != q.y ? p.y.CompareTo(q.y) : p.x.CompareTo(q.x));
// ① 그림자 = 사람보다 먼저 모두(한 아틀라스 = 한 묶음 · 내정 순찰과 같은 값)
float std = F(S("shadow_std"), 180f);
var shadows = All("shadow");
foreach (var it in items)
{
if (it.actor == null) continue;
float k = it.actor.h / Mathf.Max(1f, std);
foreach (var sh in shadows)
{
var rt = UiKit.Rect("Shadow_" + it.actor.spot + it.actor.slot, Scene, new Vector2(0f, 1f), new Vector2(0.5f, 0.5f),
new Vector2(it.foot.x + At(sh, 1) * k, -(it.foot.y + At(sh, 2) * k)), new Vector2(At(sh, 3) * k, At(sh, 4) * k));
var img = rt.gameObject.AddComponent<Image>();
var sp = UISkin.Icon(Str(sh, 0));
img.sprite = sp != null ? sp : UiKit.Circle;
img.color = Col(sh, 5, new Color(0f, 0f, 0f, 0.4f));
img.raycastTarget = false;
}
}
// ② 유닛 · 앞 층(위 = 뒤 먼저)
foreach (var it in items)
{
if (it.actor != null) PlaceActor(it.actor, it.foot);
else PlaceLayer(it.layer, it.rect);
}
// ③ 고삐(말 코 → 울타리 기둥 · 처지는 줄 · 맨 위)
foreach (var rn in All("rein")) PlaceRein(rn);
}
void PlaceActor(Actor a, Vector2 foot)
{
var data = UnitArt.Load(a.art);
Sprite[] fr;
if (data == null || data.Meta.pivot == null || data.Meta.pivot.Length < 2) return;
string clip = a.clip.Length > 0 ? a.clip : "front_idle";
if (!data.Clips.TryGetValue(clip, out fr) || fr.Length == 0)
{
clip = "front_idle";
if (!data.Clips.TryGetValue(clip, out fr) || fr.Length == 0) return;
}
// 키 기준 = 대기 첫 프레임 불투명 높이(charHeightPx · 무기 포함 = 시안이 키를 맞춘 bbox 높이)
float basis = data.Meta.charHeightPx > 0.5f ? data.Meta.charHeightPx : data.BodyPx;
if (basis <= 0.5f) return;
float k = a.h / basis;
// 크기 = 원본 px(월드 크기 × meta ppu · Android 축소 임포트에서도 같음) × 배율
var size = (Vector2)fr[0].bounds.size * data.Meta.ppu * k;
var rt = UiKit.Rect("Actor_" + a.spot + a.slot + "_" + a.art, Scene, new Vector2(0f, 1f), new Vector2(data.Meta.pivot[0], data.Meta.pivot[1]), new Vector2(foot.x, -foot.y), size);
if (a.flip) rt.localScale = new Vector3(-1f, 1f, 1f);
var img = rt.gameObject.AddComponent<Image>();
img.sprite = fr[0];
img.raycastTarget = false;
UiFrameAnim.Attach(img, data, clip); // 1 프레임 클립(대련 · 겨누기) = 정지
actorRt[a.spot + ":" + a.slot] = rt;
ActorCount++;
}
void PlaceLayer(string path, LayerJson j)
{
var sp = Resources.Load<Sprite>(path);
if (sp == null) return;
var rt = UiKit.Rect("Front_" + sp.name, Scene, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(j.x, -j.y), new Vector2(j.w, j.h));
var img = rt.gameObject.AddComponent<Image>();
img.sprite = sp;
img.raycastTarget = false;
LayerCount++;
}
/// <summary>표 rein = 장소|유닛 순번|시작 x|시작 y(유닛 발 기준)|끝 x(캔버스)|끝 y(유닛 발 기준)|처짐 · rein_line = 굵기|색(먼저 쓴 줄이 아래).</summary>
void PlaceRein(string[] rn)
{
RectTransform horse;
if (!actorRt.TryGetValue(Str(rn, 0) + ":" + Str(rn, 1), out horse)) return;
var s = SpotOf(Str(rn, 0));
int slot = (int)At(rn, 1);
if (s == null || slot >= s.feet.Count) return;
var foot = s.feet[slot];
var a = new Vector2(foot.x + At(rn, 2), -(foot.y + At(rn, 3)));
var b = new Vector2(At(rn, 4), -(foot.y + At(rn, 5)));
float sag = At(rn, 6);
var root = UiKit.Rect("Rein_" + s.id, Scene, new Vector2(0f, 1f), new Vector2(0f, 1f), Vector2.zero, Vector2.zero);
int i = 0;
foreach (var ln in All("rein_line"))
{
var go = new GameObject("Line" + (i++), typeof(RectTransform));
go.transform.SetParent(root, false);
var rt = (RectTransform)go.transform;
rt.anchorMin = rt.anchorMax = rt.pivot = new Vector2(0f, 1f);
rt.anchoredPosition = Vector2.zero;
rt.sizeDelta = Vector2.zero;
var rope = go.AddComponent<UiRope>();
rope.raycastTarget = false;
rope.color = Col(ln, 1, Color.black);
rope.Set(a, b, sag, At(ln, 0, 2f));
}
}
void BuildTags()
{
// 누름 칸(투명 · 그리지 않음) 먼저 → 이름표가 그 위(이름표도 누름)
foreach (var s in Spots)
{
if (s.pressSize.x <= 0f || s.pressSize.y <= 0f || s.open.Length == 0) continue;
var rt = UiKit.Rect("Press_" + s.id, Tags, new Vector2(0f, 1f), new Vector2(0.5f, 0.5f), new Vector2(s.press.x, -s.press.y), s.pressSize);
var img = rt.gameObject.AddComponent<Image>();
img.color = new Color(1f, 1f, 1f, 0f);
img.canvasRenderer.cullTransparentMesh = true; // 누름만 · 그리지 않음
img.raycastTarget = true;
var b = rt.gameObject.AddComponent<Button>();
b.transition = Selectable.Transition.None;
var id = s.id;
b.onClick.AddListener(() => Press(id));
}
foreach (var s in Spots)
if (s.hasTag && s.nameKey.Length > 0)
BuildTag(s);
}
/// <summary>이름표 = 명패(9 분할 · 아틀라스) + 이름(제목 글꼴) + 상태 줄(칩 + 본문 굵게) + 새 소식 점 · 자물쇠 — 크기·색 = 허브 표(시안 mk_mock.py tag()).</summary>
void BuildTag(Spot s)
{
var pl = L("plaque"); // 스프라이트|높이|최소 폭|여백
var nt = L("name_text"); // 글자|색|외곽선 색|외곽선|세로 어긋남
var lk = L("lock"); // 스프라이트|크기|자리 폭|간격
float H = At(pl, 1, 62f);
var root = UiKit.Rect("Tag_" + s.id, Tags, new Vector2(0f, 1f), new Vector2(0.5f, 0.5f), new Vector2(s.tag.x, -s.tag.y), Vector2.zero);
tagRoot[s.id] = root;
var plq = UiKit.Rect("Plaque", root, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), Vector2.zero, new Vector2(0f, H));
var pimg = plq.gameObject.AddComponent<Image>();
var sp = UISkin.Icon(Str(pl, 0));
float side = 0f;
if (sp != null)
{
pimg.sprite = sp;
if (sp.border != Vector4.zero)
{
pimg.type = Image.Type.Sliced;
pimg.pixelsPerUnitMultiplier = sp.rect.height / Mathf.Max(1f, H); // 명패 높이에 맞춰 좌우 끝 장식도 같은 비율(시안 = 60 px 끝 × 높이 비)
side = sp.border.x * H / Mathf.Max(1f, sp.rect.height);
}
}
else pimg.color = UiKit.Dark;
pimg.raycastTarget = true;
float iconW = s.locked ? At(lk, 2) : 0f;
var name = UiKit.Title(UiKit.Label(plq, UiText.T(s.nameKey), (int)At(nt, 0, 30f), Col(nt, 1, Color.white), TextAnchor.MiddleCenter,
new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(iconW * 0.5f, At(nt, 4)), new Vector2(1000f, H)));
name.horizontalOverflow = HorizontalWrapMode.Overflow;
UISkin.Stroke(name, Col(nt, 2, Color.black), At(nt, 3, 3f));
nameText[s.id] = name;
float tw = name.preferredWidth;
float wp = Mathf.Max(tw + iconW + 2f * side + At(pl, 3), At(pl, 2));
plq.sizeDelta = new Vector2(wp, H);
name.rectTransform.sizeDelta = new Vector2(wp, H);
if (s.locked)
{
float isz = At(lk, 1, 34f);
var ic = UISkin.IconImage(plq, Str(lk, 0), new Vector2(0.5f, 0.5f), new Vector2(1f, 0.5f), new Vector2(iconW * 0.5f - tw * 0.5f - At(lk, 3), 0f), new Vector2(isz, isz));
if (ic != null) ic.name = "Lock";
}
if (s.dot)
{
var dt = L("dot"); // 스프라이트|크기|x(명패 오른끝 기준)|y(명패 위끝 기준)
float d = At(dt, 1, 24f);
var dot = UISkin.IconImage(plq, Str(dt, 0), new Vector2(1f, 1f), new Vector2(0.5f, 0.5f), new Vector2(At(dt, 2), At(dt, 3)), new Vector2(d, d));
if (dot != null) dot.name = "Dot";
}
// 상태 줄(명패 아래 · 겹침 overlap)
var st = L("status"); // 스킨|높이|좌우 여백 합|겹침|바탕색|글자|글자색
float sh = At(st, 1, 34f);
var pill = UiKit.Rect("Status", root, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -(H - At(st, 3))), new Vector2(0f, sh));
UiKit.Skin(pill, Str(st, 0), Col(st, 4, UiKit.Dark), true);
var stt = UiKit.Label(pill, "", (int)At(st, 5, 21f), Col(st, 6, Color.white), TextAnchor.MiddleCenter, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, new Vector2(1000f, sh));
stt.horizontalOverflow = HorizontalWrapMode.Overflow;
statusText[s.id] = stt;
statusPill[s.id] = pill;
var b = root.gameObject.AddComponent<Button>();
b.targetGraphic = pimg;
var nav = b.navigation;
nav.mode = Navigation.Mode.None;
b.navigation = nav;
var id = s.id;
b.onClick.AddListener(() => Press(id));
TagCount++;
}
void BuildHint()
{
var h = L("hint"); // 글자 키|글자|글자색|바탕색|높이|좌우 여백 합|탭 바 위 간격
var key = Str(h, 0);
if (key.Length == 0) return;
float hh = At(h, 4, 50f);
var band = UiKit.Rect("Hint", View, new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), new Vector2(0f, OutGameRoot.TabBarH + At(h, 6)), new Vector2(0f, hh));
UiKit.Skin(band, Str(L("status"), 0), Col(h, 3, UiKit.Dark));
var t = UiKit.Label(band, UiText.T(key), (int)At(h, 1, 27f), Col(h, 2, Color.white), TextAnchor.MiddleCenter, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, new Vector2(1000f, hh));
t.horizontalOverflow = HorizontalWrapMode.Overflow;
float w = t.preferredWidth + At(h, 5);
band.sizeDelta = new Vector2(w, hh);
t.rectTransform.sizeDelta = new Vector2(w, hh);
}
// ---------- 상태 줄 · 누름 ----------
/// <summary>
/// 상태 줄 값 = 게임 데이터가 있는 자리만 실제 값 · 나머지 자리 = 장소 표 s_status_args(시안 예시).
/// raid(성문 맹장 토벌전 · 컨텐츠 모드 ③) {0} 오늘 기록 도전 = 메인 + 서브 사용 · {1} 하루 최대 = raid.entries_split 합 · {2} 주간 순위 = 서버 순위가 있을 때만 실제(없으면 예시) ·
/// tower {0} 최고 층 · league(투기장 · 컨텐츠 모드 ④) {0} 오늘 남은 입장 · {1} 하루 최대(arena.entries_per_day + 오늘 산 입장) ·
/// scenario(연의 전기 · 컨텐츠 모드 ②) {0} = 열린 편 가운데 연의를 아직 못 이긴 첫 편 이름(없으면 예시) · supply(보급전) = 글자 키에 값 자리 없음.
/// </summary>
public string[] Args(Spot s)
{
var a = new List<string>(s.args);
var d = screen.S.Save;
var now = screen.S.Now;
switch (s.open)
{
case "raid":
Need(a, 2);
a[0] = (RaidRules.Used(d, RaidData.Main, now) + RaidRules.Used(d, RaidData.Sub, now)).ToString(CultureInfo.InvariantCulture);
a[1] = (RaidData.EntryLimit(RaidData.Main) + RaidData.EntryLimit(RaidData.Sub)).ToString(CultureInfo.InvariantCulture);
if (d.raid.serverView && d.raid.rank > 0)
{
Need(a, 3);
a[2] = d.raid.rank.ToString(CultureInfo.InvariantCulture);
}
break;
case "tower":
Need(a, 1);
a[0] = d.arena.towerFloor.ToString(CultureInfo.InvariantCulture);
break;
case "league":
Need(a, 2);
int left = LeagueRules.Left(screen.S.Db, d, now); // 날이 바뀌면 산 입장도 0 으로 → 그다음 최대를 계산
a[0] = left.ToString(CultureInfo.InvariantCulture);
a[1] = (ContentTables.Int("arena", "entries_per_day") + d.league.bought).ToString(CultureInfo.InvariantCulture);
break;
case "scenario":
var ep = NextScenario(d);
if (ep != null)
{
Need(a, 1);
a[0] = ep.S("s_title_ko");
}
break;
}
return a.ToArray();
}
/// <summary>연의 전기 「새 편」 = 열린 편(서장 제외 · 편 번호 순) 가운데 연의를 아직 이기지 못한 첫 편 · 없으면 null.</summary>
static ContentRow NextScenario(SaveData d)
{
foreach (var b in ScenarioModeRules.Battles())
{
if (b.I("n_no") <= 0 || !ScenarioModeRules.Unlocked(d, b)) continue;
var e = d.scenario.Get(b.S("s_id"), false);
if (e == null || !e.normal[0]) return b;
}
return null;
}
static void Need(List<string> a, int n)
{
while (a.Count < n) a.Add("");
}
public void RefreshStatus()
{
foreach (var s in Spots)
{
Text t;
if (!statusText.TryGetValue(s.id, out t)) continue;
var v = UiText.F(s.statusKey, Args(s));
if (t.text == v) continue;
t.text = v;
var st = L("status");
float w = t.preferredWidth + At(st, 2);
var pill = statusPill[s.id];
pill.sizeDelta = new Vector2(w, pill.sizeDelta.y);
t.rectTransform.sizeDelta = new Vector2(w, pill.sizeDelta.y);
var root = tagRoot[s.id];
var plq = (RectTransform)root.Find("Plaque");
root.sizeDelta = new Vector2(Mathf.Max(plq.sizeDelta.x, w), plq.sizeDelta.y + pill.sizeDelta.y - At(st, 3)); // 이름표 묶음 가운데 = 표 f_tag_x,f_tag_y(시안 tag())
}
}
/// <summary>장소 누름 = 표 open: tower 탑 · supply 보급전(첫 화면 = 던전 목록) · league 투기장 · raid 맹장 토벌전 · scenario 연의 전기 · soon 「준비 중」 · later 「추후 업데이트」(잠김).</summary>
public void Press(string id)
{
var s = SpotOf(id);
if (s == null) return;
switch (s.open)
{
case "tower": screen.SetPage(1); break;
case "supply": screen.SetPage(2); break;
case "league": screen.SetPage(3); break;
case "raid": screen.SetPage(4); break;
case "scenario": screen.SetPage(ArenaScreen.ScenarioPage); break;
case "soon": screen.Root.ComingSoon(UiText.T(s.nameKey)); break;
case "later": screen.Root.ComingSoon(UiText.T(s.nameKey), true); break;
default: Debug.LogWarning("[TKS] 연무장 장소 연결 없음(허브 표 open): " + id); break;
}
}
/// <summary>이름표 이름 · 상태 글자(테스트).</summary>
public string NameOf(string id)
{
Text t;
return nameText.TryGetValue(id, out t) ? t.text : null;
}
public string StatusOf(string id)
{
Text t;
return statusText.TryGetValue(id, out t) ? t.text : null;
}
public RectTransform TagOf(string id)
{
RectTransform t;
return tagRoot.TryGetValue(id, out t) ? t : null;
}
/// <summary>세운 장식 유닛 그림(발 = anchoredPosition · 연출 ArenaHubFx 가 묶음) · 없으면 null.</summary>
public RectTransform ActorRt(string spot, int slot)
{
RectTransform t;
return actorRt.TryGetValue(spot + ":" + slot, out t) ? t : null;
}
public Actor ActorOf(string spot, int slot)
{
foreach (var a in Actors)
if (a.spot == spot && a.slot == slot)
return a;
return null;
}
}
}