Skip to content

Commit

Permalink
UI: fix: when switching players, it would show old config (#122)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Goodfeat authored Nov 10, 2024
1 parent b17e4f7 commit 299be82
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/Ryujinx/Assets/Locales/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/Ryujinx/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
18 changes: 18 additions & 0 deletions src/Ryujinx/UI/Helpers/ContentDialogHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,24 @@ internal static async Task<UserResult> CreateConfirmationDialog(
(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,
Expand Down
11 changes: 11 additions & 0 deletions src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class InputViewModel : BaseModel, IDisposable
private readonly MainWindow _mainWindow;

private PlayerIndex _playerId;
private PlayerIndex _playerIdChoose;
private int _controller;
private string _controllerImage;
private int _device;
Expand Down Expand Up @@ -83,13 +84,21 @@ public object ConfigViewModel
}
}

public PlayerIndex PlayerIdChoose
{
get => _playerIdChoose;
set { }
}

public PlayerIndex PlayerId
{
get => _playerId;
set
{
if (IsModified)
{

_playerIdChoose = value;
return;
}

Expand All @@ -99,7 +108,9 @@ public PlayerIndex PlayerId
if (!Enum.IsDefined(typeof(PlayerIndex), _playerId))
{
_playerId = PlayerIndex.Player1;

}
_isLoaded = false;

LoadConfiguration();
LoadDevice();
Expand Down
59 changes: 57 additions & 2 deletions src/Ryujinx/UI/Views/Input/ControllerInputView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
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
Expand All @@ -27,6 +30,16 @@ public ControllerInputView()
{
button.IsCheckedChanged += Button_IsCheckedChanged;
}

if (visual is CheckBox check)
{
check.IsCheckedChanged += CheckBox_IsCheckedChanged;
}

if (visual is Slider slider)
{
slider.PropertyChanged += Slider_IsCheckedChanged;
}
}
}

Expand All @@ -40,9 +53,51 @@ protected override void OnPointerReleased(PointerReleasedEventArgs e)
}
}

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)
{
Expand Down Expand Up @@ -149,7 +204,7 @@ private void Button_IsCheckedChanged(object sender, RoutedEventArgs e)
}
else
{
if (_currentAssigner != null)
if (_currentAssigner != null )
{
_currentAssigner.Cancel();
_currentAssigner = null;
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx/UI/Views/Input/InputView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
ToolTip.Tip="{ext:Locale ControllerSettingsLoadProfileToolTip}"
Command="{Binding LoadProfile}">
<ui:SymbolIcon
Symbol="Upload"
Symbol="View"
FontSize="15"
Height="20" />
</Button>
Expand Down
34 changes: 30 additions & 4 deletions src/Ryujinx/UI/Views/Input/InputView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,58 @@ public void SaveCurrentProfile()

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();
}

_dialogOpen = false;

if (result == UserResult.Cancel)
{

return;
}

ViewModel.IsModified = false;

if (e.AddedItems.Count > 0)
if (result != UserResult.Cancel)
{
ViewModel.PlayerId = ViewModel.PlayerIdChoose;
}

if (result == UserResult.Cancel)
{
var player = (PlayerModel)e.AddedItems[0];
ViewModel.PlayerId = player.Id;
if (e.AddedItems.Count > 0)
{
ViewModel.IsModified = true;
var player = (PlayerModel)e.AddedItems[0];
ViewModel.PlayerId = player.Id;
}
}
}

}

public void Dispose()
Expand Down

0 comments on commit 299be82

Please sign in to comment.