1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-11-17 22:36:40 +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 event Action DirtyEvent;
private const string Disabled = "disabled";
private const string ProControllerResource = "Ryujinx.UI.Common/Resources/Controller_ProCon.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;
private readonly SettingsViewModel _settingsViewModel;
public object ConfigViewModel
{
get => _configViewModel;
@ -239,10 +239,8 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
public InputConfig Config { get; set; }
public SettingsInputViewModel(UserControl owner, SettingsViewModel settingsViewModel) : this()
public SettingsInputViewModel(UserControl owner) : this()
{
_settingsViewModel = settingsViewModel;
if (Program.PreviewerDetached)
{
_mainWindow =
@ -754,8 +752,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
return;
}
else
{
bool validFileName = ProfileName.IndexOfAny(Path.GetInvalidFileNameChars()) == -1;
if (validFileName)
@ -786,7 +783,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance[LocaleKeys.DialogProfileInvalidProfileNameErrorMessage]);
}
}
}
public async void RemoveProfile()
{
@ -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)
{
newConfig.Remove(newConfig.Find(x => x.PlayerIndex == this.PlayerId));
newInputConfig.Remove(newInputConfig.Find(x => x.PlayerIndex == this.PlayerId));
}
else
{
@ -833,48 +829,41 @@ namespace Ryujinx.Ava.UI.ViewModels.Settings
if (device.Type == DeviceType.Keyboard)
{
var inputConfig = (ConfigViewModel as KeyboardInputViewModel).Config;
inputConfig.Id = device.Id;
var keyboardConfig = (ConfigViewModel as KeyboardInputViewModel).Config;
keyboardConfig.Id = device.Id;
}
else
{
var inputConfig = (ConfigViewModel as ControllerInputViewModel).Config;
inputConfig.Id = device.Id.Split(" ")[0];
var controllerConfig = (ConfigViewModel as ControllerInputViewModel).Config;
controllerConfig.Id = device.Id.Split(" ")[0];
}
var config = !IsController
var inputConfig = !IsController
? (ConfigViewModel as KeyboardInputViewModel).Config.GetConfig()
: (ConfigViewModel as ControllerInputViewModel).Config.GetConfig();
config.ControllerType = Controllers[_controller].Type;
config.PlayerIndex = _playerId;
inputConfig.ControllerType = Controllers[_controller].Type;
inputConfig.PlayerIndex = _playerId;
int i = newConfig.FindIndex(x => x.PlayerIndex == PlayerId);
int i = newInputConfig.FindIndex(x => x.PlayerIndex == PlayerId);
if (i == -1)
{
newConfig.Add(config);
newInputConfig.Add(inputConfig);
}
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.
// 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;
ConfigurationState.Instance.Hid.EnableKeyboard.Value = EnableKeyboard;
ConfigurationState.Instance.Hid.EnableMouse.Value = EnableMouse;
ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
}
public void NotifyChange(string property)
{
OnPropertyChanged(property);
config.System.EnableDockedMode.Value = EnableDockedMode;
config.Hid.EnableKeyboard.Value = EnableKeyboard;
config.Hid.EnableMouse.Value = EnableMouse;
}
public void NotifyChanges()

View file

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

View file

@ -5,23 +5,18 @@ namespace Ryujinx.Ava.UI.Views.Settings
{
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();
}
public void SaveCurrentProfile()
{
_viewModel.Save();
}
public void Dispose()
{
_viewModel.Dispose();
ViewModel.Dispose();
}
}
}

View file

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