Skip to content

Commit

Permalink
Fixed the logic of saving the input section. Added a new dialog box w…
Browse files Browse the repository at this point in the history
…hen changing parameters
  • Loading branch information
Goodfeat committed Nov 3, 2024
1 parent 25499cb commit 0ab5767
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 7 deletions.
Binary file modified distribution/macos/Ryujinx.icns
Binary file not shown.
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 @@ -407,6 +407,7 @@
"AvatarSetBackgroundColor": "Set Background Color",
"AvatarClose": "Close",
"ControllerSettingsLoadProfileToolTip": "Load Profile",
"ControllerSettingsViewProfileToolTip": "View Profile",
"ControllerSettingsAddProfileToolTip": "Add Profile",
"ControllerSettingsRemoveProfileToolTip": "Remove Profile",
"ControllerSettingsSaveProfileToolTip": "Save Profile",
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
10 changes: 10 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,6 +108,7 @@ public PlayerIndex PlayerId
if (!Enum.IsDefined(typeof(PlayerIndex), _playerId))
{
_playerId = PlayerIndex.Player1;

}
_isLoaded = false;

Expand Down
60 changes: 58 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,52 @@ 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;
//Logger.Notice.Print(LogClass.Application, $"IsEnabled: {temp}\" \"{check.Value} {check.IsPointerOver}");
_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 +205,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 0ab5767

Please sign in to comment.