Skip to content

Commit 96f5e3e

Browse files
CopilotMistEO
andauthored
feat: Add target parameter to Scroll action for Win32 controller (#1082)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: MistEO <18511905+MistEO@users.noreply.github.com>
1 parent ca636c1 commit 96f5e3e

14 files changed

Lines changed: 83 additions & 7 deletions

File tree

docs/en_us/3.1-PipelineProtocol.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,16 @@ Mouse wheel scroll.
977977

978978
Additional properties for this action:
979979

980+
- `target`: *true* | *string* | *array<int, 2>* | *array<int, 4>*
981+
Position of the scroll target. The mouse will first move to this position before scrolling. Optional, default is `true`.
982+
- *true*: Target is the position just recognized in this node (i.e., itself).
983+
- *string*: Fill in a node name; the target is the position recognized by a previously executed node.
984+
- *array<int, 2>*: Fixed coordinate point `[x, y]`.
985+
- *array<int, 4>*: Fixed coordinate area `[x, y, w, h]`, a random point will be selected within the rectangle (with higher probability towards the center and lower probability at the edges). Use [0, 0, 0, 0] for full screen.
986+
987+
- `target_offset`: *array<int, 4>*
988+
Additional offset applied to `target` for the scroll position, each of the four values is added respectively. Optional, default is [0, 0, 0, 0].
989+
980990
- `dx`: *int*
981991
Horizontal scroll distance, positive values scroll right, negative values scroll left. Optional, default is 0.
982992

docs/zh_cn/3.1-任务流水线协议.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,16 @@ Pipeline v2 时,将这些字段放到 `recognition.param` 中即可。
985985

986986
该动作属性需额外部分字段:
987987

988+
- `target`: *true* | *string* | *array<int, 2>* | *array<int, 4>*
989+
滚动目标的位置,鼠标会先移动到该位置再进行滚动。可选,默认 true 。
990+
- *true*: 目标为本节点中刚刚识别到的位置(即自身)。
991+
- *string*: 填写节点名,目标为之前执行过的某节点识别到的位置。
992+
- *array<int, 2>*: 固定坐标点 `[x, y]`
993+
- *array<int, 4>*: 固定坐标区域 `[x, y, w, h]`,会在矩形内随机选取一点(越靠近中心概率越高,边缘概率相对较低),若希望全屏可设为 [0, 0, 0, 0]
994+
995+
- `target_offset`: *array<int, 4>*
996+
`target` 的基础上额外移动再作为滚动目标,四个值分别相加。可选,默认 [0, 0, 0, 0]
997+
988998
- `dx`: *int*
989999
水平滚动距离,正值向右滚动,负值向左滚动。可选,默认 0 。
9901000

source/MaaFramework/Controller/ControllerAgent.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,12 @@ bool ControllerAgent::handle_scroll(const ScrollParam& param)
816816
return false;
817817
}
818818

819+
// Move to target position before scrolling
820+
cv::Point point = preproc_touch_point(param.point);
821+
if (!control_unit_->touch_move(0, point.x, point.y, 0)) {
822+
LogWarn << "Failed to move to scroll position" << VAR(point);
823+
}
824+
819825
bool ret = control_unit_->scroll(param.dx, param.dy);
820826
return ret;
821827
}

source/MaaFramework/Controller/ControllerAgent.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,11 @@ struct AppParam
100100

101101
struct ScrollParam
102102
{
103+
cv::Point point {};
103104
int dx = 0;
104105
int dy = 0;
105106

106-
MEO_TOJSON(dx, dy);
107+
MEO_TOJSON(point, dx, dy);
107108
};
108109

109110
struct ShellParam

