From b69a840484e945d46565ca7c4e30e7ef103d09f7 Mon Sep 17 00:00:00 2001 From: uye <99072975+ABA2396@users.noreply.github.com> Date: Mon, 1 Apr 2024 16:54:33 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=B8=80=E5=A4=A9=E5=8F=AA=E5=96=9D?= =?UTF-8?q?=E4=B8=80=E6=AC=A1=E9=85=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaWpfGui/Constants/ConfigurationKeys.cs | 4 ++ src/MaaWpfGui/Main/AsstProxy.cs | 12 +++++- .../ViewModels/UI/SettingsViewModel.cs | 40 ++++++++++--------- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/MaaWpfGui/Constants/ConfigurationKeys.cs b/src/MaaWpfGui/Constants/ConfigurationKeys.cs index 9e083323a8..ef5227cdb3 100644 --- a/src/MaaWpfGui/Constants/ConfigurationKeys.cs +++ b/src/MaaWpfGui/Constants/ConfigurationKeys.cs @@ -42,6 +42,10 @@ namespace MaaWpfGui.Constants public const string CustomStageCode = "GUI.CustomStageCode"; public const string InverseClearMode = "GUI.InverseClearMode"; public const string WindowTitlePrefix = "GUI.WindowTitlePrefix"; + public const string SoberLanguage = "GUI.SoberLanguage"; + public const string Cheers = "GUI.Cheers"; + public const string Hangover = "GUI.Hangover"; + public const string LastBuyWineTime = "GUI.LastBuyWineTime"; public const string AddressHistory = "Connect.AddressHistory"; public const string AutoDetect = "Connect.AutoDetect"; diff --git a/src/MaaWpfGui/Main/AsstProxy.cs b/src/MaaWpfGui/Main/AsstProxy.cs index 36dacde386..c8722a7a64 100644 --- a/src/MaaWpfGui/Main/AsstProxy.cs +++ b/src/MaaWpfGui/Main/AsstProxy.cs @@ -715,7 +715,17 @@ namespace MaaWpfGui.Main if (buyWine) { - Instances.SettingsViewModel.Cheers = true; + var result = MessageBoxHelper.Show( + LocalizationHelper.GetString("DrunkAndStaggering"), + LocalizationHelper.GetString("Burping"), + iconKey: "DrunkAndStaggeringGeometry", + iconBrushKey: "PallasBrush"); + if (result == MessageBoxResult.OK) + { + Instances.SettingsViewModel.Cheers = true; + Instances.SettingsViewModel.LastBuyWineTime = DateTime.UtcNow.ToYjDate().ToFormattedString(); + Bootstrapper.ShutdownAndRestartWithoutArgs(); + } } break; diff --git a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs index 61a71ebb38..466a2d1ee9 100644 --- a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs @@ -2168,7 +2168,7 @@ namespace MaaWpfGui.ViewModels.UI } /* 访问好友设置 */ - private string _lastCreditFightTaskTime = ConfigurationHelper.GetValue(ConfigurationKeys.LastCreditFightTaskTime, DateTime.UtcNow.ToYjDate().AddDays(-1).ToString("yyyy/MM/dd HH:mm:ss")); + private string _lastCreditFightTaskTime = ConfigurationHelper.GetValue(ConfigurationKeys.LastCreditFightTaskTime, DateTime.UtcNow.ToYjDate().AddDays(-1).ToFormattedString()); public string LastCreditFightTaskTime { @@ -3933,7 +3933,7 @@ namespace MaaWpfGui.ViewModels.UI } } - private string _soberLanguage = ConfigurationHelper.GetValue("GUI.SoberLanguage", LocalizationHelper.DefaultLanguage); + private string _soberLanguage = ConfigurationHelper.GetValue(ConfigurationKeys.SoberLanguage, LocalizationHelper.DefaultLanguage); public string SoberLanguage { @@ -3941,7 +3941,7 @@ namespace MaaWpfGui.ViewModels.UI set { SetAndNotify(ref _soberLanguage, value); - ConfigurationHelper.SetValue("GUI.SoberLanguage", value); + ConfigurationHelper.SetValue(ConfigurationKeys.SoberLanguage, value); } } @@ -4015,7 +4015,7 @@ namespace MaaWpfGui.ViewModels.UI } } - private bool _cheers = bool.Parse(ConfigurationHelper.GetValue("GUI.Cheers", bool.FalseString)); + private bool _cheers = bool.Parse(ConfigurationHelper.GetValue(ConfigurationKeys.Cheers, bool.FalseString)); /// /// Gets or sets a value indicating whether to cheer. @@ -4031,15 +4031,15 @@ namespace MaaWpfGui.ViewModels.UI } SetAndNotify(ref _cheers, value); - ConfigurationHelper.SetValue("GUI.Cheers", value.ToString()); + ConfigurationHelper.SetValue(ConfigurationKeys.Cheers, value.ToString()); if (_cheers) { - SetPallasLanguage(); + ConfigurationHelper.SetValue(ConfigurationKeys.Localization, PallasLangKey); } } } - private bool _hangover = bool.Parse(ConfigurationHelper.GetValue("GUI.Hangover", bool.FalseString)); + private bool _hangover = bool.Parse(ConfigurationHelper.GetValue(ConfigurationKeys.Hangover, bool.FalseString)); /// /// Gets or sets a value indicating whether to hangover. @@ -4050,21 +4050,19 @@ namespace MaaWpfGui.ViewModels.UI set { SetAndNotify(ref _hangover, value); - ConfigurationHelper.SetValue("GUI.Hangover", value.ToString()); + ConfigurationHelper.SetValue(ConfigurationKeys.Hangover, value.ToString()); } } - private static void SetPallasLanguage() + private string _lastBuyWineTime = ConfigurationHelper.GetValue(ConfigurationKeys.LastBuyWineTime, DateTime.UtcNow.ToYjDate().AddDays(-1).ToFormattedString()); + + public string LastBuyWineTime { - ConfigurationHelper.SetValue(ConfigurationKeys.Localization, PallasLangKey); - var result = MessageBoxHelper.Show( - LocalizationHelper.GetString("DrunkAndStaggering"), - LocalizationHelper.GetString("Burping"), - iconKey: "DrunkAndStaggeringGeometry", - iconBrushKey: "PallasBrush"); - if (result == MessageBoxResult.OK) + get => _lastBuyWineTime; + set { - Bootstrapper.ShutdownAndRestartWithoutArgs(); + SetAndNotify(ref _lastBuyWineTime, value); + ConfigurationHelper.SetValue(ConfigurationKeys.LastBuyWineTime, value); } } @@ -4104,7 +4102,13 @@ namespace MaaWpfGui.ViewModels.UI /// The answer. public bool DidYouBuyWine() { - if (DateTime.UtcNow.ToYjDate().IsAprilFoolsDay()) + var now = DateTime.UtcNow.ToYjDate(); + if (now == DateTime.ParseExact(LastBuyWineTime.Replace('-', '/'), "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture)) + { + return false; + } + + if (now.IsAprilFoolsDay()) { return true; }