mirror of
https://github.com/GreemDev/Ryujinx
synced 2025-01-02 17:19:43 +01:00
Ability to assign hotkeys to cycle controllers for players
This commit is contained in:
parent
b5483d8fe0
commit
1d4e578034
9 changed files with 376 additions and 185 deletions
|
@ -1,3 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Ryujinx.Common.Configuration.Hid
|
||||
{
|
||||
public class KeyboardHotkeys
|
||||
|
@ -13,5 +15,6 @@ namespace Ryujinx.Common.Configuration.Hid
|
|||
public Key VolumeDown { get; set; }
|
||||
public Key CustomVSyncIntervalIncrement { get; set; }
|
||||
public Key CustomVSyncIntervalDecrement { get; set; }
|
||||
public List<Key> CycleControllers { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ using Ryujinx.HLE;
|
|||
using Ryujinx.HLE.FileSystem;
|
||||
using Ryujinx.HLE.HOS;
|
||||
using Ryujinx.HLE.HOS.Services.Account.Acc;
|
||||
using Ryujinx.HLE.HOS.Services.Hid;
|
||||
using Ryujinx.HLE.HOS.SystemState;
|
||||
using Ryujinx.Input;
|
||||
using Ryujinx.Input.HLE;
|
||||
|
@ -48,6 +49,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -1297,6 +1299,18 @@ namespace Ryujinx.Ava
|
|||
|
||||
_viewModel.Volume = Device.GetVolume();
|
||||
break;
|
||||
case KeyboardHotkeyState.CycleControllersPlayer1:
|
||||
case KeyboardHotkeyState.CycleControllersPlayer2:
|
||||
case KeyboardHotkeyState.CycleControllersPlayer3:
|
||||
case KeyboardHotkeyState.CycleControllersPlayer4:
|
||||
case KeyboardHotkeyState.CycleControllersPlayer5:
|
||||
case KeyboardHotkeyState.CycleControllersPlayer6:
|
||||
case KeyboardHotkeyState.CycleControllersPlayer7:
|
||||
case KeyboardHotkeyState.CycleControllersPlayer8:
|
||||
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();
|
||||
break;
|
||||
|
@ -1379,6 +1393,15 @@ namespace Ryujinx.Ava
|
|||
state = KeyboardHotkeyState.CustomVSyncIntervalDecrement;
|
||||
}
|
||||
|
||||
foreach (var cycle in ConfigurationState.Instance.Hid.Hotkeys.Value.CycleControllers?.Select((value, index) => (value, index)) ?? [])
|
||||
{
|
||||
if (_keyboardInterface.IsPressed((Key)cycle.value))
|
||||
{
|
||||
state = KeyboardHotkeyState.CycleControllersPlayer1 + cycle.index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4917,6 +4917,30 @@
|
|||
"zh_TW": "啟用警告日誌"
|
||||
}
|
||||
},
|
||||
{
|
||||
"ID": "SettingsTabHotkeysCycleControllers",
|
||||
"Translations": {
|
||||
"ar_SA": "",
|
||||
"de_DE": "",
|
||||
"el_GR": "",
|
||||
"en_US": "Cycle Controllers",
|
||||
"es_ES": "",
|
||||
"fr_FR": "",
|
||||
"he_IL": "",
|
||||
"it_IT": "",
|
||||
"ja_JP": "",
|
||||
"ko_KR": "",
|
||||
"no_NO": "",
|
||||
"pl_PL": "",
|
||||
"pt_BR": "",
|
||||
"ru_RU": "",
|
||||
"th_TH": "",
|
||||
"tr_TR": "",
|
||||
"uk_UA": "",
|
||||
"zh_CN": "",
|
||||
"zh_TW": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"ID": "SettingsTabLoggingEnableErrorLogs",
|
||||
"Translations": {
|
||||
|
@ -21574,4 +21598,4 @@
|
|||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,5 +14,13 @@ namespace Ryujinx.Ava.Common
|
|||
VolumeDown,
|
||||
CustomVSyncIntervalIncrement,
|
||||
CustomVSyncIntervalDecrement,
|
||||
CycleControllersPlayer1,
|
||||
CycleControllersPlayer2,
|
||||
CycleControllersPlayer3,
|
||||
CycleControllersPlayer4,
|
||||
CycleControllersPlayer5,
|
||||
CycleControllersPlayer6,
|
||||
CycleControllersPlayer7,
|
||||
CycleControllersPlayer8
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
using DynamicData;
|
||||
using Ryujinx.Ava.UI.Helpers;
|
||||
using Ryujinx.Ava.UI.ViewModels;
|
||||
using Ryujinx.Common.Configuration.Hid;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Ryujinx.Ava.UI.Models.Input
|
||||
{
|
||||
|
@ -126,8 +131,15 @@ namespace Ryujinx.Ava.UI.Models.Input
|
|||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<CycleController> CycleControllers { get; set; } = new ObservableCollection<CycleController>();
|
||||
public ICommand AddCycleController { get; set; }
|
||||
public ICommand RemoveCycleController { get; set; }
|
||||
public bool CanRemoveCycleController => CycleControllers.Count > 0 && CycleControllers.Count < 8;
|
||||
|
||||
public HotkeyConfig(KeyboardHotkeys config)
|
||||
{
|
||||
AddCycleController = MiniCommand.Create(() => CycleControllers.Add(new CycleController(CycleControllers.Count + 1, Key.Unbound)));
|
||||
RemoveCycleController = MiniCommand.Create(() => CycleControllers.Remove(CycleControllers.Last()));
|
||||
if (config != null)
|
||||
{
|
||||
ToggleVSyncMode = config.ToggleVSyncMode;
|
||||
|
@ -141,7 +153,9 @@ namespace Ryujinx.Ava.UI.Models.Input
|
|||
VolumeDown = config.VolumeDown;
|
||||
CustomVSyncIntervalIncrement = config.CustomVSyncIntervalIncrement;
|
||||
CustomVSyncIntervalDecrement = config.CustomVSyncIntervalDecrement;
|
||||
CycleControllers.AddRange((config.CycleControllers ?? []).Select((x, i) => new CycleController(i + 1, x)));
|
||||
}
|
||||
CycleControllers.CollectionChanged += (sender, e) => OnPropertyChanged(nameof(CanRemoveCycleController));
|
||||
}
|
||||
|
||||
public KeyboardHotkeys GetConfig()
|
||||
|
@ -159,6 +173,7 @@ namespace Ryujinx.Ava.UI.Models.Input
|
|||
VolumeDown = VolumeDown,
|
||||
CustomVSyncIntervalIncrement = CustomVSyncIntervalIncrement,
|
||||
CustomVSyncIntervalDecrement = CustomVSyncIntervalDecrement,
|
||||
CycleControllers = CycleControllers.Select(x => x.Hotkey).ToList()
|
||||
};
|
||||
|
||||
return config;
|
||||
|
|
48
src/Ryujinx/UI/ViewModels/CycleController.cs
Normal file
48
src/Ryujinx/UI/ViewModels/CycleController.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
using Ryujinx.Ava.Common.Locale;
|
||||
using Ryujinx.Common.Configuration.Hid;
|
||||
|
||||
namespace Ryujinx.Ava.UI.ViewModels
|
||||
{
|
||||
public class CycleController : BaseModel
|
||||
{
|
||||
private string _player;
|
||||
private Key _hotkey;
|
||||
|
||||
public string Player
|
||||
{
|
||||
get => _player;
|
||||
set
|
||||
{
|
||||
_player = value;
|
||||
OnPropertyChanged(nameof(Player));
|
||||
}
|
||||
}
|
||||
|
||||
public Key Hotkey
|
||||
{
|
||||
get => _hotkey;
|
||||
set
|
||||
{
|
||||
_hotkey = value;
|
||||
OnPropertyChanged(nameof(Hotkey));
|
||||
}
|
||||
}
|
||||
|
||||
public CycleController(int v, Key x)
|
||||
{
|
||||
Player = v switch
|
||||
{
|
||||
1 => LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer1],
|
||||
2 => LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer2],
|
||||
3 => LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer3],
|
||||
4 => LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer4],
|
||||
5 => LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer5],
|
||||
6 => LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer6],
|
||||
7 => LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer7],
|
||||
8 => LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer8],
|
||||
_ => LocaleManager.Instance[LocaleKeys.ControllerSettingsPlayer] + " " + v
|
||||
};
|
||||
Hotkey = x;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -266,6 +266,10 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
|||
|
||||
public InputViewModel()
|
||||
{
|
||||
_mainWindow =
|
||||
(MainWindow)((IClassicDesktopStyleApplicationLifetime)Application.Current
|
||||
.ApplicationLifetime).MainWindow;
|
||||
AvaloniaKeyboardDriver = new AvaloniaKeyboardDriver(_mainWindow);
|
||||
PlayerIndexes = new ObservableCollection<PlayerModel>();
|
||||
Controllers = new ObservableCollection<ControllerModel>();
|
||||
Devices = new ObservableCollection<(DeviceType Type, string Id, string Name)>();
|
||||
|
@ -754,38 +758,34 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
|||
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
||||
bool validFileName = ProfileName.IndexOfAny(Path.GetInvalidFileNameChars()) == -1;
|
||||
|
||||
if (!validFileName)
|
||||
{
|
||||
bool validFileName = ProfileName.IndexOfAny(Path.GetInvalidFileNameChars()) == -1;
|
||||
|
||||
if (validFileName)
|
||||
{
|
||||
string path = Path.Combine(GetProfileBasePath(), ProfileName + ".json");
|
||||
|
||||
InputConfig config = null;
|
||||
|
||||
if (IsKeyboard)
|
||||
{
|
||||
config = (ConfigViewModel as KeyboardInputViewModel).Config.GetConfig();
|
||||
}
|
||||
else if (IsController)
|
||||
{
|
||||
config = (ConfigViewModel as ControllerInputViewModel).Config.GetConfig();
|
||||
}
|
||||
|
||||
config.ControllerType = Controllers[_controller].Type;
|
||||
|
||||
string jsonString = JsonHelper.Serialize(config, _serializerContext.InputConfig);
|
||||
|
||||
await File.WriteAllTextAsync(path, jsonString);
|
||||
|
||||
LoadProfiles();
|
||||
}
|
||||
else
|
||||
{
|
||||
await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance[LocaleKeys.DialogProfileInvalidProfileNameErrorMessage]);
|
||||
}
|
||||
await ContentDialogHelper.CreateErrorDialog(LocaleManager.Instance[LocaleKeys.DialogProfileInvalidProfileNameErrorMessage]);
|
||||
return;
|
||||
}
|
||||
string path = Path.Combine(GetProfileBasePath(), ProfileName + ".json");
|
||||
|
||||
InputConfig config = null;
|
||||
|
||||
if (IsKeyboard)
|
||||
{
|
||||
config = (ConfigViewModel as KeyboardInputViewModel).Config.GetConfig();
|
||||
}
|
||||
else if (IsController)
|
||||
{
|
||||
config = (ConfigViewModel as ControllerInputViewModel).Config.GetConfig();
|
||||
}
|
||||
|
||||
config.ControllerType = Controllers[_controller].Type;
|
||||
|
||||
string jsonString = JsonHelper.Serialize(config, _serializerContext.InputConfig);
|
||||
|
||||
await File.WriteAllTextAsync(path, jsonString);
|
||||
|
||||
LoadProfiles();
|
||||
}
|
||||
|
||||
public async void RemoveProfile()
|
||||
|
@ -899,5 +899,13 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
|
|||
|
||||
AvaloniaKeyboardDriver.Dispose();
|
||||
}
|
||||
|
||||
public void CyclePlayerDevice(int player)
|
||||
{
|
||||
LoadDevices();
|
||||
PlayerId = (PlayerIndex)player;
|
||||
Device = (Device + 1) % Devices.Count;
|
||||
Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<UserControl
|
||||
<UserControl
|
||||
x:Class="Ryujinx.Ava.UI.Views.Settings.SettingsHotkeysView"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
|
@ -18,17 +18,18 @@
|
|||
<helpers:KeyValueConverter x:Key="Key" />
|
||||
</UserControl.Resources>
|
||||
<UserControl.Styles>
|
||||
<Style Selector="StackPanel > StackPanel">
|
||||
<Style Selector="StackPanel StackPanel">
|
||||
<Setter Property="Margin" Value="10, 0, 0, 0" />
|
||||
<Setter Property="Orientation" Value="Horizontal" />
|
||||
</Style>
|
||||
<Style Selector="StackPanel > StackPanel > TextBlock">
|
||||
<Style Selector="StackPanel StackPanel > TextBlock">
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="Width" Value="230" />
|
||||
</Style>
|
||||
<Style Selector="ToggleButton">
|
||||
<Style Selector="ToggleButton, Button">
|
||||
<Setter Property="Width" Value="90" />
|
||||
<Setter Property="Height" Value="27" />
|
||||
<Setter Property="Padding" Value="0,5,0,5" /> <!-- Added vertical padding -->
|
||||
</Style>
|
||||
<Style Selector="ToggleButton > TextBlock">
|
||||
<Setter Property="TextAlignment" Value="Center" />
|
||||
|
@ -42,79 +43,123 @@
|
|||
VerticalScrollBarVisibility="Auto">
|
||||
<Border Classes="settings">
|
||||
<StackPanel
|
||||
Name="SettingButtons"
|
||||
Margin="10"
|
||||
HorizontalAlignment="Stretch"
|
||||
Orientation="Vertical"
|
||||
Spacing="10">
|
||||
Spacing="10"
|
||||
Name="SettingButtons">
|
||||
<TextBlock
|
||||
Classes="h1"
|
||||
Text="{ext:Locale SettingsTabHotkeysHotkeys}" />
|
||||
<StackPanel>
|
||||
<TextBlock Text="{ext:Locale SettingsTabHotkeysToggleVSyncModeHotkey}" />
|
||||
<ToggleButton Name="ToggleVSyncMode">
|
||||
<TextBlock Text="{Binding KeyboardHotkey.ToggleVSyncMode, Converter={StaticResource Key}}" />
|
||||
</ToggleButton>
|
||||
<StackPanel
|
||||
Margin="10,0,0,0"
|
||||
Spacing="10"
|
||||
Orientation="Vertical">
|
||||
<StackPanel>
|
||||
<TextBlock Text="{ext:Locale SettingsTabHotkeysToggleVSyncModeHotkey}" />
|
||||
<ToggleButton Name="ToggleVSyncMode">
|
||||
<TextBlock Text="{Binding KeyboardHotkey.ToggleVSyncMode, Converter={StaticResource Key}}" />
|
||||
</ToggleButton>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{ext:Locale SettingsTabHotkeysScreenshotHotkey}" />
|
||||
<ToggleButton Name="Screenshot">
|
||||
<TextBlock Text="{Binding KeyboardHotkey.Screenshot, Converter={StaticResource Key}}" />
|
||||
</ToggleButton>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{ext:Locale SettingsTabHotkeysShowUiHotkey}" />
|
||||
<ToggleButton Name="ShowUI">
|
||||
<TextBlock Text="{Binding KeyboardHotkey.ShowUI, Converter={StaticResource Key}}" />
|
||||
</ToggleButton>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{ext:Locale SettingsTabHotkeysPauseHotkey}" />
|
||||
<ToggleButton Name="Pause">
|
||||
<TextBlock Text="{Binding KeyboardHotkey.Pause, Converter={StaticResource Key}}" />
|
||||
</ToggleButton>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{ext:Locale SettingsTabHotkeysToggleMuteHotkey}" />
|
||||
<ToggleButton Name="ToggleMute">
|
||||
<TextBlock Text="{Binding KeyboardHotkey.ToggleMute, Converter={StaticResource Key}}" />
|
||||
</ToggleButton>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{ext:Locale SettingsTabHotkeysResScaleUpHotkey}" />
|
||||
<ToggleButton Name="ResScaleUp">
|
||||
<TextBlock Text="{Binding KeyboardHotkey.ResScaleUp, Converter={StaticResource Key}}" />
|
||||
</ToggleButton>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{ext:Locale SettingsTabHotkeysResScaleDownHotkey}" />
|
||||
<ToggleButton Name="ResScaleDown">
|
||||
<TextBlock Text="{Binding KeyboardHotkey.ResScaleDown, Converter={StaticResource Key}}" />
|
||||
</ToggleButton>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{ext:Locale SettingsTabHotkeysVolumeUpHotkey}" />
|
||||
<ToggleButton Name="VolumeUp">
|
||||
<TextBlock Text="{Binding KeyboardHotkey.VolumeUp, Converter={StaticResource Key}}" />
|
||||
</ToggleButton>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{ext:Locale SettingsTabHotkeysVolumeDownHotkey}" />
|
||||
<ToggleButton Name="VolumeDown">
|
||||
<TextBlock Text="{Binding KeyboardHotkey.VolumeDown, Converter={StaticResource Key}}" />
|
||||
</ToggleButton>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{ext:Locale SettingsTabHotkeysIncrementCustomVSyncIntervalHotkey}" />
|
||||
<ToggleButton Name="CustomVSyncIntervalIncrement">
|
||||
<TextBlock Text="{Binding KeyboardHotkey.CustomVSyncIntervalIncrement, Converter={StaticResource Key}}" />
|
||||
</ToggleButton>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{ext:Locale SettingsTabHotkeysDecrementCustomVSyncIntervalHotkey}" />
|
||||
<ToggleButton Name="CustomVSyncIntervalDecrement">
|
||||
<TextBlock Text="{Binding KeyboardHotkey.CustomVSyncIntervalDecrement, Converter={StaticResource Key}}" />
|
||||
</ToggleButton>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{ext:Locale SettingsTabHotkeysScreenshotHotkey}" />
|
||||
<ToggleButton Name="Screenshot">
|
||||
<TextBlock Text="{Binding KeyboardHotkey.Screenshot, Converter={StaticResource Key}}" />
|
||||
</ToggleButton>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{ext:Locale SettingsTabHotkeysShowUiHotkey}" />
|
||||
<ToggleButton Name="ShowUI">
|
||||
<TextBlock Text="{Binding KeyboardHotkey.ShowUI, Converter={StaticResource Key}}" />
|
||||
</ToggleButton>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{ext:Locale SettingsTabHotkeysPauseHotkey}" />
|
||||
<ToggleButton Name="Pause">
|
||||
<TextBlock Text="{Binding KeyboardHotkey.Pause, Converter={StaticResource Key}}" />
|
||||
</ToggleButton>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{ext:Locale SettingsTabHotkeysToggleMuteHotkey}" />
|
||||
<ToggleButton Name="ToggleMute">
|
||||
<TextBlock Text="{Binding KeyboardHotkey.ToggleMute, Converter={StaticResource Key}}" />
|
||||
</ToggleButton>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{ext:Locale SettingsTabHotkeysResScaleUpHotkey}" />
|
||||
<ToggleButton Name="ResScaleUp">
|
||||
<TextBlock Text="{Binding KeyboardHotkey.ResScaleUp, Converter={StaticResource Key}}" />
|
||||
</ToggleButton>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{ext:Locale SettingsTabHotkeysResScaleDownHotkey}" />
|
||||
<ToggleButton Name="ResScaleDown">
|
||||
<TextBlock Text="{Binding KeyboardHotkey.ResScaleDown, Converter={StaticResource Key}}" />
|
||||
</ToggleButton>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{ext:Locale SettingsTabHotkeysVolumeUpHotkey}" />
|
||||
<ToggleButton Name="VolumeUp">
|
||||
<TextBlock Text="{Binding KeyboardHotkey.VolumeUp, Converter={StaticResource Key}}" />
|
||||
</ToggleButton>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{ext:Locale SettingsTabHotkeysVolumeDownHotkey}" />
|
||||
<ToggleButton Name="VolumeDown">
|
||||
<TextBlock Text="{Binding KeyboardHotkey.VolumeDown, Converter={StaticResource Key}}" />
|
||||
</ToggleButton>
|
||||
</StackPanel>
|
||||
<StackPanel Margin="10,0,0,0" Orientation="Horizontal">
|
||||
<TextBlock Text="{ext:Locale SettingsTabHotkeysIncrementCustomVSyncIntervalHotkey}" />
|
||||
<ToggleButton Name="CustomVSyncIntervalIncrement">
|
||||
<TextBlock Text="{Binding KeyboardHotkey.CustomVSyncIntervalIncrement, Converter={StaticResource Key}}" />
|
||||
</ToggleButton>
|
||||
</StackPanel>
|
||||
<StackPanel Margin="10,0,0,0" Orientation="Horizontal">
|
||||
<TextBlock Text="{ext:Locale SettingsTabHotkeysDecrementCustomVSyncIntervalHotkey}" />
|
||||
<ToggleButton Name="CustomVSyncIntervalDecrement">
|
||||
<TextBlock Text="{Binding KeyboardHotkey.CustomVSyncIntervalDecrement, Converter={StaticResource Key}}" />
|
||||
</ToggleButton>
|
||||
<Separator Height="1" />
|
||||
<StackPanel Margin="0">
|
||||
<TextBlock
|
||||
Classes="h1"
|
||||
Text="{ext:Locale SettingsTabHotkeysCycleControllers}" />
|
||||
<StackPanel Orientation="Horizontal" Spacing="10">
|
||||
<Button
|
||||
Content="{ext:Locale SettingsTabGeneralAdd}"
|
||||
Margin="10,0,0,0"
|
||||
Command="{Binding KeyboardHotkey.AddCycleController}" />
|
||||
<Button
|
||||
Content="{ext:Locale SettingsTabGeneralRemove}"
|
||||
IsEnabled="{Binding KeyboardHotkey.CanRemoveCycleController}"
|
||||
Command="{Binding KeyboardHotkey.RemoveCycleController}" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
<ItemsControl ItemsSource="{Binding KeyboardHotkey.CycleControllers}"
|
||||
Name="CycleControllers">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel
|
||||
Margin="10,0,0,0"
|
||||
Orientation="Vertical"
|
||||
Spacing="10" />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel>
|
||||
<TextBlock Text="{Binding Player}" />
|
||||
<ToggleButton>
|
||||
<TextBlock
|
||||
Text="{Binding Hotkey, Converter={StaticResource Key}}" />
|
||||
</ToggleButton>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</ScrollViewer>
|
||||
|
|
|
@ -3,11 +3,17 @@ using Avalonia.Controls.Primitives;
|
|||
using Avalonia.Input;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.LogicalTree;
|
||||
using Avalonia.VisualTree;
|
||||
using DynamicData.Kernel;
|
||||
using FluentAvalonia.Core;
|
||||
using Ryujinx.Ava.Input;
|
||||
using Ryujinx.Ava.UI.Helpers;
|
||||
using Ryujinx.Ava.UI.ViewModels;
|
||||
using Ryujinx.Input;
|
||||
using Ryujinx.Input.Assigner;
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using Key = Ryujinx.Common.Configuration.Hid.Key;
|
||||
|
||||
namespace Ryujinx.Ava.UI.Views.Settings
|
||||
|
@ -20,16 +26,21 @@ namespace Ryujinx.Ava.UI.Views.Settings
|
|||
public SettingsHotkeysView()
|
||||
{
|
||||
InitializeComponent();
|
||||
RegisterEvents();
|
||||
_avaloniaKeyboardDriver = new AvaloniaKeyboardDriver(this);
|
||||
CycleControllers.LayoutUpdated += (_, _1) => RegisterEvents();
|
||||
}
|
||||
|
||||
private void RegisterEvents()
|
||||
{
|
||||
foreach (ILogical visual in SettingButtons.GetLogicalDescendants())
|
||||
{
|
||||
if (visual is ToggleButton button and not CheckBox)
|
||||
{
|
||||
button.IsCheckedChanged -= Button_IsCheckedChanged;
|
||||
button.IsCheckedChanged += Button_IsCheckedChanged;
|
||||
}
|
||||
}
|
||||
|
||||
_avaloniaKeyboardDriver = new AvaloniaKeyboardDriver(this);
|
||||
}
|
||||
|
||||
protected override void OnPointerReleased(PointerReleasedEventArgs e)
|
||||
|
@ -53,90 +64,96 @@ namespace Ryujinx.Ava.UI.Views.Settings
|
|||
|
||||
private void Button_IsCheckedChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is ToggleButton button)
|
||||
if (sender is not ToggleButton button)
|
||||
{
|
||||
if ((bool)button.IsChecked)
|
||||
{
|
||||
if (_currentAssigner != null && button == _currentAssigner.ToggledButton)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_currentAssigner == null)
|
||||
{
|
||||
_currentAssigner = new ButtonKeyAssigner(button);
|
||||
|
||||
this.Focus(NavigationMethod.Pointer);
|
||||
|
||||
PointerPressed += MouseClick;
|
||||
|
||||
var keyboard = (IKeyboard)_avaloniaKeyboardDriver.GetGamepad("0");
|
||||
IButtonAssigner assigner = new KeyboardKeyAssigner(keyboard);
|
||||
|
||||
_currentAssigner.ButtonAssigned += (sender, e) =>
|
||||
{
|
||||
if (e.ButtonValue.HasValue)
|
||||
{
|
||||
var viewModel = (DataContext) as SettingsViewModel;
|
||||
var buttonValue = e.ButtonValue.Value;
|
||||
|
||||
switch (button.Name)
|
||||
{
|
||||
case "ToggleVSyncMode":
|
||||
viewModel.KeyboardHotkey.ToggleVSyncMode = buttonValue.AsHidType<Key>();
|
||||
break;
|
||||
case "Screenshot":
|
||||
viewModel.KeyboardHotkey.Screenshot = buttonValue.AsHidType<Key>();
|
||||
break;
|
||||
case "ShowUI":
|
||||
viewModel.KeyboardHotkey.ShowUI = buttonValue.AsHidType<Key>();
|
||||
break;
|
||||
case "Pause":
|
||||
viewModel.KeyboardHotkey.Pause = buttonValue.AsHidType<Key>();
|
||||
break;
|
||||
case "ToggleMute":
|
||||
viewModel.KeyboardHotkey.ToggleMute = buttonValue.AsHidType<Key>();
|
||||
break;
|
||||
case "ResScaleUp":
|
||||
viewModel.KeyboardHotkey.ResScaleUp = buttonValue.AsHidType<Key>();
|
||||
break;
|
||||
case "ResScaleDown":
|
||||
viewModel.KeyboardHotkey.ResScaleDown = buttonValue.AsHidType<Key>();
|
||||
break;
|
||||
case "VolumeUp":
|
||||
viewModel.KeyboardHotkey.VolumeUp = buttonValue.AsHidType<Key>();
|
||||
break;
|
||||
case "VolumeDown":
|
||||
viewModel.KeyboardHotkey.VolumeDown = buttonValue.AsHidType<Key>();
|
||||
break;
|
||||
case "CustomVSyncIntervalIncrement":
|
||||
viewModel.KeyboardHotkey.CustomVSyncIntervalIncrement = buttonValue.AsHidType<Key>();
|
||||
break;
|
||||
case "CustomVSyncIntervalDecrement":
|
||||
viewModel.KeyboardHotkey.CustomVSyncIntervalDecrement = buttonValue.AsHidType<Key>();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_currentAssigner.GetInputAndAssign(assigner, keyboard);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_currentAssigner != null)
|
||||
{
|
||||
_currentAssigner.Cancel();
|
||||
_currentAssigner = null;
|
||||
button.IsChecked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentAssigner?.Cancel();
|
||||
_currentAssigner = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!button.IsChecked.ValueOr(default))
|
||||
{
|
||||
_currentAssigner?.Cancel();
|
||||
_currentAssigner = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_currentAssigner != null && button == _currentAssigner.ToggledButton)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_currentAssigner != null)
|
||||
{
|
||||
_currentAssigner.Cancel();
|
||||
_currentAssigner = null;
|
||||
button.IsChecked = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_currentAssigner = new ButtonKeyAssigner(button);
|
||||
|
||||
this.Focus(NavigationMethod.Pointer);
|
||||
|
||||
PointerPressed += MouseClick;
|
||||
|
||||
var keyboard = (IKeyboard)_avaloniaKeyboardDriver.GetGamepad("0");
|
||||
IButtonAssigner assigner = new KeyboardKeyAssigner(keyboard);
|
||||
|
||||
_currentAssigner.ButtonAssigned += (sender, e) =>
|
||||
{
|
||||
if (!e.ButtonValue.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var viewModel = (DataContext) as SettingsViewModel;
|
||||
var buttonValue = e.ButtonValue.Value;
|
||||
|
||||
switch (button.Name)
|
||||
{
|
||||
case "ToggleVSyncMode":
|
||||
viewModel.KeyboardHotkey.ToggleVSyncMode = buttonValue.AsHidType<Key>();
|
||||
break;
|
||||
case "Screenshot":
|
||||
viewModel.KeyboardHotkey.Screenshot = buttonValue.AsHidType<Key>();
|
||||
break;
|
||||
case "ShowUI":
|
||||
viewModel.KeyboardHotkey.ShowUI = buttonValue.AsHidType<Key>();
|
||||
break;
|
||||
case "Pause":
|
||||
viewModel.KeyboardHotkey.Pause = buttonValue.AsHidType<Key>();
|
||||
break;
|
||||
case "ToggleMute":
|
||||
viewModel.KeyboardHotkey.ToggleMute = buttonValue.AsHidType<Key>();
|
||||
break;
|
||||
case "ResScaleUp":
|
||||
viewModel.KeyboardHotkey.ResScaleUp = buttonValue.AsHidType<Key>();
|
||||
break;
|
||||
case "ResScaleDown":
|
||||
viewModel.KeyboardHotkey.ResScaleDown = buttonValue.AsHidType<Key>();
|
||||
break;
|
||||
case "VolumeUp":
|
||||
viewModel.KeyboardHotkey.VolumeUp = buttonValue.AsHidType<Key>();
|
||||
break;
|
||||
case "VolumeDown":
|
||||
viewModel.KeyboardHotkey.VolumeDown = buttonValue.AsHidType<Key>();
|
||||
break;
|
||||
case "CustomVSyncIntervalIncrement":
|
||||
viewModel.KeyboardHotkey.CustomVSyncIntervalIncrement = buttonValue.AsHidType<Key>();
|
||||
break;
|
||||
case "CustomVSyncIntervalDecrement":
|
||||
viewModel.KeyboardHotkey.CustomVSyncIntervalDecrement = buttonValue.AsHidType<Key>();
|
||||
break;
|
||||
default:
|
||||
var index = button.FindAncestorOfType<ItemsControl>().GetLogicalDescendants().OfType<ToggleButton>().IndexOf(button);
|
||||
if (index >= 0 && viewModel.KeyboardHotkey.CycleControllers != null)
|
||||
{
|
||||
viewModel.KeyboardHotkey.CycleControllers[index].Hotkey = buttonValue.AsHidType<Key>();
|
||||
}
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
_currentAssigner.GetInputAndAssign(assigner, keyboard);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
|
Loading…
Reference in a new issue