2024-09-16 09:15:45 -07:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2024-09-24 17:05:33 -07:00
|
|
|
using System.IO;
|
2024-09-16 09:15:45 -07:00
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.UI;
|
|
|
|
using TMPro;
|
|
|
|
|
|
|
|
public class UIManager : MonoBehaviour
|
|
|
|
{
|
|
|
|
|
|
|
|
public static UIManager Instance { get; private set; }
|
|
|
|
|
2024-09-24 17:05:33 -07:00
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private GameObject _agentStatusPanel;
|
|
|
|
[SerializeField]
|
|
|
|
private GameObject _configSelectorPanel;
|
|
|
|
private TMP_Dropdown _configDropdown;
|
2024-09-16 09:15:45 -07:00
|
|
|
public TextMeshProUGUI agentPanelText;
|
2024-09-24 17:05:33 -07:00
|
|
|
public TextMeshProUGUI simTimeText;
|
2024-09-16 09:15:45 -07:00
|
|
|
|
|
|
|
public TMP_FontAsset Font;
|
|
|
|
|
|
|
|
|
|
|
|
private UIMode curMode = UIMode.NONE;
|
|
|
|
|
|
|
|
|
|
|
|
// Start is called before the first frame update
|
|
|
|
void Awake()
|
|
|
|
{
|
|
|
|
// singleton
|
|
|
|
if (Instance == null)
|
|
|
|
Instance = this;
|
|
|
|
else
|
2024-09-24 17:05:33 -07:00
|
|
|
Destroy(gameObject);
|
|
|
|
|
2024-09-16 09:15:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
{
|
2024-09-24 17:05:33 -07:00
|
|
|
_configSelectorPanel.SetActive(false);
|
|
|
|
SetupConfigSelectorPanel();
|
2024-09-16 09:15:45 -07:00
|
|
|
//inputManager = InputManager.Instance;
|
|
|
|
//worldManager = WorldManager.Instance;
|
|
|
|
}
|
|
|
|
|
2024-09-24 17:05:33 -07:00
|
|
|
public void ToggleConfigSelectorPanel(){
|
|
|
|
_configSelectorPanel.SetActive(!_configSelectorPanel.activeSelf);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetupConfigSelectorPanel(){
|
|
|
|
_configSelectorPanel.GetComponentInChildren<Button>().onClick.AddListener(delegate {
|
|
|
|
LoadSelectedConfig();
|
|
|
|
});
|
|
|
|
_configDropdown = _configSelectorPanel.GetComponentInChildren<TMP_Dropdown>();
|
|
|
|
PopulateConfigDropdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void PopulateConfigDropdown(){
|
|
|
|
_configDropdown.ClearOptions();
|
|
|
|
string configPath = Path.Combine(Application.streamingAssetsPath, "Configs");
|
|
|
|
string[] configFiles = Directory.GetFiles(configPath, "*.json");
|
|
|
|
|
|
|
|
List<string> configFileNames = new List<string>();
|
|
|
|
foreach (string configFile in configFiles)
|
|
|
|
{
|
|
|
|
configFileNames.Add(Path.GetFileName(configFile));
|
|
|
|
}
|
|
|
|
_configDropdown.AddOptions(configFileNames);
|
|
|
|
}
|
|
|
|
private void LoadSelectedConfig(){
|
|
|
|
string selectedConfig = _configDropdown.options[_configDropdown.value].text;
|
|
|
|
SimManager.Instance.LoadNewConfig(selectedConfig);
|
|
|
|
_configSelectorPanel.SetActive(false);
|
|
|
|
//if(!InputManager.Instance.mouseActive){
|
|
|
|
// InputManager.Instance.mouseActive = true;
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
|
2024-09-16 09:15:45 -07:00
|
|
|
public void SetUIMode(UIMode mode){
|
|
|
|
curMode = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
public UIMode GetUIMode(){
|
|
|
|
return curMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetAgentPanelText(string text)
|
|
|
|
{
|
|
|
|
agentPanelText.text = text;
|
|
|
|
}
|
|
|
|
|
|
|
|
public string GetAgentPanelText()
|
|
|
|
{
|
|
|
|
return agentPanelText.text;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void UpdateAgentPanel()
|
|
|
|
{
|
|
|
|
string agentPanelText = "";
|
|
|
|
foreach(Agent agent in SimManager.Instance.GetActiveAgents())
|
|
|
|
{
|
|
|
|
string jobText = agent.name + "| Phase: " + agent.GetFlightPhase().ToString();
|
|
|
|
agentPanelText += jobText + "\n";
|
|
|
|
}
|
|
|
|
SetAgentPanelText(agentPanelText);
|
|
|
|
}
|
|
|
|
|
2024-09-24 17:05:33 -07:00
|
|
|
private void UpdateSimTimeText()
|
|
|
|
{
|
|
|
|
simTimeText.text = "Elapsed Sim Time: " + SimManager.Instance.GetElapsedSimulationTime().ToString("F2");
|
|
|
|
}
|
2024-09-16 09:15:45 -07:00
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
2024-09-24 17:05:33 -07:00
|
|
|
//UpdateAgentPanel();
|
|
|
|
UpdateSimTimeText();
|
2024-09-16 09:15:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public enum UIMode {
|
|
|
|
NONE,
|
|
|
|
BUILD,
|
|
|
|
MINE
|
|
|
|
}
|