From 13c99dfb31d181a2131f2e49e7d5d54f68a71618 Mon Sep 17 00:00:00 2001 From: sin365 <353374337@qq.com> Date: Thu, 11 Sep 2025 10:29:09 +0800 Subject: [PATCH] =?UTF-8?q?NS=20=E5=BD=92=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Script/AppMain/AxiHttp/AxiHttpTest.cs | 51 +++++ .../AppMain/AxiHttp/AxiHttpTest.cs.meta | 2 + .../UEssgeeInterface/UEGKeyboard.cs | 4 +- .../StoicGooseInterface/SGKeyboard.cs | 209 ++++++++++++++++-- .../StoicGooseInterface/SGSoundPlayer.cs | 6 + .../StoicGooseEmulator/UStoicGoose.cs | 32 +-- .../Assets/Script/AppMain/Manager/AppRoom.cs | 14 +- .../KeyMapperSetting/KeyMapperSetting.cs | 1 + .../KeyMapperSetting/MAMEKeyBinding.cs | 4 +- .../KeyMapperSetting/Model/EmuCoreBinder.cs | 23 +- .../KeyMapperSetting/StoicGooseBinding.cs | 155 +++++++++++++ .../StoicGooseBinding.cs.meta | 2 + .../KeyMapperSetting/XMBKeyBinding.cs | 186 ++++++++++------ .../AppMain/Manager/ControllerInterface.cs | 14 +- .../Devices/InputControls/Stick_C.cs | 71 +++++- .../Devices/PSVController_D.cs | 12 + .../Script/AppMain/UI/InGameUI/InGameUI.cs | 11 +- .../UI/XMBTopGroupUI/ControllerInfo.cs | 13 +- .../UI/XMBTopGroupUI/ControllerInfoPanel.cs | 5 +- .../Assets/VirtualNes.Core/NES.cs | 5 +- 20 files changed, 677 insertions(+), 143 deletions(-) create mode 100644 AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/AxiHttp/AxiHttpTest.cs create mode 100644 AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/AxiHttp/AxiHttpTest.cs.meta create mode 100644 AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/StoicGooseBinding.cs create mode 100644 AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/StoicGooseBinding.cs.meta diff --git a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/AxiHttp/AxiHttpTest.cs b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/AxiHttp/AxiHttpTest.cs new file mode 100644 index 00000000..56b3d0fc --- /dev/null +++ b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/AxiHttp/AxiHttpTest.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections; +using UnityEngine; + +public class AxiHttpTest : MonoBehaviour +{ + // Start is called once before the first execution of Update after the MonoBehaviour is created + void Start() + { + + } + + // Update is called once per frame + void Update() + { + if (Input.GetKeyDown(KeyCode.T)) + { + //for (int i = 0; i < 1000; i++) + StartCoroutine(DownloadFromURL("http://emu.axibug.com/UserSav/12/Nes/190/1/1.sav", "D:/1.bin", null)); + } + } + + IEnumerator DownloadFromURL(string url, string path, Action callback) + { + + for (int i = 0; i < 1000; i++) + { + AxiHttpProxy.SendDownLoadProxy request = AxiHttpProxy.GetDownLoad(url); + + while (!request.downloadHandler.isDone) + { + Debug.Log($"下载进度:{request.downloadHandler.DownLoadPr} ->{request.downloadHandler.loadedLenght}/{request.downloadHandler.NeedloadedLenght}"); + yield return null; + } + AxiHttpProxy.ShowAxiHttpDebugInfo(request.downloadHandler); + Debug.Log($"下载进度完毕:data.Length=>" + request.downloadHandler.data.Length); + } + + + //if (!request.downloadHandler.bHadErr) + //{ + // AxiIO.Directory.CreateDirectory(path); + // AxiIO.File.WriteAllBytes($"{path}/{url.GetHashCode()}", request.downloadHandler.data, false); + // callback?.Invoke(request.downloadHandler.data); + //} + //else + //{ + // callback?.Invoke(null); + //} + } +} diff --git a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/AxiHttp/AxiHttpTest.cs.meta b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/AxiHttp/AxiHttpTest.cs.meta new file mode 100644 index 00000000..3c638f40 --- /dev/null +++ b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/AxiHttp/AxiHttpTest.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 873427ab0a955e64fa2444505ef0775c \ No newline at end of file diff --git a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGKeyboard.cs b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGKeyboard.cs index 409fee6e..040f2ef8 100644 --- a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGKeyboard.cs +++ b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGKeyboard.cs @@ -12,7 +12,7 @@ public class UEGKeyboard : MonoBehaviour { public EssgeeControllerMapper ControllerMapper { get; private set; } public Dictionary dictKey2Motion = new Dictionary(); - public Dictionary dictMotion2RealKey = new Dictionary() + /*public Dictionary dictMotion2RealKey = new Dictionary() { { EssgeeUnityKey.P1_UP,KeyCode.W}, { EssgeeUnityKey.P1_DOWN,KeyCode.S}, @@ -54,7 +54,7 @@ public class UEGKeyboard : MonoBehaviour { EssgeeUnityKey.P4_BTN_4,KeyCode.F12}, { EssgeeUnityKey.P4_POTION_1,KeyCode.F12}, { EssgeeUnityKey.P4_POTION_2,KeyCode.F12}, - }; + };*/ public ulong[] CheckList; public EssgeeMotionKey[] mCurrKey = new EssgeeMotionKey[0]; List temp = new List(); diff --git a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Emulator/StoicGooseEmulator/StoicGooseInterface/SGKeyboard.cs b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Emulator/StoicGooseEmulator/StoicGooseInterface/SGKeyboard.cs index 716f8f5d..7627204c 100644 --- a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Emulator/StoicGooseEmulator/StoicGooseInterface/SGKeyboard.cs +++ b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Emulator/StoicGooseEmulator/StoicGooseInterface/SGKeyboard.cs @@ -1,3 +1,6 @@ +using AxibugEmuOnline.Client.ClientCore; +using AxibugEmuOnline.Client.Event; +using AxibugEmuOnline.Client.Settings; using StoicGooseUnity; using System; using System.Collections.Generic; @@ -6,12 +9,14 @@ using UnityEngine; public class SGKeyboard : MonoBehaviour { - Dictionary dictKey2SGKey = new Dictionary(); - KeyCode[] checkKeys; + public SGControllerMapper ControllerMapper { get; private set; } + //Dictionary dictKey2SGKey = new Dictionary(); + //KeyCode[] checkKeys; long currInput; private void Awake() { - SetVerticalOrientation(false); + ControllerMapper = new SGControllerMapper(); + //SetVerticalOrientation(false); } @@ -22,31 +27,187 @@ public class SGKeyboard : MonoBehaviour internal void SetVerticalOrientation(bool isVerticalOrientation) { - dictKey2SGKey[KeyCode.Return] = StoicGooseKey.Start; - dictKey2SGKey[KeyCode.W] = StoicGooseKey.X1; - dictKey2SGKey[KeyCode.S] = StoicGooseKey.X2; - dictKey2SGKey[KeyCode.A] = StoicGooseKey.X3; - dictKey2SGKey[KeyCode.D] = StoicGooseKey.X4; - dictKey2SGKey[KeyCode.G] = StoicGooseKey.Y1; - dictKey2SGKey[KeyCode.V] = StoicGooseKey.Y2; - dictKey2SGKey[KeyCode.C] = StoicGooseKey.Y3; - dictKey2SGKey[KeyCode.B] = StoicGooseKey.Y4; - dictKey2SGKey[KeyCode.Return] = StoicGooseKey.Start; - dictKey2SGKey[KeyCode.J] = StoicGooseKey.B; - dictKey2SGKey[KeyCode.K] = StoicGooseKey.A; - checkKeys = dictKey2SGKey.Keys.ToArray(); + //TODO 横屏竖屏 + + //dictKey2SGKey[KeyCode.Return] = StoicGooseKey.Start; + //dictKey2SGKey[KeyCode.W] = StoicGooseKey.X1; + //dictKey2SGKey[KeyCode.S] = StoicGooseKey.X2; + //dictKey2SGKey[KeyCode.A] = StoicGooseKey.X3; + //dictKey2SGKey[KeyCode.D] = StoicGooseKey.X4; + //dictKey2SGKey[KeyCode.G] = StoicGooseKey.Y1; + //dictKey2SGKey[KeyCode.V] = StoicGooseKey.Y2; + //dictKey2SGKey[KeyCode.C] = StoicGooseKey.Y3; + //dictKey2SGKey[KeyCode.B] = StoicGooseKey.Y4; + //dictKey2SGKey[KeyCode.Return] = StoicGooseKey.Start; + //dictKey2SGKey[KeyCode.J] = StoicGooseKey.B; + //dictKey2SGKey[KeyCode.K] = StoicGooseKey.A; + //checkKeys = dictKey2SGKey.Keys.ToArray(); } - public void Update_InputData() + internal void SetInputData(ulong inputData) { - currInput = 0; - for (int i = 0; i < checkKeys.Length; i++) + currInput = (long)inputData; + } + + public ulong Update_InputData() + { + ulong tempLocalInputAllData = 0; + tempLocalInputAllData |= ControllerMapper.Controller0.GetSingleAllInput(); + tempLocalInputAllData |= ControllerMapper.Controller1.GetSingleAllInput(); + tempLocalInputAllData |= ControllerMapper.Controller2.GetSingleAllInput(); + tempLocalInputAllData |= ControllerMapper.Controller3.GetSingleAllInput(); + return tempLocalInputAllData; + //currInput = tempLocalInputAllData; + + //currInput = 0; + //for (int i = 0; i < checkKeys.Length; i++) + //{ + // KeyCode key = checkKeys[i]; + // if (Input.GetKey(key)) + // { + // currInput |= (long)dictKey2SGKey[key]; + // } + //} + } + +} + + + +public class SGControllerMapper : IControllerSetuper +{ + public SGController Controller0 = new SGController(0); + public SGController Controller1 = new SGController(1); + public SGController Controller2 = new SGController(2); + public SGController Controller3 = new SGController(3); + + ulong mCurrAllInput; + + public void SetConnect(uint? con0ToSlot = null, + uint? con1ToSlot = null, + uint? con2ToSlot = null, + uint? con3ToSlot = null) + { + Controller0.ConnectSlot = con0ToSlot; + Controller1.ConnectSlot = con1ToSlot; + Controller2.ConnectSlot = con2ToSlot; + Controller3.ConnectSlot = con3ToSlot; + } + public int? GetSlotConnectingControllerIndex(int slotIndex) + { + if (Controller0.ConnectSlot.HasValue && Controller0.ConnectSlot.Value == slotIndex) return 0; + else if (Controller1.ConnectSlot.HasValue && Controller1.ConnectSlot.Value == slotIndex) return 1; + else if (Controller2.ConnectSlot.HasValue && Controller2.ConnectSlot.Value == slotIndex) return 2; + else if (Controller3.ConnectSlot.HasValue && Controller3.ConnectSlot.Value == slotIndex) return 3; + else return null; + } + public IController GetSlotConnectingController(int slotIndex) + { + if (Controller0.ConnectSlot.HasValue && Controller0.ConnectSlot.Value == slotIndex) return Controller0; + else if (Controller1.ConnectSlot.HasValue && Controller1.ConnectSlot.Value == slotIndex) return Controller1; + else if (Controller2.ConnectSlot.HasValue && Controller2.ConnectSlot.Value == slotIndex) return Controller2; + else if (Controller3.ConnectSlot.HasValue && Controller3.ConnectSlot.Value == slotIndex) return Controller3; + else return null; + } + static HashSet s_temp = new HashSet(); + public uint? GetFreeSlotIndex() + { + s_temp.Clear(); + s_temp.Add(0); + s_temp.Add(1); + s_temp.Add(2); + s_temp.Add(3); + + if (Controller0.ConnectSlot.HasValue) s_temp.Remove(Controller0.ConnectSlot.Value); + if (Controller1.ConnectSlot.HasValue) s_temp.Remove(Controller1.ConnectSlot.Value); + if (Controller2.ConnectSlot.HasValue) s_temp.Remove(Controller2.ConnectSlot.Value); + if (Controller3.ConnectSlot.HasValue) s_temp.Remove(Controller3.ConnectSlot.Value); + + if (s_temp.Count > 0) return s_temp.First(); + else return null; + } + public void LetControllerConnect(int conIndex, uint slotIndex) + { + SGController targetController; + switch (conIndex) { - KeyCode key = checkKeys[i]; - if (Input.GetKey(key)) - { - currInput |= (long)dictKey2SGKey[key]; - } + case 0: targetController = Controller0; break; + case 1: targetController = Controller1; break; + case 2: targetController = Controller2; break; + case 3: targetController = Controller3; break; + default: + throw new System.Exception($"Not Allowed conIndex Range: {conIndex}"); + break; } + if (targetController.ConnectSlot.HasValue) return; + + targetController.ConnectSlot = slotIndex; + Eventer.Instance.PostEvent(EEvent.OnControllerConnectChanged); + } + +} +public class SGController : IController +{ + public ulong CurrLocalSingleAllInput { get; private set; } + + int mControllerIndex; + uint? mConnectSlot; + + /// + /// 指示该手柄连接的手柄插槽 + /// 这个值代表了该手柄在实际游戏中控制的Player + /// [0,3] 例外:为空代表未连接 + /// + public uint? ConnectSlot + { + get { return mConnectSlot; } + set { mConnectSlot = value; } + } + + /// + /// 控制器编号 + /// 此编号并非对应游戏中的player1,player2,player3,player4,仅仅作为本地4个手柄的实例 + /// [0,3] + /// + public int ControllerIndex + { + get { return mControllerIndex; } + set { mControllerIndex = value; /*this.LoadControlKeyForConfig();*/ } + } + + public SGController(int controllerIndex) + { + ControllerIndex = controllerIndex; + } + + public bool AnyButtonDown() + { + return GetKeyMapper().AnyKeyDown(mControllerIndex); + } + + public StoicGooseBinding GetKeyMapper() + { + return App.settings.KeyMapper.GetBinder(UStoicGoose.instance.Platform); + } + + public ulong GetSingleAllInput() + { + if (!ConnectSlot.HasValue) + return 0; + CurrLocalSingleAllInput = 0; + + StoicGooseBinding essgeeKeys = GetKeyMapper(); + + if (essgeeKeys.GetKey(StoicGooseKey.X1, mControllerIndex)) CurrLocalSingleAllInput |= (ulong)StoicGooseKey.X1; + if (essgeeKeys.GetKey(StoicGooseKey.X2, mControllerIndex)) CurrLocalSingleAllInput |= (ulong)StoicGooseKey.X2; + if (essgeeKeys.GetKey(StoicGooseKey.X3, mControllerIndex)) CurrLocalSingleAllInput |= (ulong)StoicGooseKey.X3; + if (essgeeKeys.GetKey(StoicGooseKey.X4, mControllerIndex)) CurrLocalSingleAllInput |= (ulong)StoicGooseKey.X4; + if (essgeeKeys.GetKey(StoicGooseKey.Y1, mControllerIndex)) CurrLocalSingleAllInput |= (ulong)StoicGooseKey.Y1; + if (essgeeKeys.GetKey(StoicGooseKey.Y2, mControllerIndex)) CurrLocalSingleAllInput |= (ulong)StoicGooseKey.Y2; + if (essgeeKeys.GetKey(StoicGooseKey.Y3, mControllerIndex)) CurrLocalSingleAllInput |= (ulong)StoicGooseKey.Y3; + if (essgeeKeys.GetKey(StoicGooseKey.Y4, mControllerIndex)) CurrLocalSingleAllInput |= (ulong)StoicGooseKey.Y4; + if (essgeeKeys.GetKey(StoicGooseKey.Start, mControllerIndex)) CurrLocalSingleAllInput |= (ulong)StoicGooseKey.Start; + + return CurrLocalSingleAllInput; } } \ No newline at end of file diff --git a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Emulator/StoicGooseEmulator/StoicGooseInterface/SGSoundPlayer.cs b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Emulator/StoicGooseEmulator/StoicGooseInterface/SGSoundPlayer.cs index 11279d35..c2b359b2 100644 --- a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Emulator/StoicGooseEmulator/StoicGooseInterface/SGSoundPlayer.cs +++ b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Emulator/StoicGooseEmulator/StoicGooseInterface/SGSoundPlayer.cs @@ -10,6 +10,12 @@ public class SGSoundPlayer : MonoBehaviour//, ISoundPlayer private TimeSpan lastElapsed; public double audioFPS { get; private set; } + //TODO 是否需要和 AudioConfiguration关联起来 + [HideInInspector] + public int sampleRate = 44100; + [HideInInspector] + public int channle = 2; + void Awake() { // 获取当前音频配置 diff --git a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Emulator/StoicGooseEmulator/UStoicGoose.cs b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Emulator/StoicGooseEmulator/UStoicGoose.cs index 0e56e0f8..5ad03b20 100644 --- a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Emulator/StoicGooseEmulator/UStoicGoose.cs +++ b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Emulator/StoicGooseEmulator/UStoicGoose.cs @@ -93,7 +93,6 @@ public class UStoicGoose : EmuCore Init(); - //淇濆瓨褰撳墠姝e湪杩涜鐨勬父鎴忓瓨妗 if (emulatorHandler != null && !emulatorHandler.IsRunning) { @@ -123,11 +122,17 @@ public class UStoicGoose : EmuCore public override IControllerSetuper GetControllerSetuper() { - throw new NotImplementedException(); + return inputHandler.ControllerMapper; } protected override bool OnPushEmulatorFrame(ulong InputData) { - throw new NotImplementedException(); + if (!emulatorHandler.IsRunning) return false; + //if (!bLogicUpdatePause) return false; + + inputHandler.SetInputData(InputData); + + emulatorHandler.Frame_Update(); + return true; } protected override ulong ConvertInputDataFromNet(ReplayStep step) @@ -142,17 +147,17 @@ public class UStoicGoose : EmuCore protected override ulong GetLocalInput() { - throw new NotImplementedException(); + return inputHandler.Update_InputData(); } protected override void AfterPushFrame() { - throw new NotImplementedException(); } public override void GetAudioParams(out int frequency, out int channels) { - throw new NotImplementedException(); + channels = soundHandler.channle; + frequency = soundHandler.sampleRate; } #endregion @@ -177,15 +182,16 @@ public class UStoicGoose : EmuCore //Init(); //LoadAndRunCartridge("G:/BaiduNetdiskDownload/Rockman & Forte - Mirai Kara no Chousen Sha (J) [M][!].ws"); } - private void Update() - { - if (!emulatorHandler.IsRunning) - return; - inputHandler.Update_InputData(); + //渚濋潬澶栭儴鏍稿績椹卞姩 + //private void Update() + //{ + // if (!emulatorHandler.IsRunning) + // return; + // inputHandler.Update_InputData(); + // emulatorHandler.Frame_Update(); + //} - emulatorHandler.Frame_Update(); - } void OnDestroy() { EmuClose(); diff --git a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppRoom.cs b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppRoom.cs index 0d53f380..5aced996 100644 --- a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppRoom.cs +++ b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppRoom.cs @@ -408,27 +408,28 @@ namespace AxibugEmuOnline.Client.Manager /// 鍙戦佷慨鏀圭帺瀹舵Ы浣,浣嗘槸澧為噺 /// /// 鐜╁鍗犵敤鎴块棿GamePlaySlot鍜孡ocalJoyIdx瀛楀吀 - public void SendChangePlaySlotIdxWithJoyIdx(uint localJoyIndex, uint slotIndex, GamePadType localGamePadType) + public void SendChangePlaySlotIdxWithJoyIdx(uint localJoyIndex, uint slotIndex) { if (!App.roomMgr.InRoom) return; - Dictionary> temp = new Dictionary>(); + Dictionary temp = new Dictionary(); for (int i = 0; i < App.roomMgr.mineRoomMiniInfo.GamePlaySlotList.Count; i++) { var item = App.roomMgr.mineRoomMiniInfo.GamePlaySlotList[i]; if (item.PlayerUID <= 0) continue; if (item.PlayerUID != App.user.userdata.UID) return; - temp[(uint)i] = new ValueTuple((uint)item.PlayerLocalJoyIdx, item.PlayerLocalGamePadType); + temp[(uint)i] = (uint)item.PlayerLocalJoyIdx; } - temp[slotIndex] = new ValueTuple(localJoyIndex, localGamePadType); + temp[slotIndex] = localJoyIndex; SendChangePlaySlotIdxWithJoyIdx(temp); } + /// /// 鍙戦佷慨鏀圭帺瀹舵Ы浣,鍏ㄩ噺 /// /// 鐜╁鍗犵敤鎴块棿GamePlaySlot鍜孡ocalJoyIdx瀛楀吀 - public void SendChangePlaySlotIdxWithJoyIdx(Dictionary> dictSlotIdx2LocalJoyIdx) + public void SendChangePlaySlotIdxWithJoyIdx(Dictionary dictSlotIdx2LocalJoyIdx) { if (!InRoom) return; @@ -440,8 +441,7 @@ namespace AxibugEmuOnline.Client.Manager _Protobuf_Room_Change_PlaySlotWithJoy.SlotWithJoy.Add(new Protobuf_PlaySlotIdxWithJoyIdx() { PlayerSlotIdx = (int)slotdata.Key, - PlayerLocalJoyIdx = (int)slotdata.Value.Item1, - PlayerLocalGamePadType = slotdata.Value.Item2, + PlayerLocalJoyIdx = (int)slotdata.Value, }); } diff --git a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/KeyMapperSetting.cs b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/KeyMapperSetting.cs index dda97a95..ac6d50ab 100644 --- a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/KeyMapperSetting.cs +++ b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/KeyMapperSetting.cs @@ -13,6 +13,7 @@ namespace AxibugEmuOnline.Client.Settings Dictionary m_bindersByType = new Dictionary(); public KeyMapperSetting() { + //鍙嶅皠鎷挎墍鏈夋牳蹇冪殑閿綅缁戝畾 var baseType = typeof(InternalEmuCoreBinder); foreach (var t in baseType.Assembly.ExportedTypes) { diff --git a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/MAMEKeyBinding.cs b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/MAMEKeyBinding.cs index f8af305c..5a86f8b6 100644 --- a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/MAMEKeyBinding.cs +++ b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/MAMEKeyBinding.cs @@ -167,8 +167,8 @@ namespace AxibugEmuOnline.Client.Settings controller.SetBinding(UMAMEKSingleKey.DOWN, device.Down, 0); controller.SetBinding(UMAMEKSingleKey.LEFT, device.Left, 0); controller.SetBinding(UMAMEKSingleKey.RIGHT, device.Right, 0); - controller.SetBinding(UMAMEKSingleKey.BTN_A, device.A, 0); - controller.SetBinding(UMAMEKSingleKey.BTN_B, device.B, 0); + controller.SetBinding(UMAMEKSingleKey.BTN_A, device.B, 0); + controller.SetBinding(UMAMEKSingleKey.BTN_B, device.A, 0); controller.SetBinding(UMAMEKSingleKey.BTN_C, device.X, 0); controller.SetBinding(UMAMEKSingleKey.BTN_D, device.Y, 0); controller.SetBinding(UMAMEKSingleKey.BTN_E, device.LeftSL, 0); diff --git a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/Model/EmuCoreBinder.cs b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/Model/EmuCoreBinder.cs index dc4aab0e..9a41adff 100644 --- a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/Model/EmuCoreBinder.cs +++ b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/Model/EmuCoreBinder.cs @@ -8,8 +8,9 @@ using UnityEngine; /// /// 妯℃嫙鍣ㄦ牳蹇冩帶鍒跺櫒閿綅缁戝畾鍣 +/// 鐢ㄤ簬瀹炵幇鏉ヨ嚜涓殑杈撳叆璁惧鍜屾ā鎷熷櫒鐨勬帶鍒跺櫒鐨勬寜閿粦瀹 /// -/// +/// 妯℃嫙鍣ㄥ钩鍙扮殑鎺у埗鍣ㄧ被鍨嬫灇涓 public abstract class EmuCoreBinder : InternalEmuCoreBinder, IDeviceBinder, IDeviceBinder, @@ -20,6 +21,13 @@ public abstract class EmuCoreBinder : InternalEmuCoreBinder, IDeviceBinder where T : Enum { + /// + /// 蹇界暐杈撳叆璁惧鐨勭嫭鍗犲睘鎬 + /// false:鏍囪涓虹嫭鍗犵殑璁惧锛圗xclusive==true锛夊彧鑳界粦瀹氬埌涓涓帶鍒跺櫒涓 + /// true:璁惧鍙互琚粦瀹氬埌鎵鏈夋帶鍒跺櫒涓婏紝鏃犺璁惧鐨勭嫭鍗犲睘鎬 + /// + protected virtual bool IgnoreInputDeviceExclusive => false; + //姣忎竴涓疄渚嬩唬琛ㄤ竴涓搴旀ā鎷熷櫒骞冲彴鐨勬帶鍒跺櫒绱㈠紩 List m_controllerBinders = new List(); @@ -36,7 +44,7 @@ public abstract class EmuCoreBinder : InternalEmuCoreBinder, { foreach (var binding in m_controllerBinders) { - if (device.Exclusive && GetRegistedBinder(device) != null) continue; + if (!CheckDeviceCanBind(device)) break; binding.RegistInputDevice(device); } @@ -63,11 +71,20 @@ public abstract class EmuCoreBinder : InternalEmuCoreBinder, { foreach (var binding in m_controllerBinders) { - if (connectDevice.Exclusive && GetRegistedBinder(connectDevice) != null) continue; + if (!CheckDeviceCanBind(connectDevice)) return; binding.RegistInputDevice(connectDevice); } } + private bool CheckDeviceCanBind(InputDevice_D device) + { + if (IgnoreInputDeviceExclusive) return true; + if (!device.Exclusive) return true; + + //褰撲竴涓緭鍏ヨ澶囩殑Exclusive涓簍rue鏃讹紝鍙兘缁戝畾鍒颁竴涓帶鍒跺櫒 + return GetRegistedBinder(device) == null; + } + private void InputDevicesMgr_OnDeviceLost(InputDevice_D lostDevice) { foreach (var binding in m_controllerBinders) diff --git a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/StoicGooseBinding.cs b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/StoicGooseBinding.cs new file mode 100644 index 00000000..53ef03b6 --- /dev/null +++ b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/StoicGooseBinding.cs @@ -0,0 +1,155 @@ +锘縰sing AxibugEmuOnline.Client.InputDevices; +using AxibugProtobuf; +using StoicGooseUnity; + +namespace AxibugEmuOnline.Client.Settings +{ + public abstract class StoicGooseBinding : EmuCoreBinder + { + public override void Bind(Keyboard_D device, ControllerBinder controller) + { + switch (controller.ControllerIndex) + { + case 0: + controller.SetBinding(StoicGooseKey.Start, device.Return, 0); + controller.SetBinding(StoicGooseKey.X1, device.W, 0); + controller.SetBinding(StoicGooseKey.X2, device.S, 0); + controller.SetBinding(StoicGooseKey.X3, device.A, 0); + controller.SetBinding(StoicGooseKey.X4, device.D, 0); + controller.SetBinding(StoicGooseKey.Y1, device.G, 0); + controller.SetBinding(StoicGooseKey.Y2, device.V, 0); + controller.SetBinding(StoicGooseKey.Y3, device.C, 0); + controller.SetBinding(StoicGooseKey.Y4, device.B, 0); + controller.SetBinding(StoicGooseKey.B, device.J, 0); + controller.SetBinding(StoicGooseKey.A, device.K, 0); + break; + case 1: + controller.SetBinding(StoicGooseKey.Start, device.KeypadEnter, 0); + controller.SetBinding(StoicGooseKey.X1, device.UpArrow, 0); + controller.SetBinding(StoicGooseKey.X2, device.DownArrow, 0); + controller.SetBinding(StoicGooseKey.X3, device.LeftArrow, 0); + controller.SetBinding(StoicGooseKey.X4, device.RightArrow, 0); + controller.SetBinding(StoicGooseKey.Y1, device.Home, 0); + controller.SetBinding(StoicGooseKey.Y2, device.End, 0); + controller.SetBinding(StoicGooseKey.Y3, device.Delete, 0); + controller.SetBinding(StoicGooseKey.Y4, device.PageDown, 0); + controller.SetBinding(StoicGooseKey.B, device.Keypad1, 0); + controller.SetBinding(StoicGooseKey.A, device.Keypad2, 0); + break; + } + } + public override void Bind(PSVController_D device, ControllerBinder controller) + { + switch (controller.ControllerIndex) + { + case 0: + + + controller.SetBinding(StoicGooseKey.Start, device.Start, 0); + controller.SetBinding(StoicGooseKey.X1, device.Up, 0); + controller.SetBinding(StoicGooseKey.X2, device.Down, 0); + controller.SetBinding(StoicGooseKey.X3, device.Left, 0); + controller.SetBinding(StoicGooseKey.X4, device.Right, 0); + controller.SetBinding(StoicGooseKey.Y1, device.RightStick.Up, 0); + controller.SetBinding(StoicGooseKey.Y2, device.RightStick.Down, 0); + controller.SetBinding(StoicGooseKey.Y3, device.RightStick.Left, 0); + controller.SetBinding(StoicGooseKey.Y4, device.RightStick.Right, 0); + controller.SetBinding(StoicGooseKey.B, device.Cross, 0); + controller.SetBinding(StoicGooseKey.A, device.Circle, 0); + + break; + } + } + public override void Bind(DualShockController_D device, ControllerBinder controller) + { + controller.SetBinding(StoicGooseKey.Start, device.Options, 0); + controller.SetBinding(StoicGooseKey.X1, device.Up, 0); + controller.SetBinding(StoicGooseKey.X2, device.Down, 0); + controller.SetBinding(StoicGooseKey.X3, device.Left, 0); + controller.SetBinding(StoicGooseKey.X4, device.Right, 0); + controller.SetBinding(StoicGooseKey.Y1, device.RightStick.Up, 0); + controller.SetBinding(StoicGooseKey.Y2, device.RightStick.Down, 0); + controller.SetBinding(StoicGooseKey.Y3, device.RightStick.Left, 0); + controller.SetBinding(StoicGooseKey.Y4, device.RightStick.Right, 0); + controller.SetBinding(StoicGooseKey.B, device.Cross, 0); + controller.SetBinding(StoicGooseKey.A, device.Circle, 0); + } + public override void Bind(GamePad_D device, ControllerBinder controller) + { + controller.SetBinding(StoicGooseKey.Start, device.Start, 0); + controller.SetBinding(StoicGooseKey.X1, device.Up, 0); + controller.SetBinding(StoicGooseKey.X2, device.Down, 0); + controller.SetBinding(StoicGooseKey.X3, device.Left, 0); + controller.SetBinding(StoicGooseKey.X4, device.Right, 0); + controller.SetBinding(StoicGooseKey.Y1, device.RightStick.Up, 0); + controller.SetBinding(StoicGooseKey.Y2, device.RightStick.Down, 0); + controller.SetBinding(StoicGooseKey.Y3, device.RightStick.Left, 0); + controller.SetBinding(StoicGooseKey.Y4, device.RightStick.Right, 0); + controller.SetBinding(StoicGooseKey.B, device.South, 0); + controller.SetBinding(StoicGooseKey.A, device.East, 0); + } + public override void Bind(XboxController_D device, ControllerBinder controller) + { + controller.SetBinding(StoicGooseKey.Start, device.Menu, 0); + controller.SetBinding(StoicGooseKey.X1, device.Up, 0); + controller.SetBinding(StoicGooseKey.X2, device.Down, 0); + controller.SetBinding(StoicGooseKey.X3, device.Left, 0); + controller.SetBinding(StoicGooseKey.X4, device.Right, 0); + controller.SetBinding(StoicGooseKey.Y1, device.RightStick.Up, 0); + controller.SetBinding(StoicGooseKey.Y2, device.RightStick.Down, 0); + controller.SetBinding(StoicGooseKey.Y3, device.RightStick.Left, 0); + controller.SetBinding(StoicGooseKey.Y4, device.RightStick.Right, 0); + controller.SetBinding(StoicGooseKey.B, device.A, 0); + controller.SetBinding(StoicGooseKey.A, device.B, 0); + } + public override void Bind(ScreenGamepad_D device, ControllerBinder controller) + { + controller.SetBinding(StoicGooseKey.Start, device.OPTION_1, 0); + controller.SetBinding(StoicGooseKey.X1, device.UP, 0); + controller.SetBinding(StoicGooseKey.X2, device.DOWN, 0); + controller.SetBinding(StoicGooseKey.X3, device.LEFT, 0); + controller.SetBinding(StoicGooseKey.X4, device.RIGHT, 0); + + controller.SetBinding(StoicGooseKey.X1, device.JOYSTICK.Left, 1); + controller.SetBinding(StoicGooseKey.X2, device.JOYSTICK.Right, 1); + controller.SetBinding(StoicGooseKey.X3, device.JOYSTICK.Up, 1); + controller.SetBinding(StoicGooseKey.X4, device.JOYSTICK.Down, 1); + + //灞忓箷鏆傛椂娌℃湁绗簩涓柟鍚戞帶鍒舵殏鏃剁敤CDEF浠f浛 + controller.SetBinding(StoicGooseKey.Y1, device.BTN_C, 0); + controller.SetBinding(StoicGooseKey.Y2, device.BTN_D, 0); + controller.SetBinding(StoicGooseKey.Y3, device.BTN_E, 0); + controller.SetBinding(StoicGooseKey.Y4, device.BTN_F, 0); + + controller.SetBinding(StoicGooseKey.B, device.BTN_A, 0); + controller.SetBinding(StoicGooseKey.A, device.BTN_B, 0); + } + + public override void Bind(SwitchJoyCon_D device, ControllerBinder controller) + { + controller.SetBinding(StoicGooseKey.Start, device.Plus, 0); + controller.SetBinding(StoicGooseKey.X1, device.Up, 0); + controller.SetBinding(StoicGooseKey.X2, device.Down, 0); + controller.SetBinding(StoicGooseKey.X3, device.Left, 0); + controller.SetBinding(StoicGooseKey.X4, device.Right, 0); + controller.SetBinding(StoicGooseKey.Y1, device.RightStick.Up, 0); + controller.SetBinding(StoicGooseKey.Y2, device.RightStick.Down, 0); + controller.SetBinding(StoicGooseKey.Y3, device.RightStick.Left, 0); + controller.SetBinding(StoicGooseKey.Y4, device.RightStick.Right, 0); + controller.SetBinding(StoicGooseKey.B, device.A, 0); + controller.SetBinding(StoicGooseKey.A, device.B, 0); + } + } + + public class WonderSwanColorKeyBinding : StoicGooseBinding + { + public override RomPlatformType Platform => RomPlatformType.WonderSwanColor; + public override int ControllerCount => 1; + } + + public class WonderSwanBinding : StoicGooseBinding + { + public override RomPlatformType Platform => RomPlatformType.WonderSwan; + public override int ControllerCount => 1; + } +} \ No newline at end of file diff --git a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/StoicGooseBinding.cs.meta b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/StoicGooseBinding.cs.meta new file mode 100644 index 00000000..319cfb68 --- /dev/null +++ b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/StoicGooseBinding.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: faa0295df1a7a0c43bf9fc9f717f7513 \ No newline at end of file diff --git a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/XMBKeyBinding.cs b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/XMBKeyBinding.cs index 8061c3d0..1a2bc5aa 100644 --- a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/XMBKeyBinding.cs +++ b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/XMBKeyBinding.cs @@ -1,10 +1,12 @@ 锘縰sing AxibugEmuOnline.Client.InputDevices; using AxibugProtobuf; +using static AxibugEmuOnline.Client.NesControllerMapper; namespace AxibugEmuOnline.Client { public class XMBKeyBinding : EmuCoreBinder { + protected override bool IgnoreInputDeviceExclusive => true; public override RomPlatformType Platform => RomPlatformType.Invalid; public override int ControllerCount => 2; @@ -39,93 +41,145 @@ namespace AxibugEmuOnline.Client } public override void Bind(DualShockController_D device, ControllerBinder controller) { - controller.SetBinding(EnumCommand.Back, device.Circle, 0); - controller.SetBinding(EnumCommand.Enter, device.Cross, 0); - controller.SetBinding(EnumCommand.OptionMenu, device.Options, 0); - controller.SetBinding(EnumCommand.SelectItemDown, device.Down, 0); - controller.SetBinding(EnumCommand.SelectItemLeft, device.Left, 0); - controller.SetBinding(EnumCommand.SelectItemRight, device.Right, 0); - controller.SetBinding(EnumCommand.SelectItemUp, device.Up, 0); + switch (controller.ControllerIndex) + { + case 0: + controller.SetBinding(EnumCommand.Back, device.Circle, 0); + controller.SetBinding(EnumCommand.Enter, device.Cross, 0); + controller.SetBinding(EnumCommand.OptionMenu, device.Options, 0); + controller.SetBinding(EnumCommand.SelectItemDown, device.Down, 0); + controller.SetBinding(EnumCommand.SelectItemLeft, device.Left, 0); + controller.SetBinding(EnumCommand.SelectItemRight, device.Right, 0); + controller.SetBinding(EnumCommand.SelectItemUp, device.Up, 0); - controller.SetBinding(EnumCommand.SelectItemDown, device.LeftStick.Down, 1); - controller.SetBinding(EnumCommand.SelectItemLeft, device.LeftStick.Left, 1); - controller.SetBinding(EnumCommand.SelectItemRight, device.LeftStick.Right, 1); - controller.SetBinding(EnumCommand.SelectItemUp, device.LeftStick.Up, 1); + controller.SetBinding(EnumCommand.SelectItemDown, device.LeftStick.Down, 1); + controller.SetBinding(EnumCommand.SelectItemLeft, device.LeftStick.Left, 1); + controller.SetBinding(EnumCommand.SelectItemRight, device.LeftStick.Right, 1); + controller.SetBinding(EnumCommand.SelectItemUp, device.LeftStick.Up, 1); + break; + case 1: + controller.SetBinding(EnumCommand.OptionMenu, device.TouchpadBtn, 0); + controller.SetBinding(EnumCommand.OptionMenu, device.R3, 1); + break; + } } public override void Bind(GamePad_D device, ControllerBinder controller) { - controller.SetBinding(EnumCommand.Back, device.East, 0); - controller.SetBinding(EnumCommand.Enter, device.South, 0); - controller.SetBinding(EnumCommand.OptionMenu, device.Start, 0); - controller.SetBinding(EnumCommand.SelectItemDown, device.Down, 0); - controller.SetBinding(EnumCommand.SelectItemLeft, device.Left, 0); - controller.SetBinding(EnumCommand.SelectItemRight, device.Right, 0); - controller.SetBinding(EnumCommand.SelectItemUp, device.Up, 0); + switch (controller.ControllerIndex) + { + case 0: + controller.SetBinding(EnumCommand.Back, device.East, 0); + controller.SetBinding(EnumCommand.Enter, device.South, 0); + controller.SetBinding(EnumCommand.OptionMenu, device.Start, 0); + controller.SetBinding(EnumCommand.SelectItemDown, device.Down, 0); + controller.SetBinding(EnumCommand.SelectItemLeft, device.Left, 0); + controller.SetBinding(EnumCommand.SelectItemRight, device.Right, 0); + controller.SetBinding(EnumCommand.SelectItemUp, device.Up, 0); + + controller.SetBinding(EnumCommand.SelectItemDown, device.LeftStick.Down, 1); + controller.SetBinding(EnumCommand.SelectItemLeft, device.LeftStick.Left, 1); + controller.SetBinding(EnumCommand.SelectItemRight, device.LeftStick.Right, 1); + controller.SetBinding(EnumCommand.SelectItemUp, device.LeftStick.Up, 1); + break; + case 1: + controller.SetBinding(EnumCommand.OptionMenu, device.RightStickPress, 0); + break; + } - controller.SetBinding(EnumCommand.SelectItemDown, device.LeftStick.Down, 1); - controller.SetBinding(EnumCommand.SelectItemLeft, device.LeftStick.Left, 1); - controller.SetBinding(EnumCommand.SelectItemRight, device.LeftStick.Right, 1); - controller.SetBinding(EnumCommand.SelectItemUp, device.LeftStick.Up, 1); } public override void Bind(PSVController_D device, ControllerBinder controller) { - controller.SetBinding(EnumCommand.Back, device.Circle, 0); - controller.SetBinding(EnumCommand.Enter, device.Cross, 0); - controller.SetBinding(EnumCommand.OptionMenu, device.Start, 0); - controller.SetBinding(EnumCommand.SelectItemDown, device.Down, 0); - controller.SetBinding(EnumCommand.SelectItemLeft, device.Left, 0); - controller.SetBinding(EnumCommand.SelectItemRight, device.Right, 0); - controller.SetBinding(EnumCommand.SelectItemUp, device.Up, 0); + switch (controller.ControllerIndex) + { + case 0: + controller.SetBinding(EnumCommand.Back, device.Circle, 0); + controller.SetBinding(EnumCommand.Enter, device.Cross, 0); + controller.SetBinding(EnumCommand.OptionMenu, device.Start, 0); + controller.SetBinding(EnumCommand.SelectItemDown, device.Down, 0); + controller.SetBinding(EnumCommand.SelectItemLeft, device.Left, 0); + controller.SetBinding(EnumCommand.SelectItemRight, device.Right, 0); + controller.SetBinding(EnumCommand.SelectItemUp, device.Up, 0); + + controller.SetBinding(EnumCommand.SelectItemDown, device.LeftStick.Down, 1); + controller.SetBinding(EnumCommand.SelectItemLeft, device.LeftStick.Left, 1); + controller.SetBinding(EnumCommand.SelectItemRight, device.LeftStick.Right, 1); + controller.SetBinding(EnumCommand.SelectItemUp, device.LeftStick.Up, 1); + break; + case 1: + controller.SetBinding(EnumCommand.OptionMenu, device.Triangle, 0); + break; + } - controller.SetBinding(EnumCommand.SelectItemDown, device.LeftStick.Down, 1); - controller.SetBinding(EnumCommand.SelectItemLeft, device.LeftStick.Left, 1); - controller.SetBinding(EnumCommand.SelectItemRight, device.LeftStick.Right, 1); - controller.SetBinding(EnumCommand.SelectItemUp, device.LeftStick.Up, 1); } public override void Bind(XboxController_D device, ControllerBinder controller) { - controller.SetBinding(EnumCommand.Back, device.B, 0); - controller.SetBinding(EnumCommand.Enter, device.A, 0); - controller.SetBinding(EnumCommand.OptionMenu, device.Menu, 0); - controller.SetBinding(EnumCommand.SelectItemDown, device.Down, 0); - controller.SetBinding(EnumCommand.SelectItemLeft, device.Left, 0); - controller.SetBinding(EnumCommand.SelectItemRight, device.Right, 0); - controller.SetBinding(EnumCommand.SelectItemUp, device.Up, 0); + switch (controller.ControllerIndex) + { + case 0: + controller.SetBinding(EnumCommand.Back, device.B, 0); + controller.SetBinding(EnumCommand.Enter, device.A, 0); + controller.SetBinding(EnumCommand.OptionMenu, device.Menu, 0); + controller.SetBinding(EnumCommand.SelectItemDown, device.Down, 0); + controller.SetBinding(EnumCommand.SelectItemLeft, device.Left, 0); + controller.SetBinding(EnumCommand.SelectItemRight, device.Right, 0); + controller.SetBinding(EnumCommand.SelectItemUp, device.Up, 0); + + controller.SetBinding(EnumCommand.SelectItemDown, device.LeftStick.Down, 1); + controller.SetBinding(EnumCommand.SelectItemLeft, device.LeftStick.Left, 1); + controller.SetBinding(EnumCommand.SelectItemRight, device.LeftStick.Right, 1); + controller.SetBinding(EnumCommand.SelectItemUp, device.LeftStick.Up, 1); + break; + case 1: + controller.SetBinding(EnumCommand.OptionMenu, device.RightStickPress, 0); + break; + } - controller.SetBinding(EnumCommand.SelectItemDown, device.LeftStick.Down, 1); - controller.SetBinding(EnumCommand.SelectItemLeft, device.LeftStick.Left, 1); - controller.SetBinding(EnumCommand.SelectItemRight, device.LeftStick.Right, 1); - controller.SetBinding(EnumCommand.SelectItemUp, device.LeftStick.Up, 1); } public override void Bind(ScreenGamepad_D device, ControllerBinder controller) { - controller.SetBinding(EnumCommand.Back, device.BTN_A, 0); - controller.SetBinding(EnumCommand.Enter, device.BTN_B, 0); - controller.SetBinding(EnumCommand.OptionMenu, device.OPTION_1, 0); - controller.SetBinding(EnumCommand.SelectItemDown, device.DOWN, 0); - controller.SetBinding(EnumCommand.SelectItemLeft, device.LEFT, 0); - controller.SetBinding(EnumCommand.SelectItemRight, device.RIGHT, 0); - controller.SetBinding(EnumCommand.SelectItemUp, device.UP, 0); + switch (controller.ControllerIndex) + { + case 0: + controller.SetBinding(EnumCommand.Back, device.BTN_A, 0); + controller.SetBinding(EnumCommand.Enter, device.BTN_B, 0); + controller.SetBinding(EnumCommand.OptionMenu, device.OPTION_1, 0); + controller.SetBinding(EnumCommand.SelectItemDown, device.DOWN, 0); + controller.SetBinding(EnumCommand.SelectItemLeft, device.LEFT, 0); + controller.SetBinding(EnumCommand.SelectItemRight, device.RIGHT, 0); + controller.SetBinding(EnumCommand.SelectItemUp, device.UP, 0); - controller.SetBinding(EnumCommand.SelectItemDown, device.JOYSTICK.Down, 1); - controller.SetBinding(EnumCommand.SelectItemLeft, device.JOYSTICK.Left, 1); - controller.SetBinding(EnumCommand.SelectItemRight, device.JOYSTICK.Right, 1); - controller.SetBinding(EnumCommand.SelectItemUp, device.JOYSTICK.Up, 1); + controller.SetBinding(EnumCommand.SelectItemDown, device.JOYSTICK.Down, 1); + controller.SetBinding(EnumCommand.SelectItemLeft, device.JOYSTICK.Left, 1); + controller.SetBinding(EnumCommand.SelectItemRight, device.JOYSTICK.Right, 1); + controller.SetBinding(EnumCommand.SelectItemUp, device.JOYSTICK.Up, 1); + break; + case 1: + controller.SetBinding(EnumCommand.OptionMenu, device.HOME, 0); + break; + } } public override void Bind(SwitchJoyCon_D device, ControllerBinder controller) { - controller.SetBinding(EnumCommand.Back, device.A, 0); - controller.SetBinding(EnumCommand.Enter, device.B, 0); - controller.SetBinding(EnumCommand.OptionMenu, device.Plus, 0); - controller.SetBinding(EnumCommand.SelectItemDown, device.Down, 0); - controller.SetBinding(EnumCommand.SelectItemLeft, device.Left, 0); - controller.SetBinding(EnumCommand.SelectItemRight, device.Right, 0); - controller.SetBinding(EnumCommand.SelectItemUp, device.Up, 0); + switch (controller.ControllerIndex) + { + case 0://璁剧疆鏍囧噯UI鎺у埗 + controller.SetBinding(EnumCommand.Back, device.B, 0); + controller.SetBinding(EnumCommand.Enter, device.A, 0); + controller.SetBinding(EnumCommand.OptionMenu, device.Plus, 0); + controller.SetBinding(EnumCommand.SelectItemDown, device.Down, 0); + controller.SetBinding(EnumCommand.SelectItemLeft, device.Left, 0); + controller.SetBinding(EnumCommand.SelectItemRight, device.Right, 0); + controller.SetBinding(EnumCommand.SelectItemUp, device.Up, 0); - controller.SetBinding(EnumCommand.SelectItemDown, device.LeftStick.Down, 1); - controller.SetBinding(EnumCommand.SelectItemLeft, device.LeftStick.Left, 1); - controller.SetBinding(EnumCommand.SelectItemRight, device.LeftStick.Right, 1); - controller.SetBinding(EnumCommand.SelectItemUp, device.LeftStick.Up, 1); + controller.SetBinding(EnumCommand.SelectItemDown, device.LeftStick.Down, 1); + controller.SetBinding(EnumCommand.SelectItemLeft, device.LeftStick.Left, 1); + controller.SetBinding(EnumCommand.SelectItemRight, device.LeftStick.Right, 1); + controller.SetBinding(EnumCommand.SelectItemUp, device.LeftStick.Up, 1); + break; + case 1://娓告垙涓璘I鎺у埗 + controller.SetBinding(EnumCommand.OptionMenu, device.RightStickPress, 0); + break; + } } } } \ No newline at end of file diff --git a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/ControllerInterface.cs b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/ControllerInterface.cs index 4b440a18..2c13fc55 100644 --- a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/ControllerInterface.cs +++ b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/ControllerInterface.cs @@ -12,6 +12,13 @@ public interface IControllerSetuper uint? con2ToSlot = null, uint? con3ToSlot = null); + /// + /// 澧為噺寮忕殑淇敼涓涓墜鏌勫拰涓涓Ы浣嶇殑杩炴帴鍏崇郴 + /// + /// + /// + void LetControllerConnect(int conIndex, uint slotIndex); + /// /// 鎸囧畾鎵嬫焺鎻掓Ы浣,鑾峰彇褰撳墠妲戒綅杩炴帴鐨勬湰鍦版墜鏌勫簭鍙 /// @@ -26,12 +33,7 @@ public interface IControllerSetuper /// uint? GetFreeSlotIndex(); - /// - /// 澧為噺寮忕殑淇敼涓涓墜鏌勫拰涓涓Ы浣嶇殑杩炴帴鍏崇郴 - /// - /// - /// - void LetControllerConnect(int conIndex, uint slotIndex); + } public interface IController { diff --git a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/InputDevicesManager/Devices/InputControls/Stick_C.cs b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/InputDevicesManager/Devices/InputControls/Stick_C.cs index 05118769..020773fd 100644 --- a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/InputDevicesManager/Devices/InputControls/Stick_C.cs +++ b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/InputDevicesManager/Devices/InputControls/Stick_C.cs @@ -18,19 +18,21 @@ namespace AxibugEmuOnline.Client.InputDevices { var axis = GetVector2(); - Up.m_performing = axis.y > 0f; + var dir = GetDirection(axis, 0.15f); + Up.m_performing = dir == Direction.Up; Up.Update(); - Down.m_performing = axis.y < 0f; + Down.m_performing = dir == Direction.Down; Down.Update(); - Left.m_performing = axis.x < 0f; + Left.m_performing = dir == Direction.Left; Left.Update(); - Right.m_performing = axis.x > 0f; + Right.m_performing = dir == Direction.Right; Right.Update(); } + public class VirtualButton : InputControl_C { @@ -53,5 +55,66 @@ namespace AxibugEmuOnline.Client.InputDevices return Performing ? 1 : 0; } } + + enum Direction + { + None, + Up, + Down, + Left, + Right + } + + static Direction GetDirection(Vector2 input, float deadzone) + { + // 妫鏌ユ鍖猴細濡傛灉鐐瑰湪姝诲尯鍗婂緞鍐咃紝杩斿洖鏃 + if (input.magnitude <= deadzone) + { + return Direction.None; + } + + // 鏍囧噯鍖栧悜閲忥紙纭繚鍦ㄥ崟浣嶅渾涓婏級 + Vector2 normalized = input.normalized; + + // 璁$畻鐐逛笌鍥涗釜鏂瑰悜鍩哄噯鍚戦噺鐨勭偣绉 + float dotUp = Vector2.Dot(normalized, Vector2.up); // (0, 1) + float dotDown = Vector2.Dot(normalized, Vector2.down); // (0, -1) + float dotRight = Vector2.Dot(normalized, Vector2.right); // (1, 0) + float dotLeft = Vector2.Dot(normalized, Vector2.left); // (-1, 0) + + // 鎵惧嚭鏈澶х偣绉搴旂殑鏂瑰悜 + Direction bestDirection = Direction.None; + float maxDot = -1f; // 鍒濆鍖栦负鏈灏忓 + + // 妫鏌ヤ笂鏂瑰悜 + if (dotUp > maxDot) + { + maxDot = dotUp; + bestDirection = Direction.Up; + } + + // 妫鏌ヤ笅鏂瑰悜 + if (dotDown > maxDot) + { + maxDot = dotDown; + bestDirection = Direction.Down; + } + + // 妫鏌ュ彸鏂瑰悜 + if (dotRight > maxDot) + { + maxDot = dotRight; + bestDirection = Direction.Right; + } + + // 妫鏌ュ乏鏂瑰悜 + if (dotLeft > maxDot) + { + bestDirection = Direction.Left; + } + + return bestDirection; + } + } } diff --git a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/InputDevicesManager/Devices/PSVController_D.cs b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/InputDevicesManager/Devices/PSVController_D.cs index 8321ea53..0bec1044 100644 --- a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/InputDevicesManager/Devices/PSVController_D.cs +++ b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/Manager/InputDevicesManager/Devices/PSVController_D.cs @@ -6,9 +6,21 @@ namespace AxibugEmuOnline.Client.InputDevices { public override GamePadType PadType => GamePadType.PsvitaControl; + /// + /// X + /// public Button_C Cross; + /// + /// O + /// public Button_C Circle; + /// + /// 鏂规 + /// public Button_C Square; + /// + /// 涓夎 + /// public Button_C Triangle; public Button_C L; public Button_C R; diff --git a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/UI/InGameUI/InGameUI.cs b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/UI/InGameUI/InGameUI.cs index 60a059eb..7cc27769 100644 --- a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/UI/InGameUI/InGameUI.cs +++ b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/UI/InGameUI/InGameUI.cs @@ -125,16 +125,13 @@ namespace AxibugEmuOnline.Client { m_delayCreateRoom = false; //寤惰繜鍒涘缓鎴块棿鎴愬姛鍚,鍚屾鏈湴鎵嬫焺杩炴帴鐘舵 - Dictionary> temp = new Dictionary>(); + Dictionary temp = new Dictionary(); var setuper = App.emu.Core.GetControllerSetuper(); - for (int i = 0; i < 4; i++) + for (uint i = 0; i < 4; i++) { - var joyIndex = setuper.GetSlotConnectingControllerIndex(i); + var joyIndex = setuper.GetSlotConnectingControllerIndex((int)i); - //TODO 鎵嬫焺绫诲瀷 - GamePadType gpType = GamePadType.GlobalGamePad; - - if (joyIndex != null) temp[(uint)i] = new ValueTuple((uint)joyIndex.Value, gpType); + if (joyIndex != null) temp[i] = (uint)joyIndex.Value; } App.roomMgr.SendChangePlaySlotIdxWithJoyIdx(temp); } diff --git a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfo.cs b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfo.cs index 9d9f7dd4..f8d1cade 100644 --- a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfo.cs +++ b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfo.cs @@ -18,6 +18,7 @@ public class ControllerInfo : MonoBehaviour [SerializeField] Text m_playerName; private bool m_islocal; + private Tweener m_tween; public int SlotIndex { @@ -67,7 +68,16 @@ public class ControllerInfo : MonoBehaviour if (controller == null) return; if (!controller.AnyButtonDown()) return; - m_indexIcon.rectTransform.DOShakePosition(0.1f); + if (m_tween != null) + { + m_indexIcon.rectTransform.anchoredPosition = Vector2.zero; + m_tween.Kill(); + m_tween = null; + } + m_tween = m_indexIcon.rectTransform.DOShakePosition(0.1f).SetLink(gameObject).OnComplete(() => + { + m_tween = null; + }); } } @@ -94,7 +104,6 @@ public class ControllerInfo : MonoBehaviour { SetDisconnect(); return; - } var connecter = App.emu.Core.GetControllerSetuper(); diff --git a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfoPanel.cs b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfoPanel.cs index c85750e6..c9aa14de 100644 --- a/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfoPanel.cs +++ b/AxibugEmuOnline.Client.Switch/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfoPanel.cs @@ -28,10 +28,7 @@ public class ControllerInfoPanel : MonoBehaviour //鎵惧埌绗竴涓┖闂叉墜鏌勬彃妲 var freeSlotIndex = s_freeSlots[0]; - //TODO 鎵嬫焺绫诲瀷 - GamePadType gpType = GamePadType.GlobalGamePad; - - App.roomMgr.SendChangePlaySlotIdxWithJoyIdx((uint)joyIndex, (uint)freeSlotIndex, gpType); + App.roomMgr.SendChangePlaySlotIdxWithJoyIdx((uint)joyIndex, (uint)freeSlotIndex); } else //涓嶅湪鎴块棿涓,鐩存帴璁剧疆 { diff --git a/AxibugEmuOnline.Client.Switch/Assets/VirtualNes.Core/NES.cs b/AxibugEmuOnline.Client.Switch/Assets/VirtualNes.Core/NES.cs index 37fe9026..dc44e7f0 100644 --- a/AxibugEmuOnline.Client.Switch/Assets/VirtualNes.Core/NES.cs +++ b/AxibugEmuOnline.Client.Switch/Assets/VirtualNes.Core/NES.cs @@ -347,14 +347,13 @@ namespace VirtualNes.Core catch (Exception ex) { fp?.Close(); - Debuger.LogError($"Loading TurboFile Error.\n{ex}"); + //Debuger.LogError($"Loading TurboFile Error.\n{ex}"); } } private void LoadDISK() { - //todo : 纾佺鏈鸿鍙栨敮鎸 - Debuger.LogError($"纾佺鏈哄皻鏈敮鎸"); + //todo : 纾佺鏈鸿鍙栨敮鎸 by alienjack } private void LoadSRAM()