瀏覽代碼

Shop working

Axel Nordh 8 月之前
父節點
當前提交
f25e916eb7

+ 1 - 0
Assets/Scripts/Events/TravelEvent.cs

@@ -164,6 +164,7 @@ public class EventResult
     public bool shouldStopTravel = false;
     public bool startBattle = false;
     public bool openTrading = false;
+    public bool suppressMessage = false; // Skip showing event message (used when popup handles display)
     public string resultMessage = "";
 
     // Resource changes

+ 10 - 7
Assets/Scripts/Events/TravelEventSystem.cs

@@ -250,14 +250,17 @@ public class TravelEventSystem : MonoBehaviour
         // Record the event
         globalEventHistory.RecordEvent(travelEvent, context);
 
-        // Display event message
-        if (eventUI != null)
-        {
-            eventUI.ShowEventResult(result);
-        }
-        else
+        // Display event message (unless suppressed by popup system)
+        if (!result.suppressMessage)
         {
-            ShowEventMessage(result.resultMessage);
+            if (eventUI != null)
+            {
+                eventUI.ShowEventResult(result);
+            }
+            else
+            {
+                ShowEventMessage(result.resultMessage);
+            }
         }
 
         // Handle the event result

+ 1 - 0
Assets/Scripts/Events/TravelEventTypes.cs

@@ -111,6 +111,7 @@ public class CombatTravelEvent : TravelEvent
                 {
                     shouldStopTravel = true, // Stop travel while popup is showing
                     startBattle = false, // Don't start battle yet - popup will handle it
+                    suppressMessage = true, // Don't show default message - popup handles display
                     eventOccurred = true
                 };
             }

+ 21 - 2
Assets/Scripts/Map/TravelUIController.cs

@@ -139,6 +139,16 @@ public class TravelUIController : MonoBehaviour
         if (travelContainer == null) return;
 
         travelContainer.style.display = DisplayStyle.Flex;
+
+        // Ensure the travel container blocks mouse clicks
+        travelContainer.pickingMode = PickingMode.Position;
+
+        // Add background overlay to block clicks if travel panel exists
+        if (travelPanel != null)
+        {
+            travelPanel.pickingMode = PickingMode.Position;
+        }
+
         isUIVisible = true;
 
         // Update UI with current travel information
@@ -146,7 +156,7 @@ public class TravelUIController : MonoBehaviour
 
         if (showDebugLogs)
         {
-
+            Debug.Log("✈️ Travel UI shown - map clicks should be blocked");
         }
     }
 
@@ -158,11 +168,20 @@ public class TravelUIController : MonoBehaviour
         if (travelContainer == null) return;
 
         travelContainer.style.display = DisplayStyle.None;
+
+        // Reset picking mode to allow map clicks
+        travelContainer.pickingMode = PickingMode.Ignore;
+
+        if (travelPanel != null)
+        {
+            travelPanel.pickingMode = PickingMode.Ignore;
+        }
+
         isUIVisible = false;
 
         if (showDebugLogs)
         {
-
+            Debug.Log("✈️ Travel UI hidden - map clicks should be enabled");
         }
     }
 

+ 91 - 6
Assets/Scripts/UI/ItemShopManager.cs

@@ -52,6 +52,9 @@ public class ItemShopManager : MonoBehaviour
             return;
         }
 
+        // Ensure panel settings and proper sorting order are set
+        EnsurePanelSettings();
+
         InitializeUI();
     }
 
