using System.Collections.Generic; using UnityEngine; using UnityEngine.UIElements; public class TownShopUI : MonoBehaviour { [Header("References")] public UIDocument uiDocument; [Header("Shop Settings")] public TownShop currentShop; public TeamCharacter selectedCustomer; // UI Elements private VisualElement root; private VisualElement shopContainer; private Label shopNameLabel; private Label shopkeeperLabel; private VisualElement itemList; private VisualElement customerPanel; private DropdownField customerDropdown; private Label moneyLabel; private VisualElement tabContainer; private Button buyTab; private Button sellTab; private DropdownField categoryFilter; private TextField searchField; private Button closeButton; // State private bool isSellMode = false; private void Start() { InitializeUI(); SetupEventHandlers(); // Try to load team from GameStateManager if (GameStateManager.Instance?.savedTeam != null) { foreach (var character in GameStateManager.Instance.savedTeam) { if (character != null) { selectedCustomer = character; UpdateCustomerDisplay(); break; } } } } public void SetShop(TownShop shop) { Debug.Log($"=== TownShopUI.SetShop DEBUG ==="); Debug.Log($"Received shop: {shop?.buildingName ?? "NULL"} ({shop?.shopType})"); Debug.Log($"Shop keeper: {shop?.shopkeeperName ?? "NULL"}"); Debug.Log($"Current shop before: {currentShop?.buildingName ?? "NULL"}"); currentShop = shop; Debug.Log($"Current shop after: {currentShop?.buildingName ?? "NULL"}"); if (root != null) { UpdateShopDisplay(); RefreshItemList(); } } public void SetCustomer(TeamCharacter customer) { selectedCustomer = customer; UpdateCustomerDisplay(); RefreshItemList(); } private void InitializeUI() { if (uiDocument == null) { uiDocument = GetComponent(); } if (uiDocument?.rootVisualElement == null) { Debug.LogError("UI Document or root visual element is null!"); return; } // Force refresh the UI Document to ensure proper initialization uiDocument.enabled = false; uiDocument.enabled = true; root = uiDocument.rootVisualElement; Debug.Log($"Root element found: {root != null}"); // Ensure root element is visible and properly configured if (root != null) { root.style.position = Position.Absolute; root.style.left = 0; root.style.top = 0; root.style.right = 0; root.style.bottom = 0; root.style.visibility = Visibility.Visible; root.style.display = DisplayStyle.Flex; Debug.Log("Root element visibility and position configured"); } // Get UI elements shopContainer = root.Q("shop-container"); shopNameLabel = root.Q