diff --git a/src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs b/src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs index a39e785c3..c77df8100 100644 --- a/src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs +++ b/src/Ryujinx.Ava/UI/Helpers/ButtonKeyAssigner.cs @@ -1,7 +1,7 @@ using Avalonia; -using Avalonia.Data; using Avalonia.Controls; using Avalonia.Controls.Primitives; +using Avalonia.Data; using Avalonia.LogicalTree; using Avalonia.Threading; using Ryujinx.Ava.Common.Locale; @@ -19,7 +19,7 @@ namespace Ryujinx.Ava.UI.Helpers { public ToggleButton Button { get; } public bool IsAssigned { get; } - public object Key { get; } + public object Key { get; } public ButtonAssignedEventArgs(ToggleButton button, bool isAssigned, object key) { @@ -107,4 +107,4 @@ namespace Ryujinx.Ava.UI.Helpers _shouldUnbind = shouldUnbind; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs b/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs index cb3e171fa..4929e582e 100644 --- a/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs +++ b/src/Ryujinx.Ava/UI/Models/Input/ControllerInputConfig.cs @@ -565,7 +565,7 @@ namespace Ryujinx.Ava.UI.Models.Input } else { - config.Motion = new MotionConfigController + config.Motion = new MotionConfigController { EnableMotion = EnableMotion, MotionBackend = MotionInputBackendType.GamepadDriver, @@ -577,4 +577,4 @@ namespace Ryujinx.Ava.UI.Models.Input return config; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs b/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs index 8355f26fb..029565210 100644 --- a/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs +++ b/src/Ryujinx.Ava/UI/Models/Input/KeyboardInputConfig.cs @@ -419,4 +419,4 @@ namespace Ryujinx.Ava.UI.Models.Input return config; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs index bf94101d4..0e23dfa76 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/ControllerInputViewModel.cs @@ -81,4 +81,4 @@ namespace Ryujinx.Ava.UI.ViewModels.Input Image = parentModel.Image; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs index 0c0258679..a1303372f 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs @@ -889,4 +889,4 @@ namespace Ryujinx.Ava.UI.ViewModels.Input AvaloniaKeyboardDriver.Dispose(); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs index 7b7e9bbe7..a93873063 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/KeyboardInputViewModel.cs @@ -70,4 +70,4 @@ namespace Ryujinx.Ava.UI.ViewModels.Input Image = parentModel.Image; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs index 58f0339c9..edf7b6eba 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs @@ -25,8 +25,7 @@ namespace Ryujinx.Ava.UI.Views.Input { if (visual is ToggleButton button && !(visual is CheckBox)) { - button.Checked += Button_Checked; - button.Unchecked += Button_Unchecked; + button.IsCheckedChanged += Button_IsCheckedChanged; } } } @@ -41,129 +40,131 @@ namespace Ryujinx.Ava.UI.Views.Input } } - private void Button_Checked(object sender, RoutedEventArgs e) + private void Button_IsCheckedChanged(object sender, RoutedEventArgs e) { if (sender is ToggleButton button) { - if (_currentAssigner != null && button == _currentAssigner.ToggledButton) + if ((bool)button.IsChecked) { - return; - } - - bool isStick = button.Tag != null && button.Tag.ToString() == "stick"; - - if (_currentAssigner == null && (bool)button.IsChecked) - { - _currentAssigner = new ButtonKeyAssigner(button); - - FocusManager.Instance.Focus(this, NavigationMethod.Pointer); - - PointerPressed += MouseClick; - - IKeyboard keyboard = (IKeyboard)(DataContext as ControllerInputViewModel).parentModel.AvaloniaKeyboardDriver.GetGamepad("0"); // Open Avalonia keyboard for cancel operations. - IButtonAssigner assigner = CreateButtonAssigner(isStick); - - _currentAssigner.ButtonAssigned += (sender, e) => + if (_currentAssigner != null && button == _currentAssigner.ToggledButton) { - if (e.IsAssigned) + return; + } + + bool isStick = button.Tag != null && button.Tag.ToString() == "stick"; + + if (_currentAssigner == null && (bool)button.IsChecked) + { + _currentAssigner = new ButtonKeyAssigner(button); + + this.Focus(NavigationMethod.Pointer); + + PointerPressed += MouseClick; + + IKeyboard keyboard = (IKeyboard)(DataContext as ControllerInputViewModel).parentModel.AvaloniaKeyboardDriver.GetGamepad("0"); // Open Avalonia keyboard for cancel operations. + IButtonAssigner assigner = CreateButtonAssigner(isStick); + + _currentAssigner.ButtonAssigned += (sender, e) => { - var viewModel = (DataContext as ControllerInputViewModel); - viewModel.parentModel.IsModified = true; - - switch (button.Name) + if (e.IsAssigned) { - case "ButtonZl": - viewModel.Config.ButtonZl = (GamepadInputId)e.Key; - break; - case "ButtonL": - viewModel.Config.ButtonL = (GamepadInputId)e.Key; - break; - case "ButtonMinus": - viewModel.Config.ButtonMinus = (GamepadInputId)e.Key; - break; - case "LeftStickButton": - viewModel.Config.LeftStickButton = (GamepadInputId)e.Key; - break; - case "LeftJoystick": - viewModel.Config.LeftJoystick = (StickInputId)e.Key; - break; - case "DpadUp": - viewModel.Config.DpadUp = (GamepadInputId)e.Key; - break; - case "DpadDown": - viewModel.Config.DpadDown = (GamepadInputId)e.Key; - break; - case "DpadLeft": - viewModel.Config.DpadLeft = (GamepadInputId)e.Key; - break; - case "DpadRight": - viewModel.Config.DpadRight = (GamepadInputId)e.Key; - break; - case "LeftButtonSr": - viewModel.Config.LeftButtonSr = (GamepadInputId)e.Key; - break; - case "LeftButtonSl": - viewModel.Config.LeftButtonSl = (GamepadInputId)e.Key; - break; - case "RightButtonSr": - viewModel.Config.RightButtonSr = (GamepadInputId)e.Key; - break; - case "RightButtonSl": - viewModel.Config.RightButtonSl = (GamepadInputId)e.Key; - break; - case "ButtonZr": - viewModel.Config.ButtonZr = (GamepadInputId)e.Key; - break; - case "ButtonR": - viewModel.Config.ButtonR = (GamepadInputId)e.Key; - break; - case "ButtonPlus": - viewModel.Config.ButtonPlus = (GamepadInputId)e.Key; - break; - case "ButtonA": - viewModel.Config.ButtonA = (GamepadInputId)e.Key; - break; - case "ButtonB": - viewModel.Config.ButtonB = (GamepadInputId)e.Key; - break; - case "ButtonX": - viewModel.Config.ButtonX = (GamepadInputId)e.Key; - break; - case "ButtonY": - viewModel.Config.ButtonY = (GamepadInputId)e.Key; - break; - case "RightStickButton": - viewModel.Config.RightStickButton = (GamepadInputId)e.Key; - break; - case "RightJoystick": - viewModel.Config.RightJoystick = (StickInputId)e.Key; - break; - } - } - }; + var viewModel = (DataContext as ControllerInputViewModel); + viewModel.parentModel.IsModified = true; - _currentAssigner.GetInputAndAssign(assigner, keyboard); + switch (button.Name) + { + case "ButtonZl": + viewModel.Config.ButtonZl = (GamepadInputId)e.Key; + break; + case "ButtonL": + viewModel.Config.ButtonL = (GamepadInputId)e.Key; + break; + case "ButtonMinus": + viewModel.Config.ButtonMinus = (GamepadInputId)e.Key; + break; + case "LeftStickButton": + viewModel.Config.LeftStickButton = (GamepadInputId)e.Key; + break; + case "LeftJoystick": + viewModel.Config.LeftJoystick = (StickInputId)e.Key; + break; + case "DpadUp": + viewModel.Config.DpadUp = (GamepadInputId)e.Key; + break; + case "DpadDown": + viewModel.Config.DpadDown = (GamepadInputId)e.Key; + break; + case "DpadLeft": + viewModel.Config.DpadLeft = (GamepadInputId)e.Key; + break; + case "DpadRight": + viewModel.Config.DpadRight = (GamepadInputId)e.Key; + break; + case "LeftButtonSr": + viewModel.Config.LeftButtonSr = (GamepadInputId)e.Key; + break; + case "LeftButtonSl": + viewModel.Config.LeftButtonSl = (GamepadInputId)e.Key; + break; + case "RightButtonSr": + viewModel.Config.RightButtonSr = (GamepadInputId)e.Key; + break; + case "RightButtonSl": + viewModel.Config.RightButtonSl = (GamepadInputId)e.Key; + break; + case "ButtonZr": + viewModel.Config.ButtonZr = (GamepadInputId)e.Key; + break; + case "ButtonR": + viewModel.Config.ButtonR = (GamepadInputId)e.Key; + break; + case "ButtonPlus": + viewModel.Config.ButtonPlus = (GamepadInputId)e.Key; + break; + case "ButtonA": + viewModel.Config.ButtonA = (GamepadInputId)e.Key; + break; + case "ButtonB": + viewModel.Config.ButtonB = (GamepadInputId)e.Key; + break; + case "ButtonX": + viewModel.Config.ButtonX = (GamepadInputId)e.Key; + break; + case "ButtonY": + viewModel.Config.ButtonY = (GamepadInputId)e.Key; + break; + case "RightStickButton": + viewModel.Config.RightStickButton = (GamepadInputId)e.Key; + break; + case "RightJoystick": + viewModel.Config.RightJoystick = (StickInputId)e.Key; + break; + } + } + }; + + _currentAssigner.GetInputAndAssign(assigner, keyboard); + } + else + { + if (_currentAssigner != null) + { + ToggleButton oldButton = _currentAssigner.ToggledButton; + + _currentAssigner.Cancel(); + _currentAssigner = null; + button.IsChecked = false; + } + } } else { - if (_currentAssigner != null) - { - ToggleButton oldButton = _currentAssigner.ToggledButton; - - _currentAssigner.Cancel(); - _currentAssigner = null; - button.IsChecked = false; - } + _currentAssigner?.Cancel(); + _currentAssigner = null; } } } - private void Button_Unchecked(object sender, RoutedEventArgs e) - { - _currentAssigner?.Cancel(); - _currentAssigner = null; - } - private void MouseClick(object sender, PointerPressedEventArgs e) { bool shouldUnbind = e.GetCurrentPoint(this).Properties.IsMiddleButtonPressed; @@ -189,4 +190,4 @@ namespace Ryujinx.Ava.UI.Views.Input _currentAssigner = null; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml b/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml index a1cd3ba52..639de58e6 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml +++ b/src/Ryujinx.Ava/UI/Views/Input/InputView.axaml @@ -63,7 +63,7 @@ HorizontalAlignment="Stretch" VerticalAlignment="Center" SelectionChanged="PlayerIndexBox_OnSelectionChanged" - Items="{Binding PlayerIndexes}" + ItemsSource="{Binding PlayerIndexes}" SelectedIndex="{Binding PlayerId}"> @@ -91,14 +91,14 @@ HorizontalAlignment="Left" VerticalAlignment="Center" Text="{locale:Locale ControllerSettingsProfile}" /> -