Optimize code structure for input module.
This commit is contained in:
@@ -57,7 +57,6 @@ namespace Cryville.Crtr.Config {
|
||||
var proxy = new InputProxy(ruleset.Root, null);
|
||||
proxy.LoadFrom(_rscfg.inputs);
|
||||
m_inputConfigPanel.proxy = proxy;
|
||||
Game.InputManager.Activate();
|
||||
}
|
||||
|
||||
public void SwitchCategory(GameObject cat) {
|
||||
@@ -68,7 +67,6 @@ namespace Cryville.Crtr.Config {
|
||||
}
|
||||
|
||||
public void SaveAndReturnToMenu() {
|
||||
Game.InputManager.Deactivate();
|
||||
m_inputConfigPanel.proxy.SaveTo(_rscfg.inputs);
|
||||
m_inputConfigPanel.proxy.Dispose();
|
||||
FileInfo cfgfile = new FileInfo(
|
||||
|
@@ -24,6 +24,7 @@ namespace Cryville.Crtr.Config {
|
||||
[SerializeField]
|
||||
GameObject m_prefabInputConfigEntry;
|
||||
|
||||
readonly SimpleInputConsumer _consumer = new SimpleInputConsumer(Game.InputManager);
|
||||
public InputProxy proxy;
|
||||
readonly Dictionary<string, InputConfigPanelEntry> _entries = new Dictionary<string, InputConfigPanelEntry>();
|
||||
|
||||
@@ -32,7 +33,7 @@ namespace Cryville.Crtr.Config {
|
||||
_sel = entry;
|
||||
m_inputDialog.SetActive(true);
|
||||
CallHelper.Purge(m_deviceList);
|
||||
Game.InputManager.EnumerateEvents(ev => { });
|
||||
_consumer.EnumerateEvents(ev => { });
|
||||
_recvsrcs.Clear();
|
||||
AddSourceItem(null);
|
||||
}
|
||||
@@ -46,10 +47,11 @@ namespace Cryville.Crtr.Config {
|
||||
Target = _sel,
|
||||
Source = src,
|
||||
});
|
||||
m_inputDialog.SetActive(false);
|
||||
CloseDialog();
|
||||
}
|
||||
|
||||
void Start() {
|
||||
_consumer.Activate();
|
||||
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);
|
||||
@@ -59,6 +61,10 @@ namespace Cryville.Crtr.Config {
|
||||
proxy.ProxyChanged += OnProxyChanged;
|
||||
}
|
||||
|
||||
void OnDestroy() {
|
||||
_consumer.Deactivate();
|
||||
}
|
||||
|
||||
void OnProxyChanged(object sender, ProxyChangedEventArgs e) {
|
||||
_entries[e.Name].SetEnabled(!e.Used);
|
||||
_entries[e.Name].SetValue(e.Proxy == null ? "None" : e.Proxy.Value.Handler.GetTypeName(e.Proxy.Value.Type));
|
||||
@@ -67,7 +73,7 @@ namespace Cryville.Crtr.Config {
|
||||
readonly List<InputSource?> _recvsrcs = new List<InputSource?>();
|
||||
void Update() {
|
||||
if (m_inputDialog.activeSelf) {
|
||||
Game.InputManager.EnumerateEvents(ev => {
|
||||
_consumer.EnumerateEvents(ev => {
|
||||
AddSourceItem(ev.Id.Source);
|
||||
});
|
||||
}
|
||||
|
@@ -65,10 +65,6 @@ namespace Cryville.Crtr {
|
||||
if (_use[target] > 0)
|
||||
throw new InvalidOperationException("Input already assigned");
|
||||
if (proxy.Source != null) {
|
||||
if (_judge != null) {
|
||||
proxy.Source.Value.Handler.OnInput -= OnInput; // Prevent duplicated hooks, no exception will be thrown
|
||||
proxy.Source.Value.Handler.OnInput += OnInput;
|
||||
}
|
||||
_tproxies.Add(target, proxy);
|
||||
_sproxies.Add(proxy.Source.Value, proxy);
|
||||
IncrementUseRecursive(target);
|
||||
@@ -77,7 +73,6 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
void Remove(InputProxyEntry proxy) {
|
||||
var target = proxy.Target;
|
||||
if (_judge != null) _tproxies[target].Source.Value.Handler.OnInput -= OnInput;
|
||||
_sproxies.Remove(_tproxies[target].Source.Value);
|
||||
_tproxies.Remove(target);
|
||||
DecrementUseRecursive(target);
|
||||
@@ -142,12 +137,22 @@ namespace Cryville.Crtr {
|
||||
public void Activate() {
|
||||
_activeCounts.Clear();
|
||||
_vect.Clear(); _vecs.Clear();
|
||||
foreach (var src in _sproxies.Keys) {
|
||||
_activeCounts.Add(src, 0);
|
||||
src.Handler.Activate();
|
||||
foreach (var src in _sproxies) {
|
||||
_activeCounts.Add(src.Key, 0);
|
||||
var isrc = src.Value.Source;
|
||||
if (isrc != null) {
|
||||
isrc.Value.Handler.OnInput += OnInput;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Deactivate() {
|
||||
foreach (var src in _sproxies) {
|
||||
var isrc = src.Value.Source;
|
||||
if (isrc != null) {
|
||||
isrc.Value.Handler.OnInput -= OnInput;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Deactivate() { foreach (var src in _sproxies.Keys) src.Handler.Deactivate(); }
|
||||
|
||||
~InputProxy() {
|
||||
Dispose(false);
|
||||
|
Reference in New Issue
Block a user