From 3efbf6e0ca75e88fdcb104df8042b7891403da37 Mon Sep 17 00:00:00 2001 From: uye <2396806385@qq.com> Date: Fri, 7 Jul 2023 10:14:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=8F=AF=E9=80=89=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=B9=B6=E6=8F=90?= =?UTF-8?q?=E5=89=8D=E4=B8=A4=E5=88=86=E9=92=9F=E9=87=8D=E5=90=AF=E5=88=87?= =?UTF-8?q?=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaWpfGui/Constants/ConfigurationKeys.cs | 1 + src/MaaWpfGui/Helper/ConfigurationHelper.cs | 10 + .../ViewModels/UI/SettingsViewModel.cs | 44 +- .../ViewModels/UI/TaskQueueViewModel.cs | 35 +- .../UserControl/TimerSettingsUserControl.xaml | 652 ++++++++++-------- 5 files changed, 457 insertions(+), 285 deletions(-) diff --git a/src/MaaWpfGui/Constants/ConfigurationKeys.cs b/src/MaaWpfGui/Constants/ConfigurationKeys.cs index 5ee825ba97..f403667c33 100644 --- a/src/MaaWpfGui/Constants/ConfigurationKeys.cs +++ b/src/MaaWpfGui/Constants/ConfigurationKeys.cs @@ -175,5 +175,6 @@ namespace MaaWpfGui.Constants public const string GuideStepIndex = "Guide.StepIndex"; public const string ForceScheduledStart = "Timer.ForceScheduledStart"; + public const string CustomConfig = "Timer.CustomConfig"; } } diff --git a/src/MaaWpfGui/Helper/ConfigurationHelper.cs b/src/MaaWpfGui/Helper/ConfigurationHelper.cs index 72481005cc..4a0939e022 100644 --- a/src/MaaWpfGui/Helper/ConfigurationHelper.cs +++ b/src/MaaWpfGui/Helper/ConfigurationHelper.cs @@ -273,6 +273,16 @@ namespace MaaWpfGui.Helper return SetValue("TaskQueue.Order." + task, value); } + public static string GetTimerConfig(int i, string defaultValue) + { + return GetValue($"Timer.Timer{i + 1}.Config", defaultValue); + } + + public static bool SetTimerConfig(int i, string value) + { + return SetValue($"Timer.Timer{i + 1}.Config", value); + } + public static void Release() { lock (_lock) diff --git a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs index 4f179814a7..7638aef5d5 100644 --- a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs @@ -1651,12 +1651,20 @@ namespace MaaWpfGui.ViewModels.UI { public event PropertyChangedEventHandler PropertyChanged; - public TimerProperties(int timeId, bool isOn, int hour, int min) + public TimerProperties(int timeId, bool isOn, int hour, int min, string timerConfig) { TimerId = timeId; _isOn = isOn; _hour = hour; _min = min; + if (timerConfig == null || !ConfigurationHelper.GetConfigurationList().Contains(timerConfig)) + { + _timerConfig = ConfigurationHelper.GetCurrentConfiguration(); + } + else + { + _timerConfig = timerConfig; + } } protected void OnPropertyChanged([CallerMemberName] string name = null) @@ -1714,6 +1722,22 @@ namespace MaaWpfGui.ViewModels.UI } } + private string _timerConfig; + + /// + /// Gets or sets the config of the timer. + /// + public string TimerConfig + { + get => _timerConfig; + set + { + _timerConfig = value ?? ConfigurationHelper.GetCurrentConfiguration(); + OnPropertyChanged(); + ConfigurationHelper.SetTimerConfig(TimerId, value.ToString()); + } + } + public TimerProperties() { PropertyChanged += (sender, args) => { }; @@ -1730,7 +1754,8 @@ namespace MaaWpfGui.ViewModels.UI i, ConfigurationHelper.GetTimer(i, bool.FalseString) == bool.TrueString, int.Parse(ConfigurationHelper.GetTimerHour(i, $"{i * 3}")), - int.Parse(ConfigurationHelper.GetTimerMin(i, "0"))); + int.Parse(ConfigurationHelper.GetTimerMin(i, "0")), + ConfigurationHelper.GetTimerConfig(i, ConfigurationHelper.GetCurrentConfiguration())); } } } @@ -1752,6 +1777,21 @@ namespace MaaWpfGui.ViewModels.UI } } + private bool _customConfig = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.CustomConfig, bool.FalseString)); + + /// + /// Gets or sets a value indicating whether to use custom config. + /// + public bool CustomConfig + { + get => _customConfig; + set + { + SetAndNotify(ref _customConfig, value); + ConfigurationHelper.SetValue(ConfigurationKeys.CustomConfig, value.ToString()); + } + } + /* 刷理智设置 */ private string _penguinId = ConfigurationHelper.GetValue(ConfigurationKeys.PenguinId, string.Empty); diff --git a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs index 7d9b4fc517..f177404e19 100644 --- a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs @@ -210,8 +210,8 @@ namespace MaaWpfGui.ViewModels.UI private async void Timer1_Elapsed(object sender, EventArgs e) { // 提前记录时间,避免等待超过定时时间 - int intHour = DateTime.Now.Hour; - int intMinute = DateTime.Now.Minute; + DateTime currentTime = DateTime.Now; + currentTime = new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, currentTime.Hour, currentTime.Minute, 0); if (NeedToUpdateDatePrompt()) { @@ -251,17 +251,38 @@ namespace MaaWpfGui.ViewModels.UI } var timeToStart = false; + var timeToChangeConfig = false; + var configIndex = 0; for (int i = 0; i < 8; ++i) { - if (Instances.SettingsViewModel.TimerModels.Timers[i].IsOn && - Instances.SettingsViewModel.TimerModels.Timers[i].Hour == intHour && - Instances.SettingsViewModel.TimerModels.Timers[i].Min == intMinute) + if (Instances.SettingsViewModel.TimerModels.Timers[i].IsOn) { - timeToStart = true; - break; + DateTime startTime = new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, + Instances.SettingsViewModel.TimerModels.Timers[i].Hour, + Instances.SettingsViewModel.TimerModels.Timers[i].Min, + 0); + DateTime restartDateTime = startTime.AddMinutes(-2); + if (currentTime == restartDateTime) + { + timeToChangeConfig = true; + configIndex = i; + break; + } + else if (currentTime == startTime) + { + timeToStart = true; + break; + } } } + if (timeToChangeConfig) + { + // CurrentConfiguration设置后会重启 + Instances.SettingsViewModel.CurrentConfiguration = Instances.SettingsViewModel.TimerModels.Timers[2].TimerConfig; + return; + } + if (timeToStart) { if (Instances.SettingsViewModel.ForceScheduledStart) diff --git a/src/MaaWpfGui/Views/UserControl/TimerSettingsUserControl.xaml b/src/MaaWpfGui/Views/UserControl/TimerSettingsUserControl.xaml index 3d6270e866..f9185c68c6 100644 --- a/src/MaaWpfGui/Views/UserControl/TimerSettingsUserControl.xaml +++ b/src/MaaWpfGui/Views/UserControl/TimerSettingsUserControl.xaml @@ -13,22 +13,34 @@ xmlns:viewModels="clr-namespace:MaaWpfGui.ViewModels" xmlns:vm="clr-namespace:MaaWpfGui" d:DataContext="{d:DesignInstance {x:Type ui:SettingsViewModel}}" - d:DesignHeight="300" - d:DesignWidth="400" + d:DesignHeight="450" + d:DesignWidth="800" mc:Ignorable="d"> - + + + + + @@ -37,296 +49,384 @@ - - + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + +