76 lines
1.8 KiB
C#
76 lines
1.8 KiB
C#
using Cryville.Common.Unity.UI;
|
|
using Cryville.Crtr.Browsing.UI;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using unity = UnityEngine;
|
|
|
|
namespace Cryville.Crtr.UI {
|
|
public class Menu : MonoBehaviour {
|
|
#pragma warning disable IDE0044
|
|
[SerializeField]
|
|
ResourceBrowserMaster m_browserMaster;
|
|
[SerializeField]
|
|
ProgressBar m_progressBar;
|
|
[SerializeField]
|
|
TMP_Text m_title;
|
|
[SerializeField]
|
|
GameObject[] m_backBlockingObjects;
|
|
[SerializeField]
|
|
GameObject m_contents;
|
|
#pragma warning restore IDE0044
|
|
|
|
int frameIndex = 2;
|
|
bool initialized = false;
|
|
int totalTasks = 0;
|
|
#pragma warning disable IDE0051
|
|
void Awake() {
|
|
Game.Init();
|
|
m_contents.SetActive(true);
|
|
PushTitle("Chart Browser");
|
|
}
|
|
void Update() {
|
|
if (!initialized) {
|
|
int taskCount = Game.NetworkTaskWorker.TaskCount;
|
|
if (totalTasks < taskCount) totalTasks = taskCount;
|
|
if (frameIndex > 0) {
|
|
frameIndex--;
|
|
return;
|
|
}
|
|
if (m_progressBar != null) m_progressBar.value = totalTasks == 0 ? 1 : (1 - (float)taskCount / totalTasks);
|
|
if (taskCount == 0) {
|
|
initialized = true;
|
|
// TODO Show main
|
|
}
|
|
}
|
|
if (unity::Input.GetKeyDown(KeyCode.Escape)) {
|
|
Back();
|
|
}
|
|
}
|
|
|
|
void OnEnable() {
|
|
Application.targetFrameRate = 60;
|
|
Game.ResumeBackgroundTasks();
|
|
}
|
|
#pragma warning restore IDE0051
|
|
|
|
readonly Stack<string> _uiStack = new Stack<string>();
|
|
public void PushTitle(string title) {
|
|
_uiStack.Push(title);
|
|
if (m_title) m_title.SetText(title);
|
|
}
|
|
public void Back() {
|
|
foreach (var obj in m_backBlockingObjects) {
|
|
if (obj.activeInHierarchy) return;
|
|
}
|
|
if (m_browserMaster.Back()) return;
|
|
if (_uiStack.Count <= 1) return;
|
|
_uiStack.Pop();
|
|
if (m_title) m_title.SetText(_uiStack.Peek());
|
|
}
|
|
public void Quit() {
|
|
Application.Quit();
|
|
}
|
|
}
|
|
}
|