using System;
using System.Collections.Generic;
using System.Globalization;
using UnityEngine;
using UnityEngine.UI;
namespace TKS.OutGame
{
///
/// 이벤트 화면(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).
///
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 texts = new Dictionary();
readonly List tabFocus = new List();
readonly List tabIcon = new List();
readonly List tabText = new List();
readonly List tabDot = new List();
readonly List tabIds = new List();
bool built;
/// 지금 쪽(0 출석부 · 1 특별 미션 · 2 행운 룰렛).
public int Page { get; private set; }
/// 시안 배율 · 시안 칸 높이(1920 + 아래로 늘어난 몫) · 늘어난 몫.
public float Z { get; private set; }
public float Hm { get; private set; }
public float Extra { get; private set; }
/// 표 · 그림이 다 있는가(없으면 로비 버튼 = 준비 중).
public bool Ready
{
get { return tb != null && EventData.Loaded; }
}
/// 메인 하단 탭 대신 이벤트 탭(OutGameRoot.Show 가 메인 탭을 끔).
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; }
}
/// 정보 글자(테스트 · 없으면 null).
public string TextOf(string name)
{
Text t;
return texts.TryGetValue(name, out t) && t != null ? t.text : null;
}
/// 하단 이벤트 탭 붉은 점(테스트).
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;
}
/// 글자 키 → 글자(표 안 「\n」 = 줄바꿈).
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(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();
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;
}
/// 쪽을 열고 다시 그린다(로비 버튼 = 출석부 · 테스트).
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();
}
/// 화면 크기가 바뀌었을 때 다시 배치(캡처 · 긴 화면 확인).
public void Relayout()
{
if (built && Root.Current == this) ShowPage(Page);
}
/// 하단 이벤트 탭 누름(테스트 · 캡처 · 0 출석부 · 1 특별 미션 · 2 행운 룰렛 · 3 특별 이벤트).
public void TapTab(int i)
{
OnTabTap(i);
}
/// 이벤트 미션 · 선물 팩 팝업(룰렛 쪽 아래 버튼 · 테스트 · 캡처).
public void OpenQuestPopup()
{
OpenQuest();
}
public void OpenPackPopup()
{
OpenPack();
}
public override bool OnBack()
{
if (popup != null)
{
ClosePopup();
return true;
}
return false;
}
/// 쪽 바꿈 = 판(Art) · 정보(Info) 다시.
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();
}
///
/// 시안 판 배율 — 본문(제목 띠 아래 ~ 하단 탭 위) 기준 Z = min(폭 / 1080, 본문 높이 / 시안 본문 높이) · 판 위끝 = 시안 y 224 가 제목 띠 아래끝에 오게 ·
/// 판 높이 Hm = 시안 칸으로 본 화면 높이(늘어난 몫 Extra = 아래 묶음이 내려가는 값).
///
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();
hit.color = new Color(0f, 0f, 0f, 0f);
cell.gameObject.AddComponent