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 = 1420f; // 글자 1.2 배 · 스테이지 정보 줄(+80 · PD 2026-11-24) + 전리품 줄(+260 · 2026-11-23 스테이지 보상 드랍) — 두 PC 변경 합침
const float Side = 60f;
const float RowW = PW - Side * 2f;
const float RowH = 64f;
const float Tile = 132f;
const float BtnY = PH - 40f - 110f;
// 승전보 두루마리 = 본문 판보다 옆 · 위 · 아래로 넓게(축이 본문 · 버튼을 덮지 않게) · 제목 명패 크기
const float PaperSide = 28f, PaperTop = 70f, PaperBottom = 96f, PlaqueW = 700f, PlaqueH = 150f;
bool paper;
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;
// 승전보(PD 2026-11-25 「인게임 결과창도 우리 게임의 컨셉과 화풍에 맞게 통일감 있는 디자인」) = 양피지 두루마리(공방 제작 주문서 · 출정 군령장과 같은 판) · 위아래 축은 본문 밖으로
var paperImg = UiKit.Fill("Paper", holder, -PaperSide, -PaperSide, -PaperTop, -PaperBottom).gameObject.AddComponent();
paperImg.raycastTarget = false;
paper = PaperScroll.Apply(paperImg);
if (paper)
{
paperImg.transform.SetAsFirstSibling();
var fr = holder.Find("Frame");
if (fr != null) fr.gameObject.SetActive(false);
}
else Object.Destroy(paperImg.gameObject);
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);
var plaque = paper ? UISkin.Icon("tre_plaque") : null;
if (plaque != null)
{
// 제목 = 붉은 칠 명패(서양식 팩 리본 대신 · PD 2026-11-21 「리본 형태 UI 가 어울리지 않음」 · 패배 = 어두운 칠)
rib.sizeDelta = new Vector2(PlaqueW, PlaqueH);
var gl = rib.Find(UISkin.OverlayName);
if (gl != null) gl.gameObject.SetActive(false);
ribbon.sprite = plaque;
ribbon.type = Image.Type.Sliced;
ribbon.pixelsPerUnitMultiplier = plaque.rect.height / PlaqueH;
title.fontSize = 76;
title.rectTransform.offsetMin = new Vector2(90f, 10f);
title.rectTransform.offsetMax = new Vector2(-90f, -10f);
}
// 별 3 = 받침 원 없이 별만 크게(PD 2026-11-24 「별 크기를 키우고 둥근 프레임 제거」) · 가운데 크게 · 위로 · 0.15 s 간격 튀김
starRow = UiKit.At(pt, "StarRow", 0f, 110f, PW, 220f);
UiLayer.Nest(starRow.gameObject, UiRate.Frame, false); // 별 3 튀김 = 한 Frame 층(별마다 캔버스를 만들지 않음 · PD 2026-11-10)
for (int i = 0; i < 3; i++)
{
bool mid = i == 1;
var pos = new Vector2((i - 1) * 215f, mid ? 14f : -16f);
starImg[i] = UiKit.Icon(starRow, "star_on_l", new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), pos, mid ? 176f : 140f);
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)
if (paper) retry.GetComponent().color = UiKit.Col("ws_btn_wood", new Color(0.47f, 0.3f, 0.18f)); // 승전보 위 = 나무색(남색 팩 칠이 혼자 튀지 않게 · QA r3 M10)
stageLine = UiKit.Title(UiKit.Label(pt, "", 34, UiKit.Col("text_soft", UiKit.InkSoft), TextAnchor.MiddleCenter, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -334f), new Vector2(RowW, 52f), false)); // 스테이지 정보(PD 2026-11-24 「제목은 승리 · 패배만 · 스테이지 정보는 메뉴 안」)
ok = UiKit.SkinBtn(pt, "Ok", UISkin.Has("btn_l_yellow") ? "btn_l_yellow" : "button", UISkin.Has("btn_l_yellow") ? UiKit.White : UiKit.Coin, OkText, 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);
}
BuildTip(dim);
ApplyGameFont(dim, 1.12f); // 게임 글꼴 + 조금 크게(PD 2026-11-24 「우리 게임 폰트 · 모바일에서 잘 보이게」) — 본문은 Fill 에서 따로
go.SetActive(false);
}
Text stageLine;
GameObject tipRoot;
///
/// 게임 팁 = 팝업 밖 아래의 「!」 말풍선(PD 2026-11-24 「팝업 UI 에 표시하지 말고 게임 팁 형태로 하단에 별도의 ! 말풍선」) — 패배 때만.
///
void BuildTip(RectTransform dim)
{
var tr = UiKit.Rect("Tip", dim, new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), new Vector2(0f, 150f), new Vector2(PW, 120f));
tipRoot = tr.gameObject;
var bubble = UiKit.Rect("Bubble", tr, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(46f, 0f), new Vector2(PW - 92f, 104f));
if (UiKit.Skin(bubble, "round08", UiKit.Col("tip_bubble", new Color(0.13f, 0.14f, 0.22f, 0.94f))) == null) UiKit.Paint(bubble, new Color(0.13f, 0.14f, 0.22f, 0.94f));
var tail = UiKit.Rect("Tail", bubble, new Vector2(0f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, 0f), new Vector2(30f, 30f));
tail.localRotation = Quaternion.Euler(0f, 0f, 45f);
UiKit.Paint(tail, UiKit.Col("tip_bubble", new Color(0.13f, 0.14f, 0.22f, 0.94f)), false);
var bang = UiKit.Rect("Bang", tr, new Vector2(0f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(46f, 0f), new Vector2(92f, 92f));
if (UiKit.Skin(bang, "circle_frame", UiKit.Col("tip_bang", new Color(1f, 0.72f, 0.16f))) == null) UiKit.Paint(bang, new Color(1f, 0.72f, 0.16f));
UiKit.Title(UiKit.FillLabel(bang, "!", 62, UiKit.White), true);
var head = UiKit.Label(bubble, "게임 팁", 26, UiKit.Col("tip_head", new Color(1f, 0.8f, 0.3f)), TextAnchor.UpperLeft, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(64f, -10f), new Vector2(PW - 200f, 36f), false);
head.horizontalOverflow = HorizontalWrapMode.Overflow;
var body2 = UiKit.Label(bubble, "영웅 레벨업 · 승급 · 편성을 바꿔 다시 도전", 32, UiKit.White, TextAnchor.UpperLeft, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(64f, -48f), new Vector2(PW - 200f, 46f), false);
body2.verticalOverflow = VerticalWrapMode.Truncate; // 한 줄 · 넘치면 줄임(최적 맞춤은 Truncate 여야 높이를 봄)
body2.resizeTextForBestFit = true;
body2.resizeTextMaxSize = 32;
body2.resizeTextMinSize = 22;
tipRoot.SetActive(false);
}
/// 게임 글꼴(제목 글꼴 = 인게임 HUD 와 같음) 적용 + 글자 크기 배율(PD 2026-11-24).
static void ApplyGameFont(Transform t, float scale)
{
if (t == null) return;
foreach (var x in t.GetComponentsInChildren(true))
{
UISkin.UseTitle(x);
x.fontSize = Mathf.RoundToInt(x.fontSize * scale);
if (x.resizeTextForBestFit) x.resizeTextMaxSize = Mathf.RoundToInt(x.resizeTextMaxSize * scale);
}
}
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