From c884b99ca2dbfd2cc0eb9753e5273c281a6ed1c4 Mon Sep 17 00:00:00 2001 From: status102 <102887808+status102@users.noreply.github.com> Date: Wed, 10 Dec 2025 15:00:29 +0800 Subject: [PATCH] =?UTF-8?q?rft:=20=E8=87=AA=E5=8A=A8=E7=BC=96=E9=98=9F?= =?UTF-8?q?=E5=8A=A9=E6=88=98=E9=A1=B5=E9=9D=A2=E7=BB=A7=E6=89=BF=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Miscellaneous/BattleFormationTask.cpp | 2 +- .../Miscellaneous => Ui}/SupportList.cpp | 31 +++++++++++-------- .../{Task/Miscellaneous => Ui}/SupportList.h | 17 ++++++---- 3 files changed, 30 insertions(+), 20 deletions(-) rename src/MaaCore/{Task/Miscellaneous => Ui}/SupportList.cpp (94%) rename src/MaaCore/{Task/Miscellaneous => Ui}/SupportList.h (96%) diff --git a/src/MaaCore/Task/Miscellaneous/BattleFormationTask.cpp b/src/MaaCore/Task/Miscellaneous/BattleFormationTask.cpp index ac2688fb8e..01b02a8013 100644 --- a/src/MaaCore/Task/Miscellaneous/BattleFormationTask.cpp +++ b/src/MaaCore/Task/Miscellaneous/BattleFormationTask.cpp @@ -789,7 +789,7 @@ std::optional asst::BattleFormationTask::add_support_unit( // 通过点击编队界面右上角 <助战单位> 文字左边的 Icon 进入助战干员选择界面 ProcessTask(*this, { "Formation-AddSupportUnit-EnterSupportList" }).run(); - SupportList support_list(m_callback, m_inst, m_task_chain); + SupportList support_list(*this); if (required_opers.empty()) { // 随机模式 for (size_t refresh_times = 0; refresh_times <= max_refresh_times && !need_exit(); ++refresh_times) { diff --git a/src/MaaCore/Task/Miscellaneous/SupportList.cpp b/src/MaaCore/Ui/SupportList.cpp similarity index 94% rename from src/MaaCore/Task/Miscellaneous/SupportList.cpp rename to src/MaaCore/Ui/SupportList.cpp index 3dd561be21..fffbdc4846 100644 --- a/src/MaaCore/Task/Miscellaneous/SupportList.cpp +++ b/src/MaaCore/Ui/SupportList.cpp @@ -1,5 +1,6 @@ #include "SupportList.h" +#include "Task/AbstractTask.h" #include "Config/GeneralConfig.h" #include "Config/Miscellaneous/BattleDataConfig.h" #include "Config/TaskData.h" @@ -12,6 +13,10 @@ #include "Vision/Matcher.h" #include "Vision/MultiMatcher.h" +asst::SupportList::SupportList(AbstractTask& parent_task) + : InstHelper(parent_task.inst()), m_parent(parent_task) +{} + bool asst::SupportList::select_role(const Role role) { LogTraceFunction; @@ -32,7 +37,7 @@ bool asst::SupportList::select_role(const Role role) reset_list_and_view_data(); if (ProcessTask( - *this, + m_parent, { enum_to_string(role, true) + "@SupportList-RoleSelected", enum_to_string(role, true) + "@SupportList-SelectRole" }) .run()) { @@ -121,7 +126,7 @@ bool asst::SupportList::select_support_unit(const size_t index) ctrler()->click(click_rect); sleep(Config.get_options().task_delay); - if (!ProcessTask(*this, { "SupportList-DetailPanel-Flag", "SupportList-DetailPanel-Flag@LoadingText" }).run()) { + if (!ProcessTask(m_parent, { "SupportList-DetailPanel-Flag", "SupportList-DetailPanel-Flag@LoadingText" }).run()) { Log.error(__FUNCTION__, "| Support unit detail panel not recognised; failed to select support unit"); save_img(ctrler()->get_image(), "screenshot"); return false; @@ -138,11 +143,11 @@ bool asst::SupportList::confirm_to_use_support_unit() if (!m_in_support_unit_detail_panel) { Log.error( __FUNCTION__, - "| Invalid operation: currently not in support unit detail panel; failed to confirm to use support_unit"); + "| Invalid operation: currently not in support unit detail panel; failed to confirm to use support_unit"); return false; } - if (ProcessTask(*this, { "SupportList-DetailPanel-Confirm" }).run()) { + if (ProcessTask(m_parent, { "SupportList-DetailPanel-Confirm" }).run()) { m_in_support_unit_detail_panel = false; reset_list_and_view_data(); return true; @@ -162,7 +167,7 @@ bool asst::SupportList::leave_support_unit_detail_panel() return false; } - if (ProcessTask(*this, { "SupportList-DetailPanel-Leave" }).run()) { + if (ProcessTask(m_parent, { "SupportList-DetailPanel-Leave" }).run()) { m_in_support_unit_detail_panel = false; update_view(); return true; @@ -254,15 +259,15 @@ bool asst::SupportList::select_module(const OperModule module, const int minimum // ———————————————————————————————————————————————————————————————— // Find Module // ———————————————————————————————————————————————————————————————— - ProcessTask(*this, { "SupportList-DetailPanel-SelectModule-MoveToHead" }).run(); + ProcessTask(m_parent, { "SupportList-DetailPanel-SelectModule-MoveToHead" }).run(); if (module == OperModule::Original) { - if (!ProcessTask(*this, { "SupportList-DetailPanel-SelectOriginalModule" }).run()) { + if (!ProcessTask(m_parent, { "SupportList-DetailPanel-SelectOriginalModule" }).run()) { LogInfo << __FUNCTION__ << "| Module" << enum_to_string(module) << "does not exist; failed to select module"; return false; } - if (!ProcessTask(*this, { "SupportList-DetailPanel-ModuleSelected" }).run()) { + if (!ProcessTask(m_parent, { "SupportList-DetailPanel-ModuleSelected" }).run()) { LogError << __FUNCTION__ << "| Module" << enum_to_string(module) << "did not respond to the click; failed to select module"; return false; @@ -310,7 +315,7 @@ bool asst::SupportList::select_module(const OperModule module, const int minimum } if (page < MAX_NUM_MODULE_PAGES - 1) { - ProcessTask(*this, { "SupportList-DetailPanel-SelectModule-MoveRight" }).run(); + ProcessTask(m_parent, { "SupportList-DetailPanel-SelectModule-MoveRight" }).run(); } } @@ -330,7 +335,7 @@ bool asst::SupportList::refresh_list() reset_list_and_view_data(); - return ProcessTask(*this, { "SupportList-RefreshAfterCooldown" }).run(); + return ProcessTask(m_parent, { "SupportList-RefreshAfterCooldown" }).run(); } bool asst::SupportList::update_selected_role(const cv::Mat& image) @@ -456,21 +461,21 @@ void asst::SupportList::move_to_list_head() { LogTraceFunction; - ProcessTask(*this, { "SupportList-MoveToHead" }).run(); + ProcessTask(m_parent, { "SupportList-MoveToHead" }).run(); } void asst::SupportList::move_forward() { LogTraceFunction; - ProcessTask(*this, { "SupportList-MoveRight" }).run(); + ProcessTask(m_parent, { "SupportList-MoveRight" }).run(); } void asst::SupportList::move_backward() { LogTraceFunction; - ProcessTask(*this, { "SupportList-MoveLeft" }).run(); + ProcessTask(m_parent, { "SupportList-MoveLeft" }).run(); } std::vector asst::SupportList::analyze_module_page() diff --git a/src/MaaCore/Task/Miscellaneous/SupportList.h b/src/MaaCore/Ui/SupportList.h similarity index 96% rename from src/MaaCore/Task/Miscellaneous/SupportList.h rename to src/MaaCore/Ui/SupportList.h index df5a73403c..593bd81288 100644 --- a/src/MaaCore/Task/Miscellaneous/SupportList.h +++ b/src/MaaCore/Ui/SupportList.h @@ -1,11 +1,13 @@ #pragma once #include "Common/AsstBattleDef.h" -#include "Task/AbstractTask.h" +#include "InstHelper.h" namespace asst { -class SupportList : public AbstractTask +class AbstractTask; + +class SupportList : protected InstHelper { public: using Role = battle::Role; @@ -13,10 +15,8 @@ public: using Friendship = battle::Friendship; using SupportUnit = battle::SupportUnit; - using AbstractTask::AbstractTask; - virtual ~SupportList() override = default; - - virtual bool _run() override { return true; }; + SupportList(AbstractTask& parent_task); + virtual ~SupportList() = default; /// /// 选择助战列表职业。 @@ -188,6 +188,11 @@ private: /// static bool save_img(const cv::Mat& image, std::string_view description = "image"); + /// + /// 父任务引用,用于创建 ProcessTask。 + /// + AbstractTask& m_parent; + /// /// 当前助战列表所选职业。 ///