pokeemerald/src/start_menu.c

1422 lines
35 KiB
C
Raw Normal View History

2017-09-05 13:01:24 +02:00
#include "global.h"
#include "start_menu.h"
#include "menu.h"
#include "safari_zone.h"
#include "event_data.h"
#include "window.h"
#include "string_util.h"
#include "text.h"
#include "strings.h"
#include "bg.h"
2018-03-28 00:33:08 +02:00
#include "field_effect.h"
#include "task.h"
#include "overworld.h"
#include "link.h"
#include "battle_frontier_2.h"
#include "rom_818CFC8.h"
#include "field_specials.h"
#include "event_object_movement.h"
2018-03-28 00:33:08 +02:00
#include "script.h"
#include "main.h"
#include "sound.h"
#include "pokedex.h"
#include "field_weather.h"
#include "palette.h"
#include "item_menu.h"
#include "option_menu.h"
#include "event_scripts.h"
#include "save.h"
#include "gpu_regs.h"
#include "scanline_effect.h"
#include "text_window.h"
#include "load_save.h"
#include "international_string_util.h"
2018-03-28 21:09:27 +02:00
#include "constants/songs.h"
#include "field_player_avatar.h"
2018-08-30 20:10:57 +02:00
#include "battle_pyramid_bag.h"
2017-09-05 13:01:24 +02:00
// Menu actions
enum
{
MENU_ACTION_POKEDEX,
MENU_ACTION_POKEMON,
MENU_ACTION_BAG,
MENU_ACTION_POKENAV,
MENU_ACTION_PLAYER,
MENU_ACTION_SAVE,
MENU_ACTION_OPTION,
MENU_ACTION_EXIT,
MENU_ACTION_RETIRE_SAFARI,
MENU_ACTION_PLAYER_LINK,
MENU_ACTION_REST_FRONTIER,
MENU_ACTION_RETIRE_FRONTIER,
MENU_ACTION_PYRAMID_BAG
};
2018-03-28 00:33:08 +02:00
// Save status
enum
{
SAVE_IN_PROGRESS,
SAVE_SUCCESS,
SAVE_CANCELED,
SAVE_ERROR
};
2018-03-28 15:45:35 +02:00
EWRAM_DATA static u8 sSafariBallsWindowId = 0;
EWRAM_DATA static u8 sBattlePyramidFloorWindowId = 0;
EWRAM_DATA static u8 sStartMenuCursorPos = 0;
EWRAM_DATA static u8 sNumStartMenuActions = 0;
EWRAM_DATA static u8 sCurrentStartMenuActions[9] = {0};
EWRAM_DATA static u8 sUnknown_02037619[2] = {0};
EWRAM_DATA static u8 (*sSaveDialogCallback)(void) = NULL;
EWRAM_DATA static u8 sSaveDialogTimer = 0;
EWRAM_DATA static bool8 sSavingComplete = FALSE;
2018-03-28 21:09:27 +02:00
EWRAM_DATA static u8 sSaveInfoWindowId = 0;
2018-03-28 00:33:08 +02:00
2018-08-30 20:10:57 +02:00
// Extern variables.
2018-03-28 00:33:08 +02:00
extern u8 gDifferentSaveFile;
extern u8 gUnknown_03005DB4;
2018-08-30 20:10:57 +02:00
// Extern functions in not decompiled files.
2018-03-28 00:33:08 +02:00
extern void sub_80AF688(void);
extern void var_800D_set_xB(void);
extern void sub_808B864(void);
extern void sub_80BB534(void);
extern void play_some_sound(void);
extern void CB2_PartyMenuFromStartMenu(void);
extern void CB2_PokeNav(void);
extern void sub_80C4DDC(void (*)(void));
extern void sub_80C51C4(void (*)(void));
2018-10-13 19:41:10 +02:00
extern void TrainerCard_ShowLinkCard(u8, void (*)(void));
extern void ScriptUnfreezeEventObjects(void);
2018-03-28 00:33:08 +02:00
extern void sub_81A9EC8(void);
extern void save_serialize_map(void);
extern void sub_81A9E90(void);
2018-03-28 15:45:35 +02:00
// Menu action callbacks
static bool8 StartMenuPokedexCallback(void);
static bool8 StartMenuPokemonCallback(void);
static bool8 StartMenuBagCallback(void);
static bool8 StartMenuPokeNavCallback(void);
static bool8 StartMenuPlayerNameCallback(void);
static bool8 StartMenuSaveCallback(void);
static bool8 StartMenuOptionCallback(void);
static bool8 StartMenuExitCallback(void);
static bool8 StartMenuSafariZoneRetireCallback(void);
static bool8 StartMenuLinkModePlayerNameCallback(void);
static bool8 StartMenuBattlePyramidRetireCallback(void);
static bool8 StartMenuBattlePyramidBagCallback(void);
// Menu callbacks
2018-03-28 21:09:27 +02:00
static bool8 SaveStartCallback(void);
static bool8 SaveCallback(void);
static bool8 BattlePyramidRetireStartCallback(void);
static bool8 BattlePyramidRetireReturnCallback(void);
static bool8 BattlePyramidRetireCallback(void);
2018-03-28 15:45:35 +02:00
static bool8 HandleStartMenuInput(void);
// Save dialog callbacks
2018-03-28 21:09:27 +02:00
static u8 SaveConfirmSaveCallback(void);
static u8 SaveYesNoCallback(void);
static u8 SaveConfirmInputCallback(void);
static u8 SaveFileExistsCallback(void);
static u8 SaveConfirmOverwriteNoCallback(void);
static u8 SaveConfirmOverwriteCallback(void);
static u8 SaveOverwriteInputCallback(void);
static u8 SaveSavingMessageCallback(void);
static u8 SaveDoSaveCallback(void);
static u8 SaveSuccessCallback(void);
static u8 SaveReturnSuccessCallback(void);
static u8 SaveErrorCallback(void);
static u8 SaveReturnErrorCallback(void);
static u8 BattlePyramidConfirmRetireCallback(void);
static u8 BattlePyramidRetireYesNoCallback(void);
static u8 BattlePyramidRetireInputCallback(void);
2018-03-28 15:45:35 +02:00
// Task callbacks
2018-03-28 21:09:27 +02:00
static void StartMenuTask(u8 taskId);
static void SaveGameTask(u8 taskId);
2018-03-28 15:45:35 +02:00
static void sub_80A0550(u8 taskId);
static void sub_80A08A4(u8 taskId);
2018-03-28 21:09:27 +02:00
// Some other callback
2018-03-28 15:45:35 +02:00
static bool8 sub_809FA00(void);
2018-03-29 02:16:02 +02:00
static const struct WindowTemplate sSafariBallsWindowTemplate = {0, 1, 1, 9, 4, 0xF, 8};
static const u8* const sPyramindFloorNames[] =
{
gText_Floor1,
gText_Floor2,
gText_Floor3,
gText_Floor4,
gText_Floor5,
gText_Floor6,
gText_Floor7,
gText_Peak
};
2018-03-29 02:16:02 +02:00
static const struct WindowTemplate sPyramidFloorWindowTemplate_2 = {0, 1, 1, 0xA, 4, 0xF, 8};
static const struct WindowTemplate sPyramidFloorWindowTemplate_1 = {0, 1, 1, 0xC, 4, 0xF, 8};
2018-03-29 02:16:02 +02:00
static const struct MenuAction sStartMenuItems[] =
{
2018-03-28 15:45:35 +02:00
{gText_MenuPokedex, {.u8_void = StartMenuPokedexCallback}},
{gText_MenuPokemon, {.u8_void = StartMenuPokemonCallback}},
{gText_MenuBag, {.u8_void = StartMenuBagCallback}},
{gText_MenuPokenav, {.u8_void = StartMenuPokeNavCallback}},
{gText_MenuPlayer, {.u8_void = StartMenuPlayerNameCallback}},
{gText_MenuSave, {.u8_void = StartMenuSaveCallback}},
{gText_MenuOption, {.u8_void = StartMenuOptionCallback}},
{gText_MenuExit, {.u8_void = StartMenuExitCallback}},
{gText_MenuRetire, {.u8_void = StartMenuSafariZoneRetireCallback}},
{gText_MenuPlayer, {.u8_void = StartMenuLinkModePlayerNameCallback}},
{gText_MenuRest, {.u8_void = StartMenuSaveCallback}},
{gText_MenuRetire, {.u8_void = StartMenuBattlePyramidRetireCallback}},
{gText_MenuBag, {.u8_void = StartMenuBattlePyramidBagCallback}}
};
2018-03-29 02:16:02 +02:00
static const struct BgTemplate sUnknown_085105A8[] =
{
{
.bg = 0,
.charBaseIndex = 2,
.mapBaseIndex = 31,
.screenSize = 0,
.paletteMode = 0,
.priority = 0,
.baseTile = 0
}
};
2018-03-29 02:16:02 +02:00
static const struct WindowTemplate sUnknown_085105AC[] =
{
{0, 2, 0xF, 0x1A, 4, 0xF, 0x194},
DUMMY_WIN_TEMPLATE
};
2018-03-29 02:16:02 +02:00
static const struct WindowTemplate sSaveInfoWindowTemplate = {0, 1, 1, 0xE, 0xA, 0xF, 8};
2018-03-28 21:09:27 +02:00
// Local functions
static void BuildStartMenuActions(void);
static void AddStartMenuAction(u8 action);
static void BuildNormalStartMenu(void);
static void BuildSafariZoneStartMenu(void);
static void BuildLinkModeStartMenu(void);
static void BuildUnionRoomStartMenu(void);
static void BuildBattlePikeStartMenu(void);
static void BuildBattlePyramidStartMenu(void);
static void BuildMultiBattleRoomStartMenu(void);
static void ShowSafariBallsWindow(void);
static void ShowPyramidFloorWindow(void);
2018-03-29 02:16:02 +02:00
static void RemoveExtraStartMenuWindows(void);
2018-03-28 21:09:27 +02:00
static bool32 PrintStartMenuActions(s8 *pIndex, u32 count);
static bool32 InitStartMenuStep(void);
static void InitStartMenu(void);
static void CreateStartMenuTask(TaskFunc followupFunc);
static void InitSave(void);
static u8 RunSaveCallback(void);
static void ShowSaveMessage(const u8 *message, u8 (*saveCallback)(void));
static void sub_80A0014(void);
static void HideSaveInfoWindow(void);
static void SaveStartTimer(void);
static bool8 SaveSuccesTimer(void);
static bool8 SaveErrorTimer(void);
static void InitBattlePyramidRetire(void);
static void sub_80A03D8(void);
static bool32 sub_80A03E4(u8 *par1);
static void sub_80A0540(void);
static void ShowSaveInfoWindow(void);
static void RemoveSaveInfoWindow(void);
static void HideStartMenuWindow(void);
2018-02-02 19:00:01 +01:00
void SetDexPokemonPokenavFlags(void) // unused
{
FlagSet(FLAG_SYS_POKEDEX_GET);
FlagSet(FLAG_SYS_POKEMON_GET);
FlagSet(FLAG_SYS_POKENAV_GET);
}
2018-03-28 15:45:35 +02:00
static void BuildStartMenuActions(void)
2017-09-05 13:01:24 +02:00
{
sNumStartMenuActions = 0;
2018-03-28 21:09:27 +02:00
2017-09-05 13:01:24 +02:00
if (is_c1_link_related_active() == TRUE)
2018-03-28 21:09:27 +02:00
{
2018-03-28 15:45:35 +02:00
BuildLinkModeStartMenu();
2018-03-28 21:09:27 +02:00
}
2017-09-05 13:01:24 +02:00
else if (InUnionRoom() == TRUE)
2018-03-28 21:09:27 +02:00
{
2018-03-28 15:45:35 +02:00
BuildUnionRoomStartMenu();
2018-03-28 21:09:27 +02:00
}
2017-09-05 13:01:24 +02:00
else if (GetSafariZoneFlag() == TRUE)
2018-03-28 21:09:27 +02:00
{
2018-03-28 15:45:35 +02:00
BuildSafariZoneStartMenu();
2018-03-28 21:09:27 +02:00
}
2017-09-05 13:01:24 +02:00
else if (InBattlePike())
2018-03-28 21:09:27 +02:00
{
2018-03-28 15:45:35 +02:00
BuildBattlePikeStartMenu();
2018-03-28 21:09:27 +02:00
}
2017-09-05 13:01:24 +02:00
else if (InBattlePyramid())
2018-03-28 21:09:27 +02:00
{
2018-03-28 15:45:35 +02:00
BuildBattlePyramidStartMenu();
2018-03-28 21:09:27 +02:00
}
2017-09-05 13:01:24 +02:00
else if (InMultiBattleRoom())
2018-03-28 21:09:27 +02:00
{
2018-03-28 15:45:35 +02:00
BuildMultiBattleRoomStartMenu();
2018-03-28 21:09:27 +02:00
}
2017-09-05 13:01:24 +02:00
else
2018-03-28 21:09:27 +02:00
{
2018-03-28 15:45:35 +02:00
BuildNormalStartMenu();
2018-03-28 21:09:27 +02:00
}
2017-09-05 13:01:24 +02:00
}
2018-03-28 15:45:35 +02:00
static void AddStartMenuAction(u8 action)
2017-09-05 13:01:24 +02:00
{
AppendToList(sCurrentStartMenuActions, &sNumStartMenuActions, action);
}
2018-03-28 15:45:35 +02:00
static void BuildNormalStartMenu(void)
2017-09-05 13:01:24 +02:00
{
2017-11-08 22:20:10 +01:00
if (FlagGet(FLAG_SYS_POKEDEX_GET) == TRUE)
2018-03-28 21:09:27 +02:00
{
2017-09-05 13:01:24 +02:00
AddStartMenuAction(MENU_ACTION_POKEDEX);
2018-03-28 21:09:27 +02:00
}
2017-11-08 22:20:10 +01:00
if (FlagGet(FLAG_SYS_POKEMON_GET) == TRUE)
2018-03-28 21:09:27 +02:00
{
2017-09-05 13:01:24 +02:00
AddStartMenuAction(MENU_ACTION_POKEMON);
2018-03-28 21:09:27 +02:00
}
2017-09-05 13:01:24 +02:00
AddStartMenuAction(MENU_ACTION_BAG);
2018-03-28 21:09:27 +02:00
2017-11-08 22:20:10 +01:00
if (FlagGet(FLAG_SYS_POKENAV_GET) == TRUE)
2018-03-28 21:09:27 +02:00
{
2017-09-05 13:01:24 +02:00
AddStartMenuAction(MENU_ACTION_POKENAV);
2018-03-28 21:09:27 +02:00
}
2017-09-05 13:01:24 +02:00
AddStartMenuAction(MENU_ACTION_PLAYER);
AddStartMenuAction(MENU_ACTION_SAVE);
AddStartMenuAction(MENU_ACTION_OPTION);
AddStartMenuAction(MENU_ACTION_EXIT);
}
2018-03-28 15:45:35 +02:00
static void BuildSafariZoneStartMenu(void)
2017-09-05 13:01:24 +02:00
{
AddStartMenuAction(MENU_ACTION_RETIRE_SAFARI);
AddStartMenuAction(MENU_ACTION_POKEDEX);
AddStartMenuAction(MENU_ACTION_POKEMON);
AddStartMenuAction(MENU_ACTION_BAG);
AddStartMenuAction(MENU_ACTION_PLAYER);
AddStartMenuAction(MENU_ACTION_OPTION);
AddStartMenuAction(MENU_ACTION_EXIT);
}
2018-03-28 15:45:35 +02:00
static void BuildLinkModeStartMenu(void)
2017-09-05 13:01:24 +02:00
{
AddStartMenuAction(MENU_ACTION_POKEMON);
AddStartMenuAction(MENU_ACTION_BAG);
2018-03-28 21:09:27 +02:00
2017-11-08 22:20:10 +01:00
if (FlagGet(FLAG_SYS_POKENAV_GET) == TRUE)
2018-03-28 21:09:27 +02:00
{
2017-09-05 13:01:24 +02:00
AddStartMenuAction(MENU_ACTION_POKENAV);
2018-03-28 21:09:27 +02:00
}
2017-09-05 13:01:24 +02:00
AddStartMenuAction(MENU_ACTION_PLAYER_LINK);
AddStartMenuAction(MENU_ACTION_OPTION);
AddStartMenuAction(MENU_ACTION_EXIT);
}
2018-03-28 15:45:35 +02:00
static void BuildUnionRoomStartMenu(void)
2017-09-05 13:01:24 +02:00
{
AddStartMenuAction(MENU_ACTION_POKEMON);
AddStartMenuAction(MENU_ACTION_BAG);
2018-03-28 21:09:27 +02:00
2017-11-08 22:20:10 +01:00
if (FlagGet(FLAG_SYS_POKENAV_GET) == TRUE)
2018-03-28 21:09:27 +02:00
{
2017-09-05 13:01:24 +02:00
AddStartMenuAction(MENU_ACTION_POKENAV);
2018-03-28 21:09:27 +02:00
}
2017-09-05 13:01:24 +02:00
AddStartMenuAction(MENU_ACTION_PLAYER);
AddStartMenuAction(MENU_ACTION_OPTION);
AddStartMenuAction(MENU_ACTION_EXIT);
}
2018-03-28 15:45:35 +02:00
static void BuildBattlePikeStartMenu(void)
2017-09-05 13:01:24 +02:00
{
AddStartMenuAction(MENU_ACTION_POKEDEX);
AddStartMenuAction(MENU_ACTION_POKEMON);
AddStartMenuAction(MENU_ACTION_PLAYER);
AddStartMenuAction(MENU_ACTION_OPTION);
AddStartMenuAction(MENU_ACTION_EXIT);
}
2018-03-28 15:45:35 +02:00
static void BuildBattlePyramidStartMenu(void)
2017-09-05 13:01:24 +02:00
{
AddStartMenuAction(MENU_ACTION_POKEMON);
AddStartMenuAction(MENU_ACTION_PYRAMID_BAG);
AddStartMenuAction(MENU_ACTION_PLAYER);
AddStartMenuAction(MENU_ACTION_REST_FRONTIER);
AddStartMenuAction(MENU_ACTION_RETIRE_FRONTIER);
AddStartMenuAction(MENU_ACTION_OPTION);
AddStartMenuAction(MENU_ACTION_EXIT);
}
2018-03-28 15:45:35 +02:00
static void BuildMultiBattleRoomStartMenu(void)
2017-09-05 13:01:24 +02:00
{
AddStartMenuAction(MENU_ACTION_POKEMON);
AddStartMenuAction(MENU_ACTION_PLAYER);
AddStartMenuAction(MENU_ACTION_OPTION);
AddStartMenuAction(MENU_ACTION_EXIT);
}
2018-03-28 21:09:27 +02:00
static void ShowSafariBallsWindow(void)
2017-09-05 13:01:24 +02:00
{
2018-03-29 02:16:02 +02:00
sSafariBallsWindowId = AddWindow(&sSafariBallsWindowTemplate);
2017-09-05 13:01:24 +02:00
PutWindowTilemap(sSafariBallsWindowId);
2018-03-28 15:45:35 +02:00
NewMenuHelpers_DrawStdWindowFrame(sSafariBallsWindowId, FALSE);
2017-09-05 13:01:24 +02:00
ConvertIntToDecimalStringN(gStringVar1, gNumSafariBalls, STR_CONV_MODE_RIGHT_ALIGN, 2);
2017-09-20 21:38:05 +02:00
StringExpandPlaceholders(gStringVar4, gText_SafariBallStock);
AddTextPrinterParameterized(sSafariBallsWindowId, 1, gStringVar4, 0, 1, 0xFF, NULL);
2017-09-05 13:01:24 +02:00
CopyWindowToVram(sSafariBallsWindowId, 2);
}
2018-03-28 21:09:27 +02:00
static void ShowPyramidFloorWindow(void)
2017-09-05 13:01:24 +02:00
{
2018-10-21 00:06:42 +02:00
if (gSaveBlock2Ptr->frontier.curChallengeBattleNum == 7)
2018-03-29 02:16:02 +02:00
sBattlePyramidFloorWindowId = AddWindow(&sPyramidFloorWindowTemplate_1);
2017-09-05 13:01:24 +02:00
else
2018-03-29 02:16:02 +02:00
sBattlePyramidFloorWindowId = AddWindow(&sPyramidFloorWindowTemplate_2);
2018-03-28 15:45:35 +02:00
2017-09-05 13:01:24 +02:00
PutWindowTilemap(sBattlePyramidFloorWindowId);
2018-03-28 15:45:35 +02:00
NewMenuHelpers_DrawStdWindowFrame(sBattlePyramidFloorWindowId, FALSE);
2018-10-21 00:06:42 +02:00
StringCopy(gStringVar1, sPyramindFloorNames[gSaveBlock2Ptr->frontier.curChallengeBattleNum]);
2017-09-20 21:38:05 +02:00
StringExpandPlaceholders(gStringVar4, gText_BattlePyramidFloor);
AddTextPrinterParameterized(sBattlePyramidFloorWindowId, 1, gStringVar4, 0, 1, 0xFF, NULL);
2017-09-05 13:01:24 +02:00
CopyWindowToVram(sBattlePyramidFloorWindowId, 2);
}
2018-03-29 02:16:02 +02:00
static void RemoveExtraStartMenuWindows(void)
2017-09-05 13:01:24 +02:00
{
if (GetSafariZoneFlag())
{
2018-03-28 15:45:35 +02:00
sub_8198070(sSafariBallsWindowId, FALSE);
2017-09-05 13:01:24 +02:00
CopyWindowToVram(sSafariBallsWindowId, 2);
RemoveWindow(sSafariBallsWindowId);
}
if (InBattlePyramid())
{
2018-03-28 15:45:35 +02:00
sub_8198070(sBattlePyramidFloorWindowId, FALSE);
2017-09-05 13:01:24 +02:00
RemoveWindow(sBattlePyramidFloorWindowId);
}
}
2018-03-28 15:45:35 +02:00
static bool32 PrintStartMenuActions(s8 *pIndex, u32 count)
2017-09-05 13:01:24 +02:00
{
2018-03-28 00:33:08 +02:00
s8 index = *pIndex;
2017-09-05 13:01:24 +02:00
do
{
2018-03-28 15:45:35 +02:00
if (sStartMenuItems[sCurrentStartMenuActions[index]].func.u8_void == StartMenuPlayerNameCallback) {
2018-03-28 00:33:08 +02:00
PrintPlayerNameOnWindow(GetStartMenuWindowId(), sStartMenuItems[sCurrentStartMenuActions[index]].text, 8, (index << 4) + 9);
}
else {
StringExpandPlaceholders(gStringVar4, sStartMenuItems[sCurrentStartMenuActions[index]].text);
AddTextPrinterParameterized(GetStartMenuWindowId(), 1, gStringVar4, 8, (index << 4) + 9, 0xFF, NULL);
2018-03-28 00:33:08 +02:00
}
index++;
if (index >= sNumStartMenuActions) {
*pIndex = index;
return TRUE;
}
count--;
}
while (count != 0);
*pIndex = index;
return FALSE;
}
static bool32 InitStartMenuStep(void)
2018-03-28 00:33:08 +02:00
{
2018-03-28 15:45:35 +02:00
s8 value = sUnknown_02037619[0];
2018-03-28 21:09:27 +02:00
switch (value)
2018-03-28 00:33:08 +02:00
{
case 0:
2018-03-28 15:45:35 +02:00
sUnknown_02037619[0]++;
2018-03-28 00:33:08 +02:00
break;
case 1:
BuildStartMenuActions();
2018-03-28 15:45:35 +02:00
sUnknown_02037619[0]++;
2018-03-28 00:33:08 +02:00
break;
case 2:
sub_81973A4();
NewMenuHelpers_DrawStdWindowFrame(sub_81979C4(sNumStartMenuActions), FALSE);
2018-03-28 15:45:35 +02:00
sUnknown_02037619[1] = 0;
sUnknown_02037619[0]++;
2018-03-28 00:33:08 +02:00
break;
case 3:
if (GetSafariZoneFlag() != FALSE)
2017-09-05 13:01:24 +02:00
{
2018-03-28 21:09:27 +02:00
ShowSafariBallsWindow();
2018-03-28 00:33:08 +02:00
}
if (InBattlePyramid() != FALSE)
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
ShowPyramidFloorWindow();
2018-03-28 00:33:08 +02:00
}
2018-03-28 15:45:35 +02:00
sUnknown_02037619[0]++;
2018-03-28 00:33:08 +02:00
break;
case 4:
if (PrintStartMenuActions(&sUnknown_02037619[1], 2) == FALSE)
2018-03-28 00:33:08 +02:00
{
break;
}
2018-03-28 15:45:35 +02:00
sUnknown_02037619[0]++;
2018-03-28 00:33:08 +02:00
break;
case 5:
sStartMenuCursorPos = sub_81983AC(GetStartMenuWindowId(), 1, 0, 9, 16, sNumStartMenuActions, sStartMenuCursorPos);
CopyWindowToVram(GetStartMenuWindowId(), TRUE);
return TRUE;
}
return FALSE;
}
2018-03-28 15:45:35 +02:00
static void InitStartMenu(void)
2018-03-28 00:33:08 +02:00
{
2018-03-28 15:45:35 +02:00
sUnknown_02037619[0] = 0;
sUnknown_02037619[1] = 0;
2018-03-28 21:09:27 +02:00
while (!InitStartMenuStep());
2018-03-28 00:33:08 +02:00
}
2018-03-28 21:09:27 +02:00
static void StartMenuTask(u8 taskId)
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
if (InitStartMenuStep() == TRUE)
2018-03-28 00:33:08 +02:00
{
SwitchTaskToFollowupFunc(taskId);
}
}
2018-03-28 21:09:27 +02:00
static void CreateStartMenuTask(TaskFunc followupFunc)
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
u8 taskId;
2018-03-28 15:45:35 +02:00
sUnknown_02037619[0] = 0;
sUnknown_02037619[1] = 0;
2018-03-28 21:09:27 +02:00
taskId = CreateTask(StartMenuTask, 0x50);
SetTaskFuncWithFollowupFunc(taskId, StartMenuTask, followupFunc);
2018-03-28 00:33:08 +02:00
}
static bool8 sub_809FA00(void)
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
if (InitStartMenuStep() == FALSE)
2018-03-28 00:33:08 +02:00
{
return FALSE;
}
sub_80AF688();
return TRUE;
}
2018-03-28 15:45:35 +02:00
void sub_809FA18(void) // Called from field_screen.s
2018-03-28 00:33:08 +02:00
{
2018-03-28 15:45:35 +02:00
sUnknown_02037619[0] = 0;
sUnknown_02037619[1] = 0;
2018-06-16 00:45:48 +02:00
gFieldCallback2 = sub_809FA00;
2018-03-28 00:33:08 +02:00
}
2017-09-05 13:01:24 +02:00
2018-03-28 21:09:27 +02:00
void sub_809FA34(u8 taskId) // Referenced in field_screen.s and rom_8011DC0.s
2018-03-28 00:33:08 +02:00
{
struct Task* task = &gTasks[taskId];
switch(task->data[0])
2018-03-28 00:33:08 +02:00
{
case 0:
if (InUnionRoom() == TRUE)
{
var_800D_set_xB();
2017-09-05 13:01:24 +02:00
}
2018-03-28 00:33:08 +02:00
gMenuCallback = HandleStartMenuInput;
task->data[0]++;
break;
case 1:
if (gMenuCallback() == TRUE)
2017-09-05 13:01:24 +02:00
{
2018-03-28 00:33:08 +02:00
DestroyTask(taskId);
}
break;
}
}
2018-03-28 21:09:27 +02:00
void ShowStartMenu(void) // Called from overworld.c and field_control_avatar.s
2018-03-28 00:33:08 +02:00
{
if (!is_c1_link_related_active())
{
FreezeEventObjects();
2018-03-28 00:33:08 +02:00
sub_808B864();
sub_808BCF4();
}
2018-03-28 21:09:27 +02:00
CreateStartMenuTask(sub_809FA34);
2018-03-28 00:33:08 +02:00
ScriptContext2_Enable();
}
2017-09-05 13:01:24 +02:00
2018-03-28 15:45:35 +02:00
static bool8 HandleStartMenuInput(void)
2018-03-28 00:33:08 +02:00
{
if (gMain.newKeys & DPAD_UP)
{
2018-03-28 21:09:27 +02:00
PlaySE(SE_SELECT);
2018-03-28 00:33:08 +02:00
sStartMenuCursorPos = MoveMenuCursor(-1);
}
2018-03-28 00:33:08 +02:00
if (gMain.newKeys & DPAD_DOWN)
{
2018-03-28 21:09:27 +02:00
PlaySE(SE_SELECT);
2018-03-28 00:33:08 +02:00
sStartMenuCursorPos = MoveMenuCursor(1);
}
2018-03-28 00:33:08 +02:00
if (gMain.newKeys & A_BUTTON)
{
2018-03-28 21:09:27 +02:00
PlaySE(SE_SELECT);
2018-03-28 15:45:35 +02:00
if (sStartMenuItems[sCurrentStartMenuActions[sStartMenuCursorPos]].func.u8_void == StartMenuPokedexCallback)
2018-03-28 00:33:08 +02:00
{
2018-03-28 15:45:35 +02:00
if (GetNationalPokedexCount(0) == 0) {
2018-03-28 00:33:08 +02:00
return FALSE;
}
}
2018-03-28 00:33:08 +02:00
gMenuCallback = sStartMenuItems[sCurrentStartMenuActions[sStartMenuCursorPos]].func.u8_void;
if (gMenuCallback != StartMenuSaveCallback
2018-03-28 15:45:35 +02:00
&& gMenuCallback != StartMenuExitCallback
&& gMenuCallback != StartMenuSafariZoneRetireCallback
&& gMenuCallback != StartMenuBattlePyramidRetireCallback)
2018-03-28 00:33:08 +02:00
{
FadeScreen(1, 0);
2017-09-05 13:01:24 +02:00
}
2018-03-28 00:33:08 +02:00
return FALSE;
}
2018-03-28 00:33:08 +02:00
if (gMain.newKeys & (START_BUTTON | B_BUTTON))
{
2018-03-29 02:16:02 +02:00
RemoveExtraStartMenuWindows();
2018-03-28 21:09:27 +02:00
HideStartMenu();
2018-03-28 00:33:08 +02:00
return TRUE;
}
return FALSE;
}
2018-03-28 15:45:35 +02:00
static bool8 StartMenuPokedexCallback(void)
2018-03-28 00:33:08 +02:00
{
if (!gPaletteFade.active)
{
IncrementGameStat(GAME_STAT_CHECKED_POKEDEX);
play_some_sound();
2018-03-29 02:16:02 +02:00
RemoveExtraStartMenuWindows();
2018-03-28 00:33:08 +02:00
overworld_free_bg_tilemaps();
2018-03-28 21:09:27 +02:00
SetMainCallback2(sub_80BB534); // Display pokedex
2018-03-28 00:33:08 +02:00
return TRUE;
}
2018-03-28 00:33:08 +02:00
return FALSE;
}
2017-09-05 13:01:24 +02:00
2018-03-28 15:45:35 +02:00
static bool8 StartMenuPokemonCallback(void)
2018-03-28 00:33:08 +02:00
{
if (!gPaletteFade.active)
{
play_some_sound();
2018-03-29 02:16:02 +02:00
RemoveExtraStartMenuWindows();
2018-03-28 00:33:08 +02:00
overworld_free_bg_tilemaps();
2018-03-28 21:09:27 +02:00
SetMainCallback2(CB2_PartyMenuFromStartMenu); // Display party menu
2018-03-28 00:33:08 +02:00
return TRUE;
}
2017-09-05 13:01:24 +02:00
2018-03-28 00:33:08 +02:00
return FALSE;
}
2018-03-28 15:45:35 +02:00
static bool8 StartMenuBagCallback(void)
2018-03-28 00:33:08 +02:00
{
if (!gPaletteFade.active)
2017-09-05 13:01:24 +02:00
{
2018-03-28 00:33:08 +02:00
play_some_sound();
2018-03-29 02:16:02 +02:00
RemoveExtraStartMenuWindows();
2018-03-28 00:33:08 +02:00
overworld_free_bg_tilemaps();
2018-03-28 21:09:27 +02:00
SetMainCallback2(CB2_BagMenuFromStartMenu); // Display bag menu
2018-03-28 00:33:08 +02:00
return TRUE;
}
return FALSE;
}
2018-03-28 15:45:35 +02:00
static bool8 StartMenuPokeNavCallback(void)
2018-03-28 00:33:08 +02:00
{
if (!gPaletteFade.active)
{
play_some_sound();
2018-03-29 02:16:02 +02:00
RemoveExtraStartMenuWindows();
2018-03-28 00:33:08 +02:00
overworld_free_bg_tilemaps();
2018-03-28 21:09:27 +02:00
SetMainCallback2(CB2_PokeNav); // Display PokeNav
2018-03-28 00:33:08 +02:00
return TRUE;
}
return FALSE;
}
2018-03-28 15:45:35 +02:00
static bool8 StartMenuPlayerNameCallback(void)
2018-03-28 00:33:08 +02:00
{
if (!gPaletteFade.active)
{
play_some_sound();
2018-03-29 02:16:02 +02:00
RemoveExtraStartMenuWindows();
2018-03-28 00:33:08 +02:00
overworld_free_bg_tilemaps();
if (is_c1_link_related_active() || InUnionRoom())
{
2018-03-28 21:09:27 +02:00
sub_80C4DDC(CB2_ReturnToFieldWithOpenMenu); // Display trainer card
2018-03-28 00:33:08 +02:00
}
else if (FlagGet(FLAG_SYS_FRONTIER_PASS))
{
2018-03-28 21:09:27 +02:00
sub_80C51C4(CB2_ReturnToFieldWithOpenMenu); // Display frontier pass
2018-03-28 00:33:08 +02:00
}
else
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
sub_80C4DDC(CB2_ReturnToFieldWithOpenMenu); // Display trainer card
2018-03-28 00:33:08 +02:00
}
return TRUE;
}
return FALSE;
}
2018-03-28 15:45:35 +02:00
static bool8 StartMenuSaveCallback(void)
2018-03-28 00:33:08 +02:00
{
if (InBattlePyramid())
{
2018-03-29 02:16:02 +02:00
RemoveExtraStartMenuWindows();
2018-03-28 00:33:08 +02:00
}
2018-03-28 21:09:27 +02:00
gMenuCallback = SaveStartCallback; // Display save menu
2018-03-28 00:33:08 +02:00
return FALSE;
}
2018-03-28 15:45:35 +02:00
static bool8 StartMenuOptionCallback(void)
2018-03-28 00:33:08 +02:00
{
if (!gPaletteFade.active)
{
play_some_sound();
2018-03-29 02:16:02 +02:00
RemoveExtraStartMenuWindows();
2018-03-28 00:33:08 +02:00
overworld_free_bg_tilemaps();
2018-03-28 21:09:27 +02:00
SetMainCallback2(CB2_InitOptionMenu); // Display option menu
2018-03-28 00:33:08 +02:00
gMain.savedCallback = CB2_ReturnToFieldWithOpenMenu;
return TRUE;
}
return FALSE;
}
2018-03-28 15:45:35 +02:00
static bool8 StartMenuExitCallback(void)
2018-03-28 00:33:08 +02:00
{
2018-03-29 02:16:02 +02:00
RemoveExtraStartMenuWindows();
2018-03-28 21:09:27 +02:00
HideStartMenu(); // Hide start menu
2018-03-28 00:33:08 +02:00
return TRUE;
}
2018-03-28 15:45:35 +02:00
static bool8 StartMenuSafariZoneRetireCallback(void)
2018-03-28 00:33:08 +02:00
{
2018-03-29 02:16:02 +02:00
RemoveExtraStartMenuWindows();
2018-03-28 21:09:27 +02:00
HideStartMenu();
2018-03-28 00:33:08 +02:00
SafariZoneRetirePrompt();
return TRUE;
}
2018-03-28 15:45:35 +02:00
static bool8 StartMenuLinkModePlayerNameCallback(void)
2018-03-28 00:33:08 +02:00
{
if (!gPaletteFade.active)
{
play_some_sound();
overworld_free_bg_tilemaps();
2018-10-13 19:41:10 +02:00
TrainerCard_ShowLinkCard(gUnknown_03005DB4, CB2_ReturnToFieldWithOpenMenu);
2018-03-28 00:33:08 +02:00
return TRUE;
}
return FALSE;
}
2018-03-28 15:45:35 +02:00
static bool8 StartMenuBattlePyramidRetireCallback(void)
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
gMenuCallback = BattlePyramidRetireStartCallback; // Confirm retire
2018-03-28 00:33:08 +02:00
return FALSE;
}
2018-03-28 15:45:35 +02:00
void sub_809FDD4(void) // Called from battle_frontier_2.s
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
sub_8197DF8(0, FALSE);
ScriptUnfreezeEventObjects();
2018-03-28 21:09:27 +02:00
CreateStartMenuTask(sub_809FA34);
2018-03-28 00:33:08 +02:00
ScriptContext2_Enable();
}
2018-03-28 15:45:35 +02:00
static bool8 StartMenuBattlePyramidBagCallback(void)
2018-03-28 00:33:08 +02:00
{
if (!gPaletteFade.active)
{
play_some_sound();
2018-03-29 02:16:02 +02:00
RemoveExtraStartMenuWindows();
2018-03-28 00:33:08 +02:00
overworld_free_bg_tilemaps();
2018-08-30 20:10:57 +02:00
SetMainCallback2(CB2_PyramidBagMenuFromStartMenu);
2018-03-28 00:33:08 +02:00
return TRUE;
}
return FALSE;
}
2018-03-28 21:09:27 +02:00
static bool8 SaveStartCallback(void)
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
InitSave();
gMenuCallback = SaveCallback;
2018-03-28 00:33:08 +02:00
return FALSE;
}
2018-03-28 21:09:27 +02:00
static bool8 SaveCallback(void)
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
switch (RunSaveCallback())
2018-03-28 00:33:08 +02:00
{
case SAVE_IN_PROGRESS:
2017-09-05 13:01:24 +02:00
return FALSE;
2018-03-28 21:09:27 +02:00
case SAVE_CANCELED: // Back to start menu
sub_8197DF8(0, FALSE);
2018-03-28 00:33:08 +02:00
InitStartMenu();
gMenuCallback = HandleStartMenuInput;
return FALSE;
case SAVE_SUCCESS:
2018-03-28 21:09:27 +02:00
case SAVE_ERROR: // Close start menu
sub_8197DF8(0, TRUE);
ScriptUnfreezeEventObjects();
2018-03-28 00:33:08 +02:00
ScriptContext2_Disable();
sub_81A9EC8();
return TRUE;
}
return FALSE;
}
2018-03-28 21:09:27 +02:00
static bool8 BattlePyramidRetireStartCallback(void)
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
InitBattlePyramidRetire();
gMenuCallback = BattlePyramidRetireCallback;
2018-03-28 00:33:08 +02:00
return FALSE;
}
2018-03-28 21:09:27 +02:00
static bool8 BattlePyramidRetireReturnCallback(void)
2018-03-28 00:33:08 +02:00
{
InitStartMenu();
gMenuCallback = HandleStartMenuInput;
return FALSE;
}
2018-03-28 21:09:27 +02:00
static bool8 BattlePyramidRetireCallback(void)
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
switch (RunSaveCallback())
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
case SAVE_SUCCESS: // No (Stay in battle pyramid)
2018-03-29 02:16:02 +02:00
RemoveExtraStartMenuWindows();
2018-03-28 21:09:27 +02:00
gMenuCallback = BattlePyramidRetireReturnCallback;
2018-03-28 00:33:08 +02:00
return FALSE;
case SAVE_IN_PROGRESS:
return FALSE;
2018-03-28 21:09:27 +02:00
case SAVE_CANCELED: // Yes (Retire from battle pyramid)
sub_8197DF8(0, TRUE);
ScriptUnfreezeEventObjects();
2018-03-28 00:33:08 +02:00
ScriptContext2_Disable();
ScriptContext1_SetupScript(BattleFrontier_BattlePyramidEmptySquare_EventScript_252C88);
return TRUE;
}
return FALSE;
}
2018-03-28 21:09:27 +02:00
static void InitSave(void)
2018-03-28 00:33:08 +02:00
{
save_serialize_map();
2018-03-28 21:09:27 +02:00
sSaveDialogCallback = SaveConfirmSaveCallback;
2018-03-28 15:45:35 +02:00
sSavingComplete = FALSE;
2018-03-28 00:33:08 +02:00
}
2018-03-28 21:09:27 +02:00
static u8 RunSaveCallback(void)
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
// True if text is still printing
2018-09-14 19:15:46 +02:00
if (RunTextPrintersAndIsPrinter0Active() == TRUE)
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
return SAVE_IN_PROGRESS;
2018-03-28 00:33:08 +02:00
}
2018-03-28 15:45:35 +02:00
sSavingComplete = FALSE;
return sSaveDialogCallback();
2018-03-28 00:33:08 +02:00
}
2018-03-28 21:09:27 +02:00
void SaveGame(void) // Called from cable_club.s
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
InitSave();
CreateTask(SaveGameTask, 0x50);
2018-03-28 00:33:08 +02:00
}
2018-03-28 21:09:27 +02:00
static void ShowSaveMessage(const u8 *message, u8 (*saveCallback)(void))
2018-03-28 00:33:08 +02:00
{
StringExpandPlaceholders(gStringVar4, message);
sub_819786C(0, TRUE);
AddTextPrinterForMessage_2(TRUE);
2018-03-28 15:45:35 +02:00
sSavingComplete = TRUE;
sSaveDialogCallback = saveCallback;
2018-03-28 00:33:08 +02:00
}
2018-03-28 21:09:27 +02:00
static void SaveGameTask(u8 taskId)
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
u8 status = RunSaveCallback();
2018-03-28 00:33:08 +02:00
switch (status)
{
case SAVE_CANCELED:
case SAVE_ERROR:
gSpecialVar_Result = 0;
break;
case SAVE_SUCCESS:
gSpecialVar_Result = status;
break;
case SAVE_IN_PROGRESS:
return;
}
2018-03-28 00:33:08 +02:00
DestroyTask(taskId);
EnableBothScriptContexts();
}
2018-03-28 15:45:35 +02:00
static void sub_80A0014(void)
2018-03-28 00:33:08 +02:00
{
sub_8197434(0, TRUE);
}
2018-03-28 21:09:27 +02:00
static void HideSaveInfoWindow(void)
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
RemoveSaveInfoWindow();
2018-03-28 00:33:08 +02:00
}
2018-03-28 21:09:27 +02:00
static void SaveStartTimer(void)
2018-03-28 00:33:08 +02:00
{
2018-03-28 15:45:35 +02:00
sSaveDialogTimer = 60;
2018-03-28 00:33:08 +02:00
}
2018-03-28 21:09:27 +02:00
static bool8 SaveSuccesTimer(void)
2018-03-28 00:33:08 +02:00
{
2018-03-28 15:45:35 +02:00
sSaveDialogTimer--;
2018-03-28 00:33:08 +02:00
if (gMain.heldKeys & A_BUTTON)
{
2018-03-28 21:09:27 +02:00
PlaySE(SE_SELECT);
2018-03-28 00:33:08 +02:00
return TRUE;
}
2018-03-28 15:45:35 +02:00
else if (sSaveDialogTimer == 0)
2018-03-28 00:33:08 +02:00
{
return TRUE;
}
return FALSE;
}
2018-03-28 21:09:27 +02:00
static bool8 SaveErrorTimer(void)
2018-03-28 00:33:08 +02:00
{
2018-03-28 15:45:35 +02:00
if (sSaveDialogTimer != 0)
2018-03-28 00:33:08 +02:00
{
2018-03-28 15:45:35 +02:00
sSaveDialogTimer--;
2018-03-28 00:33:08 +02:00
}
else if (gMain.heldKeys & A_BUTTON)
{
return TRUE;
}
return FALSE;
}
2018-03-28 21:09:27 +02:00
static u8 SaveConfirmSaveCallback(void)
2018-03-28 00:33:08 +02:00
{
sub_819746C(GetStartMenuWindowId(), FALSE);
2018-03-29 02:16:02 +02:00
RemoveStartMenuWindow();
2018-03-28 21:09:27 +02:00
ShowSaveInfoWindow();
2018-03-28 00:33:08 +02:00
if (InBattlePyramid())
{
2018-03-28 21:09:27 +02:00
ShowSaveMessage(gText_BattlePyramidConfirmRest, SaveYesNoCallback);
2018-03-28 00:33:08 +02:00
}
else
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
ShowSaveMessage(gText_ConfirmSave, SaveYesNoCallback);
2018-03-28 00:33:08 +02:00
}
2018-03-28 15:45:35 +02:00
return SAVE_IN_PROGRESS;
2018-03-28 00:33:08 +02:00
}
2018-03-28 21:09:27 +02:00
static u8 SaveYesNoCallback(void)
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
sub_8197930(); // Show Yes/No menu
sSaveDialogCallback = SaveConfirmInputCallback;
2018-03-28 15:45:35 +02:00
return SAVE_IN_PROGRESS;
2018-03-28 00:33:08 +02:00
}
2018-03-28 21:09:27 +02:00
static u8 SaveConfirmInputCallback(void)
2018-03-28 00:33:08 +02:00
{
2018-08-12 21:54:07 +02:00
switch (Menu_ProcessInputNoWrap_())
2018-03-28 00:33:08 +02:00
{
case 0: // Yes
switch (gSaveFileStatus)
{
case 0:
case 2:
if (gDifferentSaveFile == FALSE)
{
2018-03-28 21:09:27 +02:00
sSaveDialogCallback = SaveFileExistsCallback;
2018-03-28 00:33:08 +02:00
return SAVE_IN_PROGRESS;
}
2018-03-28 21:09:27 +02:00
sSaveDialogCallback = SaveSavingMessageCallback;
2018-03-28 00:33:08 +02:00
return SAVE_IN_PROGRESS;
default:
2018-03-28 21:09:27 +02:00
sSaveDialogCallback = SaveFileExistsCallback;
2018-03-28 00:33:08 +02:00
return SAVE_IN_PROGRESS;
}
case -1: // B Button
case 1: // No
2018-03-28 21:09:27 +02:00
HideSaveInfoWindow();
2018-03-28 00:33:08 +02:00
sub_80A0014();
return SAVE_CANCELED;
}
return SAVE_IN_PROGRESS;
}
// A different save file exists
2018-03-28 21:09:27 +02:00
static u8 SaveFileExistsCallback(void)
2018-03-28 00:33:08 +02:00
{
if (gDifferentSaveFile == TRUE)
{
2018-03-28 21:09:27 +02:00
ShowSaveMessage(gText_DifferentSaveFile, SaveConfirmOverwriteNoCallback);
2018-03-28 00:33:08 +02:00
}
else
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
ShowSaveMessage(gText_AlreadySavedFile, SaveConfirmOverwriteCallback);
2018-03-28 00:33:08 +02:00
}
return SAVE_IN_PROGRESS;
}
2018-03-28 21:09:27 +02:00
static u8 SaveConfirmOverwriteNoCallback(void)
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
sub_8197948(1); // Show Yes/No menu (No selected as default)
sSaveDialogCallback = SaveOverwriteInputCallback;
2018-03-28 00:33:08 +02:00
return SAVE_IN_PROGRESS;
}
2018-03-28 21:09:27 +02:00
static u8 SaveConfirmOverwriteCallback(void)
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
sub_8197930(); // Show Yes/No menu
sSaveDialogCallback = SaveOverwriteInputCallback;
2018-03-28 00:33:08 +02:00
return SAVE_IN_PROGRESS;
}
2018-03-28 21:09:27 +02:00
static u8 SaveOverwriteInputCallback(void)
2018-03-28 00:33:08 +02:00
{
2018-08-12 21:54:07 +02:00
switch (Menu_ProcessInputNoWrap_())
2018-03-28 00:33:08 +02:00
{
case 0: // Yes
2018-03-28 21:09:27 +02:00
sSaveDialogCallback = SaveSavingMessageCallback;
2018-03-28 00:33:08 +02:00
return SAVE_IN_PROGRESS;
case -1: // B Button
case 1: // No
2018-03-28 21:09:27 +02:00
HideSaveInfoWindow();
2018-03-28 00:33:08 +02:00
sub_80A0014();
return SAVE_CANCELED;
}
return SAVE_IN_PROGRESS;
}
2018-03-28 21:09:27 +02:00
static u8 SaveSavingMessageCallback(void)
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
ShowSaveMessage(gText_SavingDontTurnOff, SaveDoSaveCallback);
2018-03-28 00:33:08 +02:00
return SAVE_IN_PROGRESS;
}
2018-03-28 21:09:27 +02:00
static u8 SaveDoSaveCallback(void)
2018-03-28 00:33:08 +02:00
{
u8 saveStatus;
IncrementGameStat(GAME_STAT_SAVED_GAME);
sub_81A9E90();
if (gDifferentSaveFile == TRUE)
{
saveStatus = TrySavingData(SAVE_OVERWRITE_DIFFERENT_FILE);
gDifferentSaveFile = FALSE;
}
else
2018-03-28 00:33:08 +02:00
{
saveStatus = TrySavingData(SAVE_NORMAL);
}
if (saveStatus == 1) // Save succeded
{
2018-03-28 21:09:27 +02:00
ShowSaveMessage(gText_PlayerSavedGame, SaveSuccessCallback);
2018-03-28 00:33:08 +02:00
}
2018-03-28 21:09:27 +02:00
else // Save error
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
ShowSaveMessage(gText_SaveError, SaveErrorCallback);
2018-03-28 00:33:08 +02:00
}
2018-03-28 21:09:27 +02:00
SaveStartTimer();
2018-03-28 00:33:08 +02:00
return SAVE_IN_PROGRESS;
}
2018-03-28 21:09:27 +02:00
static u8 SaveSuccessCallback(void)
2018-03-28 00:33:08 +02:00
{
if (!IsTextPrinterActive(0))
{
2018-03-28 21:09:27 +02:00
PlaySE(SE_SAVE);
sSaveDialogCallback = SaveReturnSuccessCallback;
2018-03-28 00:33:08 +02:00
}
return SAVE_IN_PROGRESS;
}
2018-03-28 21:09:27 +02:00
static u8 SaveReturnSuccessCallback(void)
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
if (!IsSEPlaying() && SaveSuccesTimer())
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
HideSaveInfoWindow();
2018-03-28 00:33:08 +02:00
return SAVE_SUCCESS;
}
else
2018-03-28 00:33:08 +02:00
{
return SAVE_IN_PROGRESS;
}
}
2018-03-28 21:09:27 +02:00
static u8 SaveErrorCallback(void)
2018-03-28 00:33:08 +02:00
{
if (!IsTextPrinterActive(0))
{
2018-03-28 21:09:27 +02:00
PlaySE(SE_BOO);
sSaveDialogCallback = SaveReturnErrorCallback;
2018-03-28 00:33:08 +02:00
}
2018-03-28 00:33:08 +02:00
return SAVE_IN_PROGRESS;
}
2018-03-28 21:09:27 +02:00
static u8 SaveReturnErrorCallback(void)
2018-03-28 00:33:08 +02:00
{
if (!SaveErrorTimer())
2018-03-28 00:33:08 +02:00
{
return SAVE_IN_PROGRESS;
2017-09-05 13:01:24 +02:00
}
else
{
2018-03-28 21:09:27 +02:00
HideSaveInfoWindow();
2018-03-28 00:33:08 +02:00
return SAVE_ERROR;
}
}
2018-03-28 21:09:27 +02:00
static void InitBattlePyramidRetire(void)
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
sSaveDialogCallback = BattlePyramidConfirmRetireCallback;
2018-03-28 15:45:35 +02:00
sSavingComplete = FALSE;
2018-03-28 00:33:08 +02:00
}
2018-03-28 21:09:27 +02:00
static u8 BattlePyramidConfirmRetireCallback(void)
2018-03-28 00:33:08 +02:00
{
sub_819746C(GetStartMenuWindowId(), FALSE);
2018-03-29 02:16:02 +02:00
RemoveStartMenuWindow();
2018-03-28 21:09:27 +02:00
ShowSaveMessage(gText_BattlePyramidConfirmRetire, BattlePyramidRetireYesNoCallback);
2018-03-28 00:33:08 +02:00
return SAVE_IN_PROGRESS;
}
2018-03-28 21:09:27 +02:00
static u8 BattlePyramidRetireYesNoCallback(void)
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
sub_8197948(1); // Show Yes/No menu (No selected as default)
sSaveDialogCallback = BattlePyramidRetireInputCallback;
2018-03-28 00:33:08 +02:00
return SAVE_IN_PROGRESS;
}
2018-03-28 21:09:27 +02:00
static u8 BattlePyramidRetireInputCallback(void)
2018-03-28 00:33:08 +02:00
{
2018-08-12 21:54:07 +02:00
switch (Menu_ProcessInputNoWrap_())
2018-03-28 00:33:08 +02:00
{
case 0: // Yes
return SAVE_CANCELED;
case -1: // B Button
case 1: // No
sub_80A0014();
return SAVE_SUCCESS;
}
2018-03-28 00:33:08 +02:00
return SAVE_IN_PROGRESS;
}
2018-03-28 15:45:35 +02:00
static void sub_80A03D8(void)
2018-03-28 00:33:08 +02:00
{
TransferPlttBuffer();
}
2018-03-28 15:45:35 +02:00
static bool32 sub_80A03E4(u8 *par1)
2018-03-28 00:33:08 +02:00
{
switch (*par1)
{
case 0:
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_MODE_0);
SetVBlankCallback(NULL);
ScanlineEffect_Stop();
DmaClear16(3, PLTT, PLTT_SIZE);
DmaFillLarge16(3, 0, (void *)(VRAM + 0x0), 0x18000, 0x1000);
break;
case 1:
ResetSpriteData();
ResetTasks();
ResetPaletteFade();
ScanlineEffect_Clear();
break;
case 2:
ResetBgsAndClearDma3BusyFlags(0);
2018-03-29 02:16:02 +02:00
InitBgsFromTemplates(0, sUnknown_085105A8, ARRAY_COUNT(sUnknown_085105A8));
InitWindows(sUnknown_085105AC);
2018-07-16 20:23:05 +02:00
LoadUserWindowBorderGfx_(0, 8, 224);
2018-03-28 00:33:08 +02:00
sub_81978B0(240);
break;
case 3:
ShowBg(0);
BlendPalettes(-1, 16, 0);
SetVBlankCallback(sub_80A03D8);
EnableInterrupts(1);
break;
case 4:
2017-09-05 13:01:24 +02:00
return TRUE;
}
2018-03-28 00:33:08 +02:00
(*par1)++;
return FALSE;
}
2018-03-28 15:45:35 +02:00
void sub_80A0514(void) // Called from cable_club.s
2018-03-28 00:33:08 +02:00
{
if (sub_80A03E4(&gMain.state))
{
2018-03-28 22:43:25 +02:00
CreateTask(sub_80A0550, 0x50);
2018-03-28 00:33:08 +02:00
SetMainCallback2(sub_80A0540);
}
}
2018-03-28 15:45:35 +02:00
static void sub_80A0540(void)
2018-03-28 00:33:08 +02:00
{
RunTasks();
UpdatePaletteFade();
}
2018-03-28 15:45:35 +02:00
static void sub_80A0550(u8 taskId)
2018-03-28 00:33:08 +02:00
{
s16 *step = gTasks[taskId].data;
if (!gPaletteFade.active)
{
switch (*step)
{
case 0:
FillWindowPixelBuffer(0, 17);
AddTextPrinterParameterized2(0,
1,
2018-03-28 00:33:08 +02:00
gText_SavingDontTurnOffPower,
255,
NULL,
2,
1,
3);
sub_8098858(0, 8, 14);
PutWindowTilemap(0);
CopyWindowToVram(0, 3);
2018-07-15 13:23:38 +02:00
BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, 0);
2018-03-28 00:33:08 +02:00
if (gWirelessCommType != 0 && InUnionRoom())
{
if (sub_800A07C())
{
*step = 1;
}
else
2018-03-28 00:33:08 +02:00
{
*step = 5;
}
}
else
{
gSoftResetDisabled = 1;
*step = 1;
}
break;
case 1:
sub_8076D5C();
sub_8153430();
*step = 2;
break;
case 2:
if (sub_8153474())
{
sav2_gender2_inplace_and_xFE();
*step = 3;
gSoftResetDisabled = 0;
}
break;
case 3:
2018-07-15 13:23:38 +02:00
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, 0);
2018-03-28 00:33:08 +02:00
*step = 4;
break;
case 4:
FreeAllWindowBuffers();
SetMainCallback2(gMain.savedCallback);
DestroyTask(taskId);
break;
case 5:
2018-03-28 22:43:25 +02:00
CreateTask(sub_8153688, 0x5);
2018-03-28 00:33:08 +02:00
*step = 6;
break;
case 6:
2018-03-28 22:43:25 +02:00
if (!FuncIsActiveTask(sub_8153688))
2018-03-28 00:33:08 +02:00
{
*step = 3;
}
break;
}
}
}
2018-03-28 21:09:27 +02:00
static void ShowSaveInfoWindow(void)
2018-03-28 00:33:08 +02:00
{
2018-03-29 02:16:02 +02:00
struct WindowTemplate saveInfoWindow = sSaveInfoWindowTemplate;
2018-03-28 00:33:08 +02:00
u8 gender;
u8 color;
u32 xOffset;
u32 yOffset;
2018-03-28 00:33:08 +02:00
if (!FlagGet(FLAG_SYS_POKEDEX_GET))
{
saveInfoWindow.height -= 2;
}
2018-03-28 21:09:27 +02:00
sSaveInfoWindowId = AddWindow(&saveInfoWindow);
NewMenuHelpers_DrawStdWindowFrame(sSaveInfoWindowId, FALSE);
2018-03-28 00:33:08 +02:00
gender = gSaveBlock2Ptr->playerGender;
2018-03-28 21:09:27 +02:00
color = TEXT_COLOR_RED; // Red when female, blue when male.
2018-03-28 00:33:08 +02:00
if (gender == MALE)
{
2018-03-28 00:33:08 +02:00
color = TEXT_COLOR_BLUE;
}
// Print region name
yOffset = 1;
sub_819A344(3, gStringVar4, TEXT_COLOR_GREEN);
AddTextPrinterParameterized(sSaveInfoWindowId, 1, gStringVar4, 0, yOffset, 0xFF, NULL);
2018-03-28 00:33:08 +02:00
// Print player name
yOffset = 0x11;
AddTextPrinterParameterized(sSaveInfoWindowId, 1, gText_SavingPlayer, 0, yOffset, 0xFF, NULL);
2018-03-28 00:33:08 +02:00
sub_819A344(0, gStringVar4, color);
xOffset = GetStringRightAlignXOffset(1, gStringVar4, 0x70);
2018-03-28 21:09:27 +02:00
PrintPlayerNameOnWindow(sSaveInfoWindowId, gStringVar4, xOffset, yOffset);
2018-03-28 00:33:08 +02:00
// Print badge count
yOffset = 0x21;
AddTextPrinterParameterized(sSaveInfoWindowId, 1, gText_SavingBadges, 0, yOffset, 0xFF, NULL);
2018-03-28 00:33:08 +02:00
sub_819A344(4, gStringVar4, color);
xOffset = GetStringRightAlignXOffset(1, gStringVar4, 0x70);
AddTextPrinterParameterized(sSaveInfoWindowId, 1, gStringVar4, xOffset, yOffset, 0xFF, NULL);
2018-03-28 00:33:08 +02:00
if (FlagGet(FLAG_SYS_POKEDEX_GET) == TRUE)
{
// Print pokedex count
yOffset = 0x31;
AddTextPrinterParameterized(sSaveInfoWindowId, 1, gText_SavingPokedex, 0, yOffset, 0xFF, NULL);
2018-03-28 00:33:08 +02:00
sub_819A344(1, gStringVar4, color);
xOffset = GetStringRightAlignXOffset(1, gStringVar4, 0x70);
AddTextPrinterParameterized(sSaveInfoWindowId, 1, gStringVar4, xOffset, yOffset, 0xFF, NULL);
2018-03-28 00:33:08 +02:00
}
// Print play time
yOffset += 0x10;
AddTextPrinterParameterized(sSaveInfoWindowId, 1, gText_SavingTime, 0, yOffset, 0xFF, NULL);
2018-03-28 00:33:08 +02:00
sub_819A344(2, gStringVar4, color);
xOffset = GetStringRightAlignXOffset(1, gStringVar4, 0x70);
AddTextPrinterParameterized(sSaveInfoWindowId, 1, gStringVar4, xOffset, yOffset, 0xFF, NULL);
2018-03-28 00:33:08 +02:00
2018-03-28 21:09:27 +02:00
CopyWindowToVram(sSaveInfoWindowId, 2);
2018-03-28 00:33:08 +02:00
}
2018-03-28 21:09:27 +02:00
static void RemoveSaveInfoWindow(void)
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
sub_819746C(sSaveInfoWindowId, FALSE);
RemoveWindow(sSaveInfoWindowId);
2018-03-28 00:33:08 +02:00
}
2018-03-28 15:45:35 +02:00
static void sub_80A08A4(u8 taskId)
2018-03-28 00:33:08 +02:00
{
if (!FuncIsActiveTask(sub_8153688))
{
DestroyTask(taskId);
EnableBothScriptContexts();
}
}
2018-03-28 15:45:35 +02:00
void sub_80A08CC(void) // Referenced in data/specials.inc and data/scripts/maps/BattleFrontier_BattleTowerLobby.inc
2018-03-28 00:33:08 +02:00
{
2018-03-28 22:43:25 +02:00
u8 taskId = CreateTask(sub_8153688, 0x5);
gTasks[taskId].data[2] = 1;
gTasks[CreateTask(sub_80A08A4, 0x6)].data[1] = taskId;
2018-03-28 00:33:08 +02:00
}
2018-03-28 21:09:27 +02:00
static void HideStartMenuWindow(void)
2018-03-28 00:33:08 +02:00
{
sub_819746C(GetStartMenuWindowId(), TRUE);
2018-03-29 02:16:02 +02:00
RemoveStartMenuWindow();
ScriptUnfreezeEventObjects();
2018-03-28 00:33:08 +02:00
ScriptContext2_Disable();
}
2018-03-28 21:09:27 +02:00
void HideStartMenu(void) // Called from map_name_popup.s
2018-03-28 00:33:08 +02:00
{
2018-03-28 21:09:27 +02:00
PlaySE(SE_SELECT);
HideStartMenuWindow();
2018-03-28 00:33:08 +02:00
}
void AppendToList(u8 *list, u8 *pos, u8 newEntry)
{
list[*pos] = newEntry;
(*pos)++;
}