using Cryville.Crtr.Config.UI; using Cryville.Crtr.UI; using System.Collections.Generic; using System.IO; using UnityEngine; using UnityEngine.SceneManagement; namespace Cryville.Crtr.Browsing.UI { public class ResourceBrowserMaster : MonoBehaviour { [SerializeField] ConfigPanelMaster m_configPanel; [SerializeField] Transform m_tabContainer; [SerializeField] GameObject m_tabPrefab; [SerializeField] PathedResourceBrowser m_mainBrowser; [SerializeField] SettingsBrowser m_settingsBrowser; BrowserTab _currentTab; readonly Dictionary _tabs = new Dictionary(); 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(); 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 bool Back() { return true; // TODO } 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 Master.Instance.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 = Path.Combine(detail.Meta.ruleset, ".umgr"); Settings.Default.LoadRulesetConfig = detail.Meta.ruleset + ".json"; Settings.Default.LoadChart = m_mainBrowser.ResourceManager.GetItemUri(id).LocalPath; } } }