|
@@ -2,21 +2,60 @@ using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using UnityEngine;
|
|
|
+using BepInEx.Configuration;
|
|
|
|
|
|
namespace COM3D2.MeidoPhotoStudio.Plugin
|
|
|
{
|
|
|
internal class InputManager
|
|
|
{
|
|
|
private static InputListener inputListener;
|
|
|
+ private static readonly Dictionary<MpsKey, KeyCode> ActionKeys = new Dictionary<MpsKey, KeyCode>();
|
|
|
+ private static readonly Dictionary<MpsKey, ConfigEntry<KeyCode>> ConfigEntries
|
|
|
+ = new Dictionary<MpsKey, ConfigEntry<KeyCode>>();
|
|
|
public static KeyCode CurrentKeyCode { get; private set; }
|
|
|
public static bool Listening { get; private set; }
|
|
|
public static event EventHandler KeyChange;
|
|
|
public static bool Control => Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);
|
|
|
public static bool Alt => Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt);
|
|
|
public static bool Shift => Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
|
|
|
- private static readonly Dictionary<MpsKey, KeyCode> Actions = new Dictionary<MpsKey, KeyCode>();
|
|
|
+ public static readonly AcceptableValueBase controlRange;
|
|
|
+ public const KeyCode upperKeyCode = KeyCode.F15;
|
|
|
+ public const string configHeader = "Controls";
|
|
|
|
|
|
- public static void Register(MpsKey action, KeyCode key) => Actions[action] = key;
|
|
|
+ static InputManager() => controlRange = new AcceptableValueRange<KeyCode>(default, upperKeyCode);
|
|
|
+
|
|
|
+ public static void Register(MpsKey action, KeyCode key, string description)
|
|
|
+ {
|
|
|
+ key = Clamp(key, default, upperKeyCode);
|
|
|
+ if (ConfigEntries.ContainsKey(action)) Rebind(action, key);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ConfigDescription configDescription = new ConfigDescription(description, controlRange);
|
|
|
+ ConfigEntries[action] = Configuration.Config.Bind(
|
|
|
+ configHeader, action.ToString(), key, configDescription
|
|
|
+ );
|
|
|
+ key = ConfigEntries[action].Value;
|
|
|
+ ActionKeys[action] = key;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void Rebind(MpsKey action, KeyCode key)
|
|
|
+ {
|
|
|
+ key = Clamp(key, default, upperKeyCode);
|
|
|
+ if (ConfigEntries.ContainsKey(action)) ConfigEntries[action].Value = key;
|
|
|
+ ActionKeys[action] = key;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static KeyCode Clamp(KeyCode value, KeyCode min, KeyCode max)
|
|
|
+ {
|
|
|
+ return value < min ? min : value > max ? max : value;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static KeyCode GetActionKey(MpsKey action)
|
|
|
+ {
|
|
|
+ ActionKeys.TryGetValue(action, out KeyCode keyCode);
|
|
|
+ return keyCode;
|
|
|
+ }
|
|
|
|
|
|
public static void StartListening()
|
|
|
{
|
|
@@ -35,16 +74,18 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
|
|
|
inputListener.gameObject.SetActive(false);
|
|
|
inputListener.KeyChange -= OnKeyChange;
|
|
|
CurrentKeyCode = KeyCode.None;
|
|
|
+ Listening = false;
|
|
|
+ Input.ResetInputAxes();
|
|
|
}
|
|
|
|
|
|
public static bool GetKey(MpsKey action)
|
|
|
{
|
|
|
- return (Listening || !Actions.ContainsKey(action)) ? false : Input.GetKey(Actions[action]);
|
|
|
+ return !Listening && ActionKeys.ContainsKey(action) && Input.GetKey(ActionKeys[action]);
|
|
|
}
|
|
|
|
|
|
public static bool GetKeyDown(MpsKey action)
|
|
|
{
|
|
|
- return (Listening || !Actions.ContainsKey(action)) ? false : Input.GetKeyDown(Actions[action]);
|
|
|
+ return !Listening && ActionKeys.ContainsKey(action) && Input.GetKeyDown(ActionKeys[action]);
|
|
|
}
|
|
|
|
|
|
public static void Deactivate()
|
|
@@ -71,7 +112,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
|
|
|
{
|
|
|
keyCodes = Enum.GetValues(typeof(KeyCode))
|
|
|
.Cast<KeyCode>()
|
|
|
- .Where(keyCode => keyCode < KeyCode.Numlock)
|
|
|
+ .Where(keyCode => keyCode <= upperKeyCode)
|
|
|
.ToArray();
|
|
|
}
|
|
|
|
|
@@ -96,7 +137,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
|
|
|
private class KeyChangeEventArgs : EventArgs
|
|
|
{
|
|
|
public KeyCode Key { get; }
|
|
|
- public KeyChangeEventArgs(KeyCode key) => this.Key = key;
|
|
|
+ public KeyChangeEventArgs(KeyCode key) => Key = key;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -109,8 +150,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
|
|
|
// Camera
|
|
|
CameraLayer, CameraReset, CameraSave, CameraLoad,
|
|
|
// Dragpoint
|
|
|
- DragSelect, DragDelete, DragMove, DragRotate, DragScale,
|
|
|
- DragFinger,
|
|
|
+ DragSelect, DragDelete, DragMove, DragRotate, DragScale, DragFinger,
|
|
|
// Scene management
|
|
|
SaveScene, LoadScene, OpenSceneManager
|
|
|
}
|