1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-11-17 22:16:39 +00:00

Adjust SettingsInputViewModel for new system

This commit is contained in:
Isaac Marovitz 2024-04-19 16:36:04 -04:00
parent ddbdd0246a
commit 2e48ef62fa
No known key found for this signature in database
GPG key ID: 97250B2B09A132E1
4 changed files with 72 additions and 86 deletions

View file

@ -35,6 +35,8 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
{ {
public class SettingsInputViewModel : BaseModel, IDisposable public class SettingsInputViewModel : BaseModel, IDisposable
{ {
public event Action DirtyEvent;
private const string Disabled = "disabled"; private const string Disabled = "disabled";
private const string ProControllerResource = "Ryujinx.UI.Common/Resources/Controller_ProCon.svg"; private const string ProControllerResource = "Ryujinx.UI.Common/Resources/Controller_ProCon.svg";
private const string JoyConPairResource = "Ryujinx.UI.Common/Resources/Controller_JoyConPair.svg"; private const string JoyConPairResource = "Ryujinx.UI.Common/Resources/Controller_JoyConPair.svg";
@ -85,8 +87,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
public event Action NotifyChangesEvent; public event Action NotifyChangesEvent;
private readonly SettingsViewModel _settingsViewModel;
public object ConfigViewModel public object ConfigViewModel
{ {
get => _configViewModel; get => _configViewModel;
@ -239,10 +239,8 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
public InputConfig Config { get; set; } public InputConfig Config { get; set; }
public SettingsInputViewModel(UserControl owner, SettingsViewModel settingsViewModel) : this() public SettingsInputViewModel(UserControl owner) : this()
{ {
_settingsViewModel = settingsViewModel;
if (Program.PreviewerDetached) if (Program.PreviewerDetached)
{ {
_mainWindow = _mainWindow =
@ -754,37 +752,35 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
return; return;
} }
bool validFileName = ProfileName.IndexOfAny(Path.GetInvalidFileNameChars()) == -1;
if (validFileName)
{
string path = Path.Combine(GetProfileBasePath(), ProfileName + ".json");
InputConfig config = null;
if (IsKeyboard)
{
config = (ConfigViewModel as KeyboardInputViewModel).Config.GetConfig();
}
else if (IsController)
{
config = (ConfigViewModel as ControllerInputViewModel).Config.GetConfig();
}
config.ControllerType = Controllers[_controller].Type;
string jsonString = JsonHelper.Serialize(config, _serializerContext.InputConfig);
await File.WriteAllTextAsync(path, jsonString);
LoadProfiles();
}
else else
{ {
bool validFileName = ProfileName.IndexOfAny(Path.GetInvalidFileNameChars()) == -1; await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance[LocaleKeys.DialogProfileInvalidProfileNameErrorMessage]);
if (validFileName)
{
string path = Path.Combine(GetProfileBasePath(), ProfileName + ".json");
InputConfig config = null;
if (IsKeyboard)
{
config = (ConfigViewModel as KeyboardInputViewModel).Config.GetConfig();
}
else if (IsController)
{
config = (ConfigViewModel as ControllerInputViewModel).Config.GetConfig();
}
config.ControllerType = Controllers[_controller].Type;
string jsonString = JsonHelper.Serialize(config, _serializerContext.InputConfig);
await File.WriteAllTextAsync(path, jsonString);
LoadProfiles();
}
else
{
await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance[LocaleKeys.DialogProfileInvalidProfileNameErrorMessage]);
}
} }
} }
@ -815,17 +811,17 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
} }
} }
public void Save() public void Save(ConfigurationState config)
{ {
List<InputConfig> newConfig = new(); List<InputConfig> newInputConfig = new();
newConfig.AddRange(ConfigurationState.Instance.Hid.InputConfig.Value); newInputConfig.AddRange(ConfigurationState.Instance.Hid.InputConfig.Value);
newConfig.Remove(newConfig.Find(x => x == null)); newInputConfig.Remove(newInputConfig.Find(x => x == null));
if (Device == 0) if (Device == 0)
{ {
newConfig.Remove(newConfig.Find(x => x.PlayerIndex == this.PlayerId)); newInputConfig.Remove(newInputConfig.Find(x => x.PlayerIndex == this.PlayerId));
} }
else else
{ {
@ -833,48 +829,41 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
if (device.Type == DeviceType.Keyboard) if (device.Type == DeviceType.Keyboard)
{ {
var inputConfig = (ConfigViewModel as KeyboardInputViewModel).Config; var keyboardConfig = (ConfigViewModel as KeyboardInputViewModel).Config;
inputConfig.Id = device.Id; keyboardConfig.Id = device.Id;
} }
else else
{ {
var inputConfig = (ConfigViewModel as ControllerInputViewModel).Config; var controllerConfig = (ConfigViewModel as ControllerInputViewModel).Config;
inputConfig.Id = device.Id.Split(" ")[0]; controllerConfig.Id = device.Id.Split(" ")[0];
} }
var config = !IsController var inputConfig = !IsController
? (ConfigViewModel as KeyboardInputViewModel).Config.GetConfig() ? (ConfigViewModel as KeyboardInputViewModel).Config.GetConfig()
: (ConfigViewModel as ControllerInputViewModel).Config.GetConfig(); : (ConfigViewModel as ControllerInputViewModel).Config.GetConfig();
config.ControllerType = Controllers[_controller].Type; inputConfig.ControllerType = Controllers[_controller].Type;
config.PlayerIndex = _playerId; inputConfig.PlayerIndex = _playerId;
int i = newConfig.FindIndex(x => x.PlayerIndex == PlayerId); int i = newInputConfig.FindIndex(x => x.PlayerIndex == PlayerId);
if (i == -1) if (i == -1)
{ {
newConfig.Add(config); newInputConfig.Add(inputConfig);
} }
else else
{ {
newConfig[i] = config; newInputConfig[i] = inputConfig;
} }
} }
_mainWindow.ViewModel.AppHost?.NpadManager.ReloadConfiguration(newConfig, ConfigurationState.Instance.Hid.EnableKeyboard, ConfigurationState.Instance.Hid.EnableMouse); _mainWindow.ViewModel.AppHost?.NpadManager.ReloadConfiguration(newInputConfig, ConfigurationState.Instance.Hid.EnableKeyboard, ConfigurationState.Instance.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.Instance.Hid.InputConfig.Value = newConfig; config.Hid.InputConfig.Value = newInputConfig;
ConfigurationState.Instance.System.EnableDockedMode.Value = EnableDockedMode; config.System.EnableDockedMode.Value = EnableDockedMode;
ConfigurationState.Instance.Hid.EnableKeyboard.Value = EnableKeyboard; config.Hid.EnableKeyboard.Value = EnableKeyboard;
ConfigurationState.Instance.Hid.EnableMouse.Value = EnableMouse; config.Hid.EnableMouse.Value = EnableMouse;
ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
}
public void NotifyChange(string property)
{
OnPropertyChanged(property);
} }
public void NotifyChanges() public void NotifyChanges()

View file

@ -2,7 +2,6 @@ using Avalonia.Collections;
using Avalonia.Threading; using Avalonia.Threading;
using LibHac.Tools.FsSystem; using LibHac.Tools.FsSystem;
using Ryujinx.Ava.Common.Locale; using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.UI.Models.Input;
using Ryujinx.Ava.UI.Windows; using Ryujinx.Ava.UI.Windows;
using Ryujinx.Common.Configuration; using Ryujinx.Common.Configuration;
using Ryujinx.Common.Configuration.Multiplayer; using Ryujinx.Common.Configuration.Multiplayer;
@ -47,7 +46,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
} }
public event Action CloseWindow; public event Action CloseWindow;
public event Action SaveSettingsEvent;
public event Action<bool> DirtyEvent; public event Action<bool> DirtyEvent;
public event Action<bool> ToggleButtons; public event Action<bool> ToggleButtons;
@ -172,6 +170,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
private readonly SettingsCpuViewModel _cpuViewModel; private readonly SettingsCpuViewModel _cpuViewModel;
private readonly SettingsGraphicsViewModel _graphicsViewModel; private readonly SettingsGraphicsViewModel _graphicsViewModel;
private readonly SettingsLoggingViewModel _loggingViewModel; private readonly SettingsLoggingViewModel _loggingViewModel;
private readonly SettingsInputViewModel _inputViewModel;
private readonly SettingsHotkeysViewModel _hotkeysViewModel; private readonly SettingsHotkeysViewModel _hotkeysViewModel;
public DateTimeOffset CurrentDate { get; set; } public DateTimeOffset CurrentDate { get; set; }
@ -212,6 +211,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
SettingsCpuViewModel cpuViewModel, SettingsCpuViewModel cpuViewModel,
SettingsGraphicsViewModel graphicsViewModel, SettingsGraphicsViewModel graphicsViewModel,
SettingsHotkeysViewModel hotkeysViewModel, SettingsHotkeysViewModel hotkeysViewModel,
SettingsInputViewModel inputViewModel,
SettingsLoggingViewModel loggingViewModel) : this() SettingsLoggingViewModel loggingViewModel) : this()
{ {
_virtualFileSystem = virtualFileSystem; _virtualFileSystem = virtualFileSystem;
@ -221,12 +221,14 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
_cpuViewModel = cpuViewModel; _cpuViewModel = cpuViewModel;
_graphicsViewModel = graphicsViewModel; _graphicsViewModel = graphicsViewModel;
_hotkeysViewModel = hotkeysViewModel; _hotkeysViewModel = hotkeysViewModel;
_inputViewModel = inputViewModel;
_loggingViewModel = loggingViewModel; _loggingViewModel = loggingViewModel;
_audioViewModel.DirtyEvent += CheckIfModified; _audioViewModel.DirtyEvent += CheckIfModified;
_cpuViewModel.DirtyEvent += CheckIfModified; _cpuViewModel.DirtyEvent += CheckIfModified;
_graphicsViewModel.DirtyEvent += CheckIfModified; _graphicsViewModel.DirtyEvent += CheckIfModified;
_hotkeysViewModel.DirtyEvent += CheckIfModified; _hotkeysViewModel.DirtyEvent += CheckIfModified;
_inputViewModel.DirtyEvent += CheckIfModified;
_loggingViewModel.DirtyEvent += CheckIfModified; _loggingViewModel.DirtyEvent += CheckIfModified;
if (Program.PreviewerDetached) if (Program.PreviewerDetached)
@ -303,6 +305,12 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
isDirty |= _hotkeysViewModel.CheckIfModified(config); isDirty |= _hotkeysViewModel.CheckIfModified(config);
} }
if (_inputViewModel != null)
{
// TODO: IMPLEMENT THIS!!
// isDirty |= _inputViewModel.CheckIfModified(config);
}
// Network // Network
isDirty |= config.System.EnableInternetAccess.Value != EnableInternetAccess; isDirty |= config.System.EnableInternetAccess.Value != EnableInternetAccess;
@ -443,6 +451,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
_cpuViewModel?.Save(config); _cpuViewModel?.Save(config);
_graphicsViewModel?.Save(config); _graphicsViewModel?.Save(config);
_hotkeysViewModel?.Save(config); _hotkeysViewModel?.Save(config);
_inputViewModel?.Save(config);
// Network // Network
config.System.EnableInternetAccess.Value = EnableInternetAccess; config.System.EnableInternetAccess.Value = EnableInternetAccess;
@ -456,8 +465,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
MainWindow.UpdateGraphicsConfig(); MainWindow.UpdateGraphicsConfig();
SaveSettingsEvent?.Invoke();
_directoryChanged = false; _directoryChanged = false;
} }

