Per-game input controller settings!
This commit is contained in:
parent
d630405a5a
commit
4995801d81
2 changed files with 26 additions and 4 deletions
|
@ -19,6 +19,7 @@ using Ryujinx.Common.Configuration.Hid.Keyboard;
|
||||||
using Ryujinx.Common.Logging;
|
using Ryujinx.Common.Logging;
|
||||||
using Ryujinx.Common.Utilities;
|
using Ryujinx.Common.Utilities;
|
||||||
using Ryujinx.Input;
|
using Ryujinx.Input;
|
||||||
|
using Ryujinx.UI.App.Common;
|
||||||
using Ryujinx.UI.Common.Configuration;
|
using Ryujinx.UI.Common.Configuration;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -51,9 +52,12 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||||
private object _configViewModel;
|
private object _configViewModel;
|
||||||
private string _profileName;
|
private string _profileName;
|
||||||
private bool _isLoaded;
|
private bool _isLoaded;
|
||||||
|
private ApplicationData _applicationData;
|
||||||
|
|
||||||
private static readonly InputConfigJsonSerializerContext _serializerContext = new(JsonHelper.GetDefaultSerializerOptions());
|
private static readonly InputConfigJsonSerializerContext _serializerContext = new(JsonHelper.GetDefaultSerializerOptions());
|
||||||
|
|
||||||
|
public bool IsTitleSpecificSettings => _applicationData != null;
|
||||||
|
|
||||||
public IGamepadDriver AvaloniaKeyboardDriver { get; }
|
public IGamepadDriver AvaloniaKeyboardDriver { get; }
|
||||||
public IGamepad SelectedGamepad { get; private set; }
|
public IGamepad SelectedGamepad { get; private set; }
|
||||||
|
|
||||||
|
@ -275,6 +279,17 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||||
PlayerIndexes.Add(new(PlayerIndex.Handheld, LocaleManager.Instance[LocaleKeys.ControllerSettingsHandheld]));
|
PlayerIndexes.Add(new(PlayerIndex.Handheld, LocaleManager.Instance[LocaleKeys.ControllerSettingsHandheld]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void SetApplicationData(ApplicationData applicationData)
|
||||||
|
{
|
||||||
|
_applicationData = applicationData;
|
||||||
|
OnPropertyChanged(nameof(_applicationData));
|
||||||
|
_isLoaded = false;
|
||||||
|
LoadConfiguration(ConfigurationState.Instance(IsTitleSpecificSettings).Hid.InputConfig.Value.Find(inputConfig => inputConfig.PlayerIndex == _playerId));
|
||||||
|
LoadDevice();
|
||||||
|
_isLoaded = true;
|
||||||
|
LoadProfiles();
|
||||||
|
}
|
||||||
|
|
||||||
private void LoadConfiguration(InputConfig inputConfig = null)
|
private void LoadConfiguration(InputConfig inputConfig = null)
|
||||||
{
|
{
|
||||||
Config = inputConfig ?? ConfigurationState.Shared.Hid.InputConfig.Value.Find(inputConfig => inputConfig.PlayerIndex == _playerId);
|
Config = inputConfig ?? ConfigurationState.Shared.Hid.InputConfig.Value.Find(inputConfig => inputConfig.PlayerIndex == _playerId);
|
||||||
|
@ -807,7 +822,9 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||||
|
|
||||||
List<InputConfig> newConfig = new();
|
List<InputConfig> newConfig = new();
|
||||||
|
|
||||||
newConfig.AddRange(ConfigurationState.Shared.Hid.InputConfig.Value);
|
ConfigurationState configState = ConfigurationState.Instance(IsTitleSpecificSettings);
|
||||||
|
|
||||||
|
newConfig.AddRange(configState.Hid.InputConfig.Value);
|
||||||
|
|
||||||
newConfig.Remove(newConfig.Find(x => x == null));
|
newConfig.Remove(newConfig.Find(x => x == null));
|
||||||
|
|
||||||
|
@ -847,13 +864,15 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_mainWindow.ViewModel.AppHost?.NpadManager.ReloadConfiguration(newConfig, ConfigurationState.Shared.Hid.EnableKeyboard, ConfigurationState.Shared.Hid.EnableMouse);
|
_mainWindow.ViewModel.AppHost?.NpadManager.ReloadConfiguration(newConfig, configState.Hid.EnableKeyboard, configState.Hid.EnableMouse);
|
||||||
|
|
||||||
// Atomically replace and signal input change.
|
// Atomically replace and signal input change.
|
||||||
// NOTE: Do not modify InputConfig.Value directly as other code depends on the on-change event.
|
// NOTE: Do not modify InputConfig.Value directly as other code depends on the on-change event.
|
||||||
ConfigurationState.Shared.Hid.InputConfig.Value = newConfig;
|
configState.Hid.InputConfig.Value = newConfig;
|
||||||
|
|
||||||
ConfigurationState.Shared.ToFileFormat().SaveConfig(Program.ConfigurationPath);
|
configState.ToFileFormat().SaveConfig(IsTitleSpecificSettings
|
||||||
|
? ConfigurationState.ConfigurationFilePathForTitle(_applicationData.TitleId)
|
||||||
|
: Program.ConfigurationPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NotifyChange(string property)
|
public void NotifyChange(string property)
|
||||||
|
@ -863,6 +882,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
||||||
|
|
||||||
public void NotifyChanges()
|
public void NotifyChanges()
|
||||||
{
|
{
|
||||||
|
OnPropertyChanged(nameof(_applicationData));
|
||||||
OnPropertyChanged(nameof(ConfigViewModel));
|
OnPropertyChanged(nameof(ConfigViewModel));
|
||||||
OnPropertyChanged(nameof(IsController));
|
OnPropertyChanged(nameof(IsController));
|
||||||
OnPropertyChanged(nameof(ShowSettings));
|
OnPropertyChanged(nameof(ShowSettings));
|
||||||
|
|
|
@ -79,6 +79,8 @@ namespace Ryujinx.Ava.UI.Windows
|
||||||
NavPanel.Content = UiPage;
|
NavPanel.Content = UiPage;
|
||||||
break;
|
break;
|
||||||
case "InputPage":
|
case "InputPage":
|
||||||
|
(InputPage.InputView.DataContext as InputViewModel)?.SetApplicationData(
|
||||||
|
ViewModel.ApplicationData);
|
||||||
NavPanel.Content = InputPage;
|
NavPanel.Content = InputPage;
|
||||||
break;
|
break;
|
||||||
case "HotkeysPage":
|
case "HotkeysPage":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue