From ca9807ce099e5cae133293df8dfcd2b56b0e06bd Mon Sep 17 00:00:00 2001 From: Status102 <102887808+status102@users.noreply.github.com> Date: Tue, 23 Dec 2025 17:11:48 +0800 Subject: [PATCH] chore: Update C# EditorConfig for c# 13 & 14 (#15146) [blame ignore] --- src/MaaWpfGui/.editorconfig | 19 ++- .../Configuration/Factory/ConfigFactory.cs | 19 +-- src/MaaWpfGui/Main/AsstProxy.cs | 99 ++++++-------- src/MaaWpfGui/Main/Bootstrapper.cs | 6 +- src/MaaWpfGui/States/RunningState.cs | 15 +- .../ViewModels/CopilotItemViewModel.cs | 6 +- src/MaaWpfGui/ViewModels/DragItemViewModel.cs | 6 +- src/MaaWpfGui/ViewModels/TaskViewModel.cs | 1 + .../ViewModels/UI/AnnouncementViewModel.cs | 39 ++---- .../ViewModels/UI/CopilotViewModel.cs | 85 ++++-------- src/MaaWpfGui/ViewModels/UI/RootViewModel.cs | 12 +- .../ViewModels/UI/SettingsViewModel.cs | 51 +++---- .../ViewModels/UI/TaskQueueViewModel.cs | 48 +++---- .../ViewModels/UI/ToolboxViewModel.cs | 79 ++++------- .../ViewModels/UI/VersionUpdateViewModel.cs | 31 ++--- .../AchievementSettingsUserControlModel.cs | 18 +-- .../BackgroundSettingsUserControlModel.cs | 18 +-- .../ConnectSettingsUserControlModel.cs | 87 ++++-------- ...nalNotificationSettingsUserControlModel.cs | 90 ++++-------- .../Settings/GameSettingsUserControlModel.cs | 60 +++----- .../Settings/GuiSettingsUserControlModel.cs | 45 ++---- .../Settings/IssueReportUserControlModel.cs | 3 +- .../Settings/PerformanceUserControlModel.cs | 6 +- .../Settings/RemoteControlUserControlModel.cs | 15 +- .../Settings/StartSettingsUserControlModel.cs | 45 ++---- .../Settings/TimerSettingsUserControlModel.cs | 21 +-- .../VersionUpdateSettingsUserControlModel.cs | 60 +++----- .../AwardSettingsUserControlModel.cs | 24 ++-- .../CustomSettingsUserControlModel.cs | 20 ++- .../FightSettingsUserControlModel.cs | 90 ++++-------- .../InfrastSettingsUserControlModel.cs | 48 +++---- .../TaskQueue/MallSettingsUserControlModel.cs | 60 +++----- .../ReclamationSettingsUserControlModel.cs | 27 ++-- .../RecruitSettingsUserControlModel.cs | 69 ++++------ .../RoguelikeSettingsUserControlModel.cs | 128 ++++++------------ .../StartUpSettingsUserControlModel.cs | 15 +- 36 files changed, 511 insertions(+), 954 deletions(-) diff --git a/src/MaaWpfGui/.editorconfig b/src/MaaWpfGui/.editorconfig index 1e11ad2c33..5e699c3f1e 100644 --- a/src/MaaWpfGui/.editorconfig +++ b/src/MaaWpfGui/.editorconfig @@ -161,12 +161,19 @@ csharp_style_deconstructed_variable_declaration = true:suggestion csharp_prefer_simple_default_expression = true:suggestion csharp_style_pattern_local_over_anonymous_function = true:suggestion csharp_style_inlined_variable_declaration = true:suggestion +# C# 13+ features +# Collection expressions (C# 12+) +dotnet_style_prefer_collection_expression = when_types_exactly_match:suggestion +# Primary constructors (C# 12+) +csharp_style_prefer_primary_constructors = true:suggestion +# Using aliases for any type (C# 12+) +csharp_using_directive_placement = outside_namespace:silent ############################### # C# Formatting Rules # ############################### # New line preferences -csharp_new_line_before_open_brace = all +csharp_new_line_before_open_brace = methods, types, control_blocks, properties csharp_new_line_before_else = true csharp_new_line_before_catch = true csharp_new_line_before_finally = true @@ -206,4 +213,12 @@ resharper_bad_list_line_breaks_highlighting = Hint # Code inspection: Incorrect spacing (multiple spaces are prohibited) resharper_multiple_spaces_highlighting = Hint # Code inspection: Incorrect spacing (around attributes) -resharper_bad_attribute_brackets_spaces_highlighting = Hint \ No newline at end of file +resharper_bad_attribute_brackets_spaces_highlighting = Hint + +# SA1500: Braces for multi-line statements should not share line +# Allow compact property syntax with field keyword (C# 13) +dotnet_diagnostic.SA1500.severity = none + +# SA1513: Closing brace should be followed by blank line +# Allow compact code style +dotnet_diagnostic.SA1513.severity = none \ No newline at end of file diff --git a/src/MaaWpfGui/Configuration/Factory/ConfigFactory.cs b/src/MaaWpfGui/Configuration/Factory/ConfigFactory.cs index b503ad80e4..0b3dfbcc78 100644 --- a/src/MaaWpfGui/Configuration/Factory/ConfigFactory.cs +++ b/src/MaaWpfGui/Configuration/Factory/ConfigFactory.cs @@ -31,6 +31,7 @@ using Serilog; [assembly: PropertyChanged.FilterType("MaaWpfGui.Configuration.")] namespace MaaWpfGui.Configuration.Factory; + using static MaaWpfGui.Helper.PathsHelper; public static class ConfigFactory @@ -54,8 +55,7 @@ public static class ConfigFactory private static readonly JsonSerializerOptions _options = new() { WriteIndented = true, Converters = { new JsonStringEnumConverter() }, Encoder = JavaScriptEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.CjkUnifiedIdeographs, UnicodeRanges.CjkSymbolsandPunctuation, UnicodeRanges.HalfwidthandFullwidthForms), DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }; // TODO: 参考 ConfigurationHelper ,拆几个函数出来 - private static readonly Lazy _rootConfig = new(() => - { + private static readonly Lazy _rootConfig = new(() => { lock (_lock) { if (Directory.Exists(ConfigDir) is false) @@ -111,8 +111,7 @@ public static class ConfigFactory } parsed.PropertyChanged += OnPropertyChangedFactory("Root."); - parsed.Configurations.CollectionChanged += (in NotifyCollectionChangedEventArgs> args) => - { + parsed.Configurations.CollectionChanged += (in NotifyCollectionChangedEventArgs> args) => { switch (args.Action) { case NotifyCollectionChangedAction.Add: @@ -207,8 +206,7 @@ public static class ConfigFactory private static PropertyChangedEventHandler OnPropertyChangedFactory(string key, object? oldValue, object? newValue) { - return (o, args) => - { + return (o, args) => { var after = newValue; if (after == null && args is PropertyChangedEventDetailArgs detailArgs) { @@ -221,8 +219,7 @@ public static class ConfigFactory private static PropertyChangedEventHandler OnPropertyChangedFactory(string key = "") { - return (o, args) => - { + return (o, args) => { object? after = null; if (args is PropertyChangedEventDetailArgs detailArgs) { @@ -235,8 +232,7 @@ public static class ConfigFactory private static NotifyCollectionChangedEventHandler> OnCollectionChangedFactory(string key) { - return (in NotifyCollectionChangedEventArgs> args) => - { + return (in NotifyCollectionChangedEventArgs> args) => { OnPropertyChanged(key + args.NewItem.Key, null, args.NewItem.Value); }; } @@ -384,8 +380,7 @@ public static class ConfigFactory public static List ConfigList { - get - { + get { var lists = new List(Root.Configurations.Count); using var enumerator = Root.Configurations.GetEnumerator(); while (enumerator.MoveNext()) diff --git a/src/MaaWpfGui/Main/AsstProxy.cs b/src/MaaWpfGui/Main/AsstProxy.cs index 5ec6c1f574..a09d24f85f 100644 --- a/src/MaaWpfGui/Main/AsstProxy.cs +++ b/src/MaaWpfGui/Main/AsstProxy.cs @@ -328,8 +328,7 @@ public class AsstProxy { _callback = CallbackFunction; _runningState = RunningState.Instance; - _tasksStatus.CollectionChanged += (in NotifyCollectionChangedEventArgs> args) => - { + _tasksStatus.CollectionChanged += (in NotifyCollectionChangedEventArgs> args) => { if (args.Action == NotifyCollectionChangedAction.Reset) { TaskSettingVisibilityInfo.Instance.CurrentTask = string.Empty; @@ -504,11 +503,10 @@ public class AsstProxy if (loaded == false || _handle == AsstHandle.Zero) { Execute.OnUIThreadAsync( - () => - { - MessageBoxHelper.Show(LocalizationHelper.GetString("ResourceBroken"), LocalizationHelper.GetString("Error"), iconKey: ResourceToken.FatalGeometry, iconBrushKey: ResourceToken.DangerBrush); - Bootstrapper.Shutdown(); - }); + () => { + MessageBoxHelper.Show(LocalizationHelper.GetString("ResourceBroken"), LocalizationHelper.GetString("Error"), iconKey: ResourceToken.FatalGeometry, iconBrushKey: ResourceToken.DangerBrush); + Bootstrapper.Shutdown(); + }); } _runningState.SetInit(true); @@ -519,31 +517,30 @@ public class AsstProxy // TODO: 之后把这个 OnUIThread 拆出来 // ReSharper disable once AsyncVoidLambda Execute.OnUIThread( - async () => - { - if (SettingsViewModel.StartSettings.RunDirectly) - { - // 如果是直接运行模式,就先让按钮显示为运行 - _runningState.SetIdle(false); - } + async () => { + if (SettingsViewModel.StartSettings.RunDirectly) + { + // 如果是直接运行模式,就先让按钮显示为运行 + _runningState.SetIdle(false); + } - await Task.Run(() => SettingsViewModel.StartSettings.TryToStartEmulator(true)); + await Task.Run(() => SettingsViewModel.StartSettings.TryToStartEmulator(true)); - // 一般是点了“停止”按钮了 - if (_runningState.GetStopping()) - { - Instances.TaskQueueViewModel.SetStopped(); - return; - } + // 一般是点了“停止”按钮了 + if (_runningState.GetStopping()) + { + Instances.TaskQueueViewModel.SetStopped(); + return; + } - // ReSharper disable once InvertIf - if (SettingsViewModel.StartSettings.RunDirectly) - { - // 重置按钮状态,不影响LinkStart判断 - _runningState.SetIdle(true); - await Instances.TaskQueueViewModel.LinkStart(); - } - }); + // ReSharper disable once InvertIf + if (SettingsViewModel.StartSettings.RunDirectly) + { + // 重置按钮状态,不影响LinkStart判断 + _runningState.SetIdle(true); + await Instances.TaskQueueViewModel.LinkStart(); + } + }); } /// @@ -584,10 +581,9 @@ public class AsstProxy var json = (JObject?)JsonConvert.DeserializeObject(jsonStr ?? string.Empty); MaaService.ProcCallbackMsg dlg = ProcMsg; Execute.OnUIThread( - () => - { - dlg((AsstMsg)msg, json); - }); + () => { + dlg((AsstMsg)msg, json); + }); } private AsstHandle _handle; @@ -712,8 +708,7 @@ public class AsstProxy var alternativesToken = details["details"]?["alternatives"]; if (alternativesToken is JArray { Count: > 1 } arr) { - screencapAlternatives = arr.Select(item => - { + screencapAlternatives = arr.Select(item => { string method1 = item?["method"]?.ToString() ?? "???"; string cost1 = item?["cost"]?.ToString() ?? "???"; return (method1, cost1); @@ -792,8 +787,7 @@ public class AsstProxy // 截图增强未生效禁止启动 if (needToStop) { - Execute.OnUIThreadAsync(async () => - { + Execute.OnUIThreadAsync(async () => { Connected = false; await Instances.TaskQueueViewModel.Stop(); Instances.TaskQueueViewModel.SetStopped(); @@ -939,11 +933,9 @@ public class AsstProxy else { var log = LocalizationHelper.GetString("TaskError") + LocalizationHelper.GetString(taskChain); - Task.Run(async () => - { + Task.Run(async () => { var screenshot = await AsstGetImageAsync(); - Execute.OnUIThread(() => - { + Execute.OnUIThread(() => { Instances.TaskQueueViewModel.AddLog(log, UiLogColor.Error, toolTip: screenshot?.CreateTooltip()); }); }); @@ -1098,8 +1090,7 @@ public class AsstProxy var interval = recoveryTime - DateTimeOffset.Now.AddMinutes(6); if (interval > TimeSpan.Zero) { - _toastNotificationTimer = new DispatcherTimer - { + _toastNotificationTimer = new DispatcherTimer { Interval = interval, }; _toastNotificationTimer.Tick += OnToastNotificationTimerTick; @@ -2068,8 +2059,7 @@ public class AsstProxy // string p = @"C:\tmp\this path contains spaces, and,commas\target.txt"; string args = $"/e, /select, \"{filename}\""; - ProcessStartInfo info = new() - { + ProcessStartInfo info = new() { FileName = "explorer", Arguments = args, }; @@ -2111,8 +2101,7 @@ public class AsstProxy bool success = false; try { - success = await GameDataReportService.PostWithRetryAsync(url, content, headers, subTask, penguinId => - { + success = await GameDataReportService.PostWithRetryAsync(url, content, headers, subTask, penguinId => { SettingsViewModel.GameSettings.PenguinId = penguinId; _logger.Information("New PenguinId got: {PenguinId}", penguinId); }); @@ -2276,10 +2265,9 @@ public class AsstProxy else { Execute.OnUIThreadAsync( - () => - { - Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("AutoDetectConnectionNotSupported"), UiLogColor.Error); - }); + () => { + Instances.TaskQueueViewModel.AddLog(LocalizationHelper.GetString("AutoDetectConnectionNotSupported"), UiLogColor.Error); + }); } } @@ -2510,8 +2498,7 @@ public class AsstProxy /// 是否成功。 public bool AsstStartGacha(bool once = true) { - var task = new AsstCustomTask() - { + var task = new AsstCustomTask() { CustomTasks = [once ? "GachaOnce" : "GachaTenTimes"], }; var (type, param) = task.Serialize(); @@ -2525,8 +2512,7 @@ public class AsstProxy /// 是否成功。 public bool AsstMiniGame(string taskName) { - var task = new AsstCustomTask() - { + var task = new AsstCustomTask() { CustomTasks = [taskName], }; var (type, param) = task.Serialize(); @@ -2540,8 +2526,7 @@ public class AsstProxy /// 是否成功。 public bool AsstStartVideoRec(string filename) { - var taskParams = new JObject - { + var taskParams = new JObject { ["filename"] = filename, }; AsstTaskId id = AsstAppendTaskWithEncoding(AsstTaskType.VideoRecognition, taskParams); diff --git a/src/MaaWpfGui/Main/Bootstrapper.cs b/src/MaaWpfGui/Main/Bootstrapper.cs index df9a3fee78..f42b53eb80 100644 --- a/src/MaaWpfGui/Main/Bootstrapper.cs +++ b/src/MaaWpfGui/Main/Bootstrapper.cs @@ -340,8 +340,7 @@ public class Bootstrapper : Bootstrapper cancel: LocalizationHelper.GetString("Cancel")); if (ret == MessageBoxResult.OK) { - var startInfo = new ProcessStartInfo - { + var startInfo = new ProcessStartInfo { FileName = "DependencySetup_依赖库安装.bat", WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory, // 设置工作目录 WindowStyle = ProcessWindowStyle.Normal, // 显示窗口让用户看到进度 @@ -671,8 +670,7 @@ public class Bootstrapper : Bootstrapper private static void ShowErrorDialog(Exception exception) { - Application.Current.Dispatcher.Invoke(() => - { + Application.Current.Dispatcher.Invoke(() => { // DragDrop.DoDragSourceMove 会导致崩溃,但不需要退出程序 // 这是一坨屎,但是没办法,只能这样了 var isDragDropException = exception is COMException && exception.ToString()!.Contains("DragDrop.DoDragSourceMove"); diff --git a/src/MaaWpfGui/States/RunningState.cs b/src/MaaWpfGui/States/RunningState.cs index fa85c94e37..a45125c2e7 100644 --- a/src/MaaWpfGui/States/RunningState.cs +++ b/src/MaaWpfGui/States/RunningState.cs @@ -50,8 +50,7 @@ public class RunningState public static RunningState Instance { - get - { + get { _instance ??= new(); return _instance; } @@ -68,8 +67,7 @@ public class RunningState public int ReminderIntervalMinutes { get => _reminderIntervalMinutes; - set - { + set { if (value < 1) { return; @@ -138,8 +136,7 @@ public class RunningState public bool Idle { get => _idle; - set - { + set { if (_idle == value) { return; @@ -175,8 +172,7 @@ public class RunningState public bool Inited { get => _inited; - set - { + set { if (_inited != value) { _inited = value; @@ -198,8 +194,7 @@ public class RunningState public bool Stopping { get => _stopping; - set - { + set { if (_stopping != value) { _stopping = value; diff --git a/src/MaaWpfGui/ViewModels/CopilotItemViewModel.cs b/src/MaaWpfGui/ViewModels/CopilotItemViewModel.cs index fbe64c9116..d7d6f64f5a 100644 --- a/src/MaaWpfGui/ViewModels/CopilotItemViewModel.cs +++ b/src/MaaWpfGui/ViewModels/CopilotItemViewModel.cs @@ -64,8 +64,7 @@ public class CopilotItemViewModel : PropertyChangedBase public bool IsRaid { get => _isRaid; - set - { + set { SetAndNotify(ref _isRaid, value); Instances.CopilotViewModel.SaveCopilotTask(); } @@ -80,8 +79,7 @@ public class CopilotItemViewModel : PropertyChangedBase public bool IsChecked { get => _isChecked; - set - { + set { SetAndNotify(ref _isChecked, value); Instances.CopilotViewModel.SaveCopilotTask(); } diff --git a/src/MaaWpfGui/ViewModels/DragItemViewModel.cs b/src/MaaWpfGui/ViewModels/DragItemViewModel.cs index d4b9402143..522c78a3b7 100644 --- a/src/MaaWpfGui/ViewModels/DragItemViewModel.cs +++ b/src/MaaWpfGui/ViewModels/DragItemViewModel.cs @@ -85,8 +85,7 @@ public class DragItemViewModel : PropertyChangedBase public bool? IsCheckedWithNull { get => _isCheckedWithNull; - set - { + set { SetAndNotify(ref _isCheckedWithNull, value); value ??= false; ConfigurationHelper.SetCheckedStorage(_storageKey, OriginalName, value.ToString()); @@ -147,8 +146,7 @@ public class DragItemViewModel : PropertyChangedBase public bool EnableSetting { get => _enableSetting; - set - { + set { SetAndNotify(ref _enableSetting, value); TaskSettingVisibilityInfo.Instance.Set(OriginalName, value); } diff --git a/src/MaaWpfGui/ViewModels/TaskViewModel.cs b/src/MaaWpfGui/ViewModels/TaskViewModel.cs index f46309e2f6..cb1a627a2a 100644 --- a/src/MaaWpfGui/ViewModels/TaskViewModel.cs +++ b/src/MaaWpfGui/ViewModels/TaskViewModel.cs @@ -28,6 +28,7 @@ using Newtonsoft.Json.Linq; using Stylet; namespace MaaWpfGui.ViewModels; + public abstract class TaskViewModel : PropertyChangedBase { private readonly Dictionary> _propertyDependencies = []; // 属性依赖关系, key为被订阅的属性名, value为依赖于该属性的属性名列表 diff --git a/src/MaaWpfGui/ViewModels/UI/AnnouncementViewModel.cs b/src/MaaWpfGui/ViewModels/UI/AnnouncementViewModel.cs index cf776cb846..67a644d7a0 100644 --- a/src/MaaWpfGui/ViewModels/UI/AnnouncementViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/AnnouncementViewModel.cs @@ -53,8 +53,7 @@ public class AnnouncementViewModel : Screen { UpdateImageSource(); - UpdateScrollStateCommand = new RelayCommand(scrollViewer => - { + UpdateScrollStateCommand = new RelayCommand(scrollViewer => { if (scrollViewer == null) { return; @@ -64,8 +63,7 @@ public class AnnouncementViewModel : Screen IsScrolledToBottom |= scrollViewer.VerticalOffset >= scrollViewer.ScrollableHeight - 10; }); - ScrollToTopCommand = new RelayCommand(scrollViewer => - { + ScrollToTopCommand = new RelayCommand(scrollViewer => { if (scrollViewer == null) { return; @@ -78,8 +76,7 @@ public class AnnouncementViewModel : Screen private void UpdateImageSource() { - ImageSource = SettingsViewModel.GuiSettings.Language switch - { + ImageSource = SettingsViewModel.GuiSettings.Language switch { "zh-cn" or "zh-tw" => "/Res/Img/NoSkland.jpg", _ => "/Res/Img/NoSkLandEn.jpg", }; @@ -89,8 +86,7 @@ public class AnnouncementViewModel : Screen { const string NewString = "(NEW!!!)"; var sections = markdown.Split(["### "], StringSplitOptions.RemoveEmptyEntries) - .Select(section => - { + .Select(section => { var lines = section.Split('\n'); bool isNew = false; if (lines.Length > 0 && lines[0].Contains(NewString, StringComparison.OrdinalIgnoreCase)) @@ -99,16 +95,14 @@ public class AnnouncementViewModel : Screen lines[0] = lines[0].Replace(NewString, string.Empty, StringComparison.OrdinalIgnoreCase).Trim(); } - return new AnnouncementSection - { + return new AnnouncementSection { Title = lines.FirstOrDefault(), IsNew = isNew, Content = "### " + string.Join("\n", lines).Trim([' ', '\n', '-']), }; }).ToList(); - sections.Insert(0, new() - { + sections.Insert(0, new() { Title = "ALL~ the Announcements", Content = markdown.Replace(NewString, "*", StringComparison.OrdinalIgnoreCase).Trim(), }); @@ -133,8 +127,7 @@ public class AnnouncementViewModel : Screen public ObservableCollection AnnouncementSections { get => _announcementSections; - set - { + set { SetAndNotify(ref _announcementSections, value); SelectedAnnouncementSection = AnnouncementSections.FirstOrDefault(); } @@ -148,16 +141,14 @@ public class AnnouncementViewModel : Screen set => SetAndNotify(ref _selectedAnnouncementSection, value); } - private static readonly string _announcementInFile = SettingsViewModel.GuiSettings.Language switch - { + private static readonly string _announcementInFile = SettingsViewModel.GuiSettings.Language switch { "zh-cn" or "zh-tw" => Path.Combine(PathsHelper.CacheDir, "announcement.md"), _ => Path.Combine(PathsHelper.CacheDir, "announcement_en.md"), }; private static string AnnouncementInFile { - get - { + get { if (!File.Exists(_announcementInFile)) { return null; @@ -178,8 +169,7 @@ public class AnnouncementViewModel : Screen return null; } - set - { + set { try { lock (_lock) @@ -203,8 +193,7 @@ public class AnnouncementViewModel : Screen public string AnnouncementInfo { get => _announcementInfo; - private set - { + private set { SetAndNotify(ref _announcementInfo, value); AnnouncementInFile = value; AnnouncementSections = [.. ParseAnnouncementInfo(AnnouncementInfo)]; @@ -216,8 +205,7 @@ public class AnnouncementViewModel : Screen public bool DoNotRemindThisAnnouncementAgain { get => _doNotRemindThisAnnouncementAgain; - set - { + set { SetAndNotify(ref _doNotRemindThisAnnouncementAgain, value); ConfigFactory.Root.AnnouncementInfo.DoNotShowAgain = value; } @@ -231,8 +219,7 @@ public class AnnouncementViewModel : Screen public bool DoNotShowAnnouncement { get => _doNotShowAnnouncement; - set - { + set { SetAndNotify(ref _doNotShowAnnouncement, value); ConfigFactory.Root.AnnouncementInfo.DoNotShow = value; } diff --git a/src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs b/src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs index 5c27687c4f..8f6b042f26 100644 --- a/src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs @@ -92,8 +92,7 @@ public partial class CopilotViewModel : Screen DisplayName = LocalizationHelper.GetString("Copilot"); AddLog(LocalizationHelper.GetString("CopilotTip"), showTime: false); _runningState = RunningState.Instance; - _runningState.StateChanged += (_, e) => - { + _runningState.StateChanged += (_, e) => { Idle = e.Idle; Inited = e.Inited; Stopping = e.Stopping; @@ -132,9 +131,7 @@ public partial class CopilotViewModel : Screen { return; } - - Execute.OnUIThread(() => - { + Execute.OnUIThread(() => { LogItemViewModels.Add(new LogItemViewModel(content, color, weight, "HH':'mm':'ss", showTime: showTime)); if (showTime) { @@ -161,8 +158,7 @@ public partial class CopilotViewModel : Screen /// private void ClearLog() { - Execute.OnUIThread(() => - { + Execute.OnUIThread(() => { foreach (var log in LogItemViewModels) { if (log.ToolTip is ToolTip t) @@ -229,16 +225,14 @@ public partial class CopilotViewModel : Screen public int CopilotTabIndex { get => _copilotTabIndex; - set - { + set { if (!SetAndNotify(ref _copilotTabIndex, value)) { return; } Form = false; - UseCopilotList = value switch - { + UseCopilotList = value switch { 1 => false, _ => UseCopilotList, }; @@ -253,8 +247,7 @@ public partial class CopilotViewModel : Screen public string Filename { get => _filename; - set - { + set { if (!File.Exists(value)) { var resourceFile = Path.Combine(ResourceDir, "copilot", Path.GetFileName(value)); @@ -326,8 +319,7 @@ public partial class CopilotViewModel : Screen public bool AddUserAdditional { get => _addUserAdditional; - set - { + set { SetAndNotify(ref _addUserAdditional, value); ConfigurationHelper.SetValue(ConfigurationKeys.CopilotAddUserAdditional, value.ToString()); } @@ -341,8 +333,7 @@ public partial class CopilotViewModel : Screen public string UserAdditional { get => _userAdditional; - set - { + set { value = value.Trim(); SetAndNotify(ref _userAdditional, value); ConfigurationHelper.SetValue(ConfigurationKeys.CopilotUserAdditional, value); @@ -396,8 +387,7 @@ public partial class CopilotViewModel : Screen skill = 3; } - var item = new UserAdditionalItemViewModel - { + var item = new UserAdditionalItemViewModel { Name = op.Name, Skill = skill, Module = op.Module, @@ -426,8 +416,7 @@ public partial class CopilotViewModel : Screen skill = 3; } - var item = new UserAdditionalItemViewModel - { + var item = new UserAdditionalItemViewModel { Name = name, Skill = skill, Module = 0, @@ -476,8 +465,7 @@ public partial class CopilotViewModel : Screen skill = 3; } - list.Add(new UserAdditional - { + list.Add(new UserAdditional { Name = item.Name.Trim(), Skill = skill, Module = item.Module, @@ -597,8 +585,7 @@ public partial class CopilotViewModel : Screen public int FormationIndex { get => _formationIndex; - set - { + set { SetAndNotify(ref _formationIndex, value); ConfigurationHelper.SetValue(ConfigurationKeys.CopilotSelectFormation, value.ToString()); } @@ -617,8 +604,7 @@ public partial class CopilotViewModel : Screen public int SupportUnitUsage { get => _supportUnitUsage; - set - { + set { SetAndNotify(ref _supportUnitUsage, value); ConfigurationHelper.SetValue(ConfigurationKeys.CopilotSupportUnitUsage, value.ToString()); } @@ -639,8 +625,7 @@ public partial class CopilotViewModel : Screen public bool UseCopilotList { get => _useCopilotList; - set - { + set { if (value) { _taskType = AsstTaskType.Copilot; @@ -659,8 +644,7 @@ public partial class CopilotViewModel : Screen public string? CopilotTaskName { get => _copilotTaskName; - set - { + set { value = InvalidStageNameRegex().Replace(value ?? string.Empty, string.Empty).Trim(); SetAndNotify(ref _copilotTaskName, value); } @@ -673,8 +657,7 @@ public partial class CopilotViewModel : Screen public int LoopTimes { get => _loopTimes; - set - { + set { SetAndNotify(ref _loopTimes, value); ConfigurationHelper.SetValue(ConfigurationKeys.CopilotLoopTimes, value.ToString()); } @@ -701,8 +684,7 @@ public partial class CopilotViewModel : Screen public string CopilotUrl { get => _copilotUrl; - private set - { + private set { UrlText = value == CopilotUiUrl ? LocalizationHelper.GetString("PrtsPlus") : LocalizationHelper.GetString("VideoLink"); SetAndNotify(ref _copilotUrl, value); } @@ -737,8 +719,7 @@ public partial class CopilotViewModel : Screen [UsedImplicitly] public void SelectFile() { - var dialog = new OpenFileDialog - { + var dialog = new OpenFileDialog { Filter = "JSON|*.json|Video|*.mp4;*.m4s;*.mkv;*.flv;*.avi", }; @@ -797,8 +778,7 @@ public partial class CopilotViewModel : Screen [UsedImplicitly] public async Task ImportFiles() { - var dialog = new OpenFileDialog - { + var dialog = new OpenFileDialog { Filter = "JSON|*.json", Multiselect = true, }; @@ -1491,8 +1471,7 @@ public partial class CopilotViewModel : Screen /// public void CopilotTaskSuccess() { - Execute.OnUIThread(() => - { + Execute.OnUIThread(() => { foreach (var model in CopilotItemViewModels) { if (!model.IsChecked) @@ -1521,8 +1500,7 @@ public partial class CopilotViewModel : Screen [UsedImplicitly] public void CopilotItemIndexChanged() { - Execute.OnUIThread(() => - { + Execute.OnUIThread(() => { for (int i = 0; i < CopilotItemViewModels.Count; i++) { CopilotItemViewModels[i].Index = i; @@ -1633,8 +1611,7 @@ public partial class CopilotViewModel : Screen { Regex regex = new(@"(?<=;)(?[^,;]+)(?:, *(?\d))?(?=;)", RegexOptions.Compiled); var matches = regex.Matches(";" + UserAdditional + ";").ToList(); - userAdditional = matches.Select(match => - { + userAdditional = matches.Select(match => { var name = match.Groups[1].Value.Trim(); var skillStr = match.Groups[2].Value; int skill = string.IsNullOrEmpty(skillStr) ? 1 : int.Parse(skillStr); @@ -1647,8 +1624,7 @@ public partial class CopilotViewModel : Screen skill = 3; } - return new UserAdditional - { + return new UserAdditional { Name = name, Skill = skill, Module = 0, @@ -1669,14 +1645,12 @@ public partial class CopilotViewModel : Screen { _copilotIdList.Clear(); - var t = CopilotItemViewModels.Where(i => i.IsChecked).Select(i => - { + var t = CopilotItemViewModels.Where(i => i.IsChecked).Select(i => { _copilotIdList.Add(i.CopilotId); return new MultiTask { FileName = i.FilePath, IsRaid = i.IsRaid, StageName = i.Name, IsParadox = CopilotTabIndex == 2, }; }); - var task = new AsstCopilotTask() - { + var task = new AsstCopilotTask() { MultiTasks = [.. t], Formation = Form, SupportUnitUsage = UseSupportUnitUsage ? SupportUnitUsage : 0, @@ -1706,8 +1680,7 @@ public partial class CopilotViewModel : Screen } } - var task = new AsstCopilotTask() - { + var task = new AsstCopilotTask() { FileName = IsDataFromWeb ? TempCopilotFile : Filename, Formation = Form, SupportUnitUsage = UseSupportUnitUsage ? SupportUnitUsage : 0, @@ -1786,8 +1759,7 @@ public partial class CopilotViewModel : Screen private int CopilotId { get => _copilotId; - set - { + set { SetAndNotify(ref _copilotId, value); CouldLikeWebJson = value > 0; } @@ -1834,8 +1806,7 @@ public partial class CopilotViewModel : Screen return false; } - var stageNames = copilotItemViewModels.Select(i => i.FilePath).ToHashSet().Select(async path => - { + var stageNames = copilotItemViewModels.Select(i => i.FilePath).ToHashSet().Select(async path => { if (!File.Exists(path)) { AddLog(LocalizationHelper.GetString("CopilotNoFound") + path, UiLogColor.Error, showTime: false); diff --git a/src/MaaWpfGui/ViewModels/UI/RootViewModel.cs b/src/MaaWpfGui/ViewModels/UI/RootViewModel.cs index 36dd418f2b..a4b2c8b700 100644 --- a/src/MaaWpfGui/ViewModels/UI/RootViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/RootViewModel.cs @@ -52,8 +52,7 @@ public class RootViewModel : Conductor.Collection.OneActive MessageBoxHelper.Show(LocalizationHelper.GetString("NightlyWarning")); } - Task.Run(async () => - { + Task.Run(async () => { await Instances.AnnouncementViewModel.CheckAndDownloadAnnouncement(); if (Instances.AnnouncementViewModel.DoNotRemindThisAnnouncementAgain) { @@ -140,12 +139,10 @@ public class RootViewModel : Conductor.Collection.OneActive public (int Current, int Max)? TaskProgress { get => _taskProgress; - set - { + set { SetAndNotify(ref _taskProgress, value); - Execute.OnUIThreadAsync(() => - { + Execute.OnUIThreadAsync(() => { if (Application.Current.MainWindow == null || !Application.Current.MainWindow.IsVisible) { return; @@ -198,8 +195,7 @@ public class RootViewModel : Conductor.Collection.OneActive public bool IsWindowTopMost { get => _isWindowTopMost; - set - { + set { if (_isWindowTopMost == value) { return; diff --git a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs index 4560d8d3e1..6437270d43 100644 --- a/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/SettingsViewModel.cs @@ -131,8 +131,7 @@ public class SettingsViewModel : Screen HangoverEnd(); _runningState = RunningState.Instance; - _runningState.StateChanged += (_, e) => - { + _runningState.StateChanged += (_, e) => { Idle = e.Idle; // Inited = e.Inited; @@ -263,8 +262,7 @@ public class SettingsViewModel : Screen private void Settings_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs? e) { - Execute.OnUIThread(() => - { + Execute.OnUIThread(() => { for (int i = 0; i < Settings.Count; i++) { var item = Settings[i]; @@ -283,8 +281,7 @@ public class SettingsViewModel : Screen private void OnSettingItemValueChanged() { - Application.Current.Dispatcher.InvokeAsync(() => - { + Application.Current.Dispatcher.InvokeAsync(() => { RefreshDividerOffsetsRequested?.Invoke(this, EventArgs.Empty); }, System.Windows.Threading.DispatcherPriority.Loaded); } @@ -355,8 +352,7 @@ public class SettingsViewModel : Screen public bool Cheers { get => _cheers; - set - { + set { if (_cheers == value) { return; @@ -379,8 +375,7 @@ public class SettingsViewModel : Screen public bool Hangover { get => _hangover; - set - { + set { SetAndNotify(ref _hangover, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.Hangover, value.ToString()); } @@ -391,8 +386,7 @@ public class SettingsViewModel : Screen public string LastBuyWineTime { get => _lastBuyWineTime; - set - { + set { SetAndNotify(ref _lastBuyWineTime, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.LastBuyWineTime, value); } @@ -431,8 +425,7 @@ public class SettingsViewModel : Screen public string SoberLanguage { get => _soberLanguage; - set - { + set { SetAndNotify(ref _soberLanguage, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.SoberLanguage, value); } @@ -503,8 +496,7 @@ public class SettingsViewModel : Screen public string? CurrentConfiguration { get => _currentConfiguration; - set - { + set { SetAndNotify(ref _currentConfiguration, value); ConfigurationHelper.SwitchConfiguration(value); @@ -533,8 +525,7 @@ public class SettingsViewModel : Screen { ConfigurationList.Add(new CombinedData { Display = NewConfigurationName, Value = NewConfigurationName }); - var growlInfo = new GrowlInfo - { + var growlInfo = new GrowlInfo { IsCustom = true, Message = string.Format(LocalizationHelper.GetString("AddConfigSuccess"), NewConfigurationName), IconKey = "HangoverGeometry", @@ -544,8 +535,7 @@ public class SettingsViewModel : Screen } else { - var growlInfo = new GrowlInfo - { + var growlInfo = new GrowlInfo { IsCustom = true, Message = string.Format(LocalizationHelper.GetString("ConfigExists"), NewConfigurationName), IconKey = "HangoverGeometry", @@ -576,8 +566,7 @@ public class SettingsViewModel : Screen public int GuideStepIndex { get => _guideStepIndex; - set - { + set { SetAndNotify(ref _guideStepIndex, value); ConfigurationHelper.SetValue(ConfigurationKeys.GuideStepIndex, value.ToString()); } @@ -639,8 +628,7 @@ public class SettingsViewModel : Screen } _resetNotifyTimer = new Timer(20); - _resetNotifyTimer.Elapsed += (_, _) => - { + _resetNotifyTimer.Elapsed += (_, _) => { _notifySource = NotifyType.None; }; _resetNotifyTimer.AutoReset = false; @@ -666,8 +654,7 @@ public class SettingsViewModel : Screen public List DividerVerticalOffsetList { get => _dividerVerticalOffsetList; - set - { + set { if (_dividerVerticalOffsetList == value) { return; @@ -686,8 +673,7 @@ public class SettingsViewModel : Screen public int SelectedIndex { get => _selectedIndex; - set - { + set { if (_selectedIndex == value) { return; @@ -730,8 +716,7 @@ public class SettingsViewModel : Screen public double ScrollOffset { get => _scrollOffset; - set - { + set { if (!AllowScrollOffsetChange) { return; @@ -820,8 +805,7 @@ public class SettingsViewModel : Screen public bool IsCheckingAnnouncement { get => _isCheckingAnnouncement; - set - { + set { SetAndNotify(ref _isCheckingAnnouncement, value); } } @@ -933,8 +917,7 @@ public class SettingsViewModel : Screen /// private string ClientName { - get - { + get { foreach (var item in GameSettings.ClientTypeList.Where(item => item.Value == GameSettings.ClientType)) { return item.Display; diff --git a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs index e8f7a1a903..d59f93d8c3 100644 --- a/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/TaskQueueViewModel.cs @@ -133,8 +133,7 @@ public class TaskQueueViewModel : Screen public void TaskItemSelectionChanged(object? sender = null, NotifyCollectionChangedEventArgs? e = null) { _ = (sender, e); - Execute.OnUIThread(() => - { + Execute.OnUIThread(() => { int index = 0; foreach (var item in TaskItemViewModels) { @@ -171,8 +170,7 @@ public class TaskQueueViewModel : Screen public bool EnableAfterActionSetting { get => _enableAfterActionSetting; - set - { + set { SetAndNotify(ref _enableAfterActionSetting, value); TaskSettingVisibilityInfo.Instance.Set("AfterAction", value); } @@ -323,8 +321,7 @@ public class TaskQueueViewModel : Screen public TaskQueueViewModel() { _runningState = RunningState.Instance; - _runningState.StateChanged += (_, e) => - { + _runningState.StateChanged += (_, e) => { Idle = e.Idle; Inited = e.Inited; Stopping = e.Stopping; @@ -340,8 +337,7 @@ public class TaskQueueViewModel : Screen private void RunningState_TimeOut(object? sender, string message) { - Execute.OnUIThread(() => - { + Execute.OnUIThread(() => { AddLog(message, UiLogColor.Warning); ToastNotification.ShowDirect(message); if (!SettingsViewModel.ExternalNotificationSettings.ExternalNotificationSendWhenTimeout) @@ -482,8 +478,7 @@ public class TaskQueueViewModel : Screen UpdateDatePromptAndStagesLocally(); var delayTime = CalculateRandomDelay(); - _ = Task.Run(async () => - { + _ = Task.Run(async () => { await Task.Delay(delayTime); await _runningState.UntilIdleAsync(60000); await UpdateDatePromptAndStagesWeb(); @@ -507,8 +502,7 @@ public class TaskQueueViewModel : Screen _isCheckingForUpdates = true; var delayTime = CalculateRandomDelay(); - _ = Task.Run(async () => - { + _ = Task.Run(async () => { _logger.Information("waiting for update check: {DelayTime}", delayTime); await Task.Delay(delayTime); await Instances.VersionUpdateViewModel.VersionUpdateAndAskToRestartAsync(); @@ -669,8 +663,7 @@ public class TaskQueueViewModel : Screen delay.TotalMilliseconds); var dialog = HandyControl.Controls.Dialog.Show(dialogUserControl, nameof(Views.UI.RootView)); var tcs = new TaskCompletionSource(); - dialogUserControl.Click += (_, _) => - { + dialogUserControl.Click += (_, _) => { canceled = true; dialog.Close(); tcs.TrySetResult(true); @@ -886,13 +879,11 @@ public class TaskQueueViewModel : Screen /// The toolTip public void AddLog(string? content, string color = UiLogColor.Trace, string weight = "Regular", ToolTip? toolTip = null) { - if (string.IsNullOrWhiteSpace(content)) + if (string.IsNullOrEmpty(content)) { return; } - - Execute.OnUIThread(() => - { + Execute.OnUIThread(() => { var log = new LogItemViewModel(content, color, weight, toolTip: toolTip); LogItemViewModels.Add(log); switch (color) @@ -915,8 +906,7 @@ public class TaskQueueViewModel : Screen /// private void ClearLog() { - Execute.OnUIThread(() => - { + Execute.OnUIThread(() => { LogItemViewModels.Clear(); DownloadLogItemViewModel = new(string.Empty); _logger.Information("Main windows log clear."); @@ -932,8 +922,7 @@ public class TaskQueueViewModel : Screen /// Optional tooltip. public void UpdateDownloadLog(string fullText, string? toolTip = null) { - Execute.OnUIThread(() => - { + Execute.OnUIThread(() => { // Keep download area limited to a single entry. if (string.IsNullOrEmpty(fullText)) { @@ -975,8 +964,7 @@ public class TaskQueueViewModel : Screen public bool InverseMode { get => _inverseMode; - set - { + set { SetAndNotify(ref _inverseMode, value); InverseShowText = value ? LocalizationHelper.GetString("Inverse") : LocalizationHelper.GetString("Clear"); InverseMenuText = value ? LocalizationHelper.GetString("Clear") : LocalizationHelper.GetString("Inverse"); @@ -1431,8 +1419,7 @@ public class TaskQueueViewModel : Screen { _runningState.SetStopping(true); AddLog(LocalizationHelper.GetString("Stopping")); - await Task.Run(() => - { + await Task.Run(() => { if (!Instances.AsstProxy.AsstStop()) { _logger.Warning("Failed to stop Asst"); @@ -1605,8 +1592,7 @@ public class TaskQueueViewModel : Screen if (mainFightRet && FightTask.UseRemainingSanityStage && !string.IsNullOrEmpty(FightTask.RemainingSanityStage)) { - var task = new AsstFightTask() - { + var task = new AsstFightTask() { Stage = FightTask.RemainingSanityStage, MaxTimes = int.MaxValue, Series = 0, @@ -1651,8 +1637,7 @@ public class TaskQueueViewModel : Screen return; } - var task = new AsstFightTask() - { + var task = new AsstFightTask() { Stage = FightTask.RemainingSanityStage ?? string.Empty, MaxTimes = int.MaxValue, Series = 0, @@ -1696,8 +1681,7 @@ public class TaskQueueViewModel : Screen public bool Idle { get => _idle; - set - { + set { SetAndNotify(ref _idle, value); if (!value) { diff --git a/src/MaaWpfGui/ViewModels/UI/ToolboxViewModel.cs b/src/MaaWpfGui/ViewModels/UI/ToolboxViewModel.cs index 31faf4e3f8..026c5e2c01 100644 --- a/src/MaaWpfGui/ViewModels/UI/ToolboxViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/ToolboxViewModel.cs @@ -32,7 +32,6 @@ using MaaWpfGui.Main; using MaaWpfGui.Models; using MaaWpfGui.Models.AsstTasks; using MaaWpfGui.States; -using MaaWpfGui.Utilities.ValueType; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Serilog; @@ -56,8 +55,7 @@ public class ToolboxViewModel : Screen { DisplayName = LocalizationHelper.GetString("Toolbox"); _runningState = RunningState.Instance; - _runningState.StateChanged += (__, e) => - { + _runningState.StateChanged += (__, e) => { Idle = e.Idle; Inited = e.Inited; Stopping = e.Stopping; @@ -144,8 +142,7 @@ public class ToolboxViewModel : Screen var opersArray = (JArray?)combs["opers"] ?? []; - var opersWithPotential = opersArray.Select(oper => - { + var opersWithPotential = opersArray.Select(oper => { int operLevel = (int)(oper["level"] ?? -1); var operId = oper["id"]?.ToString(); @@ -208,8 +205,7 @@ public class ToolboxViewModel : Screen string GetBrushKeyByStar(int level, bool isMax) { - return (level, isMax) switch - { + return (level, isMax) switch { (6, true) => UiLogColor.Star6OperatorPotentialFull, (6, false) => UiLogColor.Star6Operator, (5, true) => UiLogColor.Star5OperatorPotentialFull, @@ -235,8 +231,7 @@ public class ToolboxViewModel : Screen public bool ChooseLevel3 { get => _chooseLevel3; - set - { + set { SetAndNotify(ref _chooseLevel3, value); ConfigurationHelper.SetValue(ConfigurationKeys.ChooseLevel3, value.ToString()); } @@ -250,8 +245,7 @@ public class ToolboxViewModel : Screen public bool ChooseLevel4 { get => _chooseLevel4; - set - { + set { SetAndNotify(ref _chooseLevel4, value); ConfigurationHelper.SetValue(ConfigurationKeys.ChooseLevel4, value.ToString()); } @@ -265,8 +259,7 @@ public class ToolboxViewModel : Screen public bool ChooseLevel5 { get => _chooseLevel5; - set - { + set { SetAndNotify(ref _chooseLevel5, value); ConfigurationHelper.SetValue(ConfigurationKeys.ChooseLevel5, value.ToString()); } @@ -280,8 +273,7 @@ public class ToolboxViewModel : Screen public bool ChooseLevel6 { get => _chooseLevel6; - set - { + set { SetAndNotify(ref _chooseLevel6, value); ConfigurationHelper.SetValue(ConfigurationKeys.ChooseLevel6, value.ToString()); } @@ -295,8 +287,7 @@ public class ToolboxViewModel : Screen public bool RecruitAutoSetTime { get => _autoSetTime; - set - { + set { SetAndNotify(ref _autoSetTime, value); ConfigurationHelper.SetValue(ConfigurationKeys.AutoSetTime, value.ToString()); } @@ -345,8 +336,7 @@ public class ToolboxViewModel : Screen levelList.Add(6); } - var task = new AsstRecruitTask() - { + var task = new AsstRecruitTask() { SelectList = levelList, ConfirmList = [-1], // 仅公招识别时将-1加入comfirm_level SetRecruitTime = RecruitAutoSetTime, @@ -365,8 +355,7 @@ public class ToolboxViewModel : Screen public bool RecruitmentShowPotential { get => _recruitmentShowPotential; - set - { + set { SetAndNotify(ref _recruitmentShowPotential, value); ConfigurationHelper.SetValue(ConfigurationKeys.RecruitmentShowPotential, value.ToString()); } @@ -504,8 +493,7 @@ public class ToolboxViewModel : Screen continue; } - DepotResultDate result = new() - { + DepotResultDate result = new() { Id = id, Name = ItemListHelper.GetItemName(id), Image = ItemListHelper.GetItemImage(id), @@ -613,8 +601,7 @@ public class ToolboxViewModel : Screen public List OperBoxDataArray { get => _operBoxDataArray; - set - { + set { SetAndNotify(ref _operBoxDataArray, value); _operBoxPotential = null; // reset } @@ -624,8 +611,7 @@ public class ToolboxViewModel : Screen public Dictionary? OperBoxPotential { - get - { + get { if (_operBoxPotential != null) { return _operBoxPotential; @@ -832,8 +818,7 @@ public class ToolboxViewModel : Screen } else { - exportList.Add(new OperBoxData.OperData() - { + exportList.Add(new OperBoxData.OperData() { Id = operId, Name = operName, Rarity = operInfo.Rarity, @@ -875,8 +860,7 @@ public class ToolboxViewModel : Screen public bool IsGachaInProgress { get => _isGachaInProgress; - set - { + set { if (!SetAndNotify(ref _isGachaInProgress, value)) { return; @@ -927,8 +911,7 @@ public class ToolboxViewModel : Screen public bool GachaShowDisclaimer { get => _gachaShowDisclaimer; - set - { + set { SetAndNotify(ref _gachaShowDisclaimer, value); } } @@ -938,8 +921,7 @@ public class ToolboxViewModel : Screen public bool GachaShowDisclaimerNoMore { get => _gachaShowDisclaimerNoMore; - set - { + set { SetAndNotify(ref _gachaShowDisclaimerNoMore, value); ConfigurationHelper.SetValue(ConfigurationKeys.GachaShowDisclaimerNoMore, value.ToString()); } @@ -976,8 +958,7 @@ public class ToolboxViewModel : Screen public bool Peeping { get => _peeping; - set - { + set { if (!SetAndNotify(ref _peeping, value)) { return; @@ -998,8 +979,7 @@ public class ToolboxViewModel : Screen public bool IsPeepInProgress { get => _isPeepInProgress; - set - { + set { if (!SetAndNotify(ref _isPeepInProgress, value)) { return; @@ -1032,15 +1012,12 @@ public class ToolboxViewModel : Screen public int PeepTargetFps { - get - { + get { return _peepTargetFps; } - set - { - value = value switch - { + set { + value = value switch { > 600 => 600, < 1 => 1, _ => value, @@ -1101,8 +1078,7 @@ public class ToolboxViewModel : Screen } _logger.Warning("Screenshot Semaphore Full, Reduce Target FPS count to {PeepTargetFps}", --PeepTargetFps); - _ = Execute.OnUIThreadAsync(() => - { + _ = Execute.OnUIThreadAsync(() => { Growl.Clear(); Growl.Warning($"Screenshot taking too long, reduce Target FPS to {PeepTargetFps}"); }); @@ -1128,8 +1104,7 @@ public class ToolboxViewModel : Screen return; } - await Execute.OnUIThreadAsync(() => - { + await Execute.OnUIThreadAsync(() => { _peepImageCache[index] = AsstProxy.WriteBgrToBitmap(frameData, _peepImageCache[index]); }); @@ -1250,8 +1225,7 @@ public class ToolboxViewModel : Screen public string MiniGameTaskName { get => _miniGameTaskName; - set - { + set { SetAndNotify(ref _miniGameTaskName, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.MiniGameTaskName, value); MiniGameTip = GetMiniGameTip(value); @@ -1262,8 +1236,7 @@ public class ToolboxViewModel : Screen public string MiniGameTip { - get - { + get { _miniGameTip ??= GetMiniGameTip(MiniGameTaskName); return _miniGameTip; } diff --git a/src/MaaWpfGui/ViewModels/UI/VersionUpdateViewModel.cs b/src/MaaWpfGui/ViewModels/UI/VersionUpdateViewModel.cs index df1e283689..095343ce33 100644 --- a/src/MaaWpfGui/ViewModels/UI/VersionUpdateViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/VersionUpdateViewModel.cs @@ -15,7 +15,6 @@ using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.IO; using System.IO.Compression; using System.Linq; @@ -83,8 +82,7 @@ public class VersionUpdateViewModel : Screen public string UpdateTag { get => _updateTag; - set - { + set { SetAndNotify(ref _updateTag, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.VersionName, value); } @@ -99,8 +97,7 @@ public class VersionUpdateViewModel : Screen /// public string UpdateInfo { - get - { + get { try { return AddContributorLink(_updateInfo); @@ -111,8 +108,7 @@ public class VersionUpdateViewModel : Screen } } - set - { + set { SetAndNotify(ref _updateInfo, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.VersionUpdateBody, value); } @@ -137,8 +133,7 @@ public class VersionUpdateViewModel : Screen public bool IsFirstBootAfterUpdate { get => _isFirstBootAfterUpdate; - set - { + set { SetAndNotify(ref _isFirstBootAfterUpdate, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.VersionUpdateIsFirstBoot, value.ToString()); } @@ -152,8 +147,7 @@ public class VersionUpdateViewModel : Screen public string UpdatePackageName { get => _updatePackageName; - set - { + set { SetAndNotify(ref _updatePackageName, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.VersionUpdatePackage, value); } @@ -293,8 +287,7 @@ public class VersionUpdateViewModel : Screen List deleteTasks = []; foreach (var dir in Directory.GetDirectories(extractDir)) { - deleteTasks.Add(Task.Run(() => - { + deleteTasks.Add(Task.Run(() => { try { FileSystem.DeleteDirectory(dir.Replace(extractDir, curDir), UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); @@ -466,8 +459,7 @@ public class VersionUpdateViewModel : Screen public bool DoNotShowUpdate { get => _doNotShowUpdate; - set - { + set { SetAndNotify(ref _doNotShowUpdate, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.VersionUpdateDoNotShowUpdate, value.ToString()); } @@ -554,8 +546,7 @@ public class VersionUpdateViewModel : Screen return checkRet; } - return source switch - { + return source switch { AppUpdateSource.MaaApi => await HandleUpdateFromMaaApi(), AppUpdateSource.MirrorChyan => await HandleUpdateFromMirrorChyan(), _ => CheckUpdateRetT.UnknownError, @@ -877,8 +868,7 @@ public class VersionUpdateViewModel : Screen return CheckUpdateRetT.FailedToGetInfo; } - string versionType = SettingsViewModel.VersionUpdateSettings.VersionType switch - { + string versionType = SettingsViewModel.VersionUpdateSettings.VersionType switch { VersionUpdateSettingsUserControlModel.UpdateVersionType.Beta => "beta", VersionUpdateSettingsUserControlModel.UpdateVersionType.Nightly => "alpha", _ => "stable", @@ -975,8 +965,7 @@ public class VersionUpdateViewModel : Screen { var cdk = SettingsViewModel.VersionUpdateSettings.MirrorChyanCdk.Trim(); var arch = IsArm ? "arm64" : "x64"; - string channel = SettingsViewModel.VersionUpdateSettings.VersionType switch - { + string channel = SettingsViewModel.VersionUpdateSettings.VersionType switch { VersionUpdateSettingsUserControlModel.UpdateVersionType.Beta => "beta", VersionUpdateSettingsUserControlModel.UpdateVersionType.Nightly => "alpha", _ => "stable", diff --git a/src/MaaWpfGui/ViewModels/UserControl/Settings/AchievementSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/Settings/AchievementSettingsUserControlModel.cs index fa0f154a77..582c071e53 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/Settings/AchievementSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/AchievementSettingsUserControlModel.cs @@ -54,8 +54,7 @@ public class AchievementSettingsUserControlModel : PropertyChangedBase if (success) { - var growlInfo = new GrowlInfo - { + var growlInfo = new GrowlInfo { IsCustom = true, Message = $"{LocalizationHelper.GetString("AchievementBackupSuccess")} {Path.Combine(selectedPath, fileName)}.json", StaysOpen = true, @@ -70,8 +69,7 @@ public class AchievementSettingsUserControlModel : PropertyChangedBase public void RestoreAchievements() { - var dlg = new Microsoft.Win32.OpenFileDialog - { + var dlg = new Microsoft.Win32.OpenFileDialog { Filter = "JSON|*.json", InitialDirectory = PathsHelper.BaseDir, }; @@ -114,12 +112,10 @@ public class AchievementSettingsUserControlModel : PropertyChangedBase if (_achievementsWindow is null) { _achievementsWindow = new AchievementListWindow(); - _achievementsWindow.Loaded += (_, _) => - { + _achievementsWindow.Loaded += (_, _) => { WindowManager.MoveWindowToRootCenter(_achievementsWindow); }; - _achievementsWindow.Closed += (_, _) => - { + _achievementsWindow.Closed += (_, _) => { _achievementsWindow = null; }; } @@ -210,8 +206,7 @@ public class AchievementSettingsUserControlModel : PropertyChangedBase public bool AchievementPopupDisabled { get => _achievementPopupDisabled; - set - { + set { SetAndNotify(ref _achievementPopupDisabled, value); ConfigurationHelper.SetValue(ConfigurationKeys.AchievementPopupDisabled, value.ToString()); } @@ -225,8 +220,7 @@ public class AchievementSettingsUserControlModel : PropertyChangedBase public bool AchievementPopupAutoClose { get => _achievementPopupAutoClose; - set - { + set { SetAndNotify(ref _achievementPopupAutoClose, value); ConfigurationHelper.SetValue(ConfigurationKeys.AchievementPopupAutoClose, value.ToString()); } diff --git a/src/MaaWpfGui/ViewModels/UserControl/Settings/BackgroundSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/Settings/BackgroundSettingsUserControlModel.cs index cfa2cab258..c0e9d51a7e 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/Settings/BackgroundSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/BackgroundSettingsUserControlModel.cs @@ -41,8 +41,7 @@ public class BackgroundSettingsUserControlModel : PropertyChangedBase public string BackgroundImagePath { get => _backgroundImagePath; - set - { + set { SetAndNotify(ref _backgroundImagePath, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.BackgroundImagePath, value); BackgroundImage = RefreshBackgroundImage(value); @@ -53,8 +52,7 @@ public class BackgroundSettingsUserControlModel : PropertyChangedBase public void SelectImagePath() { - var dialog = new OpenFileDialog - { + var dialog = new OpenFileDialog { Filter = "Image|*.jpg;*.png", }; @@ -69,8 +67,7 @@ public class BackgroundSettingsUserControlModel : PropertyChangedBase public BitmapImage? BackgroundImage { get => _backgroundImage; - set - { + set { SetAndNotify(ref _backgroundImage, value); } } @@ -80,8 +77,7 @@ public class BackgroundSettingsUserControlModel : PropertyChangedBase public Stretch BackgroundImageStretchMode { get => _backgroundImageStretchMode; - set - { + set { SetAndNotify(ref _backgroundImageStretchMode, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.BackgroundImageStretchMode, value.ToString()); } @@ -126,8 +122,7 @@ public class BackgroundSettingsUserControlModel : PropertyChangedBase public int BackgroundOpacity { get => _backgroundOpacity; - set - { + set { SetAndNotify(ref _backgroundOpacity, value); } } @@ -137,8 +132,7 @@ public class BackgroundSettingsUserControlModel : PropertyChangedBase public int BackgroundBlurEffectRadius { get => _backgroundBlurEffectRadius; - set - { + set { SetAndNotify(ref _backgroundBlurEffectRadius, value); } } diff --git a/src/MaaWpfGui/ViewModels/UserControl/Settings/ConnectSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/Settings/ConnectSettingsUserControlModel.cs index 67846fd7ae..f6b6333399 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/Settings/ConnectSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/ConnectSettingsUserControlModel.cs @@ -90,8 +90,7 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase public bool AutoDetectConnection { get => _autoDetectConnection; - set - { + set { if (!SetAndNotify(ref _autoDetectConnection, value)) { return; @@ -111,8 +110,7 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase public bool AlwaysAutoDetectConnection { get => _alwaysAutoDetectConnection; - set - { + set { SetAndNotify(ref _alwaysAutoDetectConnection, value); ConfigurationHelper.SetValue(ConfigurationKeys.AlwaysAutoDetect, value.ToString()); } @@ -134,8 +132,7 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase public string ConnectAddress { get => _connectAddress; - set - { + set { value = value .Replace(" ", string.Empty) .Replace(":", ":") @@ -195,8 +192,7 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase public string AdbPath { get => _adbPath; - set - { + set { if (!Path.GetFileName(value).ToLower().Contains("adb")) { var count = 3; @@ -231,8 +227,7 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase public string ConnectConfig { get => _connectConfig; - set - { + set { Instances.AsstProxy.Connected = false; SetAndNotify(ref _connectConfig, value); ConfigurationHelper.SetValue(ConfigurationKeys.ConnectConfig, value); @@ -259,8 +254,7 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase public bool Enable { get => _enable; - set - { + set { if (!SetAndNotify(ref _enable, value)) { return; @@ -344,8 +338,7 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase public string EmulatorPath { get => _emulatorPath; - set - { + set { if (_enable && !string.IsNullOrEmpty(value) && !Directory.Exists(value)) { MessageBoxHelper.Show(LocalizationHelper.GetString("MuMuEmulatorPathNotFound")); @@ -378,8 +371,7 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase public bool MuMuBridgeConnection { get => _mumuBridgeConnection; - set - { + set { if (_mumuBridgeConnection == value) { return; @@ -414,8 +406,7 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase public string Index { get => _index; - set - { + set { Instances.AsstProxy.Connected = false; SetAndNotify(ref _index, value); ConfigurationHelper.SetValue(ConfigurationKeys.MuMu12Index, value); @@ -424,15 +415,13 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase public string Config { - get - { + get { if (!Enable) { return JsonConvert.SerializeObject(new JObject()); } - var configObject = new JObject - { + var configObject = new JObject { ["path"] = EmulatorPath, }; @@ -455,8 +444,7 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase public bool Enable { get => _enable; - set - { + set { if (!SetAndNotify(ref _enable, value)) { return; @@ -524,8 +512,7 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase public string EmulatorPath { get => _emulatorPath; - set - { + set { if (_enable && !string.IsNullOrEmpty(value) && !Directory.Exists(value)) { MessageBoxHelper.Show(LocalizationHelper.GetString("LdPlayerEmulatorPathNotFound")); @@ -556,8 +543,7 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase public bool ManualSetIndex { get => _manualSetIndex; - set - { + set { if (_manualSetIndex == value) { return; @@ -582,8 +568,7 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase public string Index { get => _index; - set - { + set { Instances.AsstProxy.Connected = false; SetAndNotify(ref _index, value); ConfigurationHelper.SetValue(ConfigurationKeys.LdPlayerIndex, value); @@ -598,8 +583,7 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase return 0; } - var startInfo = new ProcessStartInfo - { + var startInfo = new ProcessStartInfo { FileName = emulatorPath, Arguments = "list2", RedirectStandardOutput = true, @@ -667,8 +651,7 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase public string Config { - get - { + get { if (!Enable) { return JsonConvert.SerializeObject(new JObject()); @@ -684,8 +667,7 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase index = GetEmulatorIndex(SettingsViewModel.ConnectSettings.ConnectAddress); } - var configObject = new JObject - { + var configObject = new JObject { ["path"] = EmulatorPath, ["index"] = index, ["pid"] = GetEmulatorPid(index), @@ -706,8 +688,7 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase public bool RetryOnDisconnected { get => _retryOnDisconnected; - set - { + set { if (string.IsNullOrEmpty(SettingsViewModel.StartSettings.EmulatorPath)) { MessageBoxHelper.Show( @@ -731,8 +712,7 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase public bool AllowAdbRestart { get => _allowAdbRestart; - set - { + set { SetAndNotify(ref _allowAdbRestart, value); ConfigurationHelper.SetValue(ConfigurationKeys.AllowAdbRestart, value.ToString()); } @@ -746,8 +726,7 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase public bool AllowAdbHardRestart { get => _allowAdbHardRestart; - set - { + set { SetAndNotify(ref _allowAdbHardRestart, value); ConfigurationHelper.SetValue(ConfigurationKeys.AllowAdbHardRestart, value.ToString()); } @@ -758,8 +737,7 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase public bool AdbLiteEnabled { get => _adbLiteEnabled; - set - { + set { SetAndNotify(ref _adbLiteEnabled, value); ConfigurationHelper.SetValue(ConfigurationKeys.AdbLiteEnabled, value.ToString()); UpdateInstanceSettings(); @@ -771,8 +749,7 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase public bool KillAdbOnExit { get => _killAdbOnExit; - set - { + set { SetAndNotify(ref _killAdbOnExit, value); ConfigurationHelper.SetValue(ConfigurationKeys.KillAdbOnExit, value.ToString()); UpdateInstanceSettings(); @@ -983,26 +960,21 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase double contentHeight = contentWidth * 9.0 / 16.0; double totalWindowHeight = contentHeight + (nc.Top + nc.Bottom + rb.Top + rb.Bottom); - _imagePopupWindow = new() - { + _imagePopupWindow = new() { Width = TotalWindowWidth, Height = totalWindowHeight, - Content = new Image - { + Content = new Image { Source = TestLinkImage, }, }; - _imagePopupWindow.Loaded += (_, _) => - { + _imagePopupWindow.Loaded += (_, _) => { WindowManager.MoveWindowToRootCenter(_imagePopupWindow); }; - _imagePopupWindow.Closed += (_, _) => - { + _imagePopupWindow.Closed += (_, _) => { _imagePopupWindow = null; }; var img = (Image)_imagePopupWindow.Content; - img.MouseLeftButtonUp += (_, _) => - { + img.MouseLeftButtonUp += (_, _) => { _ = TestLinkAndGetImage(); }; } @@ -1088,8 +1060,7 @@ public class ConnectSettingsUserControlModel : PropertyChangedBase public string TouchMode { get => _touchMode; - set - { + set { SetAndNotify(ref _touchMode, value); UpdateInstanceSettings(); ConfigurationHelper.SetValue(ConfigurationKeys.TouchMode, value); diff --git a/src/MaaWpfGui/ViewModels/UserControl/Settings/ExternalNotificationSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/Settings/ExternalNotificationSettingsUserControlModel.cs index 4fc973e6e6..d95a65df60 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/Settings/ExternalNotificationSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/ExternalNotificationSettingsUserControlModel.cs @@ -50,8 +50,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public bool ExternalNotificationSendWhenComplete { get => _externalNotificationSendWhenComplete; - set - { + set { SetAndNotify(ref _externalNotificationSendWhenComplete, value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationSendWhenComplete, value.ToString()); } @@ -62,8 +61,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public bool ExternalNotificationEnableDetails { get => _externalNotificationEnableDetails; - set - { + set { SetAndNotify(ref _externalNotificationEnableDetails, value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationEnableDetails, value.ToString()); } @@ -74,8 +72,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public bool ExternalNotificationSendWhenError { get => _externalNotificationSendWhenError; - set - { + set { SetAndNotify(ref _externalNotificationSendWhenError, value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationSendWhenError, value.ToString()); } @@ -86,8 +83,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public bool ExternalNotificationSendWhenTimeout { get => _externalNotificationSendWhenTimeout; - set - { + set { SetAndNotify(ref _externalNotificationSendWhenTimeout, value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationSendWhenTimeout, value.ToString()); } @@ -118,8 +114,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public object[] EnabledExternalNotificationProviders { get => _enabledExternalNotificationProviders; - set - { + set { SetAndNotify(ref _enabledExternalNotificationProviders, value); var validProviders = value .Where(provider => ExternalNotificationProviders.Contains(provider.ToString() ?? string.Empty)) @@ -235,8 +230,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public string ServerChanSendKey { get => _serverChanSendKey; - set - { + set { SetAndNotify(ref _serverChanSendKey, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationServerChanSendKey, value); @@ -248,8 +242,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public string BarkSendKey { get => _barkSendKey; - set - { + set { SetAndNotify(ref _barkSendKey, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationBarkSendKey, value); @@ -261,8 +254,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public string BarkServer { get => _barkServer; - set - { + set { SetAndNotify(ref _barkServer, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationBarkServer, value); @@ -274,8 +266,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public string SmtpServer { get => _smtpServer; - set - { + set { SetAndNotify(ref _smtpServer, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationSmtpServer, value); @@ -287,8 +278,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public string SmtpPort { get => _smtpPort; - set - { + set { SetAndNotify(ref _smtpPort, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationSmtpPort, value); @@ -300,8 +290,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public string SmtpUser { get => _smtpUser; - set - { + set { SetAndNotify(ref _smtpUser, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationSmtpUser, value); @@ -313,8 +302,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public string SmtpPassword { get => _smtpPassword; - set - { + set { SetAndNotify(ref _smtpPassword, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationSmtpPassword, value); @@ -326,8 +314,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public string SmtpFrom { get => _smtpFrom; - set - { + set { SetAndNotify(ref _smtpFrom, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationSmtpFrom, value); @@ -339,8 +326,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public string SmtpTo { get => _smtpTo; - set - { + set { SetAndNotify(ref _smtpTo, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationSmtpTo, value); @@ -352,8 +338,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public bool SmtpUseSsl { get => _smtpUseSsl; - set - { + set { SetAndNotify(ref _smtpUseSsl, value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationSmtpUseSsl, value.ToString()); } @@ -364,8 +349,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public bool SmtpRequireAuthentication { get => _smtpRequireAuthentication; - set - { + set { SetAndNotify(ref _smtpRequireAuthentication, value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationSmtpRequiresAuthentication, value.ToString()); } @@ -376,8 +360,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public string DiscordBotToken { get => _discordBotToken; - set - { + set { SetAndNotify(ref _discordBotToken, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationDiscordBotToken, value); @@ -389,8 +372,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public string DiscordUserId { get => _discordUserId; - set - { + set { SetAndNotify(ref _discordUserId, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationDiscordUserId, value); @@ -402,8 +384,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public string DiscordWebhookUrl { get => _discordWebhookUrl; - set - { + set { SetAndNotify(ref _discordWebhookUrl, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationDiscordWebhookUrl, value); @@ -415,8 +396,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public string DingTalkAccessToken { get => _dingTalkAccessToken; - set - { + set { SetAndNotify(ref _dingTalkAccessToken, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationDingTalkAccessToken, value); @@ -428,8 +408,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public string DingTalkSecret { get => _dingTalkSecret; - set - { + set { SetAndNotify(ref _dingTalkSecret, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationDingTalkSecret, value); @@ -441,8 +420,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public string TelegramBotToken { get => _telegramBotToken; - set - { + set { SetAndNotify(ref _telegramBotToken, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationTelegramBotToken, value); @@ -454,8 +432,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public string TelegramChatId { get => _telegramChatId; - set - { + set { SetAndNotify(ref _telegramChatId, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationTelegramChatId, value); @@ -467,8 +444,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public string TelegramTopicId { get => _telegramTopicId; - set - { + set { SetAndNotify(ref _telegramTopicId, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationTelegramTopicId, value); @@ -480,8 +456,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public string QmsgServer { get => _qmsgServer; - set - { + set { SetAndNotify(ref _qmsgServer, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationQmsgServer, value); @@ -493,8 +468,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public string QmsgKey { get => _qmsgKey; - set - { + set { SetAndNotify(ref _qmsgKey, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationQmsgKey, value); @@ -506,8 +480,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public string QmsgUser { get => _qmsgUser; - set - { + set { SetAndNotify(ref _qmsgUser, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationQmsgUser, value); @@ -519,8 +492,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public string QmsgBot { get => _qmsgBot; - set - { + set { SetAndNotify(ref _qmsgBot, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationQmsgBot, value); @@ -532,8 +504,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public string CustomWebhookUrl { get => _customWebhookUrl; - set - { + set { SetAndNotify(ref _customWebhookUrl, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationCustomWebhookUrl, value); @@ -545,8 +516,7 @@ public class ExternalNotificationSettingsUserControlModel : PropertyChangedBase public string CustomWebhookBody { get => _customWebhookBody; - set - { + set { SetAndNotify(ref _customWebhookBody, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.ExternalNotificationCustomWebhookBody, value); diff --git a/src/MaaWpfGui/ViewModels/UserControl/Settings/GameSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/Settings/GameSettingsUserControlModel.cs index 8f5c92c25f..58fd65dade 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/Settings/GameSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/GameSettingsUserControlModel.cs @@ -49,8 +49,7 @@ public class GameSettingsUserControlModel : PropertyChangedBase public bool StartGame { get => _startGame; - set - { + set { SetAndNotify(ref _startGame, value); ConfigurationHelper.SetValue(ConfigurationKeys.StartGame, value.ToString()); } @@ -76,8 +75,7 @@ public class GameSettingsUserControlModel : PropertyChangedBase /// public string ClientType { - get - { // v5.19.0-beta.1 + get { // v5.19.0-beta.1 if (!string.IsNullOrEmpty(_clientType)) { return _clientType; @@ -87,8 +85,7 @@ public class GameSettingsUserControlModel : PropertyChangedBase return "Official"; } - set - { + set { var oldValue = _clientType; if (!SetAndNotify(ref _clientType, value)) { @@ -105,8 +102,7 @@ public class GameSettingsUserControlModel : PropertyChangedBase return; } - Task.Run(() => - { + Task.Run(() => { Instances.AsstProxy.LoadResource(); }); @@ -131,8 +127,7 @@ public class GameSettingsUserControlModel : PropertyChangedBase public bool DeploymentWithPause { get => _deploymentWithPause; - set - { + set { SetAndNotify(ref _deploymentWithPause, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeDeploymentWithPause, value.ToString()); SettingsViewModel.ConnectSettings.UpdateInstanceSettings(); @@ -144,8 +139,7 @@ public class GameSettingsUserControlModel : PropertyChangedBase public string StartsWithScript { get => _startsWithScript; - set - { + set { SetAndNotify(ref _startsWithScript, value); ConfigurationHelper.SetValue(ConfigurationKeys.StartsWithScript, value); } @@ -156,8 +150,7 @@ public class GameSettingsUserControlModel : PropertyChangedBase public string EndsWithScript { get => _endsWithScript; - set - { + set { SetAndNotify(ref _endsWithScript, value); ConfigurationHelper.SetValue(ConfigurationKeys.EndsWithScript, value); } @@ -168,8 +161,7 @@ public class GameSettingsUserControlModel : PropertyChangedBase public bool CopilotWithScript { get => _copilotWithScript; - set - { + set { SetAndNotify(ref _copilotWithScript, value); ConfigurationHelper.SetValue(ConfigurationKeys.CopilotWithScript, value.ToString()); } @@ -180,8 +172,7 @@ public class GameSettingsUserControlModel : PropertyChangedBase public bool ManualStopWithScript { get => _manualStopWithScript; - set - { + set { SetAndNotify(ref _manualStopWithScript, value); ConfigurationHelper.SetValue(ConfigurationKeys.ManualStopWithScript, value.ToString()); } @@ -189,8 +180,7 @@ public class GameSettingsUserControlModel : PropertyChangedBase public void RunScript(string str, bool showLog = true) { - bool enable = str switch - { + bool enable = str switch { "StartsWithScript" => !string.IsNullOrWhiteSpace(StartsWithScript), "EndsWithScript" => !string.IsNullOrWhiteSpace(EndsWithScript), _ => false, @@ -201,8 +191,7 @@ public class GameSettingsUserControlModel : PropertyChangedBase return; } - Func func = str switch - { + Func func = str switch { "StartsWithScript" => () => ExecuteScript(StartsWithScript), "EndsWithScript" => () => ExecuteScript(EndsWithScript), _ => () => false, @@ -270,10 +259,8 @@ public class GameSettingsUserControlModel : PropertyChangedBase arguments = arguments.Replace("-minimized", string.Empty).Trim(); } - var process = new Process - { - StartInfo = new ProcessStartInfo - { + var process = new Process { + StartInfo = new ProcessStartInfo { FileName = fileName, Arguments = arguments, WindowStyle = minimized ? ProcessWindowStyle.Minimized : ProcessWindowStyle.Normal, @@ -296,8 +283,7 @@ public class GameSettingsUserControlModel : PropertyChangedBase public bool BlockSleep { get => _blockSleep; - set - { + set { SetAndNotify(ref _blockSleep, value); SleepManagement.SetBlockSleep(value); ConfigurationHelper.SetValue(ConfigurationKeys.BlockSleep, value.ToString()); @@ -309,8 +295,7 @@ public class GameSettingsUserControlModel : PropertyChangedBase public bool BlockSleepWithScreenOn { get => _blockSleepWithScreenOn; - set - { + set { SetAndNotify(ref _blockSleepWithScreenOn, value); SleepManagement.SetBlockSleepWithScreenOn(value); ConfigurationHelper.SetValue(ConfigurationKeys.BlockSleepWithScreenOn, value.ToString()); @@ -327,8 +312,7 @@ public class GameSettingsUserControlModel : PropertyChangedBase public string PenguinId { get => _penguinId; - set - { + set { SetAndNotify(ref _penguinId, value); ConfigurationHelper.SetValue(ConfigurationKeys.PenguinId, value); } @@ -342,8 +326,7 @@ public class GameSettingsUserControlModel : PropertyChangedBase public bool EnablePenguin { get => _enablePenguin; - set - { + set { SetAndNotify(ref _enablePenguin, value); ConfigurationHelper.SetValue(ConfigurationKeys.EnablePenguin, value.ToString()); } @@ -357,8 +340,7 @@ public class GameSettingsUserControlModel : PropertyChangedBase public bool EnableYituliu { get => _enableYituliu; - set - { + set { SetAndNotify(ref _enableYituliu, value); ConfigurationHelper.SetValue(ConfigurationKeys.EnableYituliu, value.ToString()); } @@ -373,8 +355,7 @@ public class GameSettingsUserControlModel : PropertyChangedBase public int TaskTimeoutMinutes { get => _taskTimeoutMinutes; - set - { + set { SetAndNotify(ref _taskTimeoutMinutes, value); _runningState.TaskTimeoutMinutes = value; ConfigurationHelper.SetValue(ConfigurationKeys.TaskTimeoutMinutes, value.ToString()); @@ -386,8 +367,7 @@ public class GameSettingsUserControlModel : PropertyChangedBase public int ReminderIntervalMinutes { get => _reminderIntervalMinutes; - set - { + set { SetAndNotify(ref _reminderIntervalMinutes, value); _runningState.ReminderIntervalMinutes = value; ConfigurationHelper.SetValue(ConfigurationKeys.ReminderIntervalMinutes, value.ToString()); diff --git a/src/MaaWpfGui/ViewModels/UserControl/Settings/GuiSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/Settings/GuiSettingsUserControlModel.cs index 35428fc2df..e42b37c13b 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/Settings/GuiSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/GuiSettingsUserControlModel.cs @@ -78,8 +78,7 @@ public class GuiSettingsUserControlModel : PropertyChangedBase public bool UseTray { get => _useTray; - set - { + set { if (!value) { MinimizeToTray = false; @@ -99,8 +98,7 @@ public class GuiSettingsUserControlModel : PropertyChangedBase public bool MinimizeToTray { get => _minimizeToTray; - set - { + set { SetAndNotify(ref _minimizeToTray, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.MinimizeToTray, value.ToString()); Instances.MainWindowManager.SetMinimizeToTray(value); @@ -115,8 +113,7 @@ public class GuiSettingsUserControlModel : PropertyChangedBase public bool WindowTitleScrollable { get => _windowTitleScrollable; - set - { + set { SetAndNotify(ref _windowTitleScrollable, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.WindowTitleScrollable, value.ToString()); var rvm = (RootViewModel)Instances.SettingsViewModel.Parent; @@ -132,8 +129,7 @@ public class GuiSettingsUserControlModel : PropertyChangedBase public bool HideCloseButton { get => _hideCloseButton; - set - { + set { SetAndNotify(ref _hideCloseButton, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.HideCloseButton, value.ToString()); var rvm = (RootViewModel)Instances.SettingsViewModel.Parent; @@ -147,8 +143,7 @@ public class GuiSettingsUserControlModel : PropertyChangedBase public bool UseNotify { get => ConfigFactory.Root.GUI.UseNotify; - set - { + set { ConfigFactory.Root.GUI.UseNotify = value; NotifyOfPropertyChange(); if (value) @@ -161,8 +156,7 @@ public class GuiSettingsUserControlModel : PropertyChangedBase public bool MainTasksInvertNullFunction { get => ConfigFactory.Root.GUI.MainTasksInvertNullFunction; - set - { + set { ConfigFactory.Root.GUI.MainTasksInvertNullFunction = value; NotifyOfPropertyChange(); } @@ -184,8 +178,7 @@ public class GuiSettingsUserControlModel : PropertyChangedBase public string LogItemDateFormatString { get => _logItemDateFormatString; - set - { + set { SetAndNotify(ref _logItemDateFormatString, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.LogItemDateFormat, value); } @@ -197,8 +190,7 @@ public class GuiSettingsUserControlModel : PropertyChangedBase public DarkModeType DarkMode { get => ConfigFactory.Root.GUI.DarkMode; - set - { + set { ConfigFactory.Root.GUI.DarkMode = value; NotifyOfPropertyChange(); SwitchDarkMode(); @@ -249,8 +241,7 @@ public class GuiSettingsUserControlModel : PropertyChangedBase public string InverseClearMode { get => _inverseClearMode.ToString(); - set - { + set { if (!Enum.TryParse(value, out InverseClearType tempEnumValue)) { return; @@ -302,8 +293,7 @@ public class GuiSettingsUserControlModel : PropertyChangedBase public object[] WindowTitleSelectShowList { get => _windowTitleSelectShowList; - set - { + set { SetAndNotify(ref _windowTitleSelectShowList, value); Instances.SettingsViewModel.UpdateWindowTitle(); var config = string.Join(' ', _windowTitleSelectShowList.Cast>().Select(pair => pair.Key).ToList()); @@ -319,8 +309,7 @@ public class GuiSettingsUserControlModel : PropertyChangedBase public string Language { get => _language; - set - { + set { if (value == _language) { return; @@ -375,8 +364,7 @@ public class GuiSettingsUserControlModel : PropertyChangedBase /// public string LanguageInfo { - get - { + get { var language = (string?)Application.Current.Resources["Language"]; return language == "Language" ? language : language + " / Language"; } @@ -389,8 +377,7 @@ public class GuiSettingsUserControlModel : PropertyChangedBase public string OperNameLanguage { - get - { + get { if (!_operNameLanguage.Contains('.')) { return _operNameLanguage; @@ -405,8 +392,7 @@ public class GuiSettingsUserControlModel : PropertyChangedBase return "OperNameLanguageForce"; } - set - { + set { if (value == _operNameLanguage.Split('.')[0]) { return; @@ -451,8 +437,7 @@ public class GuiSettingsUserControlModel : PropertyChangedBase public string OperNameLocalization { - get - { + get { if (_operNameLanguage == "OperNameLanguageClient") { return DataHelper.ClientLanguageMapper[SettingsViewModel.GameSettings.ClientType]; diff --git a/src/MaaWpfGui/ViewModels/UserControl/Settings/IssueReportUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/Settings/IssueReportUserControlModel.cs index e3fb7cb54e..bbf5291dfe 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/Settings/IssueReportUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/IssueReportUserControlModel.cs @@ -236,8 +236,7 @@ public class IssueReportUserControlModel : PropertyChangedBase private static void ShowGrowl(string message) { - var growlInfo = new GrowlInfo - { + var growlInfo = new GrowlInfo { IsCustom = true, Message = message, IconKey = "HangoverGeometry", diff --git a/src/MaaWpfGui/ViewModels/UserControl/Settings/PerformanceUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/Settings/PerformanceUserControlModel.cs index 4c81309829..228cb05123 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/Settings/PerformanceUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/PerformanceUserControlModel.cs @@ -36,8 +36,7 @@ public class PerformanceUserControlModel : PropertyChangedBase public GpuOption ActiveGpuOption { get => GpuOption.GetCurrent(); - set - { + set { GpuOption.SetCurrent(value); SettingsViewModel.AskRestartToApplySettings(); } @@ -46,8 +45,7 @@ public class PerformanceUserControlModel : PropertyChangedBase public bool AllowDeprecatedGpu { get => GpuOption.AllowDeprecatedGpu; - set - { + set { GpuOption.AllowDeprecatedGpu = value; NotifyOfPropertyChange(); } diff --git a/src/MaaWpfGui/ViewModels/UserControl/Settings/RemoteControlUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/Settings/RemoteControlUserControlModel.cs index ad50f17517..3548164940 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/Settings/RemoteControlUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/RemoteControlUserControlModel.cs @@ -36,8 +36,7 @@ public class RemoteControlUserControlModel : PropertyChangedBase public string RemoteControlGetTaskEndpointUri { get => _remoteControlGetTaskEndpointUri; - set - { + set { if (!SetAndNotify(ref _remoteControlGetTaskEndpointUri, value)) { return; @@ -54,8 +53,7 @@ public class RemoteControlUserControlModel : PropertyChangedBase public string RemoteControlReportStatusUri { get => _remoteControlReportStatusUri; - set - { + set { SetAndNotify(ref _remoteControlReportStatusUri, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.RemoteControlReportStatusUri, value); @@ -67,8 +65,7 @@ public class RemoteControlUserControlModel : PropertyChangedBase public string RemoteControlUserIdentity { get => _remoteControlUserIdentity; - set - { + set { SetAndNotify(ref _remoteControlUserIdentity, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.RemoteControlUserIdentity, value); @@ -80,8 +77,7 @@ public class RemoteControlUserControlModel : PropertyChangedBase public string RemoteControlDeviceIdentity { get => _remoteControlDeviceIdentity; - set - { + set { SetAndNotify(ref _remoteControlDeviceIdentity, value); value = SimpleEncryptionHelper.Encrypt(value); ConfigurationHelper.SetValue(ConfigurationKeys.RemoteControlDeviceIdentity, value); @@ -93,8 +89,7 @@ public class RemoteControlUserControlModel : PropertyChangedBase public int RemoteControlPollIntervalMs { get => _remoteControlPollIntervalMs; - set - { + set { if (!SetAndNotify(ref _remoteControlPollIntervalMs, value)) { return; diff --git a/src/MaaWpfGui/ViewModels/UserControl/Settings/StartSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/Settings/StartSettingsUserControlModel.cs index 5123289b6a..39cd9ed18c 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/Settings/StartSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/StartSettingsUserControlModel.cs @@ -62,8 +62,7 @@ public class StartSettingsUserControlModel : PropertyChangedBase public bool StartSelf { get => _startSelf; - set - { + set { if (!AutoStart.SetStart(value, out var error)) { _logger.Error("Failed to set startup: {Error}", error); @@ -83,8 +82,7 @@ public class StartSettingsUserControlModel : PropertyChangedBase public bool RunDirectly { get => _runDirectly; - set - { + set { SetAndNotify(ref _runDirectly, value); ConfigurationHelper.SetValue(ConfigurationKeys.RunDirectly, value.ToString()); } @@ -98,8 +96,7 @@ public class StartSettingsUserControlModel : PropertyChangedBase public bool MinimizeDirectly { get => _minimizeDirectly; - set - { + set { SetAndNotify(ref _minimizeDirectly, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.MinimizeDirectly, value.ToString()); } @@ -113,8 +110,7 @@ public class StartSettingsUserControlModel : PropertyChangedBase public bool OpenEmulatorAfterLaunch { get => _openEmulatorAfterLaunch; - set - { + set { if (string.IsNullOrEmpty(SettingsViewModel.StartSettings.EmulatorPath)) { MessageBoxHelper.Show( @@ -142,8 +138,7 @@ public class StartSettingsUserControlModel : PropertyChangedBase public string EmulatorPath { get => _emulatorPath; - set - { + set { value = value.Trim(); // 这里不用 SetAndNotify 判断 @@ -198,8 +193,7 @@ public class StartSettingsUserControlModel : PropertyChangedBase public string EmulatorAddCommand { get => _emulatorAddCommand; - set - { + set { SetAndNotify(ref _emulatorAddCommand, value); ConfigurationHelper.SetValue(ConfigurationKeys.EmulatorAddCommand, value); } @@ -213,8 +207,7 @@ public class StartSettingsUserControlModel : PropertyChangedBase public string EmulatorWaitSeconds { get => _emulatorWaitSeconds; - set - { + set { SetAndNotify(ref _emulatorWaitSeconds, value); ConfigurationHelper.SetValue(ConfigurationKeys.EmulatorWaitSeconds, value); } @@ -225,8 +218,7 @@ public class StartSettingsUserControlModel : PropertyChangedBase public bool BlockSleep { get => _blockSleep; - set - { + set { SetAndNotify(ref _blockSleep, value); SleepManagement.SetBlockSleep(value); ConfigurationHelper.SetValue(ConfigurationKeys.BlockSleep, value.ToString()); @@ -238,8 +230,7 @@ public class StartSettingsUserControlModel : PropertyChangedBase public bool BlockSleepWithScreenOn { get => _blockSleepWithScreenOn; - set - { + set { SetAndNotify(ref _blockSleepWithScreenOn, value); SleepManagement.SetBlockSleepWithScreenOn(value); ConfigurationHelper.SetValue(ConfigurationKeys.BlockSleepWithScreenOn, value.ToString()); @@ -334,10 +325,8 @@ public class StartSettingsUserControlModel : PropertyChangedBase try { var (fileName, arguments) = ResolveShortcut(EmulatorPath); - Process process = new Process - { - StartInfo = new ProcessStartInfo(fileName, arguments) - { + Process process = new Process { + StartInfo = new ProcessStartInfo(fileName, arguments) { UseShellExecute = false, }, }; @@ -397,8 +386,7 @@ public class StartSettingsUserControlModel : PropertyChangedBase return; } - ProcessStartInfo processStartInfo = new ProcessStartInfo - { + ProcessStartInfo processStartInfo = new ProcessStartInfo { FileName = "cmd.exe", RedirectStandardInput = true, RedirectStandardOutput = true, @@ -406,8 +394,7 @@ public class StartSettingsUserControlModel : PropertyChangedBase UseShellExecute = false, }; - Process process = new Process - { + Process process = new Process { StartInfo = processStartInfo, }; @@ -431,8 +418,7 @@ public class StartSettingsUserControlModel : PropertyChangedBase return; } - ProcessStartInfo processStartInfo = new ProcessStartInfo - { + ProcessStartInfo processStartInfo = new ProcessStartInfo { FileName = "cmd.exe", RedirectStandardInput = true, RedirectStandardOutput = true, @@ -510,8 +496,7 @@ public class StartSettingsUserControlModel : PropertyChangedBase [UsedImplicitly] public void SelectEmulatorExec() { - var dialog = new OpenFileDialog - { + var dialog = new OpenFileDialog { Filter = LocalizationHelper.GetString("Executable") + "|*.exe;*.bat;*.lnk", }; diff --git a/src/MaaWpfGui/ViewModels/UserControl/Settings/TimerSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/Settings/TimerSettingsUserControlModel.cs index 6f75b0522a..81710bbdb9 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/Settings/TimerSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/TimerSettingsUserControlModel.cs @@ -39,8 +39,7 @@ public class TimerSettingsUserControlModel : PropertyChangedBase public bool ForceScheduledStart { get => _forceScheduledStart; - set - { + set { SetAndNotify(ref _forceScheduledStart, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.ForceScheduledStart, value.ToString()); } @@ -54,8 +53,7 @@ public class TimerSettingsUserControlModel : PropertyChangedBase public bool ShowWindowBeforeForceScheduledStart { get => _showWindowBeforeForceScheduledStart; - set - { + set { SetAndNotify(ref _showWindowBeforeForceScheduledStart, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.ShowWindowBeforeForceScheduledStart, value.ToString()); } @@ -69,8 +67,7 @@ public class TimerSettingsUserControlModel : PropertyChangedBase public bool CustomConfig { get => _customConfig; - set - { + set { SetAndNotify(ref _customConfig, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.CustomConfig, value.ToString()); } @@ -112,8 +109,7 @@ public class TimerSettingsUserControlModel : PropertyChangedBase public bool? IsOn { get => _isOn; - set - { + set { SetAndNotify(ref _isOn, value); ConfigurationHelper.SetTimer(TimerId, value.ToString()); } @@ -127,8 +123,7 @@ public class TimerSettingsUserControlModel : PropertyChangedBase public int Hour { get => _hour; - set - { + set { SetAndNotify(ref _hour, value); ConfigurationHelper.SetTimerHour(TimerId, _hour.ToString()); } @@ -142,8 +137,7 @@ public class TimerSettingsUserControlModel : PropertyChangedBase public int Min { get => _min; - set - { + set { SetAndNotify(ref _min, value); ConfigurationHelper.SetTimerMin(TimerId, _min.ToString()); } @@ -157,8 +151,7 @@ public class TimerSettingsUserControlModel : PropertyChangedBase public string? TimerConfig { get => _timerConfig; - set - { + set { SetAndNotify(ref _timerConfig, value ?? ConfigurationHelper.GetCurrentConfiguration()); ConfigurationHelper.SetTimerConfig(TimerId, _timerConfig); } diff --git a/src/MaaWpfGui/ViewModels/UserControl/Settings/VersionUpdateSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/Settings/VersionUpdateSettingsUserControlModel.cs index 2249a65d00..88ec24cca9 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/Settings/VersionUpdateSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/Settings/VersionUpdateSettingsUserControlModel.cs @@ -100,8 +100,7 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase public string NewResourceFoundInfo { get => _newResourceFoundInfo; - set - { + set { SetAndNotify(ref _newResourceFoundInfo, value); Instances.SettingsViewModel.UpdateWindowTitle(); } @@ -112,8 +111,7 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase public string NewVersionFoundInfo { get => _newVersionFoundInfo; - set - { + set { SetAndNotify(ref _newVersionFoundInfo, value); Instances.SettingsViewModel.UpdateWindowTitle(); } @@ -219,8 +217,7 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase public UpdateVersionType VersionType { get => _versionType; - set - { + set { SetAndNotify(ref _versionType, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.VersionType, value.ToString()); } @@ -248,8 +245,7 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase public bool HasAcknowledgedNightlyWarning { get => _hasAcknowledgedNightlyWarning; - set - { + set { SetAndNotify(ref _hasAcknowledgedNightlyWarning, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.HasAcknowledgedNightlyWarning, value.ToString()); } @@ -268,8 +264,7 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase public string UpdateSource { get => _updateSource; - set - { + set { SetAndNotify(ref _updateSource, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.UpdateSource, value); } @@ -280,8 +275,7 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase public bool ForceGithubGlobalSource { get => _forceGithubGlobalSource; - set - { + set { SetAndNotify(ref _forceGithubGlobalSource, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.ForceGithubGlobalSource, value.ToString()); } @@ -292,8 +286,7 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase public string MirrorChyanCdk { get => _mirrorChyanCdk; - set - { + set { if (string.IsNullOrEmpty(value)) { MirrorChyanCdkExpiredTime = 0; @@ -306,8 +299,7 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase if (value.Length == 24) { - Task.Run(async () => - { + Task.Run(async () => { await Instances.VersionUpdateViewModel.VersionUpdateAndAskToRestartAsync(); await ResourceUpdater.ResourceUpdateAndReloadAsync(); }); @@ -325,8 +317,7 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase public long MirrorChyanCdkExpiredTime { get => _mirrorChyanCdkExpiredTime; - set - { + set { if (!SetAndNotify(ref _mirrorChyanCdkExpiredTime, value)) { return; @@ -375,8 +366,7 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase /// public string MirrorChyanCdkRemainingBrush { - get - { + get { if (IsMirrorChyanCdkExpired) { return UiLogColor.Error; @@ -417,8 +407,7 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase public bool StartupUpdateCheck { get => _startupUpdateCheck; - set - { + set { SetAndNotify(ref _startupUpdateCheck, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.StartupUpdateCheck, value.ToString()); } @@ -432,8 +421,7 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase public bool UpdateAutoCheck { get => _updateAutoCheck; - set - { + set { SetAndNotify(ref _updateAutoCheck, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.UpdateAutoCheck, value.ToString()); } @@ -447,8 +435,7 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase public string Proxy { get => _proxy; - set - { + set { SetAndNotify(ref _proxy, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.UpdateProxy, value); } @@ -465,8 +452,7 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase public string ProxyType { get => _proxyType; - set - { + set { SetAndNotify(ref _proxyType, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.ProxyType, value); } @@ -480,8 +466,7 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase public bool IsCheckingForUpdates { get => _isCheckingForUpdates; - set - { + set { SetAndNotify(ref _isCheckingForUpdates, value); } } @@ -494,8 +479,7 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase public bool AutoDownloadUpdatePackage { get => _autoDownloadUpdatePackage; - set - { + set { SetAndNotify(ref _autoDownloadUpdatePackage, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.AutoDownloadUpdatePackage, value.ToString()); } @@ -509,8 +493,7 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase public bool AutoInstallUpdatePackage { get => _autoInstallUpdatePackage; - set - { + set { SetAndNotify(ref _autoInstallUpdatePackage, value); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.AutoInstallUpdatePackage, value.ToString()); } @@ -531,8 +514,7 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase var ret = await Instances.VersionUpdateViewModel.CheckAndDownloadVersionUpdate(); - var toastMessage = ret switch - { + var toastMessage = ret switch { VersionUpdateViewModel.CheckUpdateRetT.NoNeedToUpdate => string.Empty, VersionUpdateViewModel.CheckUpdateRetT.NoNeedToUpdateDebugVersion => LocalizationHelper.GetString("NoNeedToUpdateDebugVersion"), VersionUpdateViewModel.CheckUpdateRetT.AlreadyLatest => LocalizationHelper.GetString("AlreadyLatest"), @@ -569,8 +551,7 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase IsCheckingForUpdates = true; var (ret, uri, releaseNote) = await ResourceUpdater.CheckFromMirrorChyanAsync(); - var toastMessage = ret switch - { + var toastMessage = ret switch { VersionUpdateViewModel.CheckUpdateRetT.AlreadyLatest => LocalizationHelper.GetString("AlreadyLatest"), VersionUpdateViewModel.CheckUpdateRetT.UnknownError => LocalizationHelper.GetString("NewVersionDetectFailedTitle"), VersionUpdateViewModel.CheckUpdateRetT.NetworkError => LocalizationHelper.GetString("CheckNetworking"), @@ -588,8 +569,7 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase return; } - bool success = UpdateSource switch - { + bool success = UpdateSource switch { "Github" => await ResourceUpdater.UpdateFromGithubAsync(), "MirrorChyan" => (ret == VersionUpdateViewModel.CheckUpdateRetT.OK) && await ResourceUpdater.DownloadFromMirrorChyanAsync(uri, releaseNote), _ => await ResourceUpdater.UpdateFromGithubAsync(), diff --git a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/AwardSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/AwardSettingsUserControlModel.cs index f64e225689..120ce25082 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/AwardSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/AwardSettingsUserControlModel.cs @@ -41,8 +41,7 @@ public class AwardSettingsUserControlModel : TaskViewModel public bool ReceiveAward { get => _receiveAward; - set - { + set { SetAndNotify(ref _receiveAward, value); ConfigurationHelper.SetValue(ConfigurationKeys.ReceiveAward, value.ToString()); } @@ -56,8 +55,7 @@ public class AwardSettingsUserControlModel : TaskViewModel public bool ReceiveMail { get => _receiveMail; - set - { + set { SetAndNotify(ref _receiveMail, value); ConfigurationHelper.SetValue(ConfigurationKeys.ReceiveMail, value.ToString()); } @@ -71,8 +69,7 @@ public class AwardSettingsUserControlModel : TaskViewModel public bool ReceiveFreeGacha { get => _receiveFreeGacha; - set - { + set { if (value) { var result = MessageBoxHelper.Show( @@ -102,8 +99,7 @@ public class AwardSettingsUserControlModel : TaskViewModel public bool ReceiveOrundum { get => _receiveOrundum; - set - { + set { SetAndNotify(ref _receiveOrundum, value); ConfigurationHelper.SetValue(ConfigurationKeys.ReceiveOrundum, value.ToString()); } @@ -117,8 +113,7 @@ public class AwardSettingsUserControlModel : TaskViewModel public bool ReceiveMining { get => _receiveMining; - set - { + set { SetAndNotify(ref _receiveMining, value); ConfigurationHelper.SetValue(ConfigurationKeys.ReceiveMining, value.ToString()); } @@ -132,8 +127,7 @@ public class AwardSettingsUserControlModel : TaskViewModel public bool ReceiveSpecialAccess { get => _receiveReceiveSpecialAccess; - set - { + set { SetAndNotify(ref _receiveReceiveSpecialAccess, value); ConfigurationHelper.SetValue(ConfigurationKeys.ReceiveSpecialAccess, value.ToString()); } @@ -141,8 +135,7 @@ public class AwardSettingsUserControlModel : TaskViewModel public override (AsstTaskType Type, JObject Params) Serialize() { - var task = new AsstAwardTask() - { + var task = new AsstAwardTask() { Award = ReceiveAward, Mail = ReceiveMail, FreeGacha = ReceiveFreeGacha, @@ -160,8 +153,7 @@ public class AwardSettingsUserControlModel : TaskViewModel return null; } - var task = new AsstAwardTask() - { + var task = new AsstAwardTask() { Award = award.Award, Mail = award.Mail, FreeGacha = award.FreeGacha, diff --git a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/CustomSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/CustomSettingsUserControlModel.cs index b1aad93548..9a8c623018 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/CustomSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/CustomSettingsUserControlModel.cs @@ -37,8 +37,7 @@ public class CustomSettingsUserControlModel : TaskViewModel public string TaskName { get => _taskName; - set - { + set { value = value.Replace(",", ",").Replace(";", ";"); SetAndNotify(ref _taskName, value); OnPropertyChanged(nameof(FormattedTaskNames)); @@ -52,8 +51,7 @@ public class CustomSettingsUserControlModel : TaskViewModel public string FormattedTaskNames { - get - { + get { if (string.IsNullOrWhiteSpace(TaskName)) { return string.Empty; @@ -71,8 +69,7 @@ public class CustomSettingsUserControlModel : TaskViewModel public override (AsstTaskType Type, JObject Params) Serialize() { - var task = new AsstCustomTask() - { + var task = new AsstCustomTask() { CustomTasks = TaskName.Split(',', StringSplitOptions.RemoveEmptyEntries) .Select(task => task.Trim()) .ToList(), @@ -84,22 +81,21 @@ public class CustomSettingsUserControlModel : TaskViewModel { if (string.IsNullOrWhiteSpace(TaskName)) { - return new List<(AsstTaskType, JObject)>(); + return []; } if (!TaskName.Contains(';')) { - return new List<(AsstTaskType, JObject)> { Serialize() }; + return [Serialize()]; } var taskGroups = TaskName.Split(';', StringSplitOptions.RemoveEmptyEntries); - return taskGroups.Select(group => new AsstCustomTask() - { - CustomTasks = group.Split(',', StringSplitOptions.RemoveEmptyEntries) + return taskGroups.Select(group => new AsstCustomTask() { + CustomTasks = group.Split(',', StringSplitOptions.RemoveEmptyEntries) .Select(task => task.Trim()) .ToList(), - }) + }) .Select(task => task.Serialize()) .ToList(); } diff --git a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/FightSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/FightSettingsUserControlModel.cs index e4fdf7dfe3..815ff349d4 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/FightSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/FightSettingsUserControlModel.cs @@ -71,8 +71,7 @@ public class FightSettingsUserControlModel : TaskViewModel /// public string Stage { - get - { + get { Stage1 ??= _stage1Fallback; if (!UseAlternateStage) @@ -130,8 +129,7 @@ public class FightSettingsUserControlModel : TaskViewModel public string? Stage1 { get => _stage1; - set - { + set { if (_stage1 == value) { return; @@ -161,8 +159,7 @@ public class FightSettingsUserControlModel : TaskViewModel public string? Stage2 { get => _stage2; - set - { + set { if (_stage2 == value) { return; @@ -191,8 +188,7 @@ public class FightSettingsUserControlModel : TaskViewModel public string? Stage3 { get => _stage3; - set - { + set { if (_stage3 == value) { return; @@ -221,8 +217,7 @@ public class FightSettingsUserControlModel : TaskViewModel public string? Stage4 { get => _stage4; - set - { + set { if (_stage4 == value) { return; @@ -248,8 +243,7 @@ public class FightSettingsUserControlModel : TaskViewModel public bool UseRemainingSanityStage { get => _useRemainingSanityStage; - set - { + set { SetAndNotify(ref _useRemainingSanityStage, value); ConfigurationHelper.SetValue(ConfigurationKeys.UseRemainingSanityStage, value.ToString()); } @@ -263,8 +257,7 @@ public class FightSettingsUserControlModel : TaskViewModel public bool CustomStageCode { get => _customStageCode; - set - { + set { if (!value) { RemoveNonExistStage(); @@ -292,8 +285,7 @@ public class FightSettingsUserControlModel : TaskViewModel public string? RemainingSanityStage { get => _remainingSanityStage; - set - { + set { if (_remainingSanityStage == value) { return; @@ -332,8 +324,7 @@ public class FightSettingsUserControlModel : TaskViewModel public bool? UseMedicine { get => _useMedicine; - set - { + set { SetAndNotify(ref _useMedicine, value); if (value == false) { @@ -354,8 +345,7 @@ public class FightSettingsUserControlModel : TaskViewModel public int MedicineNumber { get => _medicineNumber; - set - { + set { if (!SetAndNotify(ref _medicineNumber, value)) { return; @@ -377,8 +367,7 @@ public class FightSettingsUserControlModel : TaskViewModel public bool? UseStone { get => _useStone; - set - { + set { if (!AllowUseStoneSave && value == true) { value = null; @@ -421,8 +410,7 @@ public class FightSettingsUserControlModel : TaskViewModel public int StoneNumber { get => _stoneNumber; - set - { + set { if (!SetAndNotify(ref _stoneNumber, value)) { return; @@ -441,8 +429,7 @@ public class FightSettingsUserControlModel : TaskViewModel public bool? HasTimesLimited { get => _hasTimesLimited; - set - { + set { SetAndNotify(ref _hasTimesLimited, value); Instances.TaskQueueViewModel.SetFightParams(); value ??= false; @@ -458,8 +445,7 @@ public class FightSettingsUserControlModel : TaskViewModel public int MaxTimes { get => _maxTimes; - set - { + set { if (!SetAndNotify(ref _maxTimes, value)) { return; @@ -502,8 +488,7 @@ public class FightSettingsUserControlModel : TaskViewModel public int Series { get => _series; - set - { + set { if (!SetAndNotify(ref _series, value)) { return; @@ -524,8 +509,7 @@ public class FightSettingsUserControlModel : TaskViewModel public bool? IsSpecifiedDrops { get => _isSpecifiedDrops; - set - { + set { if (!SetAndNotify(ref _isSpecifiedDrops, value)) { return; @@ -612,8 +596,7 @@ public class FightSettingsUserControlModel : TaskViewModel public string DropsItemId { get => _dropsItemId; - set - { + set { SetAndNotify(ref _dropsItemId, value); Instances.TaskQueueViewModel.SetFightParams(); ConfigurationHelper.SetValue(ConfigurationKeys.DropsItemId, DropsItemId); @@ -649,8 +632,7 @@ public class FightSettingsUserControlModel : TaskViewModel public int DropsQuantity { get => _dropsQuantity; - set - { + set { SetAndNotify(ref _dropsQuantity, value); Instances.TaskQueueViewModel.SetFightParams(); ConfigurationHelper.SetValue(ConfigurationKeys.DropsQuantity, value.ToString()); @@ -672,8 +654,7 @@ public class FightSettingsUserControlModel : TaskViewModel public bool UseCustomAnnihilation { get => _useCustomAnnihilation; - set - { + set { SetAndNotify(ref _useCustomAnnihilation, value); ConfigurationHelper.SetValue(ConfigurationKeys.UseCustomAnnihilation, value.ToString()); } @@ -684,8 +665,7 @@ public class FightSettingsUserControlModel : TaskViewModel public string AnnihilationStage { get => _annihilationStage; - set - { + set { SetAndNotify(ref _annihilationStage, value); ConfigurationHelper.SetValue(ConfigurationKeys.AnnihilationStage, value); } @@ -699,8 +679,7 @@ public class FightSettingsUserControlModel : TaskViewModel public bool IsDrGrandet { get => _isDrGrandet; - set - { + set { SetAndNotify(ref _isDrGrandet, value); ConfigurationHelper.SetValue(ConfigurationKeys.IsDrGrandet, value.ToString()); } @@ -714,8 +693,7 @@ public class FightSettingsUserControlModel : TaskViewModel public bool UseAlternateStage { get => _useAlternateStage; - set - { + set { SetAndNotify(ref _useAlternateStage, value); ConfigurationHelper.SetValue(ConfigurationKeys.UseAlternateStage, value.ToString()); if (value) @@ -730,8 +708,7 @@ public class FightSettingsUserControlModel : TaskViewModel public bool AllowUseStoneSave { get => _allowUseStoneSave; - set - { + set { if (value) { var result = MessageBoxHelper.Show( @@ -758,8 +735,7 @@ public class FightSettingsUserControlModel : TaskViewModel public bool UseExpiringMedicine { get => _useExpiringMedicine; - set - { + set { SetAndNotify(ref _useExpiringMedicine, value); ConfigurationHelper.SetValue(ConfigurationKeys.UseExpiringMedicine, value.ToString()); Instances.TaskQueueViewModel.SetFightParams(); @@ -774,8 +750,7 @@ public class FightSettingsUserControlModel : TaskViewModel public bool HideUnavailableStage { get => _hideUnavailableStage; - set - { + set { SetAndNotify(ref _hideUnavailableStage, value); ConfigurationHelper.SetValue(ConfigurationKeys.HideUnavailableStage, value.ToString()); @@ -796,8 +771,7 @@ public class FightSettingsUserControlModel : TaskViewModel public bool HideSeries { get => _hideSeries; - set - { + set { SetAndNotify(ref _hideSeries, value); ConfigurationHelper.SetValue(ConfigurationKeys.HideSeries, value.ToString()); } @@ -808,8 +782,7 @@ public class FightSettingsUserControlModel : TaskViewModel public bool AutoRestartOnDrop { get => _autoRestartOnDrop; - set - { + set { SetAndNotify(ref _autoRestartOnDrop, value); ConfigurationHelper.SetValue(ConfigurationKeys.AutoRestartOnDrop, value.ToString()); } @@ -846,8 +819,7 @@ public class FightSettingsUserControlModel : TaskViewModel public override (AsstTaskType Type, JObject Params) Serialize() { - var task = new AsstFightTask() - { + var task = new AsstFightTask() { Stage = Stage, Medicine = UseMedicine != false ? MedicineNumber : 0, Stone = UseStoneDisplay ? StoneNumber : 0, @@ -883,8 +855,7 @@ public class FightSettingsUserControlModel : TaskViewModel public bool CustomInfrastPlanShowInFightSettings { get => _customInfrastPlanShowInFightSettings; - set - { + set { SetAndNotify(ref _customInfrastPlanShowInFightSettings, value); ConfigurationHelper.SetValue(ConfigurationKeys.CustomInfrastPlanShowInFightSettings, value.ToString()); } @@ -906,8 +877,7 @@ public class FightSettingsUserControlModel : TaskViewModel // 这个函数被列为public可见,意味着他注入对象前被调用 public void UpdateStageList() { - Execute.PostToUIThreadAsync(() => - { + Execute.PostToUIThreadAsync(() => { var hideUnavailableStage = HideUnavailableStage; Instances.TaskQueueViewModel.EnableSetFightParams = false; diff --git a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/InfrastSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/InfrastSettingsUserControlModel.cs index dd60ffb799..edba8e1cc5 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/InfrastSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/InfrastSettingsUserControlModel.cs @@ -130,8 +130,7 @@ public class InfrastSettingsUserControlModel : TaskViewModel public int DormThreshold { get => _dormThreshold; - set - { + set { SetAndNotify(ref _dormThreshold, value); ConfigurationHelper.SetValue(ConfigurationKeys.DormThreshold, value.ToString()); } @@ -200,8 +199,7 @@ public class InfrastSettingsUserControlModel : TaskViewModel public Mode InfrastMode { get => _infrastMode; - set - { + set { if (!SetAndNotify(ref _infrastMode, value)) { return; @@ -221,8 +219,7 @@ public class InfrastSettingsUserControlModel : TaskViewModel public string UsesOfDrones { get => _usesOfDrones; - set - { + set { SetAndNotify(ref _usesOfDrones, value); ConfigurationHelper.SetValue(ConfigurationKeys.UsesOfDrones, value); } @@ -233,8 +230,7 @@ public class InfrastSettingsUserControlModel : TaskViewModel public bool ReceptionMessageBoardReceive { get => _receptionMessageBoardReceive; - set - { + set { SetAndNotify(ref _receptionMessageBoardReceive, value); ConfigurationHelper.SetValue(ConfigurationKeys.InfrastReceptionMessageBoardReceive, value.ToString()); } @@ -245,8 +241,7 @@ public class InfrastSettingsUserControlModel : TaskViewModel public bool ReceptionClueExchange { get => _receptionClueExchange; - set - { + set { SetAndNotify(ref _receptionClueExchange, value); ConfigurationHelper.SetValue(ConfigurationKeys.InfrastReceptionClueExchange, value.ToString()); } @@ -260,8 +255,7 @@ public class InfrastSettingsUserControlModel : TaskViewModel public bool ContinueTraining { get => _continueTraining; - set - { + set { SetAndNotify(ref _continueTraining, value); ConfigurationHelper.SetValue(ConfigurationKeys.ContinueTraining, value.ToString()); } @@ -277,8 +271,7 @@ public class InfrastSettingsUserControlModel : TaskViewModel public string DefaultInfrast { get => _defaultInfrast; - set - { + set { SetAndNotify(ref _defaultInfrast, value); if (_defaultInfrast != UserDefined) { @@ -300,8 +293,7 @@ public class InfrastSettingsUserControlModel : TaskViewModel public bool DormFilterNotStationedEnabled { get => _dormFilterNotStationedEnabled; - set - { + set { SetAndNotify(ref _dormFilterNotStationedEnabled, value); ConfigurationHelper.SetValue(ConfigurationKeys.DormFilterNotStationedEnabled, value.ToString()); } @@ -315,8 +307,7 @@ public class InfrastSettingsUserControlModel : TaskViewModel public bool DormTrustEnabled { get => _dormTrustEnabled; - set - { + set { SetAndNotify(ref _dormTrustEnabled, value); ConfigurationHelper.SetValue(ConfigurationKeys.DormTrustEnabled, value.ToString()); } @@ -330,8 +321,7 @@ public class InfrastSettingsUserControlModel : TaskViewModel public bool OriginiumShardAutoReplenishment { get => _originiumShardAutoReplenishment; - set - { + set { SetAndNotify(ref _originiumShardAutoReplenishment, value); ConfigurationHelper.SetValue(ConfigurationKeys.OriginiumShardAutoReplenishment, value.ToString()); } @@ -344,8 +334,7 @@ public class InfrastSettingsUserControlModel : TaskViewModel [UsedImplicitly] public void SelectCustomInfrastFile() { - var dialog = new OpenFileDialog - { + var dialog = new OpenFileDialog { Filter = LocalizationHelper.GetString("CustomInfrastFile") + "|*.json", }; @@ -362,8 +351,7 @@ public class InfrastSettingsUserControlModel : TaskViewModel public string CustomInfrastFile { get => _customInfrastFile; - set - { + set { SetAndNotify(ref _customInfrastFile, value); ConfigurationHelper.SetValue(ConfigurationKeys.CustomInfrastFile, value); RefreshCustomInfrastPlan(); @@ -381,8 +369,7 @@ public class InfrastSettingsUserControlModel : TaskViewModel public int CustomInfrastPlanIndex { - get - { + get { if (CustomInfrastPlanInfoList.Count == 0) { return 0; @@ -396,8 +383,7 @@ public class InfrastSettingsUserControlModel : TaskViewModel return _customInfrastPlanIndex; } - set - { + set { if (CustomInfrastPlanInfoList.Count == 0) { return; @@ -554,8 +540,7 @@ public class InfrastSettingsUserControlModel : TaskViewModel Instances.TaskQueueViewModel.AddLog(descPost); } - CustomInfrastPlanInfoList.Add(new CustomInfrastPlanInfo - { + CustomInfrastPlanInfoList.Add(new CustomInfrastPlanInfo { Index = i, Name = display, Description = desc, @@ -640,8 +625,7 @@ public class InfrastSettingsUserControlModel : TaskViewModel public override (AsstTaskType Type, JObject Params) Serialize() { - return new AsstInfrastTask - { + return new AsstInfrastTask { Mode = InfrastMode, Facilitys = GetInfrastOrderList(), UsesOfDrones = UsesOfDrones, diff --git a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/MallSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/MallSettingsUserControlModel.cs index 70370f87ec..34460569d0 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/MallSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/MallSettingsUserControlModel.cs @@ -59,8 +59,7 @@ public class MallSettingsUserControlModel : TaskViewModel public string LastCreditFightTaskTime { get => _lastCreditFightTaskTime; - set - { + set { SetAndNotify(ref _lastCreditFightTaskTime, value); ConfigurationHelper.SetValue(ConfigurationKeys.LastCreditFightTaskTime, value); } @@ -73,8 +72,7 @@ public class MallSettingsUserControlModel : TaskViewModel /// public bool CreditFightTaskEnabled { - get - { + get { try { if (DateTime.UtcNow.ToYjDate() > DateTime.ParseExact(_lastCreditFightTaskTime.Replace('-', '/'), "yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture)) @@ -90,8 +88,7 @@ public class MallSettingsUserControlModel : TaskViewModel return false; } - set - { + set { SetAndNotify(ref _creditFightTaskEnabled, value); ConfigurationHelper.SetValue(ConfigurationKeys.CreditFightTaskEnabled, value.ToString()); } @@ -99,13 +96,11 @@ public class MallSettingsUserControlModel : TaskViewModel public bool CreditFightTaskEnabledDisplay { - get - { + get { return _creditFightTaskEnabled; } - set - { + set { SetAndNotify(ref _creditFightTaskEnabled, value); ConfigurationHelper.SetValue(ConfigurationKeys.CreditFightTaskEnabled, value.ToString()); } @@ -129,8 +124,7 @@ public class MallSettingsUserControlModel : TaskViewModel public string LastCreditVisitFriendsTime { get => _lastCreditVisitFriendsTime; - set - { + set { SetAndNotify(ref _lastCreditVisitFriendsTime, value); ConfigurationHelper.SetValue(ConfigurationKeys.LastCreditVisitFriendsTime, value); } @@ -144,8 +138,7 @@ public class MallSettingsUserControlModel : TaskViewModel public bool CreditVisitOnceADay { get => _creditVisitOnceADay; - set - { + set { SetAndNotify(ref _creditVisitOnceADay, value); ConfigurationHelper.SetValue(ConfigurationKeys.CreditVisitOnceADay, value.ToString()); } @@ -158,8 +151,7 @@ public class MallSettingsUserControlModel : TaskViewModel /// public bool CreditVisitFriendsEnabled { - get - { + get { if (!_creditVisitOnceADay) { return _creditVisitFriendsEnabled; @@ -176,8 +168,7 @@ public class MallSettingsUserControlModel : TaskViewModel } } - set - { + set { SetAndNotify(ref _creditVisitFriendsEnabled, value); ConfigurationHelper.SetValue(ConfigurationKeys.CreditVisitFriendsEnabled, value.ToString()); } @@ -185,13 +176,11 @@ public class MallSettingsUserControlModel : TaskViewModel public bool CreditVisitFriendsEnabledDisplay { - get - { + get { return _creditVisitFriendsEnabled; } - set - { + set { SetAndNotify(ref _creditVisitFriendsEnabled, value); ConfigurationHelper.SetValue(ConfigurationKeys.CreditVisitFriendsEnabled, value.ToString()); } @@ -205,8 +194,7 @@ public class MallSettingsUserControlModel : TaskViewModel public int CreditFightSelectFormation { get => _creditFightSelectFormation; - set - { + set { SetAndNotify(ref _creditFightSelectFormation, value); ConfigurationHelper.SetValue(ConfigurationKeys.CreditFightSelectFormation, value.ToString()); } @@ -220,8 +208,7 @@ public class MallSettingsUserControlModel : TaskViewModel public bool CreditShopping { get => _creditShopping; - set - { + set { SetAndNotify(ref _creditShopping, value); ConfigurationHelper.SetValue(ConfigurationKeys.CreditShopping, value.ToString()); } @@ -235,8 +222,7 @@ public class MallSettingsUserControlModel : TaskViewModel public string CreditFirstList { get => _creditFirstList; - set - { + set { value = value.Replace(";", ";").Trim(); SetAndNotify(ref _creditFirstList, value); ConfigurationHelper.SetValue(ConfigurationKeys.CreditFirstListNew, value); @@ -251,8 +237,7 @@ public class MallSettingsUserControlModel : TaskViewModel public string CreditBlackList { get => _creditBlackList; - set - { + set { value = value.Replace(";", ";").Trim(); SetAndNotify(ref _creditBlackList, value); ConfigurationHelper.SetValue(ConfigurationKeys.CreditBlackListNew, value); @@ -267,8 +252,7 @@ public class MallSettingsUserControlModel : TaskViewModel public bool CreditForceShoppingIfCreditFull { get => _creditForceShoppingIfCreditFull; - set - { + set { SetAndNotify(ref _creditForceShoppingIfCreditFull, value); ConfigurationHelper.SetValue(ConfigurationKeys.CreditForceShoppingIfCreditFull, value.ToString()); } @@ -282,8 +266,7 @@ public class MallSettingsUserControlModel : TaskViewModel public bool CreditOnlyBuyDiscount { get => _creditOnlyBuyDiscount; - set - { + set { SetAndNotify(ref _creditOnlyBuyDiscount, value); ConfigurationHelper.SetValue(ConfigurationKeys.CreditOnlyBuyDiscount, value.ToString()); } @@ -297,8 +280,7 @@ public class MallSettingsUserControlModel : TaskViewModel public bool CreditReserveMaxCredit { get => _creditReserveMaxCredit; - set - { + set { SetAndNotify(ref _creditReserveMaxCredit, value); ConfigurationHelper.SetValue(ConfigurationKeys.CreditReserveMaxCredit, value.ToString()); } @@ -307,8 +289,7 @@ public class MallSettingsUserControlModel : TaskViewModel public override (AsstTaskType Type, JObject Params) Serialize() { var fightEnable = Instances.TaskQueueViewModel.TaskItemViewModels.FirstOrDefault(x => x.OriginalName == "Combat")?.IsCheckedWithNull is not false; - var task = new AsstMallTask() - { + var task = new AsstMallTask() { CreditFight = fightEnable ? (!string.IsNullOrEmpty(FightSettingsUserControlModel.Instance.Stage) && CreditFightTaskEnabled) : CreditFightTaskEnabled, FormationIndex = CreditFightSelectFormation, VisitFriends = CreditVisitFriendsEnabled, @@ -359,8 +340,7 @@ public class MallSettingsUserControlModel : TaskViewModel { } - var task = new AsstMallTask() - { + var task = new AsstMallTask() { CreditFight = creditFight && !fightStage, FormationIndex = mall.CreditFightFormation, VisitFriends = visitFriends, diff --git a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/ReclamationSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/ReclamationSettingsUserControlModel.cs index a4a6b3b0f3..9efad0d38f 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/ReclamationSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/ReclamationSettingsUserControlModel.cs @@ -55,8 +55,7 @@ public class ReclamationSettingsUserControlModel : TaskViewModel public Theme ReclamationTheme { get => _reclamationTheme; - set - { + set { SetAndNotify(ref _reclamationTheme, value); ConfigurationHelper.SetValue(ConfigurationKeys.ReclamationTheme, value.ToString()); } @@ -79,8 +78,7 @@ public class ReclamationSettingsUserControlModel : TaskViewModel public Mode ReclamationMode { get => _reclamationMode; - set - { + set { SetAndNotify(ref _reclamationMode, value); ConfigurationHelper.SetValue(ConfigurationKeys.ReclamationMode, value.ToString()); } @@ -90,8 +88,7 @@ public class ReclamationSettingsUserControlModel : TaskViewModel public string ReclamationToolToCraft { - get - { + get { if (string.IsNullOrEmpty(_reclamationToolToCraft)) { return LocalizationHelper.GetString("ReclamationToolToCraftPlaceholder", DataHelper.ClientLanguageMapper[SettingsViewModel.GameSettings.ClientType]); @@ -100,8 +97,7 @@ public class ReclamationSettingsUserControlModel : TaskViewModel return _reclamationToolToCraft; } - set - { + set { value = value.Replace(';', ';'); SetAndNotify(ref _reclamationToolToCraft, value); ConfigurationHelper.SetValue(ConfigurationKeys.ReclamationToolToCraft, value); @@ -113,8 +109,7 @@ public class ReclamationSettingsUserControlModel : TaskViewModel public int ReclamationIncrementMode { get => _reclamationIncrementMode; - set - { + set { SetAndNotify(ref _reclamationIncrementMode, value); ConfigurationHelper.SetValue(ConfigurationKeys.ReclamationIncrementMode, value.ToString()); } @@ -134,8 +129,7 @@ public class ReclamationSettingsUserControlModel : TaskViewModel public int ReclamationMaxCraftCountPerRound { get => int.Parse(_reclamationMaxCraftCountPerRound); - set - { + set { SetAndNotify(ref _reclamationMaxCraftCountPerRound, value.ToString()); ConfigurationHelper.SetValue(ConfigurationKeys.ReclamationMaxCraftCountPerRound, value.ToString()); } @@ -146,8 +140,7 @@ public class ReclamationSettingsUserControlModel : TaskViewModel public bool ReclamationClearStore { get => _reclamationClearStore; - set - { + set { SetAndNotify(ref _reclamationClearStore, value); ConfigurationHelper.SetValue(ConfigurationKeys.ReclamationClearStore, value.ToString()); } @@ -177,8 +170,7 @@ public class ReclamationSettingsUserControlModel : TaskViewModel /// 返回(Asst任务类型, 参数) public override (AsstTaskType Type, JObject Params) Serialize() { - return new AsstReclamationTask - { + return new AsstReclamationTask { Theme = ReclamationTheme, Mode = ReclamationMode, IncrementMode = ReclamationIncrementMode, @@ -196,8 +188,7 @@ public class ReclamationSettingsUserControlModel : TaskViewModel } var toolToCraft = !string.IsNullOrEmpty(task.ToolToCraft) ? task.ToolToCraft : LocalizationHelper.GetString("ReclamationToolToCraftPlaceholder", DataHelper.ClientLanguageMapper[SettingsViewModel.GameSettings.ClientType]); - var asstTask = new AsstReclamationTask() - { + var asstTask = new AsstReclamationTask() { Theme = task.Theme, Mode = task.Mode, IncrementMode = task.IncrementMode, diff --git a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/RecruitSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/RecruitSettingsUserControlModel.cs index 7e74fd5ac8..8f53dd463f 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/RecruitSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/RecruitSettingsUserControlModel.cs @@ -72,8 +72,7 @@ public class RecruitSettingsUserControlModel : TaskViewModel public object[] AutoRecruitFirstList { get => _autoRecruitFirstList; - set - { + set { SetAndNotify(ref _autoRecruitFirstList, value); var config = string.Join(';', value.Cast().Select(i => i.Value)); ConfigurationHelper.SetValue(ConfigurationKeys.AutoRecruitFirstList, config); @@ -88,8 +87,7 @@ public class RecruitSettingsUserControlModel : TaskViewModel public int RecruitMaxTimes { get => _recruitMaxTimes; - set - { + set { SetAndNotify(ref _recruitMaxTimes, value); ConfigurationHelper.SetValue(ConfigurationKeys.RecruitMaxTimes, value.ToString()); } @@ -103,8 +101,7 @@ public class RecruitSettingsUserControlModel : TaskViewModel public bool RefreshLevel3 { get => _refreshLevel3; - set - { + set { SetAndNotify(ref _refreshLevel3, value); ConfigurationHelper.SetValue(ConfigurationKeys.RefreshLevel3, value.ToString()); } @@ -118,8 +115,7 @@ public class RecruitSettingsUserControlModel : TaskViewModel public bool ForceRefresh { get => _forceRefresh; - set - { + set { SetAndNotify(ref _forceRefresh, value); ConfigurationHelper.SetValue(ConfigurationKeys.ForceRefresh, value.ToString()); } @@ -130,8 +126,7 @@ public class RecruitSettingsUserControlModel : TaskViewModel public bool? UseExpeditedWithNull { get => _useExpeditedWithNull; - set - { + set { if (value == true) { value = null; @@ -166,8 +161,7 @@ public class RecruitSettingsUserControlModel : TaskViewModel public int SelectExtraTags { get => _selectExtraTags; - set - { + set { SetAndNotify(ref _selectExtraTags, value); ConfigurationHelper.SetValue(ConfigurationKeys.SelectExtraTags, value.ToString()); } @@ -181,8 +175,7 @@ public class RecruitSettingsUserControlModel : TaskViewModel public bool NotChooseLevel1 { get => _notChooseLevel1; - set - { + set { SetAndNotify(ref _notChooseLevel1, value); ConfigurationHelper.SetValue(ConfigurationKeys.NotChooseLevel1, value.ToString()); } @@ -196,8 +189,7 @@ public class RecruitSettingsUserControlModel : TaskViewModel public bool ChooseLevel3 { get => _chooseLevel3; - set - { + set { SetAndNotify(ref _chooseLevel3, value); ConfigurationHelper.SetValue(ConfigurationKeys.RecruitChooseLevel3, value.ToString()); } @@ -211,8 +203,7 @@ public class RecruitSettingsUserControlModel : TaskViewModel public bool ChooseLevel4 { get => _chooseLevel4; - set - { + set { SetAndNotify(ref _chooseLevel4, value); ConfigurationHelper.SetValue(ConfigurationKeys.RecruitChooseLevel4, value.ToString()); } @@ -226,8 +217,7 @@ public class RecruitSettingsUserControlModel : TaskViewModel public bool ChooseLevel5 { get => _chooseLevel5; - set - { + set { SetAndNotify(ref _chooseLevel5, value); ConfigurationHelper.SetValue(ConfigurationKeys.RecruitChooseLevel5, value.ToString()); } @@ -238,8 +228,7 @@ public class RecruitSettingsUserControlModel : TaskViewModel public int ChooseLevel3Hour { get => _chooseLevel3Hour; - set - { + set { if (!SetAndNotify(ref _chooseLevel3Hour, value)) { return; @@ -254,8 +243,7 @@ public class RecruitSettingsUserControlModel : TaskViewModel public int ChooseLevel3Min { get => _chooseLevel3Min; - set - { + set { if (!SetAndNotify(ref _chooseLevel3Min, value)) { return; @@ -270,10 +258,8 @@ public class RecruitSettingsUserControlModel : TaskViewModel public int ChooseLevel3Time { get => _chooseLevel3Time; - set - { - value = value switch - { + set { + value = value switch { < 60 => 540, > 540 => 60, _ => value / 10 * 10, @@ -291,8 +277,7 @@ public class RecruitSettingsUserControlModel : TaskViewModel public int ChooseLevel4Hour { get => _chooseLevel4Hour; - set - { + set { if (!SetAndNotify(ref _chooseLevel4Hour, value)) { return; @@ -307,8 +292,7 @@ public class RecruitSettingsUserControlModel : TaskViewModel public int ChooseLevel4Min { get => _chooseLevel4Min; - set - { + set { if (!SetAndNotify(ref _chooseLevel4Min, value)) { return; @@ -323,10 +307,8 @@ public class RecruitSettingsUserControlModel : TaskViewModel public int ChooseLevel4Time { get => _chooseLevel4Time; - set - { - value = value switch - { + set { + value = value switch { < 60 => 540, > 540 => 60, _ => value / 10 * 10, @@ -344,8 +326,7 @@ public class RecruitSettingsUserControlModel : TaskViewModel public int ChooseLevel5Hour { get => _chooseLevel5Hour; - set - { + set { if (!SetAndNotify(ref _chooseLevel5Hour, value)) { return; @@ -360,8 +341,7 @@ public class RecruitSettingsUserControlModel : TaskViewModel public int ChooseLevel5Min { get => _chooseLevel5Min; - set - { + set { if (!SetAndNotify(ref _chooseLevel5Min, value)) { return; @@ -376,10 +356,8 @@ public class RecruitSettingsUserControlModel : TaskViewModel public int ChooseLevel5Time { get => _chooseLevel5Time; - set - { - value = value switch - { + set { + value = value switch { < 60 => 540, > 540 => 60, _ => value / 10 * 10, @@ -394,8 +372,7 @@ public class RecruitSettingsUserControlModel : TaskViewModel public override (AsstTaskType Type, JObject Params) Serialize() { - var task = new AsstRecruitTask() - { + var task = new AsstRecruitTask() { Refresh = RefreshLevel3, ForceRefresh = ForceRefresh, SetRecruitTime = true, diff --git a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/RoguelikeSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/RoguelikeSettingsUserControlModel.cs index b96660639d..c2faa2c990 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/RoguelikeSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/RoguelikeSettingsUserControlModel.cs @@ -78,8 +78,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel foreach (var i in list) { int value = i; - var display = value switch - { + var display = value switch { -1 => LocalizationHelper.GetString("NotSwitch") + " (-1)", int.MaxValue => $"MAX ({maxThemeDifficulty})", 0 => "MIN (0)", @@ -92,8 +91,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel RoguelikeDifficulty = RoguelikeDifficultyList.Any(item => item.Value == RoguelikeDifficulty) ? difficulty : -1; } - private static int GetMaxDifficultyForTheme(Theme theme) => theme switch - { + private static int GetMaxDifficultyForTheme(Theme theme) => theme switch { Theme.Phantom => 15, Theme.Mizuki => 18, Theme.Sami => 15, @@ -161,8 +159,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel RoguelikeRoles = RoguelikeRolesList.Any(x => x.Value == roguelikeRoles) ? roguelikeRoles : "稳扎稳打"; } - private readonly Dictionary> _squadDictionary = new() - { + private readonly Dictionary> _squadDictionary = new() { ["Phantom_Default"] = [ ("GatheringSquad", "集群分队"), @@ -375,8 +372,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public Theme RoguelikeTheme { get => _roguelikeTheme; - set - { + set { SetAndNotify(ref _roguelikeTheme, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeTheme, value.ToString()); @@ -421,8 +417,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public int RoguelikeDifficulty { get => _roguelikeDifficulty; - set - { + set { SetAndNotify(ref _roguelikeDifficulty, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeDifficulty, value.ToString()); } @@ -436,8 +431,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public Mode RoguelikeMode { get => _roguelikeMode; - set - { + set { if (value == Mode.Investment) { RoguelikeInvestmentEnabled = true; @@ -458,8 +452,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public string RoguelikeCollectibleModeSquad { get => _roguelikeCollectibleModeSquad; - set - { + set { SetAndNotify(ref _roguelikeCollectibleModeSquad, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeCollectibleModeSquad, value); } @@ -473,8 +466,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public string RoguelikeSquad { get => _roguelikeSquad; - set - { + set { SetAndNotify(ref _roguelikeSquad, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeSquad, value); } @@ -494,8 +486,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public string RoguelikeRoles { get => _roguelikeRoles; - set - { + set { SetAndNotify(ref _roguelikeRoles, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeRoles, value); } @@ -509,8 +500,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public string RoguelikeCoreChar { get => _roguelikeCoreChar; - set - { + set { if (_roguelikeCoreChar == (value ??= string.Empty)) { return; @@ -530,8 +520,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public ObservableCollection RoguelikeCoreCharList { get => _roguelikeCoreCharList; - private set - { + private set { if (!string.IsNullOrEmpty(RoguelikeCoreChar) && !value.Contains(RoguelikeCoreChar)) { value.Add(RoguelikeCoreChar); @@ -549,8 +538,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public bool RoguelikeStartWithEliteTwo { get => _roguelikeStartWithEliteTwo; - set - { + set { switch (value) { case true when RoguelikeUseSupportUnit: @@ -575,8 +563,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public bool RoguelikeOnlyStartWithEliteTwoRaw { get => _roguelikeOnlyStartWithEliteTwo; - set - { + set { SetAndNotify(ref _roguelikeOnlyStartWithEliteTwo, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeOnlyStartWithEliteTwo, value.ToString()); } @@ -632,8 +619,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public object[] RoguelikeStartWithSelectList { get => _roguelikeStartWithSelectList; - set - { + set { SetAndNotify(ref _roguelikeStartWithSelectList, value); var config = string.Join(' ', _roguelikeStartWithSelectList.Cast>().Select(i => i.Value).ToList()); ConfigurationHelper.SetGlobalValue(ConfigurationKeys.RoguelikeStartWithSelectList, config); @@ -648,8 +634,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public bool Roguelike3FirstFloorFoldartal { get => _roguelike3FirstFloorFoldartal; - set - { + set { SetAndNotify(ref _roguelike3FirstFloorFoldartal, value); ConfigurationHelper.SetValue(ConfigurationKeys.Roguelike3FirstFloorFoldartal, value.ToString()); } @@ -660,8 +645,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public string Roguelike3FirstFloorFoldartals { get => _roguelike3FirstFloorFoldartals; - set - { + set { value = value.Trim(); SetAndNotify(ref _roguelike3FirstFloorFoldartals, value); ConfigurationHelper.SetValue(ConfigurationKeys.Roguelike3FirstFloorFoldartals, value); @@ -676,8 +660,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public bool Roguelike3NewSquad2StartingFoldartal { get => _roguelike3NewSquad2StartingFoldartal; - set - { + set { SetAndNotify(ref _roguelike3NewSquad2StartingFoldartal, value); ConfigurationHelper.SetValue(ConfigurationKeys.Roguelike3NewSquad2StartingFoldartal, value.ToString()); } @@ -688,8 +671,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public string Roguelike3NewSquad2StartingFoldartals { get => _roguelike3NewSquad2StartingFoldartals; - set - { + set { value = value.Replace(';', ';').Trim(); SetAndNotify(ref _roguelike3NewSquad2StartingFoldartals, value); ConfigurationHelper.SetValue(ConfigurationKeys.Roguelike3NewSquad2StartingFoldartals, value); @@ -705,8 +687,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public string RoguelikeExpectedCollapsalParadigms { get => _roguelikeExpectedCollapsalParadigms; - set - { + set { value = value.Replace(';', ';').Trim(); SetAndNotify(ref _roguelikeExpectedCollapsalParadigms, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeExpectedCollapsalParadigms, value); @@ -721,8 +702,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public bool RoguelikeUseSupportUnit { get => _roguelikeUseSupportUnit; - set - { + set { if (value && _roguelikeStartWithEliteTwo && RoguelikeSquadIsProfessional) { RoguelikeStartWithEliteTwo = false; @@ -741,8 +721,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public bool RoguelikeEnableNonfriendSupport { get => _roguelikeEnableNonfriendSupport; - set - { + set { SetAndNotify(ref _roguelikeEnableNonfriendSupport, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeEnableNonfriendSupport, value.ToString()); } @@ -756,8 +735,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public int RoguelikeStartsCount { get => _roguelikeStartsCount; - set - { + set { SetAndNotify(ref _roguelikeStartsCount, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeStartsCount, value.ToString()); } @@ -771,8 +749,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public bool RoguelikeInvestmentEnabled { get => _roguelikeInvestmentEnabled; - set - { + set { SetAndNotify(ref _roguelikeInvestmentEnabled, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeInvestmentEnabled, value.ToString()); } @@ -786,8 +763,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public bool RoguelikeInvestmentWithMoreScoreRaw { get => _roguelikeInvestmentWithMoreScore; - set - { + set { SetAndNotify(ref _roguelikeInvestmentWithMoreScore, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeInvestmentEnterSecondFloor, value.ToString()); } @@ -806,8 +782,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public bool RoguelikeCollectibleModeShopping { get => _roguelikeCollectibleModeShopping; - set - { + set { SetAndNotify(ref _roguelikeCollectibleModeShopping, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeCollectibleModeShopping, value.ToString()); } @@ -818,8 +793,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public bool RoguelikeRefreshTraderWithDiceRaw { get => _roguelikeRefreshTraderWithDice; - set - { + set { SetAndNotify(ref _roguelikeRefreshTraderWithDice, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeRefreshTraderWithDice, value.ToString()); } @@ -828,8 +802,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public bool RoguelikeRefreshTraderWithDice { get => _roguelikeRefreshTraderWithDice && RoguelikeTheme == Theme.Mizuki; - set - { + set { SetAndNotify(ref _roguelikeRefreshTraderWithDice, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeRefreshTraderWithDice, value.ToString()); } @@ -843,8 +816,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public int RoguelikeInvestsCount { get => _roguelikeInvestsCount; - set - { + set { SetAndNotify(ref _roguelikeInvestsCount, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeInvestsCount, value.ToString()); } @@ -858,8 +830,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public bool RoguelikeStopWhenInvestmentFull { get => _roguelikeStopWhenInvestmentFull; - set - { + set { SetAndNotify(ref _roguelikeStopWhenInvestmentFull, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeStopWhenInvestmentFull, value.ToString()); } @@ -873,8 +844,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public bool RoguelikeStopAtFinalBoss { get => _roguelikeStopAtFinalBoss; - set - { + set { SetAndNotify(ref _roguelikeStopAtFinalBoss, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeStopAtFinalBoss, value.ToString()); } @@ -888,8 +858,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public bool RoguelikeMonthlySquadAutoIterate { get => _roguelikeMonthlySquadAutoIterate; - set - { + set { SetAndNotify(ref _roguelikeMonthlySquadAutoIterate, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeMonthlySquadAutoIterate, value.ToString()); } @@ -903,8 +872,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public bool RoguelikeMonthlySquadCheckComms { get => _roguelikeMonthlySquadCheckComms; - set - { + set { SetAndNotify(ref _roguelikeMonthlySquadCheckComms, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeMonthlySquadCheckComms, value.ToString()); } @@ -918,8 +886,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public bool RoguelikeDeepExplorationAutoIterate { get => _roguelikeDeepExplorationAutoIterate; - set - { + set { SetAndNotify(ref _roguelikeDeepExplorationAutoIterate, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeDeepExplorationAutoIterate, value.ToString()); } @@ -933,8 +900,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public RoguelikeBoskySubNodeType RoguelikeFindPlaytimeTarget { get => _roguelikeFindPlaytimeTarget; - set - { + set { SetAndNotify(ref _roguelikeFindPlaytimeTarget, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeFindPlaytimeTarget, value.ToString()); } @@ -943,12 +909,12 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel /// /// Gets the list of available playtime target options for FindPlaytime mode. /// - public ObservableCollection> RoguelikeFindPlaytimeTargetList { get; } = new() - { + public ObservableCollection> RoguelikeFindPlaytimeTargetList { get; } = + [ new() { Display = LocalizationHelper.GetString("RoguelikePlaytimeLing"), Value = RoguelikeBoskySubNodeType.Ling }, new() { Display = LocalizationHelper.GetString("RoguelikePlaytimeShu"), Value = RoguelikeBoskySubNodeType.Shu }, new() { Display = LocalizationHelper.GetString("RoguelikePlaytimeNian"), Value = RoguelikeBoskySubNodeType.Nian }, - }; + ]; /// /// Gets a value indicating whether the FindPlaytime target selection should be visible. @@ -963,8 +929,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public bool RoguelikeStopAtMaxLevel { get => _roguelikeStopAtMaxLevel; - set - { + set { SetAndNotify(ref _roguelikeStopAtMaxLevel, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeStopAtMaxLevel, value.ToString()); } @@ -978,8 +943,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public bool RoguelikeDelayAbortUntilCombatComplete { get => _roguelikeDelayAbortUntilCombatComplete; - set - { + set { SetAndNotify(ref _roguelikeDelayAbortUntilCombatComplete, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeDelayAbortUntilCombatComplete, value.ToString()); } @@ -993,8 +957,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public bool RoguelikeStartWithSeed { get => _roguelikeStartWithSeed; - set - { + set { SetAndNotify(ref _roguelikeStartWithSeed, value); ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeStartWithSeed, value.ToString()); } @@ -1095,7 +1058,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel break; case "RoguelikeEncounterOptions": - var options = (subTaskDetails!["options"]! as JArray) ?? new JArray(); + var options = (subTaskDetails!["options"]! as JArray) ?? []; Instances.TaskQueueViewModel.AddLog(string.Format(LocalizationHelper.GetString("RoguelikeEncounterOptions"), options.Count, UiLogColor.EventIS)); foreach (var option in options) { @@ -1109,8 +1072,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel case "BoskyPassageNode": { var nodeType = subTaskDetails!["node_type"]?.ToString(); - var (localizedNodeType, logColor) = nodeType switch - { + var (localizedNodeType, logColor) = nodeType switch { "Omissions" => (LocalizationHelper.GetString("BoskyOmissions"), UiLogColor.BoskyOmissionsIS), "Legend" => (LocalizationHelper.GetString("BoskyLegend"), UiLogColor.BoskyLegendIS), "OldShop" => (LocalizationHelper.GetString("BoskyOldShop"), UiLogColor.BoskyOldShopIS), @@ -1150,8 +1112,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel case "RoguelikeJieGardenTargetFound": { var targetSubtype = subTaskDetails!["target_subtype"]?.ToString(); - var localizedTarget = targetSubtype switch - { + var localizedTarget = targetSubtype switch { "Ling" => LocalizationHelper.GetString("RoguelikePlaytimeLing"), "Shu" => LocalizationHelper.GetString("RoguelikePlaytimeShu"), "Nian" => LocalizationHelper.GetString("RoguelikePlaytimeNian"), @@ -1205,8 +1166,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel public override (AsstTaskType Type, JObject Params) Serialize() { - var task = new AsstRoguelikeTask() - { + var task = new AsstRoguelikeTask() { Theme = RoguelikeTheme, Mode = RoguelikeMode, Starts = RoguelikeStartsCount, diff --git a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/StartUpSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/StartUpSettingsUserControlModel.cs index 597717952d..658e4f80b2 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/StartUpSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/StartUpSettingsUserControlModel.cs @@ -39,8 +39,7 @@ public class StartUpSettingsUserControlModel : TaskViewModel public string AccountName { get => _accountName; - set - { + set { value = value.Trim(); SetAndNotify(ref _accountName, value); ConfigurationHelper.SetValue(ConfigurationKeys.AccountName, value); @@ -66,14 +65,12 @@ public class StartUpSettingsUserControlModel : TaskViewModel { var clientType = SettingsViewModel.GameSettings.ClientType; var startGame = SettingsViewModel.GameSettings.StartGame; - var accountName = clientType switch - { + var accountName = clientType switch { "Official" or "Bilibili" => AccountName, _ => string.Empty, }; - var task = new AsstStartUpTask() - { + var task = new AsstStartUpTask() { ClientType = clientType, StartGame = startGame, AccountName = accountName, @@ -90,14 +87,12 @@ public class StartUpSettingsUserControlModel : TaskViewModel } var clientType = SettingsViewModel.GameSettings.ClientType; - var accountName = clientType switch - { + var accountName = clientType switch { "Official" or "Bilibili" => startUp.AccountName, _ => string.Empty, }; - var task = new AsstStartUpTask() - { + var task = new AsstStartUpTask() { ClientType = clientType, StartGame = !string.IsNullOrEmpty(clientType), AccountName = accountName,