using System.Collections.Generic; using UnityEngine; using UnityEngine.UIElements; public class SimpleShopManager : MonoBehaviour { [Header("Shop Settings")] public string shopName = "General Store"; [Header("Available Items (Simple Version)")] public List weapons = new List(); public List armor = new List(); public List miscItems = new List(); private UIDocument uiDocument; private TeamCharacter currentCustomer; // Callback for when character data changes public System.Action OnCharacterDataChanged; // UI Elements private VisualElement shopContainer; private TextField searchField; private DropdownField categoryFilter; private ScrollView itemList; private Label shopTitle; private Label playerMoney; private Button closeButton; // Current filter state private string currentCategory = "All"; private string currentSearchTerm = ""; void Awake() { // Initialize default items first InitializeDefaultItems(); } void Start() { // Initialize UI in Start() to ensure UIDocument is ready uiDocument = GetComponent(); if (uiDocument == null) { Debug.LogError("SimpleShopManager requires a UIDocument component"); return; } if (uiDocument.visualTreeAsset == null) { Debug.LogError("SimpleShopManager: UIDocument needs a Visual Tree Asset assigned! Please assign ShopUI.uxml"); return; } InitializeUI(); } void InitializeDefaultItems() { // Initialize with some default items if lists are empty if (weapons.Count == 0) { weapons.Add(new SimpleShopItem("Simple Sword", "A basic sword for beginners.", ShopItemType.Weapon, 10, 0, 0, "sword,melee,blade,basic", new ItemStats { damageBonus = 1 })); weapons.Add(new SimpleShopItem("Simple Bow", "A basic bow for shooting arrows.", ShopItemType.Weapon, 15, 0, 0, "bow,ranged,arrow,basic", new ItemStats { damageBonus = 1 })); weapons.Add(new SimpleShopItem("Iron Sword", "A well-crafted iron sword.", ShopItemType.Weapon, 25, 0, 0, "sword,melee,blade,iron", new ItemStats { damageBonus = 2 })); weapons.Add(new SimpleShopItem("Composite Bow", "A bow made of multiple materials.", ShopItemType.Weapon, 35, 0, 0, "bow,ranged,arrow,composite", new ItemStats { damageBonus = 2 })); } if (armor.Count == 0) { armor.Add(new SimpleShopItem("Leather Helmet", "Basic head protection.", ShopItemType.Armor, 5, 0, 0, "helmet,head,leather,light")); armor.Add(new SimpleShopItem("Leather Vest", "Simple chest protection.", ShopItemType.Armor, 12, 0, 0, "vest,chest,leather,light", new ItemStats { acBonus = 1 })); armor.Add(new SimpleShopItem("Iron Chainmail", "Chainmail made of iron rings.", ShopItemType.Armor, 30, 0, 0, "chainmail,chest,iron,medium", new ItemStats { acBonus = 2 })); } if (miscItems.Count == 0) { miscItems.Add(new SimpleShopItem("Health Potion", "Restores 15 health points.", ShopItemType.Miscellaneous, 3, 0, 0, "potion,health,healing,consumable", new ItemStats { healthBonus = 15 })); miscItems.Add(new SimpleShopItem("Hemp Rope", "50 feet of sturdy rope.", ShopItemType.Miscellaneous, 0, 8, 0, "rope,hemp,utility,tool")); miscItems.Add(new SimpleShopItem("Torch", "Provides light in dark places.", ShopItemType.Miscellaneous, 0, 2, 0, "torch,light,utility")); } } void InitializeUI() { var root = uiDocument.rootVisualElement; Debug.Log("SimpleShopManager: Initializing UI elements..."); shopContainer = root.Q("ShopContainer"); searchField = root.Q("SearchField"); categoryFilter = root.Q("CategoryFilter"); itemList = root.Q("ItemList"); shopTitle = root.Q