using UnityEngine;
using UnityEngine.UIElements;
///
/// Setup script to configure all UI systems in the map scene.
/// Handles both travel system and team overview setup automatically.
///
public class MapSceneSetup : MonoBehaviour
{
[Header("Setup Options")]
public bool autoSetupOnStart = true;
public bool showDebugLogs = true;
[Header("UI Settings")]
public bool enableTeamOverview = true;
public bool enableTravelSystem = true;
void Start()
{
if (autoSetupOnStart)
{
SetupMapScene();
}
}
[ContextMenu("Setup Map Scene")]
public void SetupMapScene()
{
// Check if we're in Play Mode
if (!Application.isPlaying)
{
Debug.LogWarning("β οΈ MapSceneSetup: Please run this setup during Play Mode, not Edit Mode!");
Debug.LogWarning("π‘ Either enter Play Mode and try again, or let it run automatically via autoSetupOnStart.");
return;
}
if (showDebugLogs)
{
Debug.Log("ποΈ Setting up Map Scene UI systems...");
}
// Setup team overview if enabled
if (enableTeamOverview)
{
SetupTeamOverview();
}
// Setup travel system if enabled
if (enableTravelSystem)
{
SetupTravelSystem();
}
// Setup quest system
SetupQuestSystem();
if (showDebugLogs)
{
Debug.Log("β
Map Scene setup complete!");
}
}
[ContextMenu("Force Setup (Play Mode Only)")]
public void ForceSetupInPlayMode()
{
if (!Application.isPlaying)
{
Debug.LogError("β This setup requires Play Mode! Enter Play Mode first.");
return;
}
SetupMapScene();
}
///
/// Sets up the team overview controller
///
private void SetupTeamOverview()
{
// Look for UI GameObject
GameObject uiGameObject = GameObject.Find("UI");
if (uiGameObject == null)
{
if (showDebugLogs)
{
Debug.LogWarning("β οΈ No UI GameObject found - Team Overview not setup");
}
return;
}
// Check if TeamOverviewController already exists
var existingController = FindFirstObjectByType();
if (existingController != null)
{
if (showDebugLogs)
{
Debug.Log("π TeamOverviewController already exists");
}
return;
}
// Create a new GameObject for the TeamOverviewController
GameObject teamOverviewObject = new GameObject("TeamOverviewController");
teamOverviewObject.transform.SetParent(uiGameObject.transform);
// Add the TeamOverviewController component
var teamOverviewController = teamOverviewObject.AddComponent();
if (showDebugLogs)
{
Debug.Log("β
TeamOverviewController created and setup");
}
}
///
/// Sets up the travel system (delegates to existing setup if available)
///
private void SetupTravelSystem()
{
var travelSystemSetup = FindFirstObjectByType();
if (travelSystemSetup != null)
{
if (showDebugLogs)
{
Debug.Log("π Using existing TravelSystemSetup");
}
// Let the existing travel system setup handle this
return;
}
// Look for UI GameObject
GameObject uiGameObject = GameObject.Find("UI");
if (uiGameObject == null)
{
if (showDebugLogs)
{
Debug.LogWarning("β οΈ No UI GameObject found - Travel System not setup");
}
return;
}
// Check if TravelUIController already exists
var existingUIController = uiGameObject.GetComponent();
if (existingUIController != null)
{
if (showDebugLogs)
{
Debug.Log("π TravelUIController already exists");
}
return;
}
// Add TravelUIController to UI GameObject
var uiController = uiGameObject.AddComponent();
uiController.showDebugLogs = showDebugLogs;
if (showDebugLogs)
{
Debug.Log("β
TravelUIController created and setup");
}
}
///
/// Sets up the quest system and ensures quest data is loaded
///
private void SetupQuestSystem()
{
if (showDebugLogs)
{
Debug.Log("πΊοΈ Setting up Quest System for Map Scene...");
}
// Ensure QuestManager exists and loads quest data
if (QuestManager.Instance != null)
{
QuestManager.Instance.LoadQuestData();
if (showDebugLogs)
{
var activeQuests = QuestManager.Instance.GetActiveQuests();
Debug.Log($"β
Quest system ready - {activeQuests.Count} active quest(s)");
}
}
else
{
if (showDebugLogs)
{
Debug.LogWarning("β οΈ QuestManager not found in scene");
}
}
// Ensure quest markers are refreshed
var questMapMarkerManager = FindFirstObjectByType();
if (questMapMarkerManager != null)
{
questMapMarkerManager.RefreshAllMarkers();
if (showDebugLogs)
{
Debug.Log("β
Quest markers refreshed");
}
}
else
{
if (showDebugLogs)
{
Debug.LogWarning("β οΈ QuestMapMarkerManager not found in scene");
}
}
// Ensure ActiveQuestUI is refreshed
var activeQuestUI = FindFirstObjectByType();
if (activeQuestUI != null)
{
// The ActiveQuestUI should automatically refresh via events
if (showDebugLogs)
{
Debug.Log("β
ActiveQuestUI found and will auto-refresh");
}
}
else
{
// Create ActiveQuestUI if it doesn't exist
SetupActiveQuestUI();
}
}
///
/// Sets up the ActiveQuestUI component
///
private void SetupActiveQuestUI()
{
if (showDebugLogs)
{
Debug.Log("π― Setting up ActiveQuestUI...");
}
// Look for or create a QuestUI GameObject
GameObject questUIGameObject = GameObject.Find("QuestUI");
if (questUIGameObject == null)
{
questUIGameObject = new GameObject("QuestUI");
}
// Check if ActiveQuestUI already exists
var existingActiveQuestUI = questUIGameObject.GetComponent();
if (existingActiveQuestUI != null)
{
if (showDebugLogs)
{
Debug.Log("β
ActiveQuestUI component already exists");
}
return;
}
// Add UIDocument if it doesn't exist
var uiDocument = questUIGameObject.GetComponent();
if (uiDocument == null)
{
uiDocument = questUIGameObject.AddComponent();
}
// Load the UXML asset
var activeQuestUIAsset = Resources.Load("UI/MapScene/ActiveQuestUI");
if (activeQuestUIAsset != null)
{
uiDocument.visualTreeAsset = activeQuestUIAsset;
if (showDebugLogs)
{
Debug.Log("β
Loaded ActiveQuestUI.uxml");
}
}
else
{
Debug.LogError("β Could not load ActiveQuestUI.uxml from Resources/UI/MapScene/");
return;
}
// Load the USS asset
var activeQuestUIStyleSheet = Resources.Load("UI/MapScene/ActiveQuestUI");
if (activeQuestUIStyleSheet != null)
{
uiDocument.rootVisualElement.styleSheets.Add(activeQuestUIStyleSheet);
if (showDebugLogs)
{
Debug.Log("β
Loaded ActiveQuestUI.uss");
}
}
else
{
Debug.LogWarning("β οΈ Could not load ActiveQuestUI.uss from Resources/UI/MapScene/");
}
// Add the ActiveQuestUI component
var activeQuestUI = questUIGameObject.AddComponent();
activeQuestUI.uiDocument = uiDocument;
if (showDebugLogs)
{
Debug.Log("β
ActiveQuestUI component created and configured");
}
}
///
/// Context menu methods for debugging
///
[ContextMenu("Setup Team Overview Only")]
public void SetupTeamOverviewOnly()
{
SetupTeamOverview();
}
[ContextMenu("Setup Travel System Only")]
public void SetupTravelSystemOnly()
{
SetupTravelSystem();
}
[ContextMenu("Setup Quest System Only")]
public void SetupQuestSystemOnly()
{
SetupQuestSystem();
}
[ContextMenu("Setup ActiveQuestUI Only")]
public void SetupActiveQuestUIOnly()
{
SetupActiveQuestUI();
}
[ContextMenu("Verify UI Setup")]
public void VerifyUISetup()
{
var uiGameObject = GameObject.Find("UI");
var questUIGameObject = GameObject.Find("QuestUI");
if (uiGameObject == null)
{
Debug.LogError("β UI GameObject not found!");
return;
}
var uiDocument = uiGameObject.GetComponent();
var teamOverviewController = FindFirstObjectByType();
var travelUIController = uiGameObject.GetComponent();
var activeQuestUI = FindFirstObjectByType();
Debug.Log($"π UI Setup Verification:");
Debug.Log($" UIDocument: {(uiDocument != null ? "β
" : "β")}");
Debug.Log($" TeamOverviewController: {(teamOverviewController != null ? "β
" : "β")}");
Debug.Log($" TravelUIController: {(travelUIController != null ? "β
" : "β")}");
Debug.Log($" ActiveQuestUI: {(activeQuestUI != null ? "β
" : "β")}");
Debug.Log($" QuestUI GameObject: {(questUIGameObject != null ? "β
" : "β")}");
if (uiDocument?.rootVisualElement != null)
{
var root = uiDocument.rootVisualElement;
var teamOverviewPanel = root.Q("TeamOverviewPanel");
var travelContainer = root.Q("TravelContainer");
Debug.Log($" TeamOverviewPanel in UXML: {(teamOverviewPanel != null ? "β
" : "β")}");
Debug.Log($" TravelContainer in UXML: {(travelContainer != null ? "β
" : "β")}");
}
if (activeQuestUI?.uiDocument?.rootVisualElement != null)
{
var questRoot = activeQuestUI.uiDocument.rootVisualElement;
var questTracker = questRoot.Q("quest-tracker");
Debug.Log($" Quest Tracker in UXML: {(questTracker != null ? "β
" : "β")}");
}
}
}