mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
完成宿舍选择“休息中”干员的功能
This commit is contained in:
@@ -330,14 +330,15 @@ std::vector<asst::Identify::FindImageResult> asst::Identify::find_all_images(
|
||||
bool need_push = true;
|
||||
// 如果有两个点离得太近,只取里面得分高的那个
|
||||
// 一般相邻的都是刚刚push进去的,这里倒序快一点
|
||||
constexpr static int MinDistance = 10;
|
||||
for (auto iter = results.rbegin(); iter != results.rend(); ++ iter) {
|
||||
if (std::abs(j - iter->rect.x) < 5
|
||||
|| std::abs(i - iter->rect.y) < 5) {
|
||||
if (std::abs(j - iter->rect.x) < MinDistance
|
||||
&& std::abs(i - iter->rect.y) < MinDistance) {
|
||||
if (iter->score < value) {
|
||||
iter->rect = rect;
|
||||
iter->score = value;
|
||||
need_push = false;
|
||||
} // else 这个点就放弃了
|
||||
need_push = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
#include "InfrastDormTask.h"
|
||||
|
||||
#include <future>
|
||||
#include <thread>
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
#include "WinMacro.h"
|
||||
#include "Identify.h"
|
||||
#include "Configer.h"
|
||||
|
||||
using namespace asst;
|
||||
|
||||
@@ -22,8 +26,12 @@ bool asst::InfrastDormTask::run()
|
||||
m_callback(AsstMsg::PtrIsNull, json::value(), m_callback_arg);
|
||||
return false;
|
||||
}
|
||||
|
||||
enter_dorm(2);
|
||||
|
||||
enter_dorm(0);
|
||||
sleep(1000);
|
||||
enter_operator_selection();
|
||||
sleep(1000);
|
||||
clear_and_select_the_resting();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -32,7 +40,6 @@ bool asst::InfrastDormTask::enter_dorm(int index)
|
||||
{
|
||||
cv::Mat image = get_format_image();
|
||||
// 普通的和mini的,正常情况应该只有一个有结果,另一个是empty
|
||||
// 为了防止识别漏了,这里阈值先放低一点
|
||||
auto dorm_result = m_identify_ptr->find_all_images(image, "Dorm", 0.8);
|
||||
auto dorm_mini_result = m_identify_ptr->find_all_images(image, "DormMini", 0.8);
|
||||
|
||||
@@ -60,3 +67,108 @@ bool asst::InfrastDormTask::enter_dorm(int index)
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool asst::InfrastDormTask::enter_next_dorm()
|
||||
{
|
||||
static const Rect swipe_down_begin( // 向下滑动起点
|
||||
Configer::WindowWidthDefault * 0.3,
|
||||
Configer::WindowHeightDefault * 0.8,
|
||||
Configer::WindowWidthDefault * 0.2,
|
||||
Configer::WindowWidthDefault * 0.1);
|
||||
static const Rect swipe_down_end( // 向下滑动终点
|
||||
Configer::WindowWidthDefault * 0.3,
|
||||
Configer::WindowHeightDefault * 0.2,
|
||||
Configer::WindowWidthDefault * 0.2,
|
||||
Configer::WindowWidthDefault * 0.1);
|
||||
|
||||
static const int swipe_dwon_duration = 1000; // 向下滑动持续时间
|
||||
|
||||
m_control_ptr->swipe(swipe_down_begin, swipe_down_end, swipe_dwon_duration);
|
||||
|
||||
static const Rect double_click_rect(
|
||||
Configer::WindowWidthDefault * 0.4,
|
||||
Configer::WindowHeightDefault * 0.4,
|
||||
Configer::WindowWidthDefault * 0.2,
|
||||
Configer::WindowWidthDefault * 0.2
|
||||
);
|
||||
|
||||
m_control_ptr->click(double_click_rect);
|
||||
m_control_ptr->click(double_click_rect);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool asst::InfrastDormTask::enter_operator_selection()
|
||||
{
|
||||
// 有这些文字之一就说明“进驻信息”这个按钮已经点开了
|
||||
static const std::vector<std::string> info_opened_flags = {
|
||||
GbkToUtf8("当前房间入住信息"),
|
||||
GbkToUtf8("进驻人数"),
|
||||
GbkToUtf8("清空")
|
||||
};
|
||||
|
||||
std::vector<TextArea> ocr_result = ocr_detect();
|
||||
|
||||
bool is_info_opened =
|
||||
std::find_first_of(
|
||||
ocr_result.cbegin(), ocr_result.cend(),
|
||||
info_opened_flags.cbegin(), info_opened_flags.cend(),
|
||||
[](const TextArea& lhs, const std::string& rhs)
|
||||
-> bool { return lhs.text == rhs; })
|
||||
!= ocr_result.cend();
|
||||
|
||||
static const std::string station_info = GbkToUtf8("进驻信息");
|
||||
// 如果“进驻信息”窗口没点开,那就点开
|
||||
if (!is_info_opened) {
|
||||
auto station_info_iter = std::find_if(ocr_result.cbegin(), ocr_result.cend(),
|
||||
[](const TextArea& textarea) -> bool {
|
||||
return textarea.text == station_info;
|
||||
});
|
||||
m_control_ptr->click(station_info_iter->rect);
|
||||
sleep(1000);
|
||||
ocr_result = ocr_detect();
|
||||
}
|
||||
|
||||
// 点击这里面任意一个,都可以进入干员选择页面
|
||||
static const std::vector<std::string> enter_operator_page_buttons = {
|
||||
GbkToUtf8("进驻"),
|
||||
GbkToUtf8("休息中"),
|
||||
GbkToUtf8("空闲中"),
|
||||
GbkToUtf8("心情")
|
||||
};
|
||||
|
||||
auto button_iter = std::find_first_of(
|
||||
ocr_result.cbegin(), ocr_result.cend(),
|
||||
enter_operator_page_buttons.cbegin(), enter_operator_page_buttons.cend(),
|
||||
[](const TextArea& lhs, const std::string& rhs)
|
||||
-> bool { return lhs.text == rhs; });
|
||||
if (button_iter == ocr_result.cend()) {
|
||||
// TODO 报错
|
||||
return false;
|
||||
}
|
||||
m_control_ptr->click(button_iter->rect);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool asst::InfrastDormTask::clear_and_select_the_resting()
|
||||
{
|
||||
auto click_clear_button = [&]() {
|
||||
// 点击“清空选择”按钮
|
||||
m_control_ptr->click(Rect(430, 655, 150, 40));
|
||||
sleep(300);
|
||||
};
|
||||
cv::Mat image = get_format_image();
|
||||
// 异步点击清空按钮
|
||||
std::future<void> click_clear_button_future = std::async(std::launch::async, click_clear_button);
|
||||
// 识别“休息中”的干员
|
||||
auto resting_result = m_identify_ptr->find_all_images(image, "Resting", 0.8);
|
||||
click_clear_button_future.wait();
|
||||
|
||||
// 把“休息中”的干员,都再次选上
|
||||
for (const auto& resting : resting_result) {
|
||||
m_control_ptr->click(resting.rect);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,16 @@ namespace asst {
|
||||
virtual bool run() override;
|
||||
|
||||
protected:
|
||||
|
||||
// 进入宿舍,index为从上到下的编号
|
||||
bool enter_dorm(int index = 0);
|
||||
// 进入下一个宿舍
|
||||
bool enter_next_dorm();
|
||||
|
||||
// 进入当前宿舍的干员选择界面
|
||||
bool enter_operator_selection();
|
||||
|
||||
// 清空并选择原有的“休息中”干员(相当于把“空闲中”的干员去掉)
|
||||
bool clear_and_select_the_resting();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ OcrAbstractTask::OcrAbstractTask(AsstCallback callback, void* callback_arg)
|
||||
;
|
||||
}
|
||||
|
||||
std::vector<TextArea> OcrAbstractTask::ocr_detect()
|
||||
std::vector<TextArea> OcrAbstractTask::ocr_detect(bool use_raw_image)
|
||||
{
|
||||
const cv::Mat& image = get_format_image();
|
||||
const cv::Mat& image = get_format_image(use_raw_image);
|
||||
|
||||
return ocr_detect(image);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace asst {
|
||||
virtual bool run() override = 0;
|
||||
|
||||
protected:
|
||||
std::vector<TextArea> ocr_detect();
|
||||
std::vector<TextArea> ocr_detect(bool use_raw_image = false);
|
||||
std::vector<TextArea> ocr_detect(const cv::Mat& image);
|
||||
bool click_text(const cv::Mat& image, const std::string& text);
|
||||
|
||||
|
||||
BIN
resource/template/special/Resting.png
Normal file
BIN
resource/template/special/Resting.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.0 KiB |
Reference in New Issue
Block a user