mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-16 09:50:40 +08:00
* feat(controller): 集成 MaaWin32ControlUnit 支持 Win32 窗口截图与控制 - 提取公共滑动插值逻辑到 SwipeHelper.hpp,重构 Minitouch/PlayTools 控制器 - 新增 Win32ControlUnitLoader 动态加载 MaaWin32ControlUnit.dll - 新增 Win32Controller 实现 ControllerAPI,适配 touch_down/move/up 接口 - 添加 AsstAsyncAttachWindow 公开 API 用于绑定 Win32 窗口 - 添加 Win32 截图/输入方式的类型定义和枚举常量 * feat(api): 增加同步版本的 AsstAttachWindow 接口 模仿 AsstConnect 实现同步绑定 Win32 窗口的接口,方便简单场景下直接调用。 该接口标记为 deprecated,建议使用异步版本 AsstAsyncAttachWindow。 * fix: can build MaaCore * feat: 完成整体适配 * feat(ci): 添加 MaaFramework Win32ControlUnit 下载步骤 使用 robinraju/release-downloader 从 MaaFramework 最新 release 下载 win-x64 版本并提取 MaaWin32ControlUnit 到构建产物中 * docs: 添加 Win32Controller 调试所需 MaaWin32ControlUnit 的说明 在开发文档的环境配置步骤中说明调试 Win32Controller 需要手动下载 MaaWin32ControlUnit.dll,并欢迎社区贡献自动下载脚本 * fix(i18n): 修改 UseAttachWindowWarning 措辞为"仅供尝鲜" * fix: 小细节修复 * ci: fix maafw filename * feat: PC 移至连接配置 * feat: 调整描述 * chore: 调整 PC 在连接配置中的顺序 * feat: 设置指引和开始唤醒界面 PC 选项绑定 --------- Co-authored-by: uye <99072975+ABA2396@users.noreply.github.com>
103 lines
3.1 KiB
C++
103 lines
3.1 KiB
C++
#pragma once
|
||
|
||
#ifdef _WIN32
|
||
|
||
#include <memory>
|
||
#include <string>
|
||
|
||
#include "MaaUtils/SafeWindows.hpp"
|
||
|
||
#include "Common/AsstMsg.h"
|
||
#include "ControllerAPI.h"
|
||
#include "InstHelper.h"
|
||
#include "Win32ControlUnitLoader.h"
|
||
|
||
namespace asst
|
||
{
|
||
class Assistant;
|
||
|
||
class Win32Controller : public ControllerAPI, private InstHelper
|
||
{
|
||
public:
|
||
Win32Controller(const AsstCallback& callback, Assistant* inst);
|
||
virtual ~Win32Controller() override;
|
||
|
||
Win32Controller(const Win32Controller&) = delete;
|
||
Win32Controller& operator=(const Win32Controller&) = delete;
|
||
Win32Controller(Win32Controller&&) = delete;
|
||
Win32Controller& operator=(Win32Controller&&) = delete;
|
||
|
||
// 绑定到窗口(替代 connect)
|
||
bool attach(
|
||
void* hwnd,
|
||
Win32ScreencapMethod screencap_method,
|
||
Win32InputMethod mouse_method,
|
||
Win32InputMethod keyboard_method);
|
||
|
||
public: // ControllerAPI 接口
|
||
virtual bool connect(const std::string& adb_path, const std::string& address, const std::string& config) override;
|
||
virtual bool inited() const noexcept override;
|
||
|
||
virtual const std::string& get_uuid() const override;
|
||
|
||
virtual size_t get_pipe_data_size() const noexcept override { return 0; }
|
||
|
||
virtual size_t get_version() const noexcept override { return 0; }
|
||
|
||
virtual bool screencap(cv::Mat& image_payload, bool allow_reconnect = false) override;
|
||
|
||
virtual bool start_game(const std::string& client_type) override;
|
||
virtual bool stop_game(const std::string& client_type) override;
|
||
|
||
virtual bool click(const Point& p) override;
|
||
virtual bool input(const std::string& text) override;
|
||
virtual bool swipe(
|
||
const Point& p1,
|
||
const Point& p2,
|
||
int duration = 0,
|
||
bool extra_swipe = false,
|
||
double slope_in = 1,
|
||
double slope_out = 1,
|
||
bool with_pause = false) override;
|
||
|
||
virtual bool inject_input_event(const InputEvent& event) override;
|
||
|
||
virtual bool press_esc() override;
|
||
virtual ControlFeat::Feat support_features() const noexcept override;
|
||
|
||
virtual std::pair<int, int> get_screen_res() const noexcept override;
|
||
|
||
private:
|
||
void callback(AsstMsg msg, const json::value& details);
|
||
|
||
// 封装 MaaWin32ControlUnit 的调用
|
||
bool unit_connect();
|
||
bool unit_screencap(cv::Mat& image);
|
||
bool unit_click(int x, int y);
|
||
bool unit_swipe(int x1, int y1, int x2, int y2, int duration);
|
||
bool unit_touch_down(int contact, int x, int y, int pressure);
|
||
bool unit_touch_move(int contact, int x, int y, int pressure);
|
||
bool unit_touch_up(int contact);
|
||
bool unit_input_text(const std::string& text);
|
||
bool unit_click_key(int key);
|
||
|
||
private:
|
||
static constexpr int DefaultSwipeDelay = 10; // ms
|
||
|
||
AsstCallback m_callback = nullptr;
|
||
std::unique_ptr<Win32ControlUnitLoader> m_loader;
|
||
void* m_unit_handle = nullptr;
|
||
void* m_hwnd = nullptr;
|
||
|
||
bool m_inited = false;
|
||
std::string m_uuid;
|
||
std::pair<int, int> m_screen_size = { 0, 0 };
|
||
|
||
Win32ScreencapMethod m_screencap_method = Win32Screencap::None;
|
||
Win32InputMethod m_mouse_method = Win32Input::None;
|
||
Win32InputMethod m_keyboard_method = Win32Input::None;
|
||
};
|
||
} // namespace asst
|
||
|
||
#endif // _WIN32
|