Skip to content

Commit 0c80013

Browse files
authored
Merge branch 'PokemonAutomation:main' into main
2 parents 1ed4552 + 64d8950 commit 0c80013

14 files changed

Lines changed: 521 additions & 130 deletions

File tree

SerialPrograms/Source/CommonFramework/Globals.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace PokemonAutomation{
3636
#endif
3737

3838
#ifndef PA_VERSION_PATCH
39-
#define PA_VERSION_PATCH 2
39+
#define PA_VERSION_PATCH 4
4040
#endif
4141

4242
const bool IS_BETA_VERSION = PA_IS_BETA;
@@ -86,7 +86,7 @@ const std::string DISCORD_LINK_URL_PROGRAM = "https://discord.gg/BSjDp27";
8686
// URL to use in the Discord notifications/embeds.
8787
const std::string DISCORD_LINK_URL_EMBED = "https://discord.gg/xMJcveK";
8888

89-
// URL to use in the DiscordSocialSDK integration.
89+
// URL to use in the DiscordSocialSDK integration.
9090
const std::string DISCORD_LINK_URL_SDK = "https://discord.gg/gn9YEyjjAV";
9191

9292

SerialPrograms/Source/CommonFramework/ImageTools/ImageBoxes.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,25 @@ ImageFloatBox translate_to_parent(
234234
);
235235
}
236236
ImageFloatBox translate_to_parent(
237-
const ImageFloatBox& inference_box,
238-
const ImageFloatBox& box
237+
const ImageFloatBox& outer_relative_to_master,
238+
const ImageFloatBox& inner_relative_to_outer
239+
){
240+
return ImageFloatBox(
241+
outer_relative_to_master.x + inner_relative_to_outer.x * outer_relative_to_master.width,
242+
outer_relative_to_master.y + inner_relative_to_outer.y * outer_relative_to_master.height,
243+
inner_relative_to_outer.width * outer_relative_to_master.width,
244+
inner_relative_to_outer.height * outer_relative_to_master.height
245+
);
246+
}
247+
ImageFloatBox translate_to_child(
248+
const ImageFloatBox& outer_relative_to_master,
249+
const ImageFloatBox& inner_relative_to_master
239250
){
240251
return ImageFloatBox(
241-
inference_box.x + box.x * inference_box.width,
242-
inference_box.y + box.y * inference_box.height,
243-
box.width * inference_box.width,
244-
box.height * inference_box.height
252+
(inner_relative_to_master.x - outer_relative_to_master.x) / outer_relative_to_master.width,
253+
(inner_relative_to_master.y - outer_relative_to_master.y) / outer_relative_to_master.height,
254+
inner_relative_to_master.width / outer_relative_to_master.width,
255+
inner_relative_to_master.height / outer_relative_to_master.height
245256
);
246257
}
247258

SerialPrograms/Source/CommonFramework/ImageTools/ImageBoxes.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,17 @@ ImageFloatBox translate_to_parent(
129129
const ImageFloatBox& inference_box,
130130
const ImagePixelBox& box
131131
);
132+
133+
// Returns "inner_relative_to_master".
132134
ImageFloatBox translate_to_parent(
133-
const ImageFloatBox& inference_box,
134-
const ImageFloatBox& box
135+
const ImageFloatBox& outer_relative_to_master,
136+
const ImageFloatBox& inner_relative_to_outer
137+
);
138+
139+
// Returns "inner_relative_to_outer".
140+
ImageFloatBox translate_to_child(
141+
const ImageFloatBox& outer_relative_to_master,
142+
const ImageFloatBox& inner_relative_to_master
135143
);
136144

