Skip to content

Commit e78dd71

Browse files
committed
use start menu arrow detection
1 parent 7cd7e50 commit e78dd71

5 files changed

Lines changed: 70 additions & 71 deletions

File tree

SerialPrograms/Source/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,39 @@ bool AdvanceBattleDialogDetector::detect(const ImageViewRGB32& screen){
164164
return false;
165165
}
166166

167+
BattleLearnDialogDetector::BattleLearnDialogDetector(Color color)
168+
: m_menu_top_box(0.805, 0.445, 0.149, 0.006)
169+
, m_menu_right_box(0.962, 0.445, 0.006, 0.200) // right side, Yes/No selection
170+
, m_dialog_top_box(0.036, 0.763, 0.459, 0.014)
171+
, m_dialog_right_box(0.941, 0.763, 0.006, 0.179) //right side, closest to the menu
172+
{}
173+
void BattleLearnDialogDetector::make_overlays(VideoOverlaySet& items) const{
174+
const BoxOption& GAME_BOX = GameSettings::instance().GAME_BOX;
175+
items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_menu_top_box));
176+
items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_menu_right_box));
177+
items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_dialog_top_box));
178+
items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_dialog_right_box));
179+
}
180+
bool BattleLearnDialogDetector::detect(const ImageViewRGB32& screen){
181+
ImageViewRGB32 game_screen = extract_box_reference(screen, GameSettings::instance().GAME_BOX);
182+
183+
//Menu is white
184+
ImageViewRGB32 menu_top_image = extract_box_reference(game_screen, m_menu_top_box);
185+
ImageViewRGB32 menu_right_image = extract_box_reference(game_screen, m_menu_right_box);
186+
187+
//Background dialog is teal
188+
ImageViewRGB32 dialog_top_image = extract_box_reference(game_screen, m_dialog_top_box);
189+
ImageViewRGB32 dialog_right_image = extract_box_reference(game_screen, m_dialog_right_box);
190+
191+
if (is_white(menu_top_image)
192+
&& is_white(menu_right_image)
193+
&& is_solid(dialog_top_image, { 0.176, 0.357, 0.467 }, 0.25, 20) //40, 81, 106 teal
194+
&& is_solid(dialog_right_image, { 0.176, 0.357, 0.467 }, 0.25, 20)
195+
){
196+
return true;
197+
}
198+
return false;
199+
}
167200

168201

169202

SerialPrograms/Source/PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,28 @@ class AdvanceBattleDialogWatcher : public DetectorToFinder<AdvanceBattleDialogDe
101101
};
102102

103103

104+
// Similar to BattleMenuDetector, but looks for the white of the Yes/No box when learning a new move
105+
class BattleLearnDialogDetector : public StaticScreenDetector{
106+
public:
107+
BattleLearnDialogDetector(Color color);
108+
109+
virtual void make_overlays(VideoOverlaySet& items) const override;
110+
virtual bool detect(const ImageViewRGB32& screen) override;
111+
112+
private:
113+
ImageFloatBox m_menu_top_box;
114+
ImageFloatBox m_menu_right_box;
115+
ImageFloatBox m_dialog_top_box;
116+
ImageFloatBox m_dialog_right_box;
117+
};
118+
class BattleLearnDialogWatcher : public DetectorToFinder<BattleLearnDialogDetector>{
119+
public:
120+
BattleLearnDialogWatcher(Color color)
121+
: DetectorToFinder("BattleLearnDialogDetector", std::chrono::milliseconds(250), color)
122+
{}
123+
};
124+
125+
104126

105127
}
106128
}

SerialPrograms/Source/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.cpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -127,41 +127,6 @@ bool SelectionDialogDetector::detect(const ImageViewRGB32& screen){
127127
return false;
128128
}
129129

130-
131-
BattleLearnDialogDetector::BattleLearnDialogDetector(Color color)
132-
: m_menu_top_box(0.805, 0.445, 0.149, 0.006)
133-
, m_menu_right_box(0.962, 0.445, 0.006, 0.200) // right side, Yes/No selection
134-
, m_dialog_top_box(0.036, 0.763, 0.459, 0.014)
135-
, m_dialog_right_box(0.941, 0.763, 0.006, 0.179) //right side, closest to the menu
136-
{}
137-
void BattleLearnDialogDetector::make_overlays(VideoOverlaySet& items) const{
138-
const BoxOption& GAME_BOX = GameSettings::instance().GAME_BOX;
139-
items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_menu_top_box));
140-
items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_menu_right_box));
141-
items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_dialog_top_box));
142-
items.add(COLOR_RED, GAME_BOX.inner_to_outer(m_dialog_right_box));
143-
}
144-
bool BattleLearnDialogDetector::detect(const ImageViewRGB32& screen){
145-
ImageViewRGB32 game_screen = extract_box_reference(screen, GameSettings::instance().GAME_BOX);
146-
147-
//Menu is white
148-
ImageViewRGB32 menu_top_image = extract_box_reference(game_screen, m_menu_top_box);
149-
ImageViewRGB32 menu_right_image = extract_box_reference(game_screen, m_menu_right_box);
150-
151-
//Background dialog is teal
152-
ImageViewRGB32 dialog_top_image = extract_box_reference(game_screen, m_dialog_top_box);
153-
ImageViewRGB32 dialog_right_image = extract_box_reference(game_screen, m_dialog_right_box);
154-
155-
if (is_white(menu_top_image)
156-
&& is_white(menu_right_image)
157-
&& is_solid(dialog_top_image, { 0.176, 0.357, 0.467 }, 0.25, 20) //40, 81, 106 teal
158-
&& is_solid(dialog_right_image, { 0.176, 0.357, 0.467 }, 0.25, 20)
159-
){
160-
return true;
161-
}
162-
return false;
163-
}
164-
165130
PartyMenuDetector::PartyMenuDetector(Color color)
166131
: m_dialog_top_box(0.028, 0.840, 0.705, 0.010)
167132
, m_page_background_box(0.028, 0.500, 0.010, 0.250)