@@ -518,13 +521,53 @@ public class ItemShopManager : MonoBehaviour
 
     private void AddItemToCustomerInventory(Item item)
     {
-        // This method needs to be implemented based on your inventory system
-        // For now, let's just log what would happen
-        Debug.Log($"Would add {item.itemName} to {currentCustomer.name}'s inventory");
+        if (currentCustomer == null) return;
+
+        // Initialize lists if they're null
+        if (currentCustomer.weapons == null)
+            currentCustomer.weapons = new System.Collections.Generic.List<string>();
+        if (currentCustomer.armor == null)
+            currentCustomer.armor = new System.Collections.Generic.List<string>();
+        if (currentCustomer.miscItems == null)
+            currentCustomer.miscItems = new System.Collections.Generic.List<string>();
+
+        // Add item to appropriate inventory list based on type
+        switch (item.itemType)
+        {
+            case ItemType.Weapon:
+                currentCustomer.weapons.Add(item.itemName);
+                Debug.Log($"Added weapon '{item.itemName}' to {currentCustomer.name}'s weapon inventory");
+                break;
+
+            case ItemType.Armor:
+                currentCustomer.armor.Add(item.itemName);
+                Debug.Log($"Added armor '{item.itemName}' to {currentCustomer.name}'s armor inventory");
+                break;
+
+            case ItemType.Miscellaneous:
+            case ItemType.Consumable:
+            case ItemType.Tool:
+            case ItemType.Accessory:
+                currentCustomer.miscItems.Add(item.itemName);
+                Debug.Log($"Added item '{item.itemName}' to {currentCustomer.name}'s misc inventory");
+                break;
+
+            default:
+                currentCustomer.miscItems.Add(item.itemName);
+                Debug.LogWarning($"Unknown item type for '{item.itemName}', added to misc items");
+                break;
+        }
+
+        // Trigger UI update in MainTeamSelectScript if available
+        TriggerInventoryUIUpdate();
+    }
 
-        // If you have an inventory system, add the item here
-        // For example:
-        // currentCustomer.inventory.AddItem(item);
+    private void TriggerInventoryUIUpdate()
+    {
+        // The OnCharacterDataChanged event is already invoked in PurchaseItem()
+        // This should trigger any listeners to update their UI
+        // MainTeamSelectScript should listen to this event to refresh inventory displays
+        Debug.Log("Character inventory updated - OnCharacterDataChanged event will be triggered");
     }
 
     private void UpdatePlayerMoney()
@@ -696,4 +739,46 @@ public class ItemShopManager : MonoBehaviour
         Debug.Log("Opening shop with test character...");
         OpenShop(testCharacter);
     }
+
+    void EnsurePanelSettings()
+    {
+        if (uiDocument.panelSettings == null || uiDocument.sortingOrder <= 2)
+        {
+            // Try to find and reuse existing panel settings from other UI
+            var existingUI = GameObject.Find("TravelUI")?.GetComponent<UIDocument>();
+            if (existingUI?.panelSettings != null)
+            {
+                uiDocument.panelSettings = existingUI.panelSettings;
+                Debug.Log("✓ ItemShopManager: Panel Settings assigned from TravelUI");
+            }
+            else
+            {
+                // Try to find from MainTeamSelectScript or other UI components
+                var mainTeamSelect = FindFirstObjectByType<MainTeamSelectScript>();
+                if (mainTeamSelect != null)
+                {
+                    var mainUIDoc = mainTeamSelect.GetComponent<UIDocument>();
+                    if (mainUIDoc?.panelSettings != null)
+                    {
+                        uiDocument.panelSettings = mainUIDoc.panelSettings;
+                        Debug.Log("✓ ItemShopManager: Panel Settings assigned from MainTeamSelectScript");
+                    }
+                }
+            }
+
+            // Set proper sorting order (> 2 as requested)
+            uiDocument.sortingOrder = 5; // Higher than 2 to ensure shop displays on top
+
+            if (uiDocument.panelSettings != null)
+            {
+                // Make sure panel settings also have a high sorting order
+                uiDocument.panelSettings.sortingOrder = 5;
+                Debug.Log($"✓ ItemShopManager: Sorting order set to {uiDocument.sortingOrder}");
+            }
+            else
+            {
+                Debug.LogWarning("⚠ ItemShopManager: Could not assign Panel Settings. Shop may not display properly.");
+            }
+        }
+    }
 }

+ 70 - 1
Assets/Scripts/UI/QuickShopSetup.cs

