class to static; added a controller check on GetConfiguredControllers
This commit is contained in:
parent
c3bfa67393
commit
538a9c83bd
@ -15,7 +15,6 @@ namespace Ryujinx.Ava.Input
|
|||||||
private readonly InputManager _inputManager;
|
private readonly InputManager _inputManager;
|
||||||
private readonly MainWindowViewModel _viewModel;
|
private readonly MainWindowViewModel _viewModel;
|
||||||
private readonly ConfigurationState _configurationState;
|
private readonly ConfigurationState _configurationState;
|
||||||
private readonly ControllerAssignmentManager _assignmentManager;
|
|
||||||
|
|
||||||
public event Action ConfigurationUpdated;
|
public event Action ConfigurationUpdated;
|
||||||
|
|
||||||
@ -24,7 +23,6 @@ namespace Ryujinx.Ava.Input
|
|||||||
_inputManager = inputManager;
|
_inputManager = inputManager;
|
||||||
_viewModel = mainWindowViewModel;
|
_viewModel = mainWindowViewModel;
|
||||||
_configurationState = ConfigurationState.Instance;
|
_configurationState = ConfigurationState.Instance;
|
||||||
_assignmentManager = new ControllerAssignmentManager();
|
|
||||||
|
|
||||||
_inputManager.GamepadDriver.OnGamepadConnected += HandleOnGamepadConnected;
|
_inputManager.GamepadDriver.OnGamepadConnected += HandleOnGamepadConnected;
|
||||||
_inputManager.GamepadDriver.OnGamepadDisconnected += HandleOnGamepadDisconnected;
|
_inputManager.GamepadDriver.OnGamepadDisconnected += HandleOnGamepadDisconnected;
|
||||||
@ -51,7 +49,7 @@ namespace Ryujinx.Ava.Input
|
|||||||
List<IGamepad> controllers = _inputManager.GamepadDriver.GetGamepads().ToList();
|
List<IGamepad> controllers = _inputManager.GamepadDriver.GetGamepads().ToList();
|
||||||
List<InputConfig> oldConfig = _configurationState.Hid.InputConfig.Value.Where(x => x != null).ToList();
|
List<InputConfig> oldConfig = _configurationState.Hid.InputConfig.Value.Where(x => x != null).ToList();
|
||||||
|
|
||||||
List<InputConfig> newConfig = _assignmentManager.GetConfiguredControllers(
|
List<InputConfig> newConfig = ControllerAssignmentManager.GetConfiguredControllers(
|
||||||
controllers, oldConfig, out bool hasNewControllersConnected);
|
controllers, oldConfig, out bool hasNewControllersConnected);
|
||||||
|
|
||||||
_viewModel.AppHost?.NpadManager.ReloadConfiguration(newConfig, _configurationState.Hid.EnableKeyboard, _configurationState.Hid.EnableMouse);
|
_viewModel.AppHost?.NpadManager.ReloadConfiguration(newConfig, _configurationState.Hid.EnableKeyboard, _configurationState.Hid.EnableMouse);
|
||||||
|
@ -10,9 +10,9 @@ using StickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInputId;
|
|||||||
|
|
||||||
namespace Ryujinx.Ava.Input
|
namespace Ryujinx.Ava.Input
|
||||||
{
|
{
|
||||||
public class ControllerAssignmentManager
|
public static class ControllerAssignmentManager
|
||||||
{
|
{
|
||||||
private readonly uint[] _playerColors =
|
private static readonly uint[] _playerColors =
|
||||||
[
|
[
|
||||||
0xFFFF0000, // Player 1 - Red
|
0xFFFF0000, // Player 1 - Red
|
||||||
0xFF0000FF, // Player 2 - Blue
|
0xFF0000FF, // Player 2 - Blue
|
||||||
@ -43,11 +43,17 @@ namespace Ryujinx.Ava.Input
|
|||||||
return reorderedConfig;
|
return reorderedConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<InputConfig> GetConfiguredControllers(
|
public static List<InputConfig> GetConfiguredControllers(
|
||||||
List<IGamepad> controllers,
|
List<IGamepad> controllers,
|
||||||
List<InputConfig> oldConfig,
|
List<InputConfig> oldConfig,
|
||||||
out bool hasNewControllersConnected)
|
out bool hasNewControllersConnected)
|
||||||
{
|
{
|
||||||
|
if(controllers == null || controllers.Count == 0)
|
||||||
|
{
|
||||||
|
hasNewControllersConnected = false;
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
Dictionary<string, InputConfig> oldConfigMap = oldConfig
|
Dictionary<string, InputConfig> oldConfigMap = oldConfig
|
||||||
.Where(c => c?.Id != null)
|
.Where(c => c?.Id != null)
|
||||||
.ToDictionary(x => x.Id);
|
.ToDictionary(x => x.Id);
|
||||||
@ -134,7 +140,7 @@ namespace Ryujinx.Ava.Input
|
|||||||
return -1; // Should not happen unless MaxControllers is exceeded
|
return -1; // Should not happen unless MaxControllers is exceeded
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdatePlayerIndicesAndLEDs(List<InputConfig> orderedConfigs)
|
private static void UpdatePlayerIndicesAndLEDs(List<InputConfig> orderedConfigs)
|
||||||
{
|
{
|
||||||
for (int index = 0; index < orderedConfigs.Count; index++)
|
for (int index = 0; index < orderedConfigs.Count; index++)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user