ThreeKingdomsSlingshot/Assets/Scripts/OutGame/Trade/TradeScreen.Kit.cs

380 lines
19 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.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace TKS.OutGame
{
/// <summary>
/// 거래 화면 공용 부품(PD 2026-11-26 확정 · 디자인 `C:/ArtRnD/sprite_gen/ui_illust/samguk/trade_ui/design/디자인기획_r1 · r2 · r3_배경판.md`) —
/// 종이 위 먹 글자 · 크림 줄 · 붉은 옻칠 명패(tre_plaque) · 노랑 가격 버튼 · 가치 꼬리표 · 기울인 도장 · 판 그림 = Resources/UI/Trade/ui(9 분할 · 3차 시안 = 그림 세션이 같은 id 로 다시 그림).
/// 상품 그림 = 요청서 4절 경로(Resources/UI/Trade/art · icons) · 파일이 없으면 더미(색 판 + 대표 아이콘).
/// 캔버스(P41): 페이지 = 화면 중첩(Event) · 긴 목록 = UiKit.ScrollGrid 내용(Frame) · 남은 시간 글자 = OnTick 0.5 초 글자만.
/// </summary>
public partial class TradeScreen
{
public const string SceneTable = "UI/Trade/trade_scene";
public const string UiDir = "UI/Trade/ui/";
RectTransform sceneRoot;
bool scenic;
/// <summary>그림이 없어 더미로 그린 그림 · 아이콘 수(캡처 로그 · 그림 반영 확인).</summary>
public static int DummyArt { get; private set; }
// 종이 색(디자인 r1 · r3 실측 · 테마에 같은 id 가 있으면 테마 값)
static Color C(string id, string hex)
{
Color c;
ColorUtility.TryParseHtmlString("#" + hex, out c);
return UiKit.Col(id, c);
}
static Color Ink { get { return C("trade_ink", "4A2A16"); } }
static Color InkSoft { get { return C("trade_ink_soft", "8A6444"); } }
static Color InkRed { get { return C("trade_ink_red", "C23A2E"); } }
static Color RowC { get { return C("trade_row", "F3D9A8"); } }
static Color RowLine { get { return C("trade_row_line", "D2A96C"); } }
static Color CardC { get { return C("trade_card", "FBEBCB"); } }
static Color CardWell { get { return C("trade_card_well", "EBCF9C"); } }
static Color WoodLine { get { return C("trade_wood_line", "8A5A36"); } }
static Color Gold { get { return UiKit.Coin; } }
void BuildScene()
{
sceneRoot = UiKit.Fill("TradeScene", Rt, 0f, 0f, OutGameRoot.TopBarH + OutGameRoot.HeaderH, OutGameRoot.TabBarH);
RectTransform art;
float w, h;
var rows = LobbyScene.Load(SceneTable);
DomesticScene.Backdrop(sceneRoot, "Scene", rows, out art, out w, out h);
scenic = art != null;
// 배경 어둡게(PD 2026-11-26 「배경이 너무 밝아서 상품 정보가 잘 안 보임」) — 장면 위 · 판 아래 덮개 · 색 · 진하기 = 표 dim 줄 s_color
var dimRow = rows != null ? DomesticScene.First(rows, "dim") : null;
if (scenic && dimRow != null) UiKit.Paint(UiKit.Fill("Dim", sceneRoot), dimRow.color, false);
if (!scenic) UiKit.Paint(sceneRoot, UiKit.Col("list_bg", UiKit.Bg), false); // 그림이 없으면 예전 목록 바탕
sceneRoot.gameObject.SetActive(false);
}
void ShowSceneFor(int p)
{
if (sceneRoot == null) return;
bool on = p != PageRecruit;
if (sceneRoot.gameObject.activeSelf != on) sceneRoot.gameObject.SetActive(on);
}
/// <summary>위 탭 4개 = 붉은 옻칠 + 금테 명패(공방과 같은 tre_plaque) · 고른 탭 = 밝게 · 아닌 탭 = 어두운 칠.</summary>
static void PlaqueTab(Button b, bool on)
{
var plaque = UISkin.Icon("tre_plaque");
var img = b.GetComponent<Image>();
if (plaque == null || img == null)
{
UiKit.SetSubTab(b, on);
return;
}
if (img.sprite != plaque)
{
img.sprite = plaque;
img.type = Image.Type.Sliced;
img.pixelsPerUnitMultiplier = plaque.rect.height / Mathf.Max(1f, ((RectTransform)b.transform).rect.height);
var ov = b.transform.Find(UISkin.OverlayName);
if (ov != null) ov.gameObject.SetActive(false);
}
img.color = on ? Color.white : UiKit.Col("ws_tab_off", new Color(0.34f, 0.3f, 0.32f, 1f));
var t = UiKit.LabelOf(b);
if (t != null) t.color = on ? UiKit.White : UiKit.Col("ws_tab_off_text", new Color(0.86f, 0.8f, 0.7f, 1f));
}
// ---------- 판 · 줄 · 명패 ----------
/// <summary>
/// 종이 위 칠(둥근 모서리 · 테마 카드 스킨을 쓰지 않음 = 굵은 검은 테 없음 · PD 「테두리 얇게」) — 테는 Border 로 얇게 따로.
/// </summary>
static Image PaperFill(RectTransform rt, Color c, bool rounded = true, bool raycast = false)
{
var img = rt.gameObject.AddComponent<Image>();
img.color = c;
if (rounded)
{
img.sprite = UiKit.Round;
img.type = Image.Type.Sliced;
img.pixelsPerUnitMultiplier = 2f; // 모서리 반지름 22 → 11
}
img.raycastTarget = raycast;
return img;
}
/// <summary>틀 안을 빈틈없이 채우는 그림(가로세로 비 유지 · 넘치는 곳은 잘림).</summary>
static Image AspectFill(RectTransform clip, Sprite sp, float w, float h)
{
clip.gameObject.AddComponent<RectMask2D>();
float s = Mathf.Max(w / sp.rect.width, h / sp.rect.height);
var im = UiKit.Rect("Pic", clip, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, new Vector2(sp.rect.width * s, sp.rect.height * s)).gameObject.AddComponent<Image>();
im.sprite = sp;
im.raycastTarget = false;
return im;
}
static readonly Dictionary<string, Sprite> uiCache = new Dictionary<string, Sprite>();
static Sprite UiSprite(string id)
{
Sprite sp;
if (uiCache.TryGetValue(id, out sp) && sp != null) return sp;
sp = Resources.Load<Sprite>(UiDir + id);
if (sp != null) uiCache[id] = sp;
return sp;
}
/// <summary>9 분할 판(tr_sheet_parchment · tr_board_frame · tr_board_paper · tr_slip …) — 그림이 없으면 색 판.</summary>
static RectTransform Panel9(Transform p, string name, string id, float x, float y, float w, float h, Color fallback, float scale = 1f)
{
var rt = UiKit.At(p, name, x, y, w, h);
var sp = UiSprite(id);
if (sp == null)
{
PaperFill(rt, fallback);
return rt;
}
var img = rt.gameObject.AddComponent<Image>();
img.sprite = sp;
img.type = sp.border.sqrMagnitude > 0f ? Image.Type.Sliced : Image.Type.Simple;
img.pixelsPerUnitMultiplier = 1f / Mathf.Max(0.1f, scale); // scale < 1 = 테두리를 그만큼 작게
img.raycastTarget = false;
return rt;
}
/// <summary>크림 줄(행 #F3D9A8 · 테 #D2A96C).</summary>
static RectTransform Row(Transform p, string name, float x, float y, float w, float h, bool big = false)
{
var rt = UiKit.At(p, name, x, y, w, h);
var img = PaperFill(rt, RowC);
UiKit.Border(img, big ? Gold : RowLine, big ? 2f : 1.5f);
return rt;
}
/// <summary>카드(미색 면 · 나무 테 얇게).</summary>
static RectTransform Card(Transform p, string name, float x, float y, float w, float h)
{
var rt = UiKit.At(p, name, x, y, w, h);
UiKit.Border(PaperFill(rt, CardC), WoodLine, 2f);
return rt;
}
/// <summary>붉은 옻칠 명패 + 흰 글자(제목 · 카드 머리) · off = 크림 명패 + 먹 글자.</summary>
static RectTransform Plaque(Transform p, string name, string text, float x, float y, float w, float h, int size, bool red = true)
{
var rt = UiKit.At(p, name, x, y, w, h);
var plaque = red ? UISkin.Icon("tre_plaque") : null;
if (plaque != null)
{
var img = rt.gameObject.AddComponent<Image>();
img.sprite = plaque;
img.type = Image.Type.Sliced;
img.pixelsPerUnitMultiplier = plaque.rect.height / Mathf.Max(1f, h);
img.raycastTarget = false;
}
else UiKit.Border(PaperFill(rt, red ? InkRed : RowC), red ? Gold : WoodLine, 2f);
var t = UiKit.FillLabel(rt, text, size, red ? UiKit.White : Ink, TextAnchor.MiddleCenter, true, 10f);
UiKit.Title(t, red);
t.horizontalOverflow = HorizontalWrapMode.Overflow;
return rt;
}
/// <summary>왼쪽 위 기준 글자(종이 위 = 먹 글자 · 외곽선 없음 · title = 제목 글꼴).</summary>
static Text Txt(Transform p, string name, string s, int size, Color c, float x, float y, float w, float h, TextAnchor a = TextAnchor.MiddleLeft, bool title = false)
{
var t = UiKit.Label(p, s, size, c, a, TL, TL, new Vector2(x, -y), new Vector2(w, h), title);
t.name = name;
if (title) UiKit.Title(t, false);
return t;
}
/// <summary>구역 제목(먹 · 제목 글꼴) + 오른쪽 작은 안내(보조 먹).</summary>
static Text Section(Transform p, string name, string title, string note, float y, float w)
{
Txt(p, name, title, 34, Ink, 6f, y, 420f, 54f, TextAnchor.MiddleLeft, true);
return Txt(p, name + "Note", note, 19, InkSoft, 420f, y + 6f, w - 426f, 44f, TextAnchor.MiddleRight);
}
/// <summary>구분선(V1 붓 먹선 · V2 나무 졸대 = 3 분할 그림 · 없으면 가는 줄).</summary>
static void Separator(Transform p, string id, float x, float y, float w)
{
var sp = UiSprite(id);
var rt = UiKit.At(p, "Sep", x, y, w, sp != null ? sp.rect.height : 3f);
if (sp == null)
{
PaperFill(rt, RowLine, false);
return;
}
var img = rt.gameObject.AddComponent<Image>();
img.sprite = sp;
img.type = Image.Type.Sliced;
img.raycastTarget = false;
}
// ---------- 그림(요청서 4절) ----------
static readonly Dictionary<string, Sprite> artCache = new Dictionary<string, Sprite>();
/// <summary>Resources 그림(Sprite 로 임포트 안 된 그림 = Texture2D 에서 만듦) · 없으면 null.</summary>
public static Sprite ArtSprite(string dir, string id)
{
if (string.IsNullOrEmpty(id)) return null;
string path = dir + id;
Sprite sp;
if (artCache.TryGetValue(path, out sp) && sp != null) return sp;
sp = Resources.Load<Sprite>(path);
if (sp == null)
{
var tex = Resources.Load<Texture2D>(path);
if (tex != null) sp = Sprite.Create(tex, new Rect(0f, 0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100f);
}
if (sp != null) artCache[path] = sp;
return sp;
}
/// <summary>상품 그림(배너 · 카드 · 권 · 월정액 · 팝업) — 테 있는 칸 · 없으면 더미(색 판 + 대표 아이콘 · 그림에 글자 0).</summary>
static RectTransform Art(Transform p, string name, string id, float x, float y, float w, float h, string dummyIcon)
{
var rt = UiKit.At(p, name, x, y, w, h);
var sp = ArtSprite(TradeData.ArtDir, id);
UiKit.Border(PaperFill(rt, sp != null ? CardC : CardWell), WoodLine, 2f);
if (sp != null)
{
var img = UiKit.Fill("Pic", rt, 4f, 4f, 4f, 4f).gameObject.AddComponent<Image>();
img.sprite = sp;
img.preserveAspect = true;
img.raycastTarget = false;
return rt;
}
DummyArt++;
if (!string.IsNullOrEmpty(dummyIcon))
{
var ic = UiKit.Icon(rt, dummyIcon, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, Mathf.Min(w, h) * 0.6f);
if (ic != null) UiKit.DropShadow(ic, 4f);
}
return rt;
}
/// <summary>보상 낱말 칸(게임 보상 타일 · 새 낱말 아이콘 = Resources/UI/Trade/icons/icon_&lt;낱말&gt; · ★1 · ★2 조각 = 정한 영웅 얼굴).</summary>
RectTransform Item(Transform p, string name, string key, int n, float x, float y, float size, string heroId = null)
{
var tsp = ArtSprite(TradeData.IconDir, "icon_" + key);
string icon = !string.IsNullOrEmpty(heroId) ? HeroIcons.ShardPrefix + heroId : tsp != null ? "" : GoodsUi.IconOfKey(S.Db, key);
var cell = UiKit.RewardTile(p, name, x, y, size, "gear_white_", icon, n > 0 ? "x" + n.ToString("N0") : "", false);
if (tsp != null && string.IsNullOrEmpty(heroId))
{
var ic = UiKit.Rect("TradeIcon", cell, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, 4f), new Vector2(size * 0.68f, size * 0.68f)).gameObject.AddComponent<Image>();
ic.sprite = tsp;
ic.preserveAspect = true;
ic.raycastTarget = false;
var qty = cell.Find("Qty");
if (qty != null) ic.transform.SetSiblingIndex(qty.GetSiblingIndex());
}
else if (tsp == null && (key == GoodsRules.SupplyTicket || key == GoodsRules.HeroPick)) DummyArt++; // 새 낱말 아이콘 = 그림 세션 몫(없으면 대체 아이콘)
return cell;
}
/// <summary>꾸러미 칸 줄(최대 max 칸 · 넘치면 「+N종」) → 오른쪽 끝 x.</summary>
float Items(Transform p, string name, string parts, float x, float y, float size, float gap, int max)
{
var list = TradeData.Items(parts);
int n = Mathf.Min(max, list.Count);
for (int i = 0; i < n; i++)
{
if (i == max - 1 && list.Count > max)
{
var more = UiKit.At(p, name + "More", x, y, size, size);
UiKit.Border(PaperFill(more, CardWell), RowLine, 2f);
Txt(more, "Text", TradeText.F("trade_more", list.Count - max + 1), 22, Ink, 0f, 0f, size, size, TextAnchor.MiddleCenter, true);
return x + size;
}
Item(p, name + i, list[i].Key, list[i].Value, x, y, size);
x += size + gap;
}
return x - gap;
}
/// <summary>가치 꼬리표(1차 A · 미색 면 + 붉은 테 · 붉은 글자 「가치 ×N」).</summary>
static void ValueBadge(Transform p, float x, float y, float mult)
{
if (mult <= 0f) return;
var b = UiKit.At(p, "Value", x, y, 136f, 40f);
UiKit.Border(PaperFill(b, C("trade_value_bg", "FBE3D6")), InkRed, 2f);
Txt(b, "Text", TradeText.F("trade_value", mult.ToString("0.0")), 22, InkRed, 0f, 0f, 136f, 40f, TextAnchor.MiddleCenter, true);
}
/// <summary>기울인 도장(A-2 · 할인 · 가치 · 첫 구매) — 미색 면 + 붉은 테 · 붉은 글자 · −12°.</summary>
static void Stamp(Transform p, string text, float x, float y, float w, float h, int size)
{
var b = UiKit.At(p, "Stamp", x, y, w, h);
UiKit.Border(PaperFill(b, C("trade_value_bg", "FBE3D6")), InkRed, 2f);
b.localRotation = Quaternion.Euler(0f, 0f, -12f);
Txt(b, "Text", text, size, InkRed, 0f, 0f, w, h, TextAnchor.MiddleCenter, true);
}
/// <summary>결제 버튼(노랑 · ₩ 가격 · 살 수 없으면 까닭 + 회색) → 고르기 → 시험 결제 확인 → 지급 → 보상.</summary>
Button PayBtn(Transform p, string name, string sid, float x, float y, float w, float h)
{
string block = S.TradeAvailable ? TradeRules.CanPurchase(S.Db, S.Cfg, S.Save, sid, S.Now) : TradeText.T("trade_server_later");
bool ok = block == null;
var b = UiKit.SkinBtn(p, name, ok ? "btn_l_yellow" : "btn_gray", UiKit.White, ok ? TradeText.Krw(TradeData.PriceKrw(sid)) : block, ok ? (h >= 80f ? 36 : 30) : 22,
ok ? UiKit.Col("text_on_yellow", UiKit.Ink) : UiKit.White, x, y, w, h, () => TradeWindows.Buy(Root, sid, Refresh));
b.interactable = ok;
return b;
}
/// <summary>긴 목록(세로 스크롤 · 내용 = 높이 h 판 1장 · 폭 w · 자식은 왼쪽 위 기준 At 으로 놓음).</summary>
static RectTransform Sheet(Transform page, string name, float l, float r, float top, float bottom, float w, float h, out ScrollRect sr)
{
var content = UiKit.ScrollGrid(name, page, l, r, top, bottom, new Vector2(w, h), Vector2.zero, 1, out sr);
var sheet = new GameObject("Sheet", typeof(RectTransform)).GetComponent<RectTransform>();
sheet.SetParent(content, false);
return sheet;
}
static void SetSheetHeight(RectTransform sheet, float w, float h)
{
var grid = sheet.parent.GetComponent<GridLayoutGroup>();
if (grid != null) grid.cellSize = new Vector2(w, h);
}
/// <summary>남은 시간 글자(00:00:00 · 100시간 넘으면 n일 h시간).</summary>
public static string Remain(System.TimeSpan t)
{
if (t < System.TimeSpan.Zero) t = System.TimeSpan.Zero;
if (t.TotalHours >= 100) return TradeText.F("trade_days_hours", (int)t.TotalDays, t.Hours);
return ((int)t.TotalHours).ToString("00") + ":" + t.Minutes.ToString("00") + ":" + t.Seconds.ToString("00");
}
/// <summary>결제 안내 · 청약 철회 · 확률 정보 줄(모든 구매 화면 아래 · 법정 표시).</summary>
void FooterLine(Transform p, float x, float y, float w, List<string> chests)
{
var b = UiKit.At(p, "Footer", x, y, w, 50f);
var img = PaperFill(b, new Color(1f, 1f, 1f, 0f));
img.raycastTarget = true;
Txt(b, "Text", TradeText.T("trade_footer"), 22, InkSoft, 0f, 0f, w, 50f, TextAnchor.MiddleCenter);
b.gameObject.AddComponent<Button>().onClick.AddListener(() => TradeWindows.Notice(Root, chests));
}
static string FirstKey(string parts)
{
var l = TradeData.Items(parts);
return l.Count > 0 ? l[0].Key : "";
}
static string NameOf(ContentRow r)
{
return TradeText.T("trade_name_" + r.S("s_id"));
}
/// <summary>탭 · 버튼 오른쪽 위 빨간 점(꺼진 채 시작).</summary>
static GameObject Dot(Transform btn)
{
var dot = UiKit.Dot("Dot", btn, new Vector2(1f, 1f), new Vector2(0.5f, 0.5f), new Vector2(-10f, -8f), 26f, UiKit.Red);
dot.gameObject.SetActive(false);
return dot.gameObject;
}
}
}