From a0c5da7a0714a7d865c3f936f2da38370a40dc4f Mon Sep 17 00:00:00 2001 From: "ALIENJACK\\alien" Date: Wed, 25 Dec 2024 18:18:42 +0800 Subject: [PATCH 1/4] =?UTF-8?q?AppRoom=E9=83=A8=E5=88=86=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=8F=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Script/AppMain/Manager/AppRoom.cs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppRoom.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppRoom.cs index c8033d7..9706c80 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppRoom.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppRoom.cs @@ -14,7 +14,7 @@ namespace AxibugEmuOnline.Client.Manager public class AppRoom { public Protobuf_Room_MiniInfo mineRoomMiniInfo { get; private set; } = null; - public bool InRoom => mineRoomMiniInfo != null; + public bool InRoom => App.user.IsLoggedIn && mineRoomMiniInfo != null; public bool IsHost => mineRoomMiniInfo?.HostPlayerUID == App.user.userdata.UID; public bool IsScreenProviderUID => mineRoomMiniInfo?.ScreenProviderUID == App.user.userdata.UID; public RoomGameState RoomState => mineRoomMiniInfo.GameState; @@ -512,16 +512,15 @@ namespace AxibugEmuOnline.Client.Manager /// /// /// - public static bool GetFreeSlot(this Protobuf_Room_MiniInfo roomMiniInfo, out int[] freeSlots) + public static bool GetFreeSlot(this Protobuf_Room_MiniInfo roomMiniInfo, ref List freeSlots) { - List temp = new List(); + freeSlots.Clear(); for (int i = 0; i < roomMiniInfo.GamePlaySlotList.Count; i++) { if (roomMiniInfo.GamePlaySlotList[i].PlayerUID <= 0) - temp.Add(i); + freeSlots.Add(i); } - freeSlots = temp.ToArray(); - return freeSlots.Length > 0; + return freeSlots.Count > 0; } /// @@ -530,15 +529,10 @@ namespace AxibugEmuOnline.Client.Manager public static bool GetPlayerSlotIdxByUid(this Protobuf_Room_MiniInfo roomMiniInfo, long uid, int joyIdx, out uint? slotIdx) { slotIdx = null; - //joyIdx取值返回[0,3],这个序号代表玩家本地的手柄编号 - //todo : 根据uid和controllerIndex 返回占用的位置 - - //目前未实现,所有非0号位置的手柄,都返回false - for (int i = 0; i < roomMiniInfo.GamePlaySlotList.Count; i++) { - if (roomMiniInfo.GamePlaySlotList[i].PlayerUID == uid) + if (roomMiniInfo.GamePlaySlotList[i].PlayerUID == uid && roomMiniInfo.GamePlaySlotList[i].PlayerLocalJoyIdx == joyIdx) { slotIdx = (uint)i; return true; -- 2.36.0.windows.1 From 55b0752c2fc075e6e17e574d342bf82ad33693d3 Mon Sep 17 00:00:00 2001 From: "ALIENJACK\\alien" Date: Wed, 25 Dec 2024 18:19:19 +0800 Subject: [PATCH 2/4] Add UTF8-BOM --- .../Assets/Script/AppMain/UI/OverlayUI/OverlayManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OverlayUI/OverlayManager.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OverlayUI/OverlayManager.cs index a882544..b82f089 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OverlayUI/OverlayManager.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/OverlayUI/OverlayManager.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using UnityEngine; -- 2.36.0.windows.1 From ecdfd507d99fcddc187b52fdf717dd7b45fe5cf4 Mon Sep 17 00:00:00 2001 From: "ALIENJACK\\alien" Date: Wed, 25 Dec 2024 18:41:16 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=8C=89=E9=94=AE?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=AF=B7=E6=B1=82=E7=A9=BA=E9=97=B2=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Script/AppMain/Manager/AppRoom.cs | 27 +++++++++++-- .../NesEmulator/NesControllerMapper.cs | 38 +++++++++++-------- .../Assets/Script/AppMain/PSVita.meta | 8 ++++ .../UI/XMBTopGroupUI/ControllerInfoPanel.cs | 2 +- 4 files changed, 55 insertions(+), 20 deletions(-) create mode 100644 AxibugEmuOnline.Client/Assets/Script/AppMain/PSVita.meta diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppRoom.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppRoom.cs index 9f790a2..b689f73 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppRoom.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppRoom.cs @@ -400,10 +400,31 @@ namespace AxibugEmuOnline.Client.Manager // OverlayManager.PopTip($"[{PlayerName}]进入房间,手柄位:P{i}"); // } //} - } - + } + /// - /// 发送修改玩家槽位 + /// 发送修改玩家槽位,但是增量 + /// + /// 玩家占用房间GamePlaySlot和LocalJoyIdx字典 + public void SendChangePlaySlotIdxWithJoyIdx(uint localJoyIndex, uint slotIndex) + { + if (!App.roomMgr.InRoom) return; + + 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] = (uint)item.PlayerLocalJoyIdx; + } + temp[slotIndex] = localJoyIndex; + + SendChangePlaySlotIdxWithJoyIdx(temp); + } + /// + /// 发送修改玩家槽位,全量 /// /// 玩家占用房间GamePlaySlot和LocalJoyIdx字典 public void SendChangePlaySlotIdxWithJoyIdx(Dictionary dictSlotIdx2LocalJoyIdx) diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesControllerMapper.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesControllerMapper.cs index 45adb8c..6886e47 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesControllerMapper.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/NesEmulator/NesControllerMapper.cs @@ -20,16 +20,16 @@ namespace AxibugEmuOnline.Client m_states[0] = m_states[1] = m_states[2] = m_states[3] = 0; if (Controller0.ConnectSlot.HasValue) m_states[Controller0.ConnectSlot.Value] = Controller0.GetButtons(); - else if (Controller0.AnyButtonPressed()) Eventer.Instance.PostEvent(EEvent.OnLocalJoyDesireInvert, 0); + else if (Controller0.AnyButtonDown()) Eventer.Instance.PostEvent(EEvent.OnLocalJoyDesireInvert, 0); if (Controller1.ConnectSlot.HasValue) m_states[Controller1.ConnectSlot.Value] = Controller1.GetButtons(); - else if (Controller1.AnyButtonPressed()) Eventer.Instance.PostEvent(EEvent.OnLocalJoyDesireInvert, 1); + else if (Controller1.AnyButtonDown()) Eventer.Instance.PostEvent(EEvent.OnLocalJoyDesireInvert, 1); if (Controller2.ConnectSlot.HasValue) m_states[Controller2.ConnectSlot.Value] = Controller2.GetButtons(); - else if (Controller2.AnyButtonPressed()) Eventer.Instance.PostEvent(EEvent.OnLocalJoyDesireInvert, 2); + else if (Controller2.AnyButtonDown()) Eventer.Instance.PostEvent(EEvent.OnLocalJoyDesireInvert, 2); if (Controller3.ConnectSlot.HasValue) m_states[Controller3.ConnectSlot.Value] = Controller3.GetButtons(); - else if (Controller3.AnyButtonPressed()) Eventer.Instance.PostEvent(EEvent.OnLocalJoyDesireInvert, 3); + else if (Controller3.AnyButtonDown()) Eventer.Instance.PostEvent(EEvent.OnLocalJoyDesireInvert, 3); var result = new ControllerState(m_states); return result; @@ -151,18 +151,18 @@ namespace AxibugEmuOnline.Client return res; } - public bool AnyButtonPressed() + public bool AnyButtonDown() { return - UP.IsPressing || - DOWN.IsPressing || - LEFT.IsPressing || - RIGHT.IsPressing || - A.IsPressing || - B.IsPressing || - SELECT.IsPressing || - START.IsPressing || - MIC.IsPressing; + UP.IsDown || + DOWN.IsDown || + LEFT.IsDown || + RIGHT.IsDown || + A.IsDown || + B.IsDown || + SELECT.IsDown || + START.IsDown || + MIC.IsDown; } public static KeyListener GetKey(int controllerInput, EnumButtonType nesConBtnType) @@ -195,8 +195,10 @@ namespace AxibugEmuOnline.Client /// 按键监听器 KeyListener m_keyListener; - /// 指示按钮是否被按下 + /// 指示按钮是否正在按下状态 public bool IsPressing => m_keyListener.IsPressing(); + /// 指示按钮是否被按下 + public bool IsDown => m_keyListener.IsDown(); public Button(Controller controller, EnumButtonType buttonType) { @@ -212,7 +214,7 @@ namespace AxibugEmuOnline.Client /// public EnumButtonType SampleKey() { - return m_keyListener.IsPressing() ? m_buttonType : 0; + return IsPressing ? m_buttonType : 0; } private void CreateListener() @@ -246,6 +248,10 @@ namespace AxibugEmuOnline.Client { return Input.GetKey(m_key); } + public bool IsDown() + { + return Input.GetKeyDown(m_key); + } public override string ToString() { diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/PSVita.meta b/AxibugEmuOnline.Client/Assets/Script/AppMain/PSVita.meta new file mode 100644 index 0000000..ee12a21 --- /dev/null +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/PSVita.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4a4a14412f1bcc844bbd2c9bccf50db2 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfoPanel.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfoPanel.cs index 0486db7..871541c 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfoPanel.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/XMBTopGroupUI/ControllerInfoPanel.cs @@ -27,7 +27,7 @@ public class ControllerInfoPanel : MonoBehaviour //找到第一个空闲手柄插槽 var freeSlotIndex = s_freeSlots[0]; - //App.roomMgr.SendRoomSingelPlayerInput + App.roomMgr.SendChangePlaySlotIdxWithJoyIdx((uint)joyIndex, (uint)freeSlotIndex); } else //不在房间中,直接设置 { -- 2.36.0.windows.1 From 13cadd90a0877b3dc78417f7aa8f5e38db464f48 Mon Sep 17 00:00:00 2001 From: "ALIENJACK\\alien" Date: Wed, 25 Dec 2024 19:56:11 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=88=BF=E4=B8=BB?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=88=BF=E9=97=B4=E6=88=90=E5=8A=9F=E5=90=8E?= =?UTF-8?q?,=E5=B0=86=E6=9C=AC=E5=9C=B0=E7=9A=84=E6=89=8B=E6=9F=84?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E8=AE=BE=E7=BD=AE=E5=90=8C=E6=AD=A5=E5=88=B0?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E7=9A=84=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Assets/Script/AppMain/Manager/AppEmu.cs | 44 +++++++------------ .../Script/AppMain/UI/InGameUI/InGameUI.cs | 15 ++++++- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppEmu.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppEmu.cs index 6ed55dd..02c9302 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppEmu.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppEmu.cs @@ -63,39 +63,29 @@ namespace AxibugEmuOnline.Client.Manager m_emuCore.SetupScheme(); - m_controllerSetuper = Supporter.GetControllerSetuper(); - - SetupController(); + m_controllerSetuper = Supporter.GetControllerSetuper(); + + //自动分配0号手柄到0号手柄位 + m_controllerSetuper.SetConnect(con0ToSlot: 0); + Eventer.Instance.PostEvent(EEvent.OnControllerConnectChanged); Eventer.Instance.RegisterEvent(EEvent.OnRoomSlotDataChanged, OnSlotDataChanged); } private void OnSlotDataChanged() { - SetupController(); - } - - private void SetupController() - { - if (!App.roomMgr.InRoom) //不在房间中,自动分配0号手柄到0号手柄位 - { - m_controllerSetuper.SetConnect(con0ToSlot: 0); - } - else //在房间中则使用服务器下发的手柄槽位信息分配本地手柄 - { - long selfUID = App.user.userdata.UID; - uint? con0Slot; - uint? con1Slot; - uint? con2Slot; - uint? con3Slot; - - App.roomMgr.mineRoomMiniInfo.GetPlayerSlotIdxByUid(selfUID, 0, out con0Slot); - App.roomMgr.mineRoomMiniInfo.GetPlayerSlotIdxByUid(selfUID, 1, out con1Slot); - App.roomMgr.mineRoomMiniInfo.GetPlayerSlotIdxByUid(selfUID, 2, out con2Slot); - App.roomMgr.mineRoomMiniInfo.GetPlayerSlotIdxByUid(selfUID, 3, out con3Slot); - - m_controllerSetuper.SetConnect(con0Slot, con1Slot, con2Slot, con3Slot); - } + long selfUID = App.user.userdata.UID; + uint? con0Slot; + uint? con1Slot; + uint? con2Slot; + uint? con3Slot; + + App.roomMgr.mineRoomMiniInfo.GetPlayerSlotIdxByUid(selfUID, 0, out con0Slot); + App.roomMgr.mineRoomMiniInfo.GetPlayerSlotIdxByUid(selfUID, 1, out con1Slot); + App.roomMgr.mineRoomMiniInfo.GetPlayerSlotIdxByUid(selfUID, 2, out con2Slot); + App.roomMgr.mineRoomMiniInfo.GetPlayerSlotIdxByUid(selfUID, 3, out con3Slot); + + m_controllerSetuper.SetConnect(con0Slot, con1Slot, con2Slot, con3Slot); Eventer.Instance.PostEvent(EEvent.OnControllerConnectChanged); } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/InGameUI/InGameUI.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/InGameUI/InGameUI.cs index dc772b0..17eeb8c 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/InGameUI/InGameUI.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/UI/InGameUI/InGameUI.cs @@ -2,6 +2,7 @@ using AxibugEmuOnline.Client.ClientCore; using AxibugEmuOnline.Client.Event; using AxibugProtobuf; +using VirtualNes.Core; namespace AxibugEmuOnline.Client { @@ -111,7 +112,19 @@ namespace AxibugEmuOnline.Client private void OnRoomCreated() { - m_delayCreateRoom = false; + if (m_delayCreateRoom) + { + m_delayCreateRoom = false; + //延迟创建房间成功后,同步本地手柄连接状态 + Dictionary temp = new Dictionary(); + var setuper = Supporter.GetControllerSetuper(); + for (int i = 0; i < 4; i++) + { + var joyIndex = setuper.GetSlotConnectingController(i); + if (joyIndex != null) temp[(uint)i] = (uint)joyIndex.Value; + } + App.roomMgr.SendChangePlaySlotIdxWithJoyIdx(temp); + } } private void OnLoggedIn() -- 2.36.0.windows.1