diff --git a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs index 2266b6d855..8341c3af9e 100644 --- a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs @@ -488,7 +488,7 @@ namespace MaaWpfGui.ViewModels.UI for (int i = 0; i < 8; ++i) { - if (!SettingsViewModel.TimerSettings.TimerModels.Timers[i].IsOn) + if (SettingsViewModel.TimerSettings.TimerModels.Timers[i].IsOn == false) { continue; } @@ -547,6 +547,8 @@ namespace MaaWpfGui.ViewModels.UI { _logger.Information($"Scheduled start: Timer Index: {configIndex}"); await HandleScheduledStart(configIndex); + + SettingsViewModel.TimerSettings.TimerModels.Timers[configIndex].IsOn ??= false; } } diff --git a/src/MaaWpfGui/ViewModels/UserControl/Settings/TimerSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/Settings/TimerSettingsUserControlModel.cs index e2e2108ee9..9b4ab82868 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/Settings/TimerSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/TimerSettingsUserControlModel.cs @@ -82,7 +82,7 @@ public class TimerSettingsUserControlModel : PropertyChangedBase { public class TimerProperties : PropertyChangedBase { - public TimerProperties(int timeId, bool isOn, int hour, int min, string? timerConfig) + public TimerProperties(int timeId, bool? isOn, int hour, int min, string? timerConfig) { TimerId = timeId; _isOn = isOn; @@ -102,17 +102,14 @@ public class TimerSettingsUserControlModel : PropertyChangedBase private readonly string _timerName = LocalizationHelper.GetString("Timer"); - public string TimerName - { - get => $"{_timerName} {TimerId + 1}"; - } + public string TimerName => $"{_timerName} {TimerId + 1}"; - private bool _isOn; + private bool? _isOn; /// /// Gets or sets a value indicating whether the timer is set. /// - public bool IsOn + public bool? IsOn { get => _isOn; set @@ -174,12 +171,12 @@ public class TimerSettingsUserControlModel : PropertyChangedBase { for (int i = 0; i < 8; i++) { - Timers[i] = new TimerProperties( - i, - ConfigurationHelper.GetTimer(i, bool.FalseString) == bool.TrueString, - int.Parse(ConfigurationHelper.GetTimerHour(i, $"{i * 3}")), - int.Parse(ConfigurationHelper.GetTimerMin(i, "0")), - ConfigurationHelper.GetTimerConfig(i, ConfigurationHelper.GetCurrentConfiguration())); + var timerState = ConfigurationHelper.GetTimer(i, bool.FalseString); + bool? isOn = bool.TryParse(timerState, out bool parsedBool) ? parsedBool : null; + var hour = int.Parse(ConfigurationHelper.GetTimerHour(i, $"{i * 3}")); + var minute = int.Parse(ConfigurationHelper.GetTimerMin(i, "0")); + var config = ConfigurationHelper.GetTimerConfig(i, ConfigurationHelper.GetCurrentConfiguration()); + Timers[i] = new(i, isOn, hour, minute, config); } } } diff --git a/src/MaaWpfGui/Views/UserControl/Settings/TimerSettingsUserControl.xaml b/src/MaaWpfGui/Views/UserControl/Settings/TimerSettingsUserControl.xaml index 85ddf7fa66..2e6768b1ee 100644 --- a/src/MaaWpfGui/Views/UserControl/Settings/TimerSettingsUserControl.xaml +++ b/src/MaaWpfGui/Views/UserControl/Settings/TimerSettingsUserControl.xaml @@ -87,7 +87,10 @@ + IsChecked="{Binding TimerModels.Timers[0].IsOn}" + MouseRightButtonUp="{s:Action ToggleCheckBoxNullOnRightClick, + Target={x:Type helper:CheckBoxHelper}}" + ToolTip="{DynamicResource CheckBoxesNotSaved}" /> + IsChecked="{Binding TimerModels.Timers[1].IsOn}" + MouseRightButtonUp="{s:Action ToggleCheckBoxNullOnRightClick, + Target={x:Type helper:CheckBoxHelper}}" + ToolTip="{DynamicResource CheckBoxesNotSaved}" /> + IsChecked="{Binding TimerModels.Timers[2].IsOn}" + MouseRightButtonUp="{s:Action ToggleCheckBoxNullOnRightClick, + Target={x:Type helper:CheckBoxHelper}}" + ToolTip="{DynamicResource CheckBoxesNotSaved}" /> + IsChecked="{Binding TimerModels.Timers[3].IsOn}" + MouseRightButtonUp="{s:Action ToggleCheckBoxNullOnRightClick, + Target={x:Type helper:CheckBoxHelper}}" + ToolTip="{DynamicResource CheckBoxesNotSaved}" /> + IsChecked="{Binding TimerModels.Timers[4].IsOn}" + MouseRightButtonUp="{s:Action ToggleCheckBoxNullOnRightClick, + Target={x:Type helper:CheckBoxHelper}}" + ToolTip="{DynamicResource CheckBoxesNotSaved}" /> + IsChecked="{Binding TimerModels.Timers[5].IsOn}" + MouseRightButtonUp="{s:Action ToggleCheckBoxNullOnRightClick, + Target={x:Type helper:CheckBoxHelper}}" + ToolTip="{DynamicResource CheckBoxesNotSaved}" /> + IsChecked="{Binding TimerModels.Timers[6].IsOn}" + MouseRightButtonUp="{s:Action ToggleCheckBoxNullOnRightClick, + Target={x:Type helper:CheckBoxHelper}}" + ToolTip="{DynamicResource CheckBoxesNotSaved}" /> + IsChecked="{Binding TimerModels.Timers[7].IsOn}" + MouseRightButtonUp="{s:Action ToggleCheckBoxNullOnRightClick, + Target={x:Type helper:CheckBoxHelper}}" + ToolTip="{DynamicResource CheckBoxesNotSaved}" />