ThreeKingdomsSlingshot/Assets/Scripts/OutGame/Arena/LockOverlay.cs

232 lines
12 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 System.Globalization;
using UnityEngine;
using UnityEngine.UI;
namespace TKS.OutGame
{
/// <summary>
/// 잠긴 컨텐츠 표시(PD 2026-11-18 「잠겨진 컨텐츠는 설령 해당 조건에 도달하지 않았어도 잠겨진 상태로 화면이 보여져야 해 · 어둡게 암전 된 상태에서 자물쇠가 배치 된 상태에 개방 조건을 표시」 ·
/// PD 2026-11-19 「투기장, 맹장 토벌전의 경우, 진입 전 단계(연무장)에서 진입을 막도록 · 보급전(훈련장)은 각 메뉴별로 각각 개방 조건」) — 세 가지:
/// ① <see cref="Apply"/> = 아트 화면 슬롯 위 본문 칸(재화 바 · 제목 띠 아래 ~ 하단 탭 위) 덮개: 어둡게(누름 막음) + 가운데 자물쇠 + 「개방 조건」 + 조건 문장 · 자기 Event 캔버스 + 레이캐스터(P41) ·
/// 지금 쓰는 곳 = 투기장 · 맹장 토벌전 페이지에 있는 동안 잠긴 때(방어 · 들어가기는 ArenaScreen.SetPage 가 막음).
/// ② <see cref="ApplyCard"/> = 카드 하나 위(보급전 던전 카드): 카드 그림 모양 그대로 어둡게 + 같은 묶음(크기 = 표 card_* × 화면 배율) · 목록 내용 층 안(캔버스 없음).
/// ③ <see cref="Notice"/> = 들어가기 막음 안내 팝업(제목 「개방 조건」 + 같은 조건 문장 + 확인).
/// 표(C45) = Resources/UI/Lock/lock_overlay(어둡기 · 크기 · 색 · 글자 크기) · 글자 = lock_text(UiText) · 스테이지 제목 = 전투 설정 스테이지 표(BalanceConfig.stages · 못 찾으면 번호만).
/// </summary>
public static class LockOverlay
{
public const string Table = "UI/Lock/lock_overlay";
public const string Name = "LockOverlay";
public const string TitleName = "LockTitle";
public const string CondName = "LockCond";
static readonly Vector2 TopLeft = new Vector2(0f, 1f);
static Dictionary<string, string> Load()
{
var kv = new Dictionary<string, string>();
var rows = UiText.Rows(Table);
if (rows == null)
{
Debug.LogWarning("[TKS] 잠김 덮개 표 없음: " + Table);
return kv;
}
foreach (var r in rows)
{
string k, v;
if (!r.TryGetValue("s_key", out k) || k.Length == 0 || kv.ContainsKey(k)) continue;
r.TryGetValue("s_value", out v);
kv[k] = v ?? "";
}
string texts;
if (kv.TryGetValue("texts", out texts)) UiText.Use(texts);
return kv;
}
static string[] L(Dictionary<string, string> kv, string key)
{
string v;
return kv.TryGetValue(key, out v) ? v.Split('|') : new string[0];
}
static float At(string[] a, int i, float def)
{
float f;
return a != null && i < a.Length && float.TryParse(a[i].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out f) ? f : def;
}
static string Str(string[] a, int i, string def)
{
return a != null && i < a.Length && a[i].Trim().Length > 0 ? a[i].Trim() : def;
}
static Color Col(string[] a, int i, Color def)
{
Color c;
return a != null && i < a.Length && ColorUtility.TryParseHtmlString(a[i].Trim(), out c) ? c : def;
}
/// <summary>조건 문장 = 출정 장-번호 「스테이지 제목」 클리어(제목 = 스테이지 표 · 못 찾으면 번호만).</summary>
public static string Condition(string stageKey, BalanceConfig cfg)
{
Load();
var st = cfg != null ? ArenaRules.FindStage(cfg, stageKey) : null;
if (st != null && !string.IsNullOrEmpty(st.title)) return UiText.F("lock_stage", new[] { stageKey, st.title });
return UiText.F("lock_stage_no_title", new[] { stageKey ?? "" });
}
/// <summary>들어가기 막음 안내(PD 2026-11-19 · 연무장 투기장 · 맹장 토벌전) = 팝업 제목 「개방 조건」 + 조건 문장(덮개와 같은 글자) + 확인.</summary>
public static void Notice(OutGameRoot root, string stageKey, BalanceConfig cfg)
{
if (root == null) return;
string cond = Condition(stageKey, cfg); // 표 · 글자 표를 먼저 읽음
root.Modal(UiText.T("lock_title"), cond, new OutGameRoot.ModalButton(UiText.T("lock_ok"), UiKit.Dark, null));
}
/// <summary>slot 의 덮개(없거나 걷혔으면 null · 테스트).</summary>
public static RectTransform Find(Transform slot)
{
if (slot == null) return null;
for (int i = 0; i < slot.childCount; i++)
{
var c = slot.GetChild(i);
if (c.name == Name && c.gameObject.activeSelf) return (RectTransform)c;
}
return null;
}
/// <summary>덮개 글자(테스트 · 이름 = LockTitle · LockCond · 덮개 없음 = null).</summary>
public static string TextOf(Transform slot, string name)
{
var ov = Find(slot);
if (ov == null) return null;
foreach (var t in ov.GetComponentsInChildren<Text>(true))
if (t.name == name)
return t.text;
return null;
}
/// <summary>덮개를 걷는다(이름을 바꿔 같은 프레임의 Find 에 걸리지 않게).</summary>
public static void Remove(Transform slot)
{
if (slot == null) return;
for (int i = slot.childCount - 1; i >= 0; i--)
{
var c = slot.GetChild(i);
if (c.name != Name) continue;
c.name = Name + "_old";
c.gameObject.SetActive(false);
Object.Destroy(c.gameObject);
}
}
/// <summary>locked = 덮개를 새로 씌움(맨 위 · 이미 있으면 바꿈) · false = 걷음. 반환 = 덮개(없으면 null).</summary>
public static RectTransform Apply(RectTransform slot, bool locked, string stageKey, BalanceConfig cfg)
{
if (slot == null) return null;
Remove(slot);
if (!locked) return null;
var kv = Load();
// 층 = 본문 칸만(제목 띠 · 하단 탭 밖) · 자기 Event 캔버스 + 레이캐스터
var ov = UiLayer.Group(Name, slot, UiRate.Event, true);
ov.offsetMin = new Vector2(0f, OutGameRoot.TabBarH);
ov.offsetMax = new Vector2(0f, -(OutGameRoot.TopBarH + OutGameRoot.HeaderH));
ov.SetAsLastSibling();
var dm = L(kv, "dim");
var dim = UiKit.Fill("Dim", ov).gameObject.AddComponent<Image>();
var dc = Col(dm, 0, Color.black);
dc.a = At(dm, 1, 0.68f);
dim.color = dc;
dim.raycastTarget = true; // 아래 화면 누름 · 끌기(목록 스크롤)를 막음
string cy;
kv.TryGetValue("center_y", out cy);
Center(ov, kv, "", 1f, new Vector2(0.5f, 1f - At(new[] { cy ?? "" }, 0, 0.46f)), stageKey, cfg);
return ov;
}
/// <summary>
/// 카드 하나만 잠김(PD 2026-11-19 보급전 던전 카드) — card 맨 위에 어둡게(shape = 카드 그림 · 둥근 모서리 그대로 · null 이면 네모) + 자물쇠 + 「개방 조건」 + 조건 문장.
/// 크기 = 표 card_* × z(목록 화면 배율) · 캔버스를 따로 만들지 않음(목록 내용 층 안 · 끌기 = 목록 스크롤 그대로). 반환 = 판(이름 LockOverlay · Find · TextOf 그대로).
/// </summary>
public static RectTransform ApplyCard(RectTransform card, Sprite shape, string stageKey, BalanceConfig cfg, float z)
{
if (card == null) return null;
Remove(card);
var kv = Load();
var ov = UiKit.Fill(Name, card);
ov.SetAsLastSibling();
var dm = L(kv, "card_dim");
var dim = UiKit.Fill("Dim", ov).gameObject.AddComponent<Image>();
dim.sprite = shape;
var dc = Col(dm, 0, Color.black);
dc.a = At(dm, 1, 0.62f);
dim.color = dc;
dim.raycastTarget = true; // 카드 누름은 막고 끌기는 목록 ScrollRect 로 올라감
var cc = L(kv, "card_center");
Center(ov, kv, "card_", z <= 0f ? 1f : z, new Vector2(At(cc, 0, 0.5f), 1f - At(cc, 1, 0.5f)), stageKey, cfg);
return ov;
}
/// <summary>가운데 묶음 = 자물쇠 → 글자 판(「개방 조건」 · 조건 문장) · 표 키 = pre + lock · plate · title · cond · lock_gap(stroke 공용) · 크기 × z.</summary>
static void Center(RectTransform ov, Dictionary<string, string> kv, string pre, float z, Vector2 anchor, string stageKey, BalanceConfig cfg)
{
var lk = L(kv, pre + "lock");
var pl = L(kv, pre + "plate");
var ti = L(kv, pre + "title");
var cd = L(kv, pre + "cond");
var sk = L(kv, "stroke");
var c = UiKit.Rect("Center", ov, anchor, new Vector2(0.5f, 0.5f), Vector2.zero, Vector2.zero);
var pc = Col(pl, 1, UiKit.Dark);
pc.a = At(pl, 2, 0.9f);
var plate = UiKit.Skin(UiKit.At(c, "Plate", 0f, 0f, 10f, 10f), Str(pl, 0, "card"), pc);
var sc = Col(sk, 0, UiKit.Stroke);
float sw = At(sk, 1, 3f) * Mathf.Min(1f, z);
var title = Txt(c, TitleName, UiText.T("lock_title"), Mathf.RoundToInt(At(ti, 0, 46f) * z), Col(ti, 1, UiKit.Coin), sc, sw);
var cond = Txt(c, CondName, Condition(stageKey, cfg), Mathf.RoundToInt(At(cd, 0, 34f) * z), Col(cd, 1, Color.white), sc, sw);
cond.horizontalOverflow = HorizontalWrapMode.Wrap;
// 크기 = 글자 폭(줄 폭 최대까지) · 조건 문장은 넘치면 줄바꿈
float tw = Mathf.Min(At(cd, 2, 880f) * z, Mathf.Ceil(Mathf.Max(title.preferredWidth, cond.preferredWidth)) + 4f);
cond.rectTransform.sizeDelta = new Vector2(tw, 10f);
float th = Mathf.Ceil(title.fontSize * 1.3f);
float ch = Mathf.Ceil(Mathf.Max(cond.preferredHeight, cond.fontSize * 1.3f));
float padX = At(pl, 3, 56f) * z, padY = At(pl, 4, 26f) * z, gapT = At(cd, 3, 10f) * z;
float pw = tw + 2f * padX, ph = 2f * padY + th + gapT + ch;
float isz = At(lk, 1, 210f) * z;
string lg;
kv.TryGetValue(pre + "lock_gap", out lg);
float gap = At(new[] { lg ?? "" }, 0, 14f) * z;
float W = Mathf.Max(pw, isz), H = isz + gap + ph;
c.sizeDelta = new Vector2(W, H);
var ic = UiKit.Icon(c, Str(lk, 0, "lock"), TopLeft, new Vector2(0.5f, 0.5f), new Vector2(W * 0.5f, -isz * 0.5f), isz);
if (ic != null)
{
ic.name = "Lock";
UiKit.DropShadow(ic, At(lk, 2, 4f) * z);
}
float py = isz + gap;
plate.rectTransform.anchoredPosition = new Vector2((W - pw) * 0.5f, -py);
plate.rectTransform.sizeDelta = new Vector2(pw, ph);
title.rectTransform.anchoredPosition = new Vector2((W - tw) * 0.5f, -(py + padY));
title.rectTransform.sizeDelta = new Vector2(tw, th);
cond.rectTransform.anchoredPosition = new Vector2((W - tw) * 0.5f, -(py + padY + th + gapT));
cond.rectTransform.sizeDelta = new Vector2(tw, ch);
}
static Text Txt(Transform p, string name, string s, int size, Color c, Color stroke, float sw)
{
var t = UiKit.Label(p, s, size, c, name == CondName ? TextAnchor.UpperCenter : TextAnchor.MiddleCenter, TopLeft, TopLeft, Vector2.zero, new Vector2(10f, 10f));
UISkin.UseTitle(t);
UISkin.Stroke(t, stroke, sw);
t.horizontalOverflow = HorizontalWrapMode.Overflow;
t.raycastTarget = false;
t.name = name;
return t;
}
}
}