using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.UI;
namespace TKS.OutGame
{
///
/// 전투 결과 패널(기획서 §6 · 비주얼 = Fable 제안서 §4-2 #1104) — 별 3(받침 원 + 등장 튀김) · 조건 행 3 · 보상 타일(골드 · 경험 · 보옥 · 장비 · 상자) ·
/// 버튼 = 「다시」(Tertiary · 같은 스테이지 재도전) + 「확인」(Primary 노랑) · 승리면 리본 뒤 금빛.
/// 전투 HUD 의 승리/패배 판(sortingOrder 100) 위에 덮는다 · 화면 아무 데나 탭 = 기존 그대로(SlingshotInput → 월드맵 복귀 · 「다시」 위만 제외).
///
public class BattleResultPanel
{
// 패널 배치(UI px · 패널 왼쪽 위 기준)
const float PW = 920f;
const float PH = 1080f;
const float Side = 60f;
const float RowW = PW - Side * 2f;
const float RowH = 64f;
const float Tile = 132f;
const float BtnY = PH - 40f - 110f;
readonly OutGameRoot root;
readonly GameObject go;
readonly Text title;
readonly Image ribbon;
readonly Image glow;
readonly RectTransform starRow;
readonly Image[] starImg = new Image[3];
readonly RectTransform body;
readonly Text plain;
readonly Button retry;
readonly Button ok;
readonly Text retryCost;
string rewardsText = "";
public bool Visible
{
get { return go.activeSelf; }
}
public string RewardsText
{
get { return rewardsText; }
}
public BattleResultPanel(OutGameRoot r, RectTransform canvas)
{
root = r;
var dim = UiKit.Fill("Result", canvas);
UiKit.Paint(dim, UISkin.Col("dim", new Color(0f, 0f, 0f, 0.55f)), false);
go = dim.gameObject;
Image panel = null;
if (UISkin.Has("popup") && UISkin.Has("panel_frame"))
{
// 리본 뒤 금빛(승리만 · 팩 Glow_Circle01 · 호흡) → 팩 팝업 틀 → 제목 리본(승리 붉은 · 패배 회색)
if (UISkin.Has("glow_circle"))
{
glow = UiKit.Skin(UiKit.Rect("Glow", dim, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, 20f + PH * 0.5f + 90f), new Vector2(1240f, 1240f)), "glow_circle", UiKit.Col("ribbon_glow", Color.clear));
var pulse = glow.gameObject.AddComponent();
pulse.min = 0.65f;
pulse.period = 1.6f;
// 안쪽 한 겹 더(그림 가운데 α 0.5 라 한 장으로는 후광이 약함 · 검수2 보충)
var core = UiKit.Skin(UiKit.Rect("Core", glow.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, new Vector2(720f, 720f)), "glow_circle", UiKit.Col("ribbon_glow", Color.clear));
core.raycastTarget = false;
}
// 패널 = 섹션 패널 층(그림자 · 밝은 프레임 #3F4262 · 필드 #262840 · 윗면 광택 · 검수 결함 10)
var holder = UiKit.Rect("Panel", dim, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, 20f), new Vector2(PW, PH));
RectTransform froot;
UiKit.SectionPanel(holder, "Frame", 0f, 0f, PW, PH, false, false, out froot);
var pt = (Transform)holder;
var rib = UiKit.Rect("Ribbon", pt, new Vector2(0.5f, 1f), new Vector2(0.5f, 0.5f), new Vector2(0f, 10f), new Vector2(1000f, 200f));
ribbon = UiKit.Skin(rib, "ribbon", Color.white);
title = UiKit.Title(UiKit.FillLabel(rib, "", 88, UiKit.White, TextAnchor.MiddleCenter, true, 150f), true);
title.rectTransform.offsetMin = new Vector2(150f, 34f);
// 별 3 = 받침 원(Circle78 chip_dark) + 별(가운데 크게 · 위로) · 0.15 s 간격 튀김
starRow = UiKit.At(pt, "StarRow", 0f, 120f, PW, 190f);
UiLayer.Nest(starRow.gameObject, UiRate.Frame, false); // 별 3 튀김 = 한 Frame 층(별마다 캔버스를 만들지 않음 · PD 2026-11-10)
for (int i = 0; i < 3; i++)
{
bool mid = i == 1;
float plate = mid ? 150f : 120f;
var pos = new Vector2((i - 1) * 190f, mid ? 12f : -14f);
UiKit.Skin(UiKit.Rect("Plate" + i, starRow, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), pos, new Vector2(plate, plate)), "circle_frame", UiKit.Col("chip_dark", UiKit.Dark));
starImg[i] = UiKit.Icon(starRow, "star_on_l", new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), pos + new Vector2(0f, 4f), mid ? 132f : 106f);
if (starImg[i] == null) continue;
UiKit.DropShadow(starImg[i], 5f);
starImg[i].gameObject.AddComponent().delay = 0.15f * i;
}
body = UiKit.Fill("Body", pt);
retry = UiKit.SkinBtn(pt, "Retry", "round08", UiKit.Col("menu_btn", UiKit.Dark), "다시", 34, UiKit.White, Side, BtnY, 260f, 110f, () => root.RetryStage());
retryCost = UiKit.BtnCost(retry, "cur_stamina", "", 36f, 28); // 재도전 = 군량 소모 표시(검수 결함 2)
ok = UiKit.SkinBtn(pt, "Ok", UISkin.Has("btn_l_yellow") ? "btn_l_yellow" : "button", UISkin.Has("btn_l_yellow") ? UiKit.White : UiKit.Coin, "확인", 46, UiKit.Col("text_on_yellow", UiKit.Ink), PW - Side - 520f, BtnY, 520f, 110f, null);
}
else
{
panel = UiKit.Box("Panel", dim, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, 40f), new Vector2(PW, PH), UiKit.Paper);
UiKit.Border(panel, UiKit.Line, 4f);
var head = UiKit.TopBand("Head", panel.transform, 0f, 170f);
UiKit.Paint(head, UiKit.Dark);
title = UiKit.FillLabel(head, "", 96, UiKit.White);
plain = UiKit.Label(panel.transform, "", 36, UiKit.Ink, TextAnchor.UpperLeft, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -200f), new Vector2(760f, 860f), false);
plain.lineSpacing = 1.15f;
UiKit.Label(panel.transform, "화면을 탭하면 계속", 34, UiKit.InkSoft, TextAnchor.MiddleCenter, new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), new Vector2(0f, 36f), new Vector2(800f, 60f), false);
}
go.SetActive(false);
}
public void SetVisible(bool on)
{
if (go.activeSelf != on) go.SetActive(on);
}
/// 화면 좌표가 「다시」 버튼 위인가 — 화면 탭(월드맵 복귀)을 이 버튼에서는 건너뛴다.
public bool PointerOnRetry(Vector2 screen)
{
if (retry == null || !go.activeInHierarchy || !retry.gameObject.activeSelf) return false;
var c = go.GetComponentInParent