137145

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/* Box Option
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include <vector>
8+
#include "Common/Cpp/Strings/StringTools.h"
9+
#include "BoxOption.h"
10+
11+
namespace PokemonAutomation{
12+
13+
14+
BoxOption::~BoxOption(){
15+
BOX_COORDINATES.remove_listener(*this);
16+
HEIGHT.remove_listener(*this);
17+
WIDTH.remove_listener(*this);
18+
Y.remove_listener(*this);
19+
X.remove_listener(*this);
20+
}
21+
BoxOption::BoxOption(
22+
std::string label,
23+
LockMode lock_while_program_is_running,
24+
EnableMode enable_mode,
25+
bool show_restore_defaults_button,
26+
ImageFloatBox box
27+
)
28+
: GroupOption(
29+
std::move(label),
30+
lock_while_program_is_running,
31+
enable_mode,
32+
show_restore_defaults_button
33+
)
34+
, X("<b>X Coordinate:</b>", LockMode::UNLOCK_WHILE_RUNNING, box.x, 0.0, 1.0)
35+
, Y("<b>Y Coordinate:</b>", LockMode::UNLOCK_WHILE_RUNNING, box.y, 0.0, 1.0)
36+
, WIDTH("<b>Width:</b>", LockMode::UNLOCK_WHILE_RUNNING, box.width, 0.0, 1.0)
37+
, HEIGHT("<b>Height:</b>", LockMode::UNLOCK_WHILE_RUNNING, box.height, 0.0, 1.0)
38+
, BOX_COORDINATES(
39+
false,
40+
"ImageFloatBox coordinates",
41+
LockMode::UNLOCK_WHILE_RUNNING,
42+
make_full_str(),
43+
"0.3, 0.3, 0.4, 0.4"
44+
)
45+
{
46+
PA_ADD_OPTION(X);
47+
PA_ADD_OPTION(Y);
48+
PA_ADD_OPTION(WIDTH);
49+
PA_ADD_OPTION(HEIGHT);
50+
PA_ADD_OPTION(BOX_COORDINATES);
51+
52+
BoxOption::on_config_value_changed(&X);
53+
X.add_listener(*this);
54+
Y.add_listener(*this);
55+
WIDTH.add_listener(*this);
56+
HEIGHT.add_listener(*this);
57+
BOX_COORDINATES.add_listener(*this);
58+
}
59+
60+
void BoxOption::on_config_value_changed(void* object){
61+
if (object == &X || object == &Y || object == &WIDTH || object == &HEIGHT){
62+
BOX_COORDINATES.set(make_full_str());
63+
report_value_changed(this);
64+
}else if(object == &BOX_COORDINATES){
65+
std::string box_coord_string = BOX_COORDINATES;
66+
std::vector<std::string> all_coords = StringTools::split(box_coord_string, ", ");
67+
68+
std::string x_string = all_coords[0];
69+
std::string y_string = all_coords[1];
70+
std::string width_string = all_coords[2];
71+
std::string height_string = all_coords[3];
72+
73+
double x_coord = std::stod(x_string);
74+
double y_coord = std::stod(y_string);
75+
double width_coord = std::stod(width_string);
76+
double height_coord = std::stod(height_string);
77+
78+
// cout << box_coord_string << endl;
79+
// cout << std::to_string(x_coord) << endl;
80+
// cout << std::to_string(y_coord) << endl;
81+
// cout << std::to_string(width_coord) << endl;
82+
// cout << std::to_string(height_coord) << endl;
83+
84+
X.set(x_coord);
85+
Y.set(y_coord);
86+
WIDTH.set(width_coord);
87+
HEIGHT.set(height_coord);
88+
}else{
89+
report_value_changed(object);
90+
}
91+
}
92+
93+
94+
95+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* Box Option
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_BoxOption_H
8+
#define PokemonAutomation_BoxOption_H
9+
10+
#include "Common/Cpp/Options/GroupOption.h"
11+
#include "Common/Cpp/Options/FloatingPointOption.h"
12+
#include "Common/Cpp/Options/StringOption.h"
13+
#include "CommonFramework/ImageTools/ImageBoxes.h"
14+
15+
namespace PokemonAutomation{
16+
17+
18+
class BoxOption : public GroupOption, public ConfigOption::Listener{
19+
public:
20+
~BoxOption();
21+
BoxOption(
22+
std::string label,
23+
LockMode lock_while_program_is_running,
24+
EnableMode enable_mode = EnableMode::ALWAYS_ENABLED,
25+
bool show_restore_defaults_button = false,
26+
ImageFloatBox box = {0.3, 0.3, 0.4, 0.4}
27+
);
28+
29+
operator ImageFloatBox() const{
30+
return {X, Y, WIDTH, HEIGHT};
31+
}
32+
ImageFloatBox inner_to_outer(const ImageFloatBox& inner_box) const{
33+
return translate_to_parent(*this, inner_box);
34+
}
35+
36+
virtual void on_config_value_changed(void* object) override;
37+
38+
private:
39+
std::string make_full_str() const{
40+
return
41+
std::to_string(X) + ", " +
42+
std::to_string(Y) + ", " +
43+
std::to_string(WIDTH) + ", " +
44+
std::to_string(HEIGHT);
45+
}
46+
47+
public:
48+
FloatingPointOption X;
49+
FloatingPointOption Y;
50+
FloatingPointOption WIDTH;
51+
FloatingPointOption HEIGHT;
52+
StringOption BOX_COORDINATES;
53+
};
54+
55+
56+
57+
}
58+
#endif

SerialPrograms/Source/NintendoSwitch/DevPrograms/BoxDraw.cpp

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <optional>
88
#include "Common/Cpp/Concurrency/Mutex.h"
99
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
10-
#include "Common/Cpp/Strings/StringTools.h"
1110
#include "BoxDraw.h"
1211

1312
//#include <iostream>
@@ -19,85 +18,6 @@ namespace NintendoSwitch{
1918

2019

2120

22-
BoxDrawGroup::~BoxDrawGroup(){
23-
BOX_COORDINATES.remove_listener(*this);
24-
HEIGHT.remove_listener(*this);
25-
WIDTH.remove_listener(*this);
26-
Y.remove_listener(*this);
27-
X.remove_listener(*this);
28-
}
29-
BoxDrawGroup::BoxDrawGroup(
30-
std::string label,
31-
LockMode lock_while_program_is_running,
32-
EnableMode enable_mode,
33-
bool show_restore_defaults_button,
34-
ImageFloatBox box
35-
)
36-
: GroupOption(
37-
std::move(label),
38-
lock_while_program_is_running,
39-
enable_mode,
40-
show_restore_defaults_button
41-
)
42-
, X("<b>X Coordinate:</b>", LockMode::UNLOCK_WHILE_RUNNING, box.x, 0.0, 1.0)
43-
, Y("<b>Y Coordinate:</b>", LockMode::UNLOCK_WHILE_RUNNING, box.y, 0.0, 1.0)
44-
, WIDTH("<b>Width:</b>", LockMode::UNLOCK_WHILE_RUNNING, box.width, 0.0, 1.0)
45-
, HEIGHT("<b>Height:</b>", LockMode::UNLOCK_WHILE_RUNNING, box.height, 0.0, 1.0)
46-
, BOX_COORDINATES(
47-
false,
48-
"ImageFloatBox coordinates",
49-
LockMode::UNLOCK_WHILE_RUNNING,
50-
make_full_str(),
51-
"0.3, 0.3, 0.4, 0.4"
52-
)
53-
{
54-
PA_ADD_OPTION(X);
55-
PA_ADD_OPTION(Y);
56-
PA_ADD_OPTION(WIDTH);
57-
PA_ADD_OPTION(HEIGHT);
58-
PA_ADD_OPTION(BOX_COORDINATES);
59-
60-
BoxDrawGroup::on_config_value_changed(&X);
61-
X.add_listener(*this);
62-
Y.add_listener(*this);
63-
WIDTH.add_listener(*this);
64-
HEIGHT.add_listener(*this);
65-
BOX_COORDINATES.add_listener(*this);
66-
}
67-
68-
void BoxDrawGroup::on_config_value_changed(void* object){
69-
if (object == &X || object == &Y || object == &WIDTH || object == &HEIGHT){
70-
BOX_COORDINATES.set(make_full_str());
71-
report_value_changed(this);
72-
}else if(object == &BOX_COORDINATES){
73-
std::string box_coord_string = BOX_COORDINATES;
74-
std::vector<std::string> all_coords = StringTools::split(box_coord_string, ", ");
75-
76-
std::string x_string = all_coords[0];
77-
std::string y_string = all_coords[1];
78-
std::string width_string = all_coords[2];
79-
std::string height_string = all_coords[3];
80-
81-
double x_coord = std::stod(x_string);
82-
double y_coord = std::stod(y_string);
83-
double width_coord = std::stod(width_string);
84-
double height_coord = std::stod(height_string);
85-
86-
// cout << box_coord_string << endl;
87-
// cout << std::to_string(x_coord) << endl;
88-
// cout << std::to_string(y_coord) << endl;
89-
// cout << std::to_string(width_coord) << endl;
90-
// cout << std::to_string(height_coord) << endl;
91-
92-
X.set(x_coord);
93-
Y.set(y_coord);
94-
WIDTH.set(width_coord);
95-
HEIGHT.set(height_coord);
96-
}else{
97-
report_value_changed(object);
98-
}
99-
}
100-
10121

10222

10323

SerialPrograms/Source/NintendoSwitch/DevPrograms/BoxDraw.h

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,13 @@
77
#ifndef PokemonAutomation_NintendoSwitch_BoxDraw_H
88
#define PokemonAutomation_NintendoSwitch_BoxDraw_H
99

10-
#include "Common/Cpp/Options/FloatingPointOption.h"
11-
#include "Common/Cpp/Options/StringOption.h"
12-
#include "Common/Cpp/Options/GroupOption.h"
13-
#include "CommonFramework/ImageTools/ImageBoxes.h"
10+
#include "CommonFramework/Options/BoxOption.h"
1411
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
1512

1613
namespace PokemonAutomation{
1714
namespace NintendoSwitch{
1815

1916

20-
class BoxDrawGroup : public GroupOption, public ConfigOption::Listener{
21-
public:
22-
~BoxDrawGroup();
23-
BoxDrawGroup(
24-
std::string label,
25-
LockMode lock_while_program_is_running,
26-
EnableMode enable_mode = EnableMode::ALWAYS_ENABLED,
27-
bool show_restore_defaults_button = false,
28-
ImageFloatBox box = {0.3, 0.3, 0.4, 0.4}
29-
);
30-
31-
virtual void on_config_value_changed(void* object) override;
32-
33-
private:
34-
std::string make_full_str() const{
35-
return
36-
std::to_string(X) + ", " +
37-
std::to_string(Y) + ", " +
38-
std::to_string(WIDTH) + ", " +
39-
std::to_string(HEIGHT);
40-
}
41-
42-
public:
43-
FloatingPointOption X;
44-
FloatingPointOption Y;
45-
FloatingPointOption WIDTH;
46-
FloatingPointOption HEIGHT;
47-
StringOption BOX_COORDINATES;
48-
};
49-
5017

5118

5219
class BoxDraw_Descriptor : public SingleSwitchProgramDescriptor{
@@ -66,8 +33,8 @@ class BoxDraw : public SingleSwitchProgramInstance{
6633
class DrawnBox;
6734

6835
private:
69-
BoxDrawGroup INFERENCE_BOX;
70-
BoxDrawGroup CONTENT_BOX;
36+
BoxOption INFERENCE_BOX;
37+
BoxOption CONTENT_BOX;
7138
};
7239

7340

0 commit comments

Comments
 (0)