using UnityEngine;
using UnityEngine.UI;
namespace TKS.OutGame
{
///
/// 양피지 두루마리 판 + 종이 위 색(PD 2026-11-25 「전투 입장 팝업 · 결과창 · 튜토리얼을 우리 게임 컨셉과 화풍에 맞게 · 통일감」 · 공방 제작 주문서와 같은 판).
/// 판 = 내정 개발 양피지 dom_scroll(승인 그림 · 새 그림 0)을 위 · 아래 축 고정 9 분할로 — 값 = 표 UI/workshop_scene 의 forge_sheet 줄(테두리 px · 배율 · 안쪽 여백).
/// 종이 위 색 = 남색 판용으로 그린 본문(흰 글자 · 흰 반투명 줄)을 다 그린 뒤 한 번 바꿈: 흰 · 옅은 글자 → 먹 · 흐린 먹 · 노란 글자 → 짙은 금 · 흰 반투명 줄 받침 → 황갈 받침 · 가는 선 → 흐린 먹 선.
/// 버튼 · 색 칩 · 그림 위 글자(수량 알약 · 뱃지)는 그대로.
///
public static class PaperScroll
{
static Sprite sheet;
static LobbyScene.Row row;
static LobbyScene.Row Row()
{
if (row == null) row = DomesticScene.First(LobbyScene.Load("UI/workshop_scene"), "forge_sheet");
return row;
}
/// 두루마리 판 스프라이트(없으면 null).
public static Sprite Sheet()
{
if (sheet != null) return sheet;
var r = Row();
var src = r != null ? UISkin.Icon(r.sprite) : null;
if (src == null) return null;
var rect = src.packed ? src.textureRect : src.rect;
sheet = Sprite.Create(src.texture, rect, new Vector2(0.5f, 0.5f), src.pixelsPerUnit, 0, SpriteMeshType.FullRect, new Vector4(r.x, r.h, r.x, r.y));
sheet.name = "paper_scroll";
return sheet;
}
/// 이미지를 두루마리 판으로(9 분할 · 표 배율) · 판이 없으면 false.
public static bool Apply(Image img)
{
var sp = Sheet();
if (img == null || sp == null) return false;
var old = img.transform.Find(UISkin.OverlayName);
if (old != null) old.gameObject.SetActive(false);
img.sprite = sp;
img.type = Image.Type.Sliced;
img.pixelsPerUnitMultiplier = Row().scale > 0.01f ? Row().scale : 2f;
img.color = Color.white;
return true;
}
/// 종이 위쪽 축 + 종이 위 여백(화면 px) = 위 테두리 ÷ 배율.
public static float TopInset { get { var r = Row(); return r != null ? r.y / Mathf.Max(0.01f, r.scale) : 120f; } }
public static float BottomInset { get { var r = Row(); return r != null ? r.h / Mathf.Max(0.01f, r.scale) : 111f; } }
public static float SideInset { get { var r = Row(); return r != null && r.w > 0f ? r.w : 70f; } }
public static Color Ink { get { return UiKit.Col("dom_ink", new Color(0.35f, 0.23f, 0.13f)); } }
public static Color InkSoft { get { return UiKit.Col("dom_ink_soft", new Color(0.54f, 0.42f, 0.30f)); } }
public static Color Chip { get { return UiKit.Col("dom_chip", new Color(0.90f, 0.80f, 0.60f)); } }
public static Color InkGold { get { return UiKit.Col("ws_ink_gold", new Color(0.62f, 0.4f, 0.06f)); } }
static float Lum(Color c) { return 0.299f * c.r + 0.587f * c.g + 0.114f * c.b; }
static float Sat(Color c) { float mx = Mathf.Max(c.r, Mathf.Max(c.g, c.b)), mn = Mathf.Min(c.r, Mathf.Min(c.g, c.b)); return mx <= 0.001f ? 0f : (mx - mn) / mx; }
/// 글자 뒤에 진한 바탕(그림 · 색 칩 · 버튼)이 있으면 true — 그 글자는 그대로.
static bool OnArt(Transform t, Transform root)
{
for (var p = t.parent; p != null && p != root; p = p.parent)
{
if (p.GetComponent