diff --git a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs index bbde75b2e2..fcaad2549b 100644 --- a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs @@ -1615,14 +1615,11 @@ namespace MaaWpfGui.ViewModels.UI Instances.TaskQueueViewModel.RefreshCustomInfrastPlan(); // SetAndNotify 在值没有变化时不会触发 PropertyChanged 事件,所以这里手动触发一下 - var index = Instances.TaskQueueViewModel.CustomInfrastPlanIndex; - var count = Instances.TaskQueueViewModel.CustomInfrastPlanList.Count; Instances.TaskQueueViewModel.NeedAddCustomInfrastPlanInfo = false; { - Instances.TaskQueueViewModel.CustomInfrastPlanIndex = (index + 1) % count; - Instances.TaskQueueViewModel.CustomInfrastPlanIndex = index; + Instances.TaskQueueViewModel.CustomInfrastPlanIndex--; + Instances.TaskQueueViewModel.CustomInfrastPlanIndex++; } - Instances.TaskQueueViewModel.NeedAddCustomInfrastPlanInfo = true; } } diff --git a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs index e0b4f667df..e66efed781 100644 --- a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs @@ -2643,9 +2643,24 @@ namespace MaaWpfGui.ViewModels.UI public int CustomInfrastPlanIndex { - get => _customInfrastPlanIndex; + get + { + if (_customInfrastPlanIndex >= CustomInfrastPlanInfoList.Count || _customInfrastPlanIndex < 0) + { + CustomInfrastPlanIndex = _customInfrastPlanIndex; + } + + return _customInfrastPlanIndex; + } set { + if (value >= CustomInfrastPlanInfoList.Count || value < 0) + { + var count = CustomInfrastPlanInfoList.Count; + value = (value % count + count) % count; + _logger.Warning($"CustomInfrastPlanIndex out of range, reset to Index % Count: {value}"); + } + if (value != _customInfrastPlanIndex && NeedAddCustomInfrastPlanInfo) { var plan = CustomInfrastPlanInfoList[value]; @@ -2855,14 +2870,7 @@ namespace MaaWpfGui.ViewModels.UI AddLog(prePlanPostDesc); } - if (CustomInfrastPlanIndex >= CustomInfrastPlanList.Count - 1) - { - CustomInfrastPlanIndex = 0; - } - else - { - ++CustomInfrastPlanIndex; - } + ++CustomInfrastPlanIndex; } ///