#include "global.h" #include "gflib.h" #include "menu.h" #include "task.h" #include "script_menu.h" #include "quest_log.h" #include "event_data.h" #include "field_specials.h" #include "item_icon.h" #include "menu_indicators.h" #include "script.h" #include "strings.h" #include "field_effect.h" #include "event_scripts.h" #include "list_menu.h" #include "util.h" #include "constants/songs.h" #include "constants/seagallop.h" #include "constants/menu.h" #define GFXTAG_FOSSIL 7000 #define MULTICHOICE(name) {.list = name, .count = ARRAY_COUNT(name)} struct MultichoiceListStruct { const struct MenuAction * list; u8 count; }; struct DynamicListMenuEventArgs { struct ListMenuTemplate *list; u16 selectedItem; u8 windowId; }; typedef void (*DynamicListCallback)(struct DynamicListMenuEventArgs *eventArgs); struct DynamicListMenuEventCollection { DynamicListCallback OnInit; DynamicListCallback OnSelectionChanged; DynamicListCallback OnDestroy; }; static EWRAM_DATA u8 sProcessInputDelay = 0; static EWRAM_DATA u8 sDynamicMenuEventId = 0; static EWRAM_DATA struct DynamicMultichoiceStack *sDynamicMultiChoiceStack = NULL; static EWRAM_DATA u16 *sDynamicMenuEventScratchPad = NULL; static void FreeListMenuItems(struct ListMenuItem *items, u32 count); static void Task_HandleScrollingMultichoiceInput(u8 taskId); static void Task_HandleMultichoiceInput(u8 taskId); // static void Task_HandleYesNoInput(u8 taskId); // static void Task_HandleMultichoiceGridInput(u8 taskId); static void DrawMultichoiceMenuDynamic(u8 left, u8 top, u8 argc, struct ListMenuItem *items, bool8 ignoreBPress, u32 initialRow, u8 maxBeforeScroll, u32 callbackSet); static void DrawMultichoiceMenu(u8 left, u8 top, u8 mcId, u8 ignoreBpress, u8 initPos); static u8 GetMCWindowHeight(u8 count); static void InitMultichoiceCheckWrap(u8 ignoreBpress, u8 count, u8 windowId, u8 mcId); static void Task_HandleMultichoiceInput(u8 taskId); static void DrawLinkServicesMultichoiceMenu(u8 mcId); static void Task_YesNoMenu_HandleInput(u8 taskId); static void Hask_MultichoiceGridMenu_HandleInput(u8 taskId); static void CreatePCMenuWindow(void); static bool8 PicboxWait(void); static void DestroyScriptMenuWindow(u8 windowId); static u8 CreateWindowFromRect(u8 left, u8 top, u8 width, u8 height); static void MultichoiceDynamicEventDebug_OnInit(struct DynamicListMenuEventArgs *eventArgs); static void MultichoiceDynamicEventDebug_OnSelectionChanged(struct DynamicListMenuEventArgs *eventArgs); static void MultichoiceDynamicEventDebug_OnDestroy(struct DynamicListMenuEventArgs *eventArgs); static void MultichoiceDynamicEventShowItem_OnInit(struct DynamicListMenuEventArgs *eventArgs); static void MultichoiceDynamicEventShowItem_OnSelectionChanged(struct DynamicListMenuEventArgs *eventArgs); static void MultichoiceDynamicEventShowItem_OnDestroy(struct DynamicListMenuEventArgs *eventArgs); static const struct DynamicListMenuEventCollection sDynamicListMenuEventCollections[] = { [DYN_MULTICHOICE_CB_DEBUG] = { .OnInit = MultichoiceDynamicEventDebug_OnInit, .OnSelectionChanged = MultichoiceDynamicEventDebug_OnSelectionChanged, .OnDestroy = MultichoiceDynamicEventDebug_OnDestroy }, [DYN_MULTICHOICE_CB_SHOW_ITEM] = { .OnInit = MultichoiceDynamicEventShowItem_OnInit, .OnSelectionChanged = MultichoiceDynamicEventShowItem_OnSelectionChanged, .OnDestroy = MultichoiceDynamicEventShowItem_OnDestroy } }; static const struct ListMenuTemplate sScriptableListMenuTemplate = { .item_X = 8, .upText_Y = 1, .cursorPal = 2, .fillValue = 1, .cursorShadowPal = 3, .lettersSpacing = 1, .scrollMultiple = LIST_NO_MULTIPLE_SCROLL, .fontId = FONT_NORMAL, }; static const struct MenuAction sMultichoiceList_YesNo[] = { { gText_Yes }, { gText_No } }; static const struct MenuAction sMultichoiceList_TrainerCardIconTint[] = { { gText_Normal }, { gText_Black }, { gText_Pink }, { gText_Sepia } }; static const struct MenuAction sMultichoiceList_HOF_Quit[] = { { gText_HallOfFame }, { gText_Quit } }; static const struct MenuAction sMultichoiceList_Eggs_Quit[] = { { gText_Eggs }, { gText_Quit } }; static const struct MenuAction sMultichoiceList_Victories_Quit[] = { { gText_Victories }, { gText_Quit } }; static const struct MenuAction sMultichoiceList_HOF_Eggs_Quit[] = { { gText_HallOfFame }, { gText_Eggs }, { gText_Quit } }; static const struct MenuAction sMultichoiceList_HOF_Victories_Quit[] = { { gText_HallOfFame }, { gText_Victories }, { gText_Quit } }; static const struct MenuAction sMultichoiceList_Eggs_Victories_Quit[] = { { gText_Eggs }, { gText_Victories }, { gText_Quit } }; static const struct MenuAction sMultichoiceList_HOF_Eggs_Victories_Quit[] = { { gText_HallOfFame }, { gText_Eggs }, { gText_Victories }, { gText_Quit } }; static const struct MenuAction sMultichoiceList_TrainerSchoolWhiteboard[] = { { gText_Slp }, { gText_Psn }, { gText_Par }, { gText_Brn }, { gText_Frz }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_YesNoInfo[] = { { gText_Yes }, { gText_No }, { gText_Info } }; static const struct MenuAction sMultichoiceList_SingleDoubleMultiInfoExit[] = { { gText_SingleBattle }, { gText_DoubleBattle }, { gText_MultiBattle }, { gText_Info }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_YesNoInfo2[] = { { gText_Yes }, { gText_No }, { gText_Info } }; static const struct MenuAction sMultichoiceList_ChallengeInfoExit[] = { { gText_MakeAChallenge }, { gText_Info_2 }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_RooftopB1F[] = { { gText_Rooftop }, { gText_B1F }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_Helix[] = { { gText_HelixFossil }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_Dome[] = { { gText_DomeFossil }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_Amber[] = { { gText_OldAmber }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_HelixAmber[] = { { gText_HelixFossil }, { gText_OldAmber }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_DomeAmber[] = { { gText_DomeFossil }, { gText_OldAmber }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_CeladonVendingMachine[] = { { gText_FreshWater_200 }, { gText_SodaPop_300 }, { gText_Lemonade_350 }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_GameCornerTMPrizes[] = { { gText_Tm13_4000Coins }, { gText_Tm23_3500Coins }, { gText_Tm24_4000Coins }, { gText_Tm30_4500Coins }, { gText_Tm35_4000Coins }, { gText_NoThanks_2 } }; static const struct MenuAction sMultichoiceList_GameCornerBattleItemPrizes[] = { { gText_SmokeBall_800Coins }, { gText_MiracleSeed_1000Coins }, { gText_Charcoal_1000Coins }, { gText_MysticWater_1000Coins }, { gText_YellowFlute_1600Coins }, { gText_NoThanks_2 } }; static const struct MenuAction sMultichoiceList_GameCornerCoinPurchaseCounter[] = { { gText_50Coins_1000 }, { gText_500Coins_10000 }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_Excellent_NotSoBad[] = { { gText_Excellent }, { gText_NotSoBad } }; static const struct MenuAction sMultichoiceList_RightLeft[] = { { gText_Right }, { gText_Left } }; static const struct MenuAction sMultichoiceList_DeptStoreElevator[] = { { gText_5F_2 }, { gText_4F_2 }, { gText_3F_2 }, { gText_2F_2 }, { gText_1F_2 }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_ThirstyGirlFreshWater[] = { { gText_FreshWater }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_ThirstyGirlSodaPop[] = { { gText_SodaPop }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_ThirstyGirlFreshWaterSodaPop[] = { { gText_FreshWater }, { gText_SodaPop }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_ThirstyGirlLemonade[] = { { gText_Lemonade }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_ThirstyGirlFreshWaterLemonade[] = { { gText_FreshWater }, { gText_Lemonade }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_ThirstyGirlSodaPopLemonade[] = { { gText_SodaPop }, { gText_Lemonade }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_ThirstyGirlFreshWaterSodaPopLemonade[] = { { gText_FreshWater }, { gText_SodaPop }, { gText_Lemonade }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_Unref_Shards_0[] = { { gText_GreenShard }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_Unref_Shards_1[] = { { gText_RedShard }, { gText_GreenShard }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_Unref_Shards_2[] = { { gText_YellowShard }, { gText_GreenShard }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_Unref_Shards_3[] = { { gText_RedShard }, { gText_YellowShard }, { gText_GreenShard }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_Unref_Shards_4[] = { { gText_BlueShard }, { gText_GreenShard }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_Unref_Shards_5[] = { { gText_RedShard }, { gText_BlueShard }, { gText_GreenShard }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_Unref_Shards_6[] = { { gText_YellowShard }, { gText_BlueShard }, { gText_GreenShard }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_Unref_Shards_7[] = { { gText_RedShard }, { gText_YellowShard }, { gText_BlueShard }, { gText_GreenShard }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_Eeveelutions[] = { { gText_Eevee }, { gText_Flareon }, { gText_Jolteon }, { gText_Vaporeon }, { gText_QuitLooking } }; static const struct MenuAction sMultichoiceList_BikeShop[] = { { gText_Bicycle_Price }, { gText_NoThanks } }; static const struct MenuAction sMultichoiceList_GameCornerPokemonPrizes[] = { #if defined(FIRERED) { gText_Abra_180Coins }, { gText_Clefairy_500Coins }, { gText_Dratini_2800Coins }, { gText_Scyther_5500Coins }, { gText_Porygon_9999Coins }, #elif defined(LEAFGREEN) { gText_Abra_120Coins }, { gText_Clefairy_750Coins }, { gText_Pinsir_2500Coins }, { gText_Dratini_4600Coins }, { gText_Porygon_6500Coins }, #endif { gText_NoThanks_2 } }; static const struct MenuAction sMultichoiceList_TradeCenter_Colosseum[] = { { gText_TradeCenter }, { gText_Colosseum }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_Link_Wireless[] = { { gText_GameLinkCable }, { gText_Wireless }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_RocketHideoutElevator[] = { { gText_B1F }, { gText_B2F }, { gText_B4F }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_LinkedDirectUnion[] = { { gText_LinkedGamePlay }, { gText_DirectCorner }, { gText_UnionRoom }, { gOtherText_Quit } }; static const struct MenuAction sMultichoiceList_Island23[] = { { gText_TwoIsland }, { gText_ThreeIsland }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_Island13[] = { { gText_OneIsland }, { gText_ThreeIsland }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_Island12[] = { { gText_OneIsland }, { gText_TwoIsland }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_TradeColosseumCrush[] = { { gText_TradeCenter }, { gText_Colosseum_2 }, { gText_BerryCrush }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_48[] = { { gText_EmptyLinkService1 }, { gText_EmptyLinkService2 }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_TradeColosseum_2[] = { { gText_TradeCenter }, { gText_Colosseum_2 }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_PokejumpDodrio[] = { { gText_PokemonJump }, { gText_DodrioBerryPicking }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_Mushrooms[] = { { gText_2Tinymushrooms }, { gText_1BigMushroom } }; static const struct MenuAction sMultichoiceList_TradeColosseumBlankCrush[] = { { gText_TradeCenter }, { gText_Colosseum_2 }, { gText_RecordCorner }, { gText_BerryCrush }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_TradeColosseumBlank[] = { { gText_TradeCenter }, { gText_Colosseum_2 }, { gText_RecordCorner }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_SeviiNavel[] = { { gText_SeviiIslands }, { gText_NavelRock }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_SeviiBirth[] = { { gText_SeviiIslands }, { gText_BirthIsland }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_SeviiNavelBirth[] = { { gText_SeviiIslands }, { gText_NavelRock }, { gText_BirthIsland }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_Seagallop123[] = { { gText_OneIsland }, { gText_TwoIsland }, { gText_ThreeIsland }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_SeagallopV23[] = { { gText_Vermilion }, { gText_TwoIsland }, { gText_ThreeIsland }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_SeagallopV13[] = { { gText_Vermilion }, { gText_OneIsland }, { gText_ThreeIsland }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_SeagallopV12[] = { { gText_Vermilion }, { gText_OneIsland }, { gText_TwoIsland }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_SeagallopVermilion[] = { { gText_Vermilion }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_62[] = { { gText_Multichoice_Empty1 }, { gText_Multichoice_Empty2 }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_JoinOrLead[] = { { gText_JoinGroup }, { gText_BecomeLeader }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_TrainerTowerMode[] = { { gOtherText_Single }, { gOtherText_Double }, { gOtherText_Knockout }, { gOtherText_Mixed }, { gOtherText_Exit } }; static const struct MenuAction sMultichoiceList_Exit[] = { { gOtherText_Exit } }; static const struct MultichoiceListStruct sMultichoiceLists[] = { [MULTICHOICE_YES_NO] = MULTICHOICE(sMultichoiceList_YesNo), [MULTICHOICE_EEVEELUTIONS] = MULTICHOICE(sMultichoiceList_Eeveelutions), [MULTICHOICE_TRAINER_CARD_ICON_TINT] = MULTICHOICE(sMultichoiceList_TrainerCardIconTint), [MULTICHOICE_HOF_QUIT] = MULTICHOICE(sMultichoiceList_HOF_Quit), [MULTICHOICE_EGGS_QUIT] = MULTICHOICE(sMultichoiceList_Eggs_Quit), [MULTICHOICE_VICTORIES_QUIT] = MULTICHOICE(sMultichoiceList_Victories_Quit), [MULTICHOICE_HOF_EGGS_QUIT] = MULTICHOICE(sMultichoiceList_HOF_Eggs_Quit), [MULTICHOICE_HOF_VICTORIES_QUIT] = MULTICHOICE(sMultichoiceList_HOF_Victories_Quit), [MULTICHOICE_EGGS_VICTORIES_QUIT] = MULTICHOICE(sMultichoiceList_Eggs_Victories_Quit), [MULTICHOICE_HOF_EGGS_VICTORIES_QUIT] = MULTICHOICE(sMultichoiceList_HOF_Eggs_Victories_Quit), [MULTICHOICE_EXIT] = MULTICHOICE(sMultichoiceList_Exit), [MULTICHOICE_EXIT_2] = MULTICHOICE(sMultichoiceList_Exit), [MULTICHOICE_EXIT_3] = MULTICHOICE(sMultichoiceList_Exit), [MULTICHOICE_BIKE_SHOP] = MULTICHOICE(sMultichoiceList_BikeShop), [MULTICHOICE_GAME_CORNER_POKEMON_PRIZES] = MULTICHOICE(sMultichoiceList_GameCornerPokemonPrizes), [MULTICHOICE_TRAINER_SCHOOL_WHITEBOARD] = MULTICHOICE(sMultichoiceList_TrainerSchoolWhiteboard), [MULTICHOICE_YES_NO_INFO] = MULTICHOICE(sMultichoiceList_YesNoInfo), [MULTICHOICE_SINGLE_DOUBLE_MULTI_INFO_EXIT] = MULTICHOICE(sMultichoiceList_SingleDoubleMultiInfoExit), [MULTICHOICE_YES_NO_INFO_2] = MULTICHOICE(sMultichoiceList_YesNoInfo2), [MULTICHOICE_CHALLENGE_INFO_EXIT] = MULTICHOICE(sMultichoiceList_ChallengeInfoExit), [MULTICHOICE_ROOFTOP_B1F] = MULTICHOICE(sMultichoiceList_RooftopB1F), [MULTICHOICE_HELIX] = MULTICHOICE(sMultichoiceList_Helix), [MULTICHOICE_DOME] = MULTICHOICE(sMultichoiceList_Dome), [MULTICHOICE_AMBER] = MULTICHOICE(sMultichoiceList_Amber), [MULTICHOICE_HELIX_AMBER] = MULTICHOICE(sMultichoiceList_HelixAmber), [MULTICHOICE_DOME_AMBER] = MULTICHOICE(sMultichoiceList_DomeAmber), [MULTICHOICE_CELADON_VENDING_MACHINE] = MULTICHOICE(sMultichoiceList_CeladonVendingMachine), [MULTICHOICE_GAME_CORNER_COIN_PURCHASE_COUNTER] = MULTICHOICE(sMultichoiceList_GameCornerCoinPurchaseCounter), [MULTICHOICE_EXCELLENT_NOT_SO_BAD] = MULTICHOICE(sMultichoiceList_Excellent_NotSoBad), [MULTICHOICE_RIGHT_LEFT] = MULTICHOICE(sMultichoiceList_RightLeft), [MULTICHOICE_GAME_CORNER_TMPRIZES] = MULTICHOICE(sMultichoiceList_GameCornerTMPrizes), [MULTICHOICE_DEPT_STORE_ELEVATOR] = MULTICHOICE(sMultichoiceList_DeptStoreElevator), [MULTICHOICE_THIRSTY_GIRL_FRESH_WATER] = MULTICHOICE(sMultichoiceList_ThirstyGirlFreshWater), [MULTICHOICE_THIRSTY_GIRL_SODA_POP] = MULTICHOICE(sMultichoiceList_ThirstyGirlSodaPop), [MULTICHOICE_THIRSTY_GIRL_FRESH_WATER_SODA_POP] = MULTICHOICE(sMultichoiceList_ThirstyGirlFreshWaterSodaPop), [MULTICHOICE_THIRSTY_GIRL_LEMONADE] = MULTICHOICE(sMultichoiceList_ThirstyGirlLemonade), [MULTICHOICE_THIRSTY_GIRL_FRESH_WATER_LEMONADE] = MULTICHOICE(sMultichoiceList_ThirstyGirlFreshWaterLemonade), [MULTICHOICE_THIRSTY_GIRL_SODA_POP_LEMONADE] = MULTICHOICE(sMultichoiceList_ThirstyGirlSodaPopLemonade), [MULTICHOICE_THIRSTY_GIRL_FRESH_WATER_SODA_POP_LEMONADE] = MULTICHOICE(sMultichoiceList_ThirstyGirlFreshWaterSodaPopLemonade), [MULTICHOICE_TRADE_CENTER_COLOSSEUM] = MULTICHOICE(sMultichoiceList_TradeCenter_Colosseum), [MULTICHOICE_LINK_WIRELESS] = MULTICHOICE(sMultichoiceList_Link_Wireless), [MULTICHOICE_GAME_CORNER_BATTLE_ITEM_PRIZES] = MULTICHOICE(sMultichoiceList_GameCornerBattleItemPrizes), [MULTICHOICE_ROCKET_HIDEOUT_ELEVATOR] = MULTICHOICE(sMultichoiceList_RocketHideoutElevator), [MULTICHOICE_LINKED_DIRECT_UNION] = MULTICHOICE(sMultichoiceList_LinkedDirectUnion), [MULTICHOICE_ISLAND_23] = MULTICHOICE(sMultichoiceList_Island23), [MULTICHOICE_ISLAND_13] = MULTICHOICE(sMultichoiceList_Island13), [MULTICHOICE_ISLAND_12] = MULTICHOICE(sMultichoiceList_Island12), [MULTICHOICE_TRADE_COLOSSEUM_CRUSH] = MULTICHOICE(sMultichoiceList_TradeColosseumCrush), [MULTICHOICE_48] = MULTICHOICE(sMultichoiceList_48), [MULTICHOICE_POKEJUMP_DODRIO] = MULTICHOICE(sMultichoiceList_PokejumpDodrio), [MULTICHOICE_TRADE_COLOSSEUM_2] = MULTICHOICE(sMultichoiceList_TradeColosseum_2), [MULTICHOICE_MUSHROOMS] = MULTICHOICE(sMultichoiceList_Mushrooms), [MULTICHOICE_TRADE_COLOSSEUM_BLANK_CRUSH] = MULTICHOICE(sMultichoiceList_TradeColosseumBlankCrush), [MULTICHOICE_TRADE_COLOSSEUM_BLANK] = MULTICHOICE(sMultichoiceList_TradeColosseumBlank), [MULTICHOICE_SEVII_NAVEL] = MULTICHOICE(sMultichoiceList_SeviiNavel), [MULTICHOICE_SEVII_BIRTH] = MULTICHOICE(sMultichoiceList_SeviiBirth), [MULTICHOICE_SEVII_NAVEL_BIRTH] = MULTICHOICE(sMultichoiceList_SeviiNavelBirth), [MULTICHOICE_SEAGALLOP_123] = MULTICHOICE(sMultichoiceList_Seagallop123), [MULTICHOICE_SEAGALLOP_V23] = MULTICHOICE(sMultichoiceList_SeagallopV23), [MULTICHOICE_SEAGALLOP_V13] = MULTICHOICE(sMultichoiceList_SeagallopV13), [MULTICHOICE_SEAGALLOP_V12] = MULTICHOICE(sMultichoiceList_SeagallopV12), [MULTICHOICE_SEAGALLOP_VERMILION] = MULTICHOICE(sMultichoiceList_SeagallopVermilion), [MULTICHOICE_62] = MULTICHOICE(sMultichoiceList_62), [MULTICHOICE_JOIN_OR_LEAD] = MULTICHOICE(sMultichoiceList_JoinOrLead), [MULTICHOICE_TRAINER_TOWER_MODE] = MULTICHOICE(sMultichoiceList_TrainerTowerMode), }; // From Cool to Berries goes unused const u8 *const gStdStringPtrs[] = { [STDSTRING_COOL] = gText_Cool, [STDSTRING_BEAUTY] = gText_Beauty, [STDSTRING_CUTE] = gText_Cute, [STDSTRING_SMART] = gText_Smart, [STDSTRING_TOUGH] = gText_Tough, [STDSTRING_COOL2] = gText_Cool_2, [STDSTRING_BEAUTY2] = gText_Beauty_2, [STDSTRING_CUTE2] = gText_Cute_2, [STDSTRING_SMART2] = gText_Smart_2, [STDSTRING_TOUGH2] = gText_Tough_2, [STDSTRING_ITEMS] = gText_Items, [STDSTRING_KEY_ITEMS] = gText_KeyItems, [STDSTRING_POKEBALLS] = gText_PokeBalls, [STDSTRING_TMHMS] = gText_TMsAndHMs, [STDSTRING_BERRIES] = gText_Berries, [STDSTRING_BOULDER_BADGE] = gText_Boulderbadge, [STDSTRING_CASCADE_BADGE] = gText_Cascadebadge, [STDSTRING_THUNDER_BADGE] = gText_Thunderbadge, [STDSTRING_RAINBOW_BADGE] = gText_Rainbowbadge, [STDSTRING_SOUL_BADGE] = gText_Soulbadge, [STDSTRING_MARSH_BADGE] = gText_Marshbadge, [STDSTRING_VOLCANO_BADGE] = gText_Volcanobadge, [STDSTRING_EARTH_BADGE] = gText_Earthbadge, [STDSTRING_COINS] = gText_Coins_2, [STDSTRING_ITEMS_POCKET] = gText_ItemsPocket, [STDSTRING_KEY_ITEMS_POCKET] = gText_KeyItemsPocket, [STDSTRING_POKEBALLS_POCKET] = gText_PokeBallsPocket, [STDSTRING_TM_CASE] = gText_TmCase, [STDSTRING_BERRY_POUCH] = gText_BerryPouch_2 }; static const u8 sLinkServicesMultichoiceIds[] = { MULTICHOICE_TRADE_CENTER_COLOSSEUM, MULTICHOICE_TRADE_COLOSSEUM_CRUSH, MULTICHOICE_TRADE_COLOSSEUM_2 }; static const u8 *const sDescriptionPtrs_CableClub_TradeBattleCancel[] = { CableClub_Text_TradeMonsUsingLinkCable, CableClub_Text_BattleUsingLinkCable, CableClub_Text_CancelSelectedItem }; static const u8 *const sDescriptionPtrs_WirelessCenter_TradeBattleCrushCancel[] = { CableClub_Text_YouMayTradeHere, CableClub_Text_YouMayBattleHere, CableClub_Text_CanMakeBerryPowder, CableClub_Text_CancelSelectedItem }; static const u8 *const sDescriptionPtrs_WirelessCenter_TradeBattleCancel[] = { CableClub_Text_YouMayTradeHere, CableClub_Text_YouMayBattleHere, CableClub_Text_CancelSelectedItem }; static const union AnimCmd sMuseumFossilAnim0[] = { ANIMCMD_FRAME(0, 10), ANIMCMD_END }; static const union AnimCmd *const sMuseumFossilAnimCmdTable[] = { sMuseumFossilAnim0 }; static const struct OamData sMuseumFossilOamData = { .shape = SPRITE_SHAPE(64x64), .size = SPRITE_SIZE(64x64) }; static const struct SpriteTemplate sMuseumFossilSprTemplate = { .tileTag = GFXTAG_FOSSIL, .paletteTag = TAG_NONE, .oam = &sMuseumFossilOamData, .anims = sMuseumFossilAnimCmdTable, .affineAnims = gDummySpriteAffineAnimTable, .callback = SpriteCallbackDummy }; static const u16 sMuseumAerodactylSprTiles[] = INCBIN_U16("graphics/script_menu/aerodactyl_fossil.4bpp"); static const u16 sMuseumAerodactylSprPalette[] = INCBIN_U16("graphics/script_menu/aerodactyl_fossil.gbapal"); static const u16 sMuseumKabutopsSprTiles[] = INCBIN_U16("graphics/script_menu/kabutops_fossil.4bpp"); static const u16 sMuseumKabutopsSprPalette[] = INCBIN_U16("graphics/script_menu/kabutops_fossil.gbapal"); static const struct SpriteSheet sMuseumKabutopsSprSheets[] = { {sMuseumKabutopsSprTiles, sizeof(sMuseumKabutopsSprTiles), GFXTAG_FOSSIL}, {} }; static const struct SpriteSheet sMuseumAerodactylSprSheets[] = { {sMuseumAerodactylSprTiles, sizeof(sMuseumAerodactylSprTiles), GFXTAG_FOSSIL}, {} }; static const u8 *const sSeagallopDestStrings[] = { [SEAGALLOP_VERMILION_CITY] = gText_Vermilion, [SEAGALLOP_ONE_ISLAND] = gText_OneIsland, [SEAGALLOP_TWO_ISLAND] = gText_TwoIsland, [SEAGALLOP_THREE_ISLAND] = gText_ThreeIsland, [SEAGALLOP_FOUR_ISLAND] = gText_FourIsland, [SEAGALLOP_FIVE_ISLAND] = gText_FiveIsland, [SEAGALLOP_SIX_ISLAND] = gText_SixIsland, [SEAGALLOP_SEVEN_ISLAND] = gText_SevenIsland, }; static u16 GetStringTilesWide(const u8 *str) { return (GetStringWidth(FONT_NORMAL_COPY_1, str, 0) + 7) / 8; } static u8 GetMenuWidthFromList(const struct MenuAction * items, u8 count) { u16 i; u8 width = GetStringTilesWide(items[0].text); u8 tmp; for (i = 1; i < count; i++) { tmp = GetStringTilesWide(items[i].text); if (width < tmp) width = tmp; } return width; } bool8 ScriptMenu_MultichoiceDynamic(u8 left, u8 top, u8 argc, struct ListMenuItem *items, bool8 ignoreBPress, u8 maxBeforeScroll, u32 initialRow, u32 callbackSet) { if (FuncIsActiveTask(Task_HandleMultichoiceInput) == TRUE) { FreeListMenuItems(items, argc); return FALSE; } else { gSpecialVar_Result = 0xFF; DrawMultichoiceMenuDynamic(left, top, argc, items, ignoreBPress, initialRow, maxBeforeScroll, callbackSet); return TRUE; } } bool8 ScriptMenu_Multichoice(u8 left, u8 top, u8 mcId, u8 ignoreBpress) { if (FuncIsActiveTask(Task_HandleMultichoiceInput) == TRUE) return FALSE; gSpecialVar_Result = SCR_MENU_UNSET; DrawMultichoiceMenu(left, top, mcId, ignoreBpress, 0); return TRUE; } static void MultichoiceDynamicEventDebug_OnInit(struct DynamicListMenuEventArgs *eventArgs) { DebugPrintf("OnInit: %d", eventArgs->windowId); } static void MultichoiceDynamicEventDebug_OnSelectionChanged(struct DynamicListMenuEventArgs *eventArgs) { DebugPrintf("OnSelectionChanged: %d", eventArgs->selectedItem); } static void MultichoiceDynamicEventDebug_OnDestroy(struct DynamicListMenuEventArgs *eventArgs) { DebugPrintf("OnDestroy: %d", eventArgs->windowId); } #define sAuxWindowId sDynamicMenuEventScratchPad[0] #define sItemSpriteId sDynamicMenuEventScratchPad[1] #define TAG_CB_ITEM_ICON 3000 static void MultichoiceDynamicEventShowItem_OnInit(struct DynamicListMenuEventArgs *eventArgs) { struct WindowTemplate *template = &gWindows[eventArgs->windowId].window; u32 baseBlock = template->baseBlock + template->width * template->height; struct WindowTemplate auxTemplate = CreateWindowTemplate(0, template->tilemapLeft + template->width + 2, template->tilemapTop, 4, 4, 15, baseBlock); u32 auxWindowId = AddWindow(&auxTemplate); SetStandardWindowBorderStyle(auxWindowId, FALSE); FillWindowPixelBuffer(auxWindowId, 0x11); CopyWindowToVram(auxWindowId, COPYWIN_FULL); sAuxWindowId = auxWindowId; sItemSpriteId = MAX_SPRITES; } static void MultichoiceDynamicEventShowItem_OnSelectionChanged(struct DynamicListMenuEventArgs *eventArgs) { struct WindowTemplate *template = &gWindows[eventArgs->windowId].window; u32 x = template->tilemapLeft * 8 + template->width * 8 + 36; u32 y = template->tilemapTop * 8 + 20; if (sItemSpriteId != MAX_SPRITES) { FreeSpriteTilesByTag(TAG_CB_ITEM_ICON); FreeSpritePaletteByTag(TAG_CB_ITEM_ICON); DestroySprite(&gSprites[sItemSpriteId]); } sItemSpriteId = AddItemIconSprite(TAG_CB_ITEM_ICON, TAG_CB_ITEM_ICON, eventArgs->selectedItem); gSprites[sItemSpriteId].oam.priority = 0; gSprites[sItemSpriteId].x = x; gSprites[sItemSpriteId].y = y; } static void MultichoiceDynamicEventShowItem_OnDestroy(struct DynamicListMenuEventArgs *eventArgs) { ClearStdWindowAndFrame(sAuxWindowId, TRUE); RemoveWindow(sAuxWindowId); if (sItemSpriteId != MAX_SPRITES) { FreeSpriteTilesByTag(TAG_CB_ITEM_ICON); FreeSpritePaletteByTag(TAG_CB_ITEM_ICON); DestroySprite(&gSprites[sItemSpriteId]); } } #undef sAuxWindowId #undef sItemSpriteId #undef TAG_CB_ITEM_ICON static void FreeListMenuItems(struct ListMenuItem *items, u32 count) { u32 i; for (i = 0; i < count; ++i) { // All items were dynamically allocated, so items[i].name is not actually constant. Free((void *)items[i].label); } Free(items); } bool8 ScriptMenu_MultichoiceWithDefault(u8 left, u8 top, u8 mcId, u8 ignoreBpress, u8 cursorPos) { if (FuncIsActiveTask(Task_HandleMultichoiceInput) == TRUE) return FALSE; gSpecialVar_Result = SCR_MENU_UNSET; DrawMultichoiceMenu(left, top, mcId, ignoreBpress, cursorPos); return TRUE; } void MultichoiceDynamic_InitStack(u32 capacity) { AGB_ASSERT(sDynamicMultiChoiceStack == NULL); sDynamicMultiChoiceStack = AllocZeroed(sizeof(*sDynamicMultiChoiceStack)); AGB_ASSERT(sDynamicMultiChoiceStack != NULL); sDynamicMultiChoiceStack->capacity = capacity; sDynamicMultiChoiceStack->top = -1; sDynamicMultiChoiceStack->elements = AllocZeroed(capacity * sizeof(struct ListMenuItem)); } void MultichoiceDynamic_ReallocStack(u32 newCapacity) { struct ListMenuItem *newElements; AGB_ASSERT(sDynamicMultiChoiceStack != NULL); AGB_ASSERT(sDynamicMultiChoiceStack->capacity < newCapacity); newElements = AllocZeroed(newCapacity * sizeof(struct ListMenuItem)); AGB_ASSERT(newElements != NULL); memcpy(newElements, sDynamicMultiChoiceStack->elements, sDynamicMultiChoiceStack->capacity * sizeof(struct ListMenuItem)); Free(sDynamicMultiChoiceStack->elements); sDynamicMultiChoiceStack->elements = newElements; sDynamicMultiChoiceStack->capacity = newCapacity; } bool32 MultichoiceDynamic_StackFull(void) { AGB_ASSERT(sDynamicMultiChoiceStack != NULL); return sDynamicMultiChoiceStack->top == sDynamicMultiChoiceStack->capacity - 1; } bool32 MultichoiceDynamic_StackEmpty(void) { AGB_ASSERT(sDynamicMultiChoiceStack != NULL); return sDynamicMultiChoiceStack->top == -1; } u32 MultichoiceDynamic_StackSize(void) { AGB_ASSERT(sDynamicMultiChoiceStack != NULL); return sDynamicMultiChoiceStack->top + 1; } void MultichoiceDynamic_PushElement(struct ListMenuItem item) { if (sDynamicMultiChoiceStack == NULL) MultichoiceDynamic_InitStack(MULTICHOICE_DYNAMIC_STACK_SIZE); if (MultichoiceDynamic_StackFull()) MultichoiceDynamic_ReallocStack(sDynamicMultiChoiceStack->capacity + MULTICHOICE_DYNAMIC_STACK_INC); sDynamicMultiChoiceStack->elements[++sDynamicMultiChoiceStack->top] = item; } struct ListMenuItem *MultichoiceDynamic_PopElement(void) { if (sDynamicMultiChoiceStack == NULL) return NULL; if (MultichoiceDynamic_StackEmpty()) return NULL; return &sDynamicMultiChoiceStack->elements[sDynamicMultiChoiceStack->top--]; } struct ListMenuItem *MultichoiceDynamic_PeekElement(void) { if (sDynamicMultiChoiceStack == NULL) return NULL; if (MultichoiceDynamic_StackEmpty()) return NULL; return &sDynamicMultiChoiceStack->elements[sDynamicMultiChoiceStack->top]; } struct ListMenuItem *MultichoiceDynamic_PeekElementAt(u32 index) { if (sDynamicMultiChoiceStack == NULL) return NULL; if (sDynamicMultiChoiceStack->top < index) return NULL; return &sDynamicMultiChoiceStack->elements[index]; } void MultichoiceDynamic_DestroyStack(void) { TRY_FREE_AND_SET_NULL(sDynamicMultiChoiceStack->elements); TRY_FREE_AND_SET_NULL(sDynamicMultiChoiceStack); } static void MultichoiceDynamic_MoveCursor(s32 itemIndex, bool8 onInit, struct ListMenu *list) { u8 taskId; if (!onInit) PlaySE(SE_SELECT); taskId = FindTaskIdByFunc(Task_HandleScrollingMultichoiceInput); if (taskId != TASK_NONE) { ListMenuGetScrollAndRow(gTasks[taskId].data[0], &gScrollableMultichoice_ScrollOffset, NULL); if (sDynamicMenuEventId != DYN_MULTICHOICE_CB_NONE && sDynamicListMenuEventCollections[sDynamicMenuEventId].OnSelectionChanged && !onInit) { struct DynamicListMenuEventArgs eventArgs = {.selectedItem = itemIndex, .windowId = list->template.windowId, .list = &list->template}; sDynamicListMenuEventCollections[sDynamicMenuEventId].OnSelectionChanged(&eventArgs); } } } static void DrawMultichoiceMenuDynamic(u8 left, u8 top, u8 argc, struct ListMenuItem *items, bool8 ignoreBPress, u32 initialRow, u8 maxBeforeScroll, u32 callbackSet) { u32 i; u8 windowId; s32 width = 0; u8 newWidth; u8 taskId; u32 windowHeight; struct ListMenu *list; for (i = 0; i < argc; ++i) { width = DisplayTextAndGetWidth(items[i].label, width); } LoadMessageBoxAndBorderGfx(); windowHeight = (argc < maxBeforeScroll) ? argc * 2 : maxBeforeScroll * 2; newWidth = ConvertPixelWidthToTileWidth(width); left = ScriptMenu_AdjustLeftCoordFromWidth(left, newWidth); windowId = CreateWindowFromRect(left, top, newWidth, windowHeight); SetStandardWindowBorderStyle(windowId, FALSE); CopyWindowToVram(windowId, COPYWIN_FULL); // I don't like this being global either, but I could not come up with another solution that // does not invade the whole ListMenu infrastructure. sDynamicMenuEventId = callbackSet; sDynamicMenuEventScratchPad = AllocZeroed(100 * sizeof(u16)); if (sDynamicMenuEventId != DYN_MULTICHOICE_CB_NONE && sDynamicListMenuEventCollections[sDynamicMenuEventId].OnInit) { struct DynamicListMenuEventArgs eventArgs = {.selectedItem = initialRow, .windowId = windowId, .list = NULL}; sDynamicListMenuEventCollections[sDynamicMenuEventId].OnInit(&eventArgs); } gMultiuseListMenuTemplate = sScriptableListMenuTemplate; gMultiuseListMenuTemplate.windowId = windowId; gMultiuseListMenuTemplate.items = items; gMultiuseListMenuTemplate.totalItems = argc; gMultiuseListMenuTemplate.maxShowed = maxBeforeScroll; gMultiuseListMenuTemplate.moveCursorFunc = MultichoiceDynamic_MoveCursor; taskId = CreateTask(Task_HandleScrollingMultichoiceInput, 80); gTasks[taskId].data[0] = ListMenuInit(&gMultiuseListMenuTemplate, 0, 0); gTasks[taskId].data[1] = ignoreBPress; gTasks[taskId].data[2] = windowId; gTasks[taskId].data[5] = argc; gTasks[taskId].data[7] = maxBeforeScroll; StoreWordInTwoHalfwords((u16*) &gTasks[taskId].data[3], (u32) items); list = (void *) gTasks[gTasks[taskId].data[0]].data; ListMenuChangeSelectionFull(list, TRUE, FALSE, initialRow, TRUE); if (sDynamicMenuEventId != DYN_MULTICHOICE_CB_NONE && sDynamicListMenuEventCollections[sDynamicMenuEventId].OnSelectionChanged) { struct DynamicListMenuEventArgs eventArgs = {.selectedItem = items[initialRow].index, .windowId = windowId, .list = &gMultiuseListMenuTemplate}; sDynamicListMenuEventCollections[sDynamicMenuEventId].OnSelectionChanged(&eventArgs); } ListMenuGetScrollAndRow(gTasks[taskId].data[0], &gScrollableMultichoice_ScrollOffset, NULL); if (argc > maxBeforeScroll) { // Create Scrolling Arrows struct ScrollArrowsTemplate template; template.firstX = (newWidth / 2) * 8 + 12 + (left) * 8; template.firstY = top * 8 + 5; template.secondX = template.firstX; template.secondY = top * 8 + windowHeight * 8 + 12; template.fullyUpThreshold = 0; template.fullyDownThreshold = argc - maxBeforeScroll; template.firstArrowType = SCROLL_ARROW_UP; template.secondArrowType = SCROLL_ARROW_DOWN; template.tileTag = 2000; template.palTag = 100, template.palNum = 0; gTasks[taskId].data[6] = AddScrollIndicatorArrowPair(&template, &gScrollableMultichoice_ScrollOffset); } } void DrawMultichoiceMenuInternal(u8 left, u8 top, u8 multichoiceId, bool8 ignoreBPress, u8 cursorPos, const struct MenuAction *actions, int count) { s32 i; s32 strWidth; s32 tmp; u8 width; u8 height; u8 windowId; if ((ignoreBPress & 2) || QL_AvoidDisplay(QL_DestroyAbortedDisplay) != TRUE) { ignoreBPress &= 1; strWidth = 0; for (i = 0; i < count; i++) { tmp = GetStringWidth(FONT_NORMAL, actions[i].text, 0); if (tmp > strWidth) strWidth = tmp; } width = (strWidth + 9) / 8 + 1; if (left + width > 28) left = 28 - width; height = GetMCWindowHeight(count); windowId = CreateWindowFromRect(left, top, width, height); SetStandardWindowBorderStyle(windowId, FALSE); PrintMenuActionTextsWithSpacing(windowId, FONT_NORMAL, 8, 2, 14, count, actions, 0, 2); InitMenuNormal(windowId, FONT_NORMAL, 0, 2, 14, count, cursorPos); InitMultichoiceCheckWrap(ignoreBPress, count, windowId, multichoiceId); ScheduleBgCopyTilemapToVram(0); } } static void DrawMultichoiceMenu(u8 left, u8 top, u8 mcId, u8 ignoreBpress, u8 initPos) { DrawMultichoiceMenuInternal(left, top, mcId, ignoreBpress, initPos, sMultichoiceLists[mcId].list, sMultichoiceLists[mcId].count); } static u8 GetMCWindowHeight(u8 count) { switch (count) { case 0: return 1; case 1: return 2; case 2: return 4; case 3: return 6; case 4: return 7; case 5: return 9; case 6: return 11; case 7: return 13; case 8: return 14; default: return 1; } } #define tTimer data[2] #define tIgnoreBPress data[4] #define tDoWrap data[5] #define tWindowId data[6] #define tMultichoiceId data[7] static void InitMultichoiceCheckWrap(bool8 ignoreBPress, u8 count, u8 windowId, u8 multichoiceId) { u8 taskId; sProcessInputDelay = 0; for (u8 i = 0; i < ARRAY_COUNT(sLinkServicesMultichoiceIds); i++) { if (sLinkServicesMultichoiceIds[i] == multichoiceId) { sProcessInputDelay = 12; } } taskId = CreateTask(Task_HandleMultichoiceInput, 80); gTasks[taskId].tIgnoreBPress = ignoreBPress; if (count > 3) gTasks[taskId].tDoWrap = TRUE; else gTasks[taskId].tDoWrap = FALSE; gTasks[taskId].tWindowId = windowId; gTasks[taskId].tMultichoiceId = multichoiceId; DrawLinkServicesMultichoiceMenu(multichoiceId); } static void Task_HandleScrollingMultichoiceInput(u8 taskId) { bool32 done = FALSE; s32 input = ListMenu_ProcessInput(gTasks[taskId].data[0]); switch (input) { case LIST_HEADER: case LIST_NOTHING_CHOSEN: break; case LIST_CANCEL: if (!gTasks[taskId].data[1]) { gSpecialVar_Result = MULTI_B_PRESSED; done = TRUE; } break; default: gSpecialVar_Result = input; done = TRUE; break; } if (done) { struct ListMenuItem *items; PlaySE(SE_SELECT); if (sDynamicMenuEventId != DYN_MULTICHOICE_CB_NONE && sDynamicListMenuEventCollections[sDynamicMenuEventId].OnDestroy) { struct DynamicListMenuEventArgs eventArgs = {.selectedItem = input, .windowId = gTasks[taskId].data[2], .list = NULL}; sDynamicListMenuEventCollections[sDynamicMenuEventId].OnDestroy(&eventArgs); } sDynamicMenuEventId = DYN_MULTICHOICE_CB_NONE; if (gTasks[taskId].data[5] > gTasks[taskId].data[7]) { RemoveScrollIndicatorArrowPair(gTasks[taskId].data[6]); } LoadWordFromTwoHalfwords((u16*) &gTasks[taskId].data[3], (u32* )(&items)); FreeListMenuItems(items, gTasks[taskId].data[5]); TRY_FREE_AND_SET_NULL(sDynamicMenuEventScratchPad); DestroyListMenuTask(gTasks[taskId].data[0], NULL, NULL); ClearStdWindowAndFrame(gTasks[taskId].data[2], TRUE); RemoveWindow(gTasks[taskId].data[2]); ScriptContext_Enable(); DestroyTask(taskId); } } static void Task_HandleMultichoiceInput(u8 taskId) { s16 *data = gTasks[taskId].data; s8 input; if (!gPaletteFade.active) { if (sProcessInputDelay != 0) sProcessInputDelay--; else { if (tDoWrap == FALSE) input = Menu_ProcessInputNoWrap(); else input = Menu_ProcessInput(); if (JOY_NEW(DPAD_UP | DPAD_DOWN)) DrawLinkServicesMultichoiceMenu(tMultichoiceId); switch (input) { case MENU_NOTHING_CHOSEN: return; case MENU_B_PRESSED: if (tIgnoreBPress) return; PlaySE(SE_SELECT); gSpecialVar_Result = SCR_MENU_CANCEL; break; default: gSpecialVar_Result = input; break; } DestroyScriptMenuWindow(tWindowId); DestroyTask(taskId); ScriptContext_Enable(); } } } static void DrawLinkServicesMultichoiceMenu(u8 mcId) { switch (mcId) { case MULTICHOICE_TRADE_CENTER_COLOSSEUM: FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, FONT_NORMAL, sDescriptionPtrs_CableClub_TradeBattleCancel[Menu_GetCursorPos()], 0, NULL, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY); break; case MULTICHOICE_TRADE_COLOSSEUM_CRUSH: FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, FONT_NORMAL, sDescriptionPtrs_WirelessCenter_TradeBattleCrushCancel[Menu_GetCursorPos()], 0, NULL, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY); break; case MULTICHOICE_TRADE_COLOSSEUM_2: FillWindowPixelBuffer(0, PIXEL_FILL(1)); AddTextPrinterParameterized2(0, FONT_NORMAL, sDescriptionPtrs_WirelessCenter_TradeBattleCancel[Menu_GetCursorPos()], 0, NULL, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY); break; } } bool8 ScriptMenu_YesNo(u8 unused, u8 stuff) { if (FuncIsActiveTask(Task_YesNoMenu_HandleInput) == TRUE) return FALSE; gSpecialVar_Result = SCR_MENU_UNSET; if (QL_AvoidDisplay(QL_DestroyAbortedDisplay)) return TRUE; DisplayYesNoMenuDefaultYes(); CreateTask(Task_YesNoMenu_HandleInput, 80); return TRUE; } static void Task_YesNoMenu_HandleInput(u8 taskId) { s8 input; if (gTasks[taskId].tTimer < 5) { gTasks[taskId].tTimer++; } else { input = Menu_ProcessInputNoWrapClearOnChoose(); switch (input) { case MENU_NOTHING_CHOSEN: return; case MENU_B_PRESSED: case 1: // NO PlaySE(SE_SELECT); gSpecialVar_Result = FALSE; break; case 0: // YES gSpecialVar_Result = TRUE; break; } DestroyTask(taskId); ScriptContext_Enable(); } } bool8 ScriptMenu_MultichoiceGrid(u8 left, u8 top, u8 multichoiceId, bool8 ignoreBpress, u8 columnCount) { const struct MenuAction * list; u8 count; u8 width; u8 rowCount; u8 taskId; if (FuncIsActiveTask(Hask_MultichoiceGridMenu_HandleInput) == TRUE) return FALSE; gSpecialVar_Result = SCR_MENU_UNSET; if (QL_AvoidDisplay(QL_DestroyAbortedDisplay) == TRUE) return TRUE; list = sMultichoiceLists[multichoiceId].list; count = sMultichoiceLists[multichoiceId].count; width = GetMenuWidthFromList(list, count) + 1; rowCount = count / columnCount; taskId = CreateTask(Hask_MultichoiceGridMenu_HandleInput, 80); gTasks[taskId].tIgnoreBPress = ignoreBpress; gTasks[taskId].tWindowId = CreateWindowFromRect(left, top, width * columnCount, rowCount * 2); SetStandardWindowBorderStyle(gTasks[taskId].tWindowId, FALSE); MultichoiceGrid_PrintItems(gTasks[taskId].tWindowId, FONT_NORMAL_COPY_1, width * 8, 16, columnCount, rowCount, list); MultichoiceGrid_InitCursor(gTasks[taskId].tWindowId, FONT_NORMAL_COPY_1, 0, 1, width * 8, columnCount, rowCount, 0); ScheduleBgCopyTilemapToVram(0); return TRUE; } static void Hask_MultichoiceGridMenu_HandleInput(u8 taskId) { s16 *data = gTasks[taskId].data; s8 input = Menu_ProcessInputGridLayout(); switch (input) { case MENU_NOTHING_CHOSEN: return; case MENU_B_PRESSED: if (tIgnoreBPress) return; PlaySE(SE_SELECT); gSpecialVar_Result = SCR_MENU_CANCEL; break; default: gSpecialVar_Result = input; break; } DestroyScriptMenuWindow(tWindowId); DestroyTask(taskId); ScriptContext_Enable(); } #undef tIgnoreBPress #undef tDoWrap #undef tWindowId #undef tMultichoiceId #define tState data[0] #define tSpecies data[1] #define tSpriteId data[2] #define tWindowId data[5] bool8 CreatePCMenu(void) { if (FuncIsActiveTask(Task_HandleMultichoiceInput) == TRUE) return FALSE; gSpecialVar_Result = SCR_MENU_UNSET; CreatePCMenuWindow(); return TRUE; } static void CreatePCMenuWindow(void) { u8 cursorWidth = GetMenuCursorDimensionByFont(FONT_NORMAL, 0); u8 UNUSED height = GetFontAttribute(FONT_NORMAL, FONTATTR_MAX_LETTER_HEIGHT); u8 windowWidth; u8 numItems; u8 windowId; switch (GetStringTilesWide(gText_SPc)) { default: if (FlagGet(FLAG_SYS_POKEDEX_GET)) windowWidth = 14; else windowWidth = 13; break; case 9: case 10: windowWidth = 14; break; } if (FlagGet(FLAG_SYS_GAME_CLEAR)) { numItems = 5; windowId = CreateWindowFromRect(0, 0, windowWidth, 10); SetStandardWindowBorderStyle(windowId, FALSE); AddTextPrinterParameterized(windowId, FONT_NORMAL, gText_ProfOakSPc, cursorWidth, 34, TEXT_SKIP_DRAW, NULL); AddTextPrinterParameterized(windowId, FONT_NORMAL, gText_HallOfFame_2, cursorWidth, 50, TEXT_SKIP_DRAW, NULL); AddTextPrinterParameterized(windowId, FONT_NORMAL, gText_LogOff, cursorWidth, 66, TEXT_SKIP_DRAW, NULL); } else { if (FlagGet(FLAG_SYS_POKEDEX_GET)) numItems = 4; else numItems = 3; windowId = CreateWindowFromRect(0, 0, windowWidth, numItems * 2); SetStandardWindowBorderStyle(windowId, FALSE); if (FlagGet(FLAG_SYS_POKEDEX_GET)) AddTextPrinterParameterized(windowId, FONT_NORMAL, gText_ProfOakSPc, cursorWidth, 34, TEXT_SKIP_DRAW, NULL); AddTextPrinterParameterized(windowId, FONT_NORMAL, gText_LogOff, cursorWidth, 2 + 16 * (numItems - 1), TEXT_SKIP_DRAW, NULL); } if (FlagGet(FLAG_SYS_NOT_SOMEONES_PC)) AddTextPrinterParameterized(windowId, FONT_NORMAL, gText_BillSPc, cursorWidth, 2 , TEXT_SKIP_DRAW, NULL); else AddTextPrinterParameterized(windowId, FONT_NORMAL, gText_SomeoneSPc, cursorWidth, 2 , TEXT_SKIP_DRAW, NULL); StringExpandPlaceholders(gStringVar4, gText_SPc); PrintPlayerNameOnWindow(windowId, gStringVar4, cursorWidth, 18); InitMenuNormal(windowId, FONT_NORMAL, 0, 2, 16, numItems, 0); InitMultichoiceCheckWrap(FALSE, numItems, windowId, MULTICHOICE_NONE); ScheduleBgCopyTilemapToVram(0); } void ScriptMenu_DisplayPCStartupPrompt(void) { LoadMessageBoxAndFrameGfx(0, TRUE); AddTextPrinterParameterized2(0, FONT_NORMAL, Text_AccessWhichPC, 0, NULL, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY); } static void Task_ScriptShowMonPic(u8 taskId) { struct Task *task = &gTasks[taskId]; switch (task->tState) { case 0: task->tState++; break; case 1: break; case 2: FreeResourcesAndDestroySprite(&gSprites[task->tSpriteId], task->tSpriteId); task->tState++; break; case 3: DestroyScriptMenuWindow(task->tWindowId); DestroyTask(taskId); break; } } bool8 ScriptMenu_ShowPokemonPic(u16 species, u8 x, u8 y) { u8 spriteId; u8 taskId; if (QL_AvoidDisplay(QL_DestroyAbortedDisplay) == TRUE) return TRUE; if (FindTaskIdByFunc(Task_ScriptShowMonPic) != TASK_NONE) return FALSE; spriteId = CreateMonSprite_PicBox(species, 8 * x + 40, 8 * y + 40, FALSE); taskId = CreateTask(Task_ScriptShowMonPic, 80); gTasks[taskId].tWindowId = CreateWindowFromRect(x, y, 8, 8); gTasks[taskId].tState = 0; gTasks[taskId].tSpecies = species; gTasks[taskId].tSpriteId = spriteId; gSprites[spriteId].callback = SpriteCallbackDummy; gSprites[spriteId].oam.priority = 0; SetStandardWindowBorderStyle(gTasks[taskId].tWindowId, TRUE); ScheduleBgCopyTilemapToVram(0); return TRUE; } bool8 (*ScriptMenu_HidePokemonPic(void))(void) { u8 taskId = FindTaskIdByFunc(Task_ScriptShowMonPic); if (taskId == TASK_NONE) return NULL; gTasks[taskId].tState++; return PicboxWait; } static bool8 PicboxWait(void) { if (FindTaskIdByFunc(Task_ScriptShowMonPic) == TASK_NONE) return TRUE; else return FALSE; } void PicboxCancel(void) { u8 taskId = FindTaskIdByFunc(Task_ScriptShowMonPic); struct Task *task; if (taskId != TASK_NONE) { task = &gTasks[taskId]; switch (task->tState) { case 0: case 1: case 2: FreeResourcesAndDestroySprite(&gSprites[task->tSpriteId], task->tSpriteId); DestroyScriptMenuWindow(task->tWindowId); DestroyTask(taskId); break; case 3: DestroyScriptMenuWindow(task->tWindowId); DestroyTask(taskId); break; } } } void Task_WaitMuseumFossilPic(u8 taskId) { struct Task *task = &gTasks[taskId]; switch (task->tState) { case 0: task->tState++; break; case 1: break; case 2: DestroySprite(&gSprites[task->tSpriteId]); FreeSpriteTilesByTag(GFXTAG_FOSSIL); task->tState++; break; case 3: DestroyScriptMenuWindow(task->tWindowId); DestroyTask(taskId); break; } } #define FOSSIL_PIC_PAL_NUM 13 bool8 OpenMuseumFossilPic(void) { u8 spriteId; u8 taskId; if (QL_AvoidDisplay(QL_DestroyAbortedDisplay) == TRUE) return TRUE; if (FindTaskIdByFunc(Task_WaitMuseumFossilPic) != TASK_NONE) return FALSE; if (gSpecialVar_0x8004 == SPECIES_KABUTOPS) { LoadSpriteSheets(sMuseumKabutopsSprSheets); LoadPalette(sMuseumKabutopsSprPalette, OBJ_PLTT_ID(FOSSIL_PIC_PAL_NUM), sizeof(sMuseumKabutopsSprPalette)); } else if (gSpecialVar_0x8004 == SPECIES_AERODACTYL) { LoadSpriteSheets(sMuseumAerodactylSprSheets); LoadPalette(sMuseumAerodactylSprPalette, OBJ_PLTT_ID(FOSSIL_PIC_PAL_NUM), sizeof(sMuseumAerodactylSprPalette)); } else { return FALSE; } spriteId = CreateSprite(&sMuseumFossilSprTemplate, gSpecialVar_0x8005 * 8 + 40, gSpecialVar_0x8006 * 8 + 40, 0); gSprites[spriteId].oam.paletteNum = FOSSIL_PIC_PAL_NUM; taskId = CreateTask(Task_WaitMuseumFossilPic, 80); gTasks[taskId].tWindowId = CreateWindowFromRect(gSpecialVar_0x8005, gSpecialVar_0x8006, 8, 8); gTasks[taskId].tState = 0; gTasks[taskId].tSpriteId = spriteId; SetStandardWindowBorderStyle(gTasks[taskId].tWindowId, TRUE); ScheduleBgCopyTilemapToVram(0); return TRUE; } bool8 CloseMuseumFossilPic(void) { u8 taskId = FindTaskIdByFunc(Task_WaitMuseumFossilPic); if (taskId == TASK_NONE) return FALSE; gTasks[taskId].tState++; return TRUE; } static u8 CreateWindowFromRect(u8 left, u8 top, u8 width, u8 height) { struct WindowTemplate template = CreateWindowTemplate(0, left + 1, top + 1, width, height, 15, 0x038); u8 windowId = AddWindow(&template); PutWindowTilemap(windowId); return windowId; } static void DestroyScriptMenuWindow(u8 windowId) { ClearWindowTilemap(windowId); ClearStdWindowAndFrameToTransparent(windowId, TRUE); RemoveWindow(windowId); } void QL_DestroyAbortedDisplay(void) { u8 taskId; s16 *data; ScriptContext_SetupScript(EventScript_ReleaseEnd); taskId = FindTaskIdByFunc(Task_ScriptShowMonPic); if (taskId != TASK_NONE) { data = gTasks[taskId].data; if (tState < 2) FreeResourcesAndDestroySprite(&gSprites[tSpriteId], tSpriteId); } taskId = FindTaskIdByFunc(Task_WaitMuseumFossilPic); if (taskId != TASK_NONE) { data = gTasks[taskId].data; if (tState < 2) { DestroySprite(&gSprites[tSpriteId]); FreeSpriteTilesByTag(GFXTAG_FOSSIL); } } } void DrawSeagallopDestinationMenu(void) { // 8004 = Starting location // 8005 = Page (0: Verm, One, Two, Three, Four, Other, Exit; 1: Four, Five, Six, Seven, Other, Exit) u8 destinationId; u8 top; u8 numItems; u8 cursorWidth; u8 UNUSED fontHeight; u8 windowId; u8 i; gSpecialVar_Result = SCR_MENU_UNSET; if (QL_AvoidDisplay(QL_DestroyAbortedDisplay) == TRUE) return; if (gSpecialVar_0x8005 == 1) { if (gSpecialVar_0x8004 < SEAGALLOP_FIVE_ISLAND) destinationId = SEAGALLOP_FIVE_ISLAND; else destinationId = SEAGALLOP_FOUR_ISLAND; numItems = 5; top = 2; } else { destinationId = SEAGALLOP_VERMILION_CITY; numItems = 6; top = 0; } cursorWidth = GetMenuCursorDimensionByFont(FONT_NORMAL, 0); fontHeight = GetFontAttribute(FONT_NORMAL, FONTATTR_MAX_LETTER_HEIGHT); windowId = CreateWindowFromRect(17, top, 11, numItems * 2); SetStandardWindowBorderStyle(windowId, FALSE); // -2 excludes "Other" and "Exit", appended after the loop for (i = 0; i < numItems - 2; i++) { if (destinationId != gSpecialVar_0x8004) AddTextPrinterParameterized(windowId, FONT_NORMAL, sSeagallopDestStrings[destinationId], cursorWidth, i * 16 + 2, TEXT_SKIP_DRAW, NULL); else i--; destinationId++; // Wrap around if (destinationId == SEAGALLOP_SEVEN_ISLAND + 1) destinationId = SEAGALLOP_VERMILION_CITY; } AddTextPrinterParameterized(windowId, FONT_NORMAL, gText_Other, cursorWidth, i * 16 + 2, TEXT_SKIP_DRAW, NULL); i++; AddTextPrinterParameterized(windowId, FONT_NORMAL, gOtherText_Exit, cursorWidth, i * 16 + 2, TEXT_SKIP_DRAW, NULL); InitMenuNormal(windowId, FONT_NORMAL, 0, 2, 16, numItems, 0); InitMultichoiceCheckWrap(FALSE, numItems, windowId, MULTICHOICE_NONE); ScheduleBgCopyTilemapToVram(0); } u16 GetSelectedSeagallopDestination(void) { // 8004 = Starting location // 8005 = Page (0: Verm, One, Two, Three, Four, Other, Exit; 1: Four, Five, Six, Seven, Other, Exit) if (gSpecialVar_Result == SCR_MENU_CANCEL) return SCR_MENU_CANCEL; if (gSpecialVar_0x8005 == 1) { if (gSpecialVar_Result == 3) { return SEAGALLOP_MORE; } else if (gSpecialVar_Result == 4) { return SCR_MENU_CANCEL; } else if (gSpecialVar_Result == 0) { if (gSpecialVar_0x8004 > SEAGALLOP_FOUR_ISLAND) return SEAGALLOP_FOUR_ISLAND; else return SEAGALLOP_FIVE_ISLAND; } else if (gSpecialVar_Result == 1) { if (gSpecialVar_0x8004 > SEAGALLOP_FIVE_ISLAND) return SEAGALLOP_FIVE_ISLAND; else return SEAGALLOP_SIX_ISLAND; } else if (gSpecialVar_Result == 2) { if (gSpecialVar_0x8004 > SEAGALLOP_SIX_ISLAND) return SEAGALLOP_SIX_ISLAND; else return SEAGALLOP_SEVEN_ISLAND; } } else { if (gSpecialVar_Result == 4) return SEAGALLOP_MORE; else if (gSpecialVar_Result == 5) return SCR_MENU_CANCEL; else if (gSpecialVar_Result >= gSpecialVar_0x8004) return gSpecialVar_Result + 1; else return gSpecialVar_Result; } return SEAGALLOP_VERMILION_CITY; } static int DisplayTextAndGetWidthInternal(const u8 *str) { u8 temp[64]; StringExpandPlaceholders(temp, str); return GetStringWidth(FONT_NORMAL, temp, 0); } int DisplayTextAndGetWidth(const u8 *str, int prevWidth) { int width = DisplayTextAndGetWidthInternal(str); if (width < prevWidth) { width = prevWidth; } return width; } int ConvertPixelWidthToTileWidth(int width) { return (((width + 9) / 8) + 1) > MAX_MULTICHOICE_WIDTH ? MAX_MULTICHOICE_WIDTH : (((width + 9) / 8) + 1); } int ScriptMenu_AdjustLeftCoordFromWidth(int left, int width) { int adjustedLeft = left; if (left + width > MAX_MULTICHOICE_WIDTH) { if (MAX_MULTICHOICE_WIDTH - width < 0) { adjustedLeft = 0; } else { adjustedLeft = MAX_MULTICHOICE_WIDTH - width; } } return adjustedLeft; }