From 40152db813f890b7b0a826fa0b6f6d772e2ee595 Mon Sep 17 00:00:00 2001 From: madwind Date: Mon, 3 Mar 2025 16:40:13 +0800 Subject: [PATCH] Revert "Stick Visualizer (#579)" This reverts commit c3af1dbf1a82ce593c587d7ed4f9e5f8eea4b7ef. --- .../UI/Applet/ProfileSelectorDialog.axaml | 8 +- .../UI/Models/Input/StickVisualizer.cs | 260 ------------------ .../Input/ControllerInputViewModel.cs | 37 +-- .../UI/ViewModels/Input/InputViewModel.cs | 23 +- .../Input/KeyboardInputViewModel.cs | 27 +- .../UI/Views/Input/ControllerInputView.axaml | 145 ++++------ src/Ryujinx/UI/Views/Input/InputView.axaml | 42 ++- .../UI/Views/Input/KeyboardInputView.axaml | 104 ++----- .../UI/Views/Input/MotionInputView.axaml | 22 +- .../UI/Views/Input/RumbleInputView.axaml | 6 +- .../UI/Views/Misc/ApplicationGridView.axaml | 11 +- .../UI/Views/Misc/ApplicationListView.axaml | 5 +- .../UI/Views/Settings/SettingsInputView.axaml | 7 +- .../UI/Views/Settings/SettingsUIView.axaml | 14 +- .../UI/Views/User/UserEditorView.axaml | 10 +- .../User/UserFirmwareAvatarSelectorView.axaml | 8 +- .../User/UserProfileImageSelectorView.axaml | 7 +- .../UI/Views/User/UserRecovererView.axaml | 12 +- .../UI/Views/User/UserSaveManagerView.axaml | 25 +- .../UI/Views/User/UserSelectorView.axaml | 6 +- .../Windows/GameSpecificSettingsWindow.axaml | 16 +- src/Ryujinx/UI/Windows/ModManagerWindow.axaml | 6 +- src/Ryujinx/UI/Windows/SettingsWindow.axaml | 2 +- src/Ryujinx/UI/Windows/UpdateWaitWindow.axaml | 10 +- src/Ryujinx/UI/Windows/XCITrimmerWindow.axaml | 44 ++- 25 files changed, 306 insertions(+), 551 deletions(-) delete mode 100644 src/Ryujinx/UI/Models/Input/StickVisualizer.cs diff --git a/src/Ryujinx/UI/Applet/ProfileSelectorDialog.axaml b/src/Ryujinx/UI/Applet/ProfileSelectorDialog.axaml index 20d466031..d929cc501 100644 --- a/src/Ryujinx/UI/Applet/ProfileSelectorDialog.axaml +++ b/src/Ryujinx/UI/Applet/ProfileSelectorDialog.axaml @@ -17,8 +17,12 @@ - - + + + + + + _type; - set - { - _type = value; - - OnPropertyChanged(); - } - } - - private GamepadInputConfig _gamepadConfig; - public GamepadInputConfig GamepadConfig - { - get => _gamepadConfig; - set - { - _gamepadConfig = value; - - OnPropertyChanged(); - } - } - - private KeyboardInputConfig _keyboardConfig; - public KeyboardInputConfig KeyboardConfig - { - get => _keyboardConfig; - set - { - _keyboardConfig = value; - - OnPropertyChanged(); - } - } - - private (float, float) _uiStickLeft; - public (float, float) UiStickLeft - { - get => (_uiStickLeft.Item1 * DrawStickScaleFactor, _uiStickLeft.Item2 * DrawStickScaleFactor); - set - { - _uiStickLeft = value; - - OnPropertyChanged(); - OnPropertyChanged(nameof(UiStickRightX)); - OnPropertyChanged(nameof(UiStickRightY)); - OnPropertyChanged(nameof(UiDeadzoneRight)); - } - } - - private (float, float) _uiStickRight; - public (float, float) UiStickRight - { - get => (_uiStickRight.Item1 * DrawStickScaleFactor, _uiStickRight.Item2 * DrawStickScaleFactor); - set - { - _uiStickRight = value; - - OnPropertyChanged(); - OnPropertyChanged(nameof(UiStickLeftX)); - OnPropertyChanged(nameof(UiStickLeftY)); - OnPropertyChanged(nameof(UiDeadzoneLeft)); - } - } - - public float UiStickLeftX => ClampVector(UiStickLeft).Item1; - public float UiStickLeftY => ClampVector(UiStickLeft).Item2; - public float UiStickRightX => ClampVector(UiStickRight).Item1; - public float UiStickRightY => ClampVector(UiStickRight).Item2; - - public int UiStickCircumference => DrawStickCircumference; - public int UiCanvasSize => DrawStickCanvasSize; - public int UiStickBorderSize => DrawStickBorderSize; - - public float? UiDeadzoneLeft => _gamepadConfig?.DeadzoneLeft * DrawStickCanvasSize - DrawStickCircumference; - public float? UiDeadzoneRight => _gamepadConfig?.DeadzoneRight * DrawStickCanvasSize - DrawStickCircumference; - - private InputViewModel Parent; - - public StickVisualizer(InputViewModel parent) - { - Parent = parent; - - PollTokenSource = new CancellationTokenSource(); - PollToken = PollTokenSource.Token; - - Task.Run(Initialize, PollToken); - } - - public void UpdateConfig(object config) - { - if (config is ControllerInputViewModel padConfig) - { - GamepadConfig = padConfig.Config; - Type = DeviceType.Controller; - - return; - } - else if (config is KeyboardInputViewModel keyConfig) - { - KeyboardConfig = keyConfig.Config; - Type = DeviceType.Keyboard; - - return; - } - - Type = DeviceType.None; - } - - public async Task Initialize() - { - (float, float) leftBuffer; - (float, float) rightBuffer; - - while (!PollToken.IsCancellationRequested) - { - leftBuffer = (0f, 0f); - rightBuffer = (0f, 0f); - - switch (Type) - { - case DeviceType.Keyboard: - IKeyboard keyboard = (IKeyboard)Parent.AvaloniaKeyboardDriver.GetGamepad("0"); - - if (keyboard != null) - { - KeyboardStateSnapshot snapshot = keyboard.GetKeyboardStateSnapshot(); - - if (snapshot.IsPressed((Key)KeyboardConfig.LeftStickRight)) - { - leftBuffer.Item1 += 1; - } - if (snapshot.IsPressed((Key)KeyboardConfig.LeftStickLeft)) - { - leftBuffer.Item1 -= 1; - } - if (snapshot.IsPressed((Key)KeyboardConfig.LeftStickUp)) - { - leftBuffer.Item2 += 1; - } - if (snapshot.IsPressed((Key)KeyboardConfig.LeftStickDown)) - { - leftBuffer.Item2 -= 1; - } - - if (snapshot.IsPressed((Key)KeyboardConfig.RightStickRight)) - { - rightBuffer.Item1 += 1; - } - if (snapshot.IsPressed((Key)KeyboardConfig.RightStickLeft)) - { - rightBuffer.Item1 -= 1; - } - if (snapshot.IsPressed((Key)KeyboardConfig.RightStickUp)) - { - rightBuffer.Item2 += 1; - } - if (snapshot.IsPressed((Key)KeyboardConfig.RightStickDown)) - { - rightBuffer.Item2 -= 1; - } - - UiStickLeft = leftBuffer; - UiStickRight = rightBuffer; - } - break; - - case DeviceType.Controller: - IGamepad controller = Parent.SelectedGamepad; - - if (controller != null) - { - leftBuffer = controller.GetStick((StickInputId)GamepadConfig.LeftJoystick); - rightBuffer = controller.GetStick((StickInputId)GamepadConfig.RightJoystick); - } - break; - - case DeviceType.None: - break; - default: - throw new ArgumentException($"Unable to poll device type \"{Type}\""); - } - - UiStickLeft = leftBuffer; - UiStickRight = rightBuffer; - - await Task.Delay(DrawStickPollRate, PollToken); - } - - PollTokenSource.Dispose(); - } - - public static (float, float) ClampVector((float, float) vect) - { - _vectorMultiplier = 1; - _vectorLength = MathF.Sqrt((vect.Item1 * vect.Item1) + (vect.Item2 * vect.Item2)); - - if (_vectorLength > MaxVectorLength) - { - _vectorMultiplier = MaxVectorLength / _vectorLength; - } - - vect.Item1 = vect.Item1 * _vectorMultiplier + DrawStickCanvasCenter; - vect.Item2 = vect.Item2 * _vectorMultiplier + DrawStickCanvasCenter; - - return vect; - } - - protected virtual void Dispose(bool disposing) - { - if (!disposedValue) - { - if (disposing) - { - PollTokenSource.Cancel(); - } - - KeyboardConfig = null; - GamepadConfig = null; - Parent = null; - - disposedValue = true; - } - } - - public void Dispose() - { - Dispose(disposing: true); - GC.SuppressFinalize(this); - } - } -} diff --git a/src/Ryujinx/UI/ViewModels/Input/ControllerInputViewModel.cs b/src/Ryujinx/UI/ViewModels/Input/ControllerInputViewModel.cs index 96da58b5d..2b644cffa 100644 --- a/src/Ryujinx/UI/ViewModels/Input/ControllerInputViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/Input/ControllerInputViewModel.cs @@ -1,9 +1,5 @@ using Avalonia.Svg.Skia; using CommunityToolkit.Mvvm.ComponentModel; -using CommunityToolkit.Mvvm.Input; -using FluentAvalonia.UI.Controls; -using Ryujinx.Ava.Input; -using Ryujinx.Ava.UI.Helpers; using Ryujinx.Ava.UI.Models.Input; using Ryujinx.Ava.UI.Views.Input; using Ryujinx.Common.Utilities; @@ -14,30 +10,8 @@ namespace Ryujinx.Ava.UI.ViewModels.Input { public partial class ControllerInputViewModel : BaseModel { - private GamepadInputConfig _config; - public GamepadInputConfig Config - { - get => _config; - set - { - _config = value; + [ObservableProperty] private GamepadInputConfig _config; - OnPropertyChanged(); - } - } - - private StickVisualizer _visualizer; - public StickVisualizer Visualizer - { - get => _visualizer; - set - { - _visualizer = value; - - OnPropertyChanged(); - } - } - private bool _isLeft; public bool IsLeft { @@ -63,15 +37,14 @@ namespace Ryujinx.Ava.UI.ViewModels.Input } public bool HasSides => IsLeft ^ IsRight; - + [ObservableProperty] private SvgImage _image; - + public InputViewModel ParentModel { get; } - - public ControllerInputViewModel(InputViewModel model, GamepadInputConfig config, StickVisualizer visualizer) + + public ControllerInputViewModel(InputViewModel model, GamepadInputConfig config) { ParentModel = model; - Visualizer = visualizer; model.NotifyChangesEvent += OnParentModelChanged; OnParentModelChanged(); config.PropertyChanged += (_, args) => diff --git a/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs b/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs index b324d39e8..5b7bcfd32 100644 --- a/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs @@ -49,7 +49,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input private int _controller; private string _controllerImage; private int _device; - private object _configViewModel; + [ObservableProperty] private object _configViewModel; [ObservableProperty] private string _profileName; private bool _isLoaded; @@ -74,7 +74,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Input OnPropertiesChanged(nameof(HasLed), nameof(CanClearLed)); } } - public StickVisualizer VisualStick { get; private set; } public ObservableCollection PlayerIndexes { get; set; } public ObservableCollection<(DeviceType Type, string Id, string Name)> Devices { get; set; } @@ -95,19 +94,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Input public bool IsModified { get; set; } public event Action NotifyChangesEvent; - public object ConfigViewModel - { - get => _configViewModel; - set - { - _configViewModel = value; - - VisualStick.UpdateConfig(value); - - OnPropertyChanged(); - } - } - public PlayerIndex PlayerIdChoose { get => _playerIdChoose; @@ -283,7 +269,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Input Devices = []; ProfilesList = []; DeviceList = []; - VisualStick = new StickVisualizer(this); ControllerImage = ProControllerResource; @@ -304,12 +289,12 @@ namespace Ryujinx.Ava.UI.ViewModels.Input if (Config is StandardKeyboardInputConfig keyboardInputConfig) { - ConfigViewModel = new KeyboardInputViewModel(this, new KeyboardInputConfig(keyboardInputConfig), VisualStick); + ConfigViewModel = new KeyboardInputViewModel(this, new KeyboardInputConfig(keyboardInputConfig)); } if (Config is StandardControllerInputConfig controllerInputConfig) { - ConfigViewModel = new ControllerInputViewModel(this, new GamepadInputConfig(controllerInputConfig), VisualStick); + ConfigViewModel = new ControllerInputViewModel(this, new GamepadInputConfig(controllerInputConfig)); } } @@ -908,8 +893,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Input _mainWindow.ViewModel.AppHost?.NpadManager.UnblockInputUpdates(); - VisualStick.Dispose(); - SelectedGamepad?.Dispose(); AvaloniaKeyboardDriver.Dispose(); diff --git a/src/Ryujinx/UI/ViewModels/Input/KeyboardInputViewModel.cs b/src/Ryujinx/UI/ViewModels/Input/KeyboardInputViewModel.cs index bab8db7ce..5ff9bb578 100644 --- a/src/Ryujinx/UI/ViewModels/Input/KeyboardInputViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/Input/KeyboardInputViewModel.cs @@ -6,29 +6,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input { public partial class KeyboardInputViewModel : BaseModel { - private KeyboardInputConfig _config; - public KeyboardInputConfig Config - { - get => _config; - set - { - _config = value; - - OnPropertyChanged(); - } - } - - private StickVisualizer _visualizer; - public StickVisualizer Visualizer - { - get => _visualizer; - set - { - _visualizer = value; - - OnPropertyChanged(); - } - } + [ObservableProperty] private KeyboardInputConfig _config; private bool _isLeft; public bool IsLeft @@ -60,10 +38,9 @@ namespace Ryujinx.Ava.UI.ViewModels.Input public readonly InputViewModel ParentModel; - public KeyboardInputViewModel(InputViewModel model, KeyboardInputConfig config, StickVisualizer visualizer) + public KeyboardInputViewModel(InputViewModel model, KeyboardInputConfig config) { ParentModel = model; - Visualizer = visualizer; model.NotifyChangesEvent += OnParentModelChanged; OnParentModelChanged(); Config = config; diff --git a/src/Ryujinx/UI/Views/Input/ControllerInputView.axaml b/src/Ryujinx/UI/Views/Input/ControllerInputView.axaml index 555ded9fc..49c2cfd4c 100644 --- a/src/Ryujinx/UI/Views/Input/ControllerInputView.axaml +++ b/src/Ryujinx/UI/Views/Input/ControllerInputView.axaml @@ -34,7 +34,12 @@ + MinHeight="450"> + + + + + + HorizontalAlignment="Stretch"> + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - @@ -414,8 +345,8 @@ Minimum="0" Value="{Binding Config.TriggerThreshold, Mode=TwoWay}" /> + Width="25" + Text="{Binding Config.TriggerThreshold, StringFormat=\{0:0.00\}}" /> @@ -507,7 +438,11 @@ CornerRadius="5" VerticalAlignment="Bottom" HorizontalAlignment="Stretch"> - + + + + + - + + + + + - + + + + + + HorizontalAlignment="Stretch"> + + + + + + + + - + + + + + + + VerticalAlignment="Center"> + + + + + VerticalAlignment="Center"> + + + + + + + - + + + + + + + HorizontalAlignment="Stretch"> + + + + + + VerticalAlignment="Center"> + + + + + MinHeight="450"> + + + + + + HorizontalAlignment="Stretch"> + + + + + + + + - - - - - - - - - - - - - - - - - - - - + MaxHeight="300" + HorizontalAlignment="Stretch" + VerticalAlignment="Stretch" + Source="{Binding Image}" /> + HorizontalAlignment="Stretch"> + + + + + + + + - + + + + + - + + + + + - + + + + + + + + + - + + + + + - + + + + - + + + + + - + + + + - + + + + + + diff --git a/src/Ryujinx/UI/Views/Settings/SettingsUIView.axaml b/src/Ryujinx/UI/Views/Settings/SettingsUIView.axaml index 7dd5211a7..2a46dcf49 100644 --- a/src/Ryujinx/UI/Views/Settings/SettingsUIView.axaml +++ b/src/Ryujinx/UI/Views/Settings/SettingsUIView.axaml @@ -177,7 +177,12 @@ - + + + + + + - + + + + + + - + + + + + + + + + + VerticalAlignment="Stretch"> + + + + + + + VerticalAlignment="Center"> + + + + + + VerticalAlignment="Stretch"> + + + + - + + + + + - + + + + + + + HorizontalAlignment="Stretch"> + + + + + Margin="10,0, 0, 0"> + + + +