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; void OnEnable() { ClickBlockingHelper.RegisterWithClickManager(this); // Refresh quest list when returning from scenes (like settlements) // Use a coroutine to ensure other systems are ready StartCoroutine(RefreshOnEnable()); } void OnDisable() => ClickBlockingHelper.UnregisterWithClickManager(this); private IEnumerator RefreshOnEnable() { // Wait a frame to ensure other systems are initialized yield return new WaitForEndOfFrame(); // Check if we need to refresh the quest list if (QuestManager.Instance != null) { RefreshQuestList(); } } /// /// 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() { InitializeUI(); SubscribeToEvents(); // Delay quest refresh to ensure QuestManager is fully initialized StartCoroutine(DelayedQuestRefresh()); } private IEnumerator DelayedQuestRefresh() { yield return new WaitForEndOfFrame(); 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