From 24e519bbe6c228d2208a421cc762f66324f48ee4 Mon Sep 17 00:00:00 2001 From: status102 <102887808+status102@users.noreply.github.com> Date: Tue, 12 Aug 2025 16:23:32 +0800 Subject: [PATCH] =?UTF-8?q?refactor(wpf):=20=E5=88=B7=E7=90=86=E6=99=BA?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=8C=87=E5=AE=9A=E6=9D=90=E6=96=99=E4=B8=8D?= =?UTF-8?q?=E5=86=8D=E4=BD=BF=E7=94=A8=E5=8F=8C=E5=B1=9E=E6=80=A7=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=EF=BC=8C=E4=BB=85=E4=BF=9D=E5=AD=98=E7=89=A9=E5=93=81?= =?UTF-8?q?id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FightSettingsUserControlModel.cs | 47 ++++++++----------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/FightSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/FightSettingsUserControlModel.cs index e67ee329db..8634c67a22 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/FightSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/FightSettingsUserControlModel.cs @@ -584,7 +584,17 @@ public class FightSettingsUserControlModel : TaskViewModel AllDrops.Sort((a, b) => string.Compare(a.Value, b.Value, StringComparison.Ordinal)); DropsList = [.. AllDrops]; - DropsListDropDownClosed(); + if (AllDrops.FirstOrDefault(i => i.Value == DropsItemId) is { } item) + { + DropsItemName = item.Display; + NotifyOfPropertyChange(nameof(DropsItemName)); + } + else + { + DropsItemId = string.Empty; + DropsItemName = string.Empty; + NotifyOfPropertyChange(nameof(DropsItemName)); + } } /// @@ -608,44 +618,25 @@ public class FightSettingsUserControlModel : TaskViewModel } } - private string _dropsItemName = ConfigurationHelper.GetValue(ConfigurationKeys.DropsItemName, LocalizationHelper.GetString("NotSelected")); - /// /// Gets or sets the item Name of drops. /// - public string DropsItemName - { - get => _dropsItemName; - set - { - SetAndNotify(ref _dropsItemName, value); - Instances.TaskQueueViewModel.SetFightParams(); - ConfigurationHelper.SetValue(ConfigurationKeys.DropsItemName, DropsItemName); - } - } + public string DropsItemName { get; set; } = string.Empty; // UI 绑定的方法 [UsedImplicitly] public void DropsListDropDownClosed() { - foreach (var item in DropsList) + if (DropsList.FirstOrDefault(i => i.Display == DropsItemName) is { } item) { - if (DropsItemName != item.Display) - { - continue; - } - DropsItemId = item.Value; - - if (DropsItemName != item.Display) - { - DropsItemName = LocalizationHelper.GetString("NotSelected"); - } - - return; } - - DropsItemName = LocalizationHelper.GetString("NotSelected"); + else + { + DropsItemId = string.Empty; + DropsItemName = LocalizationHelper.GetString("NotSelected"); + NotifyOfPropertyChange(nameof(DropsItemName)); + } } private int _dropsQuantity = ConfigurationHelper.GetValue(ConfigurationKeys.DropsQuantity, 5);