pokeemerald/src/pokenav_match_call_2.c

1279 lines
36 KiB
C
Raw Normal View History

2019-04-16 00:51:11 +02:00
#include "global.h"
#include "bg.h"
2019-04-16 18:00:13 +02:00
#include "data.h"
#include "decompress.h"
#include "dma3.h"
#include "international_string_util.h"
#include "main.h"
#include "match_call.h"
#include "menu.h"
2019-04-16 18:00:13 +02:00
#include "overworld.h"
#include "palette.h"
2019-04-16 00:51:11 +02:00
#include "pokenav.h"
2019-04-16 18:00:13 +02:00
#include "region_map.h"
#include "sound.h"
2019-04-16 18:00:13 +02:00
#include "sprite.h"
#include "string_util.h"
#include "strings.h"
#include "task.h"
#include "text.h"
#include "text_window.h"
#include "trig.h"
2019-04-16 00:51:11 +02:00
#include "window.h"
2019-04-16 18:00:13 +02:00
#include "constants/game_stat.h"
#include "constants/region_map_sections.h"
#include "constants/songs.h"
2019-04-16 00:51:11 +02:00
struct Pokenav4Struct
{
2020-02-05 08:47:32 +01:00
bool32 (*isTaskActiveCB)(void);
u32 loopTaskId;
2019-04-16 18:00:13 +02:00
u8 filler8[0x6];
u8 unkE;
u8 unkF;
2019-12-06 04:34:55 +01:00
u16 locWindowId;
u16 infoBoxWindowId;
2019-12-08 21:49:36 +01:00
u16 msgBoxWindowId;
2019-04-16 18:00:13 +02:00
s16 unk16;
u8 unused18;
2020-10-11 00:17:34 +02:00
u8 unused19;
2019-04-16 18:00:13 +02:00
u16 unk1A;
2019-12-07 10:08:21 +01:00
struct Sprite *optionsCursorSprite;
struct Sprite *trainerPicSprite;
u8 unk24[0x800];
u8 unk824[0x800];
u8 unk1024[0x800];
2019-04-16 18:00:13 +02:00
u8 *unk1824;
u8 unk1828[0x800];
u8 unk2028[0x20];
2019-04-16 00:51:11 +02:00
};
2020-02-05 08:47:32 +01:00
static bool32 GetCurrentLoopedTaskActive(void);
static u32 LoopedTask_OpenMatchCall(s32);
2020-10-11 00:17:34 +02:00
static void InitMatchCallPokenavListMenuTemplate(void);
2019-04-16 18:00:13 +02:00
static void sub_81CBC1C(void);
2020-10-11 00:17:34 +02:00
static void RemoveMatchCallSprites(void);
2019-04-16 18:00:13 +02:00
static void sub_81CC034(struct Pokenav4Struct *);
2019-12-06 04:34:55 +01:00
static void DrawMatchCallLeftColumnWindows(struct Pokenav4Struct *);
static void UpdateMatchCallInfoBox(struct Pokenav4Struct *);
static void PrintMatchCallLocation(struct Pokenav4Struct *, int);
2019-04-16 18:00:13 +02:00
static void sub_81CC214(void);
static void sub_81CBC38(int);
2019-12-06 04:34:55 +01:00
static void PrintMatchCallSelectionOptions(struct Pokenav4Struct *);
2019-04-16 18:00:13 +02:00
static bool32 sub_81CBFC4(struct Pokenav4Struct *);
2019-12-07 10:08:21 +01:00
static void UpdateCursorGfxPos(struct Pokenav4Struct *, int);
static bool32 IsDma3ManagerBusyWithBgCopy1(struct Pokenav4Struct *);
static void UpdateWindowsReturnToTrainerList(struct Pokenav4Struct *);
static void DrawMsgBoxForMatchCallMsg(struct Pokenav4Struct *);
static bool32 IsDma3ManagerBusyWithBgCopy2(struct Pokenav4Struct *);
2019-12-06 04:34:55 +01:00
static void PrintCallingDots(struct Pokenav4Struct *);
static bool32 WaitForCallingDotsText(struct Pokenav4Struct *);
static void PrintMatchCallMessage(struct Pokenav4Struct *);
static bool32 WaitForMatchCallMessageText(struct Pokenav4Struct *);
2019-12-07 10:08:21 +01:00
static void DrawMsgBoxForCloseByMsg(struct Pokenav4Struct *);
2019-12-06 04:34:55 +01:00
static void PrintTrainerIsCloseBy(struct Pokenav4Struct *);
static bool32 WaitForTrainerIsCloseByText(struct Pokenav4Struct *);
2019-12-07 10:08:21 +01:00
static void DrawSpinningPokenavForCall(struct Pokenav4Struct *);
static bool32 WaitForSpinningPokenav(struct Pokenav4Struct *);
static void UpdateWindowsToShowCheckPage(struct Pokenav4Struct *);
static void LoadCheckPageTrainerPic(struct Pokenav4Struct *);
static bool32 WaitForTrainerPic(struct Pokenav4Struct *);
static void TrainerPicSlideOffscreen(struct Pokenav4Struct *);
2019-04-16 18:00:13 +02:00
static void sub_81CBC64(u8 taskId);
2019-12-07 10:08:21 +01:00
static void TryDrawRematchPokeballIcon(u16 windowId, u32, u32);
2019-12-06 04:34:55 +01:00
static void PrintNumberRegisteredLabel(u16 windowId);
static void PrintNumberRegistered(u16 windowId);
static void PrintNumberOfBattlesLabel(u16 windowId);
static void PrintNumberOfBattles(u16 windowId);
static void PrintMatchCallInfoLabel(u16 windowId, const u8 *str, int top);
static void PrintMatchCallInfoNumber(u16 windowId, const u8 *str, int top);
2019-04-16 18:00:13 +02:00
static void sub_81CC2F0(struct Pokenav4Struct *, int);
2019-12-06 04:34:55 +01:00
static void CloseMatchCallSelectOptionsWindow(struct Pokenav4Struct *);
2019-12-07 10:08:21 +01:00
static struct Sprite *CreateTrainerPicSprite(void);
static void SpriteCB_TrainerPicSlideOnscreen(struct Sprite *sprite);
static void SpriteCB_TrainerPicSlideOffscreen(struct Sprite *sprite);
void SpriteCB_OptionsCursor(struct Sprite *sprite);
2019-12-06 04:34:55 +01:00
u32 MatchCallListCursorDown(s32);
u32 MatchCallListCursorUp(s32);
u32 MatchCallListPageDown(s32);
u32 MatchCallListPageUp(s32);
u32 SelectMatchCallEntry(s32);
2019-12-07 10:08:21 +01:00
u32 MoveMatchCallOptionsCursor(s32);
static u32 CancelMatchCallSelection(s32);
2019-12-06 04:34:55 +01:00
u32 DoMatchCallMessage(s32);
u32 DoTrainerCloseByMessage(s32);
2019-07-20 19:11:04 +02:00
u32 sub_81CB888(s32);
2019-12-07 10:08:21 +01:00
u32 ShowCheckPage(s32);
u32 ShowCheckPageUp(s32);
u32 ShowCheckPageDown(s32);
u32 ExitCheckPage(s32);
u32 ExitMatchCall(s32);
static const u16 sMatchCallUI_Pal[] = INCBIN_U16("graphics/pokenav/ui_matchcall.gbapal");
static const u32 sMatchCallUI_Gfx[] = INCBIN_U32("graphics/pokenav/ui_matchcall.4bpp.lz");
static const u32 sMatchCallUI_Tilemap[] = INCBIN_U32("graphics/pokenav/ui_matchcall.bin.lz");
static const u16 gUnknown_08622698[] = INCBIN_U16("graphics/pokenav/arrow2.gbapal");
static const u32 gUnknown_086226B8[] = INCBIN_U32("graphics/pokenav/arrow2.4bpp.lz");
static const u16 gUnknown_086226E0[] = INCBIN_U16("graphics/pokenav/86226E0.gbapal");
static const u16 gUnknown_08622700[] = INCBIN_U16("graphics/pokenav/8622700.gbapal");
static const u16 gUnknown_08622720[] = INCBIN_U16("graphics/pokenav/pokeball_matchcall.gbapal");
static const u32 gUnknown_08622760[] = INCBIN_U32("graphics/pokenav/pokeball_matchcall.4bpp.lz");
2019-07-20 01:36:17 +02:00
2020-10-11 00:17:34 +02:00
const struct BgTemplate sMatchCallBgTemplates[3] =
2019-07-20 01:36:17 +02:00
{
{
.bg = 1,
.charBaseIndex = 3,
.mapBaseIndex = 0x1F,
.screenSize = 0,
.paletteMode = 0,
.priority = 1,
.baseTile = 0
},
{
.bg = 2,
.charBaseIndex = 2,
.mapBaseIndex = 0x06,
.screenSize = 0,
.paletteMode = 0,
.priority = 2,
.baseTile = 0x80
},
{
.bg = 3,
.charBaseIndex = 1,
.mapBaseIndex = 0x07,
.screenSize = 0,
.paletteMode = 0,
.priority = 3,
.baseTile = 0
}
};
2019-12-07 10:08:21 +01:00
static const LoopedTask sMatchCallLoopTaskFuncs[] =
2019-07-20 01:36:17 +02:00
{
[POKENAV_MC_FUNC_NONE] = NULL,
[POKENAV_MC_FUNC_DOWN] = MatchCallListCursorDown,
[POKENAV_MC_FUNC_UP] = MatchCallListCursorUp,
[POKENAV_MC_FUNC_PG_DOWN] = MatchCallListPageDown,
[POKENAV_MC_FUNC_PG_UP] = MatchCallListPageUp,
[POKENAV_MC_FUNC_SELECT] = SelectMatchCallEntry,
2019-12-08 21:49:36 +01:00
[POKENAV_MC_FUNC_MOVE_OPTIONS_CURSOR] = MoveMatchCallOptionsCursor,
[POKENAV_MC_FUNC_CANCEL] = CancelMatchCallSelection,
[POKENAV_MC_FUNC_CALL_MSG] = DoMatchCallMessage,
[POKENAV_MC_FUNC_NEARBY_MSG] = DoTrainerCloseByMessage,
[POKENAV_MC_FUNC_10] = sub_81CB888,
[POKENAV_MC_FUNC_SHOW_CHECK_PAGE] = ShowCheckPage,
[POKENAV_MC_FUNC_CHECK_PAGE_UP] = ShowCheckPageUp,
[POKENAV_MC_FUNC_CHECK_PAGE_DOWN] = ShowCheckPageDown,
[POKENAV_MC_FUNC_EXIT_CHECK_PAGE] = ExitCheckPage,
[POKENAV_MC_FUNC_EXIT] = ExitMatchCall
2019-07-20 01:36:17 +02:00
};
2019-12-06 04:34:55 +01:00
static const struct WindowTemplate sMatchCallLocationWindowTemplate =
2019-07-20 01:36:17 +02:00
{
.bg = 2,
.tilemapLeft = 0,
.tilemapTop = 5,
.width = 11,
.height = 2,
.paletteNum = 2,
.baseBlock = 16
};
2019-12-06 04:34:55 +01:00
static const struct WindowTemplate sMatchCallInfoBoxWindowTemplate =
2019-07-20 01:36:17 +02:00
{
.bg = 2,
.tilemapLeft = 0,
.tilemapTop = 9,
.width = 11,
.height = 8,
.paletteNum = 2,
.baseBlock = 38
};
2019-12-05 21:33:36 +01:00
static const u8 *const sMatchCallOptionTexts[MATCH_CALL_OPTION_COUNT] =
2019-07-20 01:36:17 +02:00
{
2019-12-05 21:33:36 +01:00
[MATCH_CALL_OPTION_CALL] = gText_Call,
[MATCH_CALL_OPTION_CHECK] = gText_Check,
[MATCH_CALL_OPTION_CANCEL] = gText_Cancel6
2019-07-20 01:36:17 +02:00
};
2019-12-06 04:34:55 +01:00
// The series of 5 dots that appear when someone is called with Match Call
2019-12-07 10:08:21 +01:00
static const u8 sText_CallingDots[] = _("·{PAUSE 0x04}·{PAUSE 0x04}·{PAUSE 0x04}·{PAUSE 0x04}·\p");
2019-07-20 01:36:17 +02:00
2019-12-08 22:57:09 +01:00
static const struct WindowTemplate sCallMsgBoxWindowTemplate =
2019-07-20 01:36:17 +02:00
{
.bg = 1,
.tilemapLeft = 1,
.tilemapTop = 12,
.width = 0x1C,
.height = 0x04,
.paletteNum = 1,
.baseBlock = 10
};
const struct CompressedSpriteSheet gUnknown_08622810[1] =
{
{gUnknown_086226B8, 0x40, 7}
};
2019-12-07 10:08:21 +01:00
const struct SpritePalette gUnknown_08622818[2] =
2019-07-20 01:36:17 +02:00
{
2019-12-07 10:08:21 +01:00
{gUnknown_08622698, 12}
2019-07-20 01:36:17 +02:00
};
2019-12-07 10:08:21 +01:00
static const struct OamData sOptionsCursorOamData =
2019-07-20 01:36:17 +02:00
{
.y = 0,
.affineMode = ST_OAM_AFFINE_OFF,
.objMode = ST_OAM_OBJ_NORMAL,
.bpp = ST_OAM_4BPP,
2019-07-20 03:05:55 +02:00
.shape = SPRITE_SHAPE(8x16),
2019-07-20 01:36:17 +02:00
.x = 0,
2019-07-20 03:05:55 +02:00
.size = SPRITE_SIZE(8x16),
2019-07-20 01:36:17 +02:00
.tileNum = 0,
.priority = 1,
.paletteNum = 0,
};
2019-12-07 10:08:21 +01:00
static const struct SpriteTemplate sOptionsCursorSpriteTemplate =
2019-07-20 01:36:17 +02:00
{
.tileTag = 7,
.paletteTag = 12,
2019-12-07 10:08:21 +01:00
.oam = &sOptionsCursorOamData,
2019-07-20 01:36:17 +02:00
.anims = gDummySpriteAnimTable,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
2019-12-07 10:08:21 +01:00
.callback = SpriteCB_OptionsCursor,
2019-07-20 01:36:17 +02:00
};
2019-12-07 10:08:21 +01:00
static const struct OamData sTrainerPicOamData =
2019-07-20 01:36:17 +02:00
{
.y = 0,
.affineMode = ST_OAM_AFFINE_OFF,
.objMode = ST_OAM_OBJ_NORMAL,
.bpp = ST_OAM_4BPP,
2019-07-20 03:05:55 +02:00
.shape = SPRITE_SHAPE(64x64),
2019-07-20 01:36:17 +02:00
.x = 0,
2019-07-20 03:05:55 +02:00
.size = SPRITE_SIZE(64x64),
2019-07-20 01:36:17 +02:00
.tileNum = 0,
.priority = 1,
.paletteNum = 0,
};
2019-12-07 10:08:21 +01:00
static const struct SpriteTemplate sTrainerPicSpriteTemplate =
2019-07-20 01:36:17 +02:00
{
.tileTag = 8,
.paletteTag = 13,
2019-12-07 10:08:21 +01:00
.oam = &sTrainerPicOamData,
2019-07-20 01:36:17 +02:00
.anims = gDummySpriteAnimTable,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SpriteCallbackDummy,
};
2020-02-05 08:47:32 +01:00
bool32 OpenMatchCall(void)
2019-04-16 00:51:11 +02:00
{
2020-10-11 00:17:34 +02:00
struct Pokenav4Struct *state = AllocSubstruct(POKENAV_SUBSTRUCT_MATCH_CALL_OPEN, sizeof(struct Pokenav4Struct));
2019-04-16 00:51:11 +02:00
if (!state)
return FALSE;
2020-10-11 00:17:34 +02:00
state->unused19 = 0;
2020-02-05 08:47:32 +01:00
state->loopTaskId = CreateLoopedTask(LoopedTask_OpenMatchCall, 1);
state->isTaskActiveCB = GetCurrentLoopedTaskActive;
2019-04-16 00:51:11 +02:00
return TRUE;
}
2020-02-01 06:25:50 +01:00
void CreateMatchCallLoopedTask(s32 index)
2019-04-16 00:51:11 +02:00
{
2020-10-11 00:17:34 +02:00
struct Pokenav4Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MATCH_CALL_OPEN);
2020-02-05 08:47:32 +01:00
state->loopTaskId = CreateLoopedTask(sMatchCallLoopTaskFuncs[index], 1);
state->isTaskActiveCB = GetCurrentLoopedTaskActive;
2019-04-16 00:51:11 +02:00
}
2020-02-05 08:47:32 +01:00
bool32 IsMatchCallLoopedTaskActive(void)
2019-04-16 00:51:11 +02:00
{
2020-10-11 00:17:34 +02:00
struct Pokenav4Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MATCH_CALL_OPEN);
2020-02-05 08:47:32 +01:00
return state->isTaskActiveCB();
2019-04-16 00:51:11 +02:00
}
2020-02-05 08:47:32 +01:00
void FreeMatchCallSubstruct2(void)
2019-04-16 00:51:11 +02:00
{
2020-10-11 00:17:34 +02:00
struct Pokenav4Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MATCH_CALL_OPEN);
RemoveMatchCallSprites();
2019-04-16 00:51:11 +02:00
sub_81CBC1C();
2019-12-06 04:34:55 +01:00
RemoveWindow(state->infoBoxWindowId);
RemoveWindow(state->locWindowId);
RemoveWindow(state->msgBoxWindowId);
2019-04-16 00:51:11 +02:00
FreePokenavSubstruct(6);
}
2020-02-05 08:47:32 +01:00
static bool32 GetCurrentLoopedTaskActive(void)
2019-04-16 00:51:11 +02:00
{
2020-10-11 00:17:34 +02:00
struct Pokenav4Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MATCH_CALL_OPEN);
2020-02-05 08:47:32 +01:00
return IsLoopedTaskActive(state->loopTaskId);
2019-04-16 00:51:11 +02:00
}
2020-02-05 08:47:32 +01:00
static u32 LoopedTask_OpenMatchCall(s32 taskState)
{
2020-10-11 00:17:34 +02:00
struct Pokenav4Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MATCH_CALL_OPEN);
switch (taskState)
{
case 0:
2020-10-11 00:17:34 +02:00
InitBgTemplates(sMatchCallBgTemplates, ARRAY_COUNT(sMatchCallBgTemplates));
ChangeBgX(2, 0, 0);
ChangeBgY(2, 0, 0);
2020-05-14 10:37:09 +02:00
DecompressAndCopyTileDataToVram(2, sMatchCallUI_Gfx, 0, 0, 0);
SetBgTilemapBuffer(2, state->unk1024);
2019-12-07 10:08:21 +01:00
CopyToBgTilemapBuffer(2, sMatchCallUI_Tilemap, 0, 0);
CopyBgTilemapBufferToVram(2);
2019-12-07 10:08:21 +01:00
CopyPaletteIntoBufferUnfaded(sMatchCallUI_Pal, 0x20, 0x20);
CopyBgTilemapBufferToVram(2);
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
case 1:
2020-05-14 10:37:09 +02:00
if (FreeTempTileDataBuffersIfPossible())
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
sub_8199DF0(1, 0, 0, 1);
SetBgTilemapBuffer(1, state->unk24);
FillBgTilemapBufferRect_Palette0(1, 0x1000, 0, 0, 32, 20);
CopyPaletteIntoBufferUnfaded(gUnknown_086226E0, 0x10, 0x20);
CopyBgTilemapBufferToVram(1);
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
case 2:
2020-05-14 10:37:09 +02:00
if (FreeTempTileDataBuffersIfPossible())
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
sub_81CC034(state);
2020-05-14 10:37:09 +02:00
DecompressAndCopyTileDataToVram(3, gUnknown_08622760, 0, 0, 0);
CopyPaletteIntoBufferUnfaded(gUnknown_08622700, 0x30, 0x20);
CopyPaletteIntoBufferUnfaded(gUnknown_08622720, 0x50, 0x20);
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
case 3:
2020-05-14 10:37:09 +02:00
if (FreeTempTileDataBuffersIfPossible() || !sub_81CAE28())
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
2020-10-11 00:17:34 +02:00
InitMatchCallPokenavListMenuTemplate();
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
case 4:
if (sub_81C8224())
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
2019-12-06 04:34:55 +01:00
DrawMatchCallLeftColumnWindows(state);
return LT_INC_AND_PAUSE;
case 5:
2019-12-06 04:34:55 +01:00
UpdateMatchCallInfoBox(state);
PrintMatchCallLocation(state, 0);
return LT_INC_AND_PAUSE;
case 6:
ChangeBgX(1, 0, 0);
ChangeBgY(1, 0, 0);
ShowBg(2);
ShowBg(3);
ShowBg(1);
sub_81CC214();
LoadLeftHeaderGfxForIndex(3);
2020-10-11 00:17:34 +02:00
ShowLeftHeaderGfx(POKENAV_GFX_MATCH_CALL_MENU, 1, 0);
2020-02-05 08:47:32 +01:00
PokenavFadeScreen(1);
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
case 7:
2020-10-11 00:17:34 +02:00
if (IsPaletteFadeActive() || AreLeftHeaderSpritesMoving())
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
sub_81CBC38(1);
2019-12-06 04:34:55 +01:00
return LT_FINISH;
default:
2019-12-06 04:34:55 +01:00
return LT_FINISH;
}
}
2019-12-06 04:34:55 +01:00
u32 MatchCallListCursorDown(s32 taskState)
{
2020-10-11 00:17:34 +02:00
struct Pokenav4Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MATCH_CALL_OPEN);
switch (taskState)
{
case 0:
switch (MatchCall_MoveCursorDown())
{
case 0:
break;
case 1:
PlaySE(SE_SELECT);
return 7;
case 2:
PlaySE(SE_SELECT);
// fall through
default:
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
}
break;
case 1:
2020-10-11 00:17:34 +02:00
if (IsMonListLoopedTaskActive())
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
2019-12-06 04:34:55 +01:00
PrintMatchCallLocation(state, 0);
return LT_INC_AND_PAUSE;
case 2:
2019-12-06 04:34:55 +01:00
PrintMatchCallLocation(state, 0);
return LT_INC_AND_PAUSE;
case 3:
if (IsDma3ManagerBusyWithBgCopy())
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
break;
}
2019-12-06 04:34:55 +01:00
return LT_FINISH;
}
2019-12-06 04:34:55 +01:00
u32 MatchCallListCursorUp(s32 taskState)
{
2020-10-11 00:17:34 +02:00
struct Pokenav4Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MATCH_CALL_OPEN);
switch (taskState)
{
case 0:
switch (MatchCall_MoveCursorUp())
{
case 0:
break;
case 1:
PlaySE(SE_SELECT);
return 7;
case 2:
PlaySE(SE_SELECT);
// fall through
default:
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
}
break;
case 1:
2020-10-11 00:17:34 +02:00
if (IsMonListLoopedTaskActive())
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
2019-12-06 04:34:55 +01:00
PrintMatchCallLocation(state, 0);
return LT_INC_AND_PAUSE;
case 2:
2019-12-06 04:34:55 +01:00
PrintMatchCallLocation(state, 0);
return LT_INC_AND_PAUSE;
case 3:
if (IsDma3ManagerBusyWithBgCopy())
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
break;
}
2019-12-06 04:34:55 +01:00
return LT_FINISH;
}
2019-12-06 04:34:55 +01:00
u32 MatchCallListPageDown(s32 taskState)
{
2020-10-11 00:17:34 +02:00
struct Pokenav4Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MATCH_CALL_OPEN);
switch (taskState)
{
case 0:
switch (MatchCall_PageDown())
{
case 0:
break;
case 1:
PlaySE(SE_SELECT);
return 7;
case 2:
PlaySE(SE_SELECT);
// fall through
default:
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
}
break;
case 1:
2020-10-11 00:17:34 +02:00
if (IsMonListLoopedTaskActive())
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
2019-12-06 04:34:55 +01:00
PrintMatchCallLocation(state, 0);
return LT_INC_AND_PAUSE;
case 2:
2019-12-06 04:34:55 +01:00
PrintMatchCallLocation(state, 0);
return LT_INC_AND_PAUSE;
case 3:
if (IsDma3ManagerBusyWithBgCopy())
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
break;
}
2019-12-06 04:34:55 +01:00
return LT_FINISH;
}
2019-12-06 04:34:55 +01:00
u32 MatchCallListPageUp(s32 taskState)
{
2020-10-11 00:17:34 +02:00
struct Pokenav4Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MATCH_CALL_OPEN);
switch (taskState)
{
case 0:
switch (MatchCall_PageUp())
{
case 0:
break;
case 1:
PlaySE(SE_SELECT);
return 7;
case 2:
PlaySE(SE_SELECT);
// fall through
default:
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
}
break;
case 1:
2020-10-11 00:17:34 +02:00
if (IsMonListLoopedTaskActive())
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
2019-12-06 04:34:55 +01:00
PrintMatchCallLocation(state, 0);
return LT_INC_AND_PAUSE;
case 2:
2019-12-06 04:34:55 +01:00
PrintMatchCallLocation(state, 0);
return LT_INC_AND_PAUSE;
case 3:
if (IsDma3ManagerBusyWithBgCopy())
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
break;
}
2019-12-06 04:34:55 +01:00
return LT_FINISH;
}
2019-04-16 18:00:13 +02:00
2019-12-06 04:34:55 +01:00
u32 SelectMatchCallEntry(s32 taskState)
2019-04-16 18:00:13 +02:00
{
2020-10-11 00:17:34 +02:00
struct Pokenav4Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MATCH_CALL_OPEN);
2019-04-16 18:00:13 +02:00
switch (taskState)
{
case 0:
PlaySE(SE_SELECT);
2019-12-06 04:34:55 +01:00
PrintMatchCallSelectionOptions(state);
2019-12-07 10:08:21 +01:00
PrintHelpBarText(HELPBAR_MC_CALL_MENU);
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
2019-04-16 18:00:13 +02:00
case 1:
if (sub_81CBFC4(state))
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
2019-04-16 18:00:13 +02:00
break;
}
2019-12-06 04:34:55 +01:00
return LT_FINISH;
2019-04-16 18:00:13 +02:00
}
2019-12-07 10:08:21 +01:00
u32 MoveMatchCallOptionsCursor(s32 taskState)
2019-04-16 18:00:13 +02:00
{
struct Pokenav4Struct *state;
2019-12-07 10:08:21 +01:00
u16 cursorPos;
2019-04-16 18:00:13 +02:00
PlaySE(SE_SELECT);
2020-10-11 00:17:34 +02:00
state = GetSubstructPtr(POKENAV_SUBSTRUCT_MATCH_CALL_OPEN);
2019-12-07 10:08:21 +01:00
cursorPos = GetMatchCallOptionCursorPos();
UpdateCursorGfxPos(state, cursorPos);
2019-12-06 04:34:55 +01:00
return LT_FINISH;
2019-04-16 18:00:13 +02:00
}
2019-12-07 10:08:21 +01:00
u32 CancelMatchCallSelection(s32 taskState)
2019-04-16 18:00:13 +02:00
{
2020-10-11 00:17:34 +02:00
struct Pokenav4Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MATCH_CALL_OPEN);
2019-04-16 18:00:13 +02:00
switch (taskState)
{
case 0:
PlaySE(SE_SELECT);
2019-12-07 10:08:21 +01:00
UpdateWindowsReturnToTrainerList(state);
PrintHelpBarText(HELPBAR_MC_TRAINER_LIST);
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
2019-04-16 18:00:13 +02:00
case 1:
2019-12-07 10:08:21 +01:00
if (IsDma3ManagerBusyWithBgCopy1(state))
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
2019-04-16 18:00:13 +02:00
break;
}
2019-12-06 04:34:55 +01:00
return LT_FINISH;
2019-04-16 18:00:13 +02:00
}
2019-12-06 04:34:55 +01:00
u32 DoMatchCallMessage(s32 taskState)
2019-04-16 18:00:13 +02:00
{
2020-10-11 00:17:34 +02:00
struct Pokenav4Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MATCH_CALL_OPEN);
2019-04-16 18:00:13 +02:00
switch (taskState)
{
case 0:
ToggleMatchCallVerticalArrows(TRUE);
2019-12-07 10:08:21 +01:00
DrawMsgBoxForMatchCallMsg(state);
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
2019-04-16 18:00:13 +02:00
case 1:
2019-12-07 10:08:21 +01:00
if (IsDma3ManagerBusyWithBgCopy2(state))
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
2019-04-16 18:00:13 +02:00
2019-12-06 04:34:55 +01:00
PrintCallingDots(state);
2020-08-21 00:02:00 +02:00
PlaySE(SE_POKENAV_CALL);
2019-04-16 18:00:13 +02:00
state->unkE = 0;
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
2019-04-16 18:00:13 +02:00
case 2:
2019-12-06 04:34:55 +01:00
if (WaitForCallingDotsText(state))
return LT_PAUSE;
2019-04-16 18:00:13 +02:00
2019-12-06 04:34:55 +01:00
PrintMatchCallMessage(state);
return LT_INC_AND_PAUSE;
2019-04-16 18:00:13 +02:00
case 3:
2019-12-06 04:34:55 +01:00
if (WaitForMatchCallMessageText(state))
return LT_PAUSE;
2019-04-16 18:00:13 +02:00
break;
}
2019-12-06 04:34:55 +01:00
return LT_FINISH;
2019-04-16 18:00:13 +02:00
}
2019-12-06 04:34:55 +01:00
u32 DoTrainerCloseByMessage(s32 taskState)
2019-04-16 18:00:13 +02:00
{
2020-10-11 00:17:34 +02:00
struct Pokenav4Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MATCH_CALL_OPEN);
2019-04-16 18:00:13 +02:00
switch (taskState)
{
case 0:
PlaySE(SE_SELECT);
2019-12-07 10:08:21 +01:00
DrawMsgBoxForCloseByMsg(state);
2019-04-16 18:00:13 +02:00
ToggleMatchCallVerticalArrows(TRUE);
state->unkE = 1;
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
2019-04-16 18:00:13 +02:00
case 1:
2019-12-07 10:08:21 +01:00
if (IsDma3ManagerBusyWithBgCopy2(state))
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
2019-04-16 18:00:13 +02:00
2019-12-06 04:34:55 +01:00
PrintTrainerIsCloseBy(state);
return LT_INC_AND_PAUSE;
2019-04-16 18:00:13 +02:00
case 2:
2019-12-06 04:34:55 +01:00
if (WaitForTrainerIsCloseByText(state))
return LT_PAUSE;
2019-04-16 18:00:13 +02:00
break;
}
2019-12-06 04:34:55 +01:00
return LT_FINISH;
2019-04-16 18:00:13 +02:00
}
2019-07-19 02:46:00 +02:00
u32 sub_81CB888(s32 taskState)
2019-04-16 18:00:13 +02:00
{
2020-10-11 00:17:34 +02:00
struct Pokenav4Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MATCH_CALL_OPEN);
2019-12-06 04:34:55 +01:00
u32 result = LT_INC_AND_PAUSE;
2019-04-16 18:00:13 +02:00
switch (taskState)
{
case 0:
if (!state->unkE)
2020-08-21 00:02:00 +02:00
PlaySE(SE_POKENAV_HANG_UP);
2019-04-16 18:00:13 +02:00
PlaySE(SE_SELECT);
break;
case 1:
2019-12-07 10:08:21 +01:00
DrawSpinningPokenavForCall(state);
2019-04-16 18:00:13 +02:00
break;
case 2:
2019-12-07 10:08:21 +01:00
if (WaitForSpinningPokenav(state))
2019-12-06 04:34:55 +01:00
result = LT_PAUSE;
2019-04-16 18:00:13 +02:00
break;
case 3:
2019-12-07 10:08:21 +01:00
UpdateWindowsReturnToTrainerList(state);
2019-04-16 18:00:13 +02:00
break;
case 4:
2019-12-07 10:08:21 +01:00
if (IsDma3ManagerBusyWithBgCopy1(state))
2019-12-06 04:34:55 +01:00
result = LT_PAUSE;
2019-04-16 18:00:13 +02:00
2019-12-07 10:08:21 +01:00
PrintHelpBarText(HELPBAR_MC_TRAINER_LIST);
2019-04-16 18:00:13 +02:00
break;
case 5:
2019-12-07 10:08:21 +01:00
if (WaitForHelpBar())
2019-04-16 18:00:13 +02:00
{
2019-12-06 04:34:55 +01:00
result = LT_PAUSE;
2019-04-16 18:00:13 +02:00
}
else
{
if (state->unkF)
{
sub_81C8838();
2019-12-06 04:34:55 +01:00
result = LT_INC_AND_CONTINUE;
2019-04-16 18:00:13 +02:00
}
else
{
ToggleMatchCallVerticalArrows(FALSE);
2019-12-06 04:34:55 +01:00
result = LT_FINISH;
2019-04-16 18:00:13 +02:00
}
}
break;
case 6:
if (IsDma3ManagerBusyWithBgCopy())
{
2019-12-06 04:34:55 +01:00
result = LT_PAUSE;
2019-04-16 18:00:13 +02:00
}
else
{
ToggleMatchCallVerticalArrows(FALSE);
2019-12-06 04:34:55 +01:00
result = LT_FINISH;
2019-04-16 18:00:13 +02:00
}
break;
}
return result;
}
2019-12-07 10:08:21 +01:00
u32 ShowCheckPage(s32 taskState)
2019-04-16 18:00:13 +02:00
{
2020-10-11 00:17:34 +02:00
struct Pokenav4Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MATCH_CALL_OPEN);
2019-04-16 18:00:13 +02:00
switch (taskState)
{
case 0:
PlaySE(SE_SELECT);
sub_81C877C();
2019-12-07 10:08:21 +01:00
UpdateWindowsToShowCheckPage(state);
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
2019-04-16 18:00:13 +02:00
case 1:
2020-10-11 00:17:34 +02:00
if (IsMatchCallListTaskActive() || IsDma3ManagerBusyWithBgCopy1(state))
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
2019-04-16 18:00:13 +02:00
2019-12-07 10:08:21 +01:00
PrintHelpBarText(HELPBAR_MC_CHECK_PAGE);
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
2019-04-16 18:00:13 +02:00
case 2:
2019-12-07 10:08:21 +01:00
PrintCheckPageInfo(0);
LoadCheckPageTrainerPic(state);
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
2019-04-16 18:00:13 +02:00
case 3:
2020-10-11 00:17:34 +02:00
if (IsMatchCallListTaskActive() || WaitForTrainerPic(state) || WaitForHelpBar())
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
2019-04-16 18:00:13 +02:00
break;
}
2019-12-06 04:34:55 +01:00
return LT_FINISH;
2019-04-16 18:00:13 +02:00
}
2019-12-07 10:08:21 +01:00
u32 ShowCheckPageDown(s32 taskState)
2019-04-16 18:00:13 +02:00
{
2019-12-07 10:08:21 +01:00
int topId;
int delta;
2020-10-11 00:17:34 +02:00
struct Pokenav4Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MATCH_CALL_OPEN);
2019-04-16 18:00:13 +02:00
switch (taskState)
{
case 0:
2019-12-07 10:08:21 +01:00
topId = GetMatchCallListTopIndex();
delta = GetIndexDeltaOfNextCheckPageDown(topId);
if (delta)
2019-04-16 18:00:13 +02:00
{
PlaySE(SE_SELECT);
2019-12-07 10:08:21 +01:00
state->unk16 = delta;
TrainerPicSlideOffscreen(state);
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
2019-04-16 18:00:13 +02:00
}
break;
case 1:
2019-12-07 10:08:21 +01:00
if (WaitForTrainerPic(state))
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
2019-04-16 18:00:13 +02:00
2019-12-06 04:34:55 +01:00
PrintMatchCallLocation(state, state->unk16);
return LT_INC_AND_PAUSE;
2019-04-16 18:00:13 +02:00
case 2:
2019-12-07 10:08:21 +01:00
PrintCheckPageInfo(state->unk16);
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
2019-04-16 18:00:13 +02:00
case 3:
2019-12-07 10:08:21 +01:00
LoadCheckPageTrainerPic(state);
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
2019-04-16 18:00:13 +02:00
case 4:
2020-10-11 00:17:34 +02:00
if (IsMatchCallListTaskActive() || WaitForTrainerPic(state))
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
2019-04-16 18:00:13 +02:00
break;
}
2019-12-06 04:34:55 +01:00
return LT_FINISH;
2019-04-16 18:00:13 +02:00
}
2019-12-07 10:08:21 +01:00
u32 ExitCheckPage(s32 taskState)
2019-04-16 18:00:13 +02:00
{
2020-10-11 00:17:34 +02:00
struct Pokenav4Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MATCH_CALL_OPEN);
2019-04-16 18:00:13 +02:00
switch (taskState)
{
case 0:
PlaySE(SE_SELECT);
2019-12-07 10:08:21 +01:00
TrainerPicSlideOffscreen(state);
2019-04-16 18:00:13 +02:00
sub_81C87F0();
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
2019-04-16 18:00:13 +02:00
case 1:
2020-10-11 00:17:34 +02:00
if (IsMatchCallListTaskActive() || WaitForTrainerPic(state))
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
2019-04-16 18:00:13 +02:00
2019-12-07 10:08:21 +01:00
PrintHelpBarText(HELPBAR_MC_TRAINER_LIST);
2019-12-06 04:34:55 +01:00
UpdateMatchCallInfoBox(state);
return LT_INC_AND_PAUSE;
2019-04-16 18:00:13 +02:00
case 2:
if (IsDma3ManagerBusyWithBgCopy())
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
2019-04-16 18:00:13 +02:00
break;
}
2019-12-06 04:34:55 +01:00
return LT_FINISH;
2019-04-16 18:00:13 +02:00
}
2019-12-07 10:08:21 +01:00
u32 ShowCheckPageUp(s32 taskState)
2019-04-16 18:00:13 +02:00
{
2019-12-07 10:08:21 +01:00
int topId;
int delta;
2020-10-11 00:17:34 +02:00
struct Pokenav4Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MATCH_CALL_OPEN);
2019-04-16 18:00:13 +02:00
switch (taskState)
{
case 0:
2019-12-07 10:08:21 +01:00
topId = GetMatchCallListTopIndex();
delta = GetIndexDeltaOfNextCheckPageUp(topId);
if (delta)
2019-04-16 18:00:13 +02:00
{
PlaySE(SE_SELECT);
2019-12-07 10:08:21 +01:00
state->unk16 = delta;
TrainerPicSlideOffscreen(state);
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
2019-04-16 18:00:13 +02:00
}
break;
case 1:
2019-12-07 10:08:21 +01:00
if (WaitForTrainerPic(state))
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
2019-04-16 18:00:13 +02:00
2019-12-06 04:34:55 +01:00
PrintMatchCallLocation(state, state->unk16);
return LT_INC_AND_PAUSE;
2019-04-16 18:00:13 +02:00
case 2:
2019-12-07 10:08:21 +01:00
PrintCheckPageInfo(state->unk16);
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
2019-04-16 18:00:13 +02:00
case 3:
2019-12-07 10:08:21 +01:00
LoadCheckPageTrainerPic(state);
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
2019-04-16 18:00:13 +02:00
case 4:
2020-10-11 00:17:34 +02:00
if (IsMatchCallListTaskActive() || WaitForTrainerPic(state))
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
2019-04-16 18:00:13 +02:00
break;
}
2019-12-06 04:34:55 +01:00
return LT_FINISH;
2019-04-16 18:00:13 +02:00
}
2019-12-07 10:08:21 +01:00
u32 ExitMatchCall(s32 taskState)
2019-04-16 18:00:13 +02:00
{
switch (taskState)
{
case 0:
PlaySE(SE_SELECT);
sub_81CBC38(0);
2020-02-05 08:47:32 +01:00
PokenavFadeScreen(0);
2020-10-11 00:17:34 +02:00
SlideMenuHeaderDown();
2019-12-06 04:34:55 +01:00
return LT_INC_AND_PAUSE;
2019-04-16 18:00:13 +02:00
case 1:
if (IsPaletteFadeActive() || MainMenuLoopedTaskIsBusy())
2019-12-06 04:34:55 +01:00
return LT_PAUSE;
2019-04-16 18:00:13 +02:00
2020-10-11 00:17:34 +02:00
SetLeftHeaderSpritesInvisibility();
2019-04-16 18:00:13 +02:00
break;
}
2019-12-06 04:34:55 +01:00
return LT_FINISH;
2019-04-16 18:00:13 +02:00
}
2020-10-11 00:17:34 +02:00
static void InitMatchCallPokenavListMenuTemplate(void)
2019-04-16 18:00:13 +02:00
{
struct PokenavListTemplate template;
template.list.matchCallEntries = sub_81CAE94();
2020-10-11 00:17:34 +02:00
template.count = GetNumberRegistered();
2019-04-16 18:00:13 +02:00
template.unk8 = 4;
template.unk6 = 0;
2020-10-11 00:17:34 +02:00
template.item_X = 13;
template.windowWidth = 16;
template.listTop = 1;
template.maxShowed = 8;
template.fillValue = 3;
template.fontId = 7;
template.listFunc.unk10_2 = BufferMatchCallNameAndDesc;
2019-12-07 10:08:21 +01:00
template.unk14 = TryDrawRematchPokeballIcon;
2020-10-11 00:17:34 +02:00
sub_81C81D4(&sMatchCallBgTemplates[2], &template, 2);
2019-04-16 18:00:13 +02:00
CreateTask(sub_81CBC64, 7);
}
static void sub_81CBC1C(void)
{
sub_81C8234();
DestroyTask(FindTaskIdByFunc(sub_81CBC64));
}
static void sub_81CBC38(int arg0)
{
u8 taskId = FindTaskIdByFunc(sub_81CBC64);
2021-02-20 05:22:26 +01:00
if (taskId != TASK_NONE)
2019-04-16 18:00:13 +02:00
gTasks[taskId].data[15] = arg0;
}
static void sub_81CBC64(u8 taskId)
{
s16 *taskData = gTasks[taskId].data;
if (taskData[15])
{
taskData[0] += 4;
taskData[0] &= 0x7F;
taskData[1] = gSineTable[taskData[0]] >> 4;
2020-10-11 00:17:34 +02:00
PokenavCopyPalette(gUnknown_08622720, gUnknown_08622720 + 0x10, 0x10, 0x10, taskData[1], gPlttBufferUnfaded + 0x50);
2019-04-16 18:00:13 +02:00
if (!gPaletteFade.active)
CpuCopy32(gPlttBufferUnfaded + 0x50, gPlttBufferFaded + 0x50, 0x20);
}
}
2019-12-07 10:08:21 +01:00
static void TryDrawRematchPokeballIcon(u16 windowId, u32 rematchId, u32 arg2)
2019-04-16 18:00:13 +02:00
{
u8 bg = GetWindowAttribute(windowId, WINDOW_BG);
u16 *tilemap = GetBgTilemapBuffer(bg);
tilemap += arg2 * 0x40 + 0x1D;
2019-12-07 10:08:21 +01:00
if (ShouldDrawRematchPokeballIcon(rematchId))
2019-04-16 18:00:13 +02:00
{
tilemap[0] = 0x5000;
tilemap[0x20] = 0x5001;
}
else
{
tilemap[0] = 0x5002;
tilemap[0x20] = 0x5002;
}
}
2019-12-07 10:08:21 +01:00
void ClearRematchPokeballIcon(u16 windowId, u32 arg0)
2019-04-16 18:00:13 +02:00
{
u8 bg = GetWindowAttribute(windowId, WINDOW_BG);
u16 *tilemap = GetBgTilemapBuffer(bg);
tilemap += arg0 * 0x40 + 0x1D;
tilemap[0] = 0x5002;
tilemap[0x20] = 0x5002;
}
2019-12-06 04:34:55 +01:00
static void DrawMatchCallLeftColumnWindows(struct Pokenav4Struct *state)
2019-04-16 18:00:13 +02:00
{
2019-12-06 04:34:55 +01:00
state->locWindowId = AddWindow(&sMatchCallLocationWindowTemplate);
state->infoBoxWindowId = AddWindow(&sMatchCallInfoBoxWindowTemplate);
FillWindowPixelBuffer(state->locWindowId, PIXEL_FILL(1));
PutWindowTilemap(state->locWindowId);
FillWindowPixelBuffer(state->infoBoxWindowId, PIXEL_FILL(1));
PutWindowTilemap(state->infoBoxWindowId);
CopyWindowToVram(state->locWindowId, 1);
2019-04-16 18:00:13 +02:00
}
2019-12-06 04:34:55 +01:00
static void UpdateMatchCallInfoBox(struct Pokenav4Struct *state)
2019-04-16 18:00:13 +02:00
{
2019-12-06 04:34:55 +01:00
FillWindowPixelBuffer(state->infoBoxWindowId, PIXEL_FILL(1));
PrintNumberRegisteredLabel(state->infoBoxWindowId);
PrintNumberRegistered(state->infoBoxWindowId);
PrintNumberOfBattlesLabel(state->infoBoxWindowId);
PrintNumberOfBattles(state->infoBoxWindowId);
CopyWindowToVram(state->infoBoxWindowId, 2);
2019-04-16 18:00:13 +02:00
}
2019-12-06 04:34:55 +01:00
static void PrintNumberRegisteredLabel(u16 windowId)
2019-04-16 18:00:13 +02:00
{
2019-12-06 04:34:55 +01:00
PrintMatchCallInfoLabel(windowId, gText_NumberRegistered, 0);
2019-04-16 18:00:13 +02:00
}
2019-12-06 04:34:55 +01:00
static void PrintNumberRegistered(u16 windowId)
2019-04-16 18:00:13 +02:00
{
u8 str[3];
2019-12-07 10:08:21 +01:00
ConvertIntToDecimalStringN(str, GetNumberRegistered(), STR_CONV_MODE_LEFT_ALIGN, 3);
2019-12-06 04:34:55 +01:00
PrintMatchCallInfoNumber(windowId, str, 1);
2019-04-16 18:00:13 +02:00
}
2019-12-06 04:34:55 +01:00
static void PrintNumberOfBattlesLabel(u16 windowId)
2019-04-16 18:00:13 +02:00
{
2019-12-06 04:34:55 +01:00
PrintMatchCallInfoLabel(windowId, gText_NumberOfBattles, 2);
2019-04-16 18:00:13 +02:00
}
2019-12-06 04:34:55 +01:00
static void PrintNumberOfBattles(u16 windowId)
2019-04-16 18:00:13 +02:00
{
u8 str[5];
int numTrainerBattles = GetGameStat(GAME_STAT_TRAINER_BATTLES);
if (numTrainerBattles > 99999)
numTrainerBattles = 99999;
ConvertIntToDecimalStringN(str, numTrainerBattles, STR_CONV_MODE_LEFT_ALIGN, 5);
2019-12-06 04:34:55 +01:00
PrintMatchCallInfoNumber(windowId, str, 3);
2019-04-16 18:00:13 +02:00
}
2019-12-06 04:34:55 +01:00
static void PrintMatchCallInfoLabel(u16 windowId, const u8 *str, int top)
2019-04-16 18:00:13 +02:00
{
int y = top * 16 + 1;
AddTextPrinterParameterized(windowId, 7, str, 2, y, TEXT_SPEED_FF, NULL);
}
2019-12-06 04:34:55 +01:00
static void PrintMatchCallInfoNumber(u16 windowId, const u8 *str, int top)
2019-04-16 18:00:13 +02:00
{
int x = GetStringRightAlignXOffset(7, str, 86);
int y = top * 16 + 1;
AddTextPrinterParameterized(windowId, 7, str, x, y, TEXT_SPEED_FF, NULL);
}
2019-12-06 04:34:55 +01:00
static void PrintMatchCallLocation(struct Pokenav4Struct *state, int arg1)
2019-04-16 18:00:13 +02:00
{
u8 mapName[32];
int x;
2020-10-11 00:17:34 +02:00
int index = GetSelectedPokenavListIndex() + arg1;
2019-12-07 10:08:21 +01:00
int mapSec = GetMatchCallMapSec(index);
if (mapSec != MAPSEC_NONE)
GetMapName(mapName, mapSec, 0);
2019-04-16 18:00:13 +02:00
else
StringCopy(mapName, gText_Unknown);
x = GetStringCenterAlignXOffset(7, mapName, 88);
2019-12-06 04:34:55 +01:00
FillWindowPixelBuffer(state->locWindowId, PIXEL_FILL(1));
AddTextPrinterParameterized(state->locWindowId, 7, mapName, x, 1, 0, NULL);
2019-04-16 18:00:13 +02:00
}
2019-12-06 04:34:55 +01:00
static void PrintMatchCallSelectionOptions(struct Pokenav4Struct *state)
2019-04-16 18:00:13 +02:00
{
u32 i;
2019-12-06 04:34:55 +01:00
FillWindowPixelBuffer(state->infoBoxWindowId, PIXEL_FILL(1));
2019-12-05 21:33:36 +01:00
for (i = 0; i < MATCH_CALL_OPTION_COUNT; i++)
2019-04-16 18:00:13 +02:00
{
2019-12-07 10:08:21 +01:00
int optionText = GetMatchCallOptionId(i);
2019-12-05 21:33:36 +01:00
if (optionText == MATCH_CALL_OPTION_COUNT)
2019-04-16 18:00:13 +02:00
break;
2019-12-06 04:34:55 +01:00
AddTextPrinterParameterized(state->infoBoxWindowId, 7, sMatchCallOptionTexts[optionText], 16, i * 16 + 1, TEXT_SPEED_FF, NULL);
2019-04-16 18:00:13 +02:00
}
2019-12-06 04:34:55 +01:00
CopyWindowToVram(state->infoBoxWindowId, 2);
2019-04-16 18:00:13 +02:00
}
static bool32 sub_81CBFC4(struct Pokenav4Struct *state)
{
if (!IsDma3ManagerBusyWithBgCopy())
{
2019-12-07 10:08:21 +01:00
sub_81CC2F0(state, GetMatchCallOptionCursorPos());
2019-04-16 18:00:13 +02:00
return FALSE;
}
return TRUE;
}
2019-12-07 10:08:21 +01:00
static void UpdateWindowsReturnToTrainerList(struct Pokenav4Struct *state)
2019-04-16 18:00:13 +02:00
{
2019-12-06 04:34:55 +01:00
CloseMatchCallSelectOptionsWindow(state);
UpdateMatchCallInfoBox(state);
2019-04-16 18:00:13 +02:00
}
2019-12-07 10:08:21 +01:00
static bool32 IsDma3ManagerBusyWithBgCopy1(struct Pokenav4Struct *state)
2019-04-16 18:00:13 +02:00
{
return IsDma3ManagerBusyWithBgCopy();
}
2019-12-07 10:08:21 +01:00
static void UpdateWindowsToShowCheckPage(struct Pokenav4Struct *state)
2019-04-16 18:00:13 +02:00
{
2019-12-06 04:34:55 +01:00
CloseMatchCallSelectOptionsWindow(state);
FillWindowPixelBuffer(state->infoBoxWindowId, PIXEL_FILL(1));
CopyWindowToVram(state->infoBoxWindowId, 2);
2019-04-16 18:00:13 +02:00
}
static void sub_81CC034(struct Pokenav4Struct *state)
{
2019-12-07 10:08:21 +01:00
state->msgBoxWindowId = AddWindow(&sCallMsgBoxWindowTemplate);
2019-12-06 04:34:55 +01:00
sub_8197184(state->msgBoxWindowId, 1, 4);
2019-04-16 18:00:13 +02:00
sub_81C7B40();
}
2019-12-07 10:08:21 +01:00
static void DrawMsgBoxForMatchCallMsg(struct Pokenav4Struct *state)
2019-04-16 18:00:13 +02:00
{
struct Sprite *sprite;
2019-12-06 04:34:55 +01:00
sub_8197184(state->msgBoxWindowId, 1, 4);
sub_81971C4(state->msgBoxWindowId, 1, 4);
FillWindowPixelBuffer(state->msgBoxWindowId, PIXEL_FILL(1));
PutWindowTilemap(state->msgBoxWindowId);
CopyWindowToVram(state->msgBoxWindowId, 3);
2019-04-16 18:00:13 +02:00
sprite = PauseSpinningPokenavSprite();
sprite->pos1.x = 24;
sprite->pos1.y = 112;
sprite->pos2.y = 0;
}
2019-12-07 10:08:21 +01:00
static void DrawMsgBoxForCloseByMsg(struct Pokenav4Struct *state)
2019-04-16 18:00:13 +02:00
{
2019-12-06 04:34:55 +01:00
LoadUserWindowBorderGfx(state->msgBoxWindowId, 1, 0x40);
DrawTextBorderOuter(state->msgBoxWindowId, 1, 4);
FillWindowPixelBuffer(state->msgBoxWindowId, PIXEL_FILL(1));
PutWindowTilemap(state->msgBoxWindowId);
CopyWindowToVram(state->msgBoxWindowId, 3);
2019-04-16 18:00:13 +02:00
}
2019-12-07 10:08:21 +01:00
static bool32 IsDma3ManagerBusyWithBgCopy2(struct Pokenav4Struct *state)
2019-04-16 18:00:13 +02:00
{
return IsDma3ManagerBusyWithBgCopy();
}
2019-12-06 04:34:55 +01:00
static void PrintCallingDots(struct Pokenav4Struct *state)
2019-04-16 18:00:13 +02:00
{
2019-12-07 10:08:21 +01:00
AddTextPrinterParameterized(state->msgBoxWindowId, 1, sText_CallingDots, 32, 1, 1, NULL);
2019-04-16 18:00:13 +02:00
}
2019-12-06 04:34:55 +01:00
static bool32 WaitForCallingDotsText(struct Pokenav4Struct *state)
2019-04-16 18:00:13 +02:00
{
RunTextPrinters();
2019-12-06 04:34:55 +01:00
return IsTextPrinterActive(state->msgBoxWindowId);
2019-04-16 18:00:13 +02:00
}
2019-12-06 04:34:55 +01:00
static void PrintTrainerIsCloseBy(struct Pokenav4Struct *state)
2019-04-16 18:00:13 +02:00
{
2019-12-06 04:34:55 +01:00
AddTextPrinterParameterized(state->msgBoxWindowId, 1, gText_TrainerCloseBy, 0, 1, 1, NULL);
2019-04-16 18:00:13 +02:00
}
2019-12-06 04:34:55 +01:00
static bool32 WaitForTrainerIsCloseByText(struct Pokenav4Struct *state)
2019-04-16 18:00:13 +02:00
{
RunTextPrinters();
2019-12-06 04:34:55 +01:00
return IsTextPrinterActive(state->msgBoxWindowId);
2019-04-16 18:00:13 +02:00
}
2019-12-06 04:34:55 +01:00
static void PrintMatchCallMessage(struct Pokenav4Struct *state)
2019-04-16 18:00:13 +02:00
{
2020-10-11 00:17:34 +02:00
int index = GetSelectedPokenavListIndex();
2019-12-06 04:34:55 +01:00
const u8 *str = GetMatchCallMessageText(index, &state->unkF);
2019-04-16 18:00:13 +02:00
u8 speed = GetPlayerTextSpeedDelay();
2019-12-06 04:34:55 +01:00
AddTextPrinterParameterized(state->msgBoxWindowId, 1, str, 32, 1, speed, NULL);
2019-04-16 18:00:13 +02:00
}
2019-12-06 04:34:55 +01:00
static bool32 WaitForMatchCallMessageText(struct Pokenav4Struct *state)
2019-04-16 18:00:13 +02:00
{
2020-09-05 03:11:55 +02:00
if (JOY_HELD(A_BUTTON))
2019-04-16 18:00:13 +02:00
gTextFlags.canABSpeedUpPrint = 1;
else
gTextFlags.canABSpeedUpPrint = 0;
RunTextPrinters();
2019-12-06 04:34:55 +01:00
return IsTextPrinterActive(state->msgBoxWindowId);
2019-04-16 18:00:13 +02:00
}
2019-12-07 10:08:21 +01:00
static void DrawSpinningPokenavForCall(struct Pokenav4Struct *state)
2019-04-16 18:00:13 +02:00
{
ResumeSpinningPokenavSprite();
FillBgTilemapBufferRect_Palette0(1, 0, 0, 0, 32, 20);
CopyBgTilemapBufferToVram(1);
}
2019-12-07 10:08:21 +01:00
static bool32 WaitForSpinningPokenav(struct Pokenav4Struct *state)
2019-04-16 18:00:13 +02:00
{
2019-12-07 10:08:21 +01:00
return IsDma3ManagerBusyWithBgCopy();
2019-04-16 18:00:13 +02:00
}
static void sub_81CC214(void)
{
int i;
u8 paletteNum;
struct SpriteSheet spriteSheet;
2020-10-11 00:17:34 +02:00
struct Pokenav4Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MATCH_CALL_OPEN);
2019-04-16 18:00:13 +02:00
for (i = 0; i < ARRAY_COUNT(gUnknown_08622810); i++)
LoadCompressedSpriteSheet(&gUnknown_08622810[i]);
Pokenav_AllocAndLoadPalettes(gUnknown_08622818);
2019-12-07 10:08:21 +01:00
state->optionsCursorSprite = NULL;
2019-04-16 18:00:13 +02:00
spriteSheet.data = state->unk1828;
spriteSheet.size = 0x800;
spriteSheet.tag = 8;
state->unk1824 = (u8 *)OBJ_VRAM0 + LoadSpriteSheet(&spriteSheet) * 0x20;
paletteNum = AllocSpritePalette(13);
state->unk1A = 0x100 + paletteNum * 0x10;
2019-12-07 10:08:21 +01:00
state->trainerPicSprite = CreateTrainerPicSprite();
state->trainerPicSprite->invisible = TRUE;
2019-04-16 18:00:13 +02:00
}
2020-10-11 00:17:34 +02:00
static void RemoveMatchCallSprites(void)
2019-04-16 18:00:13 +02:00
{
2020-10-11 00:17:34 +02:00
struct Pokenav4Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MATCH_CALL_OPEN);
2019-12-07 10:08:21 +01:00
if (state->optionsCursorSprite)
DestroySprite(state->optionsCursorSprite);
if (state->trainerPicSprite)
DestroySprite(state->trainerPicSprite);
2019-04-16 18:00:13 +02:00
FreeSpriteTilesByTag(8);
FreeSpriteTilesByTag(7);
FreeSpritePaletteByTag(12);
FreeSpritePaletteByTag(13);
}
static void sub_81CC2F0(struct Pokenav4Struct *state, int top)
{
2019-12-07 10:08:21 +01:00
if (!state->optionsCursorSprite)
2019-04-16 18:00:13 +02:00
{
2019-12-07 10:08:21 +01:00
u8 spriteId = CreateSprite(&sOptionsCursorSpriteTemplate, 4, 80, 5);
state->optionsCursorSprite = &gSprites[spriteId];
UpdateCursorGfxPos(state, top);
2019-04-16 18:00:13 +02:00
}
}
2019-12-06 04:34:55 +01:00
static void CloseMatchCallSelectOptionsWindow(struct Pokenav4Struct *state)
2019-04-16 18:00:13 +02:00
{
2019-12-07 10:08:21 +01:00
DestroySprite(state->optionsCursorSprite);
state->optionsCursorSprite = NULL;
2019-04-16 18:00:13 +02:00
}
2019-12-07 10:08:21 +01:00
static void UpdateCursorGfxPos(struct Pokenav4Struct *state, int top)
2019-04-16 18:00:13 +02:00
{
2019-12-07 10:08:21 +01:00
state->optionsCursorSprite->pos2.y = top * 16;
2019-04-16 18:00:13 +02:00
}
2019-12-07 10:08:21 +01:00
void SpriteCB_OptionsCursor(struct Sprite *sprite)
2019-04-16 18:00:13 +02:00
{
if (++sprite->data[0] > 3)
{
sprite->data[0] = 0;
sprite->pos2.x = (sprite->pos2.x + 1) & 0x7;
}
}
2019-12-07 10:08:21 +01:00
static struct Sprite *CreateTrainerPicSprite(void)
2019-04-16 18:00:13 +02:00
{
2019-12-07 10:08:21 +01:00
u8 spriteId = CreateSprite(&sTrainerPicSpriteTemplate, 44, 104, 6);
2019-04-16 18:00:13 +02:00
return &gSprites[spriteId];
}
2019-12-07 10:08:21 +01:00
static void LoadCheckPageTrainerPic(struct Pokenav4Struct *state)
2019-04-16 18:00:13 +02:00
{
u16 cursor;
2020-10-11 00:17:34 +02:00
int trainerPic = GetMatchCallTrainerPic(GetSelectedPokenavListIndex());
2019-12-05 21:33:36 +01:00
if (trainerPic >= 0)
2019-04-16 18:00:13 +02:00
{
2019-12-05 21:33:36 +01:00
DecompressPicFromTable(&gTrainerFrontPicTable[trainerPic], state->unk1828, SPECIES_NONE);
LZ77UnCompWram(gTrainerFrontPicPaletteTable[trainerPic].data, state->unk2028);
2019-04-16 18:00:13 +02:00
cursor = RequestDma3Copy(state->unk1828, state->unk1824, 0x800, 1);
LoadPalette(state->unk2028, state->unk1A, 0x20);
2019-12-07 10:08:21 +01:00
state->trainerPicSprite->data[0] = 0;
state->trainerPicSprite->data[7] = cursor;
state->trainerPicSprite->callback = SpriteCB_TrainerPicSlideOnscreen;
2019-04-16 18:00:13 +02:00
}
}
2019-12-07 10:08:21 +01:00
static void TrainerPicSlideOffscreen(struct Pokenav4Struct *state)
2019-04-16 18:00:13 +02:00
{
2019-12-07 10:08:21 +01:00
state->trainerPicSprite->callback = SpriteCB_TrainerPicSlideOffscreen;
2019-04-16 18:00:13 +02:00
}
2019-12-07 10:08:21 +01:00
static bool32 WaitForTrainerPic(struct Pokenav4Struct *state)
2019-04-16 18:00:13 +02:00
{
2019-12-07 10:08:21 +01:00
return state->trainerPicSprite->callback != SpriteCallbackDummy;
2019-04-16 18:00:13 +02:00
}
2019-12-07 10:08:21 +01:00
static void SpriteCB_TrainerPicSlideOnscreen(struct Sprite *sprite)
2019-04-16 18:00:13 +02:00
{
switch (sprite->data[0])
{
case 0:
if (CheckForSpaceForDma3Request(sprite->data[7]) != -1)
{
sprite->pos2.x = -80;
2019-12-07 10:08:21 +01:00
sprite->invisible = FALSE;
2019-04-16 18:00:13 +02:00
sprite->data[0]++;
}
break;
case 1:
sprite->pos2.x += 8;
if (sprite->pos2.x >= 0)
{
sprite->pos2.x = 0;
sprite->callback = SpriteCallbackDummy;
}
break;
}
}
2019-12-07 10:08:21 +01:00
static void SpriteCB_TrainerPicSlideOffscreen(struct Sprite *sprite)
2019-04-16 18:00:13 +02:00
{
sprite->pos2.x -= 8;
if (sprite->pos2.x <= -80)
{
2019-12-07 10:08:21 +01:00
sprite->invisible = TRUE;
2019-04-16 18:00:13 +02:00
sprite->callback = SpriteCallbackDummy;
}
}