UI: fix: when switching players, it would show old config (#122)

When switching between players' gamepads while saving settings, then
returning to the previous player, the settings show the default settings
instead of the actual settings applied
This commit is contained in:
Vladimir Sokolov 2024-11-10 15:24:17 +10:00 committed by GitHub
parent b17e4f79fb
commit 299be822c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 119 additions and 7 deletions

View file

@ -413,6 +413,7 @@
"AvatarSetBackgroundColor": "Set Background Color",
"AvatarClose": "Close",
"ControllerSettingsLoadProfileToolTip": "Load Profile",
"ControllerSettingsViewProfileToolTip": "View Profile",
"ControllerSettingsAddProfileToolTip": "Add Profile",
"ControllerSettingsRemoveProfileToolTip": "Remove Profile",
"ControllerSettingsSaveProfileToolTip": "Save Profile",

View file

@ -30,6 +30,7 @@ namespace Ryujinx.Ava
{
internal partial class Program
{
//
public static double WindowScaleFactor { get; set; }
public static double DesktopScaleFactor { get; set; } = 1.0;
public static string Version { get; private set; }

View file

@ -226,6 +226,24 @@ namespace Ryujinx.Ava.UI.Helpers
(int)Symbol.Help,
primaryButtonResult);
internal static async Task<UserResult> CreateConfirmationDialogExtended(
string primaryText,
string secondaryText,
string acceptButtonText,
string noacceptButtonText,
string cancelButtonText,
string title,
UserResult primaryButtonResult = UserResult.Yes)
=> await ShowTextDialog(
string.IsNullOrWhiteSpace(title) ? LocaleManager.Instance[LocaleKeys.DialogConfirmationTitle] : title,
primaryText,
secondaryText,
acceptButtonText,
noacceptButtonText,
cancelButtonText,
(int)Symbol.Help,
primaryButtonResult);
internal static async Task<UserResult> CreateLocalizedConfirmationDialog(string primaryText, string secondaryText)
=> await CreateConfirmationDialog(
primaryText,

View file

@ -44,6 +44,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
private readonly MainWindow _mainWindow;
private PlayerIndex _playerId;
private PlayerIndex _playerIdChoose;
private int _controller;
private string _controllerImage;
private int _device;
@ -83,6 +84,12 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
}
}
public PlayerIndex PlayerIdChoose
{
get => _playerIdChoose;
set { }
}
public PlayerIndex PlayerId
{
get => _playerId;
@ -90,6 +97,8 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
{
if (IsModified)
{
_playerIdChoose = value;
return;
}
@ -99,7 +108,9 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
if (!Enum.IsDefined(typeof(PlayerIndex), _playerId))
{
_playerId = PlayerIndex.Player1;
}
_isLoaded = false;
LoadConfiguration();
LoadDevice();

View file

@ -4,11 +4,14 @@ using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
using DiscordRPC;
using Ryujinx.Ava.UI.Helpers;
using Ryujinx.Ava.UI.ViewModels.Input;
using Ryujinx.Common.Configuration.Hid.Controller;
using Ryujinx.Common.Logging;
using Ryujinx.Input;
using Ryujinx.Input.Assigner;
using System;
using StickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInputId;
namespace Ryujinx.Ava.UI.Views.Input
@ -27,6 +30,16 @@ namespace Ryujinx.Ava.UI.Views.Input
{
button.IsCheckedChanged += Button_IsCheckedChanged;
}
if (visual is CheckBox check)
{
check.IsCheckedChanged += CheckBox_IsCheckedChanged;
}
if (visual is Slider slider)
{
slider.PropertyChanged += Slider_IsCheckedChanged;
}
}
}
@ -40,9 +53,51 @@ namespace Ryujinx.Ava.UI.Views.Input
}
}
private float _changeSlider = -1.0f;
private void Slider_IsCheckedChanged(object sender, AvaloniaPropertyChangedEventArgs e)
{
if (sender is Slider check)
{
if ((bool)check.IsPointerOver && _changeSlider == -1.0f)
{
_changeSlider = (float)check.Value;
}
else if (!(bool)check.IsPointerOver)
{
_changeSlider = -1.0f;
}
if (_changeSlider != -1.0f && _changeSlider != (float)check.Value)
{
var viewModel = (DataContext as ControllerInputViewModel);
viewModel.ParentModel.IsModified = true;
_changeSlider = (float)check.Value;
}
}
}
private void CheckBox_IsCheckedChanged(object sender, RoutedEventArgs e)
{
if (sender is CheckBox check)
{
if ((bool)check.IsPointerOver)
{
var viewModel = (DataContext as ControllerInputViewModel);
viewModel.ParentModel.IsModified = true;
_currentAssigner?.Cancel();
_currentAssigner = null;
}
}
}
private void Button_IsCheckedChanged(object sender, RoutedEventArgs e)
{
if (sender is ToggleButton button)
if (sender is ToggleButton button )
{
if ((bool)button.IsChecked)
{
@ -149,7 +204,7 @@ namespace Ryujinx.Ava.UI.Views.Input
}
else
{
if (_currentAssigner != null)
if (_currentAssigner != null )
{
_currentAssigner.Cancel();
_currentAssigner = null;

View file

@ -108,7 +108,7 @@
ToolTip.Tip="{ext:Locale ControllerSettingsLoadProfileToolTip}"
Command="{Binding LoadProfile}">
<ui:SymbolIcon
Symbol="Upload"
Symbol="View"
FontSize="15"
Height="20" />
</Button>

View file

@ -25,17 +25,27 @@ namespace Ryujinx.Ava.UI.Views.Input
private async void PlayerIndexBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (PlayerIndexBox != null)
{
if (PlayerIndexBox.SelectedIndex != (int)ViewModel.PlayerId)
{
PlayerIndexBox.SelectedIndex = (int)ViewModel.PlayerId;
}
}
if (ViewModel.IsModified && !_dialogOpen)
{
_dialogOpen = true;
var result = await ContentDialogHelper.CreateConfirmationDialog(
var result = await ContentDialogHelper.CreateConfirmationDialogExtended(
LocaleManager.Instance[LocaleKeys.DialogControllerSettingsModifiedConfirmMessage],
LocaleManager.Instance[LocaleKeys.DialogControllerSettingsModifiedConfirmSubMessage],
LocaleManager.Instance[LocaleKeys.InputDialogYes],
LocaleManager.Instance[LocaleKeys.InputDialogNo],
LocaleManager.Instance[LocaleKeys.Cancel],
LocaleManager.Instance[LocaleKeys.RyujinxConfirm]);
if (result == UserResult.Yes)
{
ViewModel.Save();
@ -43,14 +53,30 @@ namespace Ryujinx.Ava.UI.Views.Input
_dialogOpen = false;
if (result == UserResult.Cancel)
{
return;
}
ViewModel.IsModified = false;
if (e.AddedItems.Count > 0)
if (result != UserResult.Cancel)
{
var player = (PlayerModel)e.AddedItems[0];
ViewModel.PlayerId = player.Id;
ViewModel.PlayerId = ViewModel.PlayerIdChoose;
}
if (result == UserResult.Cancel)
{
if (e.AddedItems.Count > 0)
{
ViewModel.IsModified = true;
var player = (PlayerModel)e.AddedItems[0];
ViewModel.PlayerId = player.Id;
}
}
}
}
public void Dispose()