Skip to content

Commit

Permalink
UI: Rainbow cycling speed settings
Browse files Browse the repository at this point in the history
Note: this setting is global, even though it appears in the settings for the individual gamepad. This is simply for consistency; you access all the rainbow stuff in one place.
  • Loading branch information
GreemDev committed Jan 30, 2025
1 parent 11f2936 commit 1a42d13
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 23 deletions.
19 changes: 19 additions & 0 deletions src/Ryujinx/UI/ViewModels/Input/LedInputViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
using Avalonia.Media;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Gommon;
using Humanizer;
using Ryujinx.Ava.UI.Helpers;
using Ryujinx.Ava.Utilities.Configuration;
using System;
using System.Globalization;
using System.Linq;

namespace Ryujinx.Ava.UI.ViewModels.Input
{
Expand All @@ -21,6 +27,19 @@ public partial class LedInputViewModel : BaseModel

[ObservableProperty] private bool _enableLedChanging;
[ObservableProperty] private Color _ledColor;

public string RainbowSpeedText => RainbowSpeed.ToString(CultureInfo.CurrentCulture);

public float RainbowSpeed
{
get => ConfigurationState.Instance.Hid.RainbowSpeed;
set
{
ConfigurationState.Instance.Hid.RainbowSpeed.Value = value;
OnPropertyChanged();
OnPropertyChanged(nameof(RainbowSpeedText));
}
}

public bool ShowLedColorPicker => !TurnOffLed && !UseRainbowLed;

Expand Down
23 changes: 20 additions & 3 deletions src/Ryujinx/UI/Views/Input/LedInputView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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}" />
<TextBlock MinWidth="75" MaxWidth="200" Text="{ext:Locale ControllerSettingsLedColorDisable}" />
<CheckBox
Margin="5"
MinWidth="0"
Expand All @@ -20,15 +20,32 @@
</CheckBox>
</StackPanel>
<StackPanel Orientation="Horizontal" IsEnabled="{Binding !TurnOffLed}">
<TextBlock MinWidth="75" MaxWidth="150" Text="{ext:Locale ControllerSettingsLedColorRainbow}" />
<TextBlock MinWidth="75" MaxWidth="200" Text="{ext:Locale ControllerSettingsLedColorRainbow}" />
<CheckBox
Margin="5"
MinWidth="0"
IsChecked="{Binding UseRainbowLed, Mode=TwoWay}">
</CheckBox>
</StackPanel>
<StackPanel Orientation="Horizontal" IsEnabled="{Binding !TurnOffLed}">
<TextBlock MinWidth="75" MaxWidth="200" Text="Rainbow Speed" />
<Slider HorizontalAlignment="Center"
Value="{Binding RainbowSpeed}"
Width="175"
Margin="0,-3,0,0"
Height="32"
Padding="0,-5"
TickFrequency="0.25"
IsSnapToTickEnabled="True"
VerticalAlignment="Center"
Minimum="1"
Maximum="10" />
<TextBlock Margin="5,0"
MinWidth="75"
Text="{Binding RainbowSpeed}"/>
</StackPanel>
<StackPanel Orientation="Horizontal" IsEnabled="{Binding ShowLedColorPicker}">
<TextBlock MinWidth="75" MaxWidth="150" Text="{ext:Locale ControllerSettingsLedColor}" />
<TextBlock MinWidth="75" MaxWidth="200" Text="{ext:Locale ControllerSettingsLedColor}" />
<ui:ColorPickerButton
Margin="5"
IsMoreButtonVisible="False"
Expand Down
23 changes: 6 additions & 17 deletions src/Ryujinx/Utilities/Configuration/ConfigurationFileFormat.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using Ryujinx.Ava.Utilities.Configuration.System;
using Ryujinx.Ava.Utilities.Configuration.UI;
using Ryujinx.Common;
using Ryujinx.Common.Configuration;
using Ryujinx.Common.Configuration.Hid;
using Ryujinx.Common.Configuration.Multiplayer;
using Ryujinx.Common.Logging;
using Ryujinx.Common.Utilities;
using Ryujinx.HLE;
using System.Collections.Generic;
using System.Text.Json.Nodes;

