diff --git a/Assets/Config.unity b/Assets/Config.unity index daa44fa..bfe8b7a 100644 Binary files a/Assets/Config.unity and b/Assets/Config.unity differ diff --git a/Assets/Cryville/Crtr/Config/ConfigScene.cs b/Assets/Cryville/Crtr/Config/ConfigScene.cs index 507c11e..f560007 100644 --- a/Assets/Cryville/Crtr/Config/ConfigScene.cs +++ b/Assets/Cryville/Crtr/Config/ConfigScene.cs @@ -1,4 +1,8 @@ -using UnityEngine; +using Newtonsoft.Json; +using System.IO; +using System.Text; +using System; +using UnityEngine; using UnityEngine.SceneManagement; namespace Cryville.Crtr.Config { @@ -6,6 +10,45 @@ namespace Cryville.Crtr.Config { [SerializeField] Transform m_content; + [SerializeField] + InputConfigPanel m_inputConfigPanel; + + public Ruleset ruleset; + RulesetConfig _rscfg; + + void Awake() { + ChartPlayer.etor = new PdtEvaluator(); + FileInfo file = new FileInfo( + Game.GameDataPath + "/rulesets/" + Settings.Default.LoadRuleset + ); + DirectoryInfo dir = file.Directory; + using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) { + ruleset = JsonConvert.DeserializeObject(reader.ReadToEnd(), new JsonSerializerSettings() { + MissingMemberHandling = MissingMemberHandling.Error + }); + if (ruleset.format != 1) throw new FormatException("Invalid ruleset file version"); + ruleset.LoadPdt(dir); + } + FileInfo cfgfile = new FileInfo( + Game.GameDataPath + "/config/rulesets/" + Settings.Default.LoadRulesetConfig + ); + if (!cfgfile.Exists) { + if (!cfgfile.Directory.Exists) cfgfile.Directory.Create(); + _rscfg = new RulesetConfig(); + } + else { + using (StreamReader cfgreader = new StreamReader(cfgfile.FullName, Encoding.UTF8)) { + _rscfg = JsonConvert.DeserializeObject(cfgreader.ReadToEnd(), new JsonSerializerSettings() { + MissingMemberHandling = MissingMemberHandling.Error + }); + } + } + var proxy = new InputProxy(ruleset.Root, null); + proxy.LoadFrom(_rscfg.inputs); + m_inputConfigPanel.proxy = proxy; + Game.InputManager.Activate(); + } + public void SwitchCategory(GameObject cat) { foreach (Transform c in m_content) { c.gameObject.SetActive(false); @@ -14,6 +57,15 @@ namespace Cryville.Crtr.Config { } public void ReturnToMenu() { + Game.InputManager.Deactivate(); + m_inputConfigPanel.proxy.SaveTo(_rscfg.inputs); + m_inputConfigPanel.proxy.Dispose(); + FileInfo cfgfile = new FileInfo( + Game.GameDataPath + "/config/rulesets/" + Settings.Default.LoadRulesetConfig + ); + using (StreamWriter cfgwriter = new StreamWriter(cfgfile.FullName, false, Encoding.UTF8)) { + cfgwriter.Write(JsonConvert.SerializeObject(_rscfg, Game.GlobalJsonSerializerSettings)); + } GameObject.Find("Master").GetComponent().ShowMenu(); #if UNITY_5_5_OR_NEWER SceneManager.UnloadSceneAsync("Config"); diff --git a/Assets/Cryville/Crtr/Config/InputConfig.cs b/Assets/Cryville/Crtr/Config/InputConfigPanel.cs similarity index 56% rename from Assets/Cryville/Crtr/Config/InputConfig.cs rename to Assets/Cryville/Crtr/Config/InputConfigPanel.cs index 8bb39e8..c94f1fa 100644 --- a/Assets/Cryville/Crtr/Config/InputConfig.cs +++ b/Assets/Cryville/Crtr/Config/InputConfigPanel.cs @@ -1,15 +1,14 @@ using Cryville.Common.Unity; using Cryville.Common.Unity.Input; -using Newtonsoft.Json; -using System; using System.Collections.Generic; -using System.IO; -using System.Text; using UnityEngine; using UnityEngine.UI; namespace Cryville.Crtr.Config { - public class InputConfig : MonoBehaviour { + public class InputConfigPanel : MonoBehaviour { + [SerializeField] + ConfigScene m_configScene; + [SerializeField] GameObject m_inputDialog; @@ -25,14 +24,13 @@ namespace Cryville.Crtr.Config { [SerializeField] GameObject m_prefabInputConfigEntry; - InputProxy _proxy; - Dictionary _entries = new Dictionary(); + public InputProxy proxy; + Dictionary _entries = new Dictionary(); string _sel; public void OpenDialog(string entry) { _sel = entry; m_inputDialog.SetActive(true); - Game.InputManager.Activate(); CallHelper.Purge(m_deviceList); _recvsrcs.Clear(); AddSourceItem(null); @@ -40,38 +38,24 @@ namespace Cryville.Crtr.Config { public void CloseDialog() { m_inputDialog.SetActive(false); - Game.InputManager.Deactivate(); } public void CloseDialog(InputSource? src) { - _proxy.Set(new InputProxyEntry { + proxy.Set(new InputProxyEntry { Target = _sel, Source = src, }); m_inputDialog.SetActive(false); - Game.InputManager.Deactivate(); } void Start() { - ChartPlayer.etor = new PdtEvaluator(); - FileInfo file = new FileInfo( - Game.GameDataPath + "/rulesets/" + Settings.Default.LoadRuleset - ); - DirectoryInfo dir = file.Directory; - using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) { - var ruleset = JsonConvert.DeserializeObject(reader.ReadToEnd(), new JsonSerializerSettings() { - MissingMemberHandling = MissingMemberHandling.Error - }); - if (ruleset.format != 1) throw new FormatException("Invalid ruleset file version"); - ruleset.LoadPdt(dir); - _proxy = new InputProxy(ruleset.Root, null); - foreach (var i in ruleset.Root.inputs) { - var e = GameObject.Instantiate(m_prefabInputConfigEntry, m_entryList.transform).GetComponent(); - _entries.Add(i.Key, e); - e.SetKey(this, i.Key); - } - _proxy.ProxyChanged += OnProxyChanged; + foreach (var i in m_configScene.ruleset.Root.inputs) { + var e = GameObject.Instantiate(m_prefabInputConfigEntry, m_entryList.transform).GetComponent(); + _entries.Add(i.Key, e); + e.SetKey(this, i.Key); + OnProxyChanged(this, proxy[i.Key]); } + proxy.ProxyChanged += OnProxyChanged; } void OnProxyChanged(object sender, ProxyChangedEventArgs e) { @@ -94,7 +78,7 @@ namespace Cryville.Crtr.Config { var obj = Instantiate(m_prefabListItem, m_deviceList); obj.transform.Find("Text").GetComponent().text = src == null ? "None" : src.Value.Handler.GetTypeName(src.Value.Type); var btn = obj.GetComponent