Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,26 @@ class DialogTealArrowMatcher : public ImageMatch::WaterfillTemplateMatcher{
}
};

class DialogBlueArrowMatcher : public ImageMatch::WaterfillTemplateMatcher{
public:
DialogBlueArrowMatcher()
: WaterfillTemplateMatcher(
"PokemonLZA/DialogBox/DialogBoxBlueArrow-Template.png",
Color(0xff005460), Color(0xff6BBEC9), 50
)
{
m_aspect_ratio_lower = 0.9;
m_aspect_ratio_upper = 1.1;
m_area_ratio_lower = 0.8;
m_area_ratio_upper = 1.1;
}

static const ImageMatch::WaterfillTemplateMatcher& instance() {
static DialogBlueArrowMatcher matcher;
return matcher;
}
};


namespace {

Expand Down Expand Up @@ -143,6 +163,33 @@ bool detect_white_arrow(const ImageViewRGB32& screen, PokemonAutomation::ImageFl
return found;
}

bool detect_blue_arrow(const ImageViewRGB32& screen, PokemonAutomation::ImageFloatBox& found_box){
double screen_rel_size = (screen.height() / 1080.0);
double screen_rel_size_2 = screen_rel_size * screen_rel_size;

double min_area_1080p = 150.0;
double rmsd_threshold = 120.0;
size_t min_area = size_t(screen_rel_size_2 * min_area_1080p);

const std::vector<std::pair<uint32_t, uint32_t>> FILTERS = {
{0x005460, 0xff7FC0C9},
};

bool found = match_template_by_waterfill(
screen.size(),
extract_box_reference(screen, DIALOG_ARROW_BOX),
DialogBlueArrowMatcher::instance(),
FILTERS,
{min_area, SIZE_MAX},
rmsd_threshold,
[&](Kernels::Waterfill::WaterfillObject& object) -> bool {
found_box = translate_to_parent(screen, DIALOG_ARROW_BOX, object);
return true;
}
);
return found;
}

} // end anonymous namespace


Expand Down Expand Up @@ -486,6 +533,43 @@ bool TransparentBattleDialogDetector::detect(const ImageViewRGB32& screen){
}


LightBlueDialogDetector::LightBlueDialogDetector(Color color, VideoOverlay* overlay)
: m_color(color)
, m_overlay(overlay)
, m_corner(0.765093, 0.933594, 0.006586, 0.013672)
{}
void LightBlueDialogDetector::make_overlays(VideoOverlaySet& items) const{
items.add(m_color, m_corner);
items.add(m_color, DIALOG_ARROW_BOX);
}
bool LightBlueDialogDetector::detect(const ImageViewRGB32& screen){
do{
if (is_solid(
extract_box_reference(screen, m_corner),
{0.108317, 0.462282, 0.429400},
0.25
)){
break;
}
m_last_detected_box_scope.reset();
// cout << "not solid" << endl;
return false;
}while (false);

const bool found = detect_blue_arrow(screen, m_last_detected_box);

if (m_overlay){
if (found){
m_last_detected_box_scope.emplace(*m_overlay, m_last_detected_box, COLOR_GREEN);
}else{
m_last_detected_box_scope.reset();
}
}

return found;
}



}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,37 @@ class TransparentBattleDialogWatcher : public DetectorToFinder<TransparentBattle
};


// Light blue dialog box for holograms
class LightBlueDialogDetector : public StaticScreenDetector{
public:
LightBlueDialogDetector(Color color = COLOR_RED, VideoOverlay* overlay = nullptr);

virtual void make_overlays(VideoOverlaySet& items) const override;

// This is not const so that detectors can save/cache state.
virtual bool detect(const ImageViewRGB32& screen) override;

private:
friend class LightBlueDialogWatcher;

const Color m_color;
VideoOverlay* m_overlay;
const ImageFloatBox m_corner;

ImageFloatBox m_last_detected_box;
std::optional<OverlayBoxScope> m_last_detected_box_scope;
};
class LightBlueDialogWatcher : public DetectorToFinder<LightBlueDialogDetector>{
public:
LightBlueDialogWatcher(
Color color = COLOR_RED,
VideoOverlay* overlay = nullptr,
std::chrono::milliseconds hold_duration = std::chrono::milliseconds(250)
)
: DetectorToFinder("BlueDialogWatcher", hold_duration, color, overlay)
{}
};


}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* Hyperspace Reward Name Reader
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "CommonTools/OCR/OCR_RawOCR.h"
#include "PokemonLZA_HyperspaceRewardNameReader.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonLZA{

HyperspaceRewardNameReader& HyperspaceRewardNameReader::instance(){
static HyperspaceRewardNameReader reader;
return reader;
}


HyperspaceRewardNameReader::HyperspaceRewardNameReader()
: SmallDictionaryMatcher("PokemonLZA/HyperBattle/HyperspaceRewardNameOCR.json")
{}

