1414#include " PokemonSV/PokemonSV_Settings.h"
1515#include " PokemonSV/Inference/Dialogs/PokemonSV_DialogDetector.h"
1616#include " PokemonSV/Inference/Map/PokemonSV_MapDetector.h"
17- #include " PokemonSV/Inference/Map/PokemonSV_MapMenuDetector.h"
18- #include " PokemonSV/Inference/Map/PokemonSV_MapPokeCenterIconDetector.h"
19- #include " PokemonSV/Inference/Picnics/PokemonSV_PicnicDetector.h"
17+ #include " PokemonSV/Inference/PokemonSV_BagDetector.h"
2018#include " PokemonSV/Inference/PokemonSV_MainMenuDetector.h"
21- #include " PokemonSV/Inference/PokemonSV_ZeroGateWarpPromptDetector.h"
2219#include " PokemonSV/Inference/Overworld/PokemonSV_LetsGoKillDetector.h"
2320#include " PokemonSV/Inference/Overworld/PokemonSV_OverworldDetector.h"
2421#include " PokemonSV/Inference/Dialogs/PokemonSV_DialogDetector.h"
25- #include " PokemonSV/Inference/PokemonSV_TutorialDetector.h"
2622#include " PokemonSV/Inference/Battles/PokemonSV_NormalBattleMenus.h"
2723#include " PokemonSV_ConnectToInternet.h"
2824#include " PokemonSV_MenuNavigation.h"
@@ -533,25 +529,24 @@ void enter_menu_from_box_system(const ProgramInfo& info, VideoStream& stream, Pr
533529 [](ProControllerContext& context){
534530 // repeatedly pressing B and waiting for three seconds
535531 for (int i = 0 ; i < 10 ; i++){
536- pbf_press_button (context, BUTTON_B, 20 , 3 * TICKS_PER_SECOND );
532+ pbf_press_button (context, BUTTON_B, 200ms, 3s );
537533 }
538534 },
539535 {main_menu}
540536 );
541- context.wait_for (std::chrono::milliseconds (100 ));
542537
543538 const bool fast_mode = false ;
544539 switch (ret){
545540 case 0 :
546- stream.log (" Detected main menu. " );
541+ stream.log (" Detected main menu when going from box system to menu " );
547542 if (menu_index == -1 ){
548543 return ;
549544 }
550545 success = main_menu.move_cursor (info, stream, context, side, menu_index, fast_mode);
551546 if (success == false ){
552547 OperationFailedException::fire (
553548 ErrorReport::SEND_ERROR_REPORT,
554- " enter_menu_from_overworld (): Cannot move menu cursor to specified menu." ,
549+ " enter_menu_from_box_system (): Cannot move menu cursor to specified menu." ,
555550 stream
556551 );
557552 }
@@ -560,13 +555,129 @@ void enter_menu_from_box_system(const ProgramInfo& info, VideoStream& stream, Pr
560555 default :
561556 OperationFailedException::fire (
562557 ErrorReport::SEND_ERROR_REPORT,
563- " enter_menu_from_overworld (): No recognized state after 30 seconds." ,
558+ " enter_menu_from_box_system (): No recognized state after 30 seconds." ,
564559 stream
565560 );
566561 }
567562 }
568563}
569564
565+
566+ void enter_menu_from_bag (const ProgramInfo& info, VideoStream& stream, ProControllerContext& context,
567+ int menu_index,
568+ MenuSide side
569+ ){
570+ WallClock start = current_time ();
571+ bool success = false ;
572+
573+ while (true ){
574+ if (current_time () - start > std::chrono::seconds (20 )){
575+ OperationFailedException::fire (
576+ ErrorReport::SEND_ERROR_REPORT,
577+ " enter_menu_from_bag(): Failed to enter specified menu after 20 seconds." ,
578+ stream
579+ );
580+ }
581+
582+ MainMenuWatcher main_menu (COLOR_RED);
583+ BagWatcher bag_watcher (BagWatcher::FinderType::PRESENT, COLOR_RED);
584+ context.wait_for_all_requests ();
585+
586+ int ret = run_until<ProControllerContext>(
587+ stream, context,
588+ [](ProControllerContext& context){
589+ // repeatedly pressing B and waiting for three seconds
590+ for (int i = 0 ; i < 10 ; i++){
591+ pbf_press_button (context, BUTTON_B, 200ms, 3s);
592+ }
593+ },
594+ {main_menu, bag_watcher}
595+ );
596+
597+ const bool fast_mode = false ;
598+ switch (ret){
599+ case 0 :
600+ stream.log (" Detected main menu when going from box system to menu" );
601+ if (menu_index == -1 ){
602+ return ;
603+ }
604+ success = main_menu.move_cursor (info, stream, context, side, menu_index, fast_mode);
605+ if (success == false ){
606+ OperationFailedException::fire (
607+ ErrorReport::SEND_ERROR_REPORT,
608+ " enter_menu_from_bag(): Cannot move menu cursor to specified menu." ,
609+ stream
610+ );
611+ }
612+ pbf_press_button (context, BUTTON_A, 20 , 105 );
613+ return ;
614+ case 1 :
615+ stream.log (" still on bag." );
616+ pbf_press_button (context, BUTTON_B, 20 , 105 );
617+ continue ;
618+ default :
619+ OperationFailedException::fire (
620+ ErrorReport::SEND_ERROR_REPORT,
621+ " enter_menu_from_bag(): No recognized state after 30 seconds." ,
622+ stream
623+ );
624+ }
625+ }
626+ }
627+
628+
629+ void enter_bag_from_menu (const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
630+ WallClock start = current_time ();
631+ bool success = false ;
632+ stream.log (" Entering bag from menu" );
633+
634+ while (true ){
635+ if (current_time () - start > std::chrono::seconds (20 )){
636+ OperationFailedException::fire (
637+ ErrorReport::SEND_ERROR_REPORT,
638+ " enter_bag_from_menu(): Failed to enter specified menu after 20 seconds." ,
639+ stream
640+ );
641+ }
642+
643+ MainMenuWatcher main_menu (COLOR_RED);
644+ BagWatcher bag_watcher (BagWatcher::FinderType::PRESENT, COLOR_RED);
645+ context.wait_for_all_requests ();
646+
647+ int ret = wait_until (
648+ stream, context,
649+ Seconds (5 ),
650+ {main_menu, bag_watcher}
651+ );
652+
653+ const bool fast_mode = false ;
654+ switch (ret){
655+ case 0 :
656+ stream.log (" Detected main menu." );
657+ success = main_menu.move_cursor (info, stream, context, MenuSide::RIGHT, 0 , fast_mode);
658+ if (success == false ){
659+ OperationFailedException::fire (
660+ ErrorReport::SEND_ERROR_REPORT,
661+ " enter_bag_from_menu(): Cannot move menu cursor to specified menu." ,
662+ stream
663+ );
664+ }
665+ pbf_press_button (context, BUTTON_A, 20 , 105 );
666+ continue ;
667+ case 1 :
668+ stream.overlay ().add_log (" Enter bag" );
669+ return ;
670+ default :
671+ OperationFailedException::fire (
672+ ErrorReport::SEND_ERROR_REPORT,
673+ " enter_bag_from_menu(): No recognized state after 30 seconds." ,
674+ stream
675+ );
676+ }
677+ }
678+ }
679+
680+
570681void press_button_until_gradient_arrow (
571682 const ProgramInfo& info,
572683 VideoStream& stream,
0 commit comments