LedInputViewModel.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using Avalonia.Media;
  2. using CommunityToolkit.Mvvm.ComponentModel;
  3. using CommunityToolkit.Mvvm.Input;
  4. using Gommon;
  5. using Humanizer;
  6. using Ryujinx.Ava.UI.Helpers;
  7. using Ryujinx.Ava.Utilities.Configuration;
  8. using System;
  9. using System.Globalization;
  10. using System.Linq;
  11. namespace Ryujinx.Ava.UI.ViewModels.Input
  12. {
  13. public partial class LedInputViewModel : BaseModel
  14. {
  15. public required InputViewModel ParentModel { get; init; }
  16. public RelayCommand LedDisabledChanged => Commands.Create(() =>
  17. {
  18. if (!EnableLedChanging) return;
  19. if (TurnOffLed)
  20. ParentModel.SelectedGamepad.ClearLed();
  21. else
  22. ParentModel.SelectedGamepad.SetLed(LedColor.ToUInt32());
  23. });
  24. [ObservableProperty] private bool _enableLedChanging;
  25. [ObservableProperty] private Color _ledColor;
  26. public string RainbowSpeedText => RainbowSpeed.ToString(CultureInfo.CurrentCulture);
  27. public float RainbowSpeed
  28. {
  29. get => ConfigurationState.Instance.Hid.RainbowSpeed;
  30. set
  31. {
  32. ConfigurationState.Instance.Hid.RainbowSpeed.Value = value;
  33. OnPropertyChanged();
  34. OnPropertyChanged(nameof(RainbowSpeedText));
  35. }
  36. }
  37. public bool ShowLedColorPicker => !TurnOffLed && !UseRainbowLed;
  38. private bool _turnOffLed;
  39. public bool TurnOffLed
  40. {
  41. get => _turnOffLed;
  42. set
  43. {
  44. _turnOffLed = value;
  45. OnPropertyChanged();
  46. OnPropertyChanged(nameof(ShowLedColorPicker));
  47. }
  48. }
  49. private bool _useRainbowLed;
  50. public bool UseRainbowLed
  51. {
  52. get => _useRainbowLed;
  53. set
  54. {
  55. _useRainbowLed = value;
  56. OnPropertyChanged();
  57. OnPropertyChanged(nameof(ShowLedColorPicker));
  58. }
  59. }
  60. }
  61. }