UserSelectorView.axaml.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using Avalonia.Controls;
  2. using Avalonia.Input;
  3. using Avalonia.Interactivity;
  4. using FluentAvalonia.UI.Controls;
  5. using FluentAvalonia.UI.Navigation;
  6. using Ryujinx.Ava.Common.Locale;
  7. using Ryujinx.Ava.UI.Controls;
  8. using Ryujinx.Ava.UI.ViewModels;
  9. using UserProfile = Ryujinx.Ava.UI.Models.UserProfile;
  10. namespace Ryujinx.Ava.UI.Views.User
  11. {
  12. public partial class UserSelectorViews : UserControl
  13. {
  14. private NavigationDialogHost _parent;
  15. public UserProfileViewModel ViewModel { get; set; }
  16. public UserSelectorViews()
  17. {
  18. InitializeComponent();
  19. if (Program.PreviewerDetached)
  20. {
  21. AddHandler(Frame.NavigatedToEvent, (s, e) =>
  22. {
  23. NavigatedTo(e);
  24. }, RoutingStrategies.Direct);
  25. }
  26. }
  27. private void NavigatedTo(NavigationEventArgs arg)
  28. {
  29. if (Program.PreviewerDetached)
  30. {
  31. if (arg.NavigationMode == NavigationMode.New)
  32. {
  33. _parent = (NavigationDialogHost)arg.Parameter;
  34. ViewModel = _parent.ViewModel;
  35. }
  36. if (arg.NavigationMode == NavigationMode.Back)
  37. {
  38. ((ContentDialog)_parent.Parent).Title = LocaleManager.Instance[LocaleKeys.UserProfileWindowTitle];
  39. }
  40. DataContext = ViewModel;
  41. }
  42. }
  43. private void Grid_PointerEntered(object sender, PointerEventArgs e)
  44. {
  45. if (sender is Grid grid)
  46. {
  47. if (grid.DataContext is UserProfile profile)
  48. {
  49. profile.IsPointerOver = true;
  50. }
  51. }
  52. }
  53. private void Grid_OnPointerExited(object sender, PointerEventArgs e)
  54. {
  55. if (sender is Grid grid)
  56. {
  57. if (grid.DataContext is UserProfile profile)
  58. {
  59. profile.IsPointerOver = false;
  60. }
  61. }
  62. }
  63. private void ProfilesList_SelectionChanged(object sender, SelectionChangedEventArgs e)
  64. {
  65. if (sender is ListBox listBox)
  66. {
  67. int selectedIndex = listBox.SelectedIndex;
  68. if (selectedIndex >= 0 && selectedIndex < ViewModel.Profiles.Count)
  69. {
  70. if (ViewModel.Profiles[selectedIndex] is UserProfile userProfile)
  71. {
  72. _parent?.AccountManager?.OpenUser(userProfile.UserId);
  73. foreach (BaseModel profile in ViewModel.Profiles)
  74. {
  75. if (profile is UserProfile uProfile)
  76. {
  77. uProfile.UpdateState();
  78. }
  79. }
  80. }
  81. }
  82. }
  83. }
  84. private void AddUser(object sender, RoutedEventArgs e)
  85. {
  86. _parent.AddUser();
  87. }
  88. private void EditUser(object sender, RoutedEventArgs e)
  89. {
  90. if (sender is Avalonia.Controls.Button button)
  91. {
  92. if (button.DataContext is UserProfile userProfile)
  93. {
  94. _parent.EditUser(userProfile);
  95. }
  96. }
  97. }
  98. private void ManageSaves(object sender, RoutedEventArgs e)
  99. {
  100. _parent.ManageSaves();
  101. }
  102. private void RecoverLostAccounts(object sender, RoutedEventArgs e)
  103. {
  104. _parent.RecoverLostAccounts();
  105. }
  106. private void Close(object sender, RoutedEventArgs e)
  107. {
  108. ((ContentDialog)_parent.Parent).Hide();
  109. }
  110. }
  111. }