namespace Ryujinx.Ava.Utilities.Configuration
{
Expand All @@ -17,7 +15,7 @@ public class ConfigurationFileFormat
/// <summary>
/// The current version of the file format
/// </summary>
public const int CurrentVersion = 61;
public const int CurrentVersion = 62;

/// <summary>
/// Version of the configuration file format
Expand Down Expand Up @@ -376,24 +374,15 @@ public class ConfigurationFileFormat
/// </summary>
public KeyboardHotkeys Hotkeys { get; set; }

/// <summary>
/// Legacy keyboard control bindings
/// </summary>
/// <remarks>Kept for file format compatibility (to avoid possible failure when parsing configuration on old versions)</remarks>
/// TODO: Remove this when those older versions aren't in use anymore.
public List<JsonObject> KeyboardConfig { get; set; }

/// <summary>
/// Legacy controller control bindings
/// </summary>
/// <remarks>Kept for file format compatibility (to avoid possible failure when parsing configuration on old versions)</remarks>
/// TODO: Remove this when those older versions aren't in use anymore.
public List<JsonObject> ControllerConfig { get; set; }

/// <summary>
/// Input configurations
/// </summary>
public List<InputConfig> InputConfig { get; set; }

/// <summary>
/// The speed of spectrum cycling for the Rainbow LED feature.
/// </summary>
public float RainbowSpeed { get; set; }

/// <summary>
/// Graphics backend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ in _migrations.OrderBy(x => x.Key))
Hid.EnableMouse.Value = cff.EnableMouse;
Hid.Hotkeys.Value = cff.Hotkeys;
Hid.InputConfig.Value = cff.InputConfig ?? [];
Hid.RainbowSpeed.Value = cff.RainbowSpeed;

Multiplayer.LanInterfaceId.Value = cff.MultiplayerLanInterfaceId;
Multiplayer.Mode.Value = cff.MultiplayerMode;
Expand Down Expand Up @@ -427,7 +428,8 @@ in _migrations.OrderBy(x => x.Key))
LedColor = new Color(255, 5, 1, 253).ToUInt32()
};
}
})
}),
(62, static cff => cff.RainbowSpeed = 1f)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Ryujinx.Common.Configuration.Multiplayer;
using Ryujinx.Common.Helper;
using Ryujinx.Common.Logging;
using Ryujinx.Common.Utilities;
using Ryujinx.HLE;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -444,13 +445,20 @@ public class HidSection
/// TODO: Implement a ReactiveList class.
/// </summary>
public ReactiveObject<List<InputConfig>> InputConfig { get; private set; }

/// <summary>
/// The speed of spectrum cycling for the Rainbow LED feature.
/// </summary>
public ReactiveObject<float> RainbowSpeed { get; }

public HidSection()
{
EnableKeyboard = new ReactiveObject<bool>();
EnableMouse = new ReactiveObject<bool>();
Hotkeys = new ReactiveObject<KeyboardHotkeys>();
InputConfig = new ReactiveObject<List<InputConfig>>();
RainbowSpeed = new ReactiveObject<float>();
RainbowSpeed.Event += (_, args) => Rainbow.Speed = args.NewValue;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Ryujinx/Utilities/Configuration/ConfigurationState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,8 @@ public ConfigurationFileFormat ToFileFormat()
EnableKeyboard = Hid.EnableKeyboard,
EnableMouse = Hid.EnableMouse,
Hotkeys = Hid.Hotkeys,
KeyboardConfig = [],
ControllerConfig = [],
InputConfig = Hid.InputConfig,
RainbowSpeed = Hid.RainbowSpeed,
GraphicsBackend = Graphics.GraphicsBackend,
PreferredGpu = Graphics.PreferredGpu,
MultiplayerLanInterfaceId = Multiplayer.LanInterfaceId,
Expand Down Expand Up @@ -255,6 +254,7 @@ public void LoadDefault()
VolumeUp = Key.Unbound,
VolumeDown = Key.Unbound,
};
Hid.RainbowSpeed.Value = 1f;
Hid.InputConfig.Value =
[
new StandardKeyboardInputConfig
Expand Down

0 comments on commit 1a42d13

Please sign in to comment.