UserProfile.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using Avalonia.Media;
  2. using Ryujinx.Ava.UI.Controls;
  3. using Ryujinx.Ava.UI.ViewModels;
  4. using Ryujinx.Ava.UI.Views.User;
  5. using Ryujinx.HLE.HOS.Services.Account.Acc;
  6. using Profile = Ryujinx.HLE.HOS.Services.Account.Acc.UserProfile;
  7. namespace Ryujinx.Ava.UI.Models
  8. {
  9. public class UserProfile : BaseModel
  10. {
  11. private readonly Profile _profile;
  12. private readonly NavigationDialogHost _owner;
  13. private byte[] _image;
  14. private string _name;
  15. private UserId _userId;
  16. private bool _isPointerOver;
  17. private IBrush _backgroundColor;
  18. public byte[] Image
  19. {
  20. get => _image;
  21. set
  22. {
  23. _image = value;
  24. OnPropertyChanged();
  25. }
  26. }
  27. public UserId UserId
  28. {
  29. get => _userId;
  30. set
  31. {
  32. _userId = value;
  33. OnPropertyChanged();
  34. }
  35. }
  36. public string Name
  37. {
  38. get => _name;
  39. set
  40. {
  41. _name = value;
  42. OnPropertyChanged();
  43. }
  44. }
  45. public bool IsPointerOver
  46. {
  47. get => _isPointerOver;
  48. set
  49. {
  50. _isPointerOver = value;
  51. OnPropertyChanged();
  52. }
  53. }
  54. public IBrush BackgroundColor
  55. {
  56. get => _backgroundColor;
  57. set
  58. {
  59. _backgroundColor = value;
  60. OnPropertyChanged();
  61. }
  62. }
  63. public UserProfile(Profile profile, NavigationDialogHost owner)
  64. {
  65. _profile = profile;
  66. _owner = owner;
  67. UpdateBackground();
  68. Image = profile.Image;
  69. Name = profile.Name;
  70. UserId = profile.UserId;
  71. }
  72. public void UpdateState()
  73. {
  74. UpdateBackground();
  75. OnPropertyChanged(nameof(Name));
  76. }
  77. private void UpdateBackground()
  78. {
  79. Avalonia.Application.Current.Styles.TryGetResource("ControlFillColorSecondary", out object color);
  80. if (color is not null)
  81. {
  82. BackgroundColor = _profile.AccountState == AccountState.Open ? new SolidColorBrush((Color)color) : Brushes.Transparent;
  83. }
  84. }
  85. public void Recover(UserProfile userProfile)
  86. {
  87. _owner.Navigate(typeof(UserEditorView), (_owner, userProfile, true));
  88. }
  89. }
  90. }