From 4e9a77050e38255dd2d0f9789d6fdc466bccf7c5 Mon Sep 17 00:00:00 2001 From: status102 <102887808+status102@users.noreply.github.com> Date: Sun, 10 Aug 2025 16:02:56 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20wpf=E8=82=89=E9=B8=BD=E9=9A=BE=E5=BA=A6?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RoguelikeSettingsUserControlModel.cs | 60 ++++++------------- 1 file changed, 18 insertions(+), 42 deletions(-) diff --git a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/RoguelikeSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/RoguelikeSettingsUserControlModel.cs index 329ffda9a6..32be216d7d 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/RoguelikeSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/RoguelikeSettingsUserControlModel.cs @@ -66,63 +66,39 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel private void UpdateRoguelikeDifficultyList() { int maxThemeDifficulty = GetMaxDifficultyForTheme(RoguelikeTheme); + var difficulty = RoguelikeDifficulty; - var baseList = new List> - { - new() { Display = "MAX", Value = int.MaxValue }, - }; - - for (int i = 20; i >= -1; --i) - { - baseList.Add(new() { Display = i.ToString(), Value = i }); - } - - // 基于当前主题的最大难度过滤并排序 - var sortedItems = baseList - .Where(item => item.Value == -1 || item.Value == int.MaxValue || item.Value <= maxThemeDifficulty) - .OrderBy(item => item.Value switch - { - -1 => 0, - int.MaxValue => 1, - _ => 2 + (maxThemeDifficulty - item.Value), - }) - .ToList(); - + // 0 = min, -1 = current, int.MaxValue = max + var list = Enumerable.Range(0, maxThemeDifficulty + 1).OrderDescending().ToList(); + list.Insert(0, -1); + list.Insert(1, int.MaxValue); RoguelikeDifficultyList.Clear(); - foreach (var item in sortedItems) + foreach (var i in list) { - int value = item.Value; - item.Display = value switch + int value = i; + var display = value switch { -1 => LocalizationHelper.GetString("Current"), int.MaxValue => "MAX", 0 => "MIN", _ => value.ToString(), }; - RoguelikeDifficultyList.Add(item); + RoguelikeDifficultyList.Add(new() { Display = display, Value = value }); } // 验证当前选中的难度是否在新列表中 - bool currentDifficultyValid = RoguelikeDifficultyList.Any(item => item.Value == RoguelikeDifficulty); - if (!currentDifficultyValid) - { - // 如果当前难度不在有效列表中,设置为默认值 - RoguelikeDifficulty = -1; - } + RoguelikeDifficulty = RoguelikeDifficultyList.Any(item => item.Value == RoguelikeDifficulty) ? difficulty : -1; } - private static int GetMaxDifficultyForTheme(Theme theme) + private static int GetMaxDifficultyForTheme(Theme theme) => theme switch { - return theme switch - { - Theme.Phantom => SettingsViewModel.GameSettings.ClientType is "" or "Official" or "Bilibili" ? 15 : 0, - Theme.Mizuki => 18, - Theme.Sami => 15, - Theme.Sarkaz => 18, - Theme.JieGarden => 15, - _ => 20, - }; - } + Theme.Phantom => SettingsViewModel.GameSettings.ClientType is "" or "Official" or "Bilibili" ? 15 : 0, + Theme.Mizuki => 18, + Theme.Sami => 15, + Theme.Sarkaz => 18, + Theme.JieGarden => 15, + _ => 20, + }; private void UpdateRoguelikeModeList() {