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 @@ -4,6 +4,7 @@
*
*/

#include "Common/Cpp/Exceptions.h"
#include "CommonFramework/ImageTools/ImageBoxes.h"
#include "CommonFramework/ImageTypes/ImageRGB32.h"
#include "CommonFramework/ImageTools/ImageStats.h"
Expand Down Expand Up @@ -72,6 +73,57 @@ bool PartySelectionDetector::detect(const ImageViewRGB32& screen){
return false;
}

ImageFloatBox PartySlotDetector::party_slot_boxes(PartySlot position){
switch (position){
case PartySlot::ONE:
return ImageFloatBox(0.130000, 0.163000, 0.200000, 0.009000);
case PartySlot::TWO:
return ImageFloatBox(0.710000, 0.063000, 0.260000, 0.009000);
case PartySlot::THREE:
return ImageFloatBox(0.710000, 0.213000, 0.260000, 0.009000);
case PartySlot::FOUR:
return ImageFloatBox(0.710000, 0.363000, 0.260000, 0.009000);
case PartySlot::FIVE:
return ImageFloatBox(0.710000, 0.513000, 0.260000, 0.009000);
case PartySlot::SIX:
return ImageFloatBox(0.710000, 0.663000, 0.260000, 0.009000);
default:
break;
}
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Invalid FRLG Party Slot Position");
}
PartySlotDetector::PartySlotDetector(
Color color,
const ImageFloatBox& box
)
: m_color(color)
, m_party_box(box)
{}
PartySlotDetector::PartySlotDetector(
Color color,
PartySlot position
)
: m_color(color)
, m_party_box(party_slot_boxes(position))
{}
void PartySlotDetector::make_overlays(VideoOverlaySet& items) const{
const BoxOption& GAME_BOX = GameSettings::instance().GAME_BOX;
items.add(m_color, GAME_BOX.inner_to_outer(m_party_box));
}
bool PartySlotDetector::detect(const ImageViewRGB32& screen){
ImageViewRGB32 game_screen = extract_box_reference(screen, GameSettings::instance().GAME_BOX);

ImageViewRGB32 target_box_party = extract_box_reference(game_screen, m_party_box);

//orange FF701C border. light/dark blues in the selected box are close to each other.
if (is_solid(target_box_party, { 0.6455696, 0.2835, 0.070886 }, 0.25, 20)
){
return true;
}
return false;
}



}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{

enum class PartySlot{
ONE,
TWO,
THREE,
FOUR,
FIVE,
SIX
//CXL
};

// The Party menu has a white box on the bottom
// The background around the edges is dark teal/navy
Expand Down Expand Up @@ -63,6 +72,40 @@ class PartySelectionWatcher : public DetectorToFinder<PartySelectionDetector>{
};


class PartySlotDetector : public StaticScreenDetector{
public:
PartySlotDetector(
Color color,
const ImageFloatBox& box
);

PartySlotDetector(
Color color,
PartySlot position
);

static ImageFloatBox party_slot_boxes(PartySlot position);

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

private:
const Color m_color;
const ImageFloatBox m_party_box;
};
class PartySlotWatcher : public DetectorToFinder<PartySlotDetector>{
public:
PartySlotWatcher(
Color color,
PartySlot position,
std::chrono::milliseconds hold_duration = std::chrono::milliseconds(250)
)
: DetectorToFinder("PartySlotWatcher", hold_duration, color, party_slot_boxes(position))
{
}
};



}
}
Expand Down
23 changes: 20 additions & 3 deletions SerialPrograms/Source/PokemonFRLG/PokemonFRLG_Navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ bool try_open_slot_six(ConsoleHandle& console, ProControllerContext& context){
}

console.log("Navigating to party menu.");
BlackScreenOverWatcher blk1(COLOR_RED);
PartyMenuWatcher blk1(COLOR_RED);

int pm = run_until<ProControllerContext>(
console, context,
Expand All @@ -166,8 +166,25 @@ bool try_open_slot_six(ConsoleHandle& console, ProControllerContext& context){
context.wait_for_all_requests();

//Press up twice to get to the last slot
pbf_press_dpad(context, DPAD_UP, 320ms, 320ms);
pbf_press_dpad(context, DPAD_UP, 320ms, 320ms);
PartySlotWatcher last_slot(COLOR_RED, PartySlot::SIX);
int ps = run_until<ProControllerContext>(
console, context,
[](ProControllerContext& context){
for (int i = 0; i < 15; i++) { //Enough to cycle through 6pty+cxl twice
pbf_wait(context, 320ms);
context.wait_for_all_requests();
pbf_press_dpad(context, DPAD_UP, 320ms, 320ms);
}
},
{ last_slot }
);
context.wait_for_all_requests();
if (ps == 0){
console.log("Moved selection to slot six.");
} else{
console.log("open_slot_six(): Unable to move selection to slot six.", COLOR_RED);
return false;
}

//Two presses to open summary
BlackScreenOverWatcher blk2(COLOR_RED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
#include "Pokemon/Pokemon_Strings.h"
#include "PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h"
#include "PokemonFRLG/Inference/Menus/PokemonFRLG_PartyMenuDetector.h"
#include "PokemonFRLG/Inference/Menus/PokemonFRLG_StartMenuDetector.h"
#include "PokemonFRLG/Inference/Menus/PokemonFRLG_SummaryDetector.h"
#include "PokemonFRLG/Inference/PokemonFRLG_ShinySymbolDetector.h"
Expand Down Expand Up @@ -293,7 +294,7 @@ bool GiftReset::try_open_summary(SingleSwitchProgramEnvironment& env, ProControl
}

//Open party menu
BlackScreenOverWatcher blk1(COLOR_RED);
PartyMenuWatcher blk1(COLOR_RED);

int pm = run_until<ProControllerContext>(
env.console, context,
Expand All @@ -318,8 +319,29 @@ bool GiftReset::try_open_summary(SingleSwitchProgramEnvironment& env, ProControl

//Press up twice to get to the last slot
if (TARGET != Target::starters){
pbf_press_dpad(context, DPAD_UP, 320ms, 320ms);
pbf_press_dpad(context, DPAD_UP, 320ms, 320ms);
PartySlotWatcher last_slot(COLOR_RED, PartySlot::SIX);
int ps = run_until<ProControllerContext>(
env.console, context,
[](ProControllerContext& context){
for (int i = 0; i < 15; i++) { //Enough to cycle through 6pty+cxl twice
pbf_wait(context, 320ms);
context.wait_for_all_requests();
pbf_press_dpad(context, DPAD_UP, 320ms, 320ms);
}
},
{ last_slot }
);
context.wait_for_all_requests();
if (ps == 0){
env.log("Moved selection to slot six.");
} else{
env.log("open_summary(): Unable to move selection to slot six.", COLOR_RED);
send_program_recoverable_error_notification(
env, NOTIFICATION_ERROR_RECOVERABLE,
"open_summary(): Unable to move selection to slot six."
);
return false;
}
}

//Two presses to open summary
Expand Down
Loading