Implement input config scene loading and saving.
This commit is contained in:
@@ -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<Ruleset>(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<RulesetConfig>(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<Master>().ShowMenu();
|
||||
#if UNITY_5_5_OR_NEWER
|
||||
SceneManager.UnloadSceneAsync("Config");
|
||||
|
@@ -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<string, InputConfigEntry> _entries = new Dictionary<string, InputConfigEntry>();
|
||||
public InputProxy proxy;
|
||||
Dictionary<string, InputConfigPanelEntry> _entries = new Dictionary<string, InputConfigPanelEntry>();
|
||||
|
||||
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<Ruleset>(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<InputConfigEntry>();
|
||||
_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<InputConfigPanelEntry>();
|
||||
_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>().text = src == null ? "None" : src.Value.Handler.GetTypeName(src.Value.Type);
|
||||
var btn = obj.GetComponent<Button>();
|
||||
if (src != null) btn.interactable = !_proxy.IsUsed(src.Value);
|
||||
if (src != null) btn.interactable = !proxy.IsUsed(src.Value);
|
||||
btn.onClick.AddListener(() => {
|
||||
CloseDialog(src);
|
||||
});
|
@@ -2,7 +2,7 @@
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Cryville.Crtr.Config {
|
||||
public class InputConfigEntry : MonoBehaviour {
|
||||
public class InputConfigPanelEntry : MonoBehaviour {
|
||||
[SerializeField]
|
||||
Text m_key;
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Cryville.Crtr.Config {
|
||||
[SerializeField]
|
||||
Button m_button;
|
||||
|
||||
public void SetKey(InputConfig master, string name) {
|
||||
public void SetKey(InputConfigPanel master, string name) {
|
||||
m_key.text = name;
|
||||
m_value.text = "None";
|
||||
m_button.onClick.AddListener(() => {
|
Reference in New Issue
Block a user