CheatsList.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Collections.ObjectModel;
  2. using System.Collections.Specialized;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. namespace Ryujinx.Ava.Ui.Models
  6. {
  7. public class CheatsList : ObservableCollection<CheatModel>
  8. {
  9. public CheatsList(string buildId, string path)
  10. {
  11. BuildId = buildId;
  12. Path = path;
  13. CollectionChanged += CheatsList_CollectionChanged;
  14. }
  15. private void CheatsList_CollectionChanged(object sender,
  16. NotifyCollectionChangedEventArgs e)
  17. {
  18. if (e.Action == NotifyCollectionChangedAction.Add)
  19. {
  20. (e.NewItems[0] as CheatModel).EnableToggled += Item_EnableToggled;
  21. }
  22. }
  23. private void Item_EnableToggled(object sender, bool e)
  24. {
  25. OnPropertyChanged(new PropertyChangedEventArgs(nameof(IsEnabled)));
  26. }
  27. public string BuildId { get; }
  28. public string Path { get; }
  29. public bool IsEnabled
  30. {
  31. get
  32. {
  33. return this.ToList().TrueForAll(x => x.IsEnabled);
  34. }
  35. set
  36. {
  37. foreach (var cheat in this)
  38. {
  39. cheat.IsEnabled = value;
  40. }
  41. OnPropertyChanged(new PropertyChangedEventArgs(nameof(IsEnabled)));
  42. }
  43. }
  44. }
  45. }