Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* Naming Screen Detector
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "CommonFramework/ImageTools/FloatPixel.h"
#include "CommonTools/Images/SolidColorTest.h"
#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h"
#include "PokemonFRLG_NamingScreenDetector.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{


namespace{

// Keyboard fill colors by page (keyboard.pal 13, 14, 15) as channel ratios:
// (123, 172, 197), (213, 156, 115), (148, 189, 106).
const FloatPixel KEYBOARD_COLORS[] = {
{0.250, 0.350, 0.400}, // upper case
{0.440, 0.322, 0.238}, // lower case
{0.334, 0.427, 0.239}, // symbols
};

bool is_keyboard_color(const ImageViewRGB32& image, const FloatPixel& color){
return is_solid(image, color, 0.08, 30);
}

}

Check failure on line 31 in SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

namespace-close: close this namespace with // namespace


// Boxes are fractions of the 240x160 GBA screen inside the game box.
NamingScreenDetector::NamingScreenDetector(Color color)
: m_color(color)
, m_keyboard_left_box(25.0 / 240, 82.0 / 160, 4.0 / 240, 60.0 / 160) // x 25-29, y 82-142
, m_keyboard_right_box(170.0 / 240, 82.0 / 160, 5.0 / 240, 60.0 / 160) // x 170-175, y 82-142
, m_entry_box(168.0 / 240, 50.0 / 160, 6.0 / 240, 12.0 / 160) // x 168-174, y 50-62
{}
void NamingScreenDetector::make_overlays(VideoOverlaySet& items) const{
const BoxOption& GAME_BOX = GameSettings::instance().GAME_BOX;
items.add(m_color, GAME_BOX.inner_to_outer(m_keyboard_left_box));
items.add(m_color, GAME_BOX.inner_to_outer(m_keyboard_right_box));
items.add(m_color, GAME_BOX.inner_to_outer(m_entry_box));
}
bool NamingScreenDetector::detect(const ImageViewRGB32& screen){
ImageViewRGB32 game_screen = extract_box_reference(screen, GameSettings::instance().GAME_BOX);
ImageViewRGB32 left = extract_box_reference(game_screen, m_keyboard_left_box);
ImageViewRGB32 right = extract_box_reference(game_screen, m_keyboard_right_box);
if (!is_white(extract_box_reference(game_screen, m_entry_box))){
return false;
}
for (const FloatPixel& color : KEYBOARD_COLORS){
if (is_keyboard_color(left, color) && is_keyboard_color(right, color)){
return true;
}
}
return false;
}


}

Check failure on line 63 in SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

namespace-close: close this namespace with // namespace PokemonFRLG
}

Check failure on line 64 in SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

namespace-close: close this namespace with // namespace NintendoSwitch
}

Check failure on line 65 in SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

namespace-close: close this namespace with // namespace PokemonAutomation
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* Naming Screen Detector
*
* From: https://github.com/PokemonAutomation/
*
* Detects the in-game keyboard used to name the player, the rival, boxes and Pokemon.
*
* The boxes and colors come from pret/pokefirered src/naming_screen.c (commit
* ce6406d8c2eaf46d543c8a2606de0c3cb1951982), not from screenshots: the keyboard window
* covers tiles (3, 10)-(22, 18) and is filled with keyboard.pal color 13, 14 or 15 by page,
* and the text entry window at tiles (8, 6)-(22, 8) is white.
* Not yet checked against a capture.
*
*/

#ifndef PokemonAutomation_PokemonFRLG_NamingScreenDetector_H
#define PokemonAutomation_PokemonFRLG_NamingScreenDetector_H

#include <chrono>
#include "Common/Cpp/Color.h"
#include "CommonFramework/ImageTools/ImageBoxes.h"
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "CommonTools/VisualDetector.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{


class NamingScreenDetector : public StaticScreenDetector{

Check failure on line 30 in SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h

View workflow job for this annotation

GitHub Actions / code-health

Code health

header-comment: document each namespace-scope header symbol
public:
NamingScreenDetector(Color color = COLOR_RED);

virtual void make_overlays(VideoOverlaySet& items) const override;
virtual bool detect(const ImageViewRGB32& screen) override;

private:
Color m_color;
// The keyboard's margins left and right of the keys, clear of the cursor.
ImageFloatBox m_keyboard_left_box;
ImageFloatBox m_keyboard_right_box;
// The text entry window, right of the last character.
ImageFloatBox m_entry_box;
};
class NamingScreenWatcher : public DetectorToFinder<NamingScreenDetector>{

Check failure on line 45 in SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h

View workflow job for this annotation

GitHub Actions / code-health

Code health

header-comment: document each namespace-scope header symbol
public:
NamingScreenWatcher(Color color = COLOR_RED)
: DetectorToFinder("NamingScreenWatcher", std::chrono::milliseconds(250), color)
{}
};


}

Check failure on line 53 in SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h

View workflow job for this annotation

GitHub Actions / code-health

Code health

namespace-close: close this namespace with // namespace PokemonFRLG
}

Check failure on line 54 in SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h

View workflow job for this annotation

GitHub Actions / code-health

Code health

namespace-close: close this namespace with // namespace NintendoSwitch
}

Check failure on line 55 in SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_NamingScreenDetector.h

View workflow job for this annotation

GitHub Actions / code-health

Code health

namespace-close: close this namespace with // namespace PokemonAutomation

#endif
Loading
Loading