source/MaaFramework/Resource/PipelineDumper.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ PipelineV2::JAction PipelineDumper::dump_act(Action::Type type, const Action::Pa
394394
case Action::Type::Scroll: {
395395
const auto& p = std::get<Action::ScrollParam>(param);
396396
act.param = PipelineV2::JScroll {
397+
.target = dump_target(p.target),
398+
.target_offset = dump_rect(p.target.offset),
397399
.dx = p.dx,
398400
.dy = p.dy,
399401
};

source/MaaFramework/Resource/PipelineParser.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,11 @@ bool PipelineParser::parse_app_info(const json::value& input, Action::AppParam&
14111411

14121412
bool PipelineParser::parse_scroll(const json::value& input, Action::ScrollParam& output, const Action::ScrollParam& default_value)
14131413
{
1414+
if (!parse_action_target(input, "target", output.target, default_value.target)) {
1415+
LogError << "failed to parse_action_target" << VAR(input);
1416+
return false;
1417+
}
1418+
14141419
if (!get_and_check_value(input, "dx", output.dx, default_value.dx)) {
14151420
LogError << "failed to get_and_check_value dx" << VAR(input);
14161421
return false;

source/MaaFramework/Resource/PipelineTypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ struct AppParam
216216

217217
struct ScrollParam
218218
{
219+
Target target;
219220
int dx = 0;
220221
int dy = 0;
221222
};

source/MaaFramework/Resource/PipelineTypesV2.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,12 @@ struct JStopTask
270270

271271
struct JScroll
272272
{
273+
JTarget target;
274+
JRect target_offset {};
273275
int dx = 0;
274276
int dy = 0;
275277

276-
MEO_TOJSON(dx, dy);
278+
MEO_TOJSON(target, target_offset, dx, dy);
277279
};
278280

279281
struct JCommand

source/MaaFramework/Task/Component/Actuator.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ ActionResult
115115
return stop_app(std::get<AppParam>(pipeline_data.action_param), pipeline_data.name);
116116

117117
case Type::Scroll:
118-
return scroll(std::get<ScrollParam>(pipeline_data.action_param), pipeline_data.name);
118+
return scroll(std::get<ScrollParam>(pipeline_data.action_param), reco_hit, pipeline_data.name);
119119

120120
case Type::StopTask:
121121
return stop_task(pipeline_data.name);
@@ -455,21 +455,22 @@ ActionResult Actuator::input_text(const MAA_RES_NS::Action::InputTextParam& para
455455
};
456456
}
457457

458-
ActionResult Actuator::scroll(const MAA_RES_NS::Action::ScrollParam& param, const std::string& name)
458+
ActionResult Actuator::scroll(const MAA_RES_NS::Action::ScrollParam& param, const cv::Rect& box, const std::string& name)
459459
{
460460
if (!controller()) {
461461
LogError << "Controller is null";
462462
return {};
463463
}
464464

465-
MAA_CTRL_NS::ScrollParam ctrl_param { .dx = param.dx, .dy = param.dy };
465+
cv::Point point = rand_point(get_target_rect(param.target, box));
466+
MAA_CTRL_NS::ScrollParam ctrl_param { .point = point, .dx = param.dx, .dy = param.dy };
466467
bool ret = controller()->scroll(ctrl_param);
467468

468469
return ActionResult {
469470
.action_id = action_id_,
470471
.name = name,
471472
.action = "Scroll",
472-
.box = cv::Rect {},
473+
.box = box,
473474
.success = ret,
474475
.detail = json::value(ctrl_param),
475476
};

source/MaaFramework/Task/Component/Actuator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Actuator : public NonCopyable
4747
ActionResult key_down(const MAA_RES_NS::Action::KeyParam& param, const std::string& name);
4848
ActionResult key_up(const MAA_RES_NS::Action::KeyParam& param, const std::string& name);
4949
ActionResult input_text(const MAA_RES_NS::Action::InputTextParam& param, const std::string& name);
50-
ActionResult scroll(const MAA_RES_NS::Action::ScrollParam& param, const std::string& name);
50+
ActionResult scroll(const MAA_RES_NS::Action::ScrollParam& param, const cv::Rect& box, const std::string& name);
5151
ActionResult shell(const MAA_RES_NS::Action::ShellParam& param, const std::string& name);
5252

5353
ActionResult start_app(const MAA_RES_NS::Action::AppParam& param, const std::string& name);

0 commit comments

Comments
 (0)