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

603 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>
/// 행운 룰렛 쪽(시안 mock_event_roulette = build_mock_e2.py roulette_base_v3 · 14차) — 축제 마당 배경(어둡게) · 제목 · 남은 기간 · 보유 복주머니 · 확률 정보 ·
/// 바둑판(생성 그림 · 안쪽 나무 면 실측 = 표) + 둘레 12칸 바둑알(보통 = 흰 돌 · 한정 = 검은 돌 · 최종 보상 = 검은 돌 + 금 상감 · 지금 칸 = 금빛 고리 · PD 결정 ⑤) ·
/// 가운데 = 현판 「최종 보상」 + 게임 유닛 원화 전신(언덕 위 · 눕힌 그림자) + 별 + 「n회마다 반드시 · 남은 n회」 · 안내 띠 · 횟수 보상 · 뽑기 1회/10회 · 이벤트 미션 · 선물 팩 팝업.
/// 뽑기 = 금빛 고리가 칸을 돌다 멈춤(Fx 층 · Frame · 누르면 건너뜀) → 받은 보상 팝업.
/// </summary>
public partial class EventScreen
{
static readonly int[,] Ring = { { 0, 0 }, { 0, 1 }, { 0, 2 }, { 0, 3 }, { 1, 3 }, { 2, 3 }, { 3, 3 }, { 3, 2 }, { 3, 1 }, { 3, 0 }, { 2, 0 }, { 1, 0 } };
EventSpin spin;
/// <summary>뽑기 고리가 도는 중(테스트).</summary>
public bool Spinning
{
get { return spin != null && spin.Running; }
}
/// <summary>칸 n 의 왼쪽 위(시안 좌표).</summary>
Vector2 SlotPos(int n)
{
var g = L("rou_grid");
int k = ((n % 12) + 12) % 12;
return new Vector2(At(g, 0) + Ring[k, 1] * (At(g, 2) + At(g, 3)), At(g, 1) + Ring[k, 0] * (At(g, 2) + At(g, 3)));
}
// ---------- 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 sc = Col(rb, 3);
UiGradient.Add(shade, sc, A(sc, 0f));
var hd = L("rou_head");
var hc = L("rou_head_col");
Lab(art, "RouTitle", T("ev_rou_title"), At(hd, 2), Color.white, 'l', At(hd, 0), At(hd, 1), Col(hc, 0), 4f);
// 바둑판(안쪽 나무 면 = 칸 묶음 둘레 pad · 표 실측) + 그림자
var g = L("rou_grid");
var bd = L("rou_board");
float pad = At(bd, 5);
float bx0 = At(g, 0) - pad - At(bd, 1), by0 = At(g, 1) - pad - At(bd, 2), bw = At(bd, 3), bh = At(bd, 4);
Glow(art, "BoardShadow", Col(bd, 6), bx0, by0 + At(bd, 7), bw, bh);
Img(art, "Board", Sp(Str(bd, 0)), bx0, by0, bw, bh, Color.white);
// 아래 묶음 바탕(횟수 판 · 긴 화면 = 아래로)
var rc = L("rou_count");
var rcc = L("rou_count_col");
float cy0 = At(rc, 0) + Extra, cy1 = At(rc, 1) + Extra;
Box(art, "CountPanel", "card", Col(rcc, 0), 20f, cy0, 1040f, cy1 - cy0);
Box(art, "CountInner", "soft", Col(rcc, 1), At(rc, 2), cy0 + 14f, At(rc, 3) - At(rc, 2), cy1 - cy0 - 28f);
Lab(art, "DrawsLabel", T("ev_rou_draws"), At(rc, 5), Col(rcc, 2), 'm', (At(rc, 2) + At(rc, 3)) * 0.5f, cy1 - 38f, Color.clear, 0f);
// 안내 띠(판 아래)
var nt = L("rou_notice");
float ny = Mathf.Max(At(g, 1) + 4f * At(g, 2) + 3f * At(g, 3) + At(nt, 0), by0 + bh + At(nt, 1));
var nl = Lab(art, "RouNotice", F("ev_rou_notice", Num(EventData.CfgInt("roulette_limited_every"))), At(nt, 2), Color.white, 'm', 540f, ny + At(nt, 3) * 0.5f + 1f, Color.clear, 0f);
float nw = Mathf.Ceil(nl.preferredWidth) + At(nt, 4);
var nb = Box(art, "RouNoticeBg", "soft", Col(nt, 5), 540f - nw * 0.5f, ny, nw, At(nt, 3));
nb.transform.SetSiblingIndex(nl.transform.GetSiblingIndex());
// 아래 버튼 줄 바탕(이벤트 미션 · 선물 팩 · 안내)
var su = L("rou_sub");
var suc = L("rou_sub_col");
float sy = At(su, 0) + Extra;
Box(art, "HintBg", "soft", Col(suc, 1), At(su, 7), sy + 6f, At(su, 8), At(su, 9));
var hint = Lab(art, "RouHint", T("ev_rou_hint"), At(su, 10), Color.white, 'm', 540f, sy + 6f + At(su, 9) * 0.5f, Col(suc, 2), 3f);
hint.lineSpacing = 1.05f;
}
// ---------- Info(Event) ----------
void RouletteInfo()
{
var d = S.Save;
var now = S.Now;
var e = EventRules.St(d);
var hd = L("rou_head");
var hc = L("rou_head_col");
Pill(info, "RouLeft", Left(EventRules.RouletteLeft(now)), At(hd, 3), At(hd, 4), At(hd, 5), At(hd, 6), 0f, true);
// 보유 복주머니
float pbw = N("pill", 2);
Box(info, "PouchRing", "soft", C("pill", 1), At(hd, 7), At(hd, 8), At(hd, 9), At(hd, 10));
Box(info, "PouchPill", "soft", C("pill", 0), At(hd, 7) + pbw, At(hd, 8) + pbw, At(hd, 9) - 2f * pbw, At(hd, 10) - 2f * pbw);
ItemIcon(info, "PouchIcon", "ev_pouch", At(hd, 11), At(hd, 12), At(hd, 13), Color.white);
Lab(info, "Pouch", Num(e.pouch), At(hd, 16), Color.white, 'm', At(hd, 14), At(hd, 15), C("stroke_dark"), 3f);
// 확률 정보
var prob = Box(info, "Prob", "card", Col(hc, 1), At(hd, 17), At(hd, 18), At(hd, 19), At(hd, 20));
prob.raycastTarget = true;
prob.gameObject.AddComponent<Button>().onClick.AddListener(ShowProb);
Lab(prob.transform, "ProbText", T("ev_rou_prob"), At(hd, 21), Col(hc, 2), 'm', At(hd, 19) * 0.5f, At(hd, 20) * 0.5f + 1f, Color.clear, 0f);
// 칸 12
var cs = At(L("rou_grid"), 2);
foreach (var s in EventData.Slots)
{
var p = SlotPos(s.slot);
string kind = s.tag == EventData.TagFinal ? "final" : s.tag == EventData.TagLimited ? "black" : "white";
string tag = s.tag == EventData.TagFinal ? T("ev_tag_final") : s.tag == EventData.TagLimited ? T("ev_tag_limited") : null;
Stone(info, "Slot" + s.slot, s.reward.id, s.reward.n, kind, tag, s.slot == e.cursor && !Spinning, false, p.x, p.y, cs);
}
CenterFinal(d);
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));
// 이벤트 미션 · 선물 팩
var su = L("rou_sub");
var suc = L("rou_sub_col");
float sy = At(su, 0) + Extra;
SubBtn("QuestBtn", S_("quest_icon"), T("ev_rou_quest"), At(su, 3), sy, EventRules.AnyQuest(d, now), OpenQuest);
SubBtn("PackBtn", S_("pack_icon"), T("ev_rou_pack"), At(su, 4), sy, false, OpenPack);
if (Spinning) SpinSkip();
}
void SubBtn(string name, string icon, string label, float x, float y, bool dot, Action onClick)
{
var su = L("rou_sub");
var suc = L("rou_sub_col");
float w = At(su, 1), h = At(su, 2);
var b = Box(info, name, "card", Col(suc, 0), x, y, w, h);
b.raycastTarget = true;
b.gameObject.AddComponent<Button>().onClick.AddListener(() => onClick());
Img(b.transform, "Icon", Sp(icon), 14f, (h - At(su, 5)) * 0.5f, At(su, 5), At(su, 5), Color.white).preserveAspect = true;
Lab(b.transform, name + "_Text", label, At(su, 6), Color.white, 'l', 100f, h * 0.5f + 1f, Col(suc, 2), 3f);
if (dot) RedDot(b.transform, w - 10f, 8f, N("red_dot", 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);
}
/// <summary>바둑알 칸(시안 stone_cell) — 흰(보통) · 검은(한정) · 최종(검은 + 금 상감 · 장수 얼굴 + 별) · 그림자 = 돌 실루엣을 오른쪽 아래로 · 지금 칸 = 금빛 고리 · 꼬리표.</summary>
void Stone(Transform p, string name, string id, int n, string kind, string tag, bool cursor, bool dim, float x, float y, float size)
{
var st = L("stone");
var cell = UiKit.At(p, name, x, y, size, size);
var sp = Sp(S_(kind == "white" ? "stone_white" : "stone_black"));
Img(cell, "Shadow", sp, At(st, 1) * size / 180f, At(st, 2) * size / 180f, size, size, Col(st, 0));
if (cursor) CursorRing(cell, size, "Cursor");
Img(cell, "Stone", sp, 0f, 0f, size, size, Color.white);
if (kind == "final") Img(cell, "Inlay", Sp(S_("ring_inlay")), 0f, 0f, size, size, Col(st, 4));
var it = EventData.ItemOf(id);
if (it != null && it.kind == "hero")
{
float hs = Mathf.Floor(size * At(st, 13));
var fz = L("face");
var h = S.Db.Heroes.Get(it.arg);
UiKit.Portrait("Face", cell, h, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2((size - hs) * 0.5f, -Mathf.Floor(size * At(st, 14))), new Vector2(hs, hs), true, At(fz, 2), Color.clear);
float ss = Mathf.Floor(size * At(st, 15));
float sy = size - ss - Mathf.Floor(size * (kind == "final" ? At(st, 17) : At(st, 18)));
for (int k = 0; k < it.star; k++)
UiKit.Icon(cell, "star_l", new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(size * 0.5f - it.star * ss * 0.46f + k * ss * 0.92f, -sy), ss);
}
else
{
float isz = Mathf.Floor(size * At(st, 5));
var ic = ItemIcon(cell, "Icon", id, (size - isz) * 0.5f, Mathf.Floor(size * At(st, 6)), isz, Color.white);
if (dim) Gray(ic);
bool white = kind == "white";
Lab(cell, name + "_Qty", Qty(n, true), size * At(st, 8), Col(st, white ? 9 : 11), 'm', size * 0.5f, size * At(st, 7), Col(st, white ? 10 : 12), 3f);
}
if (!string.IsNullOrEmpty(tag))
{
var tg = L("stone_tag");
var tt = Lab(cell, name + "_Tag", tag, At(tg, 0), Color.white, 'm', 0f, At(tg, 6), Col(tg, 4), 2f);
float tw = Mathf.Ceil(tt.preferredWidth) + At(tg, 1);
var tb2 = Box(cell, "TagBg", "soft", Col(tg, 2), -4f, -10f, tw, At(tg, 5));
UiKit.Border(tb2, Col(tg, 3), 2f);
tt.rectTransform.anchoredPosition = new Vector2(-4f + tw * 0.5f, tt.rectTransform.anchoredPosition.y);
tt.transform.SetAsLastSibling();
}
}
/// <summary>금빛 고리(지금 칸 · 도는 고리 · 시안 cursor ring) — 칸 가운데.</summary>
Image CursorRing(Transform cell, float size, string name)
{
float rs = size * N("ring", 0);
return Img(cell, name, Sp(S_("ring_cursor")), (size - rs) * 0.5f, (size - rs) * 0.5f, rs, rs, C("stone", 3));
}
/// <summary>가운데 2×2 = 최종 보상(현판 · 유닛 원화 전신 · 언덕 · 눕힌 그림자 · 별 · 이름 · 횟수 규칙 · 시안 12~14차).</summary>
void CenterFinal(SaveData d)
{
var fin = EventData.FinalSlot;
if (fin == null) return;
var it = EventData.ItemOf(fin.reward.id);
var g = L("rou_grid");
var rc = L("rou_center");
var cc = L("rou_center_col");
float cs = At(g, 2), gap = At(g, 3);
float cx0 = At(g, 0) + cs + gap, cy0 = At(g, 1) + cs + gap, cw = cs * 2f + gap, mid = cx0 + cw * 0.5f;
var tp = Sp(S_("title_plate"));
float pw = Mathf.Floor(cw * At(rc, 0)), ph = tp != null ? Mathf.Floor(pw * tp.rect.height / tp.rect.width) : 60f;
Img(info, "FinalPlate", tp, mid - pw * 0.5f, cy0 + At(rc, 1), pw, ph, Color.white);
Lab(info, "FinalPlateText", T("ev_rou_final"), At(rc, 2), Color.white, 'm', mid, cy0 + At(rc, 1) + ph * 0.5f + 1f, Col(cc, 0), 3f);
if (it == null || it.kind != "hero") return;
var h = S.Db.Heroes.Get(it.arg);
float fy = cy0 + At(rc, 5);
// 언덕(발밑 · 윗면 풀밭) → 그림자 → 유닛 → 별(언덕 앞)
var hl = Sp(S_("hill"));
float hw = At(rc, 6), hh = hl != null ? hw * hl.rect.height / hl.rect.width : hw * 0.5f;
float hy = fy - Mathf.Floor(hh * At(rc, 7));
Img(info, "Hill", hl, mid - hw * 0.5f, hy, hw, hh, Color.white);
var shadow = UiKit.UnitStand("UnitShadow", info, h, new Vector2(0f, 1f), new Vector2(mid + At(rc, 10), -(fy + At(rc, 15))), At(rc, 3), At(rc, 4));
if (shadow != null)
{
shadow.GetComponent<Image>().color = Col(cc, 4);
shadow.localScale = new Vector3(1f, At(rc, 8), 1f);
}
UiKit.UnitStand("Unit", info, h, new Vector2(0f, 1f), new Vector2(mid, -fy), At(rc, 3), At(rc, 4));
float sty = hy + hh - At(rc, 12), ss = At(rc, 11);
for (int k = 0; k < it.star; k++)
UiKit.Icon(info, "star_l", new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(mid - it.star * ss * 0.46f + k * ss * 0.92f, -sty), ss);
float sy2 = sty + ss + 2f;
Box(info, "FinalTextBg", "soft", Col(cc, 3), cx0 + At(rc, 16), sy2, cw - 2f * At(rc, 16), At(rc, 13));
Lab(info, "FinalName", F("ev_hero_star", it.star.ToString(CultureInfo.InvariantCulture), h != null ? h.nameKo : it.arg), At(rc, 14), Col(cc, 1), 'm', mid, sy2 + 22f, Col(cc, 2), 4f);
Lab(info, "FinalRule", F("ev_rou_final_rule", Num(EventData.CfgInt("roulette_final_every")), Num(EventRules.FinalLeft(d))), At(rc, 17), Col(cc, 1), 'm', mid, sy2 + 54f, Col(cc, 2), 3f);
}
/// <summary>뽑기 횟수 판(왼쪽 = 누적 횟수 · 오른쪽 = 횟수 보상 흰 돌 4 · 받음 = 체크 · 받을 것 = 빛 + 붉은 점 · 누름 = 받기).</summary>
void CountInfo(SaveData d)
{
var rc = L("rou_count");
var rcc = L("rou_count_col");
var e = EventRules.St(d);
float y0 = At(rc, 0) + Extra, y1 = At(rc, 1) + Extra;
Lab(info, "Draws", Num(e.draws), At(rc, 4), Color.white, 'm', (At(rc, 2) + At(rc, 3)) * 0.5f, y0 + 62f, C("stroke_dark"), 4f);
var cnt = EventData.Of("count");
float colw = (At(rc, 7) - At(rc, 6)) / Mathf.Max(1, cnt.Count), fs = At(rc, 8);
for (int i = 0; i < cnt.Count; i++)
{
var c = cnt[i];
float ccx = At(rc, 6) + colw * (i + 0.5f), fx = ccx - fs * 0.5f, fy = y0 + 14f;
bool got = EventRules.CountGot(d, c), ready = EventRules.CountReady(d, c);
if (ready) Glow(info, "CountGlow" + i, C("cell_col", 9), fx, fy, fs, fs);
var rw = c.rewards.Count > 0 ? c.rewards[0] : new EventData.Reward { id = "", n = 0 };
Stone(info, "Count" + i, rw.id, rw.n, "white", null, false, got, fx, fy, fs);
var hit = Img(info, "CountHit" + i, null, fx, fy, fs, fs, new Color(0f, 0f, 0f, 0f));
hit.raycastTarget = true;
var cc = c;
hit.gameObject.AddComponent<Button>().onClick.AddListener(() => After(EventRules.ClaimCount(S.Db, S.Save, cc, S.Rng), null));
if (got) Check(info, fx + fs - 30f, fy - 6f, N("check", 2));
if (ready) RedDot(info, fx + fs - 8f, fy + 4f, N("red_dot", 2) * 0.93f);
string lab = got || ready ? F("ev_rou_count", Num(c.target)) : F("ev_rou_count_prog", Num(e.draws), Num(c.target));
Lab(info, "CountLab" + i, lab, At(rc, 9), ready ? Col(rcc, 3) : Color.white, 'm', ccx, y1 - 30f, C("stroke_dark"), 2f);
}
}
// ---------- 뽑기 ----------
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"));
}
void StartSpin(int target, Action done)
{
StopSpin();
var sp = L("spin");
float cs = At(L("rou_grid"), 2);
var host = UiKit.At(fx, "Spin", 0f, 0f, 1080f, Hm);
var ring = CursorRing(host, cs, "SpinRing");
spin = host.gameObject.AddComponent<EventSpin>();
spin.Base = cs;
var path = new List<Vector2>();
int laps = Mathf.RoundToInt(At(sp, 0));
// 지금 세이브 cursor = 이미 멈출 칸(뽑기가 먼저 반영) → 출발 = 화면에 있던 칸(spinFrom)
int steps = laps * 12 + ((target - spinFrom) % 12 + 12) % 12;
if (steps == 0) steps = 12;
for (int i = 1; i <= steps; i++) path.Add(SlotPos(spinFrom + i));
spin.Run(ring.rectTransform, path, At(sp, 1), At(sp, 2), At(sp, 3), () =>
{
StopSpin();
BuildInfo();
done();
});
BuildInfo(); // 도는 동안 = 칸 위 고리 숨김 + 건너뛰기 덮개(RouletteInfo)
}
int spinFrom;
/// <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();
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>룰렛 고리 연출(Frame 층 · 칸 경로를 처음 빠르게 → 끝에 느리게 · 끝 = done · Finish = 바로 끝).</summary>
public class EventSpin : MonoBehaviour
{
RectTransform ring;
List<Vector2> path;
float t0, t1, hold, t;
int i;
Action done;
bool running;
public bool Running
{
get { return running; }
}
public void Run(RectTransform r, List<Vector2> p, float stepStart, float stepEnd, float holdEnd, Action onDone)
{
ring = r;
path = p;
t0 = stepStart;
t1 = stepEnd;
hold = holdEnd;
done = onDone;
i = 0;
t = 0f;
running = path != null && path.Count > 0;
if (running) Place(0);
else Done();
}
/// <summary>칸 크기(고리는 칸보다 크다 · 칸 가운데에 맞춤 · 호출 쪽 CursorRing 과 같은 칸).</summary>
public float Base = 180f;
void Place(int k)
{
var pos = path[Mathf.Clamp(k, 0, path.Count - 1)];
float off = (ring.sizeDelta.x - Base) * 0.5f;
ring.anchoredPosition = new Vector2(pos.x - off, -(pos.y - off));
}
void Update()
{
if (!running) return;
t += Time.unscaledDeltaTime;
float u = path.Count > 1 ? i / (float)(path.Count - 1) : 1f;
float step = Mathf.Lerp(t0, t1, u * u);
if (i >= path.Count - 1)
{
if (t >= hold) Done();
return;
}
if (t >= step)
{
t = 0f;
i++;
Place(i);
}
}
public void Finish()
{
if (!running) return;
i = path.Count - 1;
Place(i);
Done();
}
public void Cancel()
{
running = false;
done = null;
}
void Done()
{
running = false;
var d = done;
done = null;
if (d != null) d();
}
}
}