Improved interaction with "Input" settings.

- paired devices have notifications that they are configured and require connection
- paired devices load the configuration when connected
- A notification appears when changing control configuration settings.
- Now control settings will be saved only when they are changed
- Added a button to roll back changes to the previously saved state
- Fixed a bug: when switching the "player", if the "input device" and "controller type" settings were changed, the save dialog box did not appear.
- "Motion", "Rumble" and "Led" also have events notifying about changes
This commit is contained in:
Vova 2025-02-22 23:15:34 +10:00
parent eb6b0e9adc
commit 6381f44b0b
8 changed files with 329 additions and 39 deletions

View File

@ -1,8 +1,9 @@
<Styles
<Styles
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ext="clr-namespace:Ryujinx.Ava.Common.Markup"
xmlns:ui="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
xmlns:windowing="clr-namespace:FluentAvalonia.UI.Windowing;assembly=FluentAvalonia">
xmlns:windowing="clr-namespace:FluentAvalonia.UI.Windowing;assembly=FluentAvalonia">
<Design.PreviewWith>
<Border Height="2000"
Padding="20">
@ -41,6 +42,15 @@
</StackPanel>
</Grid>
<ui:NumberBox Value="1" />
<MenuItem
Header="123 0000"
ToolTip.Tip="What this"/>
<StackPanel Orientation="Horizontal">
<TextBlock
Text="Player1"/>
<TextBlock
Classes="pending"/>
</StackPanel>
</StackPanel>
</Border>
</Design.PreviewWith>
@ -331,6 +341,21 @@
<Setter Property="Margin"
Value="0,5,0,0" />
</Style>
<Style Selector="TextBlock.globalConfigMarker" >
<Setter Property="Foreground" Value="SeaGreen"/>
<Setter Property="Margin" Value="5,0,0,0"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Text" Value="(Global)"/>
</Style>
<Style Selector="TextBlock.pending" >
<Setter Property="Foreground" Value="SlateGray"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="Text" Value="(pending!)"/>
</Style>
<Style Selector="StackPanel.globalConfigMarker">
</Style>
<Style Selector="ContextMenu">
<Setter Property="BorderBrush"
Value="{DynamicResource MenuFlyoutPresenterBorderBrush}" />

View File

