UserSelectorView.axaml.cs 3.7 KB

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