using UnityEngine; using UnityEngine.UI; using System.Collections.Generic; using TMPro; using System; /// /// UI for selecting spells to cast in battle /// public class SpellSelectionUI : MonoBehaviour { [Header("UI References")] public Canvas selectionCanvas; public Transform spellListContainer; public GameObject spellButtonPrefab; public Button cancelButton; public TextMeshProUGUI titleText; [Header("Settings")] public int maxSpellsToShow = 6; private Character currentCharacter; private List spellButtons = new List(); // Events public event Action OnSpellSelected; public event Action OnSelectionCancelled; void Awake() { if (selectionCanvas == null) selectionCanvas = GetComponentInChildren(); SetVisible(false); } void Start() { if (cancelButton != null) { cancelButton.onClick.AddListener(() => { OnSelectionCancelled?.Invoke(); HideSelection(); }); } } void Update() { if (selectionCanvas.gameObject.activeInHierarchy) { if (Input.GetKeyDown(KeyCode.Escape)) { OnSelectionCancelled?.Invoke(); HideSelection(); } } } public void ShowSpellSelection(Character character) { currentCharacter = character; if (titleText != null) titleText.text = $"{character.CharacterName} - Select Spell"; PopulateSpellList(); SetVisible(true); Debug.Log($"✨ Spell selection shown for {character.CharacterName}"); } public void HideSelection() { SetVisible(false); ClearSpellList(); currentCharacter = null; Debug.Log("✨ Spell selection hidden"); } private void PopulateSpellList() { ClearSpellList(); var spells = GetCharacterSpells(); for (int i = 0; i < spells.Count && i < maxSpellsToShow; i++) { CreateSpellButton(spells[i], i); } } private List GetCharacterSpells() { // Placeholder implementation - return sample spells // TODO: Get actual spells from character's spell list/class abilities return new List { new SpellData { name = "Magic Missile", description = "Deals 15 magic damage to target", manaCost = 5, requiresTarget = true, isAoE = false, icon = null }, new SpellData { name = "Heal", description = "Restores 25 HP to target", manaCost = 8, requiresTarget = true, isAoE = false, icon = null }, new SpellData { name = "Fireball", description = "Explosive fire damage in area", manaCost = 12, requiresTarget = true, isAoE = true, icon = null }, new SpellData { name = "Shield", description = "Increases AC by 2 for 5 turns", manaCost = 6, requiresTarget = false, isAoE = false, icon = null }, new SpellData { name = "Lightning Bolt", description = "Chain lightning hits multiple enemies", manaCost = 10, requiresTarget = true, isAoE = true, icon = null }, new SpellData { name = "Cure Disease", description = "Removes negative effects", manaCost = 7, requiresTarget = true, isAoE = false, icon = null } }; } private void CreateSpellButton(SpellData spell, int index) { GameObject buttonObj = Instantiate(spellButtonPrefab, spellListContainer); // Get or create components Button button = buttonObj.GetComponent