@ -7072,6 +7072,81 @@
"zh_TW": "新增"
}
},
{
"ID": "ControllerSettingsModifiedNotification",
"Translations": {
"ar_SA": "(تم التعديل!)",
"de_DE": "(modifiziert!)",
"el_GR": "(τροποποιημένο!)",
"en_US": "(Modified!)",
"es_ES": "(modificado!)",
"fr_FR": "(modifié!)",
"he_IL": "(שונה!)",
"it_IT": "(modificato!)",
"ja_JP": "(変更済み!)",
"ko_KR": "(수정됨!)",
"no_NO": "(modifisert!)",
"pl_PL": "(zmodyfikowane!)",
"pt_BR": "(modificado!)",
"ru_RU": "(изменено!)",
"sv_SE": "(ändrad!)",
"th_TH": "(แก้ไขแล้ว!)",
"tr_TR": "(değiştirildi!)",
"uk_UA": "(модифіковано!)",
"zh_CN": "(已修改!)",
"zh_TW": "(已修改!)"
}
},
{
"ID": "ControllerSettingsDisableDeviceForSaving",
"Translations": {
"ar_SA": "تم إعداد التحكم.\n\nفي انتظار اتصال وحدة التحكم...",
"de_DE": "Steuerung konfiguriert.\n\nWarten auf die Verbindung des Controllers...",
"el_GR": "Η διαχείριση έχει ρυθμιστεί.\n\nΑναμένεται σύνδεση του χειριστηρίου...",
"en_US": "Control configured.\n\nWaiting for controller connection...",
"es_ES": "Control configurado.\n\nEsperando la conexión del controlador...",
"fr_FR": "Contrôle configuré.\n\nEn attente de la connexion du contrôleur...",
"he_IL": "השליטה הוגדרה.\n\nממתין לחיבור הבקר...",
"it_IT": "Controllo configurato.\n\nIn attesa della connessione del controller...",
"ja_JP": "コントロールが設定されました。\n\nコントローラーの接続を待っています...",
"ko_KR": "제어가 설정되었습니다.\n\n컨트롤러 연결 대기 중...",
"no_NO": "Kontroll konfigurert.\n\nVenter på tilkobling av kontroller...",
"pl_PL": "Sterowanie skonfigurowane.\n\nOczekiwanie na połączenie kontrolera...",
"pt_BR": "Controle configurado.\n\nAguardando conexão do controle...",
"ru_RU": "Управление настроено.\n\nОжидается подключение контроллера...",
"sv_SE": "Kontroll konfigurerad.\n\nVäntar på anslutning av kontrollen...",
"th_TH": "การควบคุมได้รับการตั้งค่าแล้ว\n\nกำลังรอการเชื่อมต่อคอนโทรลเลอร์...",
"tr_TR": "Kontrol yapılandırıldı.\n\nKontrolcü bağlantısı bekleniyor...",
"uk_UA": "Керування налаштовано.\n\nОчікується підключення контролера...",
"zh_CN": "控制已配置。\n\n等待控制器连接...",
"zh_TW": "控制已設定。\n\n等待控制器連接..."
}
},
{
"ID": "ControllerSettingsUnlink",
"Translations": {
"ar_SA": "إلغاء الربط",
"de_DE": "Entkoppeln",
"el_GR": "Αποσύνδεση",
"en_US": "Unlink",
"es_ES": "Desvincular",
"fr_FR": "Dissocier",
"he_IL": "ניתוק קישור",
"it_IT": "Scollega",
"ja_JP": "リンク解除",
"ko_KR": "연결 해제",
"no_NO": "Frakoble",
"pl_PL": "Odłącz",
"pt_BR": "Desvincular",
"ru_RU": "Отвязать",
"sv_SE": "Koppla från",
"th_TH": "ยกเลิกการเชื่อมโยง",
"tr_TR": "Bağlantıyı Kes",
"uk_UA": "Відв'язати",
"zh_CN": "解除绑定",
"zh_TW": "解除綁定"
}
},
{
"ID": "ControllerSettingsRemove",
"Translations": {
@ -11722,6 +11797,31 @@
"zh_TW": "儲存設定檔"
}
},
{
"ID": "ControllerSettingsCancelCurrentChangesToolTip",
"Translations": {
"ar_SA": "إلغاء التغييرات الحالية",
"de_DE": "Aktuelle Änderungen abbrechen",
"el_GR": "Ακύρωση τρεχουσών αλλαγών",
"en_US": "Cancel current changes",
"es_ES": "Cancelar los cambios actuales",
"fr_FR": "Annuler les modifications en cours",
"he_IL": "ביטול השינויים הנוכחיים",
"it_IT": "Annulla le modifiche correnti",
"ja_JP": "現在の変更をキャンセル",
"ko_KR": "현재 변경 취소",
"no_NO": "Avbryt gjeldende endringer",
"pl_PL": "Anuluj bieżące zmiany",
"pt_BR": "Cancelar alterações atuais",
"ru_RU": "Отменить текущие изменения",
"sv_SE": "Avbryt aktuella ändringar",
"th_TH": "ยกเลิกการเปลี่ยนแปลงปัจจุบัน",
"tr_TR": "Geçerli değişiklikleri iptal et",
"uk_UA": "Скасувати поточні зміни",
"zh_CN": "取消当前更改",
"zh_TW": "取消當前變更"
}
},
{
"ID": "MenuBarFileToolsTakeScreenshot",
"Translations": {

View File

@ -68,18 +68,21 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
}
public async void ShowMotionConfig()
{
{
await MotionInputView.Show(this);
ParentModel.IsModified = true;
}
public async void ShowRumbleConfig()
{
{
await RumbleInputView.Show(this);
ParentModel.IsModified = true;
}
public async void ShowLedConfig()
{
await LedInputView.Show(this);
ParentModel.IsModified = true;
}
public void OnParentModelChanged()

View File

@ -91,7 +91,19 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
public bool HasLed => SelectedGamepad.Features.HasFlag(GamepadFeaturesFlag.Led);
public bool CanClearLed => SelectedGamepad.Name.ContainsIgnoreCase("DualSense");
public bool IsModified { get; set; }
public bool _isChangeTrackingActive;
public bool _isModified;
public bool IsModified
{
get => _isModified;
set
{
_isModified = value;
OnPropertyChanged();
}
}
public event Action NotifyChangesEvent;
public PlayerIndex PlayerIdChoose
@ -106,14 +118,14 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
set
{
if (IsModified)
{
{
_playerIdChoose = value;
return;
}
IsModified = false;
_playerId = value;
_isChangeTrackingActive = false;
if (!Enum.IsDefined<PlayerIndex>(_playerId))
{
@ -121,13 +133,12 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
}
_isLoaded = false;
LoadConfiguration();
LoadDevice();
LoadProfiles();
_isLoaded = true;
_isChangeTrackingActive = true;
OnPropertyChanged();
}
}
@ -171,11 +182,12 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
IsLeft = false;
break;
}
LoadInputDriver();
LoadProfiles();
SetChangeTrackingActive();
}
OnPropertyChanged();
NotifyChanges();
}
@ -233,14 +245,28 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
LoadConfiguration(LoadDefaultConfiguration());
}
}
FindPairedDevice();
SetChangeTrackingActive();
OnPropertyChanged();
NotifyChanges();
}
}
public InputConfig Config { get; set; }
public bool _notificationView;
public bool NotificationView
{
get => _notificationView;
set
{
_notificationView = value;
OnPropertyChanged();
}
}
public InputViewModel(UserControl owner) : this()
{
if (Program.PreviewerDetached)
@ -260,6 +286,8 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
PlayerId = PlayerIndex.Player1;
}
_isChangeTrackingActive = true;
}
public InputViewModel()
@ -296,8 +324,54 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
{
ConfigViewModel = new ControllerInputViewModel(this, new GamepadInputConfig(controllerInputConfig));
}
FindPairedDevice();
}
private void FindPairedDevice()
{
// This feature allows you to display a notification
// if a configuration is found, but the gamepad is not connected.
if (Config != null)
{
(DeviceType Type, string Id, string Name) activeDevice = Devices.FirstOrDefault(d => d.Id == Config.Id);
if (activeDevice.Id != Config.Id)
{
// display notification when input device is turned off, and
// if device and configuration do not match (different controllers)
NotificationView = true;
}
else
{
NotificationView = false;
}
}
else
{
NotificationView = false;
}
}
private void SetChangeTrackingActive()
{
if (_isChangeTrackingActive)
{
IsModified = true;
}
}
public void DisableDeviceForSaving()
{
// "Disabled" mode is available after unbinding the device
// NOTE: the IsModified flag to be able to apply the settings.
IsModified = true;
NotificationView = false;
}
public void LoadDevice()
{
if (Config == null || Config.Backend == InputBackendType.Invalid)
@ -363,14 +437,33 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
}
}
private void HandleOnGamepadDisconnected(string id)
private async void HandleOnGamepadDisconnected(string id)
{
Dispatcher.UIThread.Post(LoadDevices);
_isChangeTrackingActive = false;
await Dispatcher.UIThread.InvokeAsync(() =>
{
LoadDevices();
FindPairedDevice();
_isChangeTrackingActive = true;
return System.Threading.Tasks.Task.CompletedTask;
});
}
private void HandleOnGamepadConnected(string id)
private async void HandleOnGamepadConnected(string id)
{
Dispatcher.UIThread.Post(LoadDevices);
_isChangeTrackingActive = false;
await Dispatcher.UIThread.InvokeAsync(() =>
{
LoadDevices();
if (Config != null)
{
LoadSavedConfiguration(); // Load configuration after connection if it is in the configuration file
}
_isChangeTrackingActive = true;
});
}
private string GetCurrentGamepadId()
@ -813,8 +906,23 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
}
}
public void LoadSavedConfiguration()
{
LoadConfiguration();
LoadDevice();
LoadProfiles();
IsModified = false;
OnPropertyChanged();
}
public void Save()
{
if (!IsModified)
{
return; //If the input settings were not touched, then do nothing
}
IsModified = false;
List<InputConfig> newConfig = [];

View File

@ -63,8 +63,9 @@ namespace Ryujinx.Ava.UI.Views.Input
};
if (!float.IsNaN(_changeSlider) && _changeSlider != (float)check.Value)
{
(DataContext as ControllerInputViewModel)!.ParentModel.IsModified = true;
{
FlagInputConfigChanged();
_changeSlider = (float)check.Value;
}
}
@ -74,7 +75,8 @@ namespace Ryujinx.Ava.UI.Views.Input
{
if (sender is CheckBox { IsPointerOver: true })
{
(DataContext as ControllerInputViewModel)!.ParentModel.IsModified = true;
FlagInputConfigChanged();
_currentAssigner?.Cancel();
_currentAssigner = null;
}
@ -101,7 +103,7 @@ namespace Ryujinx.Ava.UI.Views.Input
this.Focus(NavigationMethod.Pointer);
PointerPressed += MouseClick;
ControllerInputViewModel viewModel = (DataContext as ControllerInputViewModel);
IKeyboard keyboard =
@ -114,7 +116,7 @@ namespace Ryujinx.Ava.UI.Views.Input
if (e.ButtonValue.HasValue)
{
Button buttonValue = e.ButtonValue.Value;
viewModel.ParentModel.IsModified = true;
FlagInputConfigChanged();
switch (button.Name)
{
@ -208,6 +210,11 @@ namespace Ryujinx.Ava.UI.Views.Input
}
}
private void FlagInputConfigChanged()
{
(DataContext as ControllerInputViewModel)!.ParentModel.IsModified = true;
}
private void MouseClick(object sender, PointerPressedEventArgs e)
{
bool shouldUnbind = e.GetCurrentPoint(this).Properties.IsMiddleButtonPressed;
@ -239,7 +246,6 @@ namespace Ryujinx.Ava.UI.Views.Input
{
gamepad?.ClearLed();
}
_currentAssigner?.Cancel();
_currentAssigner = null;
}

View File

@ -50,13 +50,21 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock
<StackPanel
Orientation="Vertical"
Margin="5,0,10,0"
Width="90"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Text="{ext:Locale ControllerSettingsPlayer}" />
Width="90">
<TextBlock
Text="{ext:Locale ControllerSettingsPlayer}" />
<TextBlock
Classes="pending"
Text ="{ext:Locale ControllerSettingsModifiedNotification}"
IsVisible="{Binding IsModified}"/>
</StackPanel>
<ComboBox
Grid.Column="1"
Name="PlayerIndexBox"
@ -71,6 +79,18 @@
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<Button
Grid.Column="2"
MinWidth="0"
Margin="5,0,0,0"
VerticalAlignment="Center"
ToolTip.Tip="{ext:Locale ControllerSettingsCancelCurrentChangesToolTip}"
Command="{Binding LoadSavedConfiguration}">
<ui:SymbolIcon
Symbol="Cancel"
FontSize="15"
Height="20" />
</Button>
</Grid>
<!-- Profile Selection -->
<Grid
@ -174,7 +194,7 @@
MinWidth="0"
Margin="5,0,0,0"
VerticalAlignment="Center"
Command="{Binding LoadDevices}">
Command="{Binding LoadDevice}">
<ui:SymbolIcon
Symbol="Refresh"
FontSize="15"
@ -211,15 +231,37 @@
</Grid>
</Grid>
</StackPanel>
<ContentControl Content="{Binding ConfigViewModel}" IsVisible="{Binding ShowSettings}">
<ContentControl.DataTemplates>
<DataTemplate DataType="viewModels:ControllerInputViewModel">
<views:ControllerInputView />
</DataTemplate>
<DataTemplate DataType="viewModels:KeyboardInputViewModel">
<views:KeyboardInputView />
</DataTemplate>
</ContentControl.DataTemplates>
<ContentControl IsVisible="{Binding NotificationView}">
<ContentControl.Content>
<StackPanel>
<TextBlock
Margin="5,20,0,0"
Text="{ext:Locale ControllerSettingsDisableDeviceForSaving}" />
<Button
MinWidth="0"
Width="90"
Height="27"
Margin="5,10,0,0"
VerticalAlignment="Center"
Command="{Binding DisableDeviceForSaving}">
<TextBlock
Text="{ext:Locale ControllerSettingsUnlink}"
VerticalAlignment="Center"
HorizontalAlignment="Center" />
</Button>
</StackPanel>
</ContentControl.Content>
</ContentControl>
<ContentControl Content="{Binding ConfigViewModel}" IsVisible="{Binding ShowSettings}">
<ContentControl.DataTemplates>
<DataTemplate DataType="viewModels:ControllerInputViewModel">
<views:ControllerInputView />
</DataTemplate>
<DataTemplate DataType="viewModels:KeyboardInputViewModel">
<views:KeyboardInputView />
</DataTemplate>
</ContentControl.DataTemplates>
</ContentControl>
</StackPanel>
</UserControl>

View File

@ -62,14 +62,15 @@ namespace Ryujinx.Ava.UI.Views.Input
}
return;
}
ViewModel.PlayerId = ViewModel.PlayerIdChoose;
ViewModel.IsModified = false;
ViewModel.PlayerId = ViewModel.PlayerIdChoose;
}
}
public void Dispose()
{
ViewModel.Dispose();

View File

@ -73,7 +73,7 @@ namespace Ryujinx.Ava.UI.Views.Input
if (e.ButtonValue.HasValue)
{
Button buttonValue = e.ButtonValue.Value;
viewModel.ParentModel.IsModified = true;
FlagInputConfigChanged();
switch (button.Name)
{
@ -184,6 +184,11 @@ namespace Ryujinx.Ava.UI.Views.Input
}
}
private void FlagInputConfigChanged()
{
(DataContext as KeyboardInputViewModel)!.ParentModel.IsModified = true;
}
private void MouseClick(object sender, PointerPressedEventArgs e)
{
bool shouldUnbind = e.GetCurrentPoint(this).Properties.IsMiddleButtonPressed;