实现按键自动请求空闲位置

This commit is contained in:
ALIENJACK\alien 2024-12-25 18:41:16 +08:00
parent 02693523a3
commit ecdfd507d9
4 changed files with 55 additions and 20 deletions

View File

@ -403,7 +403,28 @@ namespace AxibugEmuOnline.Client.Manager
} }
/// <summary> /// <summary>
/// 发送修改玩家槽位 /// 发送修改玩家槽位,但是增量
/// </summary>
/// <param name="dictSlotIdx2LocalJoyIdx">玩家占用房间GamePlaySlot和LocalJoyIdx字典</param>
public void SendChangePlaySlotIdxWithJoyIdx(uint localJoyIndex, uint slotIndex)
{
if (!App.roomMgr.InRoom) return;
Dictionary<uint, uint> temp = new Dictionary<uint, uint>();
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);
}
/// <summary>
/// 发送修改玩家槽位,全量
/// </summary> /// </summary>
/// <param name="dictSlotIdx2LocalJoyIdx">玩家占用房间GamePlaySlot和LocalJoyIdx字典</param> /// <param name="dictSlotIdx2LocalJoyIdx">玩家占用房间GamePlaySlot和LocalJoyIdx字典</param>
public void SendChangePlaySlotIdxWithJoyIdx(Dictionary<uint, uint> dictSlotIdx2LocalJoyIdx) public void SendChangePlaySlotIdxWithJoyIdx(Dictionary<uint, uint> dictSlotIdx2LocalJoyIdx)

View File

@ -20,16 +20,16 @@ namespace AxibugEmuOnline.Client
m_states[0] = m_states[1] = m_states[2] = m_states[3] = 0; m_states[0] = m_states[1] = m_states[2] = m_states[3] = 0;
if (Controller0.ConnectSlot.HasValue) m_states[Controller0.ConnectSlot.Value] = Controller0.GetButtons(); 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(); 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(); 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(); 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); var result = new ControllerState(m_states);
return result; return result;
@ -151,18 +151,18 @@ namespace AxibugEmuOnline.Client
return res; return res;
} }
public bool AnyButtonPressed() public bool AnyButtonDown()
{ {
return return
UP.IsPressing || UP.IsDown ||
DOWN.IsPressing || DOWN.IsDown ||
LEFT.IsPressing || LEFT.IsDown ||
RIGHT.IsPressing || RIGHT.IsDown ||
A.IsPressing || A.IsDown ||
B.IsPressing || B.IsDown ||
SELECT.IsPressing || SELECT.IsDown ||
START.IsPressing || START.IsDown ||
MIC.IsPressing; MIC.IsDown;
} }
public static KeyListener GetKey(int controllerInput, EnumButtonType nesConBtnType) public static KeyListener GetKey(int controllerInput, EnumButtonType nesConBtnType)
@ -195,8 +195,10 @@ namespace AxibugEmuOnline.Client
/// <summary> 按键监听器 </summary> /// <summary> 按键监听器 </summary>
KeyListener m_keyListener; KeyListener m_keyListener;
/// <summary> 指示按钮是否被按下 </summary> /// <summary> 指示按钮是否正在按下状态 </summary>
public bool IsPressing => m_keyListener.IsPressing(); public bool IsPressing => m_keyListener.IsPressing();
/// <summary> 指示按钮是否被按下 </summary>
public bool IsDown => m_keyListener.IsDown();
public Button(Controller controller, EnumButtonType buttonType) public Button(Controller controller, EnumButtonType buttonType)
{ {
@ -212,7 +214,7 @@ namespace AxibugEmuOnline.Client
/// <returns></returns> /// <returns></returns>
public EnumButtonType SampleKey() public EnumButtonType SampleKey()
{ {
return m_keyListener.IsPressing() ? m_buttonType : 0; return IsPressing ? m_buttonType : 0;
} }
private void CreateListener() private void CreateListener()
@ -246,6 +248,10 @@ namespace AxibugEmuOnline.Client
{ {
return Input.GetKey(m_key); return Input.GetKey(m_key);
} }
public bool IsDown()
{
return Input.GetKeyDown(m_key);
}
public override string ToString() public override string ToString()
{ {

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4a4a14412f1bcc844bbd2c9bccf50db2
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -27,7 +27,7 @@ public class ControllerInfoPanel : MonoBehaviour
//找到第一个空闲手柄插槽 //找到第一个空闲手柄插槽
var freeSlotIndex = s_freeSlots[0]; var freeSlotIndex = s_freeSlots[0];
//App.roomMgr.SendRoomSingelPlayerInput App.roomMgr.SendChangePlaySlotIdxWithJoyIdx((uint)joyIndex, (uint)freeSlotIndex);
} }
else //不在房间中,直接设置 else //不在房间中,直接设置
{ {