Implement input config scene loading and saving.
This commit is contained in:
Binary file not shown.
@@ -1,4 +1,8 @@
|
|||||||
using UnityEngine;
|
using Newtonsoft.Json;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
using UnityEngine.SceneManagement;
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Config {
|
namespace Cryville.Crtr.Config {
|
||||||
@@ -6,6 +10,45 @@ namespace Cryville.Crtr.Config {
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
Transform m_content;
|
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) {
|
public void SwitchCategory(GameObject cat) {
|
||||||
foreach (Transform c in m_content) {
|
foreach (Transform c in m_content) {
|
||||||
c.gameObject.SetActive(false);
|
c.gameObject.SetActive(false);
|
||||||
@@ -14,6 +57,15 @@ namespace Cryville.Crtr.Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void ReturnToMenu() {
|
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();
|
GameObject.Find("Master").GetComponent<Master>().ShowMenu();
|
||||||
#if UNITY_5_5_OR_NEWER
|
#if UNITY_5_5_OR_NEWER
|
||||||
SceneManager.UnloadSceneAsync("Config");
|
SceneManager.UnloadSceneAsync("Config");
|
||||||
|
@@ -1,15 +1,14 @@
|
|||||||
using Cryville.Common.Unity;
|
using Cryville.Common.Unity;
|
||||||
using Cryville.Common.Unity.Input;
|
using Cryville.Common.Unity.Input;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Text;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Config {
|
namespace Cryville.Crtr.Config {
|
||||||
public class InputConfig : MonoBehaviour {
|
public class InputConfigPanel : MonoBehaviour {
|
||||||
|
[SerializeField]
|
||||||
|
ConfigScene m_configScene;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject m_inputDialog;
|
GameObject m_inputDialog;
|
||||||
|
|
||||||
@@ -25,14 +24,13 @@ namespace Cryville.Crtr.Config {
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject m_prefabInputConfigEntry;
|
GameObject m_prefabInputConfigEntry;
|
||||||
|
|
||||||
InputProxy _proxy;
|
public InputProxy proxy;
|
||||||
Dictionary<string, InputConfigEntry> _entries = new Dictionary<string, InputConfigEntry>();
|
Dictionary<string, InputConfigPanelEntry> _entries = new Dictionary<string, InputConfigPanelEntry>();
|
||||||
|
|
||||||
string _sel;
|
string _sel;
|
||||||
public void OpenDialog(string entry) {
|
public void OpenDialog(string entry) {
|
||||||
_sel = entry;
|
_sel = entry;
|
||||||
m_inputDialog.SetActive(true);
|
m_inputDialog.SetActive(true);
|
||||||
Game.InputManager.Activate();
|
|
||||||
CallHelper.Purge(m_deviceList);
|
CallHelper.Purge(m_deviceList);
|
||||||
_recvsrcs.Clear();
|
_recvsrcs.Clear();
|
||||||
AddSourceItem(null);
|
AddSourceItem(null);
|
||||||
@@ -40,38 +38,24 @@ namespace Cryville.Crtr.Config {
|
|||||||
|
|
||||||
public void CloseDialog() {
|
public void CloseDialog() {
|
||||||
m_inputDialog.SetActive(false);
|
m_inputDialog.SetActive(false);
|
||||||
Game.InputManager.Deactivate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CloseDialog(InputSource? src) {
|
public void CloseDialog(InputSource? src) {
|
||||||
_proxy.Set(new InputProxyEntry {
|
proxy.Set(new InputProxyEntry {
|
||||||
Target = _sel,
|
Target = _sel,
|
||||||
Source = src,
|
Source = src,
|
||||||
});
|
});
|
||||||
m_inputDialog.SetActive(false);
|
m_inputDialog.SetActive(false);
|
||||||
Game.InputManager.Deactivate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Start() {
|
void Start() {
|
||||||
ChartPlayer.etor = new PdtEvaluator();
|
foreach (var i in m_configScene.ruleset.Root.inputs) {
|
||||||
FileInfo file = new FileInfo(
|
var e = GameObject.Instantiate(m_prefabInputConfigEntry, m_entryList.transform).GetComponent<InputConfigPanelEntry>();
|
||||||
Game.GameDataPath + "/rulesets/" + Settings.Default.LoadRuleset
|
_entries.Add(i.Key, e);
|
||||||
);
|
e.SetKey(this, i.Key);
|
||||||
DirectoryInfo dir = file.Directory;
|
OnProxyChanged(this, proxy[i.Key]);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
proxy.ProxyChanged += OnProxyChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnProxyChanged(object sender, ProxyChangedEventArgs e) {
|
void OnProxyChanged(object sender, ProxyChangedEventArgs e) {
|
||||||
@@ -94,7 +78,7 @@ namespace Cryville.Crtr.Config {
|
|||||||
var obj = Instantiate(m_prefabListItem, m_deviceList);
|
var obj = Instantiate(m_prefabListItem, m_deviceList);
|
||||||
obj.transform.Find("Text").GetComponent<Text>().text = src == null ? "None" : src.Value.Handler.GetTypeName(src.Value.Type);
|
obj.transform.Find("Text").GetComponent<Text>().text = src == null ? "None" : src.Value.Handler.GetTypeName(src.Value.Type);
|
||||||
var btn = obj.GetComponent<Button>();
|
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(() => {
|
btn.onClick.AddListener(() => {
|
||||||
CloseDialog(src);
|
CloseDialog(src);
|
||||||
});
|
});
|
@@ -2,7 +2,7 @@
|
|||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Config {
|
namespace Cryville.Crtr.Config {
|
||||||
public class InputConfigEntry : MonoBehaviour {
|
public class InputConfigPanelEntry : MonoBehaviour {
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
Text m_key;
|
Text m_key;
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ namespace Cryville.Crtr.Config {
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
Button m_button;
|
Button m_button;
|
||||||
|
|
||||||
public void SetKey(InputConfig master, string name) {
|
public void SetKey(InputConfigPanel master, string name) {
|
||||||
m_key.text = name;
|
m_key.text = name;
|
||||||
m_value.text = "None";
|
m_value.text = "None";
|
||||||
m_button.onClick.AddListener(() => {
|
m_button.onClick.AddListener(() => {
|
@@ -8,7 +8,7 @@ using UnityEngine;
|
|||||||
using Logger = Cryville.Common.Logger;
|
using Logger = Cryville.Common.Logger;
|
||||||
|
|
||||||
namespace Cryville.Crtr {
|
namespace Cryville.Crtr {
|
||||||
public class InputProxy {
|
public class InputProxy : IDisposable {
|
||||||
readonly PdtEvaluator _etor;
|
readonly PdtEvaluator _etor;
|
||||||
readonly PdtRuleset _ruleset;
|
readonly PdtRuleset _ruleset;
|
||||||
readonly Judge _judge;
|
readonly Judge _judge;
|
||||||
@@ -148,6 +148,22 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
public void Deactivate() { foreach (var src in _sproxies.Keys) src.Handler.Deactivate(); }
|
public void Deactivate() { foreach (var src in _sproxies.Keys) src.Handler.Deactivate(); }
|
||||||
|
|
||||||
|
~InputProxy() {
|
||||||
|
Dispose(false);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
public void Dispose() {
|
||||||
|
Dispose(true);
|
||||||
|
}
|
||||||
|
protected void Dispose(bool disposing) {
|
||||||
|
if (disposing) {
|
||||||
|
Deactivate();
|
||||||
|
foreach (var proxy in _tproxies.Values) {
|
||||||
|
proxy.Source.Value.Handler.OnInput -= OnInput;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
readonly object _lock = new object();
|
readonly object _lock = new object();
|
||||||
static readonly int _var_value = IdentifierManager.SharedInstance.Request("value");
|
static readonly int _var_value = IdentifierManager.SharedInstance.Request("value");
|
||||||
static readonly PropOp.Arbitrary _arbop = new PropOp.Arbitrary();
|
static readonly PropOp.Arbitrary _arbop = new PropOp.Arbitrary();
|
||||||
|
Reference in New Issue
Block a user