@@ -84,6 +84,19 @@ public class QuickShopSetup : MonoBehaviour
         ItemShopManager newShop = shopObject.AddComponent<ItemShopManager>();
         newShop.shopName = shopName;
 
+        // Set up UIDocument with proper panel settings
+        UIDocument uiDoc = shopObject.GetComponent<UIDocument>();
+        if (uiDoc == null)
+        {
+            uiDoc = shopObject.AddComponent<UIDocument>();
+        }
+
+        // Assign ShopUI.uxml
+        AssignShopUIXML(uiDoc);
+
+        // Set up panel settings
+        SetupPanelSettings(uiDoc);
+
         Debug.Log("✓ Converted SimpleShopManager to ItemShopManager on: " + shopObject.name);
     }
 
@@ -98,13 +111,15 @@ public class QuickShopSetup : MonoBehaviour
         // Assign ShopUI.uxml
         AssignShopUIXML(uiDoc);
 
+        // Assign Panel Settings and set proper sorting order
+        SetupPanelSettings(uiDoc);
+
         // Add ItemShopManager
         ItemShopManager shopManager = shopObject.AddComponent<ItemShopManager>();
         shopManager.shopName = "General Store";
 
         Debug.Log("✓ Created new shop system on: " + shopObject.name);
     }
-
     void AssignShopUIXML(UIDocument uiDoc)
     {
         // Try multiple paths to find ShopUI.uxml
@@ -154,6 +169,60 @@ public class QuickShopSetup : MonoBehaviour
         }
     }
 
+    void SetupPanelSettings(UIDocument uiDoc)
+    {
+        // First try to find and reuse existing panel settings from other UI
+        var existingUI = GameObject.Find("TravelUI")?.GetComponent<UIDocument>();
+        if (existingUI?.panelSettings != null)
+        {
+            uiDoc.panelSettings = existingUI.panelSettings;
+            Debug.Log("✓ Panel Settings assigned from TravelUI");
+        }
+        else
+        {
+            // Try to find from MainTeamSelectScript or other UI components
+            var mainTeamSelect = FindFirstObjectByType<MainTeamSelectScript>();
+            if (mainTeamSelect != null)
+            {
+                var mainUIDoc = mainTeamSelect.GetComponent<UIDocument>();
+                if (mainUIDoc?.panelSettings != null)
+                {
+                    uiDoc.panelSettings = mainUIDoc.panelSettings;
+                    Debug.Log("✓ Panel Settings assigned from MainTeamSelectScript");
+                }
+            }
+        }
+
+        // If still no panel settings, try to find any PanelSettings asset
+        if (uiDoc.panelSettings == null)
+        {
+#if UNITY_EDITOR
+            var panelSettingsGuids = UnityEditor.AssetDatabase.FindAssets("t:PanelSettings");
+            if (panelSettingsGuids.Length > 0)
+            {
+                var path = UnityEditor.AssetDatabase.GUIDToAssetPath(panelSettingsGuids[0]);
+                var settings = UnityEditor.AssetDatabase.LoadAssetAtPath<UnityEngine.UIElements.PanelSettings>(path);
+                uiDoc.panelSettings = settings;
+                Debug.Log($"✓ Panel Settings auto-assigned: {settings.name}");
+            }
+#endif
+        }
+
+        // Set proper sorting order (> 2 as requested)
+        uiDoc.sortingOrder = 5; // Higher than 2 to ensure shop displays on top
+
+        if (uiDoc.panelSettings != null)
+        {
+            // Make sure panel settings also have a high sorting order
+            uiDoc.panelSettings.sortingOrder = 5;
+            Debug.Log($"✓ Shop UI sorting order set to {uiDoc.sortingOrder}");
+        }
+        else
+        {
+            Debug.LogWarning("⚠ Could not assign Panel Settings. You may need to assign it manually.");
+        }
+    }
+
     [ContextMenu("Create Sample Items")]
     public void CreateSampleItems()
     {

+ 64 - 0
Assets/Scripts/UI/ShopSystemSetup.cs

@@ -1,5 +1,8 @@
 using UnityEngine;
 using UnityEngine.UIElements;
+#if UNITY_EDITOR
+using UnityEditor;
+#endif
 
 /// <summary>
 /// Helper component to ensure the shop system is properly configured
@@ -132,6 +135,67 @@ public class ShopSystemSetup : MonoBehaviour
                 Debug.LogWarning("Could not find ShopUI.uxml. Please assign it manually to the UIDocument component.");
             }
         }
