diff --git a/src/MaaWpfGui/Configuration/ConfigFactory.cs b/src/MaaWpfGui/Configuration/ConfigFactory.cs index 81200b7275..2f6ba8f1b0 100644 --- a/src/MaaWpfGui/Configuration/ConfigFactory.cs +++ b/src/MaaWpfGui/Configuration/ConfigFactory.cs @@ -50,7 +50,7 @@ namespace MaaWpfGui.Configuration private static readonly JsonSerializerOptions _options = new() { WriteIndented = true, Converters = { new JsonStringEnumConverter() }, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }; // TODO: 参考 ConfigurationHelper ,拆几个函数出来 - private static readonly Lazy _rootConfig = new Lazy(() => + private static readonly Lazy _rootConfig = new(() => { lock (_lock) { @@ -106,8 +106,6 @@ namespace MaaWpfGui.Configuration parsed = new Root(); } - parsed.CurrentConfig ??= new SpecificConfig(); - parsed.PropertyChanged += OnPropertyChangedFactory("Root."); parsed.Configurations.CollectionChanged += (in NotifyCollectionChangedEventArgs> args) => { @@ -117,13 +115,13 @@ namespace MaaWpfGui.Configuration case NotifyCollectionChangedAction.Replace: if (args.IsSingleItem) { - args.NewItem.Value.GUI.PropertyChanged += OnPropertyChangedFactory("Root.Configurations." + args.NewItem.Key, JsonSerializer.Serialize(args.NewItem.Value, _options), null); + SpecificConfigBind(args.NewItem.Key, args.NewItem.Value); } else { foreach (var value in args.NewItems) { - value.Value.GUI.PropertyChanged += OnPropertyChangedFactory("Root.Configurations." + value.Key, JsonSerializer.Serialize(value.Value, _options), null); + SpecificConfigBind(args.NewItem.Key, args.NewItem.Value); } } @@ -144,15 +142,54 @@ namespace MaaWpfGui.Configuration parsed.AnnouncementInfo.PropertyChanged += OnPropertyChangedFactory(); parsed.GUI.PropertyChanged += OnPropertyChangedFactory(); + parsed.CurrentConfig ??= new SpecificConfig(); foreach (var keyValue in parsed.Configurations) { - var key = "Root.Configurations." + keyValue.Key + "."; - keyValue.Value.DragItemIsChecked.CollectionChanged += OnCollectionChangedFactory(key + nameof(SpecificConfig.DragItemIsChecked) + "."); - keyValue.Value.InfrastOrder.CollectionChanged += OnCollectionChangedFactory(key + nameof(SpecificConfig.InfrastOrder) + "."); - keyValue.Value.TaskQueueOrder.CollectionChanged += OnCollectionChangedFactory(key + nameof(SpecificConfig.TaskQueueOrder) + "."); + SpecificConfigBind(keyValue.Key, keyValue.Value); } return parsed; + + void SpecificConfigBind(string name, SpecificConfig config) + { + var key = "Root.Configurations." + name + "."; + config.DragItemIsChecked.CollectionChanged += OnCollectionChangedFactory(key + nameof(SpecificConfig.DragItemIsChecked) + "."); + config.InfrastOrder.CollectionChanged += OnCollectionChangedFactory(key + nameof(SpecificConfig.InfrastOrder) + "."); + config.TaskQueueOrder.CollectionChanged += OnCollectionChangedFactory(key + nameof(SpecificConfig.TaskQueueOrder) + "."); + /* + config.TaskQueue.CollectionChanged += (in NotifyCollectionChangedEventArgs args) => + { + switch (args.Action) + { + case NotifyCollectionChangedAction.Add: + case NotifyCollectionChangedAction.Replace: + if (args.IsSingleItem) + { + args.NewItem.PropertyChanged += OnPropertyChangedFactory(key + args.NewItem.GetType().Name + "."); + } + else + { + foreach (var value in args.NewItems) + { + value.PropertyChanged += OnPropertyChangedFactory(key + value.GetType().Name + "."); + } + } + + break; + case NotifyCollectionChangedAction.Remove: + case NotifyCollectionChangedAction.Move: + case NotifyCollectionChangedAction.Reset: + break; + default: + throw new ArgumentOutOfRangeException(); + } + }; + foreach (var task in config.TaskQueue) + { + // TODO 改名 + task.PropertyChanged += OnPropertyChangedFactory(key + ".zdjd."); + }*/ + } } }); diff --git a/src/MaaWpfGui/Configuration/SpecificConfig.cs b/src/MaaWpfGui/Configuration/SpecificConfig.cs index 4d060a53a9..3a5cc7beb0 100644 --- a/src/MaaWpfGui/Configuration/SpecificConfig.cs +++ b/src/MaaWpfGui/Configuration/SpecificConfig.cs @@ -18,13 +18,13 @@ namespace MaaWpfGui.Configuration { public class SpecificConfig { - // ReSharper disable once AutoPropertyCanBeMadeGetOnly.Global - [JsonInclude] public GUI GUI { get; private set; } = new GUI(); + [JsonInclude] + public ObservableDictionary InfrastOrder { get; private set; } = new ObservableDictionary(); - [JsonInclude] public ObservableDictionary InfrastOrder { get; private set; } = new ObservableDictionary(); + [JsonInclude] + public ObservableDictionary TaskQueueOrder { get; private set; } = new ObservableDictionary(); - [JsonInclude] public ObservableDictionary TaskQueueOrder { get; private set; } = new ObservableDictionary(); - - [JsonInclude] public ObservableDictionary DragItemIsChecked { get; private set; } = new ObservableDictionary(); + [JsonInclude] + public ObservableDictionary DragItemIsChecked { get; private set; } = new ObservableDictionary(); } } diff --git a/src/MaaWpfGui/ViewModels/UserControl/Settings/GuiSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/Settings/GuiSettingsUserControlModel.cs index 22e035f55b..f4ffbd30ca 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/Settings/GuiSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/GuiSettingsUserControlModel.cs @@ -150,7 +150,6 @@ public class GuiSettingsUserControlModel : PropertyChangedBase set { ConfigFactory.Root.GUI.UseNotify = value; - NotifyOfPropertyChange(); if (value) { ToastNotification.ShowDirect("Test test");