using System;
using UnityEngine;
using UnityEngine.UI;
namespace TKS.OutGame
{
///
/// 영웅 성장 창 공용 부품(PD 2026-11-20 「정보 · 진화 · 각성 · 외형을 우리 게임 화풍으로 재설계」 · Fable 기획 초안 r1) —
/// 제목 좌우 ◀ ▶(모든 성장 창 같은 자리) · 로비 배경 장면 창(로비와 같은 배율 규칙으로 영웅을 세움) · 명패 · 칸 바탕.
/// 값 = 표 UI/Growth/growth_ui(C45) · 표가 없으면 On = false → 각 창은 예전 배치.
///
public static class GrowthUi
{
public const string Table = "UI/Growth/growth_ui";
static ScreenTable tb;
static Sprite scene;
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
static void ResetStatics()
{
tb = null;
scene = null;
}
public static ScreenTable Tb
{
get
{
if (tb == null) tb = ScreenTable.Load(Table);
return tb;
}
}
public static bool On
{
get { return Tb != null; }
}
public static string[] L(string key)
{
return Tb != null ? Tb.L(key) : new string[0];
}
public static Color Col(string key, Color def)
{
return Tb != null ? Tb.Color(key, def) : def;
}
public static float At(string[] a, int i, float def = 0f)
{
return ScreenTable.At(a, i, def);
}
/// 테마 아이콘 그림(성장 부품은 Samguk 납품 = 아이콘 항목)을 판으로 — 9 분할 경계가 있으면 Sliced · 없으면 Simple. 그림이 없으면 둥근 판.
public static Image Paint(RectTransform rt, string id, Color c, bool raycast = false)
{
var img = rt.gameObject.AddComponent();
var sp = UISkin.Icon(id);
if (sp == null && UISkin.Apply(img, id))
{
img.color = c;
img.raycastTarget = raycast;
return img;
}
img.sprite = sp != null ? sp : UiKit.Round;
img.type = sp == null || sp.border != Vector4.zero ? Image.Type.Sliced : Image.Type.Simple;
img.color = c;
img.raycastTarget = raycast;
return img;
}
/// 성장 창 판 = 윗변을 화면 위에서 같은 y 에(◀ ▶ · 닫기 자리 통일) · 높이 = 내용 아래 끝 + 여백(빈 아래쪽 없음) · 표 panel_top.
public static void Place(RectTransform panel, float bottom)
{
if (panel == null || Tb == null) return;
var p = L("panel_top");
float h = Mathf.Max(At(p, 2, 560f), bottom + At(p, 1, 36f));
panel.anchorMin = panel.anchorMax = new Vector2(0.5f, 1f);
panel.pivot = new Vector2(0.5f, 1f);
panel.anchoredPosition = new Vector2(0f, -At(p, 0, 128f));
panel.sizeDelta = new Vector2(panel.sizeDelta.x, h);
}
// ---------- 제목 좌우 ◀ ▶ ----------
/// 팝업 제목 글자 양옆에 ◀ ▶(이름 Prev · Next) — onStep(-1 | 1). 제목 글자가 길면 그만큼 밀림.
public static void TitleArrows(RectTransform panel, Action onStep)
{
if (panel == null || onStep == null) return;
var head = panel.Find("Head") as RectTransform;
float tw = 260f;
float hy = 60f;
if (head != null)
{
var t = head.GetComponentInChildren();
if (t != null) tw = Mathf.Min(560f, t.preferredWidth);
hy = -head.anchoredPosition.y + head.rect.height * 0.5f;
}
var a = L("arrow");
float hit = At(a, 0, 80f), gap = At(a, 1, 44f), ic = At(a, 2, 56f);
foreach (var d in new[] { -1, 1 })
{
int k = d;
var b = UiKit.Rect(d < 0 ? "Prev" : "Next", panel, new Vector2(0.5f, 1f), new Vector2(0.5f, 0.5f), new Vector2(d * (tw * 0.5f + gap + hit * 0.5f), -hy), new Vector2(hit, hit));
var img = b.gameObject.AddComponent();
img.color = new Color(0f, 0f, 0f, 0f);
b.gameObject.AddComponent