diff --git a/src/Ryujinx/UI/Views/Input/KeyboardInputView.axaml.cs b/src/Ryujinx/UI/Views/Input/KeyboardInputView.axaml.cs index 6eef81e97..9fa25fa6f 100644 --- a/src/Ryujinx/UI/Views/Input/KeyboardInputView.axaml.cs +++ b/src/Ryujinx/UI/Views/Input/KeyboardInputView.axaml.cs @@ -8,6 +8,8 @@ using Ryujinx.Ava.UI.Helpers; using Ryujinx.Ava.UI.ViewModels.Input; using Ryujinx.Input; using Ryujinx.Input.Assigner; +using System.Collections.Generic; +using System; using Button = Ryujinx.Input.Button; using Key = Ryujinx.Common.Configuration.Hid.Key; @@ -193,11 +195,65 @@ namespace Ryujinx.Ava.UI.Views.Input { bool shouldUnbind = e.GetCurrentPoint(this).Properties.IsMiddleButtonPressed; + bool shouldRemoveBinding = e.GetCurrentPoint(this).Properties.IsRightButtonPressed; + + if (shouldRemoveBinding) + { + DeleteBind(); + } + _currentAssigner?.Cancel(shouldUnbind); PointerPressed -= MouseClick; } + private void DeleteBind() + { + if (DataContext is not KeyboardInputViewModel viewModel) + return; + + if (_currentAssigner != null) + { + Dictionary buttonActions = new Dictionary + { + { "ButtonZl", () => viewModel.Config.ButtonZl = Key.Unbound }, + { "ButtonL", () => viewModel.Config.ButtonL = Key.Unbound }, + { "ButtonMinus", () => viewModel.Config.ButtonMinus = Key.Unbound }, + { "LeftStickButton", () => viewModel.Config.LeftStickButton = Key.Unbound }, + { "LeftStickUp", () => viewModel.Config.LeftStickUp = Key.Unbound }, + { "LeftStickDown", () => viewModel.Config.LeftStickDown = Key.Unbound }, + { "LeftStickRight", () => viewModel.Config.LeftStickRight = Key.Unbound }, + { "LeftStickLeft", () => viewModel.Config.LeftStickLeft = Key.Unbound }, + { "DpadUp", () => viewModel.Config.DpadUp = Key.Unbound }, + { "DpadDown", () => viewModel.Config.DpadDown = Key.Unbound }, + { "DpadLeft", () => viewModel.Config.DpadLeft = Key.Unbound }, + { "DpadRight", () => viewModel.Config.DpadRight = Key.Unbound }, + { "LeftButtonSr", () => viewModel.Config.LeftButtonSr = Key.Unbound }, + { "LeftButtonSl", () => viewModel.Config.LeftButtonSl = Key.Unbound }, + { "RightButtonSr", () => viewModel.Config.RightButtonSr = Key.Unbound }, + { "RightButtonSl", () => viewModel.Config.RightButtonSl = Key.Unbound }, + { "ButtonZr", () => viewModel.Config.ButtonZr = Key.Unbound }, + { "ButtonR", () => viewModel.Config.ButtonR = Key.Unbound }, + { "ButtonPlus", () => viewModel.Config.ButtonPlus = Key.Unbound }, + { "ButtonA", () => viewModel.Config.ButtonA = Key.Unbound }, + { "ButtonB", () => viewModel.Config.ButtonB = Key.Unbound }, + { "ButtonX", () => viewModel.Config.ButtonX = Key.Unbound }, + { "ButtonY", () => viewModel.Config.ButtonY = Key.Unbound }, + { "RightStickButton", () => viewModel.Config.RightStickButton = Key.Unbound }, + { "RightStickUp", () => viewModel.Config.RightStickUp = Key.Unbound }, + { "RightStickDown", () => viewModel.Config.RightStickDown = Key.Unbound }, + { "RightStickRight", () => viewModel.Config.RightStickRight = Key.Unbound }, + { "RightStickLeft", () => viewModel.Config.RightStickLeft = Key.Unbound } + }; + + if (buttonActions.TryGetValue(_currentAssigner.ToggledButton.Name, out Action action)) + { + action(); + FlagInputConfigChanged(); + } + } + } + protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e) { base.OnDetachedFromVisualTree(e); diff --git a/src/Ryujinx/UI/Views/Settings/SettingsHotkeysView.axaml.cs b/src/Ryujinx/UI/Views/Settings/SettingsHotkeysView.axaml.cs index d3d1537e0..759c9014e 100644 --- a/src/Ryujinx/UI/Views/Settings/SettingsHotkeysView.axaml.cs +++ b/src/Ryujinx/UI/Views/Settings/SettingsHotkeysView.axaml.cs @@ -8,6 +8,8 @@ using Ryujinx.Ava.UI.Helpers; using Ryujinx.Ava.UI.ViewModels; using Ryujinx.Input; using Ryujinx.Input.Assigner; +using System.Collections.Generic; +using System; using Button = Ryujinx.Input.Button; using Key = Ryujinx.Common.Configuration.Hid.Key; @@ -46,12 +48,47 @@ namespace Ryujinx.Ava.UI.Views.Settings private void MouseClick(object sender, PointerPressedEventArgs e) { bool shouldUnbind = e.GetCurrentPoint(this).Properties.IsMiddleButtonPressed; + bool shouldRemoveBinding = e.GetCurrentPoint(this).Properties.IsRightButtonPressed; + if (shouldRemoveBinding) + { + DeleteBind(); + } + _currentAssigner?.Cancel(shouldUnbind); PointerPressed -= MouseClick; } + private void DeleteBind() + { + if (DataContext is not SettingsViewModel viewModel) + return; + + if (_currentAssigner != null) + { + Dictionary buttonActions = new Dictionary + { + { "ToggleVSyncMode", () => viewModel.KeyboardHotkey.ToggleVSyncMode = Key.Unbound }, + { "Screenshot", () => viewModel.KeyboardHotkey.Screenshot = Key.Unbound }, + { "ShowUI", () => viewModel.KeyboardHotkey.ShowUI = Key.Unbound }, + { "Pause", () => viewModel.KeyboardHotkey.Pause = Key.Unbound }, + { "ToggleMute", () => viewModel.KeyboardHotkey.ToggleMute = Key.Unbound }, + { "ResScaleUp", () => viewModel.KeyboardHotkey.ResScaleUp = Key.Unbound }, + { "ResScaleDown", () => viewModel.KeyboardHotkey.ResScaleDown = Key.Unbound }, + { "VolumeUp", () => viewModel.KeyboardHotkey.VolumeUp = Key.Unbound }, + { "VolumeDown", () => viewModel.KeyboardHotkey.VolumeDown = Key.Unbound }, + { "CustomVSyncIntervalIncrement", () => viewModel.KeyboardHotkey.CustomVSyncIntervalIncrement = Key.Unbound }, + { "CustomVSyncIntervalDecrement", () => viewModel.KeyboardHotkey.CustomVSyncIntervalDecrement = Key.Unbound } + }; + + if (buttonActions.TryGetValue(_currentAssigner.ToggledButton.Name, out Action action)) + { + action(); + } + } + } + private void Button_IsCheckedChanged(object sender, RoutedEventArgs e) { if (sender is ToggleButton button)