96 lines
2.7 KiB
C#
96 lines
2.7 KiB
C#
using Cryville.Crtr.Config.UI;
|
|
using Cryville.Crtr.UI;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Cryville.Crtr.Browsing.UI {
|
|
public class ResourceBrowserMaster : MonoBehaviour {
|
|
[SerializeField]
|
|
Button m_playButton;
|
|
[SerializeField]
|
|
Button m_configButton;
|
|
[SerializeField]
|
|
ConfigPanelMaster m_configPanel;
|
|
[SerializeField]
|
|
Transform m_tabContainer;
|
|
[SerializeField]
|
|
GameObject m_tabPrefab;
|
|
[SerializeField]
|
|
PathedResourceBrowser m_mainBrowser;
|
|
[SerializeField]
|
|
SettingsBrowser m_settingsBrowser;
|
|
[SerializeField]
|
|
DetailPanel m_detailPanel;
|
|
|
|
BrowserTab _currentTab;
|
|
readonly Dictionary<BrowserTab, ResourceBrowser> _tabs = new Dictionary<BrowserTab, ResourceBrowser>();
|
|
|
|
void Awake() {
|
|
m_mainBrowser.ResourceManager = new LegacyResourceManager(Settings.Default.GameDataPath);
|
|
OnTabClicked(AddTab("Local", m_mainBrowser));
|
|
|
|
AddTab("Settings", m_settingsBrowser);
|
|
}
|
|
|
|
BrowserTab AddTab(string name, ResourceBrowser browser) {
|
|
var tab = Instantiate(m_tabPrefab, m_tabContainer, false).GetComponent<BrowserTab>();
|
|
tab.Icon = browser.Icon;
|
|
tab.Text = name;
|
|
tab.Clicked += OnTabClicked;
|
|
_tabs.Add(tab, browser);
|
|
return tab;
|
|
}
|
|
|
|
void OnTabClicked(BrowserTab tab) {
|
|
if (tab == _currentTab) return;
|
|
if (_currentTab != null) {
|
|
_currentTab.Selected = false;
|
|
_tabs[_currentTab].gameObject.SetActive(false);
|
|
}
|
|
_currentTab = tab;
|
|
if (_currentTab != null) {
|
|
_currentTab.Selected = true;
|
|
_tabs[_currentTab].gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
public void ShowDetail(int id, ChartDetail detail) {
|
|
// SlideIntoView(1);
|
|
m_detailPanel.Load(id, detail);
|
|
m_playButton.gameObject.SetActive(true);
|
|
m_configButton.gameObject.SetActive(true);
|
|
}
|
|
|
|
public bool Back() {
|
|
// if (_slideDest == 0) return false;
|
|
// SlideIntoView(_slideDest - 1);
|
|
return true;
|
|
}
|
|
|
|
public void Open(int id, ChartDetail detail) {
|
|
SetDataSettings(id, detail);
|
|
#if UNITY_5_3_OR_NEWER
|
|
SceneManager.LoadScene("Play", LoadSceneMode.Additive);
|
|
#else
|
|
Application.LoadLevelAdditive("Play");
|
|
#endif
|
|
GameObject.Find("/Master").GetComponent<Master>().HideMenu();
|
|
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
|
|
DiscordController.Instance.SetPlaying(string.Format("{0} - {1}", detail.Meta.song.name, detail.Meta.name), detail.Meta.length);
|
|
#endif
|
|
}
|
|
|
|
public void OpenConfig(int id, ChartDetail detail) {
|
|
SetDataSettings(id, detail);
|
|
}
|
|
|
|
void SetDataSettings(int id, ChartDetail detail) {
|
|
Settings.Default.LoadRuleset = detail.Meta.ruleset + "/.umgr";
|
|
Settings.Default.LoadRulesetConfig = detail.Meta.ruleset + ".json";
|
|
Settings.Default.LoadChart = m_mainBrowser.ResourceManager.GetItemUri(id).LocalPath;
|
|
}
|
|
}
|
|
}
|