GameListView.axaml.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using Avalonia.Collections;
  2. using Avalonia.Controls;
  3. using Avalonia.Input;
  4. using Avalonia.Interactivity;
  5. using Avalonia.Markup.Xaml;
  6. using LibHac.Common;
  7. using Ryujinx.Ava.UI.Helpers;
  8. using Ryujinx.Ava.UI.ViewModels;
  9. using Ryujinx.Ui.App.Common;
  10. using System;
  11. namespace Ryujinx.Ava.UI.Controls
  12. {
  13. public partial class GameListView : UserControl
  14. {
  15. private ApplicationData _selectedApplication;
  16. public static readonly RoutedEvent<ApplicationOpenedEventArgs> ApplicationOpenedEvent =
  17. RoutedEvent.Register<GameGridView, ApplicationOpenedEventArgs>(nameof(ApplicationOpened), RoutingStrategies.Bubble);
  18. public event EventHandler<ApplicationOpenedEventArgs> ApplicationOpened
  19. {
  20. add { AddHandler(ApplicationOpenedEvent, value); }
  21. remove { RemoveHandler(ApplicationOpenedEvent, value); }
  22. }
  23. public void GameList_DoubleTapped(object sender, RoutedEventArgs args)
  24. {
  25. if (sender is ListBox listBox)
  26. {
  27. if (listBox.SelectedItem is ApplicationData selected)
  28. {
  29. RaiseEvent(new ApplicationOpenedEventArgs(selected, ApplicationOpenedEvent));
  30. }
  31. }
  32. }
  33. public void GameList_SelectionChanged(object sender, SelectionChangedEventArgs args)
  34. {
  35. if (sender is ListBox listBox)
  36. {
  37. _selectedApplication = listBox.SelectedItem as ApplicationData;
  38. (DataContext as MainWindowViewModel).ListSelectedApplication = _selectedApplication;
  39. }
  40. }
  41. public ApplicationData SelectedApplication => _selectedApplication;
  42. public GameListView()
  43. {
  44. InitializeComponent();
  45. }
  46. private void InitializeComponent()
  47. {
  48. AvaloniaXamlLoader.Load(this);
  49. }
  50. private void SearchBox_OnKeyUp(object sender, KeyEventArgs e)
  51. {
  52. (DataContext as MainWindowViewModel).SearchText = (sender as TextBox).Text;
  53. }
  54. private void MenuBase_OnMenuOpened(object sender, EventArgs e)
  55. {
  56. var selection = SelectedApplication;
  57. if (selection != null)
  58. {
  59. if (sender is ContextMenu menu)
  60. {
  61. bool canHaveUserSave = !Utilities.IsZeros(selection.ControlHolder.ByteSpan) && selection.ControlHolder.Value.UserAccountSaveDataSize > 0;
  62. bool canHaveDeviceSave = !Utilities.IsZeros(selection.ControlHolder.ByteSpan) && selection.ControlHolder.Value.DeviceSaveDataSize > 0;
  63. bool canHaveBcatSave = !Utilities.IsZeros(selection.ControlHolder.ByteSpan) && selection.ControlHolder.Value.BcatDeliveryCacheStorageSize > 0;
  64. ((menu.Items as AvaloniaList<object>)[2] as MenuItem).IsEnabled = canHaveUserSave;
  65. ((menu.Items as AvaloniaList<object>)[3] as MenuItem).IsEnabled = canHaveDeviceSave;
  66. ((menu.Items as AvaloniaList<object>)[4] as MenuItem).IsEnabled = canHaveBcatSave;
  67. }
  68. }
  69. }
  70. }
  71. }