KeyMapper根据每种设备单独配置

This commit is contained in:
ALIENJACK\alien 2025-03-17 20:32:34 +08:00
parent 811b0b2a48
commit 667089891a

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using static AxibugEmuOnline.Client.Settings.EmuCoreControllerKeyBinding<T>;
namespace AxibugEmuOnline.Client.Settings namespace AxibugEmuOnline.Client.Settings
{ {
@ -231,10 +232,12 @@ namespace AxibugEmuOnline.Client.Settings
else return totalFloat / totalControl; else return totalFloat / totalControl;
} }
public class MapSetting : Dictionary<T, List<InputDevice.InputControl>> { }
public class BindingPage public class BindingPage
{ {
Dictionary<T, List<InputDevice.InputControl>> m_mapSetting = new Dictionary<T, List<InputDevice.InputControl>>();
Dictionary<Type, InputDevice> m_registedDevices = new Dictionary<Type, InputDevice>(); Dictionary<Type, InputDevice> m_registedDevices = new Dictionary<Type, InputDevice>();
Dictionary<InputDevice, MapSetting> m_mapSetting = new Dictionary<InputDevice, MapSetting>();
public int ControllerIndex { get; } public int ControllerIndex { get; }
public EmuCoreControllerKeyBinding<T> Host { get; } public EmuCoreControllerKeyBinding<T> Host { get; }
@ -243,9 +246,6 @@ namespace AxibugEmuOnline.Client.Settings
{ {
ControllerIndex = controllerIndex; ControllerIndex = controllerIndex;
Host = host; Host = host;
foreach (var emuBtn in host.DefineKeys())
m_mapSetting[emuBtn] = new List<InputDevice.InputControl>();
} }
internal bool IsRegisted<DEVICE>() where DEVICE : InputDevice internal bool IsRegisted<DEVICE>() where DEVICE : InputDevice
@ -264,6 +264,7 @@ namespace AxibugEmuOnline.Client.Settings
if (IsRegisted(type)) return; if (IsRegisted(type)) return;
m_registedDevices.Add(type, device); m_registedDevices.Add(type, device);
m_mapSetting[device] = new MapSetting();
Host.RaiseDeviceRegist(device, this); Host.RaiseDeviceRegist(device, this);
} }
@ -273,19 +274,7 @@ namespace AxibugEmuOnline.Client.Settings
if (!IsRegisted(type)) return; if (!IsRegisted(type)) return;
m_registedDevices.Remove(type); m_registedDevices.Remove(type);
m_mapSetting.Remove(device);
foreach (var list in m_mapSetting.Values)
{
for (int i = 0; i < list.Count; i++)
{
var inputControl = list[i];
if (inputControl.Device == device)
{
list.RemoveAt(i);
i--;
}
}
}
} }
public void SetBinding(T emuBtn, InputDevice.InputControl key, int settingSlot) public void SetBinding(T emuBtn, InputDevice.InputControl key, int settingSlot)
@ -295,7 +284,12 @@ namespace AxibugEmuOnline.Client.Settings
Debug.Assert(inputDevice == device); Debug.Assert(inputDevice == device);
var settingList = m_mapSetting[emuBtn]; var setting = m_mapSetting[inputDevice];
if (!setting.TryGetValue(emuBtn, out var settingList))
{
settingList = new List<InputDevice.InputControl>();
setting[emuBtn] = settingList;
}
int needFixCount = settingSlot - settingList.Count + 1; int needFixCount = settingSlot - settingList.Count + 1;
if (needFixCount > 0) for (int i = 0; i < needFixCount; i++) settingList.Add(null); if (needFixCount > 0) for (int i = 0; i < needFixCount; i++) settingList.Add(null);
@ -303,25 +297,41 @@ namespace AxibugEmuOnline.Client.Settings
settingList[settingSlot] = key; settingList[settingSlot] = key;
} }
public InputDevice.InputControl GetBinding(T emuBtn, int settingSlot) public InputDevice.InputControl GetBinding(T emuBtn, InputDevice device, int settingSlot)
{ {
var settingList = m_mapSetting[emuBtn]; m_mapSetting.TryGetValue(device, out var mapSetting);
if (settingSlot >= settingList.Count) return null; if (mapSetting == null) return null;
mapSetting.TryGetValue(emuBtn, out var settingList);
if (settingList == null || settingSlot >= settingList.Count) return null;
return settingList[settingSlot]; return settingList[settingSlot];
} }
public List<InputDevice.InputControl> GetBinding(T emuBtn) public IEnumerable<InputDevice.InputControl> GetBinding(T emuBtn)
{ {
return m_mapSetting[emuBtn]; foreach (var mapSettings in m_mapSetting.Values)
{
mapSettings.TryGetValue(emuBtn, out var bindControls);
if (bindControls != null)
{
return bindControls;
}
}
return null;
} }
public bool AnyKeyDown() public bool AnyKeyDown()
{ {
foreach (var item in m_mapSetting) foreach (var mapSettings in m_mapSetting.Values)
{ {
foreach (var key in item.Value) foreach (var keys in mapSettings.Values)
{ {
if (key.Start) return true; foreach (var key in keys)
{
if (key.Start) return true;
}
} }
} }