pokeemerald/src/main_menu.c

2304 lines
80 KiB
C
Raw Normal View History

2017-09-30 16:01:52 +02:00
#include "global.h"
2018-08-19 01:06:10 +02:00
#include "trainer_pokemon_sprites.h"
#include "bg.h"
#include "constants/rgb.h"
#include "constants/songs.h"
2018-09-14 19:15:46 +02:00
#include "constants/trainers.h"
#include "decompress.h"
#include "event_data.h"
2018-02-11 23:19:36 +01:00
#include "field_effect.h"
#include "gpu_regs.h"
2018-02-12 00:00:45 +01:00
#include "graphics.h"
2018-02-11 23:19:36 +01:00
#include "international_string_util.h"
#include "link.h"
#include "main.h"
#include "main_menu.h"
#include "menu.h"
2018-05-19 11:53:22 +02:00
#include "list_menu.h"
2018-02-11 23:19:36 +01:00
#include "mystery_event_menu.h"
#include "naming_screen.h"
#include "option_menu.h"
#include "overworld.h"
#include "palette.h"
#include "pokeball.h"
2018-02-11 23:19:36 +01:00
#include "pokedex.h"
2019-04-04 00:15:08 +02:00
#include "pokemon.h"
2018-02-11 23:19:36 +01:00
#include "random.h"
#include "rtc.h"
#include "save.h"
#include "scanline_effect.h"
#include "sound.h"
#include "sprite.h"
2018-02-11 23:19:36 +01:00
#include "strings.h"
#include "string_util.h"
#include "task.h"
#include "text.h"
#include "text_window.h"
2018-02-11 23:19:36 +01:00
#include "title_screen.h"
#include "window.h"
#include "mystery_gift_menu.h"
2017-09-30 16:01:52 +02:00
/*
* Main menu state machine
* -----------------------
*
* Entry point: CB2_InitMainMenu
*
* Note: States advance sequentially unless otherwise stated.
*
* CB2_InitMainMenu / CB2_ReinitMainMenu
* - Both of these states call InitMainMenu, which does all the work.
* - In the Reinit case, the init code will check if the user came from
* the options screen. If they did, then the options menu item is
* pre-selected.
*
* Task_MainMenuCheckSaveFile
* - Determines how many menu options to show based on whether
* the save file is Ok, empty, corrupted, etc.
* - If there was an error loading the save file, advance to
* Task_WaitForSaveFileErrorWindow.
* - If there were no errors, advance to Task_MainMenuCheckBattery.
* - Note that the check to enable Mystery Events would normally happen
* here, but this version of Emerald has them disabled.
*
* Task_WaitForSaveFileErrorWindow
* - Wait for the text to finish printing and then for the A button
* to be pressed.
*
* Task_MainMenuCheckBattery
* - If the battery is OK, advance to Task_DisplayMainMenu.
* - If the battery is dry, advance to Task_WaitForBatteryDryErrorWindow.
*
* Task_WaitForBatteryDryErrorWindow
* - Wait for the text to finish printing and then for the A button
* to be pressed.
*
* Task_DisplayMainWindow
* - Display the buttons to the user. If the menu is in HAS_MYSTERY_EVENTS
* mode, there are too many buttons for one screen and a scrollbar is added,
* and the scrollbar task is spawned (Task_ScrollIndicatorArrowPairOnMainMenu).
*
* Task_HighlightSelectedMainMenuItem
* - Update the UI to match the currently selected item.
*
* Task_HandleMainMenuInput
* - If A is pressed, advance to Task_HandleMainMenuAPressed.
* - If B is pressed, return to the title screen via CB2_InitTitleScreen.
* - If Up or Down is pressed, handle scrolling if there is a scroll bar, change
* the selection, then go back to Task_HighlightSelectedMainMenuItem.
*
* Task_HandleMainMenuAPressed
* - If the user selected New Game, advance to Task_NewGameBirchSpeech_Init.
* - If the user selected Continue, advance to CB2_ContinueSavedGame.
* - If the user selected the Options menu, advance to CB2_InitOptionMenu.
2021-10-14 20:10:42 +02:00
* - If the user selected Mystery Gift, advance to CB2_InitMysteryGift. However,
* if the wireless adapter was removed, instead advance to
* Task_DisplayMainMenuInvalidActionError.
* - Code to start a Mystery Event is present here, but is unreachable in this
* version.
*
* Task_HandleMainMenuBPressed
* - Clean up the main menu and go back to CB2_InitTitleScreen.
*
* Task_DisplayMainMenuInvalidActionError
* - Print one of three different error messages, wait for the text to stop
* printing, and then wait for A or B to be pressed.
* - Then advance to Task_HandleMainMenuBPressed.
*
2021-12-25 11:04:19 +01:00
* Task_NewGameBirchSpeech_Init
* - Load the sprites for the intro speech, start playing music
* Task_NewGameBirchSpeech_WaitToShowBirch
* - Spawn Task_NewGameBirchSpeech_FadeInTarget1OutTarget2
* - Spawn Task_NewGameBirchSpeech_FadePlatformOut
* - Both of these tasks destroy themselves when done.
* Task_NewGameBirchSpeech_WaitForSpriteFadeInWelcome
* Task_NewGameBirchSpeech_ThisIsAPokemon
* - When the text is done printing, spawns Task_NewGameBirchSpeechSub_InitPokeball
* Task_NewGameBirchSpeech_MainSpeech
* Task_NewGameBirchSpeech_AndYouAre
* Task_NewGameBirchSpeech_StartBirchLotadPlatformFade
* Task_NewGameBirchSpeech_StartBirchLotadPlatformFade
* Task_NewGameBirchSpeech_SlidePlatformAway
* Task_NewGameBirchSpeech_StartPlayerFadeIn
* Task_NewGameBirchSpeech_WaitForPlayerFadeIn
* Task_NewGameBirchSpeech_BoyOrGirl
* Task_NewGameBirchSpeech_WaitToShowGenderMenu
* Task_NewGameBirchSpeech_ChooseGender
* - Animates by advancing to Task_NewGameBirchSpeech_SlideOutOldGenderSprite
* whenever the player's selection changes.
* - Advances to Task_NewGameBirchSpeech_WhatsYourName when done.
*
* Task_NewGameBirchSpeech_SlideOutOldGenderSprite
* Task_NewGameBirchSpeech_SlideInNewGenderSprite
* - Returns back to Task_NewGameBirchSpeech_ChooseGender.
*
* Task_NewGameBirchSpeech_WhatsYourName
* Task_NewGameBirchSpeech_WaitForWhatsYourNameToPrint
* Task_NewGameBirchSpeech_WaitPressBeforeNameChoice
* Task_NewGameBirchSpeech_StartNamingScreen
* C2_NamingScreen
* - Returns to CB2_NewGameBirchSpeech_ReturnFromNamingScreen when done
* CB2_NewGameBirchSpeech_ReturnFromNamingScreen
* Task_NewGameBirchSpeech_ReturnFromNamingScreenShowTextbox
* Task_NewGameBirchSpeech_SoItsPlayerName
* Task_NewGameBirchSpeech_CreateNameYesNo
* Task_NewGameBirchSpeech_ProcessNameYesNoMenu
* - If confirmed, advance to Task_NewGameBirchSpeech_SlidePlatformAway2.
* - Otherwise, return to Task_NewGameBirchSpeech_BoyOrGirl.
*
* Task_NewGameBirchSpeech_SlidePlatformAway2
* Task_NewGameBirchSpeech_ReshowBirchLotad
* Task_NewGameBirchSpeech_WaitForSpriteFadeInAndTextPrinter
* Task_NewGameBirchSpeech_AreYouReady
* Task_NewGameBirchSpeech_ShrinkPlayer
* Task_NewGameBirchSpeech_WaitForPlayerShrink
* Task_NewGameBirchSpeech_FadePlayerToWhite
* Task_NewGameBirchSpeech_Cleanup
* - Advances to CB2_NewGame.
*
* Task_NewGameBirchSpeechSub_InitPokeball
* - Advances to Task_NewGameBirchSpeechSub_WaitForLotad
* Task_NewGameBirchSpeechSub_WaitForLotad
* - Destroys itself when done.
*/
2021-10-03 05:47:59 +02:00
#define OPTION_MENU_FLAG (1 << 15)
2017-09-30 16:01:52 +02:00
// Static type declarations
// Static RAM declarations
2021-09-24 20:30:15 +02:00
static EWRAM_DATA bool8 sStartedPokeBallTask = 0;
2018-07-15 13:23:38 +02:00
static EWRAM_DATA u16 sCurrItemAndOptionMenuCheck = 0;
static u8 sBirchSpeechMainTaskId;
2017-09-30 16:01:52 +02:00
// Static ROM declarations
2018-09-14 19:15:46 +02:00
static u32 InitMainMenu(bool8);
static void Task_MainMenuCheckSaveFile(u8);
static void Task_MainMenuCheckBattery(u8);
static void Task_WaitForSaveFileErrorWindow(u8);
static void CreateMainMenuErrorWindow(const u8 *);
2022-07-29 17:15:33 +02:00
static void ClearMainMenuWindowTilemap(const struct WindowTemplate *);
2018-09-14 19:15:46 +02:00
static void Task_DisplayMainMenu(u8);
static void Task_WaitForBatteryDryErrorWindow(u8);
static void MainMenu_FormatSavegameText(void);
static void HighlightSelectedMainMenuItem(u8, u8, s16);
static void Task_HandleMainMenuInput(u8);
static void Task_HandleMainMenuAPressed(u8);
static void Task_HandleMainMenuBPressed(u8);
static void Task_NewGameBirchSpeech_Init(u8);
static void Task_DisplayMainMenuInvalidActionError(u8);
static void AddBirchSpeechObjects(u8);
static void Task_NewGameBirchSpeech_WaitToShowBirch(u8);
static void NewGameBirchSpeech_StartFadeInTarget1OutTarget2(u8, u8);
static void NewGameBirchSpeech_StartFadePlatformOut(u8, u8);
static void Task_NewGameBirchSpeech_WaitForSpriteFadeInWelcome(u8);
static void NewGameBirchSpeech_ShowDialogueWindow(u8, u8);
static void NewGameBirchSpeech_ClearWindow(u8);
static void Task_NewGameBirchSpeech_ThisIsAPokemon(u8);
static void Task_NewGameBirchSpeech_MainSpeech(u8);
2022-06-01 18:41:57 +02:00
static void NewGameBirchSpeech_WaitForThisIsPokemonText(struct TextPrinterTemplate *, u16);
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_AndYouAre(u8);
static void Task_NewGameBirchSpeechSub_WaitForLotad(u8);
static void Task_NewGameBirchSpeech_StartBirchLotadPlatformFade(u8);
static void NewGameBirchSpeech_StartFadeOutTarget1InTarget2(u8, u8);
static void NewGameBirchSpeech_StartFadePlatformIn(u8, u8);
static void Task_NewGameBirchSpeech_SlidePlatformAway(u8);
static void Task_NewGameBirchSpeech_StartPlayerFadeIn(u8);
static void Task_NewGameBirchSpeech_WaitForPlayerFadeIn(u8);
static void Task_NewGameBirchSpeech_BoyOrGirl(u8);
static void LoadMainMenuWindowFrameTiles(u8, u16);
2022-07-29 17:15:33 +02:00
static void DrawMainMenuWindowBorder(const struct WindowTemplate *, u16);
2018-09-14 19:15:46 +02:00
static void Task_HighlightSelectedMainMenuItem(u8);
static void Task_NewGameBirchSpeech_WaitToShowGenderMenu(u8);
static void Task_NewGameBirchSpeech_ChooseGender(u8);
static void NewGameBirchSpeech_ShowGenderMenu(void);
static s8 NewGameBirchSpeech_ProcessGenderMenuInput(void);
static void NewGameBirchSpeech_ClearGenderWindow(u8, u8);
static void Task_NewGameBirchSpeech_WhatsYourName(u8);
static void Task_NewGameBirchSpeech_SlideOutOldGenderSprite(u8);
static void Task_NewGameBirchSpeech_SlideInNewGenderSprite(u8);
static void Task_NewGameBirchSpeech_WaitForWhatsYourNameToPrint(u8);
static void Task_NewGameBirchSpeech_WaitPressBeforeNameChoice(u8);
static void Task_NewGameBirchSpeech_StartNamingScreen(u8);
static void CB2_NewGameBirchSpeech_ReturnFromNamingScreen(void);
static void Task_NewGameBirchSpeech_CreateNameYesNo(u8);
static void Task_NewGameBirchSpeech_ProcessNameYesNoMenu(u8);
void CreateYesNoMenuParameterized(u8, u8, u16, u16, u8, u8);
static void Task_NewGameBirchSpeech_SlidePlatformAway2(u8);
static void Task_NewGameBirchSpeech_ReshowBirchLotad(u8);
static void Task_NewGameBirchSpeech_WaitForSpriteFadeInAndTextPrinter(u8);
static void Task_NewGameBirchSpeech_AreYouReady(u8);
static void Task_NewGameBirchSpeech_ShrinkPlayer(u8);
2022-07-29 17:15:33 +02:00
static void SpriteCB_MovePlayerDownWhileShrinking(struct Sprite *);
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_WaitForPlayerShrink(u8);
static void Task_NewGameBirchSpeech_FadePlayerToWhite(u8);
static void Task_NewGameBirchSpeech_Cleanup(u8);
static void SpriteCB_Null();
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_ReturnFromNamingScreenShowTextbox(u8);
static void MainMenu_FormatSavegamePlayer(void);
static void MainMenu_FormatSavegamePokedex(void);
static void MainMenu_FormatSavegameTime(void);
static void MainMenu_FormatSavegameBadges(void);
static void NewGameBirchSpeech_CreateDialogueWindowBorder(u8, u8, u8, u8, u8, u8);
2017-09-30 16:01:52 +02:00
// .rodata
2018-09-14 19:15:46 +02:00
static const u16 sBirchSpeechBgPals[][16] = {
2018-02-14 04:12:02 +01:00
INCBIN_U16("graphics/birch_speech/bg0.gbapal"),
INCBIN_U16("graphics/birch_speech/bg1.gbapal")
};
2018-10-21 09:24:57 +02:00
static const u32 sBirchSpeechShadowGfx[] = INCBIN_U32("graphics/birch_speech/shadow.4bpp.lz");
static const u32 sBirchSpeechBgMap[] = INCBIN_U32("graphics/birch_speech/map.bin.lz");
2018-09-14 19:15:46 +02:00
static const u16 sBirchSpeechBgGradientPal[] = INCBIN_U16("graphics/birch_speech/bg2.gbapal");
static const u16 sBirchSpeechPlatformBlackPal[] = {RGB_BLACK, RGB_BLACK, RGB_BLACK, RGB_BLACK, RGB_BLACK, RGB_BLACK, RGB_BLACK, RGB_BLACK};
2018-02-14 04:12:02 +01:00
2018-09-08 02:24:33 +02:00
#define MENU_LEFT 2
#define MENU_TOP_WIN0 1
#define MENU_TOP_WIN1 5
#define MENU_TOP_WIN2 1
#define MENU_TOP_WIN3 9
#define MENU_TOP_WIN4 13
#define MENU_TOP_WIN5 17
#define MENU_TOP_WIN6 21
#define MENU_WIDTH 26
#define MENU_HEIGHT_WIN0 2
#define MENU_HEIGHT_WIN1 2
#define MENU_HEIGHT_WIN2 6
#define MENU_HEIGHT_WIN3 2
#define MENU_HEIGHT_WIN4 2
#define MENU_HEIGHT_WIN5 2
#define MENU_HEIGHT_WIN6 2
#define MENU_LEFT_ERROR 2
#define MENU_TOP_ERROR 15
#define MENU_WIDTH_ERROR 26
#define MENU_HEIGHT_ERROR 4
#define MENU_SHADOW_PADDING 1
#define MENU_WIN_HCOORDS WIN_RANGE(((MENU_LEFT - 1) * 8) + MENU_SHADOW_PADDING, (MENU_LEFT + MENU_WIDTH + 1) * 8 - MENU_SHADOW_PADDING)
#define MENU_WIN_VCOORDS(n) WIN_RANGE(((MENU_TOP_WIN##n - 1) * 8) + MENU_SHADOW_PADDING, (MENU_TOP_WIN##n + MENU_HEIGHT_WIN##n + 1) * 8 - MENU_SHADOW_PADDING)
#define MENU_SCROLL_SHIFT WIN_RANGE(32, 32)
2018-09-14 19:15:46 +02:00
static const struct WindowTemplate sWindowTemplates_MainMenu[] =
2018-09-08 02:24:33 +02:00
{
// No saved game
// NEW GAME
2018-09-02 18:53:52 +02:00
{
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-08 02:24:33 +02:00
.tilemapLeft = MENU_LEFT,
.tilemapTop = MENU_TOP_WIN0,
.width = MENU_WIDTH,
.height = MENU_HEIGHT_WIN0,
2018-09-02 18:53:52 +02:00
.paletteNum = 15,
.baseBlock = 1
},
2018-09-08 02:24:33 +02:00
// OPTIONS
2018-09-02 18:53:52 +02:00
{
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-08 02:24:33 +02:00
.tilemapLeft = MENU_LEFT,
.tilemapTop = MENU_TOP_WIN1,
.width = MENU_WIDTH,
.height = MENU_HEIGHT_WIN1,
2018-09-02 18:53:52 +02:00
.paletteNum = 15,
.baseBlock = 0x35
2018-09-08 02:24:33 +02:00
},
// Has saved game
// CONTINUE
2018-09-02 18:53:52 +02:00
{
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-08 02:24:33 +02:00
.tilemapLeft = MENU_LEFT,
.tilemapTop = MENU_TOP_WIN2,
.width = MENU_WIDTH,
.height = MENU_HEIGHT_WIN2,
2018-09-02 18:53:52 +02:00
.paletteNum = 15,
.baseBlock = 1
},
2018-09-08 02:24:33 +02:00
// NEW GAME
2018-09-02 18:53:52 +02:00
{
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-08 02:24:33 +02:00
.tilemapLeft = MENU_LEFT,
.tilemapTop = MENU_TOP_WIN3,
.width = MENU_WIDTH,
.height = MENU_HEIGHT_WIN3,
2018-09-02 18:53:52 +02:00
.paletteNum = 15,
.baseBlock = 0x9D
},
2018-09-08 02:24:33 +02:00
// OPTION / MYSTERY GIFT
2018-09-02 18:53:52 +02:00
{
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-08 02:24:33 +02:00
.tilemapLeft = MENU_LEFT,
.tilemapTop = MENU_TOP_WIN4,
.width = MENU_WIDTH,
.height = MENU_HEIGHT_WIN4,
2018-09-02 18:53:52 +02:00
.paletteNum = 15,
.baseBlock = 0xD1
},
2018-09-08 02:24:33 +02:00
// OPTION / MYSTERY EVENTS
2018-09-02 18:53:52 +02:00
{
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-08 02:24:33 +02:00
.tilemapLeft = MENU_LEFT,
.tilemapTop = MENU_TOP_WIN5,
.width = MENU_WIDTH,
.height = MENU_HEIGHT_WIN5,
2018-09-02 18:53:52 +02:00
.paletteNum = 15,
.baseBlock = 0x105
},
2018-09-08 02:24:33 +02:00
// OPTION
2018-09-02 18:53:52 +02:00
{
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-08 02:24:33 +02:00
.tilemapLeft = MENU_LEFT,
.tilemapTop = MENU_TOP_WIN6,
.width = MENU_WIDTH,
.height = MENU_HEIGHT_WIN6,
2018-09-02 18:53:52 +02:00
.paletteNum = 15,
.baseBlock = 0x139
2018-09-08 02:24:33 +02:00
},
// Error message window
2018-09-02 18:53:52 +02:00
{
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-08 02:24:33 +02:00
.tilemapLeft = MENU_LEFT_ERROR,
.tilemapTop = MENU_TOP_ERROR,
.width = MENU_WIDTH_ERROR,
.height = MENU_HEIGHT_ERROR,
2018-09-02 18:53:52 +02:00
.paletteNum = 15,
.baseBlock = 0x16D
},
DUMMY_WIN_TEMPLATE
2018-02-14 04:12:02 +01:00
};
2022-05-17 19:51:54 +02:00
static const struct WindowTemplate sNewGameBirchSpeechTextWindows[] =
2018-09-02 18:53:52 +02:00
{
{
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-02 18:53:52 +02:00
.tilemapLeft = 2,
.tilemapTop = 15,
.width = 27,
.height = 4,
.paletteNum = 15,
.baseBlock = 1
},
{
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-02 18:53:52 +02:00
.tilemapLeft = 3,
.tilemapTop = 5,
.width = 6,
.height = 4,
.paletteNum = 15,
.baseBlock = 0x6D
},
{
2018-10-27 00:53:07 +02:00
.bg = 0,
2018-09-02 18:53:52 +02:00
.tilemapLeft = 3,
.tilemapTop = 2,
.width = 9,
.height = 10,
.paletteNum = 15,
.baseBlock = 0x85
},
DUMMY_WIN_TEMPLATE
2018-02-14 04:12:02 +01:00
};
2022-01-14 18:29:30 +01:00
static const u16 sMainMenuBgPal[] = INCBIN_U16("graphics/interface/main_menu_bg.gbapal");
static const u16 sMainMenuTextPal[] = INCBIN_U16("graphics/interface/main_menu_text.gbapal");
2018-02-14 04:12:02 +01:00
2019-12-10 19:48:20 +01:00
static const u8 sTextColor_Headers[] = {TEXT_DYNAMIC_COLOR_1, TEXT_DYNAMIC_COLOR_2, TEXT_DYNAMIC_COLOR_3};
static const u8 sTextColor_MenuInfo[] = {TEXT_DYNAMIC_COLOR_1, TEXT_COLOR_WHITE, TEXT_DYNAMIC_COLOR_3};
2018-02-14 04:12:02 +01:00
2018-09-14 19:15:46 +02:00
static const struct BgTemplate sMainMenuBgTemplates[] = {
2018-02-15 02:45:27 +01:00
{
.bg = 0,
.charBaseIndex = 2,
.mapBaseIndex = 30,
.screenSize = 0,
.paletteMode = 0,
.priority = 0,
.baseTile = 0
},
{
.bg = 1,
.charBaseIndex = 0,
.mapBaseIndex = 7,
.screenSize = 0,
.paletteMode = 0,
.priority = 3,
.baseTile = 0
}
2018-02-14 04:12:02 +01:00
};
2018-09-14 19:15:46 +02:00
static const struct BgTemplate sBirchBgTemplate = {
2018-02-15 02:45:27 +01:00
.bg = 0,
.charBaseIndex = 3,
.mapBaseIndex = 30,
.screenSize = 0,
.paletteMode = 0,
.priority = 0,
.baseTile = 0
};
2018-02-14 04:12:02 +01:00
2018-09-14 19:15:46 +02:00
static const struct ScrollArrowsTemplate sScrollArrowsTemplate_MainMenu = {2, 0x78, 8, 3, 0x78, 0x98, 3, 4, 1, 1, 0};
2018-02-14 04:12:02 +01:00
2018-09-14 19:15:46 +02:00
static const union AffineAnimCmd sSpriteAffineAnim_PlayerShrink[] = {
2018-02-14 04:12:02 +01:00
AFFINEANIMCMD_FRAME(-2, -2, 0, 0x30),
AFFINEANIMCMD_END
};
2018-10-27 00:53:07 +02:00
static const union AffineAnimCmd *const sSpriteAffineAnimTable_PlayerShrink[] =
2018-09-14 19:15:46 +02:00
{
sSpriteAffineAnim_PlayerShrink
};
2018-02-14 04:12:02 +01:00
2018-09-14 19:15:46 +02:00
static const struct MenuAction sMenuActions_Gender[] = {
2018-02-14 04:12:02 +01:00
{gText_BirchBoy, NULL},
{gText_BirchGirl, NULL}
};
2022-05-17 19:51:54 +02:00
static const u8 *const sMalePresetNames[] = {
2018-02-14 04:12:02 +01:00
gText_DefaultNameStu,
gText_DefaultNameMilton,
gText_DefaultNameTom,
gText_DefaultNameKenny,
gText_DefaultNameReid,
gText_DefaultNameJude,
gText_DefaultNameJaxson,
gText_DefaultNameEaston,
gText_DefaultNameWalker,
gText_DefaultNameTeru,
gText_DefaultNameJohnny,
gText_DefaultNameBrett,
gText_DefaultNameSeth,
gText_DefaultNameTerry,
gText_DefaultNameCasey,
gText_DefaultNameDarren,
gText_DefaultNameLandon,
gText_DefaultNameCollin,
gText_DefaultNameStanley,
gText_DefaultNameQuincy
2018-02-14 04:12:02 +01:00
};
2022-05-17 19:51:54 +02:00
static const u8 *const sFemalePresetNames[] = {
2018-02-14 04:12:02 +01:00
gText_DefaultNameKimmy,
gText_DefaultNameTiara,
gText_DefaultNameBella,
gText_DefaultNameJayla,
gText_DefaultNameAllie,
gText_DefaultNameLianna,
gText_DefaultNameSara,
gText_DefaultNameMonica,
gText_DefaultNameCamila,
gText_DefaultNameAubree,
gText_DefaultNameRuthie,
gText_DefaultNameHazel,
gText_DefaultNameNadine,
gText_DefaultNameTanja,
gText_DefaultNameYasmin,
gText_DefaultNameNicola,
gText_DefaultNameLillie,
gText_DefaultNameTerra,
gText_DefaultNameLucy,
gText_DefaultNameHalie
};
2017-09-30 16:01:52 +02:00
// .text
2018-02-14 04:12:02 +01:00
enum
{
HAS_NO_SAVED_GAME, //NEW GAME, OPTION
HAS_SAVED_GAME, //CONTINUE, NEW GAME, OPTION
2018-09-08 02:24:33 +02:00
HAS_MYSTERY_GIFT, //CONTINUE, NEW GAME, MYSTERY GIFT, OPTION
HAS_MYSTERY_EVENTS, //CONTINUE, NEW GAME, MYSTERY GIFT, MYSTERY EVENTS, OPTION
2018-02-14 04:12:02 +01:00
};
2018-09-14 19:15:46 +02:00
enum
{
2018-07-15 13:23:38 +02:00
ACTION_NEW_GAME,
ACTION_CONTINUE,
2018-09-08 02:24:33 +02:00
ACTION_OPTION,
2018-07-15 13:23:38 +02:00
ACTION_MYSTERY_GIFT,
ACTION_MYSTERY_EVENTS,
ACTION_EREADER,
2018-07-15 13:23:38 +02:00
ACTION_INVALID
};
2018-02-15 02:45:27 +01:00
#define MAIN_MENU_BORDER_TILE 0x1D5
2018-09-14 19:15:46 +02:00
static void CB2_MainMenu(void)
{
RunTasks();
AnimateSprites();
BuildOamBuffer();
UpdatePaletteFade();
}
2018-09-14 19:15:46 +02:00
static void VBlankCB_MainMenu(void)
{
LoadOam();
ProcessSpriteCopyRequests();
TransferPlttBuffer();
}
void CB2_InitMainMenu(void)
{
InitMainMenu(FALSE);
}
void CB2_ReinitMainMenu(void)
{
InitMainMenu(TRUE);
}
2018-09-14 19:15:46 +02:00
static u32 InitMainMenu(bool8 returningFromOptionsMenu)
{
SetVBlankCallback(NULL);
2018-02-15 12:41:32 +01:00
SetGpuReg(REG_OFFSET_DISPCNT, 0);
SetGpuReg(REG_OFFSET_BG2CNT, 0);
SetGpuReg(REG_OFFSET_BG1CNT, 0);
SetGpuReg(REG_OFFSET_BG0CNT, 0);
SetGpuReg(REG_OFFSET_BG2HOFS, 0);
SetGpuReg(REG_OFFSET_BG2VOFS, 0);
SetGpuReg(REG_OFFSET_BG1HOFS, 0);
SetGpuReg(REG_OFFSET_BG1VOFS, 0);
SetGpuReg(REG_OFFSET_BG0HOFS, 0);
SetGpuReg(REG_OFFSET_BG0VOFS, 0);
2018-02-15 12:41:32 +01:00
DmaFill16(3, 0, (void *)VRAM, VRAM_SIZE);
DmaFill32(3, 0, (void *)OAM, OAM_SIZE);
DmaFill16(3, 0, (void *)(PLTT + 2), PLTT_SIZE - 2);
2018-02-15 12:41:32 +01:00
ResetPaletteFade();
2018-09-14 19:15:46 +02:00
LoadPalette(sMainMenuBgPal, 0, 32);
LoadPalette(sMainMenuTextPal, 0xF0, 32);
ScanlineEffect_Stop();
ResetTasks();
ResetSpriteData();
FreeAllSpritePalettes();
2018-02-15 02:45:27 +01:00
if (returningFromOptionsMenu)
2021-02-24 17:01:02 +01:00
BeginNormalPaletteFade(PALETTES_ALL, 0, 0x10, 0, RGB_BLACK); // fade to black
else
2021-02-24 17:01:02 +01:00
BeginNormalPaletteFade(PALETTES_ALL, 0, 0x10, 0, RGB_WHITEALPHA); // fade to white
ResetBgsAndClearDma3BusyFlags(0);
2018-09-14 19:15:46 +02:00
InitBgsFromTemplates(0, sMainMenuBgTemplates, ARRAY_COUNT(sMainMenuBgTemplates));
2021-11-04 04:02:06 +01:00
ChangeBgX(0, 0, BG_COORD_SET);
ChangeBgY(0, 0, BG_COORD_SET);
ChangeBgX(1, 0, BG_COORD_SET);
ChangeBgY(1, 0, BG_COORD_SET);
2018-09-08 02:24:33 +02:00
InitWindows(sWindowTemplates_MainMenu);
DeactivateAllTextPrinters();
2018-02-15 02:45:27 +01:00
LoadMainMenuWindowFrameTiles(0, MAIN_MENU_BORDER_TILE);
2018-02-15 12:41:32 +01:00
SetGpuReg(REG_OFFSET_WIN0H, 0);
SetGpuReg(REG_OFFSET_WIN0V, 0);
SetGpuReg(REG_OFFSET_WININ, 0);
SetGpuReg(REG_OFFSET_WINOUT, 0);
SetGpuReg(REG_OFFSET_BLDCNT, 0);
SetGpuReg(REG_OFFSET_BLDALPHA, 0);
SetGpuReg(REG_OFFSET_BLDY, 0);
2018-02-15 12:41:32 +01:00
EnableInterrupts(1);
SetVBlankCallback(VBlankCB_MainMenu);
SetMainCallback2(CB2_MainMenu);
2018-02-14 04:12:02 +01:00
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON | DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP);
ShowBg(0);
HideBg(1);
CreateTask(Task_MainMenuCheckSaveFile, 0);
2018-02-15 12:41:32 +01:00
return 0;
}
2018-07-15 13:23:38 +02:00
#define tMenuType data[0]
#define tCurrItem data[1]
#define tItemCount data[12]
#define tScrollArrowTaskId data[13]
#define tIsScrolled data[14]
#define tWirelessAdapterConnected data[15]
#define tArrowTaskIsScrolled data[15] // For scroll indicator arrow task
2018-09-14 19:15:46 +02:00
static void Task_MainMenuCheckSaveFile(u8 taskId)
{
s16 *data = gTasks[taskId].data;
2018-02-15 12:41:32 +01:00
if (!gPaletteFade.active)
{
SetGpuReg(REG_OFFSET_WIN0H, 0);
SetGpuReg(REG_OFFSET_WIN0V, 0);
2018-07-15 13:23:38 +02:00
SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG0 | WININ_WIN0_OBJ);
SetGpuReg(REG_OFFSET_WINOUT, WINOUT_WIN01_BG0 | WINOUT_WIN01_OBJ | WINOUT_WIN01_CLR);
2018-02-14 04:12:02 +01:00
SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_EFFECT_DARKEN | BLDCNT_TGT1_BG0);
SetGpuReg(REG_OFFSET_BLDALPHA, 0);
SetGpuReg(REG_OFFSET_BLDY, 7);
2018-02-15 12:41:32 +01:00
2018-07-15 13:23:38 +02:00
if (IsWirelessAdapterConnected())
tWirelessAdapterConnected = TRUE;
switch (gSaveFileStatus)
{
2020-01-12 21:27:37 +01:00
case SAVE_STATUS_OK:
2018-07-15 13:23:38 +02:00
tMenuType = HAS_SAVED_GAME;
if (IsMysteryGiftEnabled())
2018-07-15 13:23:38 +02:00
tMenuType++;
gTasks[taskId].func = Task_MainMenuCheckBattery;
break;
2020-01-12 23:50:27 +01:00
case SAVE_STATUS_CORRUPT:
CreateMainMenuErrorWindow(gText_SaveFileErased);
2018-07-15 13:23:38 +02:00
tMenuType = HAS_NO_SAVED_GAME;
gTasks[taskId].func = Task_WaitForSaveFileErrorWindow;
break;
2020-01-12 21:27:37 +01:00
case SAVE_STATUS_ERROR:
CreateMainMenuErrorWindow(gText_SaveFileCorrupted);
gTasks[taskId].func = Task_WaitForSaveFileErrorWindow;
2018-07-15 13:23:38 +02:00
tMenuType = HAS_SAVED_GAME;
if (IsMysteryGiftEnabled() == TRUE)
2018-07-15 13:23:38 +02:00
tMenuType++;
break;
2020-01-12 21:27:37 +01:00
case SAVE_STATUS_EMPTY:
default:
2018-07-15 13:23:38 +02:00
tMenuType = HAS_NO_SAVED_GAME;
gTasks[taskId].func = Task_MainMenuCheckBattery;
break;
2020-01-12 21:27:37 +01:00
case SAVE_STATUS_NO_FLASH:
CreateMainMenuErrorWindow(gJPText_No1MSubCircuit);
2018-07-15 13:23:38 +02:00
gTasks[taskId].tMenuType = HAS_NO_SAVED_GAME;
gTasks[taskId].func = Task_WaitForSaveFileErrorWindow;
break;
}
if (sCurrItemAndOptionMenuCheck & OPTION_MENU_FLAG) // are we returning from the options menu?
{
2018-07-15 13:23:38 +02:00
switch (tMenuType) // if so, highlight the OPTIONS item
{
case HAS_NO_SAVED_GAME:
case HAS_SAVED_GAME:
2018-07-15 13:23:38 +02:00
sCurrItemAndOptionMenuCheck = tMenuType + 1;
break;
case HAS_MYSTERY_GIFT:
2018-07-15 13:23:38 +02:00
sCurrItemAndOptionMenuCheck = 3;
break;
2018-07-15 13:23:38 +02:00
case HAS_MYSTERY_EVENTS:
sCurrItemAndOptionMenuCheck = 4;
break;
}
}
2021-10-03 05:47:59 +02:00
sCurrItemAndOptionMenuCheck &= ~OPTION_MENU_FLAG; // turn off the "returning from options menu" flag
2018-07-15 13:23:38 +02:00
tCurrItem = sCurrItemAndOptionMenuCheck;
tItemCount = tMenuType + 2;
}
}
2018-09-14 19:15:46 +02:00
static void Task_WaitForSaveFileErrorWindow(u8 taskId)
{
RunTextPrinters();
2020-09-05 03:11:55 +02:00
if (!IsTextPrinterActive(7) && (JOY_NEW(A_BUTTON)))
{
ClearWindowTilemap(7);
2018-09-08 02:24:33 +02:00
ClearMainMenuWindowTilemap(&sWindowTemplates_MainMenu[7]);
gTasks[taskId].func = Task_MainMenuCheckBattery;
}
}
2018-09-14 19:15:46 +02:00
static void Task_MainMenuCheckBattery(u8 taskId)
{
if (!gPaletteFade.active)
{
SetGpuReg(REG_OFFSET_WIN0H, 0);
SetGpuReg(REG_OFFSET_WIN0V, 0);
2018-07-15 13:23:38 +02:00
SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG0 | WININ_WIN0_OBJ);
SetGpuReg(REG_OFFSET_WINOUT, WINOUT_WIN01_BG0 | WINOUT_WIN01_OBJ | WINOUT_WIN01_CLR);
2018-02-14 04:12:02 +01:00
SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_EFFECT_DARKEN | BLDCNT_TGT1_BG0);
SetGpuReg(REG_OFFSET_BLDALPHA, 0);
SetGpuReg(REG_OFFSET_BLDY, 7);
2018-02-15 12:41:32 +01:00
if (!(RtcGetErrorStatus() & RTC_ERR_FLAG_MASK))
2018-02-11 23:19:36 +01:00
{
gTasks[taskId].func = Task_DisplayMainMenu;
2018-02-11 23:19:36 +01:00
}
else
{
CreateMainMenuErrorWindow(gText_BatteryRunDry);
gTasks[taskId].func = Task_WaitForBatteryDryErrorWindow;
}
}
}
2018-09-14 19:15:46 +02:00
static void Task_WaitForBatteryDryErrorWindow(u8 taskId)
{
RunTextPrinters();
2020-09-05 03:11:55 +02:00
if (!IsTextPrinterActive(7) && (JOY_NEW(A_BUTTON)))
{
ClearWindowTilemap(7);
2018-09-08 02:24:33 +02:00
ClearMainMenuWindowTilemap(&sWindowTemplates_MainMenu[7]);
gTasks[taskId].func = Task_DisplayMainMenu;
}
}
2018-09-14 19:15:46 +02:00
static void Task_DisplayMainMenu(u8 taskId)
{
s16 *data = gTasks[taskId].data;
u16 palette;
2018-02-15 12:41:32 +01:00
if (!gPaletteFade.active)
{
SetGpuReg(REG_OFFSET_WIN0H, 0);
SetGpuReg(REG_OFFSET_WIN0V, 0);
2018-07-15 13:23:38 +02:00
SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG0 | WININ_WIN0_OBJ);
SetGpuReg(REG_OFFSET_WINOUT, WINOUT_WIN01_BG0 | WINOUT_WIN01_OBJ | WINOUT_WIN01_CLR);
2018-02-14 04:12:02 +01:00
SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_EFFECT_DARKEN | BLDCNT_TGT1_BG0);
SetGpuReg(REG_OFFSET_BLDALPHA, 0);
SetGpuReg(REG_OFFSET_BLDY, 7);
2018-02-15 12:41:32 +01:00
palette = RGB_BLACK;
LoadPalette(&palette, 254, 2);
2018-02-15 12:41:32 +01:00
palette = RGB_WHITE;
LoadPalette(&palette, 250, 2);
2018-02-15 12:41:32 +01:00
palette = RGB(12, 12, 12);
LoadPalette(&palette, 251, 2);
2018-02-15 12:41:32 +01:00
palette = RGB(26, 26, 25);
LoadPalette(&palette, 252, 2);
2018-02-15 12:41:32 +01:00
// Note: If there is no save file, the save block is zeroed out,
// so the default gender is MALE.
if (gSaveBlock2Ptr->playerGender == MALE)
{
palette = RGB(4, 16, 31);
LoadPalette(&palette, 241, 2);
}
else
{
palette = RGB(31, 3, 21);
LoadPalette(&palette, 241, 2);
}
2018-02-15 12:41:32 +01:00
2018-07-15 13:23:38 +02:00
switch (gTasks[taskId].tMenuType)
{
case HAS_NO_SAVED_GAME:
default:
FillWindowPixelBuffer(0, PIXEL_FILL(0xA));
FillWindowPixelBuffer(1, PIXEL_FILL(0xA));
AddTextPrinterParameterized3(0, FONT_NORMAL, 0, 1, sTextColor_Headers, TEXT_SKIP_DRAW, gText_MainMenuNewGame);
AddTextPrinterParameterized3(1, FONT_NORMAL, 0, 1, sTextColor_Headers, TEXT_SKIP_DRAW, gText_MainMenuOption);
PutWindowTilemap(0);
PutWindowTilemap(1);
2021-11-03 20:29:18 +01:00
CopyWindowToVram(0, COPYWIN_GFX);
CopyWindowToVram(1, COPYWIN_GFX);
2018-09-08 02:24:33 +02:00
DrawMainMenuWindowBorder(&sWindowTemplates_MainMenu[0], MAIN_MENU_BORDER_TILE);
DrawMainMenuWindowBorder(&sWindowTemplates_MainMenu[1], MAIN_MENU_BORDER_TILE);
break;
case HAS_SAVED_GAME:
FillWindowPixelBuffer(2, PIXEL_FILL(0xA));
FillWindowPixelBuffer(3, PIXEL_FILL(0xA));
FillWindowPixelBuffer(4, PIXEL_FILL(0xA));
AddTextPrinterParameterized3(2, FONT_NORMAL, 0, 1, sTextColor_Headers, TEXT_SKIP_DRAW, gText_MainMenuContinue);
AddTextPrinterParameterized3(3, FONT_NORMAL, 0, 1, sTextColor_Headers, TEXT_SKIP_DRAW, gText_MainMenuNewGame);
AddTextPrinterParameterized3(4, FONT_NORMAL, 0, 1, sTextColor_Headers, TEXT_SKIP_DRAW, gText_MainMenuOption);
2018-09-14 19:15:46 +02:00
MainMenu_FormatSavegameText();
PutWindowTilemap(2);
PutWindowTilemap(3);
PutWindowTilemap(4);
2021-11-03 20:29:18 +01:00
CopyWindowToVram(2, COPYWIN_GFX);
CopyWindowToVram(3, COPYWIN_GFX);
CopyWindowToVram(4, COPYWIN_GFX);
2018-09-08 02:24:33 +02:00
DrawMainMenuWindowBorder(&sWindowTemplates_MainMenu[2], MAIN_MENU_BORDER_TILE);
DrawMainMenuWindowBorder(&sWindowTemplates_MainMenu[3], MAIN_MENU_BORDER_TILE);
DrawMainMenuWindowBorder(&sWindowTemplates_MainMenu[4], MAIN_MENU_BORDER_TILE);
break;
case HAS_MYSTERY_GIFT:
FillWindowPixelBuffer(2, PIXEL_FILL(0xA));
FillWindowPixelBuffer(3, PIXEL_FILL(0xA));
FillWindowPixelBuffer(4, PIXEL_FILL(0xA));
FillWindowPixelBuffer(5, PIXEL_FILL(0xA));
AddTextPrinterParameterized3(2, FONT_NORMAL, 0, 1, sTextColor_Headers, TEXT_SKIP_DRAW, gText_MainMenuContinue);
AddTextPrinterParameterized3(3, FONT_NORMAL, 0, 1, sTextColor_Headers, TEXT_SKIP_DRAW, gText_MainMenuNewGame);
AddTextPrinterParameterized3(4, FONT_NORMAL, 0, 1, sTextColor_Headers, TEXT_SKIP_DRAW, gText_MainMenuMysteryGift);
AddTextPrinterParameterized3(5, FONT_NORMAL, 0, 1, sTextColor_Headers, TEXT_SKIP_DRAW, gText_MainMenuOption);
2018-09-14 19:15:46 +02:00
MainMenu_FormatSavegameText();
PutWindowTilemap(2);
PutWindowTilemap(3);
PutWindowTilemap(4);
PutWindowTilemap(5);
2021-11-03 20:29:18 +01:00
CopyWindowToVram(2, COPYWIN_GFX);
CopyWindowToVram(3, COPYWIN_GFX);
CopyWindowToVram(4, COPYWIN_GFX);
CopyWindowToVram(5, COPYWIN_GFX);
2018-09-08 02:24:33 +02:00
DrawMainMenuWindowBorder(&sWindowTemplates_MainMenu[2], MAIN_MENU_BORDER_TILE);
DrawMainMenuWindowBorder(&sWindowTemplates_MainMenu[3], MAIN_MENU_BORDER_TILE);
DrawMainMenuWindowBorder(&sWindowTemplates_MainMenu[4], MAIN_MENU_BORDER_TILE);
DrawMainMenuWindowBorder(&sWindowTemplates_MainMenu[5], MAIN_MENU_BORDER_TILE);
break;
case HAS_MYSTERY_EVENTS:
FillWindowPixelBuffer(2, PIXEL_FILL(0xA));
FillWindowPixelBuffer(3, PIXEL_FILL(0xA));
FillWindowPixelBuffer(4, PIXEL_FILL(0xA));
FillWindowPixelBuffer(5, PIXEL_FILL(0xA));
FillWindowPixelBuffer(6, PIXEL_FILL(0xA));
AddTextPrinterParameterized3(2, FONT_NORMAL, 0, 1, sTextColor_Headers, TEXT_SKIP_DRAW, gText_MainMenuContinue);
AddTextPrinterParameterized3(3, FONT_NORMAL, 0, 1, sTextColor_Headers, TEXT_SKIP_DRAW, gText_MainMenuNewGame);
AddTextPrinterParameterized3(4, FONT_NORMAL, 0, 1, sTextColor_Headers, TEXT_SKIP_DRAW, gText_MainMenuMysteryGift2);
AddTextPrinterParameterized3(5, FONT_NORMAL, 0, 1, sTextColor_Headers, TEXT_SKIP_DRAW, gText_MainMenuMysteryEvents);
AddTextPrinterParameterized3(6, FONT_NORMAL, 0, 1, sTextColor_Headers, TEXT_SKIP_DRAW, gText_MainMenuOption);
2018-09-14 19:15:46 +02:00
MainMenu_FormatSavegameText();
PutWindowTilemap(2);
PutWindowTilemap(3);
PutWindowTilemap(4);
PutWindowTilemap(5);
PutWindowTilemap(6);
2021-11-03 20:29:18 +01:00
CopyWindowToVram(2, COPYWIN_GFX);
CopyWindowToVram(3, COPYWIN_GFX);
CopyWindowToVram(4, COPYWIN_GFX);
CopyWindowToVram(5, COPYWIN_GFX);
CopyWindowToVram(6, COPYWIN_GFX);
2018-09-08 02:24:33 +02:00
DrawMainMenuWindowBorder(&sWindowTemplates_MainMenu[2], MAIN_MENU_BORDER_TILE);
DrawMainMenuWindowBorder(&sWindowTemplates_MainMenu[3], MAIN_MENU_BORDER_TILE);
DrawMainMenuWindowBorder(&sWindowTemplates_MainMenu[4], MAIN_MENU_BORDER_TILE);
DrawMainMenuWindowBorder(&sWindowTemplates_MainMenu[5], MAIN_MENU_BORDER_TILE);
DrawMainMenuWindowBorder(&sWindowTemplates_MainMenu[6], MAIN_MENU_BORDER_TILE);
2018-07-15 13:23:38 +02:00
tScrollArrowTaskId = AddScrollIndicatorArrowPair(&sScrollArrowsTemplate_MainMenu, &sCurrItemAndOptionMenuCheck);
gTasks[tScrollArrowTaskId].func = Task_ScrollIndicatorArrowPairOnMainMenu;
if (sCurrItemAndOptionMenuCheck == 4)
{
2021-11-04 04:02:06 +01:00
ChangeBgY(0, 0x2000, BG_COORD_ADD);
ChangeBgY(1, 0x2000, BG_COORD_ADD);
2018-07-15 13:23:38 +02:00
tIsScrolled = TRUE;
gTasks[tScrollArrowTaskId].tArrowTaskIsScrolled = TRUE;
}
break;
}
gTasks[taskId].func = Task_HighlightSelectedMainMenuItem;
}
}
2018-09-14 19:15:46 +02:00
static void Task_HighlightSelectedMainMenuItem(u8 taskId)
{
2018-07-15 13:23:38 +02:00
HighlightSelectedMainMenuItem(gTasks[taskId].tMenuType, gTasks[taskId].tCurrItem, gTasks[taskId].tIsScrolled);
gTasks[taskId].func = Task_HandleMainMenuInput;
}
2018-09-14 19:15:46 +02:00
static bool8 HandleMainMenuInput(u8 taskId)
{
s16 *data = gTasks[taskId].data;
2018-02-15 12:41:32 +01:00
2020-09-05 03:11:55 +02:00
if (JOY_NEW(A_BUTTON))
{
PlaySE(SE_SELECT);
2018-07-15 13:23:38 +02:00
IsWirelessAdapterConnected(); // why bother calling this here? debug? Task_HandleMainMenuAPressed will check too
2021-02-24 17:01:02 +01:00
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_BLACK);
gTasks[taskId].func = Task_HandleMainMenuAPressed;
}
2020-09-05 03:11:55 +02:00
else if (JOY_NEW(B_BUTTON))
{
PlaySE(SE_SELECT);
2021-02-24 17:01:02 +01:00
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_WHITEALPHA);
2021-04-15 08:04:01 +02:00
SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE(0, DISPLAY_WIDTH));
SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(0, DISPLAY_HEIGHT));
gTasks[taskId].func = Task_HandleMainMenuBPressed;
}
2020-09-05 03:11:55 +02:00
else if ((JOY_NEW(DPAD_UP)) && tCurrItem > 0)
{
2018-07-15 13:23:38 +02:00
if (tMenuType == HAS_MYSTERY_EVENTS && tIsScrolled == TRUE && tCurrItem == 1)
{
2021-11-04 04:02:06 +01:00
ChangeBgY(0, 0x2000, BG_COORD_SUB);
ChangeBgY(1, 0x2000, BG_COORD_SUB);
2018-07-15 13:23:38 +02:00
gTasks[tScrollArrowTaskId].tArrowTaskIsScrolled = tIsScrolled = FALSE;
}
2018-07-15 13:23:38 +02:00
tCurrItem--;
sCurrItemAndOptionMenuCheck = tCurrItem;
return TRUE;
}
2020-09-05 03:11:55 +02:00
else if ((JOY_NEW(DPAD_DOWN)) && tCurrItem < tItemCount - 1)
{
2018-07-15 13:23:38 +02:00
if (tMenuType == HAS_MYSTERY_EVENTS && tCurrItem == 3 && tIsScrolled == FALSE)
{
2021-11-04 04:02:06 +01:00
ChangeBgY(0, 0x2000, BG_COORD_ADD);
ChangeBgY(1, 0x2000, BG_COORD_ADD);
2018-07-15 13:23:38 +02:00
gTasks[tScrollArrowTaskId].tArrowTaskIsScrolled = tIsScrolled = TRUE;
}
2018-07-15 13:23:38 +02:00
tCurrItem++;
sCurrItemAndOptionMenuCheck = tCurrItem;
return TRUE;
}
return FALSE;
}
2018-09-14 19:15:46 +02:00
static void Task_HandleMainMenuInput(u8 taskId)
{
if (HandleMainMenuInput(taskId))
gTasks[taskId].func = Task_HighlightSelectedMainMenuItem;
}
2018-09-14 19:15:46 +02:00
static void Task_HandleMainMenuAPressed(u8 taskId)
{
2018-07-15 13:23:38 +02:00
bool8 wirelessAdapterConnected;
u8 action;
2018-02-15 12:41:32 +01:00
if (!gPaletteFade.active)
{
2018-07-15 13:23:38 +02:00
if (gTasks[taskId].tMenuType == HAS_MYSTERY_EVENTS)
RemoveScrollIndicatorArrowPair(gTasks[taskId].tScrollArrowTaskId);
ClearStdWindowAndFrame(0, TRUE);
ClearStdWindowAndFrame(1, TRUE);
ClearStdWindowAndFrame(2, TRUE);
ClearStdWindowAndFrame(3, TRUE);
ClearStdWindowAndFrame(4, TRUE);
ClearStdWindowAndFrame(5, TRUE);
ClearStdWindowAndFrame(6, TRUE);
ClearStdWindowAndFrame(7, TRUE);
2018-07-15 13:23:38 +02:00
wirelessAdapterConnected = IsWirelessAdapterConnected();
switch (gTasks[taskId].tMenuType)
{
case HAS_NO_SAVED_GAME:
default:
2018-07-15 13:23:38 +02:00
switch (gTasks[taskId].tCurrItem)
{
case 0:
default:
2018-07-15 13:23:38 +02:00
action = ACTION_NEW_GAME;
break;
case 1:
2018-09-08 02:24:33 +02:00
action = ACTION_OPTION;
break;
}
break;
case HAS_SAVED_GAME:
2018-07-15 13:23:38 +02:00
switch (gTasks[taskId].tCurrItem)
{
case 0:
default:
2018-07-15 13:23:38 +02:00
action = ACTION_CONTINUE;
break;
case 1:
2018-07-15 13:23:38 +02:00
action = ACTION_NEW_GAME;
break;
case 2:
2018-09-08 02:24:33 +02:00
action = ACTION_OPTION;
break;
}
break;
case HAS_MYSTERY_GIFT:
2018-07-15 13:23:38 +02:00
switch (gTasks[taskId].tCurrItem)
{
case 0:
default:
2018-07-15 13:23:38 +02:00
action = ACTION_CONTINUE;
break;
case 1:
2018-07-15 13:23:38 +02:00
action = ACTION_NEW_GAME;
break;
case 2:
2018-07-15 13:23:38 +02:00
action = ACTION_MYSTERY_GIFT;
if (!wirelessAdapterConnected)
{
2018-07-15 13:23:38 +02:00
action = ACTION_INVALID;
2018-09-08 02:24:33 +02:00
gTasks[taskId].tMenuType = HAS_NO_SAVED_GAME;
}
break;
case 3:
2018-09-08 02:24:33 +02:00
action = ACTION_OPTION;
break;
}
break;
case HAS_MYSTERY_EVENTS:
2018-07-15 13:23:38 +02:00
switch (gTasks[taskId].tCurrItem)
{
case 0:
default:
2018-07-15 13:23:38 +02:00
action = ACTION_CONTINUE;
break;
case 1:
2018-07-15 13:23:38 +02:00
action = ACTION_NEW_GAME;
break;
case 2:
2018-07-15 13:23:38 +02:00
if (gTasks[taskId].tWirelessAdapterConnected)
{
2018-07-15 13:23:38 +02:00
action = ACTION_MYSTERY_GIFT;
if (!wirelessAdapterConnected)
{
2018-07-15 13:23:38 +02:00
action = ACTION_INVALID;
2018-09-08 02:24:33 +02:00
gTasks[taskId].tMenuType = HAS_NO_SAVED_GAME;
}
}
2018-07-15 13:23:38 +02:00
else if (wirelessAdapterConnected)
{
2018-07-15 13:23:38 +02:00
action = ACTION_INVALID;
2018-09-08 02:24:33 +02:00
gTasks[taskId].tMenuType = HAS_SAVED_GAME;
}
else
2018-02-11 23:19:36 +01:00
{
action = ACTION_EREADER;
2018-02-11 23:19:36 +01:00
}
break;
case 3:
2018-07-15 13:23:38 +02:00
if (wirelessAdapterConnected)
{
2018-07-15 13:23:38 +02:00
action = ACTION_INVALID;
2018-09-08 02:24:33 +02:00
gTasks[taskId].tMenuType = HAS_MYSTERY_GIFT;
}
else
2018-02-11 23:19:36 +01:00
{
2018-07-15 13:23:38 +02:00
action = ACTION_MYSTERY_EVENTS;
2018-02-11 23:19:36 +01:00
}
break;
case 4:
2018-09-08 02:24:33 +02:00
action = ACTION_OPTION;
break;
}
break;
}
2021-11-04 04:02:06 +01:00
ChangeBgY(0, 0, BG_COORD_SET);
ChangeBgY(1, 0, BG_COORD_SET);
switch (action)
{
2018-07-15 13:23:38 +02:00
case ACTION_NEW_GAME:
default:
gPlttBufferUnfaded[0] = RGB_BLACK;
gPlttBufferFaded[0] = RGB_BLACK;
2018-09-14 19:15:46 +02:00
gTasks[taskId].func = Task_NewGameBirchSpeech_Init;
break;
2018-07-15 13:23:38 +02:00
case ACTION_CONTINUE:
gPlttBufferUnfaded[0] = RGB_BLACK;
gPlttBufferFaded[0] = RGB_BLACK;
2018-02-15 12:41:32 +01:00
SetMainCallback2(CB2_ContinueSavedGame);
DestroyTask(taskId);
break;
2018-09-08 02:24:33 +02:00
case ACTION_OPTION:
gMain.savedCallback = CB2_ReinitMainMenu;
SetMainCallback2(CB2_InitOptionMenu);
DestroyTask(taskId);
break;
2018-07-15 13:23:38 +02:00
case ACTION_MYSTERY_GIFT:
2021-10-14 20:10:42 +02:00
SetMainCallback2(CB2_InitMysteryGift);
DestroyTask(taskId);
break;
2018-07-15 13:23:38 +02:00
case ACTION_MYSTERY_EVENTS:
SetMainCallback2(CB2_InitMysteryEventMenu);
DestroyTask(taskId);
break;
case ACTION_EREADER:
2021-10-14 20:10:42 +02:00
SetMainCallback2(CB2_InitEReader);
DestroyTask(taskId);
break;
2018-07-15 13:23:38 +02:00
case ACTION_INVALID:
gTasks[taskId].tCurrItem = 0;
gTasks[taskId].func = Task_DisplayMainMenuInvalidActionError;
gPlttBufferUnfaded[0xF1] = RGB_WHITE;
gPlttBufferFaded[0xF1] = RGB_WHITE;
SetGpuReg(REG_OFFSET_BG2HOFS, 0);
SetGpuReg(REG_OFFSET_BG2VOFS, 0);
SetGpuReg(REG_OFFSET_BG1HOFS, 0);
SetGpuReg(REG_OFFSET_BG1VOFS, 0);
SetGpuReg(REG_OFFSET_BG0HOFS, 0);
SetGpuReg(REG_OFFSET_BG0VOFS, 0);
2021-02-24 17:01:02 +01:00
BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK);
return;
}
FreeAllWindowBuffers();
2018-09-08 02:24:33 +02:00
if (action != ACTION_OPTION)
2018-07-15 13:23:38 +02:00
sCurrItemAndOptionMenuCheck = 0;
else
sCurrItemAndOptionMenuCheck |= OPTION_MENU_FLAG; // entering the options menu
}
}
2018-09-14 19:15:46 +02:00
static void Task_HandleMainMenuBPressed(u8 taskId)
{
if (!gPaletteFade.active)
{
if (gTasks[taskId].tMenuType == HAS_MYSTERY_EVENTS)
2018-07-15 13:23:38 +02:00
RemoveScrollIndicatorArrowPair(gTasks[taskId].tScrollArrowTaskId);
sCurrItemAndOptionMenuCheck = 0;
FreeAllWindowBuffers();
SetMainCallback2(CB2_InitTitleScreen);
DestroyTask(taskId);
}
}
2018-09-14 19:15:46 +02:00
static void Task_DisplayMainMenuInvalidActionError(u8 taskId)
{
2018-07-15 13:23:38 +02:00
switch (gTasks[taskId].tCurrItem)
{
case 0:
2022-09-26 18:22:27 +02:00
FillBgTilemapBufferRect_Palette0(0, 0, 0, 0, DISPLAY_TILE_WIDTH, DISPLAY_TILE_HEIGHT);
2018-07-15 13:23:38 +02:00
switch (gTasks[taskId].tMenuType)
{
case 0:
CreateMainMenuErrorWindow(gText_WirelessNotConnected);
break;
case 1:
CreateMainMenuErrorWindow(gText_MysteryGiftCantUse);
break;
case 2:
CreateMainMenuErrorWindow(gText_MysteryEventsCantUse);
break;
}
2018-07-15 13:23:38 +02:00
gTasks[taskId].tCurrItem++;
break;
case 1:
if (!gPaletteFade.active)
2018-07-15 13:23:38 +02:00
gTasks[taskId].tCurrItem++;
break;
case 2:
RunTextPrinters();
if (!IsTextPrinterActive(7))
2018-07-15 13:23:38 +02:00
gTasks[taskId].tCurrItem++;
break;
case 3:
2020-09-05 03:11:55 +02:00
if (JOY_NEW(A_BUTTON | B_BUTTON))
{
PlaySE(SE_SELECT);
2021-02-24 17:01:02 +01:00
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
gTasks[taskId].func = Task_HandleMainMenuBPressed;
}
}
}
2018-07-15 13:23:38 +02:00
#undef tMenuType
#undef tCurrItem
#undef tItemCount
#undef tScrollArrowTaskId
#undef tIsScrolled
#undef tWirelessAdapterConnected
#undef tArrowTaskIsScrolled
2018-09-14 19:15:46 +02:00
static void HighlightSelectedMainMenuItem(u8 menuType, u8 selectedMenuItem, s16 isScrolled)
{
2018-09-08 02:24:33 +02:00
SetGpuReg(REG_OFFSET_WIN0H, MENU_WIN_HCOORDS);
2018-02-15 12:41:32 +01:00
switch (menuType)
{
case HAS_NO_SAVED_GAME:
default:
switch (selectedMenuItem)
{
case 0:
default:
2018-09-08 02:24:33 +02:00
SetGpuReg(REG_OFFSET_WIN0V, MENU_WIN_VCOORDS(0));
break;
case 1:
2018-09-08 02:24:33 +02:00
SetGpuReg(REG_OFFSET_WIN0V, MENU_WIN_VCOORDS(1));
break;
}
break;
case HAS_SAVED_GAME:
switch (selectedMenuItem)
{
case 0:
default:
2018-09-08 02:24:33 +02:00
SetGpuReg(REG_OFFSET_WIN0V, MENU_WIN_VCOORDS(2));
break;
case 1:
2018-09-08 02:24:33 +02:00
SetGpuReg(REG_OFFSET_WIN0V, MENU_WIN_VCOORDS(3));
break;
case 2:
2018-09-08 02:24:33 +02:00
SetGpuReg(REG_OFFSET_WIN0V, MENU_WIN_VCOORDS(4));
break;
}
break;
case HAS_MYSTERY_GIFT:
switch (selectedMenuItem)
{
case 0:
default:
2018-09-08 02:24:33 +02:00
SetGpuReg(REG_OFFSET_WIN0V, MENU_WIN_VCOORDS(2));
break;
case 1:
2018-09-08 02:24:33 +02:00
SetGpuReg(REG_OFFSET_WIN0V, MENU_WIN_VCOORDS(3));
break;
case 2:
2018-09-08 02:24:33 +02:00
SetGpuReg(REG_OFFSET_WIN0V, MENU_WIN_VCOORDS(4));
break;
case 3:
2018-09-08 02:24:33 +02:00
SetGpuReg(REG_OFFSET_WIN0V, MENU_WIN_VCOORDS(5));
break;
}
break;
case HAS_MYSTERY_EVENTS:
switch (selectedMenuItem)
{
case 0:
default:
2018-09-08 02:24:33 +02:00
SetGpuReg(REG_OFFSET_WIN0V, MENU_WIN_VCOORDS(2));
break;
case 1:
2018-07-15 13:23:38 +02:00
if (isScrolled)
2018-09-08 02:24:33 +02:00
SetGpuReg(REG_OFFSET_WIN0V, MENU_WIN_VCOORDS(3) - MENU_SCROLL_SHIFT);
else
2018-09-08 02:24:33 +02:00
SetGpuReg(REG_OFFSET_WIN0V, MENU_WIN_VCOORDS(3));
break;
case 2:
2018-07-15 13:23:38 +02:00
if (isScrolled)
2018-09-08 02:24:33 +02:00
SetGpuReg(REG_OFFSET_WIN0V, MENU_WIN_VCOORDS(4) - MENU_SCROLL_SHIFT);
else
2018-09-08 02:24:33 +02:00
SetGpuReg(REG_OFFSET_WIN0V, MENU_WIN_VCOORDS(4));
break;
case 3:
2018-07-15 13:23:38 +02:00
if (isScrolled)
2018-09-08 02:24:33 +02:00
SetGpuReg(REG_OFFSET_WIN0V, MENU_WIN_VCOORDS(5) - MENU_SCROLL_SHIFT);
else
2018-09-08 02:24:33 +02:00
SetGpuReg(REG_OFFSET_WIN0V, MENU_WIN_VCOORDS(5));
break;
case 4:
2018-09-08 02:24:33 +02:00
SetGpuReg(REG_OFFSET_WIN0V, MENU_WIN_VCOORDS(6) - MENU_SCROLL_SHIFT);
break;
}
break;
}
}
2018-09-14 19:15:46 +02:00
#define tPlayerSpriteId data[2]
#define tBG1HOFS data[4]
#define tIsDoneFadingSprites data[5]
#define tPlayerGender data[6]
#define tTimer data[7]
#define tBirchSpriteId data[8]
#define tLotadSpriteId data[9]
#define tBrendanSpriteId data[10]
#define tMaySpriteId data[11]
static void Task_NewGameBirchSpeech_Init(u8 taskId)
{
SetGpuReg(REG_OFFSET_DISPCNT, 0);
2018-02-14 04:12:02 +01:00
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP);
2018-09-14 19:15:46 +02:00
InitBgFromTemplate(&sBirchBgTemplate);
SetGpuReg(REG_OFFSET_WIN0H, 0);
SetGpuReg(REG_OFFSET_WIN0V, 0);
SetGpuReg(REG_OFFSET_WININ, 0);
SetGpuReg(REG_OFFSET_WINOUT, 0);
SetGpuReg(REG_OFFSET_BLDCNT, 0);
SetGpuReg(REG_OFFSET_BLDALPHA, 0);
SetGpuReg(REG_OFFSET_BLDY, 0);
2018-02-15 12:41:32 +01:00
2022-07-29 16:52:35 +02:00
LZ77UnCompVram(sBirchSpeechShadowGfx, (void *)VRAM);
LZ77UnCompVram(sBirchSpeechBgMap, (void *)(BG_SCREEN_ADDR(7)));
2018-09-14 19:15:46 +02:00
LoadPalette(sBirchSpeechBgPals, 0, 64);
LoadPalette(sBirchSpeechPlatformBlackPal, 1, 16);
ScanlineEffect_Stop();
ResetSpriteData();
FreeAllSpritePalettes();
2018-08-19 01:06:10 +02:00
ResetAllPicSprites();
AddBirchSpeechObjects(taskId);
2021-02-24 17:01:02 +01:00
BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK);
2018-09-14 19:15:46 +02:00
gTasks[taskId].tBG1HOFS = 0;
gTasks[taskId].func = Task_NewGameBirchSpeech_WaitToShowBirch;
2021-02-20 06:30:37 +01:00
gTasks[taskId].tPlayerSpriteId = SPRITE_NONE;
gTasks[taskId].data[3] = 0xFF;
2018-09-14 19:15:46 +02:00
gTasks[taskId].tTimer = 0xD8;
2020-08-21 00:02:00 +02:00
PlayBGM(MUS_ROUTE122);
ShowBg(0);
ShowBg(1);
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_WaitToShowBirch(u8 taskId)
{
u8 spriteId;
2018-02-15 12:41:32 +01:00
2018-09-14 19:15:46 +02:00
if (gTasks[taskId].tTimer)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
gTasks[taskId].tTimer--;
2018-02-11 23:19:36 +01:00
}
else
{
2018-09-14 19:15:46 +02:00
spriteId = gTasks[taskId].tBirchSpriteId;
2021-07-07 15:11:52 +02:00
gSprites[spriteId].x = 136;
gSprites[spriteId].y = 60;
gSprites[spriteId].invisible = FALSE;
gSprites[spriteId].oam.objMode = ST_OAM_OBJ_BLEND;
2018-09-14 19:15:46 +02:00
NewGameBirchSpeech_StartFadeInTarget1OutTarget2(taskId, 10);
NewGameBirchSpeech_StartFadePlatformOut(taskId, 20);
gTasks[taskId].tTimer = 80;
gTasks[taskId].func = Task_NewGameBirchSpeech_WaitForSpriteFadeInWelcome;
}
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_WaitForSpriteFadeInWelcome(u8 taskId)
{
2018-09-14 19:15:46 +02:00
if (gTasks[taskId].tIsDoneFadingSprites)
{
gSprites[gTasks[taskId].tBirchSpriteId].oam.objMode = ST_OAM_OBJ_NORMAL;
2018-09-14 19:15:46 +02:00
if (gTasks[taskId].tTimer)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
gTasks[taskId].tTimer--;
2018-02-11 23:19:36 +01:00
}
else
{
2022-05-17 19:51:54 +02:00
InitWindows(sNewGameBirchSpeechTextWindows);
LoadMainMenuWindowFrameTiles(0, 0xF3);
2018-09-14 19:15:46 +02:00
LoadMessageBoxGfx(0, 0xFC, 0xF0);
NewGameBirchSpeech_ShowDialogueWindow(0, 1);
PutWindowTilemap(0);
2021-11-03 20:29:18 +01:00
CopyWindowToVram(0, COPYWIN_GFX);
2018-09-14 19:15:46 +02:00
NewGameBirchSpeech_ClearWindow(0);
2018-02-11 23:19:36 +01:00
StringExpandPlaceholders(gStringVar4, gText_Birch_Welcome);
2022-07-25 20:59:14 +02:00
AddTextPrinterForMessage(TRUE);
2018-09-14 19:15:46 +02:00
gTasks[taskId].func = Task_NewGameBirchSpeech_ThisIsAPokemon;
}
}
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_ThisIsAPokemon(u8 taskId)
{
2018-09-14 19:15:46 +02:00
if (!gPaletteFade.active && !RunTextPrintersAndIsPrinter0Active())
{
2018-09-14 19:15:46 +02:00
gTasks[taskId].func = Task_NewGameBirchSpeech_MainSpeech;
StringExpandPlaceholders(gStringVar4, gText_ThisIsAPokemon);
2022-07-25 20:59:14 +02:00
AddTextPrinterWithCallbackForMessage(TRUE, NewGameBirchSpeech_WaitForThisIsPokemonText);
2018-09-14 19:15:46 +02:00
sBirchSpeechMainTaskId = taskId;
}
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_MainSpeech(u8 taskId)
{
2018-09-14 19:15:46 +02:00
if (!RunTextPrintersAndIsPrinter0Active())
{
2018-02-11 23:19:36 +01:00
StringExpandPlaceholders(gStringVar4, gText_Birch_MainSpeech);
2022-07-25 20:59:14 +02:00
AddTextPrinterForMessage(TRUE);
2018-09-14 19:15:46 +02:00
gTasks[taskId].func = Task_NewGameBirchSpeech_AndYouAre;
}
}
2018-09-14 19:15:46 +02:00
#define tState data[0]
static void Task_NewGameBirchSpeechSub_InitPokeBall(u8 taskId)
{
2018-09-14 19:15:46 +02:00
u8 spriteId = gTasks[sBirchSpeechMainTaskId].tLotadSpriteId;
2018-02-15 12:41:32 +01:00
2021-07-07 15:11:52 +02:00
gSprites[spriteId].x = 100;
gSprites[spriteId].y = 75;
gSprites[spriteId].invisible = FALSE;
gSprites[spriteId].data[0] = 0;
2018-02-15 12:41:32 +01:00
2022-06-01 18:41:57 +02:00
CreatePokeballSpriteToReleaseMon(spriteId, gSprites[spriteId].oam.paletteNum, 112, 58, 0, 0, 32, PALETTES_BG, SPECIES_LOTAD);
2018-09-14 19:15:46 +02:00
gTasks[taskId].func = Task_NewGameBirchSpeechSub_WaitForLotad;
gTasks[sBirchSpeechMainTaskId].tTimer = 0;
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeechSub_WaitForLotad(u8 taskId)
{
s16 *data = gTasks[taskId].data;
2018-09-14 19:15:46 +02:00
struct Sprite *sprite = &gSprites[gTasks[sBirchSpeechMainTaskId].tLotadSpriteId];
2018-09-14 19:15:46 +02:00
switch (tState)
{
case 0:
2021-05-09 07:38:57 +02:00
if (sprite->callback != SpriteCallbackDummy)
return;
sprite->oam.affineMode = ST_OAM_AFFINE_OFF;
break;
case 1:
2018-09-14 19:15:46 +02:00
if (gTasks[sBirchSpeechMainTaskId].tTimer >= 96)
{
DestroyTask(taskId);
2018-09-14 19:15:46 +02:00
if (gTasks[sBirchSpeechMainTaskId].tTimer < 0x4000)
gTasks[sBirchSpeechMainTaskId].tTimer++;
}
2021-05-09 07:38:57 +02:00
return;
}
2021-05-09 07:38:57 +02:00
tState++;
if (gTasks[sBirchSpeechMainTaskId].tTimer < 0x4000)
gTasks[sBirchSpeechMainTaskId].tTimer++;
}
2018-09-14 19:15:46 +02:00
#undef tState
static void Task_NewGameBirchSpeech_AndYouAre(u8 taskId)
{
2018-09-14 19:15:46 +02:00
if (!RunTextPrintersAndIsPrinter0Active())
{
2021-09-24 20:30:15 +02:00
sStartedPokeBallTask = FALSE;
2018-02-11 23:19:36 +01:00
StringExpandPlaceholders(gStringVar4, gText_Birch_AndYouAre);
2022-07-25 20:59:14 +02:00
AddTextPrinterForMessage(TRUE);
2018-09-14 19:15:46 +02:00
gTasks[taskId].func = Task_NewGameBirchSpeech_StartBirchLotadPlatformFade;
}
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_StartBirchLotadPlatformFade(u8 taskId)
{
2018-09-14 19:15:46 +02:00
if (!RunTextPrintersAndIsPrinter0Active())
{
gSprites[gTasks[taskId].tBirchSpriteId].oam.objMode = ST_OAM_OBJ_BLEND;
gSprites[gTasks[taskId].tLotadSpriteId].oam.objMode = ST_OAM_OBJ_BLEND;
2018-09-14 19:15:46 +02:00
NewGameBirchSpeech_StartFadeOutTarget1InTarget2(taskId, 2);
NewGameBirchSpeech_StartFadePlatformIn(taskId, 1);
gTasks[taskId].tTimer = 64;
gTasks[taskId].func = Task_NewGameBirchSpeech_SlidePlatformAway;
}
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_SlidePlatformAway(u8 taskId)
{
2018-09-14 19:15:46 +02:00
if (gTasks[taskId].tBG1HOFS != -60)
{
2018-09-14 19:15:46 +02:00
gTasks[taskId].tBG1HOFS -= 2;
SetGpuReg(REG_OFFSET_BG1HOFS, gTasks[taskId].tBG1HOFS);
}
else
{
2018-09-14 19:15:46 +02:00
gTasks[taskId].tBG1HOFS = -60;
gTasks[taskId].func = Task_NewGameBirchSpeech_StartPlayerFadeIn;
}
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_StartPlayerFadeIn(u8 taskId)
{
2018-09-14 19:15:46 +02:00
if (gTasks[taskId].tIsDoneFadingSprites)
{
2018-09-14 19:15:46 +02:00
gSprites[gTasks[taskId].tBirchSpriteId].invisible = TRUE;
gSprites[gTasks[taskId].tLotadSpriteId].invisible = TRUE;
if (gTasks[taskId].tTimer)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
gTasks[taskId].tTimer--;
2018-02-11 23:19:36 +01:00
}
else
{
2018-09-14 19:15:46 +02:00
u8 spriteId = gTasks[taskId].tBrendanSpriteId;
2018-02-15 12:41:32 +01:00
2021-07-07 15:11:52 +02:00
gSprites[spriteId].x = 180;
gSprites[spriteId].y = 60;
gSprites[spriteId].invisible = FALSE;
gSprites[spriteId].oam.objMode = ST_OAM_OBJ_BLEND;
2018-09-14 19:15:46 +02:00
gTasks[taskId].tPlayerSpriteId = spriteId;
gTasks[taskId].tPlayerGender = MALE;
NewGameBirchSpeech_StartFadeInTarget1OutTarget2(taskId, 2);
NewGameBirchSpeech_StartFadePlatformOut(taskId, 1);
gTasks[taskId].func = Task_NewGameBirchSpeech_WaitForPlayerFadeIn;
}
}
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_WaitForPlayerFadeIn(u8 taskId)
{
2018-09-14 19:15:46 +02:00
if (gTasks[taskId].tIsDoneFadingSprites)
{
gSprites[gTasks[taskId].tPlayerSpriteId].oam.objMode = ST_OAM_OBJ_NORMAL;
2018-09-14 19:15:46 +02:00
gTasks[taskId].func = Task_NewGameBirchSpeech_BoyOrGirl;
}
}
2018-02-11 23:19:36 +01:00
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_BoyOrGirl(u8 taskId)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
NewGameBirchSpeech_ClearWindow(0);
2018-02-11 23:19:36 +01:00
StringExpandPlaceholders(gStringVar4, gText_Birch_BoyOrGirl);
2022-07-25 20:59:14 +02:00
AddTextPrinterForMessage(TRUE);
2018-09-14 19:15:46 +02:00
gTasks[taskId].func = Task_NewGameBirchSpeech_WaitToShowGenderMenu;
2018-02-11 23:19:36 +01:00
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_WaitToShowGenderMenu(u8 taskId)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
if (!RunTextPrintersAndIsPrinter0Active())
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
NewGameBirchSpeech_ShowGenderMenu();
gTasks[taskId].func = Task_NewGameBirchSpeech_ChooseGender;
2018-02-11 23:19:36 +01:00
}
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_ChooseGender(u8 taskId)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
int gender = NewGameBirchSpeech_ProcessGenderMenuInput();
int gender2;
2018-02-15 12:41:32 +01:00
2018-02-11 23:19:36 +01:00
switch (gender)
{
case MALE:
PlaySE(SE_SELECT);
gSaveBlock2Ptr->playerGender = gender;
2018-09-14 19:15:46 +02:00
NewGameBirchSpeech_ClearGenderWindow(1, 1);
gTasks[taskId].func = Task_NewGameBirchSpeech_WhatsYourName;
2018-02-11 23:19:36 +01:00
break;
case FEMALE:
PlaySE(SE_SELECT);
gSaveBlock2Ptr->playerGender = gender;
2018-09-14 19:15:46 +02:00
NewGameBirchSpeech_ClearGenderWindow(1, 1);
gTasks[taskId].func = Task_NewGameBirchSpeech_WhatsYourName;
2018-02-11 23:19:36 +01:00
break;
}
2018-12-16 21:10:01 +01:00
gender2 = Menu_GetCursorPos();
2018-09-14 19:15:46 +02:00
if (gender2 != gTasks[taskId].tPlayerGender)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
gTasks[taskId].tPlayerGender = gender2;
gSprites[gTasks[taskId].tPlayerSpriteId].oam.objMode = ST_OAM_OBJ_BLEND;
2018-09-14 19:15:46 +02:00
NewGameBirchSpeech_StartFadeOutTarget1InTarget2(taskId, 0);
gTasks[taskId].func = Task_NewGameBirchSpeech_SlideOutOldGenderSprite;
2018-02-11 23:19:36 +01:00
}
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_SlideOutOldGenderSprite(u8 taskId)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
u8 spriteId = gTasks[taskId].tPlayerSpriteId;
if (gTasks[taskId].tIsDoneFadingSprites == 0)
2018-02-11 23:19:36 +01:00
{
2021-07-07 15:11:52 +02:00
gSprites[spriteId].x += 4;
2018-02-11 23:19:36 +01:00
}
else
{
gSprites[spriteId].invisible = TRUE;
2018-09-14 19:15:46 +02:00
if (gTasks[taskId].tPlayerGender != MALE)
spriteId = gTasks[taskId].tMaySpriteId;
2018-02-11 23:19:36 +01:00
else
2018-09-14 19:15:46 +02:00
spriteId = gTasks[taskId].tBrendanSpriteId;
2021-07-07 15:11:52 +02:00
gSprites[spriteId].x = DISPLAY_WIDTH;
gSprites[spriteId].y = 60;
gSprites[spriteId].invisible = FALSE;
2018-09-14 19:15:46 +02:00
gTasks[taskId].tPlayerSpriteId = spriteId;
gSprites[spriteId].oam.objMode = ST_OAM_OBJ_BLEND;
2018-09-14 19:15:46 +02:00
NewGameBirchSpeech_StartFadeInTarget1OutTarget2(taskId, 0);
gTasks[taskId].func = Task_NewGameBirchSpeech_SlideInNewGenderSprite;
2018-02-11 23:19:36 +01:00
}
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_SlideInNewGenderSprite(u8 taskId)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
u8 spriteId = gTasks[taskId].tPlayerSpriteId;
2018-02-15 12:41:32 +01:00
2021-07-07 15:11:52 +02:00
if (gSprites[spriteId].x > 180)
2018-02-11 23:19:36 +01:00
{
2021-07-07 15:11:52 +02:00
gSprites[spriteId].x -= 4;
2018-02-11 23:19:36 +01:00
}
else
{
2021-07-07 15:11:52 +02:00
gSprites[spriteId].x = 180;
2018-09-14 19:15:46 +02:00
if (gTasks[taskId].tIsDoneFadingSprites)
2018-02-11 23:19:36 +01:00
{
gSprites[spriteId].oam.objMode = ST_OAM_OBJ_NORMAL;
2018-09-14 19:15:46 +02:00
gTasks[taskId].func = Task_NewGameBirchSpeech_ChooseGender;
2018-02-11 23:19:36 +01:00
}
}
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_WhatsYourName(u8 taskId)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
NewGameBirchSpeech_ClearWindow(0);
2018-02-11 23:19:36 +01:00
StringExpandPlaceholders(gStringVar4, gText_Birch_WhatsYourName);
2022-07-25 20:59:14 +02:00
AddTextPrinterForMessage(TRUE);
2018-09-14 19:15:46 +02:00
gTasks[taskId].func = Task_NewGameBirchSpeech_WaitForWhatsYourNameToPrint;
2018-02-11 23:19:36 +01:00
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_WaitForWhatsYourNameToPrint(u8 taskId)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
if (!RunTextPrintersAndIsPrinter0Active())
gTasks[taskId].func = Task_NewGameBirchSpeech_WaitPressBeforeNameChoice;
2018-02-11 23:19:36 +01:00
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_WaitPressBeforeNameChoice(u8 taskId)
2018-02-11 23:19:36 +01:00
{
2020-09-05 03:11:55 +02:00
if ((JOY_NEW(A_BUTTON)) || (JOY_NEW(B_BUTTON)))
2018-02-11 23:19:36 +01:00
{
2021-02-24 17:01:02 +01:00
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 16, RGB_BLACK);
2018-09-14 19:15:46 +02:00
gTasks[taskId].func = Task_NewGameBirchSpeech_StartNamingScreen;
2018-02-11 23:19:36 +01:00
}
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_StartNamingScreen(u8 taskId)
2018-02-11 23:19:36 +01:00
{
if (!gPaletteFade.active)
{
FreeAllWindowBuffers();
2018-09-14 19:15:46 +02:00
FreeAndDestroyMonPicSprite(gTasks[taskId].tLotadSpriteId);
NewGameBirchSpeech_SetDefaultPlayerName(Random() % 20);
2018-02-11 23:19:36 +01:00
DestroyTask(taskId);
2020-08-07 08:00:41 +02:00
DoNamingScreen(NAMING_SCREEN_PLAYER, gSaveBlock2Ptr->playerName, gSaveBlock2Ptr->playerGender, 0, 0, CB2_NewGameBirchSpeech_ReturnFromNamingScreen);
2018-02-11 23:19:36 +01:00
}
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_SoItsPlayerName(u8 taskId)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
NewGameBirchSpeech_ClearWindow(0);
2018-02-11 23:19:36 +01:00
StringExpandPlaceholders(gStringVar4, gText_Birch_SoItsPlayer);
2022-07-25 20:59:14 +02:00
AddTextPrinterForMessage(TRUE);
2018-09-14 19:15:46 +02:00
gTasks[taskId].func = Task_NewGameBirchSpeech_CreateNameYesNo;
2018-02-11 23:19:36 +01:00
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_CreateNameYesNo(u8 taskId)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
if (!RunTextPrintersAndIsPrinter0Active())
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
CreateYesNoMenuParameterized(2, 1, 0xF3, 0xDF, 2, 15);
gTasks[taskId].func = Task_NewGameBirchSpeech_ProcessNameYesNoMenu;
2018-02-11 23:19:36 +01:00
}
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_ProcessNameYesNoMenu(u8 taskId)
2018-02-11 23:19:36 +01:00
{
2018-11-05 21:45:54 +01:00
switch (Menu_ProcessInputNoWrapClearOnChoose())
2018-02-11 23:19:36 +01:00
{
case 0:
PlaySE(SE_SELECT);
gSprites[gTasks[taskId].tPlayerSpriteId].oam.objMode = ST_OAM_OBJ_BLEND;
2018-09-14 19:15:46 +02:00
NewGameBirchSpeech_StartFadeOutTarget1InTarget2(taskId, 2);
NewGameBirchSpeech_StartFadePlatformIn(taskId, 1);
gTasks[taskId].func = Task_NewGameBirchSpeech_SlidePlatformAway2;
2018-02-11 23:19:36 +01:00
break;
2022-11-09 21:53:47 +01:00
case MENU_B_PRESSED:
2018-02-11 23:19:36 +01:00
case 1:
PlaySE(SE_SELECT);
2018-09-14 19:15:46 +02:00
gTasks[taskId].func = Task_NewGameBirchSpeech_BoyOrGirl;
2018-02-11 23:19:36 +01:00
}
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_SlidePlatformAway2(u8 taskId)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
if (gTasks[taskId].tBG1HOFS)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
gTasks[taskId].tBG1HOFS += 2;
SetGpuReg(REG_OFFSET_BG1HOFS, gTasks[taskId].tBG1HOFS);
2018-02-11 23:19:36 +01:00
}
else
{
2018-09-14 19:15:46 +02:00
gTasks[taskId].func = Task_NewGameBirchSpeech_ReshowBirchLotad;
2018-02-11 23:19:36 +01:00
}
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_ReshowBirchLotad(u8 taskId)
2018-02-11 23:19:36 +01:00
{
u8 spriteId;
2018-02-15 12:41:32 +01:00
2018-09-14 19:15:46 +02:00
if (gTasks[taskId].tIsDoneFadingSprites)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
gSprites[gTasks[taskId].tBrendanSpriteId].invisible = TRUE;
gSprites[gTasks[taskId].tMaySpriteId].invisible = TRUE;
spriteId = gTasks[taskId].tBirchSpriteId;
2021-07-07 15:11:52 +02:00
gSprites[spriteId].x = 136;
gSprites[spriteId].y = 60;
2018-02-15 02:45:27 +01:00
gSprites[spriteId].invisible = FALSE;
gSprites[spriteId].oam.objMode = ST_OAM_OBJ_BLEND;
2018-09-14 19:15:46 +02:00
spriteId = gTasks[taskId].tLotadSpriteId;
2021-07-07 15:11:52 +02:00
gSprites[spriteId].x = 100;
gSprites[spriteId].y = 75;
2018-02-15 02:45:27 +01:00
gSprites[spriteId].invisible = FALSE;
gSprites[spriteId].oam.objMode = ST_OAM_OBJ_BLEND;
2018-09-14 19:15:46 +02:00
NewGameBirchSpeech_StartFadeInTarget1OutTarget2(taskId, 2);
NewGameBirchSpeech_StartFadePlatformOut(taskId, 1);
NewGameBirchSpeech_ClearWindow(0);
2018-02-11 23:19:36 +01:00
StringExpandPlaceholders(gStringVar4, gText_Birch_YourePlayer);
2022-07-25 20:59:14 +02:00
AddTextPrinterForMessage(TRUE);
2018-09-14 19:15:46 +02:00
gTasks[taskId].func = Task_NewGameBirchSpeech_WaitForSpriteFadeInAndTextPrinter;
2018-02-11 23:19:36 +01:00
}
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_WaitForSpriteFadeInAndTextPrinter(u8 taskId)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
if (gTasks[taskId].tIsDoneFadingSprites)
2018-02-11 23:19:36 +01:00
{
gSprites[gTasks[taskId].tBirchSpriteId].oam.objMode = ST_OAM_OBJ_NORMAL;
gSprites[gTasks[taskId].tLotadSpriteId].oam.objMode = ST_OAM_OBJ_NORMAL;
2018-09-14 19:15:46 +02:00
if (!RunTextPrintersAndIsPrinter0Active())
2018-02-11 23:19:36 +01:00
{
gSprites[gTasks[taskId].tBirchSpriteId].oam.objMode = ST_OAM_OBJ_BLEND;
gSprites[gTasks[taskId].tLotadSpriteId].oam.objMode = ST_OAM_OBJ_BLEND;
2018-09-14 19:15:46 +02:00
NewGameBirchSpeech_StartFadeOutTarget1InTarget2(taskId, 2);
NewGameBirchSpeech_StartFadePlatformIn(taskId, 1);
gTasks[taskId].tTimer = 64;
gTasks[taskId].func = Task_NewGameBirchSpeech_AreYouReady;
2018-02-11 23:19:36 +01:00
}
}
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_AreYouReady(u8 taskId)
2018-02-11 23:19:36 +01:00
{
u8 spriteId;
2018-02-15 12:41:32 +01:00
2018-09-14 19:15:46 +02:00
if (gTasks[taskId].tIsDoneFadingSprites)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
gSprites[gTasks[taskId].tBirchSpriteId].invisible = TRUE;
gSprites[gTasks[taskId].tLotadSpriteId].invisible = TRUE;
if (gTasks[taskId].tTimer)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
gTasks[taskId].tTimer--;
2018-02-11 23:19:36 +01:00
return;
}
if (gSaveBlock2Ptr->playerGender != MALE)
2018-09-14 19:15:46 +02:00
spriteId = gTasks[taskId].tMaySpriteId;
2018-02-11 23:19:36 +01:00
else
2018-09-14 19:15:46 +02:00
spriteId = gTasks[taskId].tBrendanSpriteId;
2021-07-07 15:11:52 +02:00
gSprites[spriteId].x = 120;
gSprites[spriteId].y = 60;
gSprites[spriteId].invisible = FALSE;
gSprites[spriteId].oam.objMode = ST_OAM_OBJ_BLEND;
2018-09-14 19:15:46 +02:00
gTasks[taskId].tPlayerSpriteId = spriteId;
NewGameBirchSpeech_StartFadeInTarget1OutTarget2(taskId, 2);
NewGameBirchSpeech_StartFadePlatformOut(taskId, 1);
2018-02-11 23:19:36 +01:00
StringExpandPlaceholders(gStringVar4, gText_Birch_AreYouReady);
2022-07-25 20:59:14 +02:00
AddTextPrinterForMessage(TRUE);
2018-09-14 19:15:46 +02:00
gTasks[taskId].func = Task_NewGameBirchSpeech_ShrinkPlayer;
2018-02-11 23:19:36 +01:00
}
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_ShrinkPlayer(u8 taskId)
2018-02-11 23:19:36 +01:00
{
u8 spriteId;
2018-02-15 12:41:32 +01:00
2018-09-14 19:15:46 +02:00
if (gTasks[taskId].tIsDoneFadingSprites)
2018-02-11 23:19:36 +01:00
{
gSprites[gTasks[taskId].tPlayerSpriteId].oam.objMode = ST_OAM_OBJ_NORMAL;
2018-09-14 19:15:46 +02:00
if (!RunTextPrintersAndIsPrinter0Active())
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
spriteId = gTasks[taskId].tPlayerSpriteId;
gSprites[spriteId].oam.affineMode = ST_OAM_AFFINE_NORMAL;
2018-09-14 19:15:46 +02:00
gSprites[spriteId].affineAnims = sSpriteAffineAnimTable_PlayerShrink;
2018-02-11 23:19:36 +01:00
InitSpriteAffineAnim(&gSprites[spriteId]);
StartSpriteAffineAnim(&gSprites[spriteId], 0);
2018-09-14 19:15:46 +02:00
gSprites[spriteId].callback = SpriteCB_MovePlayerDownWhileShrinking;
2021-02-24 17:01:02 +01:00
BeginNormalPaletteFade(PALETTES_BG, 0, 0, 16, RGB_BLACK);
2018-02-11 23:19:36 +01:00
FadeOutBGM(4);
2018-09-14 19:15:46 +02:00
gTasks[taskId].func = Task_NewGameBirchSpeech_WaitForPlayerShrink;
2018-02-11 23:19:36 +01:00
}
}
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_WaitForPlayerShrink(u8 taskId)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
u8 spriteId = gTasks[taskId].tPlayerSpriteId;
2018-02-15 12:41:32 +01:00
2018-02-11 23:19:36 +01:00
if (gSprites[spriteId].affineAnimEnded)
2018-09-14 19:15:46 +02:00
gTasks[taskId].func = Task_NewGameBirchSpeech_FadePlayerToWhite;
2018-02-11 23:19:36 +01:00
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_FadePlayerToWhite(u8 taskId)
2018-02-11 23:19:36 +01:00
{
u8 spriteId;
2018-02-15 12:41:32 +01:00
2018-02-11 23:19:36 +01:00
if (!gPaletteFade.active)
{
2018-09-14 19:15:46 +02:00
spriteId = gTasks[taskId].tPlayerSpriteId;
gSprites[spriteId].callback = SpriteCB_Null;
2018-02-14 04:12:02 +01:00
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP);
2021-02-24 17:01:02 +01:00
BeginNormalPaletteFade(PALETTES_OBJECTS, 0, 0, 16, RGB_WHITEALPHA);
2018-09-14 19:15:46 +02:00
gTasks[taskId].func = Task_NewGameBirchSpeech_Cleanup;
2018-02-11 23:19:36 +01:00
}
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_Cleanup(u8 taskId)
2018-02-11 23:19:36 +01:00
{
if (!gPaletteFade.active)
{
FreeAllWindowBuffers();
2018-09-14 19:15:46 +02:00
FreeAndDestroyMonPicSprite(gTasks[taskId].tLotadSpriteId);
2018-08-19 01:06:10 +02:00
ResetAllPicSprites();
2018-02-11 23:19:36 +01:00
SetMainCallback2(CB2_NewGame);
DestroyTask(taskId);
}
}
2018-09-14 19:15:46 +02:00
static void CB2_NewGameBirchSpeech_ReturnFromNamingScreen(void)
2018-02-11 23:19:36 +01:00
{
u8 taskId;
u8 spriteId;
u16 savedIme;
2018-02-15 12:41:32 +01:00
2018-02-11 23:19:36 +01:00
ResetBgsAndClearDma3BusyFlags(0);
SetGpuReg(REG_OFFSET_DISPCNT, 0);
2018-02-14 04:12:02 +01:00
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP);
InitBgsFromTemplates(0, sMainMenuBgTemplates, ARRAY_COUNT(sMainMenuBgTemplates));
2018-09-14 19:15:46 +02:00
InitBgFromTemplate(&sBirchBgTemplate);
2018-02-11 23:19:36 +01:00
SetVBlankCallback(NULL);
SetGpuReg(REG_OFFSET_BG2CNT, 0);
SetGpuReg(REG_OFFSET_BG1CNT, 0);
SetGpuReg(REG_OFFSET_BG0CNT, 0);
SetGpuReg(REG_OFFSET_BG2HOFS, 0);
SetGpuReg(REG_OFFSET_BG2VOFS, 0);
SetGpuReg(REG_OFFSET_BG1HOFS, 0);
SetGpuReg(REG_OFFSET_BG1VOFS, 0);
SetGpuReg(REG_OFFSET_BG0HOFS, 0);
SetGpuReg(REG_OFFSET_BG0VOFS, 0);
DmaFill16(3, 0, VRAM, VRAM_SIZE);
DmaFill32(3, 0, OAM, OAM_SIZE);
DmaFill16(3, 0, PLTT, PLTT_SIZE);
ResetPaletteFade();
LZ77UnCompVram(sBirchSpeechShadowGfx, (u8 *)VRAM);
LZ77UnCompVram(sBirchSpeechBgMap, (u8 *)(BG_SCREEN_ADDR(7)));
2018-09-14 19:15:46 +02:00
LoadPalette(sBirchSpeechBgPals, 0, 64);
LoadPalette(&sBirchSpeechBgGradientPal[1], 1, 16);
2018-02-11 23:19:36 +01:00
ResetTasks();
2018-09-14 19:15:46 +02:00
taskId = CreateTask(Task_NewGameBirchSpeech_ReturnFromNamingScreenShowTextbox, 0);
gTasks[taskId].tTimer = 5;
gTasks[taskId].tBG1HOFS = -60;
2018-02-11 23:19:36 +01:00
ScanlineEffect_Stop();
ResetSpriteData();
FreeAllSpritePalettes();
2018-08-19 01:06:10 +02:00
ResetAllPicSprites();
2018-02-11 23:19:36 +01:00
AddBirchSpeechObjects(taskId);
if (gSaveBlock2Ptr->playerGender != MALE)
{
2018-09-14 19:15:46 +02:00
gTasks[taskId].tPlayerGender = FEMALE;
spriteId = gTasks[taskId].tMaySpriteId;
2018-02-11 23:19:36 +01:00
}
else
{
2018-09-14 19:15:46 +02:00
gTasks[taskId].tPlayerGender = MALE;
spriteId = gTasks[taskId].tBrendanSpriteId;
2018-02-11 23:19:36 +01:00
}
2021-07-07 15:11:52 +02:00
gSprites[spriteId].x = 180;
gSprites[spriteId].y = 60;
gSprites[spriteId].invisible = FALSE;
2018-09-14 19:15:46 +02:00
gTasks[taskId].tPlayerSpriteId = spriteId;
2018-02-11 23:19:36 +01:00
SetGpuReg(REG_OFFSET_BG1HOFS, -60);
2021-02-24 17:01:02 +01:00
BeginNormalPaletteFade(PALETTES_ALL, 0, 16, 0, RGB_BLACK);
2018-02-11 23:19:36 +01:00
SetGpuReg(REG_OFFSET_WIN0H, 0);
SetGpuReg(REG_OFFSET_WIN0V, 0);
SetGpuReg(REG_OFFSET_WININ, 0);
SetGpuReg(REG_OFFSET_WINOUT, 0);
SetGpuReg(REG_OFFSET_BLDCNT, 0);
SetGpuReg(REG_OFFSET_BLDALPHA, 0);
SetGpuReg(REG_OFFSET_BLDY, 0);
ShowBg(0);
ShowBg(1);
savedIme = REG_IME;
REG_IME = 0;
REG_IE |= 1;
REG_IME = savedIme;
SetVBlankCallback(VBlankCB_MainMenu);
SetMainCallback2(CB2_MainMenu);
2022-05-17 19:51:54 +02:00
InitWindows(sNewGameBirchSpeechTextWindows);
2018-02-11 23:19:36 +01:00
LoadMainMenuWindowFrameTiles(0, 0xF3);
2018-06-17 16:48:58 +02:00
LoadMessageBoxGfx(0, 0xFC, 0xF0);
2018-02-11 23:19:36 +01:00
PutWindowTilemap(0);
2021-11-03 20:29:18 +01:00
CopyWindowToVram(0, COPYWIN_FULL);
2018-02-11 23:19:36 +01:00
}
static void SpriteCB_Null(struct Sprite *sprite)
2018-02-11 23:19:36 +01:00
{
}
2018-09-14 19:15:46 +02:00
static void SpriteCB_MovePlayerDownWhileShrinking(struct Sprite *sprite)
2018-02-11 23:19:36 +01:00
{
u32 y;
2018-02-15 12:41:32 +01:00
2021-07-07 15:11:52 +02:00
y = (sprite->y << 16) + sprite->data[0] + 0xC000;
sprite->y = y >> 16;
2018-02-11 23:19:36 +01:00
sprite->data[0] = y;
}
2021-10-18 07:39:07 +02:00
static u8 NewGameBirchSpeech_CreateLotadSprite(u8 x, u8 y)
2018-02-11 23:19:36 +01:00
{
2021-10-18 07:39:07 +02:00
return CreateMonPicSprite_Affine(SPECIES_LOTAD, SHINY_ODDS, 0, MON_PIC_AFFINE_FRONT, x, y, 14, TAG_NONE);
2018-02-11 23:19:36 +01:00
}
2018-09-14 19:15:46 +02:00
static void AddBirchSpeechObjects(u8 taskId)
{
u8 birchSpriteId;
u8 lotadSpriteId;
u8 brendanSpriteId;
u8 maySpriteId;
birchSpriteId = AddNewGameBirchObject(0x88, 0x3C, 1);
gSprites[birchSpriteId].callback = SpriteCB_Null;
2018-09-14 19:15:46 +02:00
gSprites[birchSpriteId].oam.priority = 0;
gSprites[birchSpriteId].invisible = TRUE;
gTasks[taskId].tBirchSpriteId = birchSpriteId;
lotadSpriteId = NewGameBirchSpeech_CreateLotadSprite(100, 0x4B);
gSprites[lotadSpriteId].callback = SpriteCB_Null;
2018-09-14 19:15:46 +02:00
gSprites[lotadSpriteId].oam.priority = 0;
gSprites[lotadSpriteId].invisible = TRUE;
gTasks[taskId].tLotadSpriteId = lotadSpriteId;
brendanSpriteId = CreateTrainerSprite(FacilityClassToPicIndex(FACILITY_CLASS_BRENDAN), 120, 60, 0, &gDecompressionBuffer[0]);
gSprites[brendanSpriteId].callback = SpriteCB_Null;
2018-09-14 19:15:46 +02:00
gSprites[brendanSpriteId].invisible = TRUE;
gSprites[brendanSpriteId].oam.priority = 0;
gTasks[taskId].tBrendanSpriteId = brendanSpriteId;
maySpriteId = CreateTrainerSprite(FacilityClassToPicIndex(FACILITY_CLASS_MAY), 120, 60, 0, &gDecompressionBuffer[0x800]);
gSprites[maySpriteId].callback = SpriteCB_Null;
2018-09-14 19:15:46 +02:00
gSprites[maySpriteId].invisible = TRUE;
gSprites[maySpriteId].oam.priority = 0;
gTasks[taskId].tMaySpriteId = maySpriteId;
}
#undef tPlayerSpriteId
#undef tBG1HOFS
#undef tPlayerGender
#undef tBirchSpriteId
#undef tLotadSpriteId
#undef tBrendanSpriteId
#undef tMaySpriteId
#define tMainTask data[0]
#define tAlphaCoeff1 data[1]
#define tAlphaCoeff2 data[2]
#define tDelay data[3]
#define tDelayTimer data[4]
static void Task_NewGameBirchSpeech_FadeOutTarget1InTarget2(u8 taskId)
{
int alphaCoeff2;
if (gTasks[taskId].tAlphaCoeff1 == 0)
{
gTasks[gTasks[taskId].tMainTask].tIsDoneFadingSprites = TRUE;
2018-02-11 23:19:36 +01:00
DestroyTask(taskId);
}
2018-09-14 19:15:46 +02:00
else if (gTasks[taskId].tDelayTimer)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
gTasks[taskId].tDelayTimer--;
2018-02-11 23:19:36 +01:00
}
else
{
2018-09-14 19:15:46 +02:00
gTasks[taskId].tDelayTimer = gTasks[taskId].tDelay;
gTasks[taskId].tAlphaCoeff1--;
gTasks[taskId].tAlphaCoeff2++;
alphaCoeff2 = gTasks[taskId].tAlphaCoeff2 << 8;
SetGpuReg(REG_OFFSET_BLDALPHA, gTasks[taskId].tAlphaCoeff1 + alphaCoeff2);
2018-02-11 23:19:36 +01:00
}
}
2018-09-14 19:15:46 +02:00
static void NewGameBirchSpeech_StartFadeOutTarget1InTarget2(u8 taskId, u8 delay)
2018-02-11 23:19:36 +01:00
{
u8 taskId2;
2018-02-15 12:41:32 +01:00
2018-02-14 04:12:02 +01:00
SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT2_BG1 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT1_OBJ);
SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(16, 0));
2018-02-11 23:19:36 +01:00
SetGpuReg(REG_OFFSET_BLDY, 0);
2018-09-14 19:15:46 +02:00
gTasks[taskId].tIsDoneFadingSprites = 0;
taskId2 = CreateTask(Task_NewGameBirchSpeech_FadeOutTarget1InTarget2, 0);
gTasks[taskId2].tMainTask = taskId;
gTasks[taskId2].tAlphaCoeff1 = 16;
gTasks[taskId2].tAlphaCoeff2 = 0;
gTasks[taskId2].tDelay = delay;
gTasks[taskId2].tDelayTimer = delay;
2018-02-11 23:19:36 +01:00
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_FadeInTarget1OutTarget2(u8 taskId)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
int alphaCoeff2;
2018-02-15 12:41:32 +01:00
2018-09-14 19:15:46 +02:00
if (gTasks[taskId].tAlphaCoeff1 == 16)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
gTasks[gTasks[taskId].tMainTask].tIsDoneFadingSprites = TRUE;
2018-02-11 23:19:36 +01:00
DestroyTask(taskId);
}
2018-09-14 19:15:46 +02:00
else if (gTasks[taskId].tDelayTimer)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
gTasks[taskId].tDelayTimer--;
2018-02-11 23:19:36 +01:00
}
else
{
2018-09-14 19:15:46 +02:00
gTasks[taskId].tDelayTimer = gTasks[taskId].tDelay;
gTasks[taskId].tAlphaCoeff1++;
gTasks[taskId].tAlphaCoeff2--;
alphaCoeff2 = gTasks[taskId].tAlphaCoeff2 << 8;
SetGpuReg(REG_OFFSET_BLDALPHA, gTasks[taskId].tAlphaCoeff1 + alphaCoeff2);
2018-02-11 23:19:36 +01:00
}
}
2018-09-14 19:15:46 +02:00
static void NewGameBirchSpeech_StartFadeInTarget1OutTarget2(u8 taskId, u8 delay)
2018-02-11 23:19:36 +01:00
{
u8 taskId2;
2018-02-15 12:41:32 +01:00
2018-02-14 04:12:02 +01:00
SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT2_BG1 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT1_OBJ);
SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(0, 16));
2018-02-11 23:19:36 +01:00
SetGpuReg(REG_OFFSET_BLDY, 0);
2018-09-14 19:15:46 +02:00
gTasks[taskId].tIsDoneFadingSprites = 0;
taskId2 = CreateTask(Task_NewGameBirchSpeech_FadeInTarget1OutTarget2, 0);
gTasks[taskId2].tMainTask = taskId;
gTasks[taskId2].tAlphaCoeff1 = 0;
gTasks[taskId2].tAlphaCoeff2 = 16;
gTasks[taskId2].tDelay = delay;
gTasks[taskId2].tDelayTimer = delay;
2018-02-11 23:19:36 +01:00
}
2018-09-14 19:15:46 +02:00
#undef tMainTask
#undef tAlphaCoeff1
#undef tAlphaCoeff2
#undef tDelay
#undef tDelayTimer
#undef tIsDoneFadingSprites
#define tMainTask data[0]
#define tPalIndex data[1]
#define tDelayBefore data[2]
#define tDelay data[3]
#define tDelayTimer data[4]
static void Task_NewGameBirchSpeech_FadePlatformIn(u8 taskId)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
if (gTasks[taskId].tDelayBefore)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
gTasks[taskId].tDelayBefore--;
2018-02-11 23:19:36 +01:00
}
2018-09-14 19:15:46 +02:00
else if (gTasks[taskId].tPalIndex == 8)
2018-02-11 23:19:36 +01:00
{
DestroyTask(taskId);
}
2018-09-14 19:15:46 +02:00
else if (gTasks[taskId].tDelayTimer)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
gTasks[taskId].tDelayTimer--;
2018-02-11 23:19:36 +01:00
}
else
{
2018-09-14 19:15:46 +02:00
gTasks[taskId].tDelayTimer = gTasks[taskId].tDelay;
gTasks[taskId].tPalIndex++;
LoadPalette(&sBirchSpeechBgGradientPal[gTasks[taskId].tPalIndex], 1, 16);
2018-02-11 23:19:36 +01:00
}
}
2018-09-14 19:15:46 +02:00
static void NewGameBirchSpeech_StartFadePlatformIn(u8 taskId, u8 delay)
2018-02-11 23:19:36 +01:00
{
u8 taskId2;
2018-02-15 12:41:32 +01:00
2018-09-14 19:15:46 +02:00
taskId2 = CreateTask(Task_NewGameBirchSpeech_FadePlatformIn, 0);
gTasks[taskId2].tMainTask = taskId;
gTasks[taskId2].tPalIndex = 0;
gTasks[taskId2].tDelayBefore = 8;
gTasks[taskId2].tDelay = delay;
gTasks[taskId2].tDelayTimer = delay;
2018-02-11 23:19:36 +01:00
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_FadePlatformOut(u8 taskId)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
if (gTasks[taskId].tDelayBefore)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
gTasks[taskId].tDelayBefore--;
2018-02-11 23:19:36 +01:00
}
2018-09-14 19:15:46 +02:00
else if (gTasks[taskId].tPalIndex == 0)
2018-02-11 23:19:36 +01:00
{
DestroyTask(taskId);
}
2018-09-14 19:15:46 +02:00
else if (gTasks[taskId].tDelayTimer)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
gTasks[taskId].tDelayTimer--;
2018-02-11 23:19:36 +01:00
}
else
{
2018-09-14 19:15:46 +02:00
gTasks[taskId].tDelayTimer = gTasks[taskId].tDelay;
gTasks[taskId].tPalIndex--;
LoadPalette(&sBirchSpeechBgGradientPal[gTasks[taskId].tPalIndex], 1, 16);
2018-02-11 23:19:36 +01:00
}
}
2018-09-14 19:15:46 +02:00
static void NewGameBirchSpeech_StartFadePlatformOut(u8 taskId, u8 delay)
2018-02-11 23:19:36 +01:00
{
u8 taskId2;
2018-02-15 12:41:32 +01:00
2018-09-14 19:15:46 +02:00
taskId2 = CreateTask(Task_NewGameBirchSpeech_FadePlatformOut, 0);
gTasks[taskId2].tMainTask = taskId;
gTasks[taskId2].tPalIndex = 8;
gTasks[taskId2].tDelayBefore = 8;
gTasks[taskId2].tDelay = delay;
gTasks[taskId2].tDelayTimer = delay;
2018-02-11 23:19:36 +01:00
}
2018-09-14 19:15:46 +02:00
#undef tMainTask
#undef tPalIndex
#undef tDelayBefore
#undef tDelay
#undef tDelayTimer
static void NewGameBirchSpeech_ShowGenderMenu(void)
2018-02-11 23:19:36 +01:00
{
2022-05-17 19:51:54 +02:00
DrawMainMenuWindowBorder(&sNewGameBirchSpeechTextWindows[1], 0xF3);
FillWindowPixelBuffer(1, PIXEL_FILL(1));
2021-01-19 10:19:14 +01:00
PrintMenuTable(1, ARRAY_COUNT(sMenuActions_Gender), sMenuActions_Gender);
2022-02-27 19:47:50 +01:00
InitMenuInUpperLeftCornerNormal(1, ARRAY_COUNT(sMenuActions_Gender), 0);
2018-02-11 23:19:36 +01:00
PutWindowTilemap(1);
2021-11-03 20:29:18 +01:00
CopyWindowToVram(1, COPYWIN_FULL);
2018-02-11 23:19:36 +01:00
}
2018-09-14 19:15:46 +02:00
static s8 NewGameBirchSpeech_ProcessGenderMenuInput(void)
2018-02-11 23:19:36 +01:00
{
2018-11-05 21:45:54 +01:00
return Menu_ProcessInputNoWrap();
2018-02-11 23:19:36 +01:00
}
void NewGameBirchSpeech_SetDefaultPlayerName(u8 nameId)
2018-02-11 23:19:36 +01:00
{
const u8 *name;
2018-02-11 23:19:36 +01:00
u8 i;
2018-02-15 12:41:32 +01:00
2018-02-11 23:19:36 +01:00
if (gSaveBlock2Ptr->playerGender == MALE)
2022-05-17 19:51:54 +02:00
name = sMalePresetNames[nameId];
2018-02-11 23:19:36 +01:00
else
2022-05-17 19:51:54 +02:00
name = sFemalePresetNames[nameId];
2021-02-24 17:01:02 +01:00
for (i = 0; i < PLAYER_NAME_LENGTH; i++)
2018-02-11 23:19:36 +01:00
gSaveBlock2Ptr->playerName[i] = name[i];
2021-02-24 17:01:02 +01:00
gSaveBlock2Ptr->playerName[PLAYER_NAME_LENGTH] = EOS;
2018-02-11 23:19:36 +01:00
}
static void CreateMainMenuErrorWindow(const u8 *str)
2018-02-11 23:19:36 +01:00
{
FillWindowPixelBuffer(7, PIXEL_FILL(1));
2021-10-30 22:47:37 +02:00
AddTextPrinterParameterized(7, FONT_NORMAL, str, 0, 1, 2, 0);
2018-02-11 23:19:36 +01:00
PutWindowTilemap(7);
2021-11-03 20:29:18 +01:00
CopyWindowToVram(7, COPYWIN_GFX);
2018-09-08 02:24:33 +02:00
DrawMainMenuWindowBorder(&sWindowTemplates_MainMenu[7], MAIN_MENU_BORDER_TILE);
2021-04-15 08:04:01 +02:00
SetGpuReg(REG_OFFSET_WIN0H, WIN_RANGE(9, DISPLAY_WIDTH - 9));
SetGpuReg(REG_OFFSET_WIN0V, WIN_RANGE(113, DISPLAY_HEIGHT - 1));
2018-02-11 23:19:36 +01:00
}
2018-09-14 19:15:46 +02:00
static void MainMenu_FormatSavegameText(void)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
MainMenu_FormatSavegamePlayer();
MainMenu_FormatSavegamePokedex();
MainMenu_FormatSavegameTime();
MainMenu_FormatSavegameBadges();
2018-02-11 23:19:36 +01:00
}
2018-09-14 19:15:46 +02:00
static void MainMenu_FormatSavegamePlayer(void)
2018-02-11 23:19:36 +01:00
{
StringExpandPlaceholders(gStringVar4, gText_ContinueMenuPlayer);
AddTextPrinterParameterized3(2, FONT_NORMAL, 0, 17, sTextColor_MenuInfo, TEXT_SKIP_DRAW, gStringVar4);
AddTextPrinterParameterized3(2, FONT_NORMAL, GetStringRightAlignXOffset(FONT_NORMAL, gSaveBlock2Ptr->playerName, 100), 17, sTextColor_MenuInfo, TEXT_SKIP_DRAW, gSaveBlock2Ptr->playerName);
2018-02-11 23:19:36 +01:00
}
2018-09-14 19:15:46 +02:00
static void MainMenu_FormatSavegameTime(void)
2018-02-11 23:19:36 +01:00
{
u8 str[0x20];
u8 *ptr;
2018-02-15 12:41:32 +01:00
2018-02-11 23:19:36 +01:00
StringExpandPlaceholders(gStringVar4, gText_ContinueMenuTime);
AddTextPrinterParameterized3(2, FONT_NORMAL, 0x6C, 17, sTextColor_MenuInfo, TEXT_SKIP_DRAW, gStringVar4);
2019-09-30 21:43:44 +02:00
ptr = ConvertIntToDecimalStringN(str, gSaveBlock2Ptr->playTimeHours, STR_CONV_MODE_LEFT_ALIGN, 3);
2018-02-11 23:19:36 +01:00
*ptr = 0xF0;
2019-09-30 21:43:44 +02:00
ConvertIntToDecimalStringN(ptr + 1, gSaveBlock2Ptr->playTimeMinutes, STR_CONV_MODE_LEADING_ZEROS, 2);
AddTextPrinterParameterized3(2, FONT_NORMAL, GetStringRightAlignXOffset(FONT_NORMAL, str, 0xD0), 17, sTextColor_MenuInfo, TEXT_SKIP_DRAW, str);
2018-02-11 23:19:36 +01:00
}
2018-09-14 19:15:46 +02:00
static void MainMenu_FormatSavegamePokedex(void)
2018-02-11 23:19:36 +01:00
{
u8 str[0x20];
u16 dexCount;
2018-02-15 12:41:32 +01:00
2018-02-11 23:19:36 +01:00
if (FlagGet(FLAG_SYS_POKEDEX_GET) == TRUE)
{
if (IsNationalPokedexEnabled())
2019-10-07 07:13:34 +02:00
dexCount = GetNationalPokedexCount(FLAG_GET_CAUGHT);
2018-02-11 23:19:36 +01:00
else
2019-10-07 07:13:34 +02:00
dexCount = GetHoennPokedexCount(FLAG_GET_CAUGHT);
2018-02-11 23:19:36 +01:00
StringExpandPlaceholders(gStringVar4, gText_ContinueMenuPokedex);
AddTextPrinterParameterized3(2, FONT_NORMAL, 0, 33, sTextColor_MenuInfo, TEXT_SKIP_DRAW, gStringVar4);
2019-09-30 21:43:44 +02:00
ConvertIntToDecimalStringN(str, dexCount, STR_CONV_MODE_LEFT_ALIGN, 3);
AddTextPrinterParameterized3(2, FONT_NORMAL, GetStringRightAlignXOffset(FONT_NORMAL, str, 100), 33, sTextColor_MenuInfo, TEXT_SKIP_DRAW, str);
2018-02-11 23:19:36 +01:00
}
}
2018-09-14 19:15:46 +02:00
static void MainMenu_FormatSavegameBadges(void)
2018-02-11 23:19:36 +01:00
{
u8 str[0x20];
u8 badgeCount = 0;
u32 i;
2018-02-15 12:41:32 +01:00
2020-02-07 18:48:47 +01:00
for (i = FLAG_BADGE01_GET; i < FLAG_BADGE01_GET + NUM_BADGES; i++)
2018-02-11 23:19:36 +01:00
{
if (FlagGet(i))
badgeCount++;
}
StringExpandPlaceholders(gStringVar4, gText_ContinueMenuBadges);
AddTextPrinterParameterized3(2, FONT_NORMAL, 0x6C, 33, sTextColor_MenuInfo, TEXT_SKIP_DRAW, gStringVar4);
2019-09-30 21:43:44 +02:00
ConvertIntToDecimalStringN(str, badgeCount, STR_CONV_MODE_LEADING_ZEROS, 1);
AddTextPrinterParameterized3(2, FONT_NORMAL, GetStringRightAlignXOffset(FONT_NORMAL, str, 0xD0), 33, sTextColor_MenuInfo, TEXT_SKIP_DRAW, str);
2018-02-11 23:19:36 +01:00
}
2018-09-14 19:15:46 +02:00
static void LoadMainMenuWindowFrameTiles(u8 bgId, u16 tileOffset)
2018-02-11 23:19:36 +01:00
{
LoadBgTiles(bgId, GetWindowFrameTilesPal(gSaveBlock2Ptr->optionsWindowFrameType)->tiles, 0x120, tileOffset);
LoadPalette(GetWindowFrameTilesPal(gSaveBlock2Ptr->optionsWindowFrameType)->pal, 32, 32);
}
2018-09-14 19:15:46 +02:00
static void DrawMainMenuWindowBorder(const struct WindowTemplate *template, u16 baseTileNum)
2018-02-11 23:19:36 +01:00
{
u16 r9 = 1 + baseTileNum;
u16 r10 = 2 + baseTileNum;
u16 sp18 = 3 + baseTileNum;
u16 spC = 5 + baseTileNum;
u16 sp10 = 6 + baseTileNum;
u16 sp14 = 7 + baseTileNum;
u16 r6 = 8 + baseTileNum;
2018-02-15 12:41:32 +01:00
2018-10-27 00:53:07 +02:00
FillBgTilemapBufferRect(template->bg, baseTileNum, template->tilemapLeft - 1, template->tilemapTop - 1, 1, 1, 2);
FillBgTilemapBufferRect(template->bg, r9, template->tilemapLeft, template->tilemapTop - 1, template->width, 1, 2);
FillBgTilemapBufferRect(template->bg, r10, template->tilemapLeft + template->width, template->tilemapTop - 1, 1, 1, 2);
FillBgTilemapBufferRect(template->bg, sp18, template->tilemapLeft - 1, template->tilemapTop, 1, template->height, 2);
FillBgTilemapBufferRect(template->bg, spC, template->tilemapLeft + template->width, template->tilemapTop, 1, template->height, 2);
FillBgTilemapBufferRect(template->bg, sp10, template->tilemapLeft - 1, template->tilemapTop + template->height, 1, 1, 2);
FillBgTilemapBufferRect(template->bg, sp14, template->tilemapLeft, template->tilemapTop + template->height, template->width, 1, 2);
FillBgTilemapBufferRect(template->bg, r6, template->tilemapLeft + template->width, template->tilemapTop + template->height, 1, 1, 2);
CopyBgTilemapBufferToVram(template->bg);
2018-02-11 23:19:36 +01:00
}
2018-07-15 13:23:38 +02:00
static void ClearMainMenuWindowTilemap(const struct WindowTemplate *template)
2018-02-11 23:19:36 +01:00
{
2018-10-27 00:53:07 +02:00
FillBgTilemapBufferRect(template->bg, 0, template->tilemapLeft - 1, template->tilemapTop - 1, template->tilemapLeft + template->width + 1, template->tilemapTop + template->height + 1, 2);
CopyBgTilemapBufferToVram(template->bg);
2018-02-11 23:19:36 +01:00
}
2022-06-01 18:41:57 +02:00
static void NewGameBirchSpeech_ClearGenderWindowTilemap(u8 bg, u8 x, u8 y, u8 width, u8 height, u8 unused)
2018-02-11 23:19:36 +01:00
{
2022-06-01 18:41:57 +02:00
FillBgTilemapBufferRect(bg, 0, x + 255, y + 255, width + 2, height + 2, 2);
2018-02-11 23:19:36 +01:00
}
static void NewGameBirchSpeech_ClearGenderWindow(u8 windowId, bool8 copyToVram)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
CallWindowFunction(windowId, NewGameBirchSpeech_ClearGenderWindowTilemap);
FillWindowPixelBuffer(windowId, PIXEL_FILL(1));
2018-02-11 23:19:36 +01:00
ClearWindowTilemap(windowId);
if (copyToVram == TRUE)
2021-11-03 20:29:18 +01:00
CopyWindowToVram(windowId, COPYWIN_FULL);
2018-02-11 23:19:36 +01:00
}
2018-09-14 19:15:46 +02:00
static void NewGameBirchSpeech_ClearWindow(u8 windowId)
2018-02-11 23:19:36 +01:00
{
2021-10-30 22:47:37 +02:00
u8 bgColor = GetFontAttribute(FONT_NORMAL, FONTATTR_COLOR_BACKGROUND);
u8 maxCharWidth = GetFontAttribute(FONT_NORMAL, FONTATTR_MAX_LETTER_WIDTH);
u8 maxCharHeight = GetFontAttribute(FONT_NORMAL, FONTATTR_MAX_LETTER_HEIGHT);
2018-09-14 19:15:46 +02:00
u8 winWidth = GetWindowAttribute(windowId, WINDOW_WIDTH);
u8 winHeight = GetWindowAttribute(windowId, WINDOW_HEIGHT);
2018-02-15 12:41:32 +01:00
2018-09-14 19:15:46 +02:00
FillWindowPixelRect(windowId, bgColor, 0, 0, maxCharWidth * winWidth, maxCharHeight * winHeight);
2021-11-03 20:29:18 +01:00
CopyWindowToVram(windowId, COPYWIN_GFX);
2018-02-11 23:19:36 +01:00
}
2022-06-01 18:41:57 +02:00
static void NewGameBirchSpeech_WaitForThisIsPokemonText(struct TextPrinterTemplate *printer, u16 renderCmd)
2018-02-11 23:19:36 +01:00
{
2021-09-24 20:30:15 +02:00
// Wait for Birch's "This is a Pokémon" text to reach the pause
// Then start the PokéBall release (if it hasn't been started already)
if (*(printer->currentChar - 2) == EXT_CTRL_CODE_PAUSE && !sStartedPokeBallTask)
2018-02-11 23:19:36 +01:00
{
2021-09-24 20:30:15 +02:00
sStartedPokeBallTask = TRUE;
2018-09-14 19:15:46 +02:00
CreateTask(Task_NewGameBirchSpeechSub_InitPokeBall, 0);
2018-02-11 23:19:36 +01:00
}
}
2021-09-24 20:30:15 +02:00
void CreateYesNoMenuParameterized(u8 x, u8 y, u16 baseTileNum, u16 baseBlock, u8 yesNoPalNum, u8 winPalNum)
2018-02-11 23:19:36 +01:00
{
2021-09-24 20:30:15 +02:00
struct WindowTemplate template = CreateWindowTemplate(0, x + 1, y + 1, 5, 4, winPalNum, baseBlock);
CreateYesNoMenu(&template, baseTileNum, yesNoPalNum, 0);
2018-02-11 23:19:36 +01:00
}
2018-09-14 19:15:46 +02:00
static void NewGameBirchSpeech_ShowDialogueWindow(u8 windowId, u8 copyToVram)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
CallWindowFunction(windowId, NewGameBirchSpeech_CreateDialogueWindowBorder);
FillWindowPixelBuffer(windowId, PIXEL_FILL(1));
2018-02-11 23:19:36 +01:00
PutWindowTilemap(windowId);
2018-09-14 19:15:46 +02:00
if (copyToVram == TRUE)
2022-06-19 14:33:47 +02:00
CopyWindowToVram(windowId, COPYWIN_FULL);
2018-02-11 23:19:36 +01:00
}
2022-06-01 18:41:57 +02:00
static void NewGameBirchSpeech_CreateDialogueWindowBorder(u8 bg, u8 x, u8 y, u8 width, u8 height, u8 palNum)
{
FillBgTilemapBufferRect(bg, 0xFD, x-2, y-1, 1, 1, palNum);
FillBgTilemapBufferRect(bg, 0xFF, x-1, y-1, 1, 1, palNum);
FillBgTilemapBufferRect(bg, 0x100, x, y-1, width, 1, palNum);
FillBgTilemapBufferRect(bg, 0x101, x+width-1, y-1, 1, 1, palNum);
FillBgTilemapBufferRect(bg, 0x102, x+width, y-1, 1, 1, palNum);
FillBgTilemapBufferRect(bg, 0x103, x-2, y, 1, 5, palNum);
FillBgTilemapBufferRect(bg, 0x105, x-1, y, width+1, 5, palNum);
FillBgTilemapBufferRect(bg, 0x106, x+width, y, 1, 5, palNum);
FillBgTilemapBufferRect(bg, BG_TILE_V_FLIP(0xFD), x-2, y+height, 1, 1, palNum);
FillBgTilemapBufferRect(bg, BG_TILE_V_FLIP(0xFF), x-1, y+height, 1, 1, palNum);
FillBgTilemapBufferRect(bg, BG_TILE_V_FLIP(0x100), x, y+height, width-1, 1, palNum);
FillBgTilemapBufferRect(bg, BG_TILE_V_FLIP(0x101), x+width-1, y+height, 1, 1, palNum);
FillBgTilemapBufferRect(bg, BG_TILE_V_FLIP(0x102), x+width, y+height, 1, 1, palNum);
2018-02-11 23:19:36 +01:00
}
2018-09-14 19:15:46 +02:00
static void Task_NewGameBirchSpeech_ReturnFromNamingScreenShowTextbox(u8 taskId)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
if (gTasks[taskId].tTimer-- <= 0)
2018-02-11 23:19:36 +01:00
{
2018-09-14 19:15:46 +02:00
NewGameBirchSpeech_ShowDialogueWindow(0, 1);
gTasks[taskId].func = Task_NewGameBirchSpeech_SoItsPlayerName;
2018-02-11 23:19:36 +01:00
}
}
2018-09-14 19:15:46 +02:00
#undef tTimer