From 3289bbabb8fa29b60f3208005d503aefa8dc57f2 Mon Sep 17 00:00:00 2001 From: Sherkey Asher <57581480+SherkeyXD@users.noreply.github.com> Date: Tue, 17 Jun 2025 09:28:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=82=80=E5=BD=B1=E8=82=89=E9=B8=BD?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=9A=BE=E5=BA=A6=E9=80=89=E6=8B=A9=20(#1289?= =?UTF-8?q?7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 傀影肉鸽添加难度选择 * feat: 肉鸽难度选择不再显示不支持的选项 --- resource/tasks/Roguelike/Phantom.json | 16 ++++ .../Task/Roguelike/RoguelikeConfig.cpp | 10 +-- ...RoguelikeDifficultySelectionTaskPlugin.cpp | 5 -- .../Models/AsstTasks/AsstRoguelikeTask.cs | 6 +- .../RoguelikeSettingsUserControlModel.cs | 82 +++++++++++++------ .../RoguelikeSettingsUserControl.xaml | 3 +- 6 files changed, 77 insertions(+), 45 deletions(-) diff --git a/resource/tasks/Roguelike/Phantom.json b/resource/tasks/Roguelike/Phantom.json index e1d9602f59..b4c67beb15 100644 --- a/resource/tasks/Roguelike/Phantom.json +++ b/resource/tasks/Roguelike/Phantom.json @@ -4,6 +4,22 @@ "text": ["古堡笔记"] }, "Phantom@Roguelike@ChooseDifficulty": {}, + "Phantom@Roguelike@ChooseDifficulty_Easiest": { + "action": "ClickRect", + "specificRect": [1144, 472, 78, 24], + "postDelay": 800, + "template": "Phantom@Roguelike@StartExplore.png", + "roi": [1026, 470, 254, 248], + "sub": ["SwipeToTheUp*2"] + }, + "Phantom@Roguelike@ChooseDifficulty_Hardest": { + "action": "ClickRect", + "specificRect": [1144, 472, 78, 24], + "postDelay": 800, + "template": "Phantom@Roguelike@StartExplore.png", + "roi": [1026, 470, 254, 248], + "sub": ["SwipeToTheDown*2"] + }, "Phantom@Roguelike@ChooseOper": { "next": [ "Phantom@Roguelike@ChooseOperConfirm", diff --git a/src/MaaCore/Task/Roguelike/RoguelikeConfig.cpp b/src/MaaCore/Task/Roguelike/RoguelikeConfig.cpp index c439e1cb3f..53127e0402 100644 --- a/src/MaaCore/Task/Roguelike/RoguelikeConfig.cpp +++ b/src/MaaCore/Task/Roguelike/RoguelikeConfig.cpp @@ -20,13 +20,9 @@ bool asst::RoguelikeConfig::verify_and_load_params(const json::value& params) m_theme = theme; m_mode = mode; - if (m_theme != RoguelikeTheme::Phantom) { - m_difficulty = params.get("difficulty", 0); - } - else if (params.contains("difficulty")) { - Log.error(__FUNCTION__, "| Invalid difficulty for theme", m_theme); - return false; - } + m_difficulty = params.get("difficulty", -1); + + Log.info("Roguelike theme", m_theme, "| mode", static_cast(m_mode), "| difficulty", m_difficulty); if (mode == RoguelikeMode::Collectible) { m_collectible_mode_shopping = params.get("collectible_mode_shopping", false); diff --git a/src/MaaCore/Task/Roguelike/RoguelikeDifficultySelectionTaskPlugin.cpp b/src/MaaCore/Task/Roguelike/RoguelikeDifficultySelectionTaskPlugin.cpp index 9c5e8d4193..dc530c6d93 100644 --- a/src/MaaCore/Task/Roguelike/RoguelikeDifficultySelectionTaskPlugin.cpp +++ b/src/MaaCore/Task/Roguelike/RoguelikeDifficultySelectionTaskPlugin.cpp @@ -8,11 +8,6 @@ bool asst::RoguelikeDifficultySelectionTaskPlugin::load_params([[maybe_unused]] const json::value& params) { - // 集成战略 <傀影与猩红孤钻> 的难度选项没有数字标注,暂不支持难度选择功能 - if (m_config->get_theme() == RoguelikeTheme::Phantom) { - return false; - } - // 深入调查和月度小队模式不需要选择难度 if (m_config->get_mode() == RoguelikeMode::Exploration || m_config->get_mode() == RoguelikeMode::Squad) { return false; diff --git a/src/MaaWpfGui/Models/AsstTasks/AsstRoguelikeTask.cs b/src/MaaWpfGui/Models/AsstTasks/AsstRoguelikeTask.cs index e59f8654ab..5382ca4309 100644 --- a/src/MaaWpfGui/Models/AsstTasks/AsstRoguelikeTask.cs +++ b/src/MaaWpfGui/Models/AsstTasks/AsstRoguelikeTask.cs @@ -200,15 +200,11 @@ public class AsstRoguelikeTask : AsstBaseTask { ["mode"] = Mode, ["theme"] = Theme.ToString(), + ["difficulty"] = Difficulty, ["starts_count"] = Starts, ["investment_enabled"] = InvestmentEnabled, }; - if (Theme != RoguelikeTheme.Phantom) - { - taskParams["difficulty"] = Difficulty; - } - if (InvestmentEnabled) { taskParams["investment_with_more_score"] = InvestmentWithMoreScore; diff --git a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/RoguelikeSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/RoguelikeSettingsUserControlModel.cs index 1cb357f552..001133b45b 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/RoguelikeSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/RoguelikeSettingsUserControlModel.cs @@ -28,6 +28,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace MaaWpfGui.ViewModels.UserControl.TaskQueue; + using Theme = RoguelikeTheme; public class RoguelikeSettingsUserControlModel : TaskViewModel { @@ -51,45 +52,47 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel { int maxThemeDifficulty = GetMaxDifficultyForTheme(RoguelikeTheme); - if (RoguelikeDifficultyList.Count == 0) + var baseList = new List> { - RoguelikeDifficultyList = - [ - new() { Display = "MAX", Value = int.MaxValue } - ]; - for (int i = 20; i >= -1; --i) - { - RoguelikeDifficultyList.Add(new() { Display = i.ToString(), Value = i }); - } + new() { Display = "MAX", Value = int.MaxValue } + }; + + for (int i = 20; i >= -1; --i) + { + baseList.Add(new() { Display = i.ToString(), Value = i }); } - var sortedItems = RoguelikeDifficultyList - .Select(item => item) + // 基于当前主题的最大难度过滤并排序 + 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, - _ when item.Value <= maxThemeDifficulty => 2 + (maxThemeDifficulty - item.Value), - _ => 2 + maxThemeDifficulty + 1 + (20 - item.Value), + _ => 2 + (maxThemeDifficulty - item.Value), }) .ToList(); - for (int newIndex = 0; newIndex < sortedItems.Count; newIndex++) + RoguelikeDifficultyList.Clear(); + foreach (var item in sortedItems) { - int currentIndex = RoguelikeDifficultyList.IndexOf(sortedItems[newIndex]); - if (currentIndex != newIndex) - { - RoguelikeDifficultyList.Move(currentIndex, newIndex); - } - - int value = RoguelikeDifficultyList[newIndex].Value; - RoguelikeDifficultyList[newIndex].Display = value switch + int value = item.Value; + item.Display = value switch { -1 => LocalizationHelper.GetString("Current"), int.MaxValue => "MAX", 0 => "MIN", - _ => value > maxThemeDifficulty ? $"{value} (NONSUPPORT)" : value.ToString(), + _ => value.ToString(), }; + RoguelikeDifficultyList.Add(item); + } + + // 验证当前选中的难度是否在新列表中 + bool currentDifficultyValid = RoguelikeDifficultyList.Any(item => item.Value == RoguelikeDifficulty); + if (!currentDifficultyValid) + { + // 如果当前难度不在有效列表中,设置为默认值 + RoguelikeDifficulty = -1; } } @@ -97,7 +100,7 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel { return theme switch { - Theme.Phantom => 0, + Theme.Phantom => SettingsViewModel.GameSettings.ClientType is "" or "Official" or "Bilibili" ? 15 : 0, Theme.Mizuki => 18, Theme.Sami => 15, Theme.Sarkaz => 18, @@ -339,15 +342,42 @@ public class RoguelikeSettingsUserControlModel : TaskViewModel set { SetAndNotify(ref _roguelikeTheme, value); - ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeTheme, value.ToString()); + ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeTheme, Convert.ToString((int)value)); + + // Check and adjust difficulty if current value is not supported by new theme + int maxDifficulty = GetMaxDifficultyForTheme(value); + if (RoguelikeDifficulty != -1 && RoguelikeDifficulty != int.MaxValue && RoguelikeDifficulty > maxDifficulty) + { + RoguelikeDifficulty = -1; // Set to "Current" if not supported + } + + // 确保在更新列表之前先更新相关属性 UpdateRoguelikeDifficultyList(); UpdateRoguelikeModeList(); UpdateRoguelikeSquadList(); UpdateRoguelikeCoreCharList(); + + // 强制刷新难度显示 + OnPropertyChanged(nameof(RoguelikeDifficulty)); } } - private int _roguelikeDifficulty = Convert.ToInt32(ConfigurationHelper.GetValue(ConfigurationKeys.RoguelikeDifficulty, int.MaxValue.ToString())); + private int _roguelikeDifficulty = GetValidDifficulty(); + + /// + /// 获取有效的难度值,处理配置中的无效值 + /// + private static int GetValidDifficulty() + { + string difficultyStr = ConfigurationHelper.GetValue(ConfigurationKeys.RoguelikeDifficulty, int.MaxValue.ToString()); + if (string.IsNullOrEmpty(difficultyStr) || !int.TryParse(difficultyStr, out int difficulty)) + { + // 如果配置值无效,返回默认值并保存 + ConfigurationHelper.SetValue(ConfigurationKeys.RoguelikeDifficulty, int.MaxValue.ToString()); + return int.MaxValue; + } + return difficulty; + } public int RoguelikeDifficulty { diff --git a/src/MaaWpfGui/Views/UserControl/TaskQueue/RoguelikeSettingsUserControl.xaml b/src/MaaWpfGui/Views/UserControl/TaskQueue/RoguelikeSettingsUserControl.xaml index 8e6abaec30..2b5d2627be 100644 --- a/src/MaaWpfGui/Views/UserControl/TaskQueue/RoguelikeSettingsUserControl.xaml +++ b/src/MaaWpfGui/Views/UserControl/TaskQueue/RoguelikeSettingsUserControl.xaml @@ -35,8 +35,7 @@ ItemsSource="{Binding RoguelikeDifficultyList}" ScrollViewer.CanContentScroll="False" SelectedValue="{Binding RoguelikeDifficulty}" - SelectedValuePath="Value" - Visibility="{c:Binding 'RoguelikeTheme != task:RoguelikeTheme.Phantom'}" /> + SelectedValuePath="Value" />