View file

@ -5,23 +5,18 @@ namespace Ryujinx.Ava.UI.Views.Settings
{ {
public partial class SettingsInputView : UserControl public partial class SettingsInputView : UserControl
{ {
private readonly SettingsInputViewModel _viewModel; public SettingsInputViewModel ViewModel;
public SettingsInputView(SettingsViewModel viewModel) public SettingsInputView()
{ {
DataContext = _viewModel = new SettingsInputViewModel(this, viewModel); DataContext = ViewModel = new SettingsInputViewModel(this);
InitializeComponent(); InitializeComponent();
} }
public void SaveCurrentProfile()
{
_viewModel.Save();
}
public void Dispose() public void Dispose()
{ {
_viewModel.Dispose(); ViewModel.Dispose();
} }
} }
} }

View file

@ -33,6 +33,7 @@ namespace Ryujinx.Ava.UI.Windows
CpuPage = new SettingsCpuView(); CpuPage = new SettingsCpuView();
GraphicsPage = new SettingsGraphicsView(); GraphicsPage = new SettingsGraphicsView();
HotkeysPage = new SettingsHotkeysView(); HotkeysPage = new SettingsHotkeysView();
InputPage = new SettingsInputView();
LoggingPage = new SettingsLoggingView(); LoggingPage = new SettingsLoggingView();
ViewModel = new SettingsViewModel( ViewModel = new SettingsViewModel(
@ -42,17 +43,16 @@ namespace Ryujinx.Ava.UI.Windows
CpuPage.ViewModel, CpuPage.ViewModel,
GraphicsPage.ViewModel, GraphicsPage.ViewModel,
HotkeysPage.ViewModel, HotkeysPage.ViewModel,
InputPage.ViewModel,
LoggingPage.ViewModel); LoggingPage.ViewModel);
UiPage = new SettingsUiView(ViewModel); UiPage = new SettingsUiView(ViewModel);
InputPage = new SettingsInputView(ViewModel);
SystemPage = new SettingsSystemView(ViewModel); SystemPage = new SettingsSystemView(ViewModel);
NetworkPage = new SettingsNetworkView(); NetworkPage = new SettingsNetworkView();
DataContext = ViewModel; DataContext = ViewModel;
ViewModel.CloseWindow += Close; ViewModel.CloseWindow += Close;
ViewModel.SaveSettingsEvent += SaveSettings;
ViewModel.DirtyEvent += UpdateDirtyTitle; ViewModel.DirtyEvent += UpdateDirtyTitle;
ViewModel.ToggleButtons += ToggleButtons; ViewModel.ToggleButtons += ToggleButtons;
@ -93,16 +93,6 @@ namespace Ryujinx.Ava.UI.Windows
Buttons.IsEnabled = enable; Buttons.IsEnabled = enable;
} }
public void SaveSettings()
{
InputPage.SaveCurrentProfile();
if (Owner is MainWindow window && ViewModel.DirectoryChanged)
{
window.LoadApplications();
}
}
private void Load() private void Load()
{ {
NavPanel.SelectionChanged += NavPanelOnSelectionChanged; NavPanel.SelectionChanged += NavPanelOnSelectionChanged;
@ -177,6 +167,11 @@ namespace Ryujinx.Ava.UI.Windows
protected override void OnClosing(WindowClosingEventArgs e) protected override void OnClosing(WindowClosingEventArgs e)
{ {
if (Owner is MainWindow window && ViewModel.DirectoryChanged)
{
window.LoadApplications();
}
HotkeysPage.Dispose(); HotkeysPage.Dispose();
InputPage.Dispose(); InputPage.Dispose();
base.OnClosing(e); base.OnClosing(e);