using UnityEngine;
using UnityEngine.UIElements;
using System.Linq;
///
/// Controls the travel UI and integrates with TeamTravelSystem for route planning and execution.
/// Uses the existing travel UI elements from MapWithTravelUI.uxml
///
[RequireComponent(typeof(UIDocument))]
public class TravelUIController : MonoBehaviour
{
[Header("UI References")]
public UIDocument uiDocument;
[Header("Settings")]
public bool showDebugLogs = false;
// UI Elements
private VisualElement travelContainer;
private VisualElement travelPanel;
private Button closeButton;
private Label distanceLabel;
private Label timeLabel;
private Label specialCostsLabel;
private Button startTravelButton;
// Route selection (if available)
private VisualElement routeOptionsContainer;
private RadioButtonGroup routeSelection;
// System references
private TeamTravelSystem travelSystem;
private SimpleTeamPlacement teamPlacement;
// Current state
private TravelRoute selectedRoute;
private bool isUIVisible = false;
void Awake()
{
if (uiDocument == null)
uiDocument = GetComponent();
}
void Start()
{
// Find system references
travelSystem = TeamTravelSystem.Instance;
teamPlacement = SimpleTeamPlacement.Instance;
if (travelSystem == null)
{
Debug.LogError("❌ TeamTravelSystem not found! TravelUIController requires it.");
return;
}
// Setup UI
SetupUIElements();
SetupEventHandlers();
// Hide UI initially
HideTravelUI();
}
void Update()
{
// Monitor for travel planning
if (travelSystem != null && travelSystem.GetPlannedDestination().HasValue && !isUIVisible)
{
ShowTravelUI();
}
else if (travelSystem != null && !travelSystem.GetPlannedDestination().HasValue && isUIVisible)
{
HideTravelUI();
}
}
///
/// Sets up references to UI elements
///
private void SetupUIElements()
{
if (uiDocument?.rootVisualElement == null)
{
Debug.LogError("❌ UIDocument root not available");
return;
}
var root = uiDocument.rootVisualElement;
// Find main UI elements
travelContainer = root.Q("TravelContainer");
travelPanel = root.Q("TravelPanel");
closeButton = root.Q