diff --git a/AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/Legacy/GamingChanger_Legacy.cs b/AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/Legacy/GamingChanger.cs similarity index 85% rename from AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/Legacy/GamingChanger_Legacy.cs rename to AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/Legacy/GamingChanger.cs index 250cee93..74575397 100644 --- a/AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/Legacy/GamingChanger_Legacy.cs +++ b/AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/Legacy/GamingChanger.cs @@ -3,10 +3,10 @@ using UnityEngine; namespace AxibugEmuOnline.Client { - public class GamingChanger_Legacy : CommandChanger + public class GamingChanger : CommandChanger { Dictionary m_uiKeyMapper = new Dictionary(); - public GamingChanger_Legacy() + public GamingChanger() { m_uiKeyMapper[KeyCode.Escape] = EnumCommand.OptionMenu; diff --git a/AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/Legacy/GamingChanger_Legacy.cs.meta b/AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/Legacy/GamingChanger.cs.meta similarity index 100% rename from AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/Legacy/GamingChanger_Legacy.cs.meta rename to AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/Legacy/GamingChanger.cs.meta diff --git a/AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/Legacy/NormalChanger_Legacy.cs b/AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/Legacy/NormalChanger.cs similarity index 90% rename from AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/Legacy/NormalChanger_Legacy.cs rename to AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/Legacy/NormalChanger.cs index 2d328d99..6f6d12ea 100644 --- a/AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/Legacy/NormalChanger_Legacy.cs +++ b/AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/Legacy/NormalChanger.cs @@ -1,17 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; using UnityEngine; namespace AxibugEmuOnline.Client { - public class NormalChanger_Legacy : CommandChanger + public class NormalChanger : CommandChanger { Dictionary m_uiKeyMapper = new Dictionary(); - public NormalChanger_Legacy() + public NormalChanger() { m_uiKeyMapper[KeyCode.A] = EnumCommand.SelectItemLeft; m_uiKeyMapper[KeyCode.D] = EnumCommand.SelectItemRight; diff --git a/AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/Legacy/NormalChanger_Legacy.cs.meta b/AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/Legacy/NormalChanger.cs.meta similarity index 100% rename from AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/Legacy/NormalChanger_Legacy.cs.meta rename to AxibugEmuOnline.Client/Assets/Script/IkeyMapperChanger/Legacy/NormalChanger.cs.meta diff --git a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesControllerMapper.cs b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesControllerMapper.cs index 3a5df6e4..7c055b89 100644 --- a/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesControllerMapper.cs +++ b/AxibugEmuOnline.Client/Assets/Script/NesEmulator/NesControllerMapper.cs @@ -40,7 +40,7 @@ namespace AxibugEmuOnline.Client private void loadConfig() { - m_keyListener = MapperSetter.GetKey_Legacy(m_controllerIndex, m_buttonType); + m_keyListener = MapperSetter.GetKey(m_controllerIndex, m_buttonType); } @@ -95,13 +95,13 @@ namespace AxibugEmuOnline.Client return res; } - public static IKeyListener GetKey_Legacy(int controllerInput, EnumButtonType nesConBtnType) + public static IKeyListener GetKey(int controllerInput, EnumButtonType nesConBtnType) { string configKey = $"NES_{controllerInput}_{nesConBtnType}"; if (PlayerPrefs.HasKey(configKey)) { - return new KeyListener_Legacy(PlayerPrefs.GetString(configKey)); + return new KeyListener(PlayerPrefs.GetString(configKey)); } else { @@ -110,31 +110,31 @@ namespace AxibugEmuOnline.Client return defaultKeyCode; } - KeyListener_Legacy GetDefaultKey() + KeyListener GetDefaultKey() { switch (controllerInput) { case 1: - if (nesConBtnType == EnumButtonType.LEFT) return new KeyListener_Legacy(KeyCode.A, KeyCode.Joystick1Button12); - if (nesConBtnType == EnumButtonType.RIGHT) return new KeyListener_Legacy(KeyCode.D, KeyCode.Joystick1Button13); - if (nesConBtnType == EnumButtonType.UP) return new KeyListener_Legacy(KeyCode.W, KeyCode.Joystick1Button10); - if (nesConBtnType == EnumButtonType.DOWN) return new KeyListener_Legacy(KeyCode.S, KeyCode.Joystick1Button11); - if (nesConBtnType == EnumButtonType.START) return new KeyListener_Legacy(KeyCode.B, KeyCode.Joystick1Button7); - if (nesConBtnType == EnumButtonType.SELECT) return new KeyListener_Legacy(KeyCode.V, KeyCode.Joystick1Button6); - if (nesConBtnType == EnumButtonType.A) return new KeyListener_Legacy(KeyCode.K, KeyCode.Joystick1Button1); - if (nesConBtnType == EnumButtonType.B) return new KeyListener_Legacy(KeyCode.J, KeyCode.Joystick1Button2); - if (nesConBtnType == EnumButtonType.MIC) return new KeyListener_Legacy(KeyCode.M, KeyCode.Joystick1Button12); + if (nesConBtnType == EnumButtonType.LEFT) return new KeyListener(KeyCode.A); + if (nesConBtnType == EnumButtonType.RIGHT) return new KeyListener(KeyCode.D); + if (nesConBtnType == EnumButtonType.UP) return new KeyListener(KeyCode.W); + if (nesConBtnType == EnumButtonType.DOWN) return new KeyListener(KeyCode.S); + if (nesConBtnType == EnumButtonType.START) return new KeyListener(KeyCode.B); + if (nesConBtnType == EnumButtonType.SELECT) return new KeyListener(KeyCode.V); + if (nesConBtnType == EnumButtonType.A) return new KeyListener(KeyCode.K); + if (nesConBtnType == EnumButtonType.B) return new KeyListener(KeyCode.J); + if (nesConBtnType == EnumButtonType.MIC) return new KeyListener(KeyCode.M); break; case 2: - if (nesConBtnType == EnumButtonType.LEFT) return new KeyListener_Legacy(KeyCode.Delete, KeyCode.Joystick2Button12); - if (nesConBtnType == EnumButtonType.RIGHT) return new KeyListener_Legacy(KeyCode.PageDown, KeyCode.Joystick2Button13); - if (nesConBtnType == EnumButtonType.UP) return new KeyListener_Legacy(KeyCode.Home, KeyCode.Joystick2Button10); - if (nesConBtnType == EnumButtonType.DOWN) return new KeyListener_Legacy(KeyCode.End, KeyCode.Joystick2Button11); - if (nesConBtnType == EnumButtonType.START) return new KeyListener_Legacy(KeyCode.PageUp, KeyCode.Joystick2Button7); - if (nesConBtnType == EnumButtonType.SELECT) return new KeyListener_Legacy(KeyCode.Insert, KeyCode.Joystick2Button6); - if (nesConBtnType == EnumButtonType.A) return new KeyListener_Legacy(KeyCode.Keypad5, KeyCode.Joystick2Button1); - if (nesConBtnType == EnumButtonType.B) return new KeyListener_Legacy(KeyCode.Keypad4, KeyCode.Joystick2Button2); - if (nesConBtnType == EnumButtonType.MIC) return new KeyListener_Legacy(KeyCode.KeypadPeriod, KeyCode.Joystick2Button12); + if (nesConBtnType == EnumButtonType.LEFT) return new KeyListener(KeyCode.Delete); + if (nesConBtnType == EnumButtonType.RIGHT) return new KeyListener(KeyCode.PageDown); + if (nesConBtnType == EnumButtonType.UP) return new KeyListener(KeyCode.Home); + if (nesConBtnType == EnumButtonType.DOWN) return new KeyListener(KeyCode.End); + if (nesConBtnType == EnumButtonType.START) return new KeyListener(KeyCode.PageUp); + if (nesConBtnType == EnumButtonType.SELECT) return new KeyListener(KeyCode.Insert); + if (nesConBtnType == EnumButtonType.A) return new KeyListener(KeyCode.Keypad5); + if (nesConBtnType == EnumButtonType.B) return new KeyListener(KeyCode.Keypad4); + if (nesConBtnType == EnumButtonType.MIC) return new KeyListener(KeyCode.KeypadPeriod); break; } @@ -149,56 +149,36 @@ namespace AxibugEmuOnline.Client bool IsPressing(); } - public struct KeyListener_Legacy : IKeyListener + public struct KeyListener : IKeyListener { - private KeyCode[] m_keys; + private KeyCode m_key; - public KeyListener_Legacy(params KeyCode[] keys) + public KeyListener(KeyCode key) { - m_keys = keys; + m_key = key; } /// /// 从配置表字符串构建 /// - /// 以:分割的键值字符串 - public KeyListener_Legacy(string confStr) + public KeyListener(string confStr) { - m_keys = new KeyCode[2]; + m_key = KeyCode.None; - var temp = confStr.Split(':'); - m_keys = new KeyCode[temp.Length]; - for (int i = 0; i < temp.Length; i++) - { - if (int.TryParse(temp[i], out int result)) - m_keys[i] = (KeyCode)result; - } + if (int.TryParse(confStr, out int result)) + m_key = (KeyCode)result; } - public bool IsPressing() + public readonly bool IsPressing() { - if (m_keys == null || m_keys.Length == 0) return false; - - foreach (var key in m_keys) - { - if (Input.GetKey(key)) return true; - } + if (Input.GetKey(m_key)) return true; return false; } public override string ToString() { - if (m_keys == null || m_keys.Length == 0) return string.Empty; - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < m_keys.Length; i++) - { - var keyVal = (int)m_keys[i]; - sb.Append(keyVal); - if (i != m_keys.Length - 1) sb.Append(':'); - } - - return sb.ToString(); + return ((int)(m_key)).ToString(); } } } diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandDispatcher.cs b/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandDispatcher.cs index 1e651cc0..1631ee93 100644 --- a/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandDispatcher.cs +++ b/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandDispatcher.cs @@ -36,11 +36,11 @@ namespace AxibugEmuOnline.Client Instance = this; //ʼcommand - m_listener = new CommandListener_Legacy(); + m_listener = new CommandListener(); //ʼλ޸ - Normal = new NormalChanger_Legacy(); - Gaming = new GamingChanger_Legacy(); + Normal = new NormalChanger(); + Gaming = new GamingChanger(); } private void OnDestroy() diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandListener_Legacy.cs b/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandListener.cs similarity index 92% rename from AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandListener_Legacy.cs rename to AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandListener.cs index 8598135b..2eb5f9d9 100644 --- a/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandListener_Legacy.cs +++ b/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandListener.cs @@ -3,7 +3,7 @@ using UnityEngine; namespace AxibugEmuOnline.Client { - public class CommandListener_Legacy : ICommandListener + public class CommandListener : ICommandListener { Dictionary m_keyMapper = new Dictionary(); List m_commands = new List(); diff --git a/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandListener_Legacy.cs.meta b/AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandListener.cs.meta similarity index 100% rename from AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandListener_Legacy.cs.meta rename to AxibugEmuOnline.Client/Assets/Script/UI/CommandDispatcher/CommandListener.cs.meta