forked from Ryubing/Ryujinx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI: Convert the various options for LED into a popup window similar t…
…o motion & rumble config.
- Loading branch information
Showing
7 changed files
with
236 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Avalonia.Media; | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using CommunityToolkit.Mvvm.Input; | ||
using Ryujinx.Ava.UI.Helpers; | ||
|
||
namespace Ryujinx.Ava.UI.ViewModels.Input | ||
{ | ||
public partial class LedInputViewModel : BaseModel | ||
{ | ||
public required InputViewModel ParentModel { get; init; } | ||
|
||
public RelayCommand LedDisabledChanged => Commands.Create(() => | ||
{ | ||
if (!EnableLedChanging) return; | ||
|
||
if (TurnOffLed) | ||
ParentModel.SelectedGamepad.ClearLed(); | ||
else | ||
ParentModel.SelectedGamepad.SetLed(LedColor.ToUInt32()); | ||
}); | ||
|
||
[ObservableProperty] private bool _enableLedChanging; | ||
[ObservableProperty] private Color _ledColor; | ||
|
||
public bool ShowLedColorPicker => !TurnOffLed && !UseRainbowLed; | ||
|
||
private bool _turnOffLed; | ||
|
||
public bool TurnOffLed | ||
{ | ||
get => _turnOffLed; | ||
set | ||
{ | ||
_turnOffLed = value; | ||
OnPropertyChanged(); | ||
OnPropertyChanged(nameof(ShowLedColorPicker)); | ||
} | ||
} | ||
|
||
private bool _useRainbowLed; | ||
|
||
public bool UseRainbowLed | ||
{ | ||
get => _useRainbowLed; | ||
set | ||
{ | ||
_useRainbowLed = value; | ||
OnPropertyChanged(); | ||
OnPropertyChanged(nameof(ShowLedColorPicker)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<UserControl xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:controls="clr-namespace:Ryujinx.Ava.UI.Controls" | ||
xmlns:ui="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia" | ||
xmlns:ext="clr-namespace:Ryujinx.Ava.Common.Markup" | ||
xmlns:viewModels="clr-namespace:Ryujinx.Ava.UI.ViewModels.Input" | ||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" | ||
x:DataType="viewModels:LedInputViewModel" | ||
x:Class="Ryujinx.UI.Views.Input.LedInputView"> | ||
<StackPanel Orientation="Vertical" HorizontalAlignment="Center"> | ||
<StackPanel Orientation="Horizontal" IsVisible="{Binding ParentModel.CanClearLed}"> | ||
<TextBlock MinWidth="75" MaxWidth="150" Text="{ext:Locale ControllerSettingsLedColorDisable}" /> | ||
<CheckBox | ||
Margin="5" | ||
MinWidth="0" | ||
IsChecked="{Binding TurnOffLed, Mode=TwoWay}" | ||
Command="{Binding LedDisabledChanged}"> | ||
</CheckBox> | ||
</StackPanel> | ||
<StackPanel Orientation="Horizontal" IsEnabled="{Binding !TurnOffLed}"> | ||
<TextBlock MinWidth="75" MaxWidth="150" Text="{ext:Locale ControllerSettingsLedColorRainbow}" /> | ||
<CheckBox | ||
Margin="5" | ||
MinWidth="0" | ||
IsChecked="{Binding UseRainbowLed, Mode=TwoWay}"> | ||
</CheckBox> | ||
</StackPanel> | ||
<StackPanel Orientation="Horizontal" IsEnabled="{Binding ShowLedColorPicker}"> | ||
<TextBlock MinWidth="75" MaxWidth="150" Text="{ext:Locale ControllerSettingsLedColor}" /> | ||
<ui:ColorPickerButton | ||
Margin="5" | ||
IsMoreButtonVisible="False" | ||
UseColorPalette="False" | ||
UseColorTriangle="False" | ||
UseColorWheel="False" | ||
ShowAcceptDismissButtons="False" | ||
IsAlphaEnabled="False" | ||
AttachedToVisualTree="ColorPickerButton_OnAttachedToVisualTree" | ||
ColorChanged="ColorPickerButton_OnColorChanged" | ||
Color="{Binding LedColor, Mode=TwoWay}"> | ||
</ui:ColorPickerButton> | ||
</StackPanel> | ||
</StackPanel> | ||
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Markup.Xaml; | ||
using FluentAvalonia.UI.Controls; | ||
using Ryujinx.Ava.Common.Locale; | ||
using Ryujinx.Ava.UI.Models.Input; | ||
using Ryujinx.Ava.UI.ViewModels.Input; | ||
using Ryujinx.Ava.UI.Views.Input; | ||
using System.Threading.Tasks; | ||
|
||
namespace Ryujinx.UI.Views.Input | ||
{ | ||
public partial class LedInputView : UserControl | ||
{ | ||
private readonly LedInputViewModel _viewModel; | ||
|
||
public LedInputView(ControllerInputViewModel viewModel) | ||
{ | ||
DataContext = _viewModel = new LedInputViewModel | ||
{ | ||
ParentModel = viewModel.ParentModel, | ||
TurnOffLed = viewModel.Config.TurnOffLed, | ||
EnableLedChanging = viewModel.Config.EnableLedChanging, | ||
LedColor = viewModel.Config.LedColor, | ||
UseRainbowLed = viewModel.Config.UseRainbowLed, | ||
}; | ||
|
||
InitializeComponent(); | ||
} | ||
|
||
private void ColorPickerButton_OnColorChanged(ColorPickerButton sender, ColorButtonColorChangedEventArgs args) | ||
{ | ||
if (!args.NewColor.HasValue) return; | ||
if (DataContext is not LedInputViewModel lvm) return; | ||
if (!lvm.EnableLedChanging) return; | ||
if (lvm.TurnOffLed) return; | ||
|
||
lvm.ParentModel.SelectedGamepad.SetLed(args.NewColor.Value.ToUInt32()); | ||
} | ||
|
||
private void ColorPickerButton_OnAttachedToVisualTree(object sender, VisualTreeAttachmentEventArgs e) | ||
{ | ||
if (DataContext is not LedInputViewModel lvm) return; | ||
if (!lvm.EnableLedChanging) return; | ||
if (lvm.TurnOffLed) return; | ||
|
||
lvm.ParentModel.SelectedGamepad.SetLed(lvm.LedColor.ToUInt32()); | ||
} | ||
|
||
public static async Task Show(ControllerInputViewModel viewModel) | ||
{ | ||
LedInputView content = new(viewModel); | ||
|
||
ContentDialog contentDialog = new() | ||
{ | ||
Title = LocaleManager.Instance[LocaleKeys.ControllerLedTitle], | ||
PrimaryButtonText = LocaleManager.Instance[LocaleKeys.ControllerSettingsSave], | ||
SecondaryButtonText = string.Empty, | ||
CloseButtonText = LocaleManager.Instance[LocaleKeys.ControllerSettingsClose], | ||
Content = content, | ||
}; | ||
contentDialog.PrimaryButtonClick += (sender, args) => | ||
{ | ||
GamepadInputConfig config = viewModel.Config; | ||
config.EnableLedChanging = content._viewModel.EnableLedChanging; | ||
config.LedColor = content._viewModel.LedColor; | ||
config.UseRainbowLed = content._viewModel.UseRainbowLed; | ||
config.TurnOffLed = content._viewModel.TurnOffLed; | ||
}; | ||
|
||
await contentDialog.ShowAsync(); | ||
} | ||
} | ||
} | ||
|