From e911876f763e554223f894d76e64f63556c77318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Hamil?= Date: Sun, 18 Aug 2024 21:16:29 +0300 Subject: [PATCH] Move cycle controllers code to InputViewModel --- src/Ryujinx/AppHost.cs | 12 +++--------- src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs | 8 ++++++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Ryujinx/AppHost.cs b/src/Ryujinx/AppHost.cs index 100022d07..d0a274546 100644 --- a/src/Ryujinx/AppHost.cs +++ b/src/Ryujinx/AppHost.cs @@ -1210,15 +1210,9 @@ namespace Ryujinx.Ava case KeyboardHotkeyState.CycleControllersPlayer6: case KeyboardHotkeyState.CycleControllersPlayer7: case KeyboardHotkeyState.CycleControllersPlayer8: - Dispatcher.UIThread.Invoke(() => { - var player = currentHotkeyState - KeyboardHotkeyState.CycleControllersPlayer1; - var ivm = new UI.ViewModels.Input.InputViewModel(); - ivm.LoadDevices(); - ivm.PlayerId = (Ryujinx.Common.Configuration.Hid.PlayerIndex) player; - ivm.Device = (ivm.Device + 1) % ivm.Devices.Count; - ivm.Save(); - Console.WriteLine($"Cycling controller for player {ivm.PlayerId} to {ivm.Devices[ivm.Device].Name}"); - }); + var player = currentHotkeyState - KeyboardHotkeyState.CycleControllersPlayer1; + var ivm = new UI.ViewModels.Input.InputViewModel(); + Dispatcher.UIThread.Invoke(() => ivm.CyclePlayerDevice(player)); break; case KeyboardHotkeyState.None: (_keyboardInterface as AvaloniaKeyboard).Clear(); diff --git a/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs b/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs index 221e9d044..c2bbc6477 100644 --- a/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs @@ -885,5 +885,13 @@ namespace Ryujinx.Ava.UI.ViewModels.Input AvaloniaKeyboardDriver.Dispose(); } + + public void CyclePlayerDevice(int player) + { + LoadDevices(); + PlayerId = (PlayerIndex)player; + Device = (Device + 1) % Devices.Count; + Save(); + } } }