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

699 lines
38 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>
/// 행운 룰렛 쪽 v4(PD 2026-11-22 「레퍼런스(지붕 달린 둥근 룰렛 · 걸린 목패 임무 판 · 궁전 전각) 참고해 다시 구성 · 지금은 조잡 · 화풍 불일치」 · 그림 = 아트 폴더 roulette_v4 · 좌표 = 표 rou_*) —
/// 궁전 전각 배경 · 위 줄 = 남은 기간 · 보유 복주머니 · 바퀴 묶음 = 지붕 달린 둥근 틀 + 원판 12칸(틀 밑 · 최종 · 한정 칸 = 색 물 · 칸 = 아이콘 + 수량 · 꼬리표) ·
/// 가운데 금 단추 = 「행운 룰렛」 문구 + 장식 · 금 바늘(지금 칸 + 칸 빛) · 처마에 걸린 등롱(꾸밈) · 「확률 정보」 목패 · 받침 글자(최종 보상 · 규칙) · 받침 양옆 아이콘 버튼(이벤트 미션 · 선물 팩) ·
/// 문틀에 걸린 목패(뽑기 횟수 보상 · 막대 · 받기) · 뽑기 1회/10회 · 아래 안내 줄(한정 규칙 | 복주머니 얻는 법).
/// 2차(PD 2026-11-23 「룰렛판 크기를 더 키우고 · 이벤트 미션 · 선물 팩 = 예시 위치에 아이콘 형태(아이콘+폰트) · 가운데 = 장비 얼굴 대신 "행운 룰렛" 문구 · 등불 글자 지움」).
/// 바퀴 묶음은 층마다 받침(WheelRoot) 하나에 넣는다 — 시안 좌표 그대로 · 긴 화면 = 받침이 키우고 내린다(표 rou_extra).
/// 뽑기 = 바늘이 몇 바퀴 돌다 느려지며 멈춤(Under · Over 층 · Frame · 누르면 건너뜀) → 받은 보상 팝업.
/// </summary>
public partial class EventScreen
{
EventWheelSpin spin;
RectTransform needleRig, cursorRig;
RectTransform wArt, wUnder, wInfo, wOver;
int spinFrom;
/// <summary>뽑기 바늘이 도는 중(테스트).</summary>
public bool Spinning
{
get { return spin != null && spin.Running; }
}
// ---------- 바퀴 묶음 좌표(시안 px · 받침 안) ----------
float WheelX
{
get { return At(L("rou_shrine"), 1); }
}
float WheelY
{
get
{
var sh = L("rou_shrine");
return At(sh, 2) + At(sh, 5) * At(sh, 3);
}
}
/// <summary>긴 화면에서 바퀴 묶음 배율(늘어난 몫 × 표 비 ÷ 틀 높이 · 상한 = 표).</summary>
float WheelK
{
get
{
var ex = L("rou_extra");
var sh = L("rou_shrine");
float h = Mathf.Max(1f, At(sh, 7) * At(sh, 3));
return Mathf.Clamp(1f + Extra * At(ex, 0) / h, 1f, Mathf.Max(1f, At(ex, 1)));
}
}
/// <summary>긴 화면에서 바퀴 묶음이 내려가는 값(키우고 남은 몫 × 표 비).</summary>
float WheelShift
{
get
{
var sh = L("rou_shrine");
float grow = (WheelK - 1f) * At(sh, 7) * At(sh, 3);
return Mathf.Max(0f, Extra - grow) * At(L("rou_extra"), 2);
}
}
/// <summary>바퀴 묶음 받침(층마다 하나) — 자식은 시안 좌표 그대로 · 받침이 (바퀴 가운데 x, 틀 위끝)을 기준으로 키우고 내린다.</summary>
RectTransform WheelRoot(Transform layer)
{
var sh = L("rou_shrine");
float k = WheelK, fx = At(sh, 1), fy = At(sh, 2);
var rt = UiKit.At(layer, "Wheel", fx * (1f - k), fy * (1f - k) + WheelShift, 1080f, Hm);
rt.localScale = new Vector3(k, k, 1f);
return rt;
}
/// <summary>걸이 끈(처마 끝 밑 y0 ~ 등롱 · 목패 위끝 · 굵기 · 색 = 표 rou_cord).</summary>
void Cord(Transform p, string name, float cx, float y0, float yEnd)
{
var cd = L("rou_cord");
float w = At(cd, 0);
if (yEnd > y0) Solid(p, name, Col(cd, 1), cx - w * 0.5f, y0, w, yEnd - y0);
}
int SlotCount
{
get { return Mathf.Max(1, EventData.Slots.Count); }
}
float SlotStep
{
get { return 360f / SlotCount; }
}
/// <summary>칸 slot 가운데 방향으로 바퀴 가운데에서 r 떨어진 점(시안 좌표 · 칸 0 = 위 · 시계 방향).</summary>
Vector2 WheelPos(int slot, float r)
{
float a = slot * SlotStep * Mathf.Deg2Rad;
return new Vector2(WheelX + r * Mathf.Sin(a), WheelY - r * Mathf.Cos(a));
}
/// <summary>바퀴 가운데에 붙은 빈 받침(돌리면 자식이 바퀴 가운데를 축으로 돈다) · 각 = 칸 0 에서 시계 방향.</summary>
RectTransform WheelRig(Transform p, string name, float deg)
{
var rig = UiKit.Rect(name, p, new Vector2(0f, 1f), new Vector2(0.5f, 0.5f), new Vector2(WheelX, -WheelY), Vector2.zero);
rig.localEulerAngles = new Vector3(0f, 0f, -deg);
return rig;
}
/// <summary>칸 부채꼴(흰 그림 · 색 곱) — 받침 위에 칸 0 방향으로 놓고 받침을 칸 각도로 돌림.</summary>
RectTransform Wedge(Transform p, string name, int slot, Color c)
{
var wd = L("rou_wedge");
var sp = Sp(Str(wd, 0));
float sc = At(L("rou_shrine"), 3);
var rig = WheelRig(p, name + "Rig", slot * SlotStep);
if (sp == null) return rig;
float w = sp.rect.width * sc, h = sp.rect.height * sc, below = At(wd, 1) * sc;
Img(rig, name, sp, -w * 0.5f, -(below + h), w, h, c);
return rig;
}
// ---------- Art(Static) ----------
void RouletteArt()
{
var rb = L("rou_bg");
float top = At(rb, 0), bottom = Hm - OutGameRoot.TabBarH;
// 궁전 전각 배경 = 폭 1080 기준 위에서부터(긴 화면 = 높이에 맞춰 키우고 가운데 자름)
var tex = Resources.Load<Texture2D>(S_("rou_bg_tex"));
if (tex != null)
{
var raw = UiKit.At(art, "RouBg", 0f, top, 1080f, bottom - top).gameObject.AddComponent<RawImage>();
raw.texture = tex;
raw.raycastTarget = false;
float hNeed = bottom - top, hTex = 1080f * tex.height / tex.width;
if (hNeed <= hTex) raw.uvRect = new Rect(0f, 1f - hNeed / hTex, 1f, hNeed / hTex);
else
{
float wv = 1080f * hTex / hNeed / 1080f; // 보이는 가로 비율
raw.uvRect = new Rect((1f - wv) * 0.5f, 0f, wv, 1f);
}
}
Solid(art, "RouDim", Col(rb, 1), 0f, top, 1080f, bottom - top);
var shade = Solid(art, "RouShade", Color.white, 0f, top, 1080f, At(rb, 2));
var sc0 = Col(rb, 3);
UiGradient.Add(shade, sc0, A(sc0, 0f));
// 바퀴 묶음: 원판(틀 밑) → 최종 · 한정 칸 색 물 → 틀(원판 자리 = 투명 구멍) → 등롱 · 걸이 끈
wArt = WheelRoot(art);
var sh = L("rou_shrine");
float sc = At(sh, 3), wx = WheelX, wy = WheelY;
var fc = L("rou_face");
if (Mathf.RoundToInt(At(fc, 2)) != EventData.Slots.Count)
Debug.LogWarning("[TKS] 룰렛 원판 그림 칸 수(" + At(fc, 2) + ") ≠ 룰렛 칸 수(" + EventData.Slots.Count + ") — 아트 폴더 roulette_v4 wheel_parts.json n 을 바꿔 다시 그림");
float fw = At(fc, 1) * sc;
Img(wArt, "WheelFace", Sp(Str(fc, 0)), wx - fw * 0.5f, wy - fw * 0.5f, fw, fw, Color.white);
var wc = L("rou_wheel_col");
foreach (var s in EventData.Slots)
if (s.tag == EventData.TagFinal || s.tag == EventData.TagLimited)
Wedge(wArt, "Tint" + s.slot, s.slot, Col(wc, s.tag == EventData.TagFinal ? 0 : 1));
var ssp = Sp(Str(sh, 0));
if (ssp != null) Img(wArt, "Shrine", ssp, wx - At(sh, 4) * sc, At(sh, 2), ssp.rect.width * sc, ssp.rect.height * sc, Color.white);
var ln = L("rou_lantern");
var lsp = Sp(Str(ln, 0));
float lh = At(ln, 3), lw = lsp != null ? lh * lsp.rect.width / lsp.rect.height : lh * 0.4f;
Cord(wArt, "LanternCord", At(ln, 1), At(ln, 4), At(ln, 2) + 4f);
Img(wArt, "Lanterns", lsp, At(ln, 1) - lw * 0.5f, At(ln, 2), lw, lh, Color.white);
var ptg = L("rou_probtag");
Cord(wArt, "ProbCord", At(ptg, 1), At(ptg, 7), At(ptg, 2) + 4f);
// 횟수 보상 문틀 + 걸린 목패 바탕(긴 화면 = 아래로)
var bd = L("rou_board");
Img(art, "Gate", Sp(Str(bd, 0)), At(bd, 1), At(bd, 2) + Extra, At(bd, 3), At(bd, 4), Color.white);
var tb = L("rou_tablet");
var tsp = Sp(Str(tb, 0));
int n = EventData.Of("count").Count;
for (int i = 0; i < n; i++)
Img(art, "Tablet" + i, tsp, TabletX(i, n), At(tb, 3) + Extra, At(tb, 1), At(tb, 2), Color.white);
// 아래 안내 줄(왼쪽 = 한정 규칙 · 오른쪽 = 복주머니 얻는 법)
var inf = L("rou_info");
float iy = At(inf, 0) + Extra, ih = At(inf, 1);
Box(art, "InfoBg", "soft", Col(inf, 3), 20f, iy, 1040f, ih);
Solid(art, "InfoDiv", Col(inf, 5), 539f, iy + 8f, 2f, ih - 16f);
Lab(art, "RouNotice", F("ev_rou_notice", Num(EventData.CfgInt("roulette_limited_every"))), At(inf, 2), Col(inf, 4), 'm', At(inf, 6), iy + ih * 0.5f + 1f, Color.clear, 0f);
Lab(art, "RouHint", T("ev_rou_hint1"), At(inf, 2), Col(inf, 4), 'm', At(inf, 7), iy + ih * 0.5f + 1f, Color.clear, 0f);
}
/// <summary>걸린 목패 i 왼쪽 x(n 장을 가운데 정렬 · 표 rou_tablet 폭 · 간격).</summary>
float TabletX(int i, int n)
{
var tb = L("rou_tablet");
float w = At(tb, 1), gap = At(tb, 4);
return 540f - (n * w + (n - 1) * gap) * 0.5f + i * (w + gap);
}
// ---------- Info(Event) ----------
void RouletteInfo()
{
var d = S.Save;
var now = S.Now;
var e = EventRules.St(d);
var hd = L("rou_head");
Pill(info, "RouLeft", Left(EventRules.RouletteLeft(now)), At(hd, 0), At(hd, 1), At(hd, 2), At(hd, 3), 0f, true);
// 보유 복주머니
float pbw = N("pill", 2);
Box(info, "PouchRing", "soft", C("pill", 1), At(hd, 4), At(hd, 5), At(hd, 6), At(hd, 7));
Box(info, "PouchPill", "soft", C("pill", 0), At(hd, 4) + pbw, At(hd, 5) + pbw, At(hd, 6) - 2f * pbw, At(hd, 7) - 2f * pbw);
ItemIcon(info, "PouchIcon", "ev_pouch", At(hd, 8), At(hd, 9), At(hd, 10), Color.white);
Lab(info, "Pouch", Num(e.pouch), At(hd, 13), Color.white, 'm', At(hd, 11), At(hd, 12), C("stroke_dark"), 3f);
// 바퀴 묶음: 확률 정보 목패(누름) · 칸 · 받침 글자 · 아이콘 버튼
wInfo = WheelRoot(info);
var pt = L("rou_probtag");
var psp = Sp(Str(pt, 0));
float ph = At(pt, 3), pw2 = psp != null ? ph * psp.rect.width / psp.rect.height : ph * 0.5f;
var prob = Img(wInfo, "Prob", psp, At(pt, 1) - pw2 * 0.5f, At(pt, 2), pw2, ph, Color.white);
prob.raycastTarget = true;
prob.gameObject.AddComponent<Button>().onClick.AddListener(ShowProb);
Lab(prob.transform, "ProbText", T("ev_rou_prob_tag"), At(pt, 4), Col(pt, 6), 'm', pw2 * 0.5f, ph * At(pt, 5), Color.clear, 0f).lineSpacing = 0.95f;
WheelSlots(e);
PedestalText(d);
var ib = L("rou_icon_btn");
IconBtn("QuestBtn", S_("quest_icon"), T("ev_rou_quest"), At(ib, 1), EventRules.AnyQuest(d, now), OpenQuest);
IconBtn("PackBtn", S_("pack_icon"), T("ev_rou_pack"), At(ib, 2), false, OpenPack);
if (!Spinning) WheelPointer(e.cursor);
CountInfo(d);
// 뽑기 1회 · 10회
var rbn = L("rou_btn");
var bs = L("btn_stroke");
float by = At(rbn, 0) + Extra, bh = At(rbn, 1);
int n10 = EventData.CfgInt("roulette_count_10");
DrawBtn("Draw1", "btn_sky", Col(bs, 1), 1, At(rbn, 2), by, At(rbn, 3), bh, At(rbn, 5));
DrawBtn("Draw10", "btn_l_yellow", Col(bs, 3), n10, At(rbn, 4), by, At(rbn, 3), bh, At(rbn, 5));
if (Spinning) SpinSkip();
}
/// <summary>바퀴 칸(아이콘 + 수량 · 최종 = 장수 얼굴 + 별 · 최종 · 한정 = 꼬리표) — 칸 이름 Slot&lt;n&gt;(테스트).</summary>
void WheelSlots(EventState e)
{
var w = L("rou_wheel");
var wc = L("rou_wheel_col");
float isz = At(w, 1);
foreach (var s in EventData.Slots)
{
var p = WheelPos(s.slot, At(w, 0));
float cy = p.y + At(w, 2);
var cell = UiKit.At(wInfo, "Slot" + s.slot, p.x - isz * 0.5f, cy - isz * 0.5f, isz, isz);
var it = EventData.ItemOf(s.reward.id);
ItemIcon(cell, "Icon", s.reward.id, 0f, 0f, isz, Color.white);
float ly = isz * 0.5f + At(w, 3) - At(w, 2);
if (it != null && it.kind == "hero")
{
float ss = Mathf.Floor(At(w, 4) * 1.1f);
for (int k = 0; k < it.star; k++)
UiKit.Icon(cell, "star_l", new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(isz * 0.5f - it.star * ss * 0.46f + k * ss * 0.92f, -(ly - ss * 0.5f)), ss);
}
else Lab(cell, "Slot" + s.slot + "_Qty", Qty(s.reward.n, true), At(w, 4), Col(wc, 3), 'm', isz * 0.5f, ly, Col(wc, 4), 3f);
string tag = s.tag == EventData.TagFinal ? T("ev_rou_wtag_final") : s.tag == EventData.TagLimited ? T("ev_rou_wtag_limited") : null;
if (string.IsNullOrEmpty(tag)) continue;
var tp = WheelPos(s.slot, At(w, 5));
var tt = Lab(wInfo, "Slot" + s.slot + "_Tag", tag, At(w, 6), Col(wc, 7), 'm', tp.x, tp.y, Color.clear, 0f);
float tw = Mathf.Ceil(tt.preferredWidth) + At(w, 6) * 0.9f, th = At(w, 6) * 1.5f;
var tb = Box(wInfo, "Slot" + s.slot + "_TagBg", "soft", Col(wc, 5), tp.x - tw * 0.5f, tp.y - th * 0.5f, tw, th);
UiKit.Border(tb, Col(wc, 6), 2f);
tb.transform.SetSiblingIndex(tt.transform.GetSiblingIndex());
}
}
/// <summary>받침 글자 — 첫 줄 = 「최종 보상 · 3성 장비」 · 둘째 = 「n회마다 반드시 획득 · 남은 n회」.</summary>
void PedestalText(SaveData d)
{
var fin = EventData.FinalSlot;
if (fin == null) return;
var it = EventData.ItemOf(fin.reward.id);
string name;
if (it != null && it.kind == "hero")
{
var h = S.Db.Heroes.Get(it.arg);
name = F("ev_hero_star", it.star.ToString(CultureInfo.InvariantCulture), h != null ? h.nameKo : it.arg);
}
else name = ItemName(S.Db, fin.reward.id);
var pd = L("rou_pedestal");
Lab(wInfo, "FinalName", F("ev_rou_final_title", name), At(pd, 2), Col(pd, 4), 'm', WheelX, At(pd, 0), Col(pd, 6), 3f);
Lab(wInfo, "FinalRule", F("ev_rou_final_rule", Num(EventData.CfgInt("roulette_final_every")), Num(EventRules.FinalLeft(d))), At(pd, 3), Col(pd, 5), 'm', WheelX, At(pd, 1), Col(pd, 6), 3f);
}
/// <summary>
/// 아이콘 버튼(틀 없이 아이콘 + 아래 외곽선 글자 = 로비 옆 아이콘과 같은 방식 · PD 2026-11-23 「예시와 같은 위치에 아이콘 형태로(아이콘+폰트)」) —
/// 받침 양옆(바퀴 묶음 안) · 누름 칸 = 아이콘 위끝 ~ 글자 아래끝 · 붉은 점 = 받을 것 있음.
/// </summary>
void IconBtn(string name, string icon, string label, float cx, bool dot, Action onClick)
{
var ib = L("rou_icon_btn");
float sz = At(ib, 0), y0 = At(ib, 3) - sz * 0.5f, ty = At(ib, 5) - y0;
var hit = Img(wInfo, name, null, cx - sz * 0.5f, y0, sz, ty + At(ib, 4) * 0.7f, new Color(0f, 0f, 0f, 0f));
hit.raycastTarget = true;
hit.gameObject.AddComponent<Button>().onClick.AddListener(() => onClick());
Img(hit.transform, "Icon", Sp(icon), 0f, 0f, sz, sz, Color.white).preserveAspect = true;
Lab(hit.transform, name + "_Text", label, At(ib, 4), Col(ib, 6), 'm', sz * 0.5f, ty, Col(ib, 7), At(ib, 8));
if (dot) RedDot(hit.transform, sz - 12f, 12f, N("red_dot", 2));
}
/// <summary>지금 칸 빛(Under · 칸 아이콘 밑) + 금 바늘 · 가운데 단추 · 장식 · 「행운 룰렛」 문구(Over · 칸 위) — slot 방향으로.</summary>
void WheelPointer(int slot)
{
UiKit.Clear(under);
UiKit.Clear(over);
wUnder = WheelRoot(under);
wOver = WheelRoot(over);
var wc = L("rou_wheel_col");
var w = L("rou_wheel");
cursorRig = Wedge(wUnder, "Cursor", slot, Col(wc, 2));
needleRig = WheelRig(wOver, "NeedleRig", slot * SlotStep);
var nsp = Sp(S_("rou_needle"));
float nh = At(w, 9), nw = nsp != null ? nh * nsp.rect.width / nsp.rect.height : nh * 0.6f;
Img(needleRig, "Needle", nsp, -nw * 0.5f, -(At(w, 10) + nh), nw, nh, Color.white);
// 가운데 단추(금 고리 + 자주 원판) → 원판 위 장식 → 문구(글자 키 · 두 줄) = 금 고리 구멍 가운데(단추 가운데보다 표 값만큼 위)
float hd = At(w, 7), dd = At(w, 8), cy = WheelY + At(w, 11);
Img(wOver, "Hub", Sp(S_("rou_hub")), WheelX - hd * 0.5f, WheelY - hd * 0.5f, hd, hd, Color.white);
Img(wOver, "HubDeco", Sp(S_("rou_hub_deco")), WheelX - dd * 0.5f, cy - dd * 0.5f, dd, dd, Color.white);
var ht = L("rou_hub_title");
Lab(wOver, "HubTitle", T("ev_rou_hub"), At(ht, 0), Col(ht, 2), 'm', WheelX, cy + At(ht, 5), Col(ht, 3), At(ht, 4)).lineSpacing = At(ht, 1);
}
/// <summary>뽑기 횟수 보상 = 문틀 현판(누적 횟수) + 걸린 목패(보상 아이콘 · 수량 · 막대 / 받기 / 받음 · 누름 = 받기).</summary>
void CountInfo(SaveData d)
{
var e = EventRules.St(d);
var pl = L("rou_plaque");
float py = At(pl, 1) + Extra;
var pt = Lab(info, "CountTitle", F("ev_rou_count_title", Num(e.draws)), At(pl, 3), Col(pl, 5), 'm', 540f, py + 1f, Color.clear, 0f);
float plw = Mathf.Ceil(pt.preferredWidth) + 2f * At(pl, 4);
var pimg = Img(info, "CountPlaque", Sp(Str(pl, 0)), 540f - plw * 0.5f, py - At(pl, 2) * 0.5f, plw, At(pl, 2), Color.white);
pimg.transform.SetSiblingIndex(pt.transform.GetSiblingIndex());
var tb = L("rou_tablet");
var tc = L("rou_tablet_col");
var bs = L("btn_stroke");
var cnt = EventData.Of("count");
float tw = At(tb, 1), th = At(tb, 2), ty = At(tb, 3) + Extra, isz = At(tb, 5);
for (int i = 0; i < cnt.Count; i++)
{
var c = cnt[i];
float x = TabletX(i, cnt.Count), cx = x + tw * 0.5f, iy = ty + At(tb, 6);
bool got = EventRules.CountGot(d, c), ready = EventRules.CountReady(d, c);
var cc = c;
var hit = Img(info, "CountHit" + i, null, x, ty, tw, th, new Color(0f, 0f, 0f, 0f));
hit.raycastTarget = true;
hit.gameObject.AddComponent<Button>().onClick.AddListener(() => After(EventRules.ClaimCount(S.Db, S.Save, cc, S.Rng), null));
if (ready) Glow(info, "CountGlow" + i, C("cell_col", 9), cx - isz * 0.6f, iy - isz * 0.6f, isz * 1.2f, isz * 1.2f);
var rw = c.rewards.Count > 0 ? c.rewards[0] : new EventData.Reward { id = "", n = 0 };
var ic = ItemIcon(info, "Count" + i, rw.id, cx - isz * 0.5f, iy - isz * 0.5f, isz, Color.white);
if (got) Gray(ic);
Lab(info, "CountQty" + i, Qty(rw.n, true), At(tb, 13), Color.white, 'r', cx + At(tb, 11), iy + At(tb, 12), Col(tc, 2), 3f);
float bw = At(tb, 10), bh = At(tb, 8), by = ty + th - At(tb, 7);
if (ready)
{
Btn(info, "CountBtn" + i, "btn_l_green", Color.white, T("ev_claim"), At(tb, 9) + 2f, Col(bs, 0), cx - bw * 0.5f, by - 6f, bw, bh + 12f, () => After(EventRules.ClaimCount(S.Db, S.Save, cc, S.Rng), null));
RedDot(info, x + tw - 18f, iy - isz * 0.45f, N("red_dot", 2) * 0.93f);
}
else
{
var groove = Box(info, "CountBar" + i, "soft", Col(tc, 0), cx - bw * 0.5f, by, bw, bh);
UiKit.Border(groove, Col(tc, 3), 2f);
float pr = got ? 1f : Mathf.Clamp01(c.target > 0 ? e.draws / (float)c.target : 0f);
float fwid = Mathf.Floor((bw - 6f) * pr);
if (fwid > 0f) Box(info, "CountFill" + i, "soft", Col(tc, 1), cx - bw * 0.5f + 3f, by + 3f, Mathf.Max(fwid, bh - 6f), bh - 6f);
string lab = got ? T("ev_rou_got") : F("ev_rou_count_prog", Num(Mathf.Min(e.draws, c.target)), Num(c.target));
Lab(info, "CountLab" + i, lab, At(tb, 9), Color.white, 'm', cx, by + bh * 0.5f + 1f, Col(tc, 2), 3f);
if (got) Check(info, cx + isz * 0.25f, iy - isz * 0.62f, N("check", 2));
}
}
}
/// <summary>뽑기 버튼(「뽑기 n회 [복주머니] 비용」 한 줄 · 시안 button sub_icon).</summary>
void DrawBtn(string name, string skin, Color stroke, int count, float x, float y, float w, float h, float font)
{
var b = Btn(info, name, skin, Color.white, "", font, stroke, x, y, w, h, () => DoDraw(count));
var t1 = Lab(b.transform, name + "_Text", F("ev_rou_draw", Num(count)), font, Color.white, 'l', 0f, h * 0.47f, stroke, 3f);
float isz = Mathf.Floor(h * At(L("rou_btn"), 6));
var t2 = Lab(b.transform, name + "_Cost", Num(EventRules.Cost(count)), font, Color.white, 'l', 0f, h * 0.47f, stroke, 3f);
float w1 = Mathf.Ceil(t1.preferredWidth), w2 = Mathf.Ceil(t2.preferredWidth);
float tw = w1 + 14f + isz + 6f + w2, x0 = (w - tw) * 0.5f;
t1.rectTransform.anchoredPosition = new Vector2(x0, t1.rectTransform.anchoredPosition.y);
ItemIcon(b.transform, name + "_Icon", "ev_pouch", x0 + w1 + 14f, h * 0.47f - isz * 0.5f, isz, Color.white);
t2.rectTransform.anchoredPosition = new Vector2(x0 + w1 + 14f + isz + 6f, t2.rectTransform.anchoredPosition.y);
}
// ---------- 뽑기 ----------
void DoDraw(int count)
{
if (Spinning) return;
var got = new List<EventRules.Granted>();
string why;
int from = EventRules.St(S.Save).cursor;
var res = EventRules.Draw(S.Db, S.Save, count, S.Now, S.Rng, got, out why);
if (res == null)
{
Root.Toast(T(why));
return;
}
spinFrom = from;
S.Commit(); // 저장 먼저(연출 중 종료돼도 보상 유지) · 바늘은 연출이 끝난 뒤 지금 칸으로
StartSpin(res.Count > 0 ? res[res.Count - 1] : 0, () => ShowRewards(got, "ev_rou_result"));
}
/// <summary>바늘 = 화면에 있던 칸(spinFrom)에서 표 바퀴 수만큼 돌고 멈출 칸까지 · 끝으로 갈수록 느려짐(3차 감속) · 칸 빛 = 바늘 아래 칸.</summary>
void StartSpin(int target, Action done)
{
StopSpin();
var sp = L("wheel_spin");
int n = SlotCount;
WheelPointer(spinFrom);
int steps = ((target - spinFrom) % n + n) % n;
float from = spinFrom * SlotStep, to = from + Mathf.RoundToInt(At(sp, 0)) * 360f + steps * SlotStep;
if (to - from < SlotStep) to += 360f;
spin = over.gameObject.AddComponent<EventWheelSpin>();
spin.Run(needleRig, cursorRig, from, to, At(sp, 1), At(sp, 2), SlotStep, () =>
{
StopSpin();
BuildInfo();
done();
});
BuildInfo(); // 도는 동안 = 건너뛰기 덮개(RouletteInfo · 바늘은 그대로)
}
/// <summary>도는 동안 누르면 건너뜀(정보 층 맨 위 투명 덮개 · 다른 버튼 막음).</summary>
void SpinSkip()
{
var skip = UiKit.At(info, "SpinSkip", 0f, 0f, 1080f, Hm).gameObject.AddComponent<Image>();
skip.color = new Color(0f, 0f, 0f, 0f);
skip.raycastTarget = true;
skip.gameObject.AddComponent<Button>().onClick.AddListener(() => { if (spin != null) spin.Finish(); });
}
void StopSpin()
{
if (spin != null)
{
spin.Cancel();
UnityEngine.Object.Destroy(spin);
spin = null;
}
if (fx != null) UiKit.Clear(fx);
}
/// <summary>확률 정보(게임 팝업 · 칸마다 등급 색 점 + 아이콘 + 이름 × 수량 + 확률 · 최종 · 한정 규칙 · PD 결정 ⑤ = 등급 색은 이 창에만).</summary>
void ShowProb()
{
var pp = L("prob_pop");
float lh = At(pp, 0), icon = At(pp, 1), font = At(pp, 2);
var slots = EventData.Slots;
float sum = 0f;
foreach (var s in slots) sum += Mathf.Max(0f, s.weight);
var content = Root.ModalCustom(T("ev_prob_title"), At(pp, 3) + (slots.Count + 2) * lh, new OutGameRoot.ModalButton(T("ev_ok"), UiKit.Dark, null));
float y = 0f;
var colors = L("frame_col");
foreach (var s in slots)
{
Color fc = Color.white;
foreach (var kv in colors)
{
var p = kv.Split(':');
Color cc;
if (p.Length == 2 && p[0].Trim() == s.frame && ColorUtility.TryParseHtmlString(p[1].Trim(), out cc)) fc = cc;
}
var dot = UiKit.Dot("ProbDot" + s.slot, content, new Vector2(0f, 1f), new Vector2(0.5f, 0.5f), new Vector2(At(pp, 4), -(y + lh * 0.5f)), At(pp, 5), fc);
dot.sprite = UiKit.Circle;
ItemIcon(content, "ProbIcon" + s.slot, s.reward.id, At(pp, 6), y + (lh - icon) * 0.5f, icon, Color.white);
string nm = F("ev_prob_line", ItemName(S.Db, s.reward.id), Qty(s.reward.n, false));
if (s.tag == EventData.TagFinal) nm += " · " + T("ev_tag_final");
else if (s.tag == EventData.TagLimited) nm += " · " + T("ev_tag_limited");
UiKit.Label(content, nm, Mathf.RoundToInt(font), UiKit.Ink, TextAnchor.MiddleLeft, new Vector2(0f, 1f), new Vector2(0f, 0.5f), new Vector2(At(pp, 6) + icon + 14f, -(y + lh * 0.5f)), new Vector2(At(pp, 7), lh)).name = "ProbName" + s.slot;
float pct = sum > 0f ? s.weight / sum * 100f : 0f;
UiKit.Label(content, F("ev_prob_pct", pct.ToString("0.##", CultureInfo.InvariantCulture)), Mathf.RoundToInt(font), UiKit.Ink, TextAnchor.MiddleRight, new Vector2(1f, 1f), new Vector2(1f, 0.5f), new Vector2(-10f, -(y + lh * 0.5f)), new Vector2(200f, lh)).name = "ProbPct" + s.slot;
y += lh;
}
UiKit.Label(content, F("ev_prob_final", Num(EventData.CfgInt("roulette_final_every"))) + "\n" + F("ev_prob_limited", Num(EventData.CfgInt("roulette_limited_every"))), Mathf.RoundToInt(font * 0.9f), UiKit.InkSoft, TextAnchor.UpperLeft, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(10f, -(y + 10f)), new Vector2(At(pp, 7) + 200f, lh * 2f));
}
// ---------- 팝업: 이벤트 미션 · 선물 팩 ----------
void OpenQuest()
{
float x0, y0, x1, y1;
var fit = OpenPopup("EventQuest", "ev_quest_title", out x0, out y0, out x1, out y1);
var body = UiKit.At(fit, "Body", 0f, 0f, 1080f, Hm);
UiLayer.Nest(body.gameObject, UiRate.Event, true);
PopBanner(fit, S_("quest_head"), x0 + 30f, y0 + At(L("pop_banner"), 7), Left(EventRules.RouletteLeft(S.Now)));
popupRefresh = () => QuestRows(body, x0, y0, x1, y1);
popupRefresh();
}
void QuestRows(RectTransform body, float x0, float y0, float x1, float y1)
{
UiKit.Clear(body);
var q = L("pop_quest");
var d = S.Save;
var now = S.Now;
var bs = L("btn_stroke");
var list = EventData.Of("quest");
list.Sort((a, b) =>
{
int ka = EventRules.QuestGot(d, a) ? 2 : EventRules.QuestReady(d, a, now) ? 0 : 1;
int kb = EventRules.QuestGot(d, b) ? 2 : EventRules.QuestReady(d, b, now) ? 0 : 1;
return ka != kb ? ka.CompareTo(kb) : a.order.CompareTo(b.order);
});
float ry = y0 + At(q, 0), rh = At(q, 1), gap = At(q, 2), inset = At(q, 3);
foreach (var r in list)
{
if (ry + rh > y1 - 26f) break;
int p = EventRules.QuestProgress(d, r);
bool got = EventRules.QuestGot(d, r), ready = EventRules.QuestReady(d, r, now);
var row = Box(body, "Quest" + r.order, "soft", C("pop_row"), x0 + inset, ry, x1 - x0 - 2f * inset, rh).transform;
float lx = At(q, 5) - inset;
Lab(row, "QText" + r.order, MissionText(r.sKind, r.arg, r.target, r.textKey), At(q, 4), Color.white, 'l', lx, At(q, 16), Color.clear, 0f);
float bx0 = lx, bx1 = At(q, 6) - inset, byy = At(q, 7), bh = At(q, 8);
Box(row, "Track", "card", C("pop_track"), bx0, byy - bh * 0.5f, bx1 - bx0, bh);
float fw = Mathf.Floor((bx1 - bx0 - 8f) * Mathf.Min(1f, r.target > 0 ? p / (float)r.target : 0f));
if (fw > 10f)
{
var fill = Box(row, "Fill", "soft", Color.white, bx0 + 4f, byy - bh * 0.5f + 4f, fw, bh - 8f);
UiGradient.Add(fill, C("pop_green", 0), C("pop_green", 1));
}
Lab(row, "QProg" + r.order, F("ev_rou_count_prog", Num(Mathf.Min(p, r.target)), Num(r.target)), At(q, 9), Color.white, 'm', (bx0 + bx1) * 0.5f, byy + 1f, C("stroke_dark"), 3f);
var rw = r.rewards.Count > 0 ? r.rewards[0] : new EventData.Reward { id = "ev_pouch", n = 0 };
Framed(row, "QRw" + r.order, rw.id, rw.n, At(q, 12), S_("frame_pouch"), At(q, 10) - inset, At(q, 11));
float bw = At(q, 13), bhh = At(q, 14), bxx = x1 - x0 - 2f * inset - At(q, 15) - bw, byb = Mathf.Floor((rh - bhh) * 0.5f);
if (got) Btn(row, "QBtn" + r.order, "btn_gray", Color.white, T("ev_done"), 36f, Col(bs, 2), bxx, byb, bw, bhh, null).interactable = false;
else if (ready)
{
var rr = r;
Btn(row, "QBtn" + r.order, "btn_l_green", Color.white, T("ev_claim"), 38f, Col(bs, 0), bxx, byb, bw, bhh, () => After(EventRules.ClaimQuest(S.Db, S.Save, rr, S.Now, S.Rng), null));
RedDot(row, bxx + bw - 8f, byb + 6f, N("red_dot", 2));
}
else
{
var kind = r.sKind;
Btn(row, "QBtn" + r.order, "btn_sky", Color.white, T("ev_go"), 38f, Col(bs, 1), bxx, byb, bw, bhh, () => Go(kind));
}
ry += rh + gap;
}
}
void OpenPack()
{
float x0, y0, x1, y1;
var fit = OpenPopup("EventPack", "ev_pack_title", out x0, out y0, out x1, out y1);
var body = UiKit.At(fit, "Body", 0f, 0f, 1080f, Hm);
UiLayer.Nest(body.gameObject, UiRate.Event, true);
PopBanner(fit, S_("pack_head"), x0 + 30f, y0 + At(L("pop_banner"), 7), Left(EventRules.RouletteLeft(S.Now)));
popupRefresh = () => PackRows(body, x0, y0, x1, y1);
popupRefresh();
}
void PackRows(RectTransform body, float x0, float y0, float x1, float y1)
{
UiKit.Clear(body);
var q = L("pop_pack");
var pc = L("pop_pack_col");
var bs = L("btn_stroke");
var d = S.Save;
float ry = y0 + At(q, 0), rh = At(q, 1), gap = At(q, 2), inset = At(q, 3);
foreach (var r in EventData.Of("pack"))
{
if (ry + rh > y1 - 26f) break;
float rw = x1 - x0 - 2f * inset;
var row = Box(body, "Pack" + r.order, "soft", C("pop_row"), x0 + inset, ry, rw, rh).transform;
// 이름 = 붉은 꼬리 띠(게임 Label_Tail 부품)
var nm = Lab(row, "PName" + r.order, T(r.textKey), At(q, 4), Color.white, 'l', At(q, 8), At(q, 7) + At(q, 6) * 0.5f, Col(pc, 1), 2f);
var tail = Img(row, "Tail", Sp(S_("tail_red")), 0f, At(q, 7), Mathf.Ceil(nm.preferredWidth) + At(q, 5), At(q, 6), Color.white);
tail.transform.SetSiblingIndex(nm.transform.GetSiblingIndex());
float ix = At(q, 17) - inset;
foreach (var it in r.rewards)
{
var item = EventData.ItemOf(it.id);
Framed(row, "PRw" + r.order + "_" + it.id, it.id, it.n, At(q, 9), item != null && item.kind == "pouch" ? S_("frame_pouch") : S_("frame_other"), ix, At(q, 11));
ix += At(q, 9) + At(q, 10);
}
float bw = At(q, 12), bh = At(q, 13), bxx = rw - At(q, 15) - bw, byb = rh - bh - At(q, 14);
int bought = EventRules.PackBought(d, r);
var rr = r;
if (r.price <= 0)
{
Lab(row, "PInfo" + r.order, F("ev_pack_today", Num(bought), Num(r.limit)), At(q, 16), Col(pc, 0), 'm', bxx + bw * 0.5f, At(q, 18), Color.clear, 0f);
Btn(row, "PBtn" + r.order, "btn_l_green", Color.white, T("ev_pack_ad_btn"), 34f, Col(bs, 0), bxx, byb, bw, bh, () =>
{
string why;
var got = EventRules.Ad(S.Db, S.Save, rr, S.Now, S.Rng, out why);
if (got == null)
{
Root.Toast(T(why));
return;
}
S.Commit();
int n = 0;
foreach (var g in got) n += g.n;
Root.Toast(F("ev_ad_toast", Num(n)));
});
}
else
{
Lab(row, "PInfo" + r.order, F("ev_pack_limit", Num(bought), Num(r.limit)), At(q, 16), Col(pc, 0), 'm', bxx + bw * 0.5f, At(q, 18), Color.clear, 0f);
// 유료 = 결제 준비 중 토스트만(PD 결정 ② · 지급 없음) · 가격 = 「₩」(본문 글꼴 · Maplestory 에 글자 없음) + 숫자(게임 글꼴)
var b = Btn(row, "PBtn" + r.order, "btn_l_green", Color.white, "", 38f, Col(bs, 0), bxx, byb, bw, bh, () => Root.Toast(T("ev_pack_soon")));
var sym = Lab(b.transform, "PSym" + r.order, T("ev_price_symbol"), 38f, Color.white, 'l', 0f, bh * 0.47f, Col(bs, 0), 3f);
TextUtil.UseBody(sym, true);
sym.fontStyle = FontStyle.Bold; // 숫자(제목 글꼴)와 굵기 맞춤(QA r1 U)
var num = Lab(b.transform, "PPrice" + r.order, Num(r.price), 38f, Color.white, 'l', 0f, bh * 0.47f, Col(bs, 0), 3f);
float w1 = Mathf.Ceil(sym.preferredWidth), w2 = Mathf.Ceil(num.preferredWidth), sx = (bw - w1 - 2f - w2) * 0.5f;
sym.rectTransform.anchoredPosition = new Vector2(sx, sym.rectTransform.anchoredPosition.y);
num.rectTransform.anchoredPosition = new Vector2(sx + w1 + 2f, num.rectTransform.anchoredPosition.y);
}
ry += rh + gap;
}
}
}
/// <summary>
/// 룰렛 바늘 연출 v4(Over · Under 층 · Frame) — 바늘 받침을 from → to 도(칸 0 = 위 · 시계 방향)로 3차 감속 회전 · 칸 빛 받침 = 바늘 아래 칸으로 칸 단위 이동 ·
/// 끝 = hold 초 멈춘 뒤 done · Finish = 바로 끝 · Cancel = 콜백 없이 멈춤.
/// </summary>
public class EventWheelSpin : MonoBehaviour
{
RectTransform needle, cursor;
float from, to, dur, hold, step, t;
Action done;
bool running;
public bool Running
{
get { return running; }
}
public void Run(RectTransform needleRig, RectTransform cursorRig, float fromDeg, float toDeg, float duration, float holdEnd, float stepDeg, Action onDone)
{
needle = needleRig;
cursor = cursorRig;
from = fromDeg;
to = toDeg;
dur = Mathf.Max(0.01f, duration);
hold = holdEnd;
step = Mathf.Max(1f, stepDeg);
done = onDone;
t = 0f;
running = true;
Set(from);
}
void Set(float deg)
{
if (needle != null) needle.localEulerAngles = new Vector3(0f, 0f, -deg);
if (cursor != null)
{
float snap = Mathf.Round(deg / step) * step;
var e = new Vector3(0f, 0f, -snap);
if (cursor.localEulerAngles != Quaternion.Euler(e).eulerAngles) cursor.localEulerAngles = e;
}
}
void Update()
{
if (!running) return;
t += Time.unscaledDeltaTime;
if (t < dur)
{
float u = 1f - t / dur;
Set(Mathf.Lerp(from, to, 1f - u * u * u));
return;
}
Set(to);
if (t >= dur + hold) Done();
}
public void Finish()
{
if (!running) return;
Set(to);
Done();
}
public void Cancel()
{
running = false;
done = null;
}
void Done()
{
running = false;
var d = done;
done = null;
if (d != null) d();
}
}
}