+
+        // Set up panel settings with proper sorting order
+        SetupPanelSettings(uiDocument);
+    }
+
+    void SetupPanelSettings(UIDocument uiDoc)
+    {
+        // First try to find and reuse existing panel settings from other UI
+        var existingUI = GameObject.Find("TravelUI")?.GetComponent<UIDocument>();
+        if (existingUI?.panelSettings != null)
+        {
+            uiDoc.panelSettings = existingUI.panelSettings;
+            if (enableDebugLogging)
+                Debug.Log("✓ Panel Settings assigned from TravelUI");
+        }
+        else
+        {
+            // Try to find from MainTeamSelectScript or other UI components
+            var mainTeamSelect = FindFirstObjectByType<MainTeamSelectScript>();
+            if (mainTeamSelect != null)
+            {
+                var mainUIDoc = mainTeamSelect.GetComponent<UIDocument>();
+                if (mainUIDoc?.panelSettings != null)
+                {
+                    uiDoc.panelSettings = mainUIDoc.panelSettings;
+                    if (enableDebugLogging)
+                        Debug.Log("✓ Panel Settings assigned from MainTeamSelectScript");
+                }
+            }
+        }
+
+        // If still no panel settings, try to find any PanelSettings asset
+        if (uiDoc.panelSettings == null)
+        {
+#if UNITY_EDITOR
+            var panelSettingsGuids = UnityEditor.AssetDatabase.FindAssets("t:PanelSettings");
+            if (panelSettingsGuids.Length > 0)
+            {
+                var path = UnityEditor.AssetDatabase.GUIDToAssetPath(panelSettingsGuids[0]);
+                var settings = UnityEditor.AssetDatabase.LoadAssetAtPath<UnityEngine.UIElements.PanelSettings>(path);
+                uiDoc.panelSettings = settings;
+                if (enableDebugLogging)
+                    Debug.Log($"✓ Panel Settings auto-assigned: {settings.name}");
+            }
+#endif
+        }
+
+        // Set proper sorting order (> 2 as requested)
+        uiDoc.sortingOrder = 5; // Higher than 2 to ensure shop displays on top
+
+        if (uiDoc.panelSettings != null)
+        {
+            // Make sure panel settings also have a high sorting order
+            uiDoc.panelSettings.sortingOrder = 5;
+            if (enableDebugLogging)
+                Debug.Log($"✓ Shop UI sorting order set to {uiDoc.sortingOrder}");
+        }
+        else
+        {
+            Debug.LogWarning("⚠ Could not assign Panel Settings. You may need to assign it manually.");
+        }
     }
 
     void VerifyItems()

+ 2 - 2
UserSettings/EditorUserSettings.asset

@@ -24,10 +24,10 @@ EditorUserSettings:
       value: 5a090503000558580f0d557342700844144f4d7c7b7d74692c281e63b0e2623c
       flags: 0
     RecentlyUsedSceneGuid-5:
-      value: 51020c5550545a0354575e7b47270744174e4b787e2b77687b7e1b37e7e4366d
+      value: 510500025d560a0c095d092111730d44464f4b78757b72357a701c31b7b16368
       flags: 0
     RecentlyUsedSceneGuid-6:
-      value: 510500025d560a0c095d092111730d44464f4b78757b72357a701c31b7b16368
+      value: 51020c5550545a0354575e7b47270744174e4b787e2b77687b7e1b37e7e4366d
       flags: 0
     vcSharedLogLevel:
       value: 0d5e400f0650