UserProfileWindow.axaml.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using Avalonia;
  2. using Avalonia.Controls;
  3. using Avalonia.Interactivity;
  4. using Avalonia.Markup.Xaml;
  5. using Ryujinx.Ava.Common.Locale;
  6. using Ryujinx.Ava.Ui.ViewModels;
  7. using Ryujinx.HLE.FileSystem;
  8. using Ryujinx.HLE.HOS.Services.Account.Acc;
  9. using System.Threading.Tasks;
  10. using UserProfile = Ryujinx.Ava.Ui.Models.UserProfile;
  11. namespace Ryujinx.Ava.Ui.Windows
  12. {
  13. public class UserProfileWindow : StyleableWindow
  14. {
  15. private TextBox _nameBox;
  16. public UserProfileWindow(AccountManager accountManager, ContentManager contentManager,
  17. VirtualFileSystem virtualFileSystem)
  18. {
  19. AccountManager = accountManager;
  20. ContentManager = contentManager;
  21. ViewModel = new UserProfileViewModel(this);
  22. DataContext = ViewModel;
  23. InitializeComponent();
  24. #if DEBUG
  25. this.AttachDevTools();
  26. #endif
  27. if (contentManager.GetCurrentFirmwareVersion() != null)
  28. {
  29. Task.Run(() =>
  30. {
  31. AvatarProfileViewModel.PreloadAvatars(contentManager, virtualFileSystem);
  32. });
  33. }
  34. Title = $"Ryujinx {Program.Version} - " + LocaleManager.Instance["UserProfileWindowTitle"];
  35. }
  36. public UserProfileWindow()
  37. {
  38. ViewModel = new UserProfileViewModel();
  39. DataContext = ViewModel;
  40. InitializeComponent();
  41. #if DEBUG
  42. this.AttachDevTools();
  43. #endif
  44. Title = $"Ryujinx {Program.Version} - " + LocaleManager.Instance["UserProfileWindowTitle"];
  45. }
  46. public AccountManager AccountManager { get; }
  47. public ContentManager ContentManager { get; }
  48. public UserProfileViewModel ViewModel { get; set; }
  49. private void InitializeComponent()
  50. {
  51. AvaloniaXamlLoader.Load(this);
  52. _nameBox = this.FindControl<TextBox>("NameBox");
  53. }
  54. private void ProfilesList_DoubleTapped(object sender, RoutedEventArgs e)
  55. {
  56. if (sender is ListBox listBox)
  57. {
  58. int selectedIndex = listBox.SelectedIndex;
  59. if (selectedIndex >= 0 && selectedIndex < ViewModel.Profiles.Count)
  60. {
  61. ViewModel.SelectedProfile = ViewModel.Profiles[selectedIndex];
  62. AccountManager.OpenUser(ViewModel.SelectedProfile.UserId);
  63. ViewModel.LoadProfiles();
  64. foreach (UserProfile profile in ViewModel.Profiles)
  65. {
  66. profile.UpdateState();
  67. }
  68. }
  69. }
  70. }
  71. private void CloseButton_OnClick(object sender, RoutedEventArgs e)
  72. {
  73. Close();
  74. }
  75. private void SetNameButton_OnClick(object sender, RoutedEventArgs e)
  76. {
  77. if (!string.IsNullOrWhiteSpace(_nameBox.Text))
  78. {
  79. ViewModel.SelectedProfile.Name = _nameBox.Text;
  80. AccountManager.SetUserName(ViewModel.SelectedProfile.UserId, _nameBox.Text);
  81. }
  82. }
  83. }
  84. }