Implement the new input config.
This commit is contained in:
@@ -25,9 +25,11 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
public RulesetDefinition ruleset;
|
public RulesetDefinition ruleset;
|
||||||
RulesetConfig _rscfg;
|
RulesetConfig _rscfg;
|
||||||
|
|
||||||
|
string _rulesetName;
|
||||||
bool _loaded;
|
bool _loaded;
|
||||||
|
|
||||||
public void Load(string rulesetName) {
|
public void Load(string rulesetName) {
|
||||||
|
_rulesetName = rulesetName;
|
||||||
FileInfo file = new FileInfo(Path.Combine(
|
FileInfo file = new FileInfo(Path.Combine(
|
||||||
Game.GameDataPath, "rulesets", rulesetName, ".umgr"
|
Game.GameDataPath, "rulesets", rulesetName, ".umgr"
|
||||||
));
|
));
|
||||||
@@ -59,12 +61,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
|
|
||||||
m_genericConfigPanel.Adapter = new DefaultPropertyMasterAdapter(_rscfg.generic);
|
m_genericConfigPanel.Adapter = new DefaultPropertyMasterAdapter(_rscfg.generic);
|
||||||
m_rulesetConfigPanel.Adapter = new RulesetConfigPropertyMasterAdapter(ruleset.Root.configs, _rscfg.configs);
|
m_rulesetConfigPanel.Adapter = new RulesetConfigPropertyMasterAdapter(ruleset.Root.configs, _rscfg.configs);
|
||||||
|
m_inputConfigPanel.Load(ruleset.Root, _rscfg);
|
||||||
//var proxy = new InputProxy(ruleset.Root, null, new Vector2(Screen.width, Screen.height));
|
|
||||||
//proxy.LoadFrom(_rscfg.inputs);
|
|
||||||
//m_inputConfigPanel.proxy = proxy;
|
|
||||||
|
|
||||||
//m_inputConfigPanel.OnConfigEnable();
|
|
||||||
|
|
||||||
_loaded = true;
|
_loaded = true;
|
||||||
}
|
}
|
||||||
@@ -78,15 +75,13 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
|
|
||||||
void OnDisable() {
|
void OnDisable() {
|
||||||
if (_loaded) {
|
if (_loaded) {
|
||||||
//m_inputConfigPanel.proxy.SaveTo(_rscfg.inputs);
|
m_inputConfigPanel.SaveTo(_rscfg.inputs);
|
||||||
//m_inputConfigPanel.proxy.Dispose();
|
FileInfo cfgFile = new FileInfo(Path.Combine(
|
||||||
//FileInfo cfgfile = new FileInfo(Path.Combine(
|
Game.GameDataPath, "config", "rulesets", _rulesetName + ".json"
|
||||||
// Game.GameDataPath, "config", "rulesets", Settings.Default.LoadRulesetConfig
|
));
|
||||||
//));
|
using (StreamWriter cfgWriter = new StreamWriter(cfgFile.FullName, false, Encoding.UTF8)) {
|
||||||
//using (StreamWriter cfgwriter = new StreamWriter(cfgfile.FullName, false, Encoding.UTF8)) {
|
cfgWriter.Write(JsonConvert.SerializeObject(_rscfg, Game.GlobalJsonSerializerSettings));
|
||||||
// cfgwriter.Write(JsonConvert.SerializeObject(_rscfg, Game.GlobalJsonSerializerSettings));
|
}
|
||||||
//}
|
|
||||||
//m_inputConfigPanel.OnConfigDisable();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,155 +4,51 @@ using Cryville.Input;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
|
||||||
|
|
||||||
namespace Cryville.Crtr.Config.UI {
|
namespace Cryville.Crtr.Config.UI {
|
||||||
public class InputConfigPanel : MonoBehaviour {
|
internal class InputConfigPanel : MonoBehaviour {
|
||||||
[SerializeField]
|
|
||||||
ConfigPanelMaster m_configScene;
|
|
||||||
|
|
||||||
[SerializeField]
|
|
||||||
GameObject m_inputDialog;
|
|
||||||
|
|
||||||
[SerializeField]
|
|
||||||
Transform m_deviceList;
|
|
||||||
|
|
||||||
[SerializeField]
|
|
||||||
GameObject m_prefabListItem;
|
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
Transform m_entryList;
|
Transform m_entryList;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject m_prefabInputConfigEntry;
|
GameObject m_prefabInputConfigEntry;
|
||||||
|
|
||||||
SimpleInputConsumer _consumer;
|
PdtRuleset _ruleset;
|
||||||
public InputProxy proxy;
|
InputProxy _proxy;
|
||||||
readonly Dictionary<Identifier, InputConfigPanelEntry> _entries = new Dictionary<Identifier, InputConfigPanelEntry>();
|
readonly Dictionary<Identifier, InputConfigPanelEntry> _entries = new Dictionary<Identifier, InputConfigPanelEntry>();
|
||||||
|
|
||||||
int _applicableEntries;
|
public void Load(PdtRuleset ruleset, RulesetConfig rulesetConfig) {
|
||||||
Identifier _sel;
|
_ruleset = ruleset;
|
||||||
int _targetDim;
|
_proxy = new InputProxy(ruleset, null, new Vector2(Screen.width, Screen.height));
|
||||||
PhysicalDimension? _targetPDim;
|
_proxy.LoadFrom(rulesetConfig.inputs);
|
||||||
bool _targetNotNull;
|
|
||||||
public void OpenDialog(Identifier entry) {
|
|
||||||
_sel = entry;
|
|
||||||
var def = m_configScene.ruleset.Root.inputs[_sel];
|
|
||||||
_targetDim = def.dim;
|
|
||||||
if (def.pdim != null) _targetPDim = ParsePhysicalDimension(def.pdim);
|
|
||||||
else _targetPDim = null;
|
|
||||||
_targetNotNull = def.notnull;
|
|
||||||
m_inputDialog.SetActive(true);
|
|
||||||
foreach (Transform i in m_deviceList) Destroy(i.gameObject);
|
|
||||||
_consumer.EnumerateEvents(ev => { });
|
|
||||||
_recvsrcs.Clear();
|
|
||||||
_applicableEntries = 1;
|
|
||||||
AddSourceItem(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PhysicalDimension ParsePhysicalDimension(string str) {
|
foreach (var i in ruleset.inputs) {
|
||||||
var comps = str.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
var e = Instantiate(m_prefabInputConfigEntry, m_entryList.transform, false).GetComponent<InputConfigPanelEntry>();
|
||||||
var result = new PhysicalDimension();
|
|
||||||
foreach (var comp in comps) {
|
|
||||||
int dim = 1;
|
|
||||||
if (comp.Length > 1) dim = int.Parse(comp.Substring(1));
|
|
||||||
switch (comp[0]) {
|
|
||||||
case 'T': result.Time += dim; break;
|
|
||||||
case 'L': result.Length += dim; break;
|
|
||||||
case 'M': result.Mass += dim; break;
|
|
||||||
case 'I': result.ElectricCurrent += dim; break;
|
|
||||||
case '\x0398':
|
|
||||||
case 'H': result.ThermodynamicTemperature += dim; break;
|
|
||||||
case 'N': result.AmountOfSubstance += dim; break;
|
|
||||||
case 'J': result.LuminousIntensity += dim; break;
|
|
||||||
default: throw new ArgumentException(string.Format("Invalid dimension symbol {0}", comp[0]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void CloseDialog() {
|
|
||||||
m_inputDialog.SetActive(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void CloseDialog(InputSource? src) {
|
|
||||||
proxy.Set(new InputProxyEntry {
|
|
||||||
Target = _sel,
|
|
||||||
Source = src,
|
|
||||||
});
|
|
||||||
CloseDialog();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnConfigEnable() {
|
|
||||||
foreach (Transform i in m_entryList) Destroy(i.gameObject);
|
|
||||||
_entries.Clear();
|
|
||||||
_consumer = new SimpleInputConsumer(Game.InputManager);
|
|
||||||
_consumer.Activate();
|
|
||||||
foreach (var i in m_configScene.ruleset.Root.inputs) {
|
|
||||||
var e = Instantiate(m_prefabInputConfigEntry, m_entryList.transform).GetComponent<InputConfigPanelEntry>();
|
|
||||||
_entries.Add(i.Key, e);
|
_entries.Add(i.Key, e);
|
||||||
e.SetKey(this, i.Key);
|
e.SetKey(this, i.Key);
|
||||||
OnProxyChanged(this, proxy[i.Key]);
|
OnProxyChanged(this, _proxy[i.Key]);
|
||||||
}
|
}
|
||||||
proxy.ProxyChanged += OnProxyChanged;
|
_proxy.ProxyChanged += OnProxyChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnConfigDisable() {
|
Identifier _selectedEntry;
|
||||||
_consumer.Deactivate();
|
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) {
|
void OnProxyChanged(object sender, ProxyChangedEventArgs e) {
|
||||||
_entries[e.Name].OnProxyChanged(e);
|
_entries[e.Name].OnProxyChanged(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Start() {
|
public void SaveTo(Dictionary<string, RulesetConfig.InputEntry> inputs) {
|
||||||
_d_HandleInputEvent = HandleInputEvent;
|
_proxy.SaveTo(inputs);
|
||||||
}
|
|
||||||
|
|
||||||
readonly List<InputSource?> _recvsrcs = new List<InputSource?>();
|
|
||||||
void Update() {
|
|
||||||
if (m_inputDialog.activeSelf) {
|
|
||||||
_consumer.EnumerateEvents(_d_HandleInputEvent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Action<InputEvent> _d_HandleInputEvent;
|
|
||||||
void HandleInputEvent(InputEvent ev) {
|
|
||||||
AddSourceItem(ev.Identifier.Source);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AddSourceItem(InputSource? src) {
|
|
||||||
if (_recvsrcs.Contains(src)) return;
|
|
||||||
_recvsrcs.Add(src);
|
|
||||||
var obj = Instantiate(m_prefabListItem, m_deviceList);
|
|
||||||
var text = obj.transform.Find("Text").GetComponent<Text>();
|
|
||||||
text.text = src == null ? "(None)" : src.Value.Handler.GetTypeName(src.Value.Type);
|
|
||||||
var btn = obj.GetComponent<Button>();
|
|
||||||
if (src != null) {
|
|
||||||
var tsrc = src.Value;
|
|
||||||
bool flag = false;
|
|
||||||
if (proxy.IsUsed(tsrc)) {
|
|
||||||
text.text += " <size=9>(Used)</size>";
|
|
||||||
}
|
|
||||||
else if (tsrc.Handler.Dimension < _targetDim) {
|
|
||||||
text.text += " <size=9>(Not Applicable)</size>";
|
|
||||||
}
|
|
||||||
else if (_targetPDim != null && tsrc.Handler.ReferenceCue.PhysicalDimension != _targetPDim) {
|
|
||||||
text.text += " <size=9>(Not Applicable)</size>";
|
|
||||||
}
|
|
||||||
else if (!_targetNotNull && !tsrc.Handler.IsNullable) {
|
|
||||||
text.text += " <size=9>(Not Applicable)</size>";
|
|
||||||
}
|
|
||||||
else flag = true;
|
|
||||||
btn.interactable = flag;
|
|
||||||
obj.transform.SetSiblingIndex(flag ? _applicableEntries++ : m_deviceList.childCount - 1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
obj.transform.SetSiblingIndex(0);
|
|
||||||
}
|
|
||||||
btn.onClick.AddListener(() => {
|
|
||||||
CloseDialog(src);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,15 @@
|
|||||||
using Cryville.Common;
|
using Cryville.Common;
|
||||||
using Cryville.Crtr.Ruleset;
|
using Cryville.Crtr.Ruleset;
|
||||||
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Config.UI {
|
namespace Cryville.Crtr.Config.UI {
|
||||||
public class InputConfigPanelEntry : MonoBehaviour {
|
internal class InputConfigPanelEntry : MonoBehaviour {
|
||||||
[SerializeField]
|
[SerializeField] TextMeshProUGUI m_key;
|
||||||
Text m_key;
|
[SerializeField] TextMeshProUGUI m_value;
|
||||||
|
[SerializeField] Button m_button;
|
||||||
[SerializeField]
|
|
||||||
Text m_value;
|
|
||||||
|
|
||||||
[SerializeField]
|
|
||||||
Button m_button;
|
|
||||||
|
|
||||||
public void SetKey(InputConfigPanel master, Identifier name) {
|
public void SetKey(InputConfigPanel master, Identifier name) {
|
||||||
m_key.text = (string)name.Name;
|
m_key.text = (string)name.Name;
|
||||||
@@ -39,7 +35,7 @@ namespace Cryville.Crtr.Config.UI {
|
|||||||
m_value.text = e.Proxy.Value.Handler.GetTypeName(e.Proxy.Value.Type);
|
m_value.text = e.Proxy.Value.Handler.GetTypeName(e.Proxy.Value.Type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_value.color = e.Required ? Color.yellow : Color.black;
|
m_value.color = e.Required ? Color.yellow : Color.white;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
12
Assets/Cryville/Crtr/Config/UI/InputDeviceStatus.cs
Normal file
12
Assets/Cryville/Crtr/Config/UI/InputDeviceStatus.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Config.UI {
|
||||||
|
[Flags]
|
||||||
|
public enum InputDeviceStatus {
|
||||||
|
Default = 0x00,
|
||||||
|
Used = 0x01,
|
||||||
|
InsufficientDimension = 0x02,
|
||||||
|
IncompatiblePhysicalDimension = 0x04,
|
||||||
|
IncompatibleNullable = 0x08,
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Cryville/Crtr/Config/UI/InputDeviceStatus.cs.meta
Normal file
11
Assets/Cryville/Crtr/Config/UI/InputDeviceStatus.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: aa74ad1769b9e1442b4659fbad2feb59
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
135
Assets/Cryville/Crtr/Config/UI/InputDialog.cs
Normal file
135
Assets/Cryville/Crtr/Config/UI/InputDialog.cs
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
using Cryville.Crtr.Ruleset;
|
||||||
|
using Cryville.Input;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Config.UI {
|
||||||
|
internal class InputDialog : MonoBehaviour {
|
||||||
|
static InputDialog _instance;
|
||||||
|
[SerializeField] CanvasGroup m_group;
|
||||||
|
[SerializeField] AnimationCurve m_fadeCurve;
|
||||||
|
[SerializeField] TextMeshProUGUI m_msgText;
|
||||||
|
[SerializeField] Transform m_deviceList;
|
||||||
|
[SerializeField] GameObject m_deviceItemPrefab;
|
||||||
|
float _fadeDuration;
|
||||||
|
void Awake() {
|
||||||
|
_instance = this;
|
||||||
|
_fadeDuration = m_fadeCurve[m_fadeCurve.length - 1].time;
|
||||||
|
_consumer = new SimpleInputConsumer(Game.InputManager);
|
||||||
|
_d_HandleInputEvent = HandleInputEvent;
|
||||||
|
}
|
||||||
|
float _timer;
|
||||||
|
bool _active;
|
||||||
|
Action<InputSource?> _callback;
|
||||||
|
|
||||||
|
InputProxy _proxy;
|
||||||
|
int _applicableEntries;
|
||||||
|
int _targetDim;
|
||||||
|
PhysicalDimension? _targetPDim;
|
||||||
|
bool _targetNotNull;
|
||||||
|
readonly Dictionary<InputSource, InputDialogEntry> _recvsrcs = new Dictionary<InputSource, InputDialogEntry>();
|
||||||
|
void ShowInternal(Action<InputSource?> callback, string message, InputDefinition def, InputProxy proxy) {
|
||||||
|
_active = true;
|
||||||
|
_callback = callback;
|
||||||
|
m_group.gameObject.SetActive(true);
|
||||||
|
m_msgText.text = message;
|
||||||
|
_proxy = proxy;
|
||||||
|
|
||||||
|
_targetDim = def.dim;
|
||||||
|
if (def.pdim != null) _targetPDim = ParsePhysicalDimension(def.pdim);
|
||||||
|
else _targetPDim = null;
|
||||||
|
_targetNotNull = def.notnull;
|
||||||
|
|
||||||
|
foreach (Transform i in m_deviceList) Destroy(i.gameObject);
|
||||||
|
_consumer.EnumerateEvents(ev => { });
|
||||||
|
_recvsrcs.Clear();
|
||||||
|
_applicableEntries = 1;
|
||||||
|
AddSourceItem(null).transform.SetSiblingIndex(0);
|
||||||
|
}
|
||||||
|
public static void Show(Action<InputSource?> callback, string message, InputDefinition def, InputProxy proxy) {
|
||||||
|
_instance.ShowInternal(callback, message, def, proxy);
|
||||||
|
}
|
||||||
|
static PhysicalDimension ParsePhysicalDimension(string str) {
|
||||||
|
var comps = str.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
var result = new PhysicalDimension();
|
||||||
|
foreach (var comp in comps) {
|
||||||
|
int dim = 1;
|
||||||
|
if (comp.Length > 1) dim = int.Parse(comp.Substring(1));
|
||||||
|
switch (comp[0]) {
|
||||||
|
case 'T': result.Time += dim; break;
|
||||||
|
case 'L': result.Length += dim; break;
|
||||||
|
case 'M': result.Mass += dim; break;
|
||||||
|
case 'I': result.ElectricCurrent += dim; break;
|
||||||
|
case '\x0398':
|
||||||
|
case 'H': result.ThermodynamicTemperature += dim; break;
|
||||||
|
case 'N': result.AmountOfSubstance += dim; break;
|
||||||
|
case 'J': result.LuminousIntensity += dim; break;
|
||||||
|
default: throw new ArgumentException(string.Format("Invalid dimension symbol {0}", comp[0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update() {
|
||||||
|
if (_active) {
|
||||||
|
_consumer.EnumerateEvents(_d_HandleInputEvent);
|
||||||
|
if (_timer >= _fadeDuration) return;
|
||||||
|
_timer += Time.deltaTime;
|
||||||
|
if (_timer > _fadeDuration) _timer = _fadeDuration;
|
||||||
|
m_group.alpha = m_fadeCurve.Evaluate(_timer);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (_timer <= 0) return;
|
||||||
|
_timer -= Time.deltaTime;
|
||||||
|
if (_timer < 0) {
|
||||||
|
_timer = 0;
|
||||||
|
m_group.gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
m_group.alpha = m_fadeCurve.Evaluate(_timer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SimpleInputConsumer _consumer;
|
||||||
|
void OnEnable() { _consumer.Activate(); }
|
||||||
|
void OnDisable() { _consumer.Deactivate(); }
|
||||||
|
|
||||||
|
Action<InputEvent> _d_HandleInputEvent;
|
||||||
|
void HandleInputEvent(InputEvent ev) {
|
||||||
|
InputSource src = ev.Identifier.Source;
|
||||||
|
InputDialogEntry entry;
|
||||||
|
if (!_recvsrcs.TryGetValue(src, out entry)) {
|
||||||
|
_recvsrcs.Add(src, entry = AddSourceItem(src));
|
||||||
|
if (_proxy.IsUsed(src)) {
|
||||||
|
entry.Status |= InputDeviceStatus.Used;
|
||||||
|
}
|
||||||
|
if (src.Handler.Dimension < _targetDim) {
|
||||||
|
entry.Status |= InputDeviceStatus.InsufficientDimension;
|
||||||
|
}
|
||||||
|
if (_targetPDim != null && src.Handler.ReferenceCue.PhysicalDimension != _targetPDim) {
|
||||||
|
entry.Status |= InputDeviceStatus.IncompatiblePhysicalDimension;
|
||||||
|
}
|
||||||
|
if (!_targetNotNull && !src.Handler.IsNullable) {
|
||||||
|
entry.Status |= InputDeviceStatus.IncompatibleNullable;
|
||||||
|
}
|
||||||
|
entry.transform.SetSiblingIndex(entry.Status == InputDeviceStatus.Default ? _applicableEntries++ : m_deviceList.childCount - 1);
|
||||||
|
}
|
||||||
|
entry.OnInputEvent(ev);
|
||||||
|
}
|
||||||
|
InputDialogEntry AddSourceItem(InputSource? src) {
|
||||||
|
var entry = Instantiate(m_deviceItemPrefab, m_deviceList, false).GetComponent<InputDialogEntry>();
|
||||||
|
entry.Init(src);
|
||||||
|
entry.Clicked += () => OnItemSelected(src);
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
void OnItemSelected(InputSource? src) {
|
||||||
|
if (!_active) return;
|
||||||
|
_active = false;
|
||||||
|
_callback(src);
|
||||||
|
}
|
||||||
|
public void Close() {
|
||||||
|
_active = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Cryville/Crtr/Config/UI/InputDialog.cs.meta
Normal file
11
Assets/Cryville/Crtr/Config/UI/InputDialog.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b25b6477a93b5f64495739801fbdb19d
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
101
Assets/Cryville/Crtr/Config/UI/InputDialogEntry.cs
Normal file
101
Assets/Cryville/Crtr/Config/UI/InputDialogEntry.cs
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
using Cryville.Input;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
namespace Cryville.Crtr.Config.UI {
|
||||||
|
internal class InputDialogEntry : MonoBehaviour, IPointerClickHandler {
|
||||||
|
[SerializeField] Button m_button;
|
||||||
|
[SerializeField] TextMeshProUGUI m_nameText;
|
||||||
|
[SerializeField] Graphic m_iNull;
|
||||||
|
[SerializeField] Graphic m_iX;
|
||||||
|
[SerializeField] Graphic m_iY;
|
||||||
|
[SerializeField] Graphic m_iZ;
|
||||||
|
[SerializeField] Graphic m_iW;
|
||||||
|
[SerializeField] Color m_invalidColor;
|
||||||
|
[SerializeField] Color m_inactiveColor;
|
||||||
|
[SerializeField] Color m_activeColor;
|
||||||
|
[SerializeField] Color m_restColor;
|
||||||
|
[SerializeField] Color m_motionColor;
|
||||||
|
private InputDeviceStatus status;
|
||||||
|
|
||||||
|
public event Action Clicked;
|
||||||
|
public InputDeviceStatus Status {
|
||||||
|
get { return status; }
|
||||||
|
set {
|
||||||
|
status = value;
|
||||||
|
m_button.interactable = value == InputDeviceStatus.Default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
byte _dim;
|
||||||
|
|
||||||
|
void Awake() {
|
||||||
|
_activeInputs = new Dictionary<int, InputVector>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Init(InputSource? src) {
|
||||||
|
m_nameText.text = src == null ? "(None)" : src.Value.Handler.GetTypeName(src.Value.Type);
|
||||||
|
if (src == null) {
|
||||||
|
m_iNull.color = m_invalidColor;
|
||||||
|
m_iX.color = m_invalidColor;
|
||||||
|
m_iY.color = m_invalidColor;
|
||||||
|
m_iZ.color = m_invalidColor;
|
||||||
|
m_iW.color = m_invalidColor;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var tsrc = src.Value;
|
||||||
|
_dim = tsrc.Handler.Dimension;
|
||||||
|
m_iNull.color = m_inactiveColor;
|
||||||
|
m_iX.color = _dim >= 1 ? m_restColor : m_invalidColor;
|
||||||
|
m_iY.color = _dim >= 2 ? m_restColor : m_invalidColor;
|
||||||
|
m_iZ.color = _dim >= 3 ? m_restColor : m_invalidColor;
|
||||||
|
m_iW.color = _dim >= 4 ? m_restColor : m_invalidColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void OnPointerClick(PointerEventData eventData) {
|
||||||
|
if (status != InputDeviceStatus.Default) return;
|
||||||
|
Clicked?.Invoke();
|
||||||
|
}
|
||||||
|
|
||||||
|
float _maxScalar;
|
||||||
|
Dictionary<int, InputVector> _activeInputs;
|
||||||
|
public void OnInputEvent(InputEvent ev) {
|
||||||
|
var id = ev.Identifier.Id;
|
||||||
|
InputVector lastVec;
|
||||||
|
if (!_activeInputs.TryGetValue(id, out lastVec)) {
|
||||||
|
if (ev.To.IsNull) return;
|
||||||
|
_activeInputs.Add(id, lastVec = ev.To.Vector);
|
||||||
|
}
|
||||||
|
if (ev.To.IsNull) {
|
||||||
|
_activeInputs.Remove(id);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var vec = ev.To.Vector;
|
||||||
|
var delta = vec - lastVec;
|
||||||
|
if (_dim >= 1) {
|
||||||
|
UpdateVectorIndicator(m_iX, delta.X);
|
||||||
|
if (_dim >= 2) {
|
||||||
|
UpdateVectorIndicator(m_iY, delta.Y);
|
||||||
|
if (_dim >= 3) {
|
||||||
|
UpdateVectorIndicator(m_iZ, delta.Z);
|
||||||
|
if (_dim >= 4) {
|
||||||
|
UpdateVectorIndicator(m_iW, delta.W);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_activeInputs[id] = vec;
|
||||||
|
}
|
||||||
|
m_iNull.color = _activeInputs.Count > 0 ? m_activeColor : m_inactiveColor;
|
||||||
|
}
|
||||||
|
void UpdateVectorIndicator(Graphic i, float v) {
|
||||||
|
float a = MathF.Abs(v);
|
||||||
|
if (a > _maxScalar) _maxScalar = a;
|
||||||
|
i.color = Color.Lerp(m_restColor, m_motionColor, MathF.Sqrt(a / _maxScalar));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Cryville/Crtr/Config/UI/InputDialogEntry.cs.meta
Normal file
11
Assets/Cryville/Crtr/Config/UI/InputDialogEntry.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d709b6ddbb7cdcf4d90ef334f8212e5f
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -8,11 +8,11 @@ namespace Cryville.Crtr.UI {
|
|||||||
public class Dialog : MonoBehaviour {
|
public class Dialog : MonoBehaviour {
|
||||||
static Dialog _instance;
|
static Dialog _instance;
|
||||||
[SerializeField] CanvasGroup m_group;
|
[SerializeField] CanvasGroup m_group;
|
||||||
|
[SerializeField] AnimationCurve m_fadeCurve;
|
||||||
[SerializeField] TextMeshProUGUI m_msgText;
|
[SerializeField] TextMeshProUGUI m_msgText;
|
||||||
[SerializeField] TextMeshProUGUI m_button0Text;
|
[SerializeField] TextMeshProUGUI m_button0Text;
|
||||||
[SerializeField] TextMeshProUGUI m_button1Text;
|
[SerializeField] TextMeshProUGUI m_button1Text;
|
||||||
[SerializeField] GameObject m_button1;
|
[SerializeField] GameObject m_button1;
|
||||||
[SerializeField] AnimationCurve m_fadeCurve;
|
|
||||||
float _fadeDuration;
|
float _fadeDuration;
|
||||||
static readonly Queue<DialogEntry> _queue = new Queue<DialogEntry>();
|
static readonly Queue<DialogEntry> _queue = new Queue<DialogEntry>();
|
||||||
struct DialogEntry {
|
struct DialogEntry {
|
||||||
|
|||||||
@@ -166,6 +166,7 @@ GameObject:
|
|||||||
m_Component:
|
m_Component:
|
||||||
- component: {fileID: 8904747856256340991}
|
- component: {fileID: 8904747856256340991}
|
||||||
- component: {fileID: 6854634130160612892}
|
- component: {fileID: 6854634130160612892}
|
||||||
|
- component: {fileID: 6654318315571261080}
|
||||||
m_Layer: 5
|
m_Layer: 5
|
||||||
m_Name: Input
|
m_Name: Input
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
@@ -224,6 +225,24 @@ MonoBehaviour:
|
|||||||
m_OnValueChanged:
|
m_OnValueChanged:
|
||||||
m_PersistentCalls:
|
m_PersistentCalls:
|
||||||
m_Calls: []
|
m_Calls: []
|
||||||
|
--- !u!114 &6654318315571261080
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 3963807688312625618}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 279d2404a312e5543813d8aca02800b8, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_inputDialog: {fileID: 0}
|
||||||
|
m_deviceList: {fileID: 2262770687481501371}
|
||||||
|
m_prefabListItem: {fileID: 0}
|
||||||
|
m_entryList: {fileID: 2262770687481501371}
|
||||||
|
m_prefabInputConfigEntry: {fileID: 6357043606454703996, guid: 34769273b0bb538499f5e87bb96869f1,
|
||||||
|
type: 3}
|
||||||
--- !u!1 &4062452046247846058
|
--- !u!1 &4062452046247846058
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -1472,7 +1491,7 @@ MonoBehaviour:
|
|||||||
m_content: {fileID: 7622410881835413525}
|
m_content: {fileID: 7622410881835413525}
|
||||||
m_genericConfigPanel: {fileID: 7622410882045729187}
|
m_genericConfigPanel: {fileID: 7622410882045729187}
|
||||||
m_rulesetConfigPanel: {fileID: 736145342796254613}
|
m_rulesetConfigPanel: {fileID: 736145342796254613}
|
||||||
m_inputConfigPanel: {fileID: 0}
|
m_inputConfigPanel: {fileID: 6654318315571261080}
|
||||||
--- !u!1 &7622410882278833983
|
--- !u!1 &7622410882278833983
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
495
Assets/Interface2/Prefabs/InputConfigEntry.prefab
Normal file
495
Assets/Interface2/Prefabs/InputConfigEntry.prefab
Normal file
File diff suppressed because it is too large
Load Diff
7
Assets/Interface2/Prefabs/InputConfigEntry.prefab.meta
Normal file
7
Assets/Interface2/Prefabs/InputConfigEntry.prefab.meta
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 34769273b0bb538499f5e87bb96869f1
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
871
Assets/Interface2/Prefabs/InputDialogEntry.prefab
Normal file
871
Assets/Interface2/Prefabs/InputDialogEntry.prefab
Normal file
File diff suppressed because it is too large
Load Diff
7
Assets/Interface2/Prefabs/InputDialogEntry.prefab.meta
Normal file
7
Assets/Interface2/Prefabs/InputDialogEntry.prefab.meta
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c58513c3234156946b0ba5b6e4917160
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user