ThreeKingdomsSlingshot/Assets/Scripts/OutGame/UI/HeroInfoWindow.cs

404 lines
21 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Globalization;
using UnityEngine;
using UnityEngine.UI;
namespace TKS.OutGame
{
/// <summary>
/// 영웅 「정보」 창(2026-11-20 개발요청_영웅정보 · 목업 영웅정보_img 01 · 02 · 03) — 배너(진영 색 · 큰 유닛 · 한자 무늬 · 이름판) · 탭 능력치 / 열전 · ◀ ▶.
/// 능력치 = 기본(병종 기본 × 영웅 배율) + 성장 = 합계(HeroRules.Compute 그대로) · 전투 능력치 7(스킬 패시브 + 각성 + 보물 세트 · 0 = 회색) · 성장 내역 6 + 바로가기 · 칸 = 내역 창.
/// 열전 = hero_chronicle(연도 · 사건 · 연의 전기 편) · 없으면 「열전 준비 중」. 글자 = UI/HeroInfo/info_text · 값 = 표(C45).
/// </summary>
public static class HeroInfoWindow
{
public const string Texts = "UI/HeroInfo/info_text";
const float W = 940f;
const float L = 34f;
const float RW = 872f;
static string heroId;
static bool bio;
/// <summary>시험 · 캡처 — 마지막 창(stats · bio · breakdown).</summary>
public static string Last { get; private set; }
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
static void ResetStatics()
{
heroId = Last = null;
bio = false;
}
static string T(string k)
{
return UiText.T(k).Replace("\\n", "\n");
}
static string F(string k, params string[] a)
{
return UiText.F(k, a).Replace("\\n", "\n");
}
static string P(float v)
{
return v.ToString("0.#", CultureInfo.InvariantCulture);
}
static Text Txt(RectTransform p, string name, string s, int size, Color c, float x, float y, float w, float h, TextAnchor a = TextAnchor.MiddleLeft, bool title = false)
{
var t = UiKit.Label(p, s, size, c, a, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(x, -y), new Vector2(w, h), title);
t.name = name;
if (title) UiKit.Title(t, true);
t.horizontalOverflow = HorizontalWrapMode.Overflow;
return t;
}
static Image Box(RectTransform p, string name, float x, float y, float w, float h, Color c, bool raycast = false)
{
return UiKit.Skin(UiKit.At(p, name, x, y, w, h), "card", c, raycast);
}
static Color Soft
{
get { return UiKit.Col("text_soft", UiKit.InkSoft); }
}
// ---------- 값(지금 HeroRules 그대로 · 기본 · 성장 몫만 나눠 꺼냄) ----------
/// <summary>기본(병종 기본 × 영웅 배율) · 합계 — stat = hp|atk|def.</summary>
public static void BaseTotal(HeroRules.Stats st, string stat, out float baseV, out float total)
{
switch (stat)
{
case "hp":
baseV = st.baseHp * st.hpMult;
total = st.hp;
break;
case "def":
baseV = st.baseDef * st.defMult;
total = st.def;
break;
default:
baseV = st.baseAtk * st.atkMult;
total = st.atk;
break;
}
}
/// <summary>성장 내역 % (공격력 기준 · hero_info_sources s_key).</summary>
public static float SourcePct(HeroRules.Stats st, string key)
{
switch (key)
{
case "lv": return st.lvPct;
case "promo": return st.promoPct + st.gearPct;
case "star": return st.starPct;
case "train": return st.trainPct;
case "treasure": return st.treasureAtkPct;
case "awaken": return st.awakenAtkPct;
}
return 0f;
}
/// <summary>전투 능력치(표 Battle 키 → 표시 % · 스킬 패시브 + 각성 + 보물 세트 합 · 밀기 = 곱 → % · 받는 피해 감소 = 양수 %).</summary>
public static Dictionary<string, float> BattleStats(OutGameSession s, HeroDb.Hero h, HeroState hs)
{
var db = s.Db;
var res = new Dictionary<string, float>();
foreach (var r in db.HeroInfo.stats)
if (r.section == "Battle") res[r.key] = 0f;
var fx = new List<SkillEffect>();
fx.AddRange(AwakenRules.Effects(db, hs));
var sk = SkillCatalog.Get(h.skillPassive);
if (sk != null) fx.AddRange(sk.ScaledEffects(SkillRules.Level(hs, 1), SkillRules.PassiveMult(db, hs != null ? hs.star : h.rarity)));
var tre = TreasureRules.BattleEffects(db, s.Save);
if (tre != null) fx.AddRange(tre);
foreach (var e in fx)
{
if (e == null || !res.ContainsKey(e.Key)) continue;
float v;
switch (e.Key)
{
case SkillKeys.PushMult:
v = (e.P - 1f) * 100f;
break;
case SkillKeys.CounterTakenPct:
case SkillKeys.DmgTakenRangedPct:
v = -e.P * 100f;
break;
default:
v = e.P * 100f;
break;
}
res[e.Key] += v;
}
return res;
}
// ---------- 창 ----------
public static void Open(OutGameRoot root, string id)
{
heroId = id;
bio = false;
Draw(root);
}
static void Draw(OutGameRoot root)
{
UiText.Use(Texts);
var s = root.Session;
var db = s.Db;
var h = s.Def(heroId);
var hs = s.Save.Hero(heroId);
if (h == null || h.isSoldier || db.HeroInfo == null)
{
root.Toast(T("hi_none"));
return;
}
Last = bio ? "bio" : "stats";
var content = root.ModalCustom(T("hi_title"), 1690f);
var panel = (RectTransform)content.parent;
// ◀ ▶ = 「영웅 정보」 제목 좌우(PD 2026-11-20)
GrowthUi.TitleArrows(panel, k =>
{
heroId = root.HeroDetail.StepHero(k);
Draw(root);
});
var st = s.StatsOf(heroId);
// 장면 창 = 로비 배경 · 영웅 오른쪽(PD 2026-11-20 「캐릭터 배경을 로비와 같이」 · 구 진영 원색 판 폐지)
var sc = GrowthUi.Scene(panel, "info", h);
float y = sc.anchoredPosition.y * -1f;
var ic = GrowthUi.L("info_card");
float cx = GrowthUi.At(ic, 0, 54f), cy = GrowthUi.At(ic, 1, 150f), cw = GrowthUi.At(ic, 2, 440f);
// 진영 · 병종 · 승급 칩
var fb = UiKit.FactionBadge(panel, h.faction, new Vector2(0f, 1f), new Vector2(0.5f, 0.5f), new Vector2(cx + 26f, -(cy + 26f)), 48f);
if (fb != null) UiKit.DropShadow(fb, 2f);
var ti = UiKit.Icon(panel, UiKit.TypeSymbolId(h.type), new Vector2(0f, 1f), new Vector2(0.5f, 0.5f), new Vector2(cx + 84f, -(cy + 26f)), 48f);
if (ti != null) UiKit.DropShadow(ti, 2f);
if (hs != null)
{
var gc = UiKit.Skin(UiKit.At(panel, "Grade", cx + 116f, cy + 4f, 60f, 44f), "chip", UiKit.GradeColor(hs.grade));
UiKit.GradeTint(gc, hs.grade);
UiKit.Title(UiKit.FillLabel(gc.transform, UiKit.GradeKo(hs.grade), 24, UiKit.White), true);
}
// 이름 = 붉은 옻칠 명패
var np = GrowthUi.L("name_plaque");
GrowthUi.Plaque(panel, "Name", h.nameKo, cx, cy + 60f, Mathf.Min(cw, GrowthUi.At(np, 1, 404f)), GrowthUi.At(np, 2, 92f), 46);
// 별호 · ★ · 레벨 = 장면 위 어두운 반투명 판
var card = GrowthUi.Card(panel, "Plate", cx, cy + 164f, cw, 150f, GrowthUi.At(ic, 3, 0.82f)).rectTransform;
string ep = db.HeroInfo.EpithetOf(h.id);
Txt(card, "Epithet", (ep.Length > 0 ? ep + " · " : "") + UnitTypeInfo.Korean(h.type), 24, GrowthUi.Col("soft", Soft), 20f, 10f, cw - 40f, 36f);
int max = db.Evolve.MaxStar, star = hs != null ? hs.star : h.rarity;
for (int i = 0; i < max; i++)
{
var si = UiKit.Icon(card, i < star ? "star_l" : "star_off", new Vector2(0f, 1f), new Vector2(0.5f, 0.5f), new Vector2(42f + i * 50f, -74f), 48f);
if (si != null) UiKit.DropShadow(si, 2f);
}
var lv = s.Save.Level(heroId);
Txt(card, "Lv", "Lv " + (lv != null ? lv.lv : 1) + " / " + AwakenRules.HeroLevelCap(db, s.Save, lv), 30, UiKit.White, 24f, 102f, cw - 48f, 40f, TextAnchor.MiddleLeft, true);
// 전투력 = 목패 + 칼 아이콘 · 각성 몫은 아래 작은 글자
var pt = GrowthUi.Tag(panel, "Power", "sword", F("hi_power", st.power.ToString("N0")), cx, cy + 326f, cw, 64f, 32, GrowthUi.Col("gold", UiKit.Coin));
if (hs != null)
{
var aw = Txt((RectTransform)pt.transform.parent, "AwPower", F("hi_awaken_power", AwakenRules.Power(db, s.Cfg, h, hs, s.Save).ToString("N0")), 22, GrowthUi.Col("soft", Soft), 0f, 14f, cw - 18f, 36f, TextAnchor.MiddleRight);
aw.raycastTarget = false;
}
y += sc.rect.height + 20f;
// 탭
float tw = (RW - 16f) * 0.5f;
for (int i = 0; i < 2; i++)
{
bool on = (i == 1) == bio;
bool to = i == 1;
var tb = UiKit.SkinBtn(panel, i == 0 ? "TabStats" : "TabBio", on ? "btn_red" : "btn_s_gray", UiKit.White, T(i == 0 ? "hi_tab_stats" : "hi_tab_bio"), 32, UiKit.White, L + i * (tw + 16f), y, tw, 78f, () =>
{
bio = to;
Draw(root);
});
if (!UISkin.Has(on ? "btn_red" : "btn_s_gray")) tb.GetComponent<Image>().color = on ? UiKit.Red : UiKit.Dark;
}
y += 96f;
float end = bio ? DrawBio(root, panel, h, y) : DrawStats(root, panel, h, hs, st, y);
GrowthUi.Place(panel, end); // 판 윗변 고정 · 높이 = 내용(Fable QA r1 M1 · M2)
}
static void Section(RectTransform panel, string name, string head, string hint, float y)
{
var t = Txt(panel, name, head, 30, UiKit.White, L + 10f, y, 400f, 44f, TextAnchor.MiddleLeft, true);
Txt(panel, name + "Hint", hint, 20, Soft, L + 24f + t.preferredWidth, y + 6f, 400f, 34f);
}
static float DrawStats(OutGameRoot root, RectTransform panel, HeroDb.Hero h, HeroState hs, HeroRules.Stats st, float y)
{
var db = root.Session.Db;
float cw = (RW - 16f) * 0.5f;
Section(panel, "Base", T("hi_base"), T("hi_base_hint"), y);
y += 52f;
int bi = 0;
var bicons = new Dictionary<string, string>();
foreach (var b in GrowthUi.Tb != null ? GrowthUi.Tb.All("base_icon") : new List<string[]>()) bicons[ScreenTable.Str(b, 0)] = ScreenTable.Str(b, 1);
foreach (var r in db.HeroInfo.stats)
{
if (r.section != "Base") continue;
float x = L + (bi % 2) * (cw + 16f), cy = y + (bi / 2) * 96f;
var c = GrowthUi.Row(panel, "Base_" + r.key, x, cy, cw, 86f, r.show == "BaseBonus");
var cr = c.rectTransform;
string bic;
float nx = 16f;
if (bicons.TryGetValue(r.key, out bic))
{
var bimg = UiKit.Icon(cr, bic, new Vector2(0f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(46f, 0f), 62f);
if (bimg != null)
{
UiKit.DropShadow(bimg, 2f);
nx = 86f;
}
}
Txt(cr, "Name", r.nameKo, 26, UiKit.White, nx, 22f, 200f, 42f, TextAnchor.MiddleLeft, true);
if (r.show == "BaseBonus")
{
float bv, tot;
BaseTotal(st, r.key, out bv, out tot);
Txt(cr, "Base", Mathf.RoundToInt(bv).ToString("N0"), 20, UiKit.White, cw - 330f, 12f, 120f, 30f, TextAnchor.MiddleRight);
Txt(cr, "Bonus", "+" + Mathf.RoundToInt(tot - bv).ToString("N0"), 20, UiKit.Col("up", UiKit.Ok), cw - 330f, 42f, 120f, 30f, TextAnchor.MiddleRight);
Txt(cr, "Total", Mathf.RoundToInt(tot).ToString("N0"), 38, UiKit.White, cw - 200f, 18f, 184f, 50f, TextAnchor.MiddleRight, true);
string key = r.key, nm = r.nameKo;
c.gameObject.AddComponent<Button>().onClick.AddListener(() => OpenBreakdown(root, key, nm));
}
else Txt(cr, "Total", st.power.ToString("N0"), 38, UiKit.Col("gold", UiKit.Coin), cw - 240f, 18f, 224f, 50f, TextAnchor.MiddleRight, true);
bi++;
}
y += ((bi + 1) / 2) * 96f + 16f;
Section(panel, "Battle", T("hi_battle"), T("hi_battle_hint"), y);
y += 52f;
var vals = BattleStats(root.Session, h, hs);
int k = 0;
foreach (var r in db.HeroInfo.stats)
{
if (r.section != "Battle") continue;
float x = L + (k % 2) * (cw + 16f), cy = y + (k / 2) * 66f;
float v;
vals.TryGetValue(r.key, out v);
bool zero = Mathf.Abs(v) < 0.05f;
var aw = db.Awaken != null ? db.Awaken.StatOf(r.key) : null;
string nm = r.nameKo.Length > 0 ? r.nameKo : aw != null ? aw.nameKo : r.key;
string unit = aw != null ? aw.unit : "%";
var c = GrowthUi.Row(panel, "Battle_" + r.key, x, cy, cw, 58f);
var cr = c.rectTransform;
var chip = Box(cr, "Unit", 10f, 9f, 50f, 40f, UiKit.Col("chip_dark", UiKit.Dark));
UiKit.Title(UiKit.FillLabel(chip.transform, unit, 18, UiKit.White), true);
Color col = zero ? Soft : UiKit.White;
Txt(cr, "Name", nm, 22, col, 72f, 12f, 260f, 34f, TextAnchor.MiddleLeft, true);
Txt(cr, "Value", (zero ? "0" : (v > 0f ? "+" : "") + P(v)) + unit, 24, col, cw - 180f, 12f, 164f, 34f, TextAnchor.MiddleRight, true);
k++;
}
y += ((k + 1) / 2) * 66f + 16f;
// 성장 내역 = 칸 6개(아이콘 · 이름 · 기여 %) 한 줄 — 막대 · 바로가기 폐지(PD 2026-11-20 「성장 내역이 복잡 · 바로가기는 거의 안 씀」)
Section(panel, "Growth", T("hi_growth"), T("hi_growth_hint"), y);
y += 52f;
var icons = new Dictionary<string, string>();
foreach (var gi in GrowthUi.Tb != null ? GrowthUi.Tb.All("growth_icon") : new List<string[]>()) icons[ScreenTable.Str(gi, 0)] = ScreenTable.Str(gi, 1);
int gn = db.HeroInfo.sources.Count;
float gw = (RW - (gn - 1) * 12f) / Mathf.Max(1, gn), gh = 150f;
for (int i = 0; i < gn; i++)
{
var r = db.HeroInfo.sources[i];
float v = SourcePct(st, r.key);
bool zero = v < 0.05f;
var c = GrowthUi.Row(panel, "Grow_" + r.key, L + i * (gw + 12f), y, gw, gh).rectTransform;
string icon;
if (icons.TryGetValue(r.key, out icon))
{
var gi = UiKit.Icon(c, icon, new Vector2(0.5f, 1f), new Vector2(0.5f, 0.5f), new Vector2(0f, -44f), 64f);
if (gi != null)
{
UiKit.DropShadow(gi, 2f);
if (zero) gi.color = new Color(1f, 1f, 1f, 0.45f);
}
}
Txt(c, "Name", r.nameKo, 22, zero ? GrowthUi.Col("soft", Soft) : UiKit.White, 0f, 80f, gw, 30f, TextAnchor.MiddleCenter, true);
Txt(c, "Value", "+" + P(v) + "%", 28, zero ? GrowthUi.Col("soft", Soft) : GrowthUi.Col("up", UiKit.Ok), 0f, 110f, gw, 34f, TextAnchor.MiddleCenter, true);
}
return y + gh;
}
/// <summary>기본 능력치 내역 창(목업 02) — 곱하는 배수 + 근거 · 합계 · 계산식.</summary>
public static void OpenBreakdown(OutGameRoot root, string stat, string nameKo)
{
UiText.Use(Texts);
var s = root.Session;
var h = s.Def(heroId);
var hs = s.Save.Hero(heroId);
var st = s.StatsOf(heroId);
Last = "breakdown";
var content = root.ModalCustom(F("hi_bd_title", nameKo), 860f);
var panel = (RectTransform)content.parent;
float bv, tot;
BaseTotal(st, stat, out bv, out tot);
float tr = stat == "hp" ? st.trainHpPct : stat == "def" ? st.trainDefPct : st.trainPct;
float ts = stat == "hp" ? st.treasureHpPct : stat == "def" ? st.treasureDefPct : st.treasureAtkPct;
float aw = stat == "hp" ? st.awakenHpPct : stat == "def" ? st.awakenDefPct : st.awakenAtkPct;
var lv = s.Save.Level(heroId);
string type = UnitTypeInfo.Korean(h.type);
var rows = new List<string[]>
{
new[] { T("hi_bd_base"), F("hi_bd_base_note", type, h.nameKo), Mathf.RoundToInt(bv).ToString("N0") },
new[] { "레벨", F("hi_bd_lv_note", (lv != null ? lv.lv : 1).ToString(), P(st.lvPct)), "×" + (1f + st.lvPct / 100f).ToString("0.###", CultureInfo.InvariantCulture) },
new[] { T("hi_bd_promo"), F("hi_bd_promo_note", hs != null ? UiKit.GradeKo(hs.grade) : "-"), "×" + (1f + (st.promoPct + st.gearPct) / 100f).ToString("0.###", CultureInfo.InvariantCulture) },
new[] { "성급", F("hi_bd_star_note", (hs != null ? hs.star : h.rarity).ToString()), "×" + (1f + st.starPct / 100f).ToString("0.###", CultureInfo.InvariantCulture) },
new[] { "병법 훈련", F("hi_bd_train_note", type), "×" + (1f + tr / 100f).ToString("0.###", CultureInfo.InvariantCulture) },
new[] { T("hi_bd_ta"), F("hi_bd_ta_note", P(ts), P(aw)), "×" + ((1f + ts / 100f) * (1f + aw / 100f)).ToString("0.###", CultureInfo.InvariantCulture) },
};
float y = 130f;
foreach (var r in rows)
{
Txt(panel, "R_" + r[0], r[0], 24, UiKit.White, L + 10f, y, 230f, 52f, TextAnchor.MiddleLeft, true);
Txt(panel, "N_" + r[0], r[1], 20, Soft, L + 240f, y, 420f, 52f);
Txt(panel, "V_" + r[0], r[2], 30, UiKit.White, L + RW - 230f, y, 220f, 52f, TextAnchor.MiddleRight, true);
y += 60f;
}
Txt(panel, "Total", T("hi_bd_total"), 26, UiKit.Col("gold", UiKit.Coin), L + 10f, y + 8f, 200f, 60f, TextAnchor.MiddleLeft, true);
Txt(panel, "TotalNote", F("hi_bd_total_note", Mathf.RoundToInt(bv).ToString("N0"), Mathf.RoundToInt(tot - bv).ToString("N0")), 22, Soft, L + 240f, y + 8f, 400f, 60f, TextAnchor.MiddleRight);
Txt(panel, "TotalV", Mathf.RoundToInt(tot).ToString("N0"), 44, UiKit.White, L + RW - 230f, y + 4f, 220f, 66f, TextAnchor.MiddleRight, true);
y += 80f;
var f = Txt(panel, "Formula", T("hi_bd_formula"), 20, Soft, L + 10f, y, RW - 20f, 60f, TextAnchor.UpperLeft);
f.horizontalOverflow = HorizontalWrapMode.Wrap;
y += 70f;
UiKit.SkinBtn(panel, "BdClose", UISkin.Has("btn_s_gray") ? "btn_s_gray" : "button", UiKit.White, "닫기", 32, UiKit.White, (W - 360f) * 0.5f, y, 360f, 90f, () => Draw(root));
}
static float DrawBio(OutGameRoot root, RectTransform panel, HeroDb.Hero h, float y)
{
var db = root.Session.Db;
var evs = db.HeroInfo.ChronicleOf(h.id);
string ep = db.HeroInfo.EpithetOf(h.id);
// 열전 = 인물 설명(이름 · 한자 · 별호 · 진영 · 병종) + 열전 문단(사건 제목 · 한 줄) 만 — 연표 막대 · 연도 배지 · 연의 전기 바로가기 폐지(PD 2026-11-20)
var head = GrowthUi.Row(panel, "BioHeadBox", L, y, RW, 132f).rectTransform;
Txt(head, "BioHead", F("hi_bio_head", h.nameKo), 34, GrowthUi.Col("gold", UiKit.Coin), 24f, 14f, RW - 48f, 48f, TextAnchor.MiddleLeft, true);
Txt(head, "BioWho", (h.hanja ?? "") + (ep.Length > 0 ? " · " + ep : "") + " · " + UnitTypeInfo.Korean(h.type), 24, UiKit.White, 24f, 70f, RW - 48f, 44f);
y += 148f;
if (evs.Count == 0)
{
var e = GrowthUi.Row(panel, "BioEmpty", L, y, RW, 200f);
Txt(e.rectTransform, "T", T("hi_bio_empty"), 32, Soft, 0f, 70f, RW, 60f, TextAnchor.MiddleCenter, true);
return y + 200f;
}
var body = GrowthUi.Row(panel, "BioBody", L, y, RW, 40f).rectTransform;
float by = 22f;
foreach (var ev in evs)
{
var item = UiKit.At(body, "Ev_" + ev.order, 0f, by, RW, 84f);
Txt(item, "Title", ev.title, 30, UiKit.White, 28f, 0f, RW - 56f, 40f, TextAnchor.MiddleLeft, true);
var tx = Txt(item, "Text", ev.text, 25, GrowthUi.Col("soft", Soft), 28f, 42f, RW - 56f, 34f, TextAnchor.UpperLeft);
tx.horizontalOverflow = HorizontalWrapMode.Wrap;
by += 42f + Mathf.Max(34f, tx.preferredHeight) + 18f;
}
body.sizeDelta = new Vector2(RW, by);
return y + by;
}
}
}