55 lines
1.5 KiB
C#
55 lines
1.5 KiB
C#
using Cryville.Common;
|
|
using Cryville.Crtr.Ruleset;
|
|
using Cryville.Input;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Cryville.Crtr.Config.UI {
|
|
internal class InputConfigPanel : MonoBehaviour {
|
|
[SerializeField]
|
|
Transform m_entryList;
|
|
|
|
[SerializeField]
|
|
GameObject m_prefabInputConfigEntry;
|
|
|
|
PdtRuleset _ruleset;
|
|
InputProxy _proxy;
|
|
readonly Dictionary<Identifier, InputConfigPanelEntry> _entries = new();
|
|
|
|
public void Load(PdtRuleset ruleset, RulesetConfig rulesetConfig) {
|
|
_ruleset = ruleset;
|
|
_proxy = new InputProxy(ruleset, null, new Vector2(Screen.width, Screen.height));
|
|
_proxy.LoadFrom(rulesetConfig.inputs);
|
|
|
|
foreach (var i in ruleset.inputs) {
|
|
var e = Instantiate(m_prefabInputConfigEntry, m_entryList.transform, false).GetComponent<InputConfigPanelEntry>();
|
|
_entries.Add(i.Key, e);
|
|
e.SetKey(this, i.Key);
|
|
OnProxyChanged(this, _proxy[i.Key]);
|
|
}
|
|
_proxy.ProxyChanged += OnProxyChanged;
|
|
}
|
|
|
|
Identifier _selectedEntry;
|
|
public void OpenDialog(Identifier entry) {
|
|
_selectedEntry = entry;
|
|
InputDialog.Show(OnDialogClosed, "Please input and select a device", _ruleset.inputs[entry], _proxy);
|
|
}
|
|
public void OnDialogClosed(InputSource? src) {
|
|
_proxy.Set(new InputProxyEntry {
|
|
Target = _selectedEntry,
|
|
Source = src,
|
|
});
|
|
}
|
|
|
|
void OnProxyChanged(object sender, ProxyChangedEventArgs e) {
|
|
_entries[e.Name].OnProxyChanged(e);
|
|
}
|
|
|
|
public void SaveTo(Dictionary<string, RulesetConfig.InputEntry> inputs) {
|
|
_proxy.SaveTo(inputs);
|
|
}
|
|
}
|
|
}
|