using UnityEngine; using UnityEngine.UIElements; using System.Collections.Generic; using System.Collections; using Unity.VisualScripting; using System; public class ActiveQuestUI : MonoBehaviour, IClickBlocker { [Header("UI References")] public UIDocument uiDocument; // Main UI elements private VisualElement questTracker; private Label trackerTitle; private Button questLogButton; private Button toggleTrackerButton; private ScrollView activeQuestsList; private Label noQuestsMessage; private VisualElement quickActions; private Button showAllButton; private Button trackLocationButton; private Button abandonQuestButton; // Popup elements private VisualElement questDetailsPopup; private VisualElement popupContent; private Label popupTitle; private Button closePopupButton; private VisualElement popupDetails; private VisualElement questInfo; private VisualElement objectivesList; private VisualElement rewardsList; private VisualElement popupActions; private Button trackButton; private Button navigateButton; // Notification elements private VisualElement completionNotification; private VisualElement progressNotification; // Exposed flag other systems can check to know UI is capturing pointer // State private ActiveQuest selectedQuest; private bool isUIVisible = false; private List questEntries = new List(); [System.NonSerialized] private bool recentlyHandledClick = false; // Flag to prevent map clicks when UI handles them public bool IsVisible => isUIVisible; public bool IsBlockingClick(Vector2 screenPosition) { // Primary method: Check if we recently handled a UI click if (recentlyHandledClick) { Debug.Log("🚫 ActiveQuestUI: Blocking click due to recent UI interaction"); return true; } // If UI is not visible, don't block anything if (!isUIVisible) { return false; } // Dynamic coordinate-based approach: Block clicks in the quest tracker area // This needs to account for the expanded quest panel when it shows more options float questPanelWidth = 320f; // Approximate width of quest panel float questPanelHeight = 250f; // Larger height to cover expanded panel (was 120f) float questPanelX = 20f; // Left edge float questPanelY = Screen.height - questPanelHeight - 20f; // Top edge (converted to screen coords) // Alternative: Try to get actual bounds from the quest tracker if available if (questTracker != null) { try { // Try to use the actual UI element bounds if possible var bounds = questTracker.worldBound; if (bounds.width > 0 && bounds.height > 0) { // Convert UI bounds to screen coordinates questPanelX = bounds.x; questPanelY = Screen.height - bounds.y - bounds.height; questPanelWidth = bounds.width; questPanelHeight = bounds.height; Debug.Log($"🔍 Using actual UI bounds: x={questPanelX}, y={questPanelY}, w={questPanelWidth}, h={questPanelHeight}"); } } catch (System.Exception e) { Debug.LogWarning($"Failed to get UI bounds, using fallback: {e.Message}"); } } bool inQuestArea = screenPosition.x >= questPanelX && screenPosition.x <= questPanelX + questPanelWidth && screenPosition.y >= questPanelY && screenPosition.y <= questPanelY + questPanelHeight; if (inQuestArea) { Debug.Log($"🛡️ ActiveQuestUI: Blocking click in quest area at {screenPosition} (quest area: {questPanelX}-{questPanelX + questPanelWidth}, {questPanelY}-{questPanelY + questPanelHeight})"); return true; } // Don't block clicks outside the quest area return false; } void OnEnable() => ClickBlockingHelper.RegisterWithClickManager(this); void OnDisable() => ClickBlockingHelper.UnregisterWithClickManager(this); /// /// Sets a temporary flag to block travel system clicks when UI handles a click event. /// This is much more reliable than trying to calculate coordinates manually. /// private void SetClickFlag() { ClickBlockingHelper.SetClickFlag("ActiveQuestUI", this, (flag) => recentlyHandledClick = flag); } private void Start() { Debug.Log("ActiveQuestUI: Start called"); InitializeUI(); SubscribeToEvents(); // Delay quest refresh to ensure QuestManager is fully initialized StartCoroutine(DelayedQuestRefresh()); } private IEnumerator DelayedQuestRefresh() { yield return new WaitForEndOfFrame(); Debug.Log("ActiveQuestUI: Performing delayed quest refresh"); RefreshQuestList(); } private void InitializeUI() { if (uiDocument == null) uiDocument = GetComponent(); var root = uiDocument.rootVisualElement; if (root == null) { return; } // Ensure root doesn't block other UI - set to ignore picking root.pickingMode = PickingMode.Ignore; // Ensure this UI has proper sorting order to be above map but below modals if (uiDocument.sortingOrder == 0) { uiDocument.sortingOrder = 10; // Above map, below modals like TravelUI } // Get main elements questTracker = root.Q("quest-tracker"); trackerTitle = root.Q