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