diff --git a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/InfrastSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/InfrastSettingsUserControlModel.cs index 0d5d73c24c..ac13bb5a96 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/InfrastSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/InfrastSettingsUserControlModel.cs @@ -605,6 +605,22 @@ public class InfrastSettingsUserControlModel : TaskViewModel } var now = DateTime.Now; + + if (CustomInfrastPlanIndex >= CustomInfrastPlanInfoList.Count || CustomInfrastPlanIndex < 0) + { + CustomInfrastPlanIndex = 0; + } + + var currentPlan = CustomInfrastPlanInfoList.First(p => p.Index == CustomInfrastPlanIndex); + foreach (var period in currentPlan.PeriodList) + { + if (TimeLess(period.BeginHour, period.BeginMinute, now.Hour, now.Minute) && + TimeLess(now.Hour, now.Minute, period.EndHour, period.EndMinute)) + { + return; // 当前 index 仍在有效时间内,不需要切换 + } + } + foreach (var plan in CustomInfrastPlanInfoList.Where( plan => plan.PeriodList.Any( period => TimeLess(period.BeginHour, period.BeginMinute, now.Hour, now.Minute) && @@ -614,11 +630,6 @@ public class InfrastSettingsUserControlModel : TaskViewModel return; } - if (CustomInfrastPlanIndex >= CustomInfrastPlanList.Count || CustomInfrastPlanList.Count < 0) - { - CustomInfrastPlanIndex = 0; - } - return; static bool TimeLess(int lHour, int lMin, int rHour, int rMin) => (lHour != rHour) ? (lHour < rHour) : (lMin <= rMin);