2026-11-26 02:53:27 +00:00
using System.Collections.Generic ;
using System.Globalization ;
using UnityEngine ;
using UnityEngine.UI ;
namespace TKS.OutGame
{
/// <summary>
/// 영웅 아이콘 2종(PD 2026-11-26 「영웅 조각 = 직소 퍼즐 형태 · 완제품 영웅 아이콘은 조각과 차이가 있도록」 · 목업 선택 = 조각 SB안 · 완제품 HB안).
/// ① 조각(Shard) = 보상 칸(UiKit.ItemSlot · 색 = 태생 ★) 안에 얼굴 가득 + 칸 테두리를 얼굴 위에 다시 + 왼쪽 위 금빛 직소 배지(hi_shard_badge · 왼쪽 홈 없음) + 수량 칩.
/// ② 완제품(Badge) = 팔각 금테(hi_oct_frame) · ★색 바탕(hi_oct_fill × card_star<n>_bg + hi_oct_light × card_star<n>_glow) · 팔각으로 잘린 얼굴 · 왼쪽 위 진영 · 아래 별 받침.
/// 얼굴 = 영웅 그림 f000 의 머리 · 어깨 정사각(표 UI/HeroIcon/hero_icon_crop · Tools/hero_icon_crop.py) · 배치 값 = 표 UI/HeroIcon/hero_icon(C45).
/// 보상 줄에서는 아이콘 id 「hshard:<영웅 id>」 로 부른다(UiKit.RewardTile · UiKit.Icon 이 알아봄 · GoodsUi.Icon 이 영웅 조각에 붙임).
/// </summary>
public static class HeroIcons
{
public const string Table = "UI/HeroIcon/hero_icon" ;
public const string ShardPrefix = "hshard:" ;
static Dictionary < string , string > cfg ;
static Dictionary < string , float [ ] > crops ;
static HeroDb heroDb ;
static string Cfg ( string key )
{
if ( cfg = = null )
{
cfg = new Dictionary < string , string > ( ) ;
var rows = UiText . Rows ( Table ) ;
if ( rows = = null ) Debug . LogWarning ( "[TKS] 영웅 아이콘 표 없음: " + Table ) ;
else
foreach ( var r in rows )
{
string k , v ;
if ( r . TryGetValue ( "key" , out k ) & & k . Length > 0 & & r . TryGetValue ( "value" , out v ) ) cfg [ k ] = v ;
}
}
string s ;
return cfg . TryGetValue ( key , out s ) ? s : "" ;
}
/// <summary>표 값(기준 칸 px) × 지금 크기 ÷ 기준 칸.</summary>
static float V ( string key , float size )
{
float v , refSize ;
if ( ! float . TryParse ( Cfg ( key ) , NumberStyles . Float , CultureInfo . InvariantCulture , out v ) ) return 0f ;
if ( ! float . TryParse ( Cfg ( "ref" ) , NumberStyles . Float , CultureInfo . InvariantCulture , out refSize ) | | refSize < = 0f ) refSize = 132f ;
return v * size / refSize ;
}
/// <summary>얼굴 자리(그림 px · x · y · side · w · h) — 없으면 null(그림 위쪽 가운데로 대체).</summary>
public static float [ ] CropOf ( string art )
{
if ( crops = = null )
{
crops = new Dictionary < string , float [ ] > ( ) ;
var rows = UiText . Rows ( Cfg ( "crop_table" ) ) ;
if ( rows = = null ) Debug . LogWarning ( "[TKS] 영웅 얼굴 자리 표 없음: " + Cfg ( "crop_table" ) ) ;
else
foreach ( var r in rows )
{
string a ;
if ( ! r . TryGetValue ( "art" , out a ) | | a . Length = = 0 ) continue ;
var f = new float [ 5 ] ;
string [ ] keys = { "x" , "y" , "side" , "w" , "h" } ;
bool ok = true ;
for ( int i = 0 ; i < keys . Length & & ok ; i + + )
{
string s ;
ok = r . TryGetValue ( keys [ i ] , out s ) & & float . TryParse ( s , NumberStyles . Float , CultureInfo . InvariantCulture , out f [ i ] ) ;
}
if ( ok ) crops [ a ] = f ;
}
}
float [ ] c ;
return art ! = null & & crops . TryGetValue ( art , out c ) ? c : null ;
}
public static HeroDb . Hero Hero ( string id )
{
if ( heroDb = = null ) heroDb = Resources . Load < HeroDb > ( "OutGame/HeroDb" ) ;
return heroDb ! = null ? heroDb . Get ( id ) : null ;
}
/// <summary>보상 아이콘 id 가 영웅 조각이면 영웅(아니면 null).</summary>
public static HeroDb . Hero ShardHero ( string icon )
{
return ! string . IsNullOrEmpty ( icon ) & & icon . StartsWith ( ShardPrefix ) ? Hero ( icon . Substring ( ShardPrefix . Length ) ) : null ;
}
/// <summary>★ → 보상 칸 색 묶음(영웅 카드 = 1 녹 · 2 파랑 · 3 보라 · 4 주황 · 5 붉음 · PD 2026-11-19).</summary>
public static string SlotPrefix ( int star )
{
switch ( Mathf . Clamp ( star , 1 , 5 ) )
{
case 1 : return "gear_green_" ;
case 2 : return "gear_blue_" ;
case 3 : return "gear_purple_" ;
case 4 : return "gear_orange_" ;
}
return "grade_red_" ;
}
/// <summary>얼굴(box 를 꽉 채우는 머리 · 어깨 · box 에 RectMask2D 또는 Mask 가 있어야 밖이 잘림).</summary>
public static Image Face ( RectTransform box , HeroDb . Hero h , Vector2 boxSize )
{
2026-11-27 17:33:11 +00:00
return h ! = null ? FaceOfArt ( box , h . art , boxSize ) : null ;
}
/// <summary>그림 폴더(art) 로 얼굴 — 영웅이 아닌 적 보스도(표 hero_icon_crop 에 보스 그림 포함).</summary>
public static Image FaceOfArt ( RectTransform box , string art , Vector2 boxSize )
{
var sp = UiKit . ArtSprite ( art ) ;
2026-11-26 02:53:27 +00:00
if ( sp = = null ) return null ;
var rt = UiKit . Rect ( "Face" , box , new Vector2 ( 0f , 1f ) , new Vector2 ( 0f , 1f ) , new Vector2 ( 0f , 0f ) , Vector2 . zero ) ;
rt . pivot = new Vector2 ( 0f , 1f ) ;
var img = rt . gameObject . AddComponent < Image > ( ) ;
img . sprite = sp ;
img . raycastTarget = false ;
2026-11-27 17:33:11 +00:00
var c = CropOf ( art ) ;
2026-11-26 02:53:27 +00:00
float sw = sp . rect . width , sh = sp . rect . height ;
float x , y , side ;
if ( c ! = null )
{
float k = c [ 3 ] > 0f ? sw / c [ 3 ] : 1f ; // 표 그림 크기 ≠ 스프라이트 크기면 비율로
x = c [ 0 ] * k ;
y = c [ 1 ] * k ;
side = c [ 2 ] * k ;
}
else
{
side = sw * 0.75f ;
x = ( sw - side ) * 0.5f ;
y = 0f ;
}
float s = boxSize . x / Mathf . Max ( 1f , side ) ;
rt . sizeDelta = new Vector2 ( sw * s , sh * s ) ;
rt . anchoredPosition = new Vector2 ( - x * s , y * s ) ;
return img ;
}
/// <summary>
/// ① 영웅 조각(SB안) — cell(정사각 · 칸 크기 size) 안에 보상 칸 + 얼굴 + 칸 테두리 + 직소 배지 + 수량(qty 비면 없음).
/// 칸 색 = 태생 ★(조각은 영웅 종류의 것 · 보유 ★ 와 무관).
/// </summary>
public static void Shard ( RectTransform cell , HeroDb . Hero h , float size , string qty , bool lit = true )
{
int star = h ! = null ? Mathf . Max ( 1 , h . rarity ) : 1 ;
UiKit . ItemSlot ( cell , SlotPrefix ( star ) , lit ) ;
// 얼굴 = 칸 바탕(item_bg · 9 분할 둥근 모서리)과 같은 모양으로 자름 — 모서리 반경은 칸 크기와 무관하게 같아서 네모 자르기는 작은 칸(90 px)에서 모서리 밖으로 나옴(QA r2 B)
float clip = V ( "shard_clip" , size ) , inset = V ( "shard_inset" , size ) ;
var cm = UiKit . Fill ( "FaceClip" , cell , clip , clip , clip , clip ) ;
UiKit . Skin ( cm , "item_bg" , Color . white ) ;
cm . gameObject . AddComponent < Mask > ( ) . showMaskGraphic = false ;
float d = inset - clip ;
var box = UiKit . Fill ( "FaceBox" , cm , d , d , d , d ) ;
Face ( box , h , new Vector2 ( size - inset * 2f , size - inset * 2f ) ) ;
UiKit . Layer ( cell , "Border2" , "item_border" , UiKit . Col ( "gear_border" , UiKit . Line ) ) ; // 얼굴 위에 칸 테두리(모서리 덮기)
float bs = V ( "shard_badge" , size ) , bo = V ( "shard_badge_off" , size ) ;
var badge = UiKit . Icon ( cell , "hi_shard_badge" , new Vector2 ( 0f , 1f ) , new Vector2 ( 0f , 1f ) , new Vector2 ( bo , - bo ) , bs ) ;
if ( badge ! = null ) badge . raycastTarget = false ;
if ( ! string . IsNullOrEmpty ( qty ) ) UiKit . QtyChip ( cell , qty , size > = 120f ? 30 : 24 ) ;
}
2026-11-27 17:33:11 +00:00
/// <summary>칸 모양(item_bg 둥근 모서리)으로 자른 안쪽 상자 — 얼굴 · 스킬 그림이 칸 밖으로 나오지 않게(조각과 같은 방식).</summary>
static RectTransform ClipBox ( RectTransform cell , float size )
{
float clip = V ( "shard_clip" , size ) , inset = V ( "shard_inset" , size ) ;
var cm = UiKit . Fill ( "Clip" , cell , clip , clip , clip , clip ) ;
UiKit . Skin ( cm , "item_bg" , Color . white ) ;
cm . gameObject . AddComponent < Mask > ( ) . showMaskGraphic = false ;
float d = inset - clip ;
return UiKit . Fill ( "Box" , cm , d , d , d , d ) ;
}
/// <summary>
/// ③ 스테이지 팝업 보스 얼굴(PD 2026-11-26 「보스 스테이지 = 보스 정보」) — 보상 칸(색 = 표 boss_slot · 기본 붉음) + 그림 폴더 art 의 얼굴 + 칸 테두리 · 직소 배지 · 수량 없음.
/// </summary>
public static void Boss ( RectTransform cell , string art , float size , int star = 0 )
{
// 칸 색 = 그 보스가 영웅이면 태생 ★ 색(조각 칸과 같음 · PD 예시 = 장각 파랑) · 아니면 표 boss_slot(QA U2 · grade_red_ 는 장식 층 색이 없어 흰 칸으로 보임)
string pre = star > 0 ? SlotPrefix ( star ) : Cfg ( "boss_slot" ) ;
UiKit . ItemSlot ( cell , pre . Length > 0 ? pre : "gear_purple_" , true ) ;
float inset = V ( "shard_inset" , size ) ;
FaceOfArt ( ClipBox ( cell , size ) , art , new Vector2 ( size - inset * 2f , size - inset * 2f ) ) ;
UiKit . Layer ( cell , "Border2" , "item_border" , UiKit . Col ( "gear_border" , UiKit . Line ) ) ;
}
/// <summary>
/// ④ 스킬 칸(보스 스킬 · 누르면 툴팁은 호출 쪽) — 보상 칸(액티브 = 표 skill_slot_active · 패시브 = skill_slot_passive) + 스킬 그림(테마 skill_<id> · 영웅 정보 화면과 같은 그림) ·
/// 그림이 없는 스킬 = 병종 기호(영웅 정보 화면과 같은 대체).
/// </summary>
public static void SkillTile ( RectTransform cell , string skillId , bool active , UnitType type , float size )
{
string pre = Cfg ( active ? "skill_slot_active" : "skill_slot_passive" ) ;
UiKit . ItemSlot ( cell , pre . Length > 0 ? pre : active ? "gear_purple_" : "gear_orange_" , true ) ;
string iconId = "skill_" + skillId ;
bool has = UISkin . Theme ! = null & & UISkin . Theme . IconEntryOf ( iconId ) ! = null ;
var box = ClipBox ( cell , size ) ;
var ic = UiKit . Icon ( box , has ? iconId : UiKit . TypeSymbolId ( type ) , new Vector2 ( 0.5f , 0.5f ) , new Vector2 ( 0.5f , 0.5f ) , Vector2 . zero , has ? size - V ( "shard_inset" , size ) * 2f : size * 0.62f ) ;
if ( ic ! = null ) ic . raycastTarget = false ;
UiKit . Layer ( cell , "Border2" , "item_border" , UiKit . Col ( "gear_border" , UiKit . Line ) ) ;
}
2026-11-26 02:53:27 +00:00
/// <summary>
/// ② 완제품 영웅(HB안) — 왼쪽 위 (x, y) 정사각 size · star = 보유 ★(없으면 태생 ★) · 팔각 금테 + ★색 바탕 + 얼굴 + 진영 + 별 받침.
/// </summary>
public static RectTransform Badge ( Transform p , string name , float x , float y , float size , HeroDb . Hero h , int star )
{
if ( star < = 0 ) star = h ! = null ? Mathf . Max ( 1 , h . rarity ) : 1 ;
star = Mathf . Clamp ( star , 1 , 5 ) ;
var root = UiKit . At ( p , name , x , y , size , size ) ;
var fill = UiKit . Fill ( "Fill" , root ) ;
var fi = fill . gameObject . AddComponent < Image > ( ) ;
fi . sprite = UISkin . Icon ( "hi_oct_fill" ) ;
fi . color = UiKit . Col ( "card_star" + star + "_bg" , UiKit . Purple ) ;
fi . raycastTarget = false ;
var light = UiKit . Fill ( "Light" , root ) . gameObject . AddComponent < Image > ( ) ;
light . sprite = UISkin . Icon ( "hi_oct_light" ) ;
light . color = UiKit . Col ( "card_star" + star + "_glow" , Color . white ) ;
light . raycastTarget = false ;
// 얼굴 = 팔각 마스크(hi_oct_fill 모양 · 마스크 그림은 그리지 않음)
float inset = V ( "oct_inset" , size ) ;
var mrt = UiKit . Fill ( "FaceMask" , root ) ;
var mimg = mrt . gameObject . AddComponent < Image > ( ) ;
mimg . sprite = UISkin . Icon ( "hi_oct_fill" ) ;
mimg . raycastTarget = false ;
mrt . gameObject . AddComponent < Mask > ( ) . showMaskGraphic = false ;
var box = UiKit . Fill ( "FaceBox" , mrt , inset , inset , inset , inset ) ;
Face ( box , h , new Vector2 ( size - inset * 2f , size - inset * 2f ) ) ;
var frame = UiKit . Fill ( "Frame" , root ) . gameObject . AddComponent < Image > ( ) ;
frame . sprite = UISkin . Icon ( "hi_oct_frame" ) ;
frame . raycastTarget = false ;
// 왼쪽 위 진영
float fd = V ( "oct_faction" , size ) , fo = V ( "oct_faction_off" , size ) ;
if ( h ! = null ) UiKit . DropShadow ( UiKit . FactionBadge ( root , h . faction , new Vector2 ( 0f , 1f ) , new Vector2 ( 0f , 1f ) , new Vector2 ( fo , - fo ) , fd ) , 2f ) ;
// 아래 별 받침
float ss = V ( "oct_star" , size ) , gap = V ( "oct_star_gap" , size ) , bh = V ( "oct_band_h" , size ) ;
float bw = star * ss + ( star - 1 ) * gap + bh * 0.5f ;
var band = UiKit . Rect ( "Stars" , root , new Vector2 ( 0.5f , 0f ) , new Vector2 ( 0.5f , 1f ) , new Vector2 ( 0f , V ( "oct_band_y" , size ) ) , new Vector2 ( bw , bh ) ) ;
UiKit . Skin ( band , "chip" , UiKit . Col ( "chip_dark" , UiKit . Dark ) ) ;
for ( int i = 0 ; i < star ; i + + )
{
var st = UiKit . Icon ( band , "star_on" , new Vector2 ( 0.5f , 0.5f ) , new Vector2 ( 0.5f , 0.5f ) , new Vector2 ( ( i - ( star - 1 ) * 0.5f ) * ( ss + gap ) , 1f ) , ss ) ;
if ( st ! = null ) st . raycastTarget = false ;
}
return root ;
}
}
}