Skip to content

Commit b573ab8

Browse files
authored
Merge branch 'PokemonAutomation:main' into main
2 parents c7f6a8b + 15ecdac commit b573ab8

4 files changed

Lines changed: 110 additions & 3 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* Load Menu Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include "CommonTools/Images/SolidColorTest.h"
8+
#include "CommonTools/Images/ImageFilter.h"
9+
#include "CommonFramework/ImageTools/ImageBoxes.h"
10+
#include "CommonFramework/ImageTypes/ImageRGB32.h"
11+
#include "CommonFramework/ImageTools/ImageStats.h"
12+
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
13+
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
14+
#include "CommonTools/Images/SolidColorTest.h"
15+
#include "CommonTools/Images/WaterfillUtilities.h"
16+
#include "CommonTools/ImageMatch/WaterfillTemplateMatcher.h"
17+
#include "CommonFramework/VideoPipeline/VideoOverlay.h"
18+
#include "PokemonFRLG_LoadMenuDetector.h"
19+
20+
namespace PokemonAutomation{
21+
namespace NintendoSwitch{
22+
namespace PokemonFRLG{
23+
24+
LoadMenuDetector::LoadMenuDetector(Color color)
25+
: m_right_box(0.859, 0.023, 0.042, 0.925)
26+
, m_left_box(0.099, 0.022, 0.046, 0.926)
27+
, m_save_box(0.773, 0.062, 0.047, 0.072)
28+
{}
29+
void LoadMenuDetector::make_overlays(VideoOverlaySet& items) const{
30+
items.add(COLOR_BLUE, m_right_box);
31+
items.add(COLOR_BLUE, m_left_box);
32+
items.add(COLOR_BLUE, m_save_box);
33+
}
34+
bool LoadMenuDetector::detect(const ImageViewRGB32& screen){
35+
ImageViewRGB32 right_image = extract_box_reference(screen, m_right_box);
36+
ImageViewRGB32 left_image = extract_box_reference(screen, m_left_box);
37+
ImageViewRGB32 save_image = extract_box_reference(screen, m_save_box);
38+
39+
if (is_solid(right_image, { 0.244, 0.282, 0.474 }) //blue
40+
&& is_solid(left_image, { 0.244, 0.282, 0.474 }) //blue
41+
&& is_solid(save_image, { 0.25, 0.38, 0.369 }) //white
42+
){
43+
return true;
44+
}
45+
return false;
46+
}
47+
48+
49+
}
50+
}
51+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/* Load Menu Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonFRLG_LoadMenuDetector_H
8+
#define PokemonAutomation_PokemonFRLG_LoadMenuDetector_H
9+
10+
#include <chrono>
11+
#include <atomic>
12+
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
13+
#include "Common/Cpp/Color.h"
14+
#include "CommonFramework/ImageTools/ImageBoxes.h"
15+
#include "CommonTools/VisualDetector.h"
16+
#include "CommonTools/InferenceCallbacks/VisualInferenceCallback.h"
17+
18+
namespace PokemonAutomation{
19+
class CancellableScope;
20+
class VideoFeed;
21+
namespace NintendoSwitch{
22+
namespace PokemonFRLG{
23+
24+
// Detect save load menu by looking for the blue on the sides and the white of the save file
25+
// Untested on new game, assumes there's a save.
26+
class LoadMenuDetector : public StaticScreenDetector{
27+
public:
28+
LoadMenuDetector(Color color);
29+
30+
virtual void make_overlays(VideoOverlaySet& items) const override;
31+
virtual bool detect(const ImageViewRGB32& screen) override;
32+
33+
private:
34+
ImageFloatBox m_right_box;
35+
ImageFloatBox m_left_box;
36+
ImageFloatBox m_save_box;
37+
};
38+
class LoadMenuWatcher : public DetectorToFinder<LoadMenuDetector>{
39+
public:
40+
LoadMenuWatcher(Color color)
41+
: DetectorToFinder("LoadMenuWatcher", std::chrono::milliseconds(250), color)
42+
{}
43+
};
44+
45+
46+
}
47+
}
48+
}
49+
50+
#endif

SerialPrograms/Source/PokemonFRLG/PokemonFRLG_Navigation.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h"
1818
#include "PokemonFRLG/Inference/Sounds/PokemonFRLG_ShinySoundDetector.h"
1919
#include "PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.h"
20+
#include "PokemonFRLG/Inference/Menus/PokemonFRLG_LoadMenuDetector.h"
2021
#include "PokemonFRLG/PokemonFRLG_Settings.h"
2122
#include "PokemonFRLG_Navigation.h"
2223

@@ -40,6 +41,7 @@ void soft_reset(ConsoleHandle& console, ProControllerContext& context){
4041

4142
//Mash A until white screen to game load menu
4243
WhiteScreenOverWatcher whitescreen(COLOR_RED, {0.282, 0.064, 0.448, 0.871});
44+
LoadMenuWatcher load_menu(COLOR_BLUE);
4345

4446
int ls = run_until<ProControllerContext>(
4547
console, context,
@@ -48,11 +50,13 @@ void soft_reset(ConsoleHandle& console, ProControllerContext& context){
4850
pbf_wait(context, 5000ms);
4951
context.wait_for_all_requests();
5052
},
51-
{ whitescreen }
53+
{ whitescreen, load_menu }
5254
);
5355
context.wait_for_all_requests();
54-
if (ls == 0){
55-
console.log("Entered load menu.");
56+
if (ls == 0) {
57+
console.log("Entered load menu. (WhiteScreenOver)");
58+
}else if (ls == 1) {
59+
console.log("Entered load menu. (LoadMenu)");
5660
}else{
5761
console.log("Unable to enter load menu.", COLOR_RED);
5862
OperationFailedException::fire(

SerialPrograms/cmake/SourceFiles.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,8 @@ file(GLOB LIBRARY_SOURCES
14121412
Source/PokemonFRLG/Inference/Dialogs/PokemonFRLG_PrizeSelectDetector.h
14131413
Source/PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.cpp
14141414
Source/PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.h
1415+
Source/PokemonFRLG/Inference/Menus/PokemonFRLG_LoadMenuDetector.cpp
1416+
Source/PokemonFRLG/Inference/Menus/PokemonFRLG_LoadMenuDetector.h
14151417
Source/PokemonFRLG/Inference/Sounds/PokemonFRLG_ShinySoundDetector.cpp
14161418
Source/PokemonFRLG/Inference/Sounds/PokemonFRLG_ShinySoundDetector.h
14171419
Source/PokemonFRLG/Inference/PokemonFRLG_ShinySymbolDetector.cpp

0 commit comments

Comments
 (0)