OCR::StringMatchResult HyperspaceRewardNameReader::read_substring(
Logger& logger,
Language language,
const ImageViewRGB32& image,
const std::vector<OCR::TextColorRange>& text_color_ranges,
double min_text_ratio, double max_text_ratio
) const{
return match_substring_from_image_multifiltered(
&logger, language, image, text_color_ranges,
MAX_LOG10P, MAX_LOG10P_SPREAD, min_text_ratio, max_text_ratio
);
}

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* Hyperspace Reward Name Reader
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_PokemonLZA_HyperspaceRewardNameReader_H
#define PokemonAutomation_PokemonLZA_HyperspaceRewardNameReader_H

#include "CommonTools/OCR/OCR_SmallDictionaryMatcher.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonLZA{

class HyperspaceRewardNameReader : public OCR::SmallDictionaryMatcher{
public:
static constexpr double MAX_LOG10P = -1.40;
static constexpr double MAX_LOG10P_SPREAD = 0.50;

public:
HyperspaceRewardNameReader();

static HyperspaceRewardNameReader& instance();

OCR::StringMatchResult read_substring(
Logger& logger,
Language language,
const ImageViewRGB32& image,
const std::vector<OCR::TextColorRange>& text_color_ranges,
double min_text_ratio = 0.01, double max_text_ratio = 0.50
) const;

};
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* Hyperspace Reward Option
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "CommonFramework/Logging/Logger.h"
#include "PokemonLZA/Resources/PokemonLZA_HyperspaceRewardNames.h"
#include "PokemonLZA_HyperspaceRewardOption.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonLZA{

StringSelectDatabase make_hyperspace_reward_database(){
StringSelectDatabase ret;
for (const auto& slug : HYPERSPACE_REWARD_SLUGS()){
const HyperspaceRewardNames& data = get_hyperspace_reward_name(slug);
ret.add_entry(StringSelectEntry(slug, data.display_name()));
}
return ret;
}
const StringSelectDatabase& HYPERSPACE_REWARD_DATABASE(){
static StringSelectDatabase database = make_hyperspace_reward_database();
return database;
}


HyperspaceRewardCell::HyperspaceRewardCell(
const std::string& default_slug
)
: StringSelectCell(
HYPERSPACE_REWARD_DATABASE(),
LockMode::LOCK_WHILE_RUNNING,
default_slug
)
{}


}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* Hyperspace Reward Option
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_PokemonLZA_HyperspaceRewardOption_H
#define PokemonAutomation_PokemonLZA_HyperspaceRewardOption_H

#include "CommonTools/Options/StringSelectOption.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonLZA{

class HyperspaceRewardCell : public StringSelectCell{
public:
HyperspaceRewardCell(const std::string& default_slug);
};

}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* Hyperspace Reward Table
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "PokemonLZA/Resources/PokemonLZA_HyperspaceRewardNames.h"
#include "PokemonLZA_HyperspaceRewardTable.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonLZA{

HyperspaceRewardRow::HyperspaceRewardRow(EditableTableOption& parent_table)
: EditableTableRow(parent_table)
, item("bottle-cap")
{
PA_ADD_OPTION(item);
}
std::unique_ptr<EditableTableRow> HyperspaceRewardRow::clone() const{
std::unique_ptr<HyperspaceRewardRow> ret(new HyperspaceRewardRow(parent()));
ret->item.set_by_index(item.index());
return ret;
}

HyperspaceRewardTable::HyperspaceRewardTable(std::string label)
: EditableTableOption_t<HyperspaceRewardRow>(
std::move(label),
LockMode::LOCK_WHILE_RUNNING,
make_defaults()
)
{}

bool HyperspaceRewardTable::find_item(const std::string& item_slug) const{
std::vector<std::unique_ptr<HyperspaceRewardRow>> table = copy_snapshot();
for (const std::unique_ptr<HyperspaceRewardRow>& row : table){
if (row->item.slug() == item_slug){
return true;
}
}
return false;
}

std::vector<std::string> HyperspaceRewardTable::selected_items() const{
std::vector<std::unique_ptr<HyperspaceRewardRow>> table = copy_snapshot();
std::vector<std::string> slugs;
for (const std::unique_ptr<HyperspaceRewardRow>& row : table){
slugs.emplace_back(row->item.slug());
}
return slugs;
}


std::vector<std::string> HyperspaceRewardTable::make_header() const{
return std::vector<std::string>{
"Item",
};
}

std::vector<std::unique_ptr<EditableTableRow>> HyperspaceRewardTable::make_defaults(){
std::vector<std::unique_ptr<EditableTableRow>> ret;
ret.emplace_back(std::make_unique<HyperspaceRewardRow>(*this));
return ret;
}






}
}
}
Loading