SerialPrograms/Source/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -128,29 +128,6 @@ class SelectionDialogWatcher : public DetectorToFinder<SelectionDialogDetector>{
128128
};
129129

130130

131-
// Similar to BattleMenuDetector, but looks for the white of the Yes/No box when learning a new move
132-
class BattleLearnDialogDetector : public StaticScreenDetector{
133-
public:
134-
BattleLearnDialogDetector(Color color);
135-
136-
virtual void make_overlays(VideoOverlaySet& items) const override;
137-
virtual bool detect(const ImageViewRGB32& screen) override;
138-
139-
private:
140-
ImageFloatBox m_menu_top_box;
141-
ImageFloatBox m_menu_right_box;
142-
ImageFloatBox m_dialog_top_box;
143-
ImageFloatBox m_dialog_right_box;
144-
};
145-
class BattleLearnDialogWatcher : public DetectorToFinder<BattleLearnDialogDetector>{
146-
public:
147-
BattleLearnDialogWatcher(Color color)
148-
: DetectorToFinder("BattleLearnDialogDetector", std::chrono::milliseconds(250), color)
149-
{}
150-
};
151-
152-
153-
154131
// The Party menu has a white box on the bottom
155132
// The background around the edges is dark teal/navy
156133
class PartyMenuDetector : public StaticScreenDetector{
@@ -191,6 +168,9 @@ class PartySelectionWatcher : public DetectorToFinder<PartySelectionDetector>{
191168
{}
192169
};
193170

171+
172+
173+
194174
}
195175
}
196176
}

SerialPrograms/Source/PokemonFRLG/Programs/Farming/PokemonFRLG_PickupFarmer.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
1717
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
1818
#include "PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h"
19+
#include "PokemonFRLG/Inference/Dialogs/PokemonFRLG_BattleDialogs.h"
1920
#include "PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.h"
21+
#include "PokemonFRLG/Inference/PokemonFRLG_SelectionArrowDetector.h"
22+
#include "PokemonFRLG/Programs/PokemonFRLG_StartMenuNavigation.h"
2023
#include "PokemonFRLG/PokemonFRLG_Navigation.h"
2124
#include "PokemonFRLG_PickupFarmer.h"
2225

@@ -172,7 +175,15 @@ void close_start_menu(SingleSwitchProgramEnvironment& env, ProControllerContext&
172175
void open_party_menu_from_overworld(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
173176
PartyMenuWatcher party_open(COLOR_RED);
174177
open_start_menu(env, context);
175-
int ret = run_until<ProControllerContext>(
178+
int ret = move_cursor_to_position(env.console, context, SelectionArrowPositionStartMenu::POKEMON);
179+
if (ret < 0){
180+
OperationFailedException::fire(
181+
ErrorReport::SEND_ERROR_REPORT,
182+
"Failed to navigate to POKEMON on the Start menu.",
183+
env.console
184+
);
185+
}
186+
ret = run_until<ProControllerContext>(
176187
env.console, context,
177188
[](ProControllerContext& context) {
178189
for (int i = 0; i<2; i++){
@@ -191,16 +202,6 @@ void open_party_menu_from_overworld(SingleSwitchProgramEnvironment& env, ProCont
191202
}
192203
}
193204

194-
void prepare_start_menu(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
195-
env.log("Selecting 'Pokemon' on the Start Menu.");
196-
open_start_menu(env, context);
197-
// Should use arrow detection for this when it is available
198-
// set the menu to "Pokemon" and exit
199-
pbf_move_left_joystick(context, {0, -1}, 200ms, 300ms);
200-
pbf_press_button(context, BUTTON_B, 200ms, 300ms);
201-
close_start_menu(env, context);
202-
}
203-
204205
void use_teleport(SingleSwitchProgramEnvironment& env, ProControllerContext& context){
205206
env.log("Using Teleport.");
206207
open_party_menu_from_overworld(env, context);
@@ -533,8 +534,6 @@ void PickupFarmer::program(SingleSwitchProgramEnvironment& env, ProControllerCon
533534
bool spin_leftright = true;
534535
uint16_t moves_used = 0;
535536
uint16_t encounters_since_item_check = 0;
536-
537-
prepare_start_menu(env, context);
538537

539538
while (!shiny_found){
540539
if (stats.encounters == 0 || failed_encounter || moves_used >= MOVE_PP){

0 commit comments

Comments
 (0)