227 lines
12 KiB
C#
227 lines
12 KiB
C#
|
|
using System;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.UI;
|
|||
|
|
|
|||
|
|
namespace TKS.OutGame
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 영웅 성장 창 공용 부품(PD 2026-11-20 「정보 · 진화 · 각성 · 외형을 우리 게임 화풍으로 재설계」 · Fable 기획 초안 r1) —
|
|||
|
|
/// 제목 좌우 ◀ ▶(모든 성장 창 같은 자리) · 로비 배경 장면 창(로비와 같은 배율 규칙으로 영웅을 세움) · 명패 · 칸 바탕.
|
|||
|
|
/// 값 = 표 UI/Growth/growth_ui(C45) · 표가 없으면 On = false → 각 창은 예전 배치.
|
|||
|
|
/// </summary>
|
|||
|
|
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);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>테마 아이콘 그림(성장 부품은 Samguk 납품 = 아이콘 항목)을 판으로 — 9 분할 경계가 있으면 Sliced · 없으면 Simple. 그림이 없으면 둥근 판.</summary>
|
|||
|
|
public static Image Paint(RectTransform rt, string id, Color c, bool raycast = false)
|
|||
|
|
{
|
|||
|
|
var img = rt.gameObject.AddComponent<Image>();
|
|||
|
|
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;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>성장 창 판 = 윗변을 화면 위에서 같은 y 에(◀ ▶ · 닫기 자리 통일) · 높이 = 내용 아래 끝 + 여백(빈 아래쪽 없음) · 표 panel_top.</summary>
|
|||
|
|
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);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ---------- 제목 좌우 ◀ ▶ ----------
|
|||
|
|
|
|||
|
|
/// <summary>팝업 제목 글자 양옆에 ◀ ▶(이름 Prev · Next) — onStep(-1 | 1). 제목 글자가 길면 그만큼 밀림.</summary>
|
|||
|
|
public static void TitleArrows(RectTransform panel, Action<int> 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<Text>();
|
|||
|
|
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<Image>();
|
|||
|
|
img.color = new Color(0f, 0f, 0f, 0f);
|
|||
|
|
b.gameObject.AddComponent<Button>().onClick.AddListener(() => onStep(k));
|
|||
|
|
var i = UiKit.Icon(b, d < 0 ? "arrow_prev" : "arrow_next", new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, ic);
|
|||
|
|
if (i != null) UiKit.DropShadow(i, 3f);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ---------- 장면 창 ----------
|
|||
|
|
|
|||
|
|
/// <summary>로비 배경 장면 창 — key = 표 scene_<key> · 영웅 = 로비 배율 규칙 · 대기 동작(Frame 층) · 반환 = 창(왼쪽 위 기준 그리기).</summary>
|
|||
|
|
public static RectTransform Scene(RectTransform panel, string key, HeroDb.Hero h)
|
|||
|
|
{
|
|||
|
|
Image unit;
|
|||
|
|
return Scene(panel, key, h, out unit);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>장면 창 + 세운 영웅 그림(외형 창 = 미리보기 덮어쓰기용 · UnitStand 가 꾸미기 레이어를 붙임).</summary>
|
|||
|
|
public static RectTransform Scene(RectTransform panel, string key, HeroDb.Hero h, out Image unitImg)
|
|||
|
|
{
|
|||
|
|
unitImg = null;
|
|||
|
|
var r = L("scene_" + key);
|
|||
|
|
float x = At(r, 0, 34f), y = At(r, 1, 130f), w = At(r, 2, 872f), hh = At(r, 3, 420f), z = At(r, 4, 1.3f);
|
|||
|
|
float fx = At(r, 5, 540f), fy = At(r, 6, 980f), px = At(r, 7, w * 0.5f), py = At(r, 8, hh - 40f);
|
|||
|
|
var root = UiKit.At(panel, "Scene", x, y, w, hh);
|
|||
|
|
// 둥근 마스크 안 = 배경 그림 + 발밑 그림자
|
|||
|
|
var mimg = root.gameObject.AddComponent<Image>();
|
|||
|
|
mimg.sprite = UiKit.Round;
|
|||
|
|
mimg.type = Image.Type.Sliced;
|
|||
|
|
mimg.color = Color.white;
|
|||
|
|
mimg.raycastTarget = false;
|
|||
|
|
root.gameObject.AddComponent<Mask>().showMaskGraphic = false;
|
|||
|
|
if (scene == null) scene = Resources.Load<Sprite>(Tb != null ? Tb.S("scene_sprite") : "");
|
|||
|
|
var src = L("scene_src");
|
|||
|
|
float sx = At(src, 0, 160f), sy = At(src, 1, 300f), sw = At(src, 2, 760f), sh = At(src, 3, 760f);
|
|||
|
|
if (scene != null)
|
|||
|
|
{
|
|||
|
|
// 그림 왼쪽 위(창 좌표) = 발 자리 − (원본 발 − 영역 시작) × zoom · 창을 다 덮게 맞춤
|
|||
|
|
float gw = sw * z, gh = sh * z;
|
|||
|
|
// 그림이 창보다 작으면 가운데(배율 표 잘못 = 경고) · 크면 창을 다 덮게 맞춤
|
|||
|
|
float gx = gw < w ? (w - gw) * 0.5f : Mathf.Clamp(px - (fx - sx) * z, w - gw, 0f), gy = gh < hh ? (hh - gh) * 0.5f : Mathf.Clamp(py - (fy - sy) * z, hh - gh, 0f);
|
|||
|
|
if (gw < w || gh < hh) Debug.LogWarning("[TKS] 성장 장면 창 " + key + " 배율이 작아 그림이 창을 다 못 덮음 — 표 growth_ui zoom 확인");
|
|||
|
|
var bg = UiKit.At(root, "Bg", gx, gy, gw, gh).gameObject.AddComponent<Image>();
|
|||
|
|
bg.sprite = scene;
|
|||
|
|
bg.raycastTarget = false;
|
|||
|
|
px = gx + (fx - sx) * z;
|
|||
|
|
py = gy + (fy - sy) * z;
|
|||
|
|
}
|
|||
|
|
float unit = Tb != null ? Tb.Num("unit_px", 206f) : 206f;
|
|||
|
|
foreach (var shd in LobbyScene.All("shadow"))
|
|||
|
|
{
|
|||
|
|
var glow = UISkin.Icon(shd.sprite);
|
|||
|
|
var s = UiKit.Rect("Shadow", root, new Vector2(0f, 1f), new Vector2(0.5f, 0.5f), new Vector2(px + shd.x * z, -(py + shd.y * z)), new Vector2(shd.w * z, shd.h * z));
|
|||
|
|
var simg = s.gameObject.AddComponent<Image>();
|
|||
|
|
simg.sprite = glow != null ? glow : UiKit.Circle;
|
|||
|
|
simg.color = shd.color;
|
|||
|
|
simg.raycastTarget = false;
|
|||
|
|
}
|
|||
|
|
// 영웅 = 대기 동작(매 프레임) → Frame 층(마스크 밖 · 창 안에 들어가게 배율을 표로 맞춤)
|
|||
|
|
var units = UiLayer.Group("SceneUnit", panel, UiRate.Frame, false);
|
|||
|
|
var stand = UiKit.UnitStand("Hero", units, h, new Vector2(0f, 1f), new Vector2(x + px, -(y + py)), unit * z, 1f);
|
|||
|
|
if (stand != null)
|
|||
|
|
{
|
|||
|
|
unitImg = stand.GetComponent<Image>();
|
|||
|
|
UiFrameAnim.Attach(unitImg, UnitArt.Load(h.art), "front_idle");
|
|||
|
|
}
|
|||
|
|
// 테(고동 외곽선 + 금 선) = 맨 위
|
|||
|
|
var fr = L("scene_frame");
|
|||
|
|
var frame = UiKit.Rect("Frame", panel, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(x - 4f, -(y - 4f)), new Vector2(w + 8f, hh + 8f));
|
|||
|
|
var fimg = Paint(frame, ScreenTable.Str(fr, 0).Length > 0 ? ScreenTable.Str(fr, 0) : "grow_scene_frame", ScreenTable.Col(fr, 1, Color.white));
|
|||
|
|
fimg.raycastTarget = false;
|
|||
|
|
return root;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>장면 창 위에 놓을 판(어두운 반투명 · 둥근) — 이름 · ★ 등.</summary>
|
|||
|
|
public static Image Card(Transform p, string name, float x, float y, float w, float h, float alpha)
|
|||
|
|
{
|
|||
|
|
var c = UiKit.Skin(UiKit.At(p, name, x, y, w, h), "card", new Color(0.08f, 0.09f, 0.16f, alpha));
|
|||
|
|
c.raycastTarget = false;
|
|||
|
|
return c;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>칸 바탕(남색 반투명 · 둥근) — 정보 · 진화 · 각성 공통.</summary>
|
|||
|
|
public static Image Row(Transform p, string name, float x, float y, float w, float h, bool raycast = false)
|
|||
|
|
{
|
|||
|
|
return UiKit.Skin(UiKit.At(p, name, x, y, w, h), "card", Col("row_bg", new Color(0.11f, 0.13f, 0.22f, 0.9f)), raycast);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>이름 명패(붉은 옻칠 + 금테 · 9 분할) + 이름 글자 — 반환 = 이름 글자.</summary>
|
|||
|
|
public static Text Plaque(Transform p, string name, string text, float x, float y, float w, float h, int size)
|
|||
|
|
{
|
|||
|
|
var np = L("name_plaque");
|
|||
|
|
var pl = Paint(UiKit.At(p, name + "Plaque", x, y, w, h), ScreenTable.Str(np, 0).Length > 0 ? ScreenTable.Str(np, 0) : "tre_plaque", Color.white);
|
|||
|
|
pl.raycastTarget = false;
|
|||
|
|
var t = UiKit.Title(UiKit.FillLabel(pl.transform, text, size, UiKit.White, TextAnchor.MiddleCenter, true, 18f), true);
|
|||
|
|
t.name = name;
|
|||
|
|
t.resizeTextForBestFit = true;
|
|||
|
|
t.resizeTextMinSize = Mathf.Max(18, size - 16);
|
|||
|
|
t.resizeTextMaxSize = size;
|
|||
|
|
return t;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>작은 목패(밝은 회색 나무 · 틴트) + 아이콘 + 글자 — 전투력 · 각성 몫 등.</summary>
|
|||
|
|
public static Text Tag(Transform p, string name, string icon, string text, float x, float y, float w, float h, int size, Color fg)
|
|||
|
|
{
|
|||
|
|
var tg = L("power_tag");
|
|||
|
|
var bg = Paint(UiKit.At(p, name + "Tag", x, y, w, h), ScreenTable.Str(tg, 0).Length > 0 ? ScreenTable.Str(tg, 0) : "tre_tag", ScreenTable.Col(tg, 1, new Color(0.15f, 0.17f, 0.29f, 1f)));
|
|||
|
|
bg.raycastTarget = false;
|
|||
|
|
float tx = 16f;
|
|||
|
|
if (!string.IsNullOrEmpty(icon))
|
|||
|
|
{
|
|||
|
|
var ic = UiKit.Icon(bg.transform, icon, new Vector2(0f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(h * 0.55f, 0f), h * 0.9f);
|
|||
|
|
if (ic != null) UiKit.DropShadow(ic, 2f);
|
|||
|
|
tx = h * 1.05f;
|
|||
|
|
}
|
|||
|
|
var t = UiKit.Title(UiKit.Label(bg.transform, text, size, fg, TextAnchor.MiddleLeft, new Vector2(0f, 0.5f), new Vector2(0f, 0.5f), new Vector2(tx, 2f), new Vector2(w - tx - 10f, h)), true);
|
|||
|
|
t.name = name;
|
|||
|
|
t.horizontalOverflow = HorizontalWrapMode.Overflow;
|
|||
|
|
return t;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|