diff --git a/src/MaaWpfGui/Main/AsstProxy.cs b/src/MaaWpfGui/Main/AsstProxy.cs index d45d80ea71..2e258932d9 100644 --- a/src/MaaWpfGui/Main/AsstProxy.cs +++ b/src/MaaWpfGui/Main/AsstProxy.cs @@ -757,15 +757,15 @@ namespace MaaWpfGui.Main case "Mall": { - if (Instances.TaskQueueViewModel.Stage != string.Empty && Instances.SettingsViewModel.CreditFightTaskEnabled) + if (Instances.TaskQueueViewModel.Stage != string.Empty && SettingsViewModel.MallTask.CreditFightTaskEnabled) { - Instances.SettingsViewModel.LastCreditFightTaskTime = DateTime.UtcNow.ToYjDate().ToFormattedString(); + SettingsViewModel.MallTask.LastCreditFightTaskTime = DateTime.UtcNow.ToYjDate().ToFormattedString(); Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("CompleteTask") + LocalizationHelper.GetString("CreditFight")); } - if (Instances.SettingsViewModel.CreditVisitFriendsEnabled) + if (SettingsViewModel.MallTask.CreditVisitFriendsEnabled) { - Instances.SettingsViewModel.LastCreditVisitFriendsTime = DateTime.UtcNow.ToYjDate().ToFormattedString(); + SettingsViewModel.MallTask.LastCreditVisitFriendsTime = DateTime.UtcNow.ToYjDate().ToFormattedString(); Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("CompleteTask") + LocalizationHelper.GetString("Visiting")); } diff --git a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs index 07bc6b404e..d429a5f1e4 100644 --- a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs @@ -74,6 +74,11 @@ namespace MaaWpfGui.ViewModels.UI #region 长草任务Model + /// + /// Gets 信用及购物任务Model + /// + public static MallSettingsUserControlModel MallTask { get; } = new(); + /// /// Gets 肉鸽任务Model /// @@ -404,7 +409,7 @@ namespace MaaWpfGui.ViewModels.UI } string[] wineList = ["酒", "liquor", "drink", "wine", "beer", "술", "🍷", "🍸", "🍺", "🍻", "🥃", "🍶"]; - return wineList.Any(CreditFirstList.Contains); + return wineList.Any(MallTask.CreditFirstList.Contains); } #endregion EasterEggs @@ -885,258 +890,6 @@ namespace MaaWpfGui.ViewModels.UI #endregion 基建设置 - #region 信用相关设置 - - private string _lastCreditFightTaskTime = ConfigurationHelper.GetValue(ConfigurationKeys.LastCreditFightTaskTime, DateTime.UtcNow.ToYjDate().AddDays(-1).ToFormattedString()); - - public string LastCreditFightTaskTime - { - get => _lastCreditFightTaskTime; - set - { - SetAndNotify(ref _lastCreditFightTaskTime, value); - ConfigurationHelper.SetValue(ConfigurationKeys.LastCreditFightTaskTime, value); - } - } - - private bool _creditFightTaskEnabled = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.CreditFightTaskEnabled, bool.FalseString)); - - /// - /// Gets or sets a value indicating whether credit fight task is enabled. - /// - public bool CreditFightTaskEnabled - { - get - { - try - { - if (DateTime.UtcNow.ToYjDate() > DateTime.ParseExact(_lastCreditFightTaskTime.Replace('-', '/'), "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture)) - { - return _creditFightTaskEnabled; - } - } - catch - { - return _creditFightTaskEnabled; - } - - return false; - } - - set - { - SetAndNotify(ref _creditFightTaskEnabled, value); - ConfigurationHelper.SetValue(ConfigurationKeys.CreditFightTaskEnabled, value.ToString()); - } - } - - public bool CreditFightTaskEnabledDisplay - { - get - { - return _creditFightTaskEnabled; - } - - set - { - SetAndNotify(ref _creditFightTaskEnabled, value); - ConfigurationHelper.SetValue(ConfigurationKeys.CreditFightTaskEnabled, value.ToString()); - } - } - - /// - /// Gets 设置选择的编队 - /// - // ReSharper disable once MemberCanBePrivate.Global - public List FormationSelectList { get; } = - [ - new() { Display = LocalizationHelper.GetString("Current"), Value = "0" }, - new() { Display = "1", Value = "1" }, - new() { Display = "2", Value = "2" }, - new() { Display = "3", Value = "3" }, - new() { Display = "4", Value = "4" }, - ]; - - private string _lastCreditVisitFriendsTime = ConfigurationHelper.GetValue(ConfigurationKeys.LastCreditVisitFriendsTime, DateTime.UtcNow.ToYjDate().AddDays(-1).ToFormattedString()); - - public string LastCreditVisitFriendsTime - { - get => _lastCreditVisitFriendsTime; - set - { - SetAndNotify(ref _lastCreditVisitFriendsTime, value); - ConfigurationHelper.SetValue(ConfigurationKeys.LastCreditVisitFriendsTime, value); - } - } - - private bool _creditVisitOnceADay = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.CreditVisitOnceADay, bool.FalseString)); - - /// - /// Gets or sets a value indicating whether to bypass the daily limit. - /// - public bool CreditVisitOnceADay - { - get => _creditVisitOnceADay; - set - { - SetAndNotify(ref _creditVisitOnceADay, value); - ConfigurationHelper.SetValue(ConfigurationKeys.CreditVisitOnceADay, value.ToString()); - } - } - - private bool _creditVisitFriendsEnabled = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.CreditVisitFriendsEnabled, bool.TrueString)); - - /// - /// Gets or sets a value indicating whether visiting friends task is enabled. - /// - public bool CreditVisitFriendsEnabled - { - get - { - if (!_creditVisitOnceADay) - { - return _creditVisitFriendsEnabled; - } - - try - { - return DateTime.UtcNow.ToYjDate() > DateTime.ParseExact(_lastCreditVisitFriendsTime.Replace('-', '/'), "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture) - && _creditVisitFriendsEnabled; - } - catch - { - return _creditVisitFriendsEnabled; - } - } - - set - { - SetAndNotify(ref _creditVisitFriendsEnabled, value); - ConfigurationHelper.SetValue(ConfigurationKeys.CreditVisitFriendsEnabled, value.ToString()); - } - } - - public bool CreditVisitFriendsEnabledDisplay - { - get - { - return _creditVisitFriendsEnabled; - } - - set - { - SetAndNotify(ref _creditVisitFriendsEnabled, value); - ConfigurationHelper.SetValue(ConfigurationKeys.CreditVisitFriendsEnabled, value.ToString()); - } - } - - private int _creditFightSelectFormation = Convert.ToInt32(ConfigurationHelper.GetValue(ConfigurationKeys.CreditFightSelectFormation, "0")); - - /// - /// Gets or sets a value indicating which formation will be select in credit fight. - /// - public int CreditFightSelectFormation - { - get => _creditFightSelectFormation; - set - { - SetAndNotify(ref _creditFightSelectFormation, value); - ConfigurationHelper.SetValue(ConfigurationKeys.CreditFightSelectFormation, value.ToString()); - } - } - - private bool _creditShopping = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.CreditShopping, bool.TrueString)); - - /// - /// Gets or sets a value indicating whether to shop with credit. - /// - public bool CreditShopping - { - get => _creditShopping; - set - { - SetAndNotify(ref _creditShopping, value); - ConfigurationHelper.SetValue(ConfigurationKeys.CreditShopping, value.ToString()); - } - } - - private string _creditFirstList = ConfigurationHelper.GetValue(ConfigurationKeys.CreditFirstListNew, LocalizationHelper.GetString("HighPriorityDefault")); - - /// - /// Gets or sets the priority item list of credit shop. - /// - public string CreditFirstList - { - get => _creditFirstList; - set - { - SetAndNotify(ref _creditFirstList, value); - ConfigurationHelper.SetValue(ConfigurationKeys.CreditFirstListNew, value); - } - } - - private string _creditBlackList = ConfigurationHelper.GetValue(ConfigurationKeys.CreditBlackListNew, LocalizationHelper.GetString("BlacklistDefault")); - - /// - /// Gets or sets the blacklist of credit shop. - /// - public string CreditBlackList - { - get => _creditBlackList; - set - { - SetAndNotify(ref _creditBlackList, value); - ConfigurationHelper.SetValue(ConfigurationKeys.CreditBlackListNew, value); - } - } - - private bool _creditForceShoppingIfCreditFull = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.CreditForceShoppingIfCreditFull, bool.FalseString)); - - /// - /// Gets or sets a value indicating whether save credit is enabled. - /// - public bool CreditForceShoppingIfCreditFull - { - get => _creditForceShoppingIfCreditFull; - set - { - SetAndNotify(ref _creditForceShoppingIfCreditFull, value); - ConfigurationHelper.SetValue(ConfigurationKeys.CreditForceShoppingIfCreditFull, value.ToString()); - } - } - - private bool _creditOnlyBuyDiscount = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.CreditOnlyBuyDiscount, bool.FalseString)); - - /// - /// Gets or sets a value indicating whether only buy discount is enabled. - /// - public bool CreditOnlyBuyDiscount - { - get => _creditOnlyBuyDiscount; - set - { - SetAndNotify(ref _creditOnlyBuyDiscount, value); - ConfigurationHelper.SetValue(ConfigurationKeys.CreditOnlyBuyDiscount, value.ToString()); - } - } - - private bool _creditReserveMaxCredit = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.CreditReserveMaxCredit, bool.FalseString)); - - /// - /// Gets or sets a value indicating whether reserve max credit is enabled. - /// - public bool CreditReserveMaxCredit - { - get => _creditReserveMaxCredit; - set - { - SetAndNotify(ref _creditReserveMaxCredit, value); - ConfigurationHelper.SetValue(ConfigurationKeys.CreditReserveMaxCredit, value.ToString()); - } - } - - #endregion 信用相关设置 - #region 领取奖励设置 private bool _receiveAward = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.ReceiveAward, bool.TrueString)); diff --git a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs index 5fe902097f..d43f61da5a 100644 --- a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs @@ -1678,24 +1678,24 @@ namespace MaaWpfGui.ViewModels.UI private bool AppendMall() { - var buyFirst = Instances.SettingsViewModel.CreditFirstList.Split(';', ';') + var buyFirst = SettingsViewModel.MallTask.CreditFirstList.Split(';', ';') .Select(s => s.Trim()); - var blackList = Instances.SettingsViewModel.CreditBlackList.Split(';', ';') + var blackList = SettingsViewModel.MallTask.CreditBlackList.Split(';', ';') .Select(s => s.Trim()); blackList = blackList.Union(_blackCharacterListMapping[SettingsViewModel.GameSettings.ClientType]); return Instances.AsstProxy.AsstAppendMall( - !string.IsNullOrEmpty(this.Stage) && Instances.SettingsViewModel.CreditFightTaskEnabled, - Instances.SettingsViewModel.CreditFightSelectFormation, - Instances.SettingsViewModel.CreditVisitFriendsEnabled, - Instances.SettingsViewModel.CreditShopping, + !string.IsNullOrEmpty(this.Stage) && SettingsViewModel.MallTask.CreditFightTaskEnabled, + SettingsViewModel.MallTask.CreditFightSelectFormation, + SettingsViewModel.MallTask.CreditVisitFriendsEnabled, + SettingsViewModel.MallTask.CreditShopping, buyFirst.ToArray(), blackList.ToArray(), - Instances.SettingsViewModel.CreditForceShoppingIfCreditFull, - Instances.SettingsViewModel.CreditOnlyBuyDiscount, - Instances.SettingsViewModel.CreditReserveMaxCredit); + SettingsViewModel.MallTask.CreditForceShoppingIfCreditFull, + SettingsViewModel.MallTask.CreditOnlyBuyDiscount, + SettingsViewModel.MallTask.CreditReserveMaxCredit); } private static bool AppendAward() diff --git a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/MallSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/MallSettingsUserControlModel.cs new file mode 100644 index 0000000000..0799363513 --- /dev/null +++ b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/MallSettingsUserControlModel.cs @@ -0,0 +1,278 @@ +// +// MaaWpfGui - A part of the MaaCoreArknights project +// Copyright (C) 2021 MistEO and Contributors +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License v3.0 only as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY +// + +#nullable enable +using System; +using System.Collections.Generic; +using System.Globalization; +using MaaWpfGui.Constants; +using MaaWpfGui.Extensions; +using MaaWpfGui.Helper; +using MaaWpfGui.Utilities.ValueType; +using Stylet; + +namespace MaaWpfGui.ViewModels.UserControl.TaskQueue; + +/// +/// 信用购物 +/// +public class MallSettingsUserControlModel : PropertyChangedBase +{ + private string _lastCreditFightTaskTime = ConfigurationHelper.GetValue(ConfigurationKeys.LastCreditFightTaskTime, DateTime.UtcNow.ToYjDate().AddDays(-1).ToFormattedString()); + + public string LastCreditFightTaskTime + { + get => _lastCreditFightTaskTime; + set + { + SetAndNotify(ref _lastCreditFightTaskTime, value); + ConfigurationHelper.SetValue(ConfigurationKeys.LastCreditFightTaskTime, value); + } + } + + private bool _creditFightTaskEnabled = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.CreditFightTaskEnabled, bool.FalseString)); + + /// + /// Gets or sets a value indicating whether credit fight task is enabled. + /// + public bool CreditFightTaskEnabled + { + get + { + try + { + if (DateTime.UtcNow.ToYjDate() > DateTime.ParseExact(_lastCreditFightTaskTime.Replace('-', '/'), "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture)) + { + return _creditFightTaskEnabled; + } + } + catch + { + return _creditFightTaskEnabled; + } + + return false; + } + + set + { + SetAndNotify(ref _creditFightTaskEnabled, value); + ConfigurationHelper.SetValue(ConfigurationKeys.CreditFightTaskEnabled, value.ToString()); + } + } + + public bool CreditFightTaskEnabledDisplay + { + get + { + return _creditFightTaskEnabled; + } + + set + { + SetAndNotify(ref _creditFightTaskEnabled, value); + ConfigurationHelper.SetValue(ConfigurationKeys.CreditFightTaskEnabled, value.ToString()); + } + } + + /// + /// Gets 设置选择的编队 + /// + // ReSharper disable once MemberCanBePrivate.Global + public List> FormationSelectList { get; } = + [ + new() { Display = LocalizationHelper.GetString("Current"), Value = 0 }, + new() { Display = "1", Value = 1 }, + new() { Display = "2", Value = 2 }, + new() { Display = "3", Value = 3 }, + new() { Display = "4", Value = 4 }, + ]; + + private string _lastCreditVisitFriendsTime = ConfigurationHelper.GetValue(ConfigurationKeys.LastCreditVisitFriendsTime, DateTime.UtcNow.ToYjDate().AddDays(-1).ToFormattedString()); + + public string LastCreditVisitFriendsTime + { + get => _lastCreditVisitFriendsTime; + set + { + SetAndNotify(ref _lastCreditVisitFriendsTime, value); + ConfigurationHelper.SetValue(ConfigurationKeys.LastCreditVisitFriendsTime, value); + } + } + + private bool _creditVisitOnceADay = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.CreditVisitOnceADay, bool.FalseString)); + + /// + /// Gets or sets a value indicating whether to bypass the daily limit. + /// + public bool CreditVisitOnceADay + { + get => _creditVisitOnceADay; + set + { + SetAndNotify(ref _creditVisitOnceADay, value); + ConfigurationHelper.SetValue(ConfigurationKeys.CreditVisitOnceADay, value.ToString()); + } + } + + private bool _creditVisitFriendsEnabled = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.CreditVisitFriendsEnabled, bool.TrueString)); + + /// + /// Gets or sets a value indicating whether visiting friends task is enabled. + /// + public bool CreditVisitFriendsEnabled + { + get + { + if (!_creditVisitOnceADay) + { + return _creditVisitFriendsEnabled; + } + + try + { + return DateTime.UtcNow.ToYjDate() > DateTime.ParseExact(_lastCreditVisitFriendsTime.Replace('-', '/'), "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture) + && _creditVisitFriendsEnabled; + } + catch + { + return _creditVisitFriendsEnabled; + } + } + + set + { + SetAndNotify(ref _creditVisitFriendsEnabled, value); + ConfigurationHelper.SetValue(ConfigurationKeys.CreditVisitFriendsEnabled, value.ToString()); + } + } + + public bool CreditVisitFriendsEnabledDisplay + { + get + { + return _creditVisitFriendsEnabled; + } + + set + { + SetAndNotify(ref _creditVisitFriendsEnabled, value); + ConfigurationHelper.SetValue(ConfigurationKeys.CreditVisitFriendsEnabled, value.ToString()); + } + } + + private int _creditFightSelectFormation = Convert.ToInt32(ConfigurationHelper.GetValue(ConfigurationKeys.CreditFightSelectFormation, "0")); + + /// + /// Gets or sets a value indicating which formation will be select in credit fight. + /// + public int CreditFightSelectFormation + { + get => _creditFightSelectFormation; + set + { + SetAndNotify(ref _creditFightSelectFormation, value); + ConfigurationHelper.SetValue(ConfigurationKeys.CreditFightSelectFormation, value.ToString()); + } + } + + private bool _creditShopping = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.CreditShopping, bool.TrueString)); + + /// + /// Gets or sets a value indicating whether to shop with credit. + /// + public bool CreditShopping + { + get => _creditShopping; + set + { + SetAndNotify(ref _creditShopping, value); + ConfigurationHelper.SetValue(ConfigurationKeys.CreditShopping, value.ToString()); + } + } + + private string _creditFirstList = ConfigurationHelper.GetValue(ConfigurationKeys.CreditFirstListNew, LocalizationHelper.GetString("HighPriorityDefault")); + + /// + /// Gets or sets the priority item list of credit shop. + /// + public string CreditFirstList + { + get => _creditFirstList; + set + { + SetAndNotify(ref _creditFirstList, value); + ConfigurationHelper.SetValue(ConfigurationKeys.CreditFirstListNew, value); + } + } + + private string _creditBlackList = ConfigurationHelper.GetValue(ConfigurationKeys.CreditBlackListNew, LocalizationHelper.GetString("BlacklistDefault")); + + /// + /// Gets or sets the blacklist of credit shop. + /// + public string CreditBlackList + { + get => _creditBlackList; + set + { + SetAndNotify(ref _creditBlackList, value); + ConfigurationHelper.SetValue(ConfigurationKeys.CreditBlackListNew, value); + } + } + + private bool _creditForceShoppingIfCreditFull = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.CreditForceShoppingIfCreditFull, bool.FalseString)); + + /// + /// Gets or sets a value indicating whether save credit is enabled. + /// + public bool CreditForceShoppingIfCreditFull + { + get => _creditForceShoppingIfCreditFull; + set + { + SetAndNotify(ref _creditForceShoppingIfCreditFull, value); + ConfigurationHelper.SetValue(ConfigurationKeys.CreditForceShoppingIfCreditFull, value.ToString()); + } + } + + private bool _creditOnlyBuyDiscount = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.CreditOnlyBuyDiscount, bool.FalseString)); + + /// + /// Gets or sets a value indicating whether only buy discount is enabled. + /// + public bool CreditOnlyBuyDiscount + { + get => _creditOnlyBuyDiscount; + set + { + SetAndNotify(ref _creditOnlyBuyDiscount, value); + ConfigurationHelper.SetValue(ConfigurationKeys.CreditOnlyBuyDiscount, value.ToString()); + } + } + + private bool _creditReserveMaxCredit = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.CreditReserveMaxCredit, bool.FalseString)); + + /// + /// Gets or sets a value indicating whether reserve max credit is enabled. + /// + public bool CreditReserveMaxCredit + { + get => _creditReserveMaxCredit; + set + { + SetAndNotify(ref _creditReserveMaxCredit, value); + ConfigurationHelper.SetValue(ConfigurationKeys.CreditReserveMaxCredit, value.ToString()); + } + } +} diff --git a/src/MaaWpfGui/Views/UI/TaskQueueView.xaml b/src/MaaWpfGui/Views/UI/TaskQueueView.xaml index 377e014621..d93739e869 100644 --- a/src/MaaWpfGui/Views/UI/TaskQueueView.xaml +++ b/src/MaaWpfGui/Views/UI/TaskQueueView.xaml @@ -256,22 +256,19 @@ DataContext="{Binding TaskSettingDataContext}" IsEnabled="{Binding Idle}" Visibility="{c:Binding TaskSettingVisibilities.Base}" /> - + - - + + - + + IsChecked="{Binding CreditVisitFriendsEnabledDisplay}" /> + IsChecked="{Binding CreditVisitOnceADay}" + Visibility="{c:Binding CreditVisitFriendsEnabledDisplay}" /> - + + ToolTip="{DynamicResource OnlyBuyDiscountTips}" /> + ToolTip="{DynamicResource ReserveMaxCreditTips}" /> diff --git a/src/MaaWpfGui/Views/UserControl/MallSettingsUserControl.xaml.cs b/src/MaaWpfGui/Views/UserControl/TaskQueue/MallSettingsUserControl.xaml.cs similarity index 95% rename from src/MaaWpfGui/Views/UserControl/MallSettingsUserControl.xaml.cs rename to src/MaaWpfGui/Views/UserControl/TaskQueue/MallSettingsUserControl.xaml.cs index 67701c69e9..796c7c9e15 100644 --- a/src/MaaWpfGui/Views/UserControl/MallSettingsUserControl.xaml.cs +++ b/src/MaaWpfGui/Views/UserControl/TaskQueue/MallSettingsUserControl.xaml.cs @@ -11,7 +11,7 @@ // but WITHOUT ANY WARRANTY // -namespace MaaWpfGui.Views.UserControl +namespace MaaWpfGui.Views.UserControl.TaskQueue { /// /// MallSettingsUserControl.xaml 的交互逻辑