ThreeKingdomsSlingshot/Assets/Scripts/OutGame/Event/EventScreen.cs

744 lines
33 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>
/// 이벤트 화면(PD 2026-11-19 「게임에 구현해」 · 시안 event_attend/final/mock/mock_event_*.png 7장) — 로비 오른쪽 「이벤트」 버튼(PD 결정 ① · 기기 세이브 모드만).
/// 하단 = 이벤트 탭 4(출석부 · 특별 미션 · 행운 룰렛 · 특별 이벤트 = 「준비 중」 토스트만 · 메인 하단 탭 대신) · 위 = 재화 바 · 「이벤트」 제목 띠.
/// 배치 = 시안 좌표(1080 × 1920)를 그대로 쓰는 판(Fit · 배율 Z = 화면 폭 · 본문 높이에 맞춤 · 아래로 긴 화면 = 아래 묶음만 내려가고 판 · 목록이 늘어남).
/// 값 = 화면 표 Resources/UI/Event/event_screen(자리 · 크기 · 색 · 그림 · C45) · 글자 = event_text(UiText) · 규칙 = EventRules(표 Resources/Event).
/// 층(P41): 화면(Event) → Bg(Static · 바탕 그러데이션) · Page/Art(Static · 배너 · 판 · 나무 · 배경) · Page/Info(Event + 레이캐스터 · 칸 · 글자 · 버튼) · Page/Fx(Frame · 룰렛 도는 고리) · Tabs(Event + 레이캐스터) · 팝업 = 위 덮개 루트(Event).
/// </summary>
public partial class EventScreen : OutGameScreen
{
public const string Table = "UI/Event/event_screen";
public const int PageAttend = 0;
public const int PageMission = 1;
public const int PageRoulette = 2;
public const int PageSpecial = 3;
ScreenTable tb;
RectTransform bgRoot, pageRoot, art, info, fx, tabsRoot, popup;
readonly Dictionary<string, Text> texts = new Dictionary<string, Text>();
readonly List<Image> tabFocus = new List<Image>();
readonly List<RectTransform> tabIcon = new List<RectTransform>();
readonly List<Text> tabText = new List<Text>();
readonly List<GameObject> tabDot = new List<GameObject>();
readonly List<string> tabIds = new List<string>();
bool built;
/// <summary>지금 쪽(0 출석부 · 1 특별 미션 · 2 행운 룰렛).</summary>
public int Page { get; private set; }
/// <summary>시안 배율 · 시안 칸 높이(1920 + 아래로 늘어난 몫) · 늘어난 몫.</summary>
public float Z { get; private set; }
public float Hm { get; private set; }
public float Extra { get; private set; }
/// <summary>표 · 그림이 다 있는가(없으면 로비 버튼 = 준비 중).</summary>
public bool Ready
{
get { return tb != null && EventData.Loaded; }
}
/// <summary>메인 하단 탭 대신 이벤트 탭(OutGameRoot.Show 가 메인 탭을 끔).</summary>
public override bool OwnTabBar
{
get { return true; }
}
public RectTransform ArtLayer
{
get { return art; }
}
public RectTransform InfoLayer
{
get { return info; }
}
public RectTransform FxLayer
{
get { return fx; }
}
public RectTransform TabsLayer
{
get { return tabsRoot; }
}
public bool PopupOpen
{
get { return popup != null; }
}
public RectTransform Popup
{
get { return popup; }
}
/// <summary>정보 글자(테스트 · 없으면 null).</summary>
public string TextOf(string name)
{
Text t;
return texts.TryGetValue(name, out t) && t != null ? t.text : null;
}
/// <summary>하단 이벤트 탭 붉은 점(테스트).</summary>
public bool TabDot(int i)
{
return i >= 0 && i < tabDot.Count && tabDot[i] != null && tabDot[i].activeSelf;
}
// ---------- 표 ----------
string S_(string key)
{
return tb != null ? tb.S(key) : "";
}
string[] L(string key)
{
return tb != null ? tb.L(key) : new string[0];
}
static float At(string[] a, int i)
{
return ScreenTable.At(a, i, 0f);
}
static string Str(string[] a, int i)
{
return ScreenTable.Str(a, i);
}
static Color Col(string[] a, int i)
{
return ScreenTable.Col(a, i, Color.white);
}
Color C(string key, int i = 0)
{
return Col(L(key), i);
}
float N(string key, int i)
{
return At(L(key), i);
}
static Color A(Color c, float a)
{
c.a = a;
return c;
}
/// <summary>글자 키 → 글자(표 안 「\n」 = 줄바꿈).</summary>
static string T(string key)
{
return UiText.T(key).Replace("\\n", "\n");
}
static string F(string key, params string[] args)
{
return UiText.F(key, args).Replace("\\n", "\n");
}
static string Num(int v)
{
return v.ToString("N0", CultureInfo.InvariantCulture);
}
static Sprite Sp(string path)
{
return string.IsNullOrEmpty(path) ? null : Resources.Load<Sprite>(path);
}
// ---------- 만들기 ----------
public override void Build()
{
tb = ScreenTable.Load(Table);
if (tb == null)
{
Debug.LogWarning("[TKS] 이벤트 화면 표 없음: " + Table);
return;
}
UiText.Use(S_("texts"));
// 바탕(Static · 세로 그러데이션 · 시안 screen())
bgRoot = UiLayer.Group("Bg", Rt, UiRate.Static, false);
var bg = UiKit.Fill("Grad", bgRoot).gameObject.AddComponent<Image>();
bg.raycastTarget = true; // 아래 화면 누름 막기
UiGradient.Add(bg, C("bg", 0), C("bg", 1));
Header(T(S_("title_key")), "", true);
pageRoot = UiKit.Rect("Page", Rt, new Vector2(0f, 1f), new Vector2(0f, 1f), Vector2.zero, new Vector2(1080f, 1920f));
art = UiLayer.Group("Art", pageRoot, UiRate.Static, false);
info = UiLayer.Group("Info", pageRoot, UiRate.Event, true);
fx = UiLayer.Group("Fx", pageRoot, UiRate.Frame, false);
tabsRoot = UiLayer.Group("EventTabs", Rt, UiRate.Event, true);
BuildTabs();
built = true;
}
/// <summary>쪽을 열고 다시 그린다(로비 버튼 = 출석부 · 테스트).</summary>
public void Open(int page)
{
Page = Mathf.Clamp(page, PageAttend, PageRoulette);
if (Root != null && Root.Current != this) Root.Show(this);
else ShowPage(Page);
}
public override void OnShow()
{
if (!built) return;
bool ch = EventRules.Tick(S.Save, S.Now);
ShowPage(Page);
if (ch) S.Commit();
}
public override void Refresh()
{
if (!built || !Rt.gameObject.activeInHierarchy || Root.Current != this) return;
BuildInfo();
if (popup != null && popupRefresh != null) popupRefresh();
}
/// <summary>화면 크기가 바뀌었을 때 다시 배치(캡처 · 긴 화면 확인).</summary>
public void Relayout()
{
if (built && Root.Current == this) ShowPage(Page);
}
/// <summary>하단 이벤트 탭 누름(테스트 · 캡처 · 0 출석부 · 1 특별 미션 · 2 행운 룰렛 · 3 특별 이벤트).</summary>
public void TapTab(int i)
{
OnTabTap(i);
}
/// <summary>이벤트 미션 · 선물 팩 팝업(룰렛 쪽 아래 버튼 · 테스트 · 캡처).</summary>
public void OpenQuestPopup()
{
OpenQuest();
}
public void OpenPackPopup()
{
OpenPack();
}
public override bool OnBack()
{
if (popup != null)
{
ClosePopup();
return true;
}
return false;
}
/// <summary>쪽 바꿈 = 판(Art) · 정보(Info) 다시.</summary>
void ShowPage(int p)
{
StopSpin();
ClosePopup();
Page = p;
Measure();
texts.Clear(); // 판 · 정보 글자 기록(정보만 다시 그릴 때는 같은 이름을 덮어씀)
UiKit.Clear(art);
UiKit.Clear(fx);
switch (Page)
{
case PageAttend: AttendArt(); break;
case PageMission: MissionArt(); break;
case PageRoulette: RouletteArt(); break;
}
BuildInfo();
}
void BuildInfo()
{
UiKit.Clear(info);
switch (Page)
{
case PageAttend: AttendInfo(); break;
case PageMission: MissionInfo(); break;
case PageRoulette: RouletteInfo(); break;
}
RefreshTabs();
}
/// <summary>
/// 시안 판 배율 — 본문(제목 띠 아래 ~ 하단 탭 위) 기준 Z = min(폭 / 1080, 본문 높이 / 시안 본문 높이) · 판 위끝 = 시안 y 224 가 제목 띠 아래끝에 오게 ·
/// 판 높이 Hm = 시안 칸으로 본 화면 높이(늘어난 몫 Extra = 아래 묶음이 내려가는 값).
/// </summary>
void Measure()
{
Canvas.ForceUpdateCanvases();
var r = Rt.rect;
float top = OutGameRoot.TopBarH + OutGameRoot.HeaderH, bot = OutGameRoot.TabBarH;
float mockBody = 1920f - top - bot;
float w = r.width > 1f ? r.width : 1080f, h = r.height > 1f ? r.height : 1920f;
Z = Mathf.Min(w / 1080f, (h - top - bot) / mockBody);
if (Z <= 0f) Z = 1f;
Hm = top + (h - top - bot) / Z + bot;
Extra = Mathf.Max(0f, Hm - 1920f);
pageRoot.localScale = new Vector3(Z, Z, 1f);
pageRoot.anchoredPosition = new Vector2((w - 1080f * Z) * 0.5f, -(top - top * Z));
pageRoot.sizeDelta = new Vector2(1080f, Hm);
}
// ---------- 하단 이벤트 탭(OutGameRoot.BuildTabBar 와 같은 부품) ----------
void BuildTabs()
{
var bar = UiKit.Rect("TabBar", tabsRoot, new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), Vector2.zero, new Vector2(1080f, OutGameRoot.TabBarH));
bar.anchorMin = new Vector2(0f, 0f);
bar.anchorMax = new Vector2(1f, 0f);
bar.offsetMin = Vector2.zero;
bar.offsetMax = new Vector2(0f, OutGameRoot.TabBarH);
UiKit.Skin(bar, "tabbar", UiKit.Col("chrome_tab", UiKit.BarColor), true);
var items = tb.All("tab");
var ts = L("tab_size");
var tf = L("tab_focus");
var tt = L("tab_text");
for (int i = 0; i < items.Count; i++)
{
int k = i;
var it = items[i];
tabIds.Add(Str(it, 0));
var cell = UiKit.Rect("Tab" + i, bar, Vector2.zero, Vector2.zero, Vector2.zero, Vector2.zero);
cell.anchorMin = new Vector2(i / (float)items.Count, 0f);
cell.anchorMax = new Vector2((i + 1) / (float)items.Count, 1f);
cell.offsetMin = cell.offsetMax = Vector2.zero;
var hit = cell.gameObject.AddComponent<Image>();
hit.color = new Color(0f, 0f, 0f, 0f);
cell.gameObject.AddComponent<Button>().onClick.AddListener(() => OnTabTap(k));
var focus = UiKit.Rect("Focus", cell, new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), Vector2.zero, new Vector2(At(tf, 0), At(tf, 1)));
var fimg = UiKit.Skin(focus, "tab_focus", Col(tf, 2));
UiKit.Skin(UiKit.Rect("Light", focus, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -6f), new Vector2(At(tf, 3), At(tf, 4))), "tab_focus_light", A(Col(tf, 5), At(tf, 6)));
tabFocus.Add(fimg);
var ic = UiKit.Rect("Icon", cell, new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), new Vector2(0f, At(ts, 2)), Vector2.one * At(ts, 0));
var ii = ic.gameObject.AddComponent<Image>();
ii.sprite = Sp(Str(it, 2));
ii.preserveAspect = true;
ii.raycastTarget = false;
var sh = ic.gameObject.AddComponent<Shadow>();
sh.effectColor = UiKit.Col("icon_shadow", Color.black);
sh.effectDistance = new Vector2(0f, -4f);
tabIcon.Add(ic);
var t = UiKit.Label(cell, T(Str(it, 1)), Mathf.RoundToInt(At(ts, 4)), Col(tt, 1), TextAnchor.MiddleCenter, new Vector2(0.5f, 0f), new Vector2(0.5f, 0.5f), new Vector2(0f, At(ts, 6)), new Vector2(At(tf, 0) + 40f, 50f));
UISkin.UseTitle(t);
Outline(t, Col(tt, 2), At(tt, 4));
t.horizontalOverflow = HorizontalWrapMode.Overflow;
tabText.Add(t);
// 받을 것 있음 = 아이콘 오른쪽 위 붉은 점
var dot = RedDot(ic, At(ts, 0) * 0.5f + N("tab_dot", 0), -N("tab_dot", 1), N("red_dot", 2));
dot.gameObject.SetActive(false);
tabDot.Add(dot.gameObject);
}
}
void OnTabTap(int i)
{
if (i < 0 || i >= tabIds.Count) return;
switch (tabIds[i])
{
case "attend": ShowPage(PageAttend); break;
case "mission": ShowPage(PageMission); break;
case "roulette": ShowPage(PageRoulette); break;
default: Root.Toast(T(S_("special_toast"))); break; // 특별 이벤트 = 「준비 중」 토스트만(시안 mock_event_special_toast)
}
}
void RefreshTabs()
{
var ts = L("tab_size");
var tt = L("tab_text");
var d = S.Save;
var now = S.Now;
for (int i = 0; i < tabIds.Count; i++)
{
int p = tabIds[i] == "attend" ? PageAttend : tabIds[i] == "mission" ? PageMission : tabIds[i] == "roulette" ? PageRoulette : -1;
bool on = p == Page;
tabFocus[i].gameObject.SetActive(on);
tabIcon[i].sizeDelta = Vector2.one * At(ts, on ? 1 : 0);
tabIcon[i].anchoredPosition = new Vector2(0f, At(ts, on ? 3 : 2));
tabText[i].fontSize = Mathf.RoundToInt(At(ts, on ? 5 : 4));
tabText[i].color = Col(tt, on ? 0 : 1);
tabText[i].rectTransform.anchoredPosition = new Vector2(0f, At(ts, on ? 7 : 6));
var o = tabText[i].GetComponent<UnityEngine.UI.Outline>();
if (o != null) o.effectDistance = new Vector2(1f, -1f) * StrokeD(At(tt, on ? 3 : 4));
bool dot = p == PageAttend ? EventRules.AnyAttend(d, now) : p == PageMission ? EventRules.AnyMission(d, now) : p == PageRoulette && EventRules.AnyRoulette(d, now);
tabDot[i].SetActive(dot && !on);
var dr = (RectTransform)tabDot[i].transform;
dr.anchoredPosition = new Vector2(At(ts, on ? 1 : 0) * 0.5f + N("tab_dot", 0), -N("tab_dot", 1));
}
}
// ---------- 공용 그리기(시안 좌표 · 왼쪽 위 기준 · 부모 = 시안 판 또는 그 안의 칸) ----------
static float StrokeD(float stroke)
{
return stroke <= 0f ? 0f : Mathf.Max(1f, stroke * 0.7f);
}
/// <summary>글자 외곽선(시안 stroke px → 외곽선 거리).</summary>
static void Outline(Text t, Color c, float stroke)
{
if (stroke <= 0f) return;
var o = t.gameObject.AddComponent<Outline>();
o.effectColor = c;
float d = StrokeD(stroke);
o.effectDistance = new Vector2(d, -d);
}
/// <summary>
/// 글자(제목 글꼴) — anchor = 시안 PIL 기준점: 'm'(가운데) · 'l'(왼쪽 · 세로 가운데) · 'r'(오른쪽 · 세로 가운데) · 반환 = 글자(texts[name] 에 기록).
/// </summary>
Text Lab(Transform p, string name, string s, float size, Color c, char anchor, float x, float y, Color stroke, float strokePx, float boxW = 0f)
{
var pivot = anchor == 'l' ? new Vector2(0f, 0.5f) : anchor == 'r' ? new Vector2(1f, 0.5f) : new Vector2(0.5f, 0.5f);
var align = anchor == 'l' ? TextAnchor.MiddleLeft : anchor == 'r' ? TextAnchor.MiddleRight : TextAnchor.MiddleCenter;
float w = boxW > 0f ? boxW : Mathf.Max(40f, size * 24f);
var rt = UiKit.Rect(name, p, new Vector2(0f, 1f), pivot, new Vector2(x, -y), new Vector2(w, size * 1.6f));
var t = rt.gameObject.AddComponent<Text>();
UISkin.UseTitle(t);
t.fontSize = Mathf.Max(1, Mathf.RoundToInt(size));
t.alignment = align;
t.color = c;
t.supportRichText = true;
t.horizontalOverflow = HorizontalWrapMode.Overflow;
t.verticalOverflow = VerticalWrapMode.Overflow;
t.raycastTarget = false;
t.text = s;
Outline(t, stroke, strokePx);
texts[name] = t;
return t;
}
/// <summary>그림(스프라이트 · 단순 늘림).</summary>
static Image Img(Transform p, string name, Sprite sp, float x, float y, float w, float h, Color c)
{
var img = UiKit.At(p, name, x, y, w, h).gameObject.AddComponent<Image>();
img.sprite = sp;
img.color = c;
img.raycastTarget = false;
if (sp != null && sp.border != Vector4.zero) img.type = Image.Type.Sliced;
return img;
}
/// <summary>판(테마 스킨 · 틴트) — card = 굵은 테 둥근 판 · soft = 테 없는 둥근 판.</summary>
static Image Box(Transform p, string name, string skin, Color c, float x, float y, float w, float h)
{
var img = UiKit.Skin(UiKit.At(p, name, x, y, w, h), skin, c);
img.raycastTarget = false;
return img;
}
/// <summary>단색 사각(나무 결 · 걸이 줄 · 선).</summary>
static Image Solid(Transform p, string name, Color c, float x, float y, float w, float h)
{
var img = UiKit.At(p, name, x, y, w, h).gameObject.AddComponent<Image>();
img.color = c;
img.raycastTarget = false;
return img;
}
/// <summary>번짐 빛(흰 번짐 둥근 사각 9 분할 · 가운데 = core 사각).</summary>
Image Glow(Transform p, string name, Color c, float x, float y, float w, float h)
{
var g = L("glow");
float m = At(g, 1);
return Img(p, name, Sp(Str(g, 0)), x - m, y - m, w + 2f * m, h + 2f * m, c);
}
/// <summary>붉은 점(받을 것 있음) — 가운데 (cx, cy).</summary>
Image RedDot(Transform p, float cx, float cy, float d)
{
var rd = L("red_dot");
var img = UiKit.Skin(UiKit.Rect("Dot", p, new Vector2(0f, 1f), new Vector2(0.5f, 0.5f), new Vector2(cx, -cy), new Vector2(d, d)), "badge_circle", Col(rd, 0));
img.raycastTarget = false;
img.preserveAspect = true;
return img;
}
/// <summary>받은 표시(초록 원 + 체크 · 시안 check_badge) — 왼쪽 위 (x, y).</summary>
void Check(Transform p, float x, float y, float d)
{
var ck = L("check");
var ring = UiKit.Dot("Check", p, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(x, -y), d, Col(ck, 0));
ring.sprite = UiKit.Circle;
var fill = UiKit.Dot("Fill", ring.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, d - 6f, Col(ck, 1));
fill.sprite = UiKit.Circle;
UiKit.Icon(ring.transform, "check", new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, 1f), d * 0.62f);
}
/// <summary>남은 기간 글자.</summary>
static string Left(TimeSpan t)
{
if (t.TotalSeconds <= 0) return T("ev_ended");
int days = (int)t.TotalDays;
int hours = Mathf.Max(days > 0 ? 0 : 1, t.Hours);
return days > 0 ? F("ev_left_dh", days.ToString(CultureInfo.InvariantCulture), hours.ToString(CultureInfo.InvariantCulture))
: F("ev_left_h", "", hours.ToString(CultureInfo.InvariantCulture));
}
/// <summary>남은 기간 알약(어두운 판 + 금 테 · 시계 아이콘 선택) — 글자 폭 맞춤 · 반환 = 폭.</summary>
float Pill(Transform p, string name, string s, float x, float y, float h, float font, float minW, bool timer)
{
var pl = L("pill");
// 금 테 = 금 판 위에 테 두께만큼 들인 어두운 판(시안 rounded(fill, outline #FFD23E 2))
var ring = Box(p, name + "_Ring", "soft", Col(pl, 1), x, y, 10f, h);
float bw = At(pl, 2);
var bgi = Box(ring.transform, name, "soft", Col(pl, 0), bw, bw, 10f, h - 2f * bw);
float pad = timer ? At(pl, 3) : At(pl, 4);
var t = Lab(bgi.transform, name + "_Text", s, font, Color.white, 'l', pad, h * 0.5f + 1f, Color.clear, 0f);
float w = Mathf.Max(minW, Mathf.Ceil(t.preferredWidth) + pad + At(pl, 4));
ring.rectTransform.sizeDelta = new Vector2(w, h);
bgi.rectTransform.sizeDelta = new Vector2(w - 2f * bw, h - 2f * bw);
t.rectTransform.anchoredPosition = new Vector2(t.rectTransform.anchoredPosition.x - bw, t.rectTransform.anchoredPosition.y + bw);
if (!timer && minW > 0f)
{
t.alignment = TextAnchor.MiddleCenter;
t.rectTransform.pivot = new Vector2(0.5f, 0.5f);
t.rectTransform.anchoredPosition = new Vector2(w * 0.5f - bw, -(h * 0.5f + 1f) + bw);
t.rectTransform.sizeDelta = new Vector2(w, t.rectTransform.sizeDelta.y);
}
if (timer)
{
float ts = At(pl, 5);
Img(bgi.transform, "Timer", Sp(S_("timer")), At(pl, 6) - bw, (h - ts) * 0.5f - bw, ts, ts, Color.white).preserveAspect = true;
}
return w;
}
// ---------- 아이템 · 보상 ----------
static string ItemName(OutGameData db, string id)
{
var it = EventData.ItemOf(id);
if (it == null) return id;
if (it.kind == "hero")
{
var h = db.Heroes.Get(it.arg);
return F(it.nameKey, h != null ? h.nameKo : it.arg);
}
return T(it.nameKey);
}
/// <summary>수량 글자(×n · 룰렛 돌 = 1만 이상이고 천으로 나눠떨어지면 「×2만」).</summary>
string Qty(int n, bool man)
{
float lim = N("qty_man", 0);
if (man && lim > 0f && n >= lim && n % 1000 == 0) return F("ev_qty_man", (n / lim).ToString("0.#", CultureInfo.InvariantCulture));
return F("ev_qty", Num(n));
}
static Material grayMat;
/// <summary>받은 칸 아이콘 탈색(셰이더 Resources/UI/UiGray · 섞는 비 = 표 gray · QA r1 M 「색이 남은 채 어둡기만 함」).</summary>
void Gray(RectTransform icon)
{
if (icon == null) return;
if (grayMat == null)
{
var g = L("gray");
var sh = Resources.Load<Shader>(Str(g, 0));
if (sh == null) return;
grayMat = new Material(sh) { name = "EventGray", hideFlags = HideFlags.HideAndDontSave };
grayMat.SetFloat("_Keep", At(g, 1));
}
foreach (var img in icon.GetComponentsInChildren<Image>(true)) img.material = grayMat;
}
/// <summary>아이템 그림(테마 아이콘 · Resources 스프라이트 · 영웅 = 둥근 얼굴 · bare = 틀 없이 얼굴만(호출 쪽 원 위)) — 왼쪽 위 (x, y) 정사각 size.</summary>
RectTransform ItemIcon(Transform p, string name, string id, float x, float y, float size, Color tint, bool bare = false)
{
var it = EventData.ItemOf(id);
if (it != null && it.kind == "hero")
{
var h = S.Db.Heroes.Get(it.arg);
var fz = L("face");
return UiKit.Portrait(name, p, h, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(x, -y), new Vector2(size, size), true, At(fz, 0), bare ? Color.clear : Col(fz, 1));
}
string icon = it != null ? it.icon : id;
if (icon.Contains("/"))
{
var img = Img(p, name, Sp(icon), x, y, size, size, tint);
img.preserveAspect = true;
return img.rectTransform;
}
var ic = UiKit.Icon(p, icon, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(x, -y), size);
if (ic == null) return UiKit.At(p, name, x, y, size, size);
ic.name = name;
ic.color = new Color(ic.color.r * tint.r, ic.color.g * tint.g, ic.color.b * tint.b, ic.color.a * tint.a);
return ic.rectTransform;
}
/// <summary>받은 보상 팝업(게임 팝업 · 칸 + 수량 + 이름) — 비면 아무것도 안 함.</summary>
void ShowRewards(List<EventRules.Granted> got, string titleKey = "ev_reward_title")
{
if (got == null || got.Count == 0) return;
var rw = L("reward_pop");
float tile = At(rw, 0), gap = At(rw, 1), lab = At(rw, 2);
int perRow = Mathf.Max(1, Mathf.RoundToInt(At(rw, 3)));
int rows = (got.Count + perRow - 1) / perRow;
float rowH = tile + lab * 2.4f + gap;
var content = Root.ModalCustom(T(titleKey), At(rw, 4) + rows * rowH, new OutGameRoot.ModalButton(T("ev_ok"), UiKit.Dark, null));
var db = S.Db;
for (int i = 0; i < got.Count; i++)
{
int r = i / perRow, c = i % perRow;
int inRow = Mathf.Min(perRow, got.Count - r * perRow);
float rowW = inRow * tile + (inRow - 1) * gap;
float x = (At(rw, 5) - rowW) * 0.5f + c * (tile + gap);
float y = At(rw, 6) + r * rowH;
var g = got[i];
var cell = UiKit.At(content, "Got" + i, x, y, tile, tile);
UiKit.ItemSlot(cell, "gear_white_", false);
ItemIcon(cell, "Icon", g.id, tile * 0.16f, tile * 0.16f, tile * 0.68f, Color.white);
UiKit.QtyChip(cell, Qty(g.n, false), 26);
string nm = ItemName(db, g.id);
if (!string.IsNullOrEmpty(g.shardOf))
{
var h = db.Heroes.Get(g.shardOf);
nm = F("ev_shard_of", h != null ? h.nameKo : g.shardOf, Num(g.shards));
}
var t = UiKit.Label(content, nm, Mathf.RoundToInt(lab), UiKit.Ink, TextAnchor.UpperCenter, new Vector2(0f, 1f), new Vector2(0.5f, 1f), new Vector2(x + tile * 0.5f, -(y + tile + 10f)), new Vector2(tile + gap, lab * 2.4f));
t.name = "GotName" + i;
}
}
/// <summary>규칙 동작 결과 → 저장 · 보상 팝업 / 실패 글자 토스트.</summary>
void After(List<EventRules.Granted> got, string whyKey)
{
if (got != null)
{
S.Commit();
ShowRewards(got);
}
else if (!string.IsNullOrEmpty(whyKey)) Root.Toast(T(whyKey));
}
// ---------- 이동(미션 「이동」 버튼 · 표 event_kinds s_go) ----------
void Go(string kind)
{
var k = EventData.KindOf(kind);
string go = k != null ? k.go : "";
if (string.IsNullOrEmpty(go)) return;
ClosePopup();
if (go == "map") Root.OpenWorldMap();
else if (go == "hero") Root.Show(Root.HeroList);
else if (go == "recruit")
{
Root.Show(Root.Trade);
Root.Trade.SetPage(0);
}
else if (go == "treasure") Root.Show(Root.Treasures);
else if (go == "domestic") Root.Show(Root.Domestic);
else if (go.StartsWith("arena:"))
{
int pg;
Root.Show(Root.Arena);
if (int.TryParse(go.Substring(6), NumberStyles.Integer, CultureInfo.InvariantCulture, out pg)) Root.Arena.SetPage(pg);
}
}
/// <summary>미션 글자(종류 글자 키 · {0} = 목표 · {1} = 값(훈련장 = 던전 이름)).</summary>
static string MissionText(string kind, string arg, int target, string textKey)
{
var k = EventData.KindOf(kind);
string key = !string.IsNullOrEmpty(textKey) ? textKey : k != null ? k.textKey : kind;
string a = arg ?? "";
if (kind == EventRules.KSupplyTry && a.Length > 0)
foreach (var dg in SupplyData.AllDungeons())
if (dg.id == a) a = dg.nameKo;
return F(key, Num(target), a);
}
// ---------- 버튼 ----------
/// <summary>게임 버튼(스킨 · 글자 = 흰 + 짙은 테) — 왼쪽 위 (x, y).</summary>
Button Btn(Transform p, string name, string skin, Color tint, string label, float size, Color stroke, float x, float y, float w, float h, Action onClick)
{
var b = UiKit.SkinBtn(p, name, skin, tint, "", 10, Color.white, x, y, w, h, onClick);
var bl = b.GetComponentInChildren<Text>();
if (bl != null) bl.gameObject.SetActive(false);
if (!string.IsNullOrEmpty(label)) Lab(b.transform, name + "_Text", label, size, Color.white, 'm', w * 0.5f, h * 0.47f, stroke, 3f);
return b;
}
// ---------- 위 덮개 팝업(이벤트 미션 · 선물 팩 · 시안 popup()) ----------
Action popupRefresh;
/// <summary>팝업 판(어둡게 + 짙은 남색 판 · 제목 띠 · 붉은 X) — 반환 = 시안 좌표 판(같은 배율) · 내용은 호출 쪽.</summary>
RectTransform OpenPopup(string name, string titleKey, out float x0, out float y0, out float x1, out float y1)
{
ClosePopup();
popup = UiKit.Fill(name, Root.TopRoot);
UiLayer.Nest(popup.gameObject, UiRate.Event, true);
var dim = popup.gameObject.AddComponent<Image>();
dim.color = C("pop_dim");
dim.raycastTarget = true;
var fit = UiKit.Rect("Fit", popup, new Vector2(0f, 1f), new Vector2(0f, 1f), pageRoot.anchoredPosition, new Vector2(1080f, Hm));
fit.localScale = new Vector3(Z, Z, 1f);
var pp = L("pop");
x0 = At(pp, 0);
y0 = At(pp, 1) + Extra * 0.5f;
x1 = At(pp, 2);
y1 = At(pp, 3) + Extra * 0.5f;
float hh = At(pp, 4);
var pc = L("pop_col");
var panel = Box(fit, "Panel", "card", Col(pc, 0), x0, y0, x1 - x0, y1 - y0);
panel.raycastTarget = true;
Box(fit, "Head", "soft", Col(pc, 1), x0 + 7f, y0 + 7f, x1 - x0 - 14f, hh);
Solid(fit, "HeadLine", Col(pc, 2), x0 + 44f, y0 + 9f, x1 - x0 - 88f, 4f);
Lab(fit, "PopTitle", T(titleKey), At(pp, 5), Color.white, 'm', (x0 + x1) * 0.5f, y0 + hh * 0.5f + 4f, Col(pc, 3), 3f);
var close = UiKit.Skin(UiKit.At(fit, "Close", x1 - At(pp, 6), y0 + At(pp, 7), At(pp, 8), At(pp, 8)), "close", Color.white, true);
close.gameObject.AddComponent<Button>().onClick.AddListener(ClosePopup);
return fit;
}
/// <summary>팝업 머리 그림(둥근 그림 + 아래 어두운 띠 · 시계 · 남은 기간) — 시안 pop_banner.</summary>
void PopBanner(Transform fit, string sprite, float x, float y, string left)
{
var pb = L("pop_banner");
float w = At(pb, 0), h = At(pb, 1), band = At(pb, 2);
var b = Img(fit, "PopBanner", Sp(sprite), x, y, w, h, Color.white);
var m = b.gameObject.AddComponent<Mask>(); // 띠 = 그림 둥근 모서리 안으로
m.showMaskGraphic = true;
Solid(b.transform, "Band", C("pop_band"), 0f, h - band, w, band);
float ts = At(pb, 3);
Img(b.transform, "Timer", Sp(S_("timer")), At(pb, 4), h - band + (band - ts) * 0.5f, ts, ts, Color.white).preserveAspect = true;
Lab(b.transform, "PopLeft", left, At(pb, 5), Color.white, 'l', At(pb, 6), h - band * 0.5f + 1f, C("stroke_dark"), 2f);
}
public void ClosePopup()
{
popupRefresh = null;
if (popup == null) return;
popup.gameObject.SetActive(false);
UnityEngine.Object.Destroy(popup.gameObject);
popup = null;
}
/// <summary>등급 칸 틀 + 아이콘 + 오른쪽 아래 수량(시안 framed) — 왼쪽 위 (x, y).</summary>
void Framed(Transform p, string name, string id, int n, float fs, string frame, float x, float y)
{
var fr = L("framed");
var cell = UiKit.At(p, name, x, y, fs, fs);
Box(cell, "Bg", "soft", C("framed_bg"), At(fr, 0), At(fr, 0), fs - 2f * At(fr, 0), fs - 2f * At(fr, 0));
ItemIcon(cell, "Icon", id, (fs - fs * At(fr, 1)) * 0.5f, fs * At(fr, 2), fs * At(fr, 1), Color.white);
Box(cell, "Frame", frame, Color.white, 0f, 0f, fs, fs);
Lab(cell, name + "_Qty", Qty(n, false), fs * At(fr, 3), Color.white, 'r', fs - At(fr, 4), fs - At(fr, 5), C("stroke_dark"), 3f);
}
}
}