mirror of
https://github.com/GreemDev/Ryujinx
synced 2024-12-22 03:46:39 +01:00
Merge 6d38a5bfc1
into 0adaa4cb96
This commit is contained in:
commit
ddd70c43bf
4 changed files with 103 additions and 5 deletions
|
@ -426,6 +426,8 @@ namespace Ryujinx.Headless.SDL2
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_inputManager.AddUpdaterForConfiguration(_inputConfiguration);
|
||||||
|
|
||||||
// Setup logging level
|
// Setup logging level
|
||||||
Logger.SetEnable(LogLevel.Debug, option.LoggingEnableDebug);
|
Logger.SetEnable(LogLevel.Debug, option.LoggingEnableDebug);
|
||||||
Logger.SetEnable(LogLevel.Stub, !option.LoggingDisableStub);
|
Logger.SetEnable(LogLevel.Stub, !option.LoggingDisableStub);
|
||||||
|
@ -482,7 +484,7 @@ namespace Ryujinx.Headless.SDL2
|
||||||
}
|
}
|
||||||
|
|
||||||
_inputManager.Dispose();
|
_inputManager.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SetupProgressHandler()
|
private static void SetupProgressHandler()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
|
using LibHac.Common;
|
||||||
|
using Ryujinx.Common.Configuration.Hid;
|
||||||
|
using Ryujinx.Common.Logging;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Ryujinx.Input.HLE
|
namespace Ryujinx.Input.HLE
|
||||||
{
|
{
|
||||||
|
@ -41,6 +46,76 @@ namespace Ryujinx.Input.HLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeSDPWhenExternalPadsConnected(List<Tuple<string,string>> availableDevices) {
|
||||||
|
//remove all steam virtual gamepads
|
||||||
|
availableDevices.RemoveAll(a => a.Item2 == "Steam Virtual Gamepad");
|
||||||
|
//remove Steam Deck Controller if external controllers are connected (docked game mode)
|
||||||
|
if (availableDevices.Count > 1) {
|
||||||
|
var steamDeckPad = availableDevices.FindFirst( a => a.Item2 == "Steam Deck Controller");
|
||||||
|
if (steamDeckPad.HasValue) {
|
||||||
|
availableDevices.Remove(steamDeckPad.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Tuple<string,string>> getGamepadsDescriptions() {
|
||||||
|
var result = new List<Tuple<string,string>> ();
|
||||||
|
foreach (string id in GamepadDriver.GamepadsIds) {
|
||||||
|
result.Add(Tuple.Create(id,GamepadDriver.GetGamepad(id).Name));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LinkDevicesToPlayers(List<InputConfig> _inputConfig) {
|
||||||
|
var _availableDevices = getGamepadsDescriptions();
|
||||||
|
removeSDPWhenExternalPadsConnected(_availableDevices);
|
||||||
|
var _playersWithNoDevices = new List<PlayerIndex>();
|
||||||
|
//Remove all used Devices in current Config and at the same time list player with missing Devices
|
||||||
|
foreach(PlayerIndex _playerId in Enum.GetValues(typeof(PlayerIndex)))
|
||||||
|
{
|
||||||
|
var _config = _inputConfig.Find(inputConfig => inputConfig.PlayerIndex == _playerId);
|
||||||
|
if (_config != null && _config.Backend != InputBackendType.WindowKeyboard)
|
||||||
|
{
|
||||||
|
//check device id of the player is in the existing/connected devices
|
||||||
|
var _connectedDevice = _availableDevices.FindFirst(d => d.Item1 == _config.Id);
|
||||||
|
if (_connectedDevice.HasValue)
|
||||||
|
{
|
||||||
|
_availableDevices.Remove(_connectedDevice.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_playersWithNoDevices.Add(_playerId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var hasChanges = _playersWithNoDevices.Count() > 0 && _availableDevices.Count() > 0;
|
||||||
|
if (hasChanges)
|
||||||
|
{
|
||||||
|
Logger.Info?.Print(LogClass.Configuration, $"Controllers configuration changed. Updating players configuration...");
|
||||||
|
for (int i = 0; i < _playersWithNoDevices.Count; i++)
|
||||||
|
{
|
||||||
|
var _playerId = _playersWithNoDevices[i];
|
||||||
|
var _config = _inputConfig.Find(inputConfig => inputConfig.PlayerIndex == _playerId);
|
||||||
|
if (_config != null && _availableDevices.Count > 0)
|
||||||
|
{
|
||||||
|
var _device = _availableDevices.First();
|
||||||
|
var deviceId = _device.Item1;
|
||||||
|
var deviceName = _device.Item2;
|
||||||
|
_config.Id = _device.Item1;
|
||||||
|
Logger.Info?.Print(LogClass.Configuration, $"Link Player {_playerId} to Device {deviceName}");
|
||||||
|
_availableDevices.Remove(_device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Logger.Info?.Print(LogClass.Configuration, $"Updated players configuration to sync with Controllers configuration changes.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddUpdaterForConfiguration(List<InputConfig> _inputConfig) {
|
||||||
|
GamepadDriver.OnGamepadConnected += id => LinkDevicesToPlayers(_inputConfig);
|
||||||
|
GamepadDriver.OnGamepadDisconnected += id => LinkDevicesToPlayers(_inputConfig);
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
|
|
|
@ -97,7 +97,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||||
{
|
{
|
||||||
if (IsModified)
|
if (IsModified)
|
||||||
{
|
{
|
||||||
|
|
||||||
_playerIdChoose = value;
|
_playerIdChoose = value;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -367,12 +367,12 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||||
|
|
||||||
private void HandleOnGamepadDisconnected(string id)
|
private void HandleOnGamepadDisconnected(string id)
|
||||||
{
|
{
|
||||||
Dispatcher.UIThread.Post(LoadDevices);
|
Dispatcher.UIThread.Post(RefreshDevicesAndCurrentPlayerConfiguration);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleOnGamepadConnected(string id)
|
private void HandleOnGamepadConnected(string id)
|
||||||
{
|
{
|
||||||
Dispatcher.UIThread.Post(LoadDevices);
|
Dispatcher.UIThread.Post(RefreshDevicesAndCurrentPlayerConfiguration);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetCurrentGamepadId()
|
private string GetCurrentGamepadId()
|
||||||
|
@ -441,6 +441,21 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||||
return str[(str.IndexOf(Hyphen) + Offset)..];
|
return str[(str.IndexOf(Hyphen) + Offset)..];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void RefreshDevicesAndCurrentPlayerConfiguration()
|
||||||
|
{
|
||||||
|
LoadDevices();
|
||||||
|
|
||||||
|
//update Device for current user based on new configuration.
|
||||||
|
var config = ConfigurationState.Instance.Hid.InputConfig.Value.Find(inputConfig => inputConfig.PlayerIndex == PlayerId);
|
||||||
|
var device = Devices.FindFirst(d => d.Id==config.Id);
|
||||||
|
if (device.HasValue) {
|
||||||
|
Device=Devices.IndexOf(device);
|
||||||
|
} else {
|
||||||
|
//0 is the None Device
|
||||||
|
Device = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void LoadDevices()
|
public void LoadDevices()
|
||||||
{
|
{
|
||||||
string GetGamepadName(IGamepad gamepad, int controllerNumber)
|
string GetGamepadName(IGamepad gamepad, int controllerNumber)
|
||||||
|
@ -464,17 +479,19 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||||
DeviceList.Clear();
|
DeviceList.Clear();
|
||||||
Devices.Add((DeviceType.None, Disabled, LocaleManager.Instance[LocaleKeys.ControllerSettingsDeviceDisabled]));
|
Devices.Add((DeviceType.None, Disabled, LocaleManager.Instance[LocaleKeys.ControllerSettingsDeviceDisabled]));
|
||||||
|
|
||||||
int controllerNumber = 0;
|
int controllerNumber = 1;
|
||||||
foreach (string id in _mainWindow.InputManager.KeyboardDriver.GamepadsIds)
|
foreach (string id in _mainWindow.InputManager.KeyboardDriver.GamepadsIds)
|
||||||
{
|
{
|
||||||
using IGamepad gamepad = _mainWindow.InputManager.KeyboardDriver.GetGamepad(id);
|
using IGamepad gamepad = _mainWindow.InputManager.KeyboardDriver.GetGamepad(id);
|
||||||
|
|
||||||
if (gamepad != null)
|
if (gamepad != null)
|
||||||
{
|
{
|
||||||
|
controllerNumber++;
|
||||||
Devices.Add((DeviceType.Keyboard, id, $"{GetShortGamepadName(gamepad.Name)}"));
|
Devices.Add((DeviceType.Keyboard, id, $"{GetShortGamepadName(gamepad.Name)}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
controllerNumber = 1;
|
||||||
foreach (string id in _mainWindow.InputManager.GamepadDriver.GamepadsIds)
|
foreach (string id in _mainWindow.InputManager.GamepadDriver.GamepadsIds)
|
||||||
{
|
{
|
||||||
using IGamepad gamepad = _mainWindow.InputManager.GamepadDriver.GetGamepad(id);
|
using IGamepad gamepad = _mainWindow.InputManager.GamepadDriver.GetGamepad(id);
|
||||||
|
@ -482,6 +499,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||||
if (gamepad != null)
|
if (gamepad != null)
|
||||||
{
|
{
|
||||||
string name = GetUniqueGamepadName(gamepad, ref controllerNumber);
|
string name = GetUniqueGamepadName(gamepad, ref controllerNumber);
|
||||||
|
controllerNumber++;
|
||||||
Devices.Add((DeviceType.Controller, id, name));
|
Devices.Add((DeviceType.Controller, id, name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ using Ryujinx.Ava.UI.Applet;
|
||||||
using Ryujinx.Ava.UI.Helpers;
|
using Ryujinx.Ava.UI.Helpers;
|
||||||
using Ryujinx.Ava.UI.ViewModels;
|
using Ryujinx.Ava.UI.ViewModels;
|
||||||
using Ryujinx.Common;
|
using Ryujinx.Common;
|
||||||
|
using Ryujinx.Common.Configuration.Hid;
|
||||||
using Ryujinx.Common.Logging;
|
using Ryujinx.Common.Logging;
|
||||||
using Ryujinx.Graphics.Gpu;
|
using Ryujinx.Graphics.Gpu;
|
||||||
using Ryujinx.HLE.FileSystem;
|
using Ryujinx.HLE.FileSystem;
|
||||||
|
@ -103,6 +104,8 @@ namespace Ryujinx.Ava.UI.Windows
|
||||||
if (Program.PreviewerDetached)
|
if (Program.PreviewerDetached)
|
||||||
{
|
{
|
||||||
InputManager = new InputManager(new AvaloniaKeyboardDriver(this), new SDL2GamepadDriver());
|
InputManager = new InputManager(new AvaloniaKeyboardDriver(this), new SDL2GamepadDriver());
|
||||||
|
InputManager.AddUpdaterForConfiguration(ConfigurationState.Instance.Hid.InputConfig);
|
||||||
|
|
||||||
|
|
||||||
_ = this.GetObservable(IsActiveProperty).Subscribe(it => ViewModel.IsActive = it);
|
_ = this.GetObservable(IsActiveProperty).Subscribe(it => ViewModel.IsActive = it);
|
||||||
this.ScalingChanged += OnScalingChanged;
|
this.ScalingChanged += OnScalingChanged;
|
||||||
|
|
Loading…
Reference in a new issue