DownloadableContentManagerWindow.axaml.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using Avalonia.Controls;
  2. using Avalonia.Interactivity;
  3. using Avalonia.Styling;
  4. using FluentAvalonia.UI.Controls;
  5. using Ryujinx.Ava.Common.Locale;
  6. using Ryujinx.Ava.UI.Helpers;
  7. using Ryujinx.Ava.UI.Models;
  8. using Ryujinx.Ava.UI.ViewModels;
  9. using Ryujinx.HLE.FileSystem;
  10. using Ryujinx.Ui.Common.Helper;
  11. using System.Threading.Tasks;
  12. using Button = Avalonia.Controls.Button;
  13. namespace Ryujinx.Ava.UI.Windows
  14. {
  15. public partial class DownloadableContentManagerWindow : UserControl
  16. {
  17. public DownloadableContentManagerViewModel ViewModel;
  18. public DownloadableContentManagerWindow()
  19. {
  20. DataContext = this;
  21. InitializeComponent();
  22. }
  23. public DownloadableContentManagerWindow(VirtualFileSystem virtualFileSystem, ulong titleId, string titleName)
  24. {
  25. DataContext = ViewModel = new DownloadableContentManagerViewModel(virtualFileSystem, titleId, titleName);
  26. InitializeComponent();
  27. }
  28. public static async Task Show(VirtualFileSystem virtualFileSystem, ulong titleId, string titleName)
  29. {
  30. ContentDialog contentDialog = new()
  31. {
  32. PrimaryButtonText = "",
  33. SecondaryButtonText = "",
  34. CloseButtonText = "",
  35. Content = new DownloadableContentManagerWindow(virtualFileSystem, titleId, titleName),
  36. Title = string.Format(LocaleManager.Instance[LocaleKeys.DlcWindowTitle], titleName, titleId.ToString("X16"))
  37. };
  38. Style bottomBorder = new(x => x.OfType<Grid>().Name("DialogSpace").Child().OfType<Border>());
  39. bottomBorder.Setters.Add(new Setter(IsVisibleProperty, false));
  40. contentDialog.Styles.Add(bottomBorder);
  41. await ContentDialogHelper.ShowAsync(contentDialog);
  42. }
  43. private void SaveAndClose(object sender, RoutedEventArgs routedEventArgs)
  44. {
  45. ViewModel.Save();
  46. ((ContentDialog)Parent).Hide();
  47. }
  48. private void Close(object sender, RoutedEventArgs e)
  49. {
  50. ((ContentDialog)Parent).Hide();
  51. }
  52. private void RemoveDLC(object sender, RoutedEventArgs e)
  53. {
  54. if (sender is Button button)
  55. {
  56. if (button.DataContext is DownloadableContentModel model)
  57. {
  58. ViewModel.Remove(model);
  59. }
  60. }
  61. }
  62. private void OpenLocation(object sender, RoutedEventArgs e)
  63. {
  64. if (sender is Button button)
  65. {
  66. if (button.DataContext is DownloadableContentModel model)
  67. {
  68. OpenHelper.LocateFile(model.ContainerPath);
  69. }
  70. }
  71. }
  72. private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
  73. {
  74. foreach (var content in e.AddedItems)
  75. {
  76. if (content is DownloadableContentModel model)
  77. {
  78. var index = ViewModel.DownloadableContents.IndexOf(model);
  79. if (index != -1)
  80. {
  81. ViewModel.DownloadableContents[index].Enabled = true;
  82. }
  83. }
  84. }
  85. foreach (var content in e.RemovedItems)
  86. {
  87. if (content is DownloadableContentModel model)
  88. {
  89. var index = ViewModel.DownloadableContents.IndexOf(model);
  90. if (index != -1)
  91. {
  92. ViewModel.DownloadableContents[index].Enabled = false;
  93. }
  94. }
  95. }
  96. }
  97. }
  98. }