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. public string BuildId { get; }
  16. public string Path { get; }
  17. public bool IsEnabled
  18. {
  19. get
  20. {
  21. return this.ToList().TrueForAll(x => x.IsEnabled);
  22. }
  23. set
  24. {
  25. foreach (var cheat in this)
  26. {
  27. cheat.IsEnabled = value;
  28. }
  29. OnPropertyChanged(new PropertyChangedEventArgs(nameof(IsEnabled)));
  30. }
  31. }
  32. private void CheatsList_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
  33. {
  34. if (e.Action == NotifyCollectionChangedAction.Add)
  35. {
  36. (e.NewItems[0] as CheatModel).EnableToggled += Item_EnableToggled;
  37. }
  38. }
  39. private void Item_EnableToggled(object sender, bool e)
  40. {
  41. OnPropertyChanged(new PropertyChangedEventArgs(nameof(IsEnabled)));
  42. }
  43. }
  44. }