fix: 修复更换不同班次数的基建排班表可能遇到的数组越界

fix #9779
This commit is contained in:
uye
2024-07-21 22:48:31 +08:00
parent 4d8d31430e
commit 328e5db765
2 changed files with 19 additions and 14 deletions

View File

@@ -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;
}
}

View File

@@ -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;
}
/// <summary>