Skip to content

Commit 0896e03

Browse files
committed
lgpe battle menu detector
1 parent ef1c5ab commit 0896e03

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,8 @@ file(GLOB MAIN_SOURCES
13751375
Source/PokemonLA/Resources/PokemonLA_WeatherAndTimeIcons.h
13761376
Source/PokemonLGPE/Commands/PokemonLGPE_DateSpam.cpp
13771377
Source/PokemonLGPE/Commands/PokemonLGPE_DateSpam.h
1378+
Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleMenuDetector.cpp
1379+
Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleMenuDetector.h
13781380
Source/PokemonLGPE/Inference/Sounds/PokemonLGPE_ShinySoundDetector.cpp
13791381
Source/PokemonLGPE/Inference/Sounds/PokemonLGPE_ShinySoundDetector.h
13801382
Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.cpp

SerialPrograms/SerialPrograms.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ SOURCES += \
674674
Source/PokemonLA/Resources/PokemonLA_PokemonSprites.cpp \
675675
Source/PokemonLA/Resources/PokemonLA_WeatherAndTimeIcons.cpp \
676676
Source/PokemonLGPE/Commands/PokemonLGPE_DateSpam.cpp \
677+
Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleMenuDetector.cpp \
677678
Source/PokemonLGPE/Inference/Sounds/PokemonLGPE_ShinySoundDetector.cpp \
678679
Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.cpp \
679680
Source/PokemonLGPE/Programs/Farming/PokemonLGPE_DailyItemFarmer.cpp \
@@ -1871,6 +1872,7 @@ HEADERS += \
18711872
Source/PokemonLA/Resources/PokemonLA_PokemonSprites.h \
18721873
Source/PokemonLA/Resources/PokemonLA_WeatherAndTimeIcons.h \
18731874
Source/PokemonLGPE/Commands/PokemonLGPE_DateSpam.h \
1875+
Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleMenuDetector.h \
18741876
Source/PokemonLGPE/Inference/Sounds/PokemonLGPE_ShinySoundDetector.h \
18751877
Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.h \
18761878
Source/PokemonLGPE/Programs/Farming/PokemonLGPE_DailyItemFarmer.h \
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* Battle 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 "PokemonLGPE_BattleMenuDetector.h"
15+
16+
namespace PokemonAutomation{
17+
namespace NintendoSwitch{
18+
namespace PokemonLGPE{
19+
20+
BattleMenuDetector::BattleMenuDetector(Color color)
21+
: m_your_box(0.114, 0.916, 0.016, 0.027)
22+
, m_opponent_box(0.904, 0.048, 0.022, 0.031)
23+
{}
24+
void BattleMenuDetector::make_overlays(VideoOverlaySet& items) const{
25+
items.add(COLOR_RED, m_your_box);
26+
items.add(COLOR_RED, m_opponent_box);
27+
}
28+
bool BattleMenuDetector::detect(const ImageViewRGB32& screen) const{
29+
ImageViewRGB32 left_image = extract_box_reference(screen, m_your_box);
30+
ImageViewRGB32 right_image = extract_box_reference(screen, m_opponent_box);
31+
32+
//Has a bit of a gradient in the box
33+
//TODO: Do more boxes, horizonal so less gradient variation.
34+
if (is_solid(left_image, { 0.040, 0.467, 0.493 }) && is_solid(right_image, { 0.074, 0.458, 0.468 })){
35+
return true;
36+
}
37+
return false;
38+
}
39+
40+
41+
42+
}
43+
}
44+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* Battle Menu Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonLGPE_BattleMenuDetector_H
8+
#define PokemonAutomation_PokemonLGPE_BattleMenuDetector_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 PokemonLGPE{
23+
24+
//Detect the light blue of your HP box and your opponent's HP box
25+
class BattleMenuDetector : public StaticScreenDetector{
26+
public:
27+
BattleMenuDetector(Color color);
28+
29+
virtual void make_overlays(VideoOverlaySet& items) const override;
30+
virtual bool detect(const ImageViewRGB32& screen) const override;
31+
32+
private:
33+
ImageFloatBox m_your_box;
34+
ImageFloatBox m_opponent_box;
35+
};
36+
class BattleMenuWatcher : public DetectorToFinder<BattleMenuDetector>{
37+
public:
38+
BattleMenuWatcher(Color color)
39+
: DetectorToFinder("BattleMenuWatcher", std::chrono::milliseconds(250), color)
40+
{}
41+
};
42+
43+
//Battle dialog detector - white of the box
44+
45+
/*
46+
Possible future improvements:
47+
Detect arrow and position
48+
|Fight|Pokemon|Bag|Run| for wild battle
49+
|---|Fight|Pokemon|Bag| for trainer battle
50+
(align right)
51+
52+
Detect Y Info button located next to menu.
53+
Don't know what changes for a double battle.
54+
*/
55+
56+
}
57+
}
58+
}
59+
60+
#endif

0 commit comments

Comments
 (0)