Skip to content

Commit 451654c

Browse files
neko-paraMistEOCopilot
authored
feat: controller features (#815)
Co-authored-by: MistEO <mistereo@hotmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 292be3a commit 451654c

38 files changed

Lines changed: 224 additions & 206 deletions

include/MaaFramework/Instance/MaaCustomController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ extern "C"
3434

3535
/// Write result to buffer.
3636
MaaBool (*request_uuid)(void* trans_arg, /* out */ MaaStringBuffer* buffer);
37+
MaaControllerFeature (*get_features)(void* trans_arg);
3738

3839
MaaBool (*start_app)(const char* intent, void* trans_arg);
3940
MaaBool (*stop_app)(const char* intent, void* trans_arg);

include/MaaFramework/MaaDef.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@ typedef uint64_t MaaDbgControllerType;
271271
#define MaaDbgControllerType_CarouselImage 1ULL
272272
#define MaaDbgControllerType_ReplayRecording (1ULL << 1)
273273

274+
typedef uint64_t MaaControllerFeature;
275+
#define MaaControllerFeature_None 0
276+
#define MaaControllerFeature_UseMouseDownAndUpInsteadOfClick 1ULL
277+
#define MaaControllerFeature_UseKeyboardDownAndUpInsteadOfClick (1ULL << 1)
278+
274279
typedef struct MaaRect
275280
{
276281
int32_t x;

source/MaaAdbControlUnit/Base/UnitBase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,18 @@ class InputBase
8383
virtual bool init() = 0;
8484

8585
public:
86+
virtual MaaControllerFeature get_features() const = 0;
87+
8688
virtual bool click(int x, int y) = 0;
8789
virtual bool swipe(int x1, int y1, int x2, int y2, int duration) = 0;
8890

89-
virtual bool is_touch_availabled() const = 0;
9091
virtual bool touch_down(int contact, int x, int y, int pressure) = 0;
9192
virtual bool touch_move(int contact, int x, int y, int pressure) = 0;
9293
virtual bool touch_up(int contact) = 0;
9394

9495
virtual bool click_key(int key) = 0;
9596
virtual bool input_text(const std::string& text) = 0;
9697

97-
virtual bool is_key_down_up_availabled() const = 0;
9898
virtual bool key_down(int key) = 0;
9999
virtual bool key_up(int key) = 0;
100100
};

source/MaaAdbControlUnit/EmulatorExtras/MuMuPlayerExtras.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ std::optional<cv::Mat> MuMuPlayerExtras::screencap()
9292
return dst;
9393
}
9494

95+
MaaControllerFeature MuMuPlayerExtras::get_features() const
96+
{
97+
return MaaControllerFeature_UseMouseDownAndUpInsteadOfClick | MaaControllerFeature_UseKeyboardDownAndUpInsteadOfClick;
98+
}
99+
95100
bool MuMuPlayerExtras::click(int x, int y)
96101
{
97102
LogError << "deprecated" << VAR(x) << VAR(y);
@@ -555,6 +560,7 @@ int MuMuPlayerExtras::get_display_id()
555560
return display_id;
556561
}
557562

563+
558564
MAA_CTRL_UNIT_NS_END
559565

560566
#endif

source/MaaAdbControlUnit/EmulatorExtras/MuMuPlayerExtras.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,17 @@ class MuMuPlayerExtras
3030
virtual std::optional<cv::Mat> screencap() override;
3131

3232
public: // from InputBase
33+
virtual MaaControllerFeature get_features() const override;
34+
3335
virtual bool click(int x, int y) override;
3436
virtual bool swipe(int x1, int y1, int x2, int y2, int duration) override;
35-
36-
virtual bool is_touch_availabled() const override { return true; }
37-
3837
virtual bool touch_down(int contact, int x, int y, int pressure) override;
3938
virtual bool touch_move(int contact, int x, int y, int pressure) override;
4039
virtual bool touch_up(int contact) override;
4140

4241
virtual bool click_key(int key) override;
4342
virtual bool input_text(const std::string& text) override;
4443

45-
virtual bool is_key_down_up_availabled() const override { return true; }
46-
4744
virtual bool key_down(int key) override;
4845
virtual bool key_up(int key) override;
4946

