EerieVillage/Assets/Scripts/MyUI/SkillSelectionUI.cs

124 lines
4.9 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;
using TMPro;
using EerieVillage.Skills;
namespace EerieVillage.MyUI
{
/// <summary>
/// BT12-MVP-A 영역 스킬 선택 UI — PD 첨부 예시 ("기술 선택" 화면) 정합.
/// LevelUpManager 영역 호출 — Show(cards, level, onConfirm).
///
/// Phase 2-D 정정 (2026-05-09) — SkillCardPlaceholder → ActiveSkillData 전환.
///
/// 화면 구조:
/// [Header] "기술 선택" 타이틀 + X 닫기 버튼
/// [Body] 카드 3장 가로 배치 (SkillCardSlot ×3)
/// [Footer] "남은 포인트: N" + "확인" 버튼
///
/// 인터랙션:
/// - 카드 클릭 → 선택 (highlight)
/// - 확인 버튼 → onConfirm 콜백 + UI 닫기
/// - X 버튼 → 첫 카드 자동 선택 + 콜백 (취소 영역 placeholder)
/// </summary>
public class SkillSelectionUI : MonoBehaviour
{
[Header("Root")]
[SerializeField] GameObject _rootPanel; // 일시정지 시 활성·복귀 시 비활성
[Header("Header")]
[SerializeField] TMP_Text _titleText; // "기술 선택"
[SerializeField] Button _closeButton; // X 버튼 (우측 상단)
[Header("Card Slots (3개 가로 배치)")]
[SerializeField] SkillCardSlot _slot1;
[SerializeField] SkillCardSlot _slot2;
[SerializeField] SkillCardSlot _slot3;
[Header("Footer")]
[SerializeField] TMP_Text _pointText; // "남은 포인트: N"
[SerializeField] Button _confirmButton; // "확인"
ActiveSkillData _selected;
System.Action<ActiveSkillData> _onConfirm;
void Awake()
{
Debug.Log($"[SkillSelectionUI] Awake — _rootPanel={(_rootPanel == null ? "NULL" : _rootPanel.name)}");
// BT12-MVP-A 정정 (2026-05-08) — Canvas 자체 비활성 (SkillSelectionCanvas Sort Order 200 영역 화면 가림 차단)
if (_rootPanel != null) _rootPanel.SetActive(false);
gameObject.SetActive(false); // Canvas root 자체 비활성
}
/// <summary>레벨업 시점 호출 — 카드 3장 표시 + 사용자 선택 대기.</summary>
public void Show(List<ActiveSkillData> cards, int level, System.Action<ActiveSkillData> onConfirm)
{
Debug.Log($"[SkillSelectionUI] Show 호출 cards={cards.Count} level={level}");
_onConfirm = onConfirm;
_selected = null;
gameObject.SetActive(true); // BT12-MVP-A 정정 — Canvas root 활성
if (_rootPanel != null) _rootPanel.SetActive(true);
if (_titleText != null) _titleText.text = "기술 선택";
if (_pointText != null) _pointText.text = "남은 포인트: 1";
if (_confirmButton != null) _confirmButton.interactable = false;
// 카드 3장 영역 바인딩 (부족 영역 = 슬롯 hide)
BindSlot(_slot1, cards.Count > 0 ? cards[0] : null);
BindSlot(_slot2, cards.Count > 1 ? cards[1] : null);
BindSlot(_slot3, cards.Count > 2 ? cards[2] : null);
// 버튼 영역 리스너
if (_confirmButton != null)
{
_confirmButton.onClick.RemoveAllListeners();
_confirmButton.onClick.AddListener(OnConfirmClicked);
}
if (_closeButton != null)
{
_closeButton.onClick.RemoveAllListeners();
_closeButton.onClick.AddListener(OnCloseClicked);
}
}
public void Hide()
{
if (_rootPanel != null) _rootPanel.SetActive(false);
gameObject.SetActive(false); // BT12-MVP-A 정정 — Canvas root 비활성
}
void BindSlot(SkillCardSlot slot, ActiveSkillData card)
{
if (slot == null) return;
slot.Bind(card, () => OnCardSelected(slot, card));
}
void OnCardSelected(SkillCardSlot clickedSlot, ActiveSkillData card)
{
if (card == null) return;
_selected = card;
if (_confirmButton != null) _confirmButton.interactable = true;
// 다른 슬롯 영역 highlight 해제 + 선택 슬롯만 활성
if (_slot1 != null) _slot1.SetHighlight(_slot1 == clickedSlot);
if (_slot2 != null) _slot2.SetHighlight(_slot2 == clickedSlot);
if (_slot3 != null) _slot3.SetHighlight(_slot3 == clickedSlot);
}
void OnConfirmClicked()
{
if (_selected == null) return;
var sel = _selected;
_onConfirm?.Invoke(sel);
}
void OnCloseClicked()
{
// 취소 영역 = 첫 카드 자동 확정 (BT12-MVP-A 영역 placeholder · 차기 영역 PD 결정 영역)
var fallback = _slot1 != null ? _slot1.Card : null;
_onConfirm?.Invoke(fallback);
}
}
}