source/MaaAdbControlUnit/Input/AdbShellInput.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ bool AdbShellInput::parse(const json::value& config)
2424
&& parse_command("InputText", config, kDefaultInputTextArgv, input_text_argv_);
2525
}
2626

27+
MaaControllerFeature AdbShellInput::get_features() const
28+
{
29+
return MaaControllerFeature_None;
30+
}
31+
2732
bool AdbShellInput::click(int x, int y)
2833
{
2934
LogInfo << VAR(x) << VAR(y);

source/MaaAdbControlUnit/Input/AdbShellInput.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,18 @@ class AdbShellInput : public InputBase
1717
public: // from InputBase
1818
virtual bool init() override { return true; }
1919

20+
virtual MaaControllerFeature get_features() const override;
21+
2022
virtual bool click(int x, int y) override;
2123
virtual bool swipe(int x1, int y1, int x2, int y2, int duration) override;
2224

23-
virtual bool is_touch_availabled() const override { return false; }
24-
2525
virtual bool touch_down(int contact, int x, int y, int pressure) override;
2626
virtual bool touch_move(int contact, int x, int y, int pressure) override;
2727
virtual bool touch_up(int contact) override;
2828

2929
virtual bool click_key(int key) override;
3030
virtual bool input_text(const std::string& text) override;
3131

32-
virtual bool is_key_down_up_availabled() const override { return false; }
33-
3432
virtual bool key_down(int key) override;
3533
virtual bool key_up(int key) override;
3634

source/MaaAdbControlUnit/Input/MaatouchInput.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ bool MaatouchInput::init()
4343
return invoke_and_read_info();
4444
}
4545

46+
MaaControllerFeature MaatouchInput::get_features() const
47+
{
48+
return MaaControllerFeature_UseMouseDownAndUpInsteadOfClick | MaaControllerFeature_UseKeyboardDownAndUpInsteadOfClick;
49+
}
50+
4651
bool MaatouchInput::click_key(int key)
4752
{
4853
LogError << "deprecated" << VAR(key);

source/MaaAdbControlUnit/Input/MaatouchInput.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ class MaatouchInput : public MtouchHelper
2727
public: // from InputBase
2828
virtual bool init() override;
2929

30+
virtual MaaControllerFeature get_features() const override;
31+
3032
virtual bool click_key(int key) override;
3133
virtual bool input_text(const std::string& text) override;
32-
33-
virtual bool is_key_down_up_availabled() const override { return true; }
3434

3535
virtual bool key_down(int key) override;
3636
virtual bool key_up(int key) override;

source/MaaAdbControlUnit/Input/MinitouchInput.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,34 +63,33 @@ bool MinitouchInput::init()
6363
return invoke_and_read_info();
6464
}
6565

66-
bool MinitouchInput::click_key(int key)
66+
MaaControllerFeature MinitouchInput::get_features() const
6767
{
68-
if (!adb_shell_input_) {
69-
LogError << "adb_shell_input_ is nullptr";
70-
return false;
68+
MaaControllerFeature feat = MaaControllerFeature_UseMouseDownAndUpInsteadOfClick;
69+
if (adb_shell_input_) {
70+
feat |= adb_shell_input_->get_features() & MaaControllerFeature_UseKeyboardDownAndUpInsteadOfClick;
7171
}
72-
73-
return adb_shell_input_->click_key(key);
72+
return feat;
7473
}
7574

76-
bool MinitouchInput::input_text(const std::string& text)
75+
bool MinitouchInput::click_key(int key)
7776
{
7877
if (!adb_shell_input_) {
7978
LogError << "adb_shell_input_ is nullptr";
8079
return false;
8180
}
8281

83-
return adb_shell_input_->input_text(text);
82+
return adb_shell_input_->click_key(key);
8483
}
8584

86-
bool MinitouchInput::is_key_down_up_availabled() const
85+
bool MinitouchInput::input_text(const std::string& text)
8786
{
8887
if (!adb_shell_input_) {
8988
LogError << "adb_shell_input_ is nullptr";
9089
return false;
9190
}
9291

93-
return adb_shell_input_->is_key_down_up_availabled();
92+
return adb_shell_input_->input_text(text);
9493
}
9594

9695
bool MinitouchInput::key_down(int key)

0 commit comments

Comments
 (0)