pokeemerald/src/pokenav_conditions_gfx.c

893 lines
30 KiB
C
Raw Normal View History

2019-07-20 04:06:42 +02:00
#include "global.h"
#include "bg.h"
#include "window.h"
#include "pokenav.h"
2019-07-24 17:02:52 +02:00
#include "decompress.h"
#include "gpu_regs.h"
#include "graphics.h"
#include "menu.h"
#include "menu_specialized.h"
#include "mon_markings.h"
#include "palette.h"
#include "pokenav.h"
#include "scanline_effect.h"
#include "string_util.h"
#include "strings.h"
#include "text.h"
2019-07-20 04:06:42 +02:00
2021-11-10 02:02:12 +01:00
static u32 LoopedTask_TransitionMons(s32);
2021-11-11 22:50:36 +01:00
static u32 LoopedTask_ExitConditionGraphMenu(s32);
2021-11-10 02:02:12 +01:00
static u32 LoopedTask_MoveCursorNoTransition(s32);
static u32 LoopedTask_SlideMonOut(s32);
static u32 LoopedTask_OpenMonMarkingsWindow(s32);
static u32 LoopedTask_CloseMonMarkingsWindow(s32);
2019-07-20 04:06:42 +02:00
2021-11-11 22:50:36 +01:00
static u8 sInitialLoadId; // Never read
2019-07-20 18:30:41 +02:00
2020-08-10 19:48:16 +02:00
const u16 gConditionGraphData_Pal[] = INCBIN_U16("graphics/pokenav/condition/graph_data.gbapal");
2020-08-10 23:05:42 +02:00
const u16 gConditionText_Pal[] = INCBIN_U16("graphics/pokenav/condition/text.gbapal");
2021-11-11 22:50:36 +01:00
static const u32 sConditionGraphData_Gfx[] = INCBIN_U32("graphics/pokenav/condition/graph_data.4bpp.lz");
static const u32 sConditionGraphData_Tilemap[] = INCBIN_U32("graphics/pokenav/condition/graph_data.bin.lz");
static const u16 sMonMarkings_Pal[] = INCBIN_U16("graphics/pokenav/condition/mon_markings.gbapal");
2019-07-20 04:06:42 +02:00
2021-11-11 22:50:36 +01:00
static const struct BgTemplate sMenuBgTemplates[3] =
2019-07-20 04:06:42 +02:00
{
{
.bg = 1,
.charBaseIndex = 1,
.mapBaseIndex = 0x1F,
.screenSize = 0,
.paletteMode = 0,
.priority = 1,
.baseTile = 0
},
{
.bg = 2,
.charBaseIndex = 3,
.mapBaseIndex = 0x1D,
.screenSize = 0,
.paletteMode = 0,
.priority = 2,
.baseTile = 0
},
{
.bg = 3,
.charBaseIndex = 2,
.mapBaseIndex = 0x1E,
.screenSize = 0,
.paletteMode = 0,
.priority = 3,
.baseTile = 0
}
};
2021-11-10 02:02:12 +01:00
static const struct WindowTemplate sMonNameGenderWindowTemplate =
2019-07-20 04:06:42 +02:00
{
.bg = 1,
.tilemapLeft = 13,
.tilemapTop = 1,
.width = 13,
.height = 4,
.paletteNum = 15,
.baseBlock = 2
};
2021-11-11 22:50:36 +01:00
static const struct WindowTemplate sListIndexWindowTemplate =
2019-07-20 04:06:42 +02:00
{
.bg = 1,
.tilemapLeft = 1,
.tilemapTop = 6,
.width = 7,
.height = 2,
.paletteNum = 15,
.baseBlock = 0x36
};
2021-11-10 02:02:12 +01:00
static const struct WindowTemplate sUnusedWindowTemplate1 =
2019-07-20 04:06:42 +02:00
{
.bg = 1,
.tilemapLeft = 1,
.tilemapTop = 0x1C,
.width = 5,
.height = 2,
.paletteNum = 15,
.baseBlock = 0x44
};
2021-11-10 02:02:12 +01:00
static const struct WindowTemplate sUnusedWindowTemplate2 =
2019-07-20 04:06:42 +02:00
{
.bg = 1,
.tilemapLeft = 13,
.tilemapTop = 0x1C,
.width = 3,
.height = 2,
.paletteNum = 15,
.baseBlock = 0x44
};
2021-11-11 22:50:36 +01:00
static const LoopedTask sLoopedTaskFuncs[] =
2019-07-20 04:06:42 +02:00
{
2021-11-11 22:50:36 +01:00
[CONDITION_FUNC_NONE] = NULL,
[CONDITION_FUNC_SLIDE_MON_IN] = LoopedTask_TransitionMons,
[CONDITION_FUNC_RETURN] = LoopedTask_ExitConditionGraphMenu,
[CONDITION_FUNC_NO_TRANSITION] = LoopedTask_MoveCursorNoTransition,
[CONDITION_FUNC_SLIDE_MON_OUT] = LoopedTask_SlideMonOut,
[CONDITION_FUNC_ADD_MARKINGS] = LoopedTask_OpenMonMarkingsWindow,
[CONDITION_FUNC_CLOSE_MARKINGS] = LoopedTask_CloseMonMarkingsWindow
2019-07-20 04:06:42 +02:00
};
2019-07-29 19:06:45 +02:00
2021-11-11 22:50:36 +01:00
struct Pokenav_ConditionMenuGfx
2019-07-24 17:02:52 +02:00
{
u32 loopedTaskId;
u8 tilemapBuffers[3][BG_SCREEN_SIZE];
u8 filler[2];
2021-11-11 22:50:36 +01:00
u8 partyPokeballSpriteIds[PARTY_SIZE + 1];
2020-10-11 00:17:34 +02:00
u32 (*callback)(void);
s16 monTransitionX;
u8 monPicSpriteId;
u16 monPalIndex;
u16 monGfxTileStart;
2021-11-11 22:50:36 +01:00
void *monGfxPtr;
2020-10-11 00:17:34 +02:00
u8 nameGenderWindowId;
u8 listIndexWindowId;
u8 unusedWindowId1;
u8 unusedWindowId2;
2021-11-10 02:02:12 +01:00
struct MonMarkingsMenu marksMenu;
2020-10-11 00:17:34 +02:00
struct Sprite *monMarksSprite;
struct Sprite *conditionSparkleSprites[MAX_CONDITION_SPARKLES];
u8 windowModeState;
2021-11-10 02:02:12 +01:00
u8 filler2[0xFA3];
2019-07-24 17:02:52 +02:00
};
2021-11-12 17:07:52 +01:00
extern s8 GetConditionGraphMenuCurrentLoadIndex(void); // This function's declaration here is s8 vs. u8 in pokenav_conditions.c
2019-07-25 18:56:08 +02:00
2021-11-11 22:50:36 +01:00
static u32 LoopedTask_OpenConditionGraphMenu(s32);
static u32 GetConditionGraphMenuLoopedTaskActive(void);
static void CreateConditionMonPic(u8);
2021-11-10 02:02:12 +01:00
static void CreateMonMarkingsOrPokeballIndicators(void);
static void CopyUnusedConditionWindowsToVram(void);
2021-11-11 22:50:36 +01:00
static bool32 UpdateConditionGraphMenuWindows(u8, u16, bool8);
2021-11-11 00:52:30 +01:00
static void VBlankCB_PokenavConditionGraph(void);
2021-11-11 22:50:36 +01:00
static void DoConditionGraphEnterTransition(void);
static void DoConditionGraphExitTransition(void);
static void SetExitVBlank(void);
static void ToggleGraphData(bool8);
2019-07-24 17:02:52 +02:00
2021-11-11 22:50:36 +01:00
bool32 OpenConditionGraphMenu(void)
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_ConditionMenuGfx *menu = AllocSubstruct(POKENAV_SUBSTRUCT_CONDITION_GRAPH_MENU_GFX, sizeof(struct Pokenav_ConditionMenuGfx));
2019-07-24 17:02:52 +02:00
2021-11-11 22:50:36 +01:00
if (menu == NULL)
2019-07-24 17:02:52 +02:00
return FALSE;
2021-11-11 22:50:36 +01:00
menu->monPicSpriteId = SPRITE_NONE;
menu->loopedTaskId = CreateLoopedTask(LoopedTask_OpenConditionGraphMenu, 1);
menu->callback = GetConditionGraphMenuLoopedTaskActive;
menu->windowModeState = 0;
2019-07-24 17:02:52 +02:00
return TRUE;
}
2021-11-11 22:50:36 +01:00
void CreateConditionGraphMenuLoopedTask(s32 id)
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_ConditionMenuGfx *menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_GRAPH_MENU_GFX);
menu->loopedTaskId = CreateLoopedTask(sLoopedTaskFuncs[id], 1);
menu->callback = GetConditionGraphMenuLoopedTaskActive;
2019-07-24 17:02:52 +02:00
}
2021-11-11 22:50:36 +01:00
u32 IsConditionGraphMenuLoopedTaskActive(void)
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_ConditionMenuGfx *menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_GRAPH_MENU_GFX);
return menu->callback();
2019-07-24 17:02:52 +02:00
}
2021-11-11 22:50:36 +01:00
static u32 GetConditionGraphMenuLoopedTaskActive(void)
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_ConditionMenuGfx *menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_GRAPH_MENU_GFX);
return IsLoopedTaskActive(menu->loopedTaskId);
2019-07-24 17:02:52 +02:00
}
2021-11-11 22:50:36 +01:00
static u32 LoopedTask_OpenConditionGraphMenu(s32 state)
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_ConditionMenuGfx *menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_GRAPH_MENU_GFX);
2019-07-24 17:02:52 +02:00
switch (state)
{
case 0:
2021-11-11 22:50:36 +01:00
if (LoadConditionGraphMenuGfx() != TRUE)
2019-12-07 10:08:21 +01:00
return LT_PAUSE;
return LT_INC_AND_PAUSE;
2019-07-24 17:02:52 +02:00
case 1:
2021-11-11 22:50:36 +01:00
InitBgTemplates(sMenuBgTemplates, ARRAY_COUNT(sMenuBgTemplates));
2021-11-04 04:02:06 +01:00
ChangeBgX(1, 0, BG_COORD_SET);
ChangeBgY(1, 0, BG_COORD_SET);
ChangeBgX(2, 0, BG_COORD_SET);
ChangeBgY(2, 0, BG_COORD_SET);
ChangeBgX(3, 0, BG_COORD_SET);
ChangeBgY(3, 0, BG_COORD_SET);
2019-07-24 17:02:52 +02:00
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_WIN0_ON | DISPCNT_WIN1_ON | DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP | DISPCNT_BG0_ON | DISPCNT_BG3_ON);
SetGpuReg(REG_OFFSET_BLDCNT, BLDCNT_TGT1_BG2 | BLDCNT_EFFECT_BLEND | BLDCNT_TGT2_BG3);
SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(11, 4));
2020-05-14 10:37:09 +02:00
DecompressAndCopyTileDataToVram(3, gPokenavCondition_Gfx, 0, 0, 0);
2019-12-07 10:08:21 +01:00
return LT_INC_AND_PAUSE;
2019-07-24 17:02:52 +02:00
case 2:
2020-05-14 10:37:09 +02:00
if (FreeTempTileDataBuffersIfPossible())
2019-12-07 10:08:21 +01:00
return LT_PAUSE;
2021-11-11 22:50:36 +01:00
DecompressAndCopyTileDataToVram(2, sConditionGraphData_Gfx, 0, 0, 0);
2019-12-07 10:08:21 +01:00
return LT_INC_AND_PAUSE;
2019-07-24 17:02:52 +02:00
case 3:
2020-05-14 10:37:09 +02:00
if (FreeTempTileDataBuffersIfPossible())
2019-12-07 10:08:21 +01:00
return LT_PAUSE;
2019-07-24 17:02:52 +02:00
2021-11-11 22:50:36 +01:00
LZ77UnCompVram(gPokenavCondition_Tilemap, menu->tilemapBuffers[0]);
SetBgTilemapBuffer(3, menu->tilemapBuffers[0]);
2020-10-11 00:17:34 +02:00
if (IsConditionMenuSearchMode() == TRUE)
2019-07-24 17:02:52 +02:00
CopyToBgTilemapBufferRect(3, gPokenavOptions_Tilemap, 0, 5, 9, 4);
CopyBgTilemapBufferToVram(3);
CopyPaletteIntoBufferUnfaded(gPokenavCondition_Pal, 0x10, 0x20);
2020-08-10 23:05:42 +02:00
CopyPaletteIntoBufferUnfaded(gConditionText_Pal, 0xF0, 0x20);
2021-11-11 22:50:36 +01:00
menu->monTransitionX = -80;
2019-12-07 10:08:21 +01:00
return LT_INC_AND_PAUSE;
2019-07-24 17:02:52 +02:00
case 4:
2020-05-14 10:37:09 +02:00
if (FreeTempTileDataBuffersIfPossible())
2019-12-07 10:08:21 +01:00
return LT_PAUSE;
2019-07-24 17:02:52 +02:00
2021-11-11 22:50:36 +01:00
LZ77UnCompVram(sConditionGraphData_Tilemap, menu->tilemapBuffers[2]);
SetBgTilemapBuffer(2, menu->tilemapBuffers[2]);
2019-07-24 17:02:52 +02:00
CopyBgTilemapBufferToVram(2);
2020-08-10 19:48:16 +02:00
CopyPaletteIntoBufferUnfaded(gConditionGraphData_Pal, 0x30, 0x20);
2021-11-11 00:52:30 +01:00
ConditionGraph_InitWindow(2);
2019-12-07 10:08:21 +01:00
return LT_INC_AND_PAUSE;
2019-07-24 17:02:52 +02:00
case 5:
2021-11-04 04:20:59 +01:00
BgDmaFill(1, 0, 0, 1);
BgDmaFill(1, 17, 1, 1);
2021-11-11 22:50:36 +01:00
CpuFill32(0, menu->tilemapBuffers[1], BG_SCREEN_SIZE);
SetBgTilemapBuffer(1, menu->tilemapBuffers[1]);
2019-12-07 10:08:21 +01:00
return LT_INC_AND_PAUSE;
2019-07-24 17:02:52 +02:00
case 6:
2020-05-14 10:37:09 +02:00
if (FreeTempTileDataBuffersIfPossible())
2019-12-07 10:08:21 +01:00
return LT_PAUSE;
2019-07-24 17:02:52 +02:00
2021-11-11 22:50:36 +01:00
menu->nameGenderWindowId = AddWindow(&sMonNameGenderWindowTemplate);
2020-10-11 00:17:34 +02:00
if (IsConditionMenuSearchMode() == TRUE)
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
menu->listIndexWindowId = AddWindow(&sListIndexWindowTemplate);
menu->unusedWindowId1 = AddWindow(&sUnusedWindowTemplate1);
menu->unusedWindowId2 = AddWindow(&sUnusedWindowTemplate2);
2019-07-24 17:02:52 +02:00
}
DeactivateAllTextPrinters();
2019-12-07 10:08:21 +01:00
return LT_INC_AND_PAUSE;
2019-07-24 17:02:52 +02:00
case 7:
2020-10-11 00:17:34 +02:00
CreateConditionMonPic(0);
2019-12-07 10:08:21 +01:00
return LT_INC_AND_PAUSE;
2019-07-24 17:02:52 +02:00
case 8:
2020-10-11 00:17:34 +02:00
CreateMonMarkingsOrPokeballIndicators();
2019-12-07 10:08:21 +01:00
return LT_INC_AND_PAUSE;
2019-07-24 17:02:52 +02:00
case 9:
2020-10-11 00:17:34 +02:00
if (IsConditionMenuSearchMode() == TRUE)
CopyUnusedConditionWindowsToVram();
2019-12-07 10:08:21 +01:00
return LT_INC_AND_PAUSE;
2019-07-24 17:02:52 +02:00
case 10:
2021-11-11 22:50:36 +01:00
UpdateConditionGraphMenuWindows(0, GetConditionGraphMenuCurrentLoadIndex(), TRUE);
2019-12-07 10:08:21 +01:00
return LT_INC_AND_PAUSE;
2019-07-24 17:02:52 +02:00
case 11:
2021-11-11 22:50:36 +01:00
UpdateConditionGraphMenuWindows(1, GetConditionGraphMenuCurrentLoadIndex(), TRUE);
2019-12-07 10:08:21 +01:00
return LT_INC_AND_PAUSE;
2019-07-24 17:02:52 +02:00
case 12:
2021-11-11 22:50:36 +01:00
UpdateConditionGraphMenuWindows(2, GetConditionGraphMenuCurrentLoadIndex(), TRUE);
2019-12-07 10:08:21 +01:00
return LT_INC_AND_PAUSE;
2019-07-24 17:02:52 +02:00
case 13:
2021-11-11 22:50:36 +01:00
if (UpdateConditionGraphMenuWindows(3, GetConditionGraphMenuCurrentLoadIndex(), TRUE) != TRUE)
2019-12-07 10:08:21 +01:00
return LT_PAUSE;
2021-11-11 22:50:36 +01:00
PutWindowTilemap(menu->nameGenderWindowId);
2020-10-11 00:17:34 +02:00
if (IsConditionMenuSearchMode() == TRUE)
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
PutWindowTilemap(menu->listIndexWindowId);
PutWindowTilemap(menu->unusedWindowId1);
PutWindowTilemap(menu->unusedWindowId2);
2019-07-24 17:02:52 +02:00
}
2019-12-07 10:08:21 +01:00
return LT_INC_AND_PAUSE;
2019-07-24 17:02:52 +02:00
case 14:
ShowBg(1);
HideBg(2);
ShowBg(3);
2020-10-11 00:17:34 +02:00
if (IsConditionMenuSearchMode() == TRUE)
2019-12-07 10:08:21 +01:00
PrintHelpBarText(HELPBAR_CONDITION_MON_STATUS);
return LT_INC_AND_PAUSE;
2019-07-24 17:02:52 +02:00
case 15:
2021-11-12 23:28:06 +01:00
PokenavFadeScreen(POKENAV_FADE_FROM_BLACK);
2020-10-11 00:17:34 +02:00
if (!IsConditionMenuSearchMode())
2019-07-24 17:02:52 +02:00
{
2020-10-11 00:17:34 +02:00
LoadLeftHeaderGfxForIndex(POKENAV_GFX_PARTY_MENU);
2022-07-25 20:59:14 +02:00
ShowLeftHeaderGfx(POKENAV_GFX_CONDITION_MENU, TRUE, FALSE);
ShowLeftHeaderGfx(POKENAV_GFX_PARTY_MENU, TRUE, FALSE);
2019-07-24 17:02:52 +02:00
}
2019-12-07 10:08:21 +01:00
return LT_INC_AND_PAUSE;
2019-07-24 17:02:52 +02:00
case 16:
if (IsPaletteFadeActive())
2019-12-07 10:08:21 +01:00
return LT_PAUSE;
2020-10-11 00:17:34 +02:00
if (!IsConditionMenuSearchMode() && AreLeftHeaderSpritesMoving())
2019-12-07 10:08:21 +01:00
return LT_PAUSE;
2021-11-11 00:52:30 +01:00
SetVBlankCallback_(VBlankCB_PokenavConditionGraph);
2019-12-07 10:08:21 +01:00
return LT_INC_AND_PAUSE;
2019-07-24 17:02:52 +02:00
case 17:
2021-11-11 22:50:36 +01:00
DoConditionGraphEnterTransition();
2021-11-11 00:52:30 +01:00
ConditionGraph_InitResetScanline(GetConditionGraphPtr());
2019-12-07 10:08:21 +01:00
return LT_INC_AND_PAUSE;
2019-07-24 17:02:52 +02:00
case 18:
2021-11-11 00:52:30 +01:00
if (ConditionGraph_ResetScanline(GetConditionGraphPtr()))
2019-12-07 10:08:21 +01:00
return LT_PAUSE;
return LT_INC_AND_PAUSE;
2019-07-24 17:02:52 +02:00
case 19:
2021-11-10 02:02:12 +01:00
ToggleGraphData(TRUE);
2019-12-07 10:08:21 +01:00
return LT_INC_AND_PAUSE;
2019-07-24 17:02:52 +02:00
case 20:
2021-11-11 22:50:36 +01:00
if (!ConditionMenu_UpdateMonEnter(GetConditionGraphPtr(), &menu->monTransitionX))
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
ResetConditionSparkleSprites(menu->conditionSparkleSprites);
if (IsConditionMenuSearchMode() == TRUE || GetConditionGraphCurrentListIndex() != GetMonListCount())
CreateConditionSparkleSprites(menu->conditionSparkleSprites, menu->monPicSpriteId, GetNumConditionMonSparkles());
2019-07-24 17:02:52 +02:00
2019-12-07 10:08:21 +01:00
return LT_FINISH;
2019-07-24 17:02:52 +02:00
}
2019-12-07 10:08:21 +01:00
return LT_PAUSE;
2019-07-24 17:02:52 +02:00
}
2019-12-07 10:08:21 +01:00
return LT_FINISH;
2019-07-24 17:02:52 +02:00
}
2021-11-11 22:50:36 +01:00
static u32 LoopedTask_ExitConditionGraphMenu(s32 state)
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_ConditionMenuGfx *menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_GRAPH_MENU_GFX);
2019-07-24 17:02:52 +02:00
switch (state)
{
case 0:
2021-11-11 22:50:36 +01:00
DoConditionGraphExitTransition();
DestroyConditionSparkleSprites(menu->conditionSparkleSprites);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 1:
2021-11-11 22:50:36 +01:00
if (ConditionMenu_UpdateMonExit(GetConditionGraphPtr(), &menu->monTransitionX))
2019-07-24 17:02:52 +02:00
return 2;
2021-11-10 02:02:12 +01:00
ToggleGraphData(FALSE);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 2:
2021-11-12 23:28:06 +01:00
PokenavFadeScreen(POKENAV_FADE_TO_BLACK);
2020-10-11 00:17:34 +02:00
if (!IsConditionMenuSearchMode())
SlideMenuHeaderDown();
return LT_INC_AND_PAUSE;
2019-07-24 17:02:52 +02:00
case 3:
if (IsPaletteFadeActive() || MainMenuLoopedTaskIsBusy())
2020-10-11 00:17:34 +02:00
return LT_PAUSE;
2021-11-11 22:50:36 +01:00
FreeConditionSparkles(menu->conditionSparkleSprites);
2019-07-24 17:02:52 +02:00
HideBg(1);
HideBg(2);
HideBg(3);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
}
2019-12-07 10:08:21 +01:00
return LT_FINISH;
2019-07-24 17:02:52 +02:00
}
2021-11-10 02:02:12 +01:00
static u32 LoopedTask_TransitionMons(s32 state)
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_ConditionMenuGfx *menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_GRAPH_MENU_GFX);
2021-11-11 00:52:30 +01:00
struct ConditionGraph *graph = GetConditionGraphPtr();
2019-07-24 17:02:52 +02:00
switch (state)
{
case 0:
2021-11-11 22:50:36 +01:00
LoadNextConditionMenuMonData(CONDITION_LOAD_MON_INFO);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 1:
2021-11-11 22:50:36 +01:00
LoadNextConditionMenuMonData(CONDITION_LOAD_GRAPH);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 2:
2021-11-11 22:50:36 +01:00
LoadNextConditionMenuMonData(CONDITION_LOAD_MON_PIC);
DestroyConditionSparkleSprites(menu->conditionSparkleSprites);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 3:
2021-11-11 00:52:30 +01:00
ConditionGraph_TryUpdate(graph);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 4:
2021-11-11 22:50:36 +01:00
if (!MoveConditionMonOffscreen(&menu->monTransitionX))
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
CreateConditionMonPic(GetConditionGraphMenuCurrentLoadIndex());
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
}
2020-10-11 00:17:34 +02:00
return LT_PAUSE;
2019-07-24 17:02:52 +02:00
case 5:
2021-11-11 22:50:36 +01:00
UpdateConditionGraphMenuWindows(0, GetConditionGraphMenuCurrentLoadIndex(), FALSE);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 6:
2021-11-11 22:50:36 +01:00
UpdateConditionGraphMenuWindows(1, GetConditionGraphMenuCurrentLoadIndex(), FALSE);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 7:
2021-11-11 22:50:36 +01:00
UpdateConditionGraphMenuWindows(2, GetConditionGraphMenuCurrentLoadIndex(), FALSE);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 8:
2021-11-11 22:50:36 +01:00
if (UpdateConditionGraphMenuWindows(3, GetConditionGraphMenuCurrentLoadIndex(), FALSE) == TRUE)
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
return LT_PAUSE;
2019-07-24 17:02:52 +02:00
case 9:
2021-11-11 00:52:30 +01:00
graph = GetConditionGraphPtr();
2021-11-11 22:50:36 +01:00
if (!ConditionMenu_UpdateMonEnter(graph, &menu->monTransitionX))
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
ResetConditionSparkleSprites(menu->conditionSparkleSprites);
if (IsConditionMenuSearchMode() != TRUE && GetConditionGraphCurrentListIndex() == GetMonListCount())
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
2021-11-11 22:50:36 +01:00
CreateConditionSparkleSprites(menu->conditionSparkleSprites, menu->monPicSpriteId, GetNumConditionMonSparkles());
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
}
2020-10-11 00:17:34 +02:00
return LT_PAUSE;
2019-07-24 17:02:52 +02:00
}
2019-12-07 10:08:21 +01:00
return LT_FINISH;
2019-07-24 17:02:52 +02:00
}
2021-11-10 02:02:12 +01:00
static u32 LoopedTask_MoveCursorNoTransition(s32 state)
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_ConditionMenuGfx *menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_GRAPH_MENU_GFX);
2019-07-24 17:02:52 +02:00
switch (state)
{
case 0:
2021-11-11 22:50:36 +01:00
LoadNextConditionMenuMonData(CONDITION_LOAD_MON_INFO);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 1:
2021-11-11 22:50:36 +01:00
LoadNextConditionMenuMonData(CONDITION_LOAD_GRAPH);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 2:
2021-11-11 22:50:36 +01:00
LoadNextConditionMenuMonData(CONDITION_LOAD_MON_PIC);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 3:
2021-11-11 22:50:36 +01:00
CreateConditionMonPic(GetConditionGraphMenuCurrentLoadIndex());
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 4:
2021-11-11 22:50:36 +01:00
UpdateConditionGraphMenuWindows(0, GetConditionGraphMenuCurrentLoadIndex(), FALSE);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 5:
2021-11-11 22:50:36 +01:00
UpdateConditionGraphMenuWindows(1, GetConditionGraphMenuCurrentLoadIndex(), FALSE);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 6:
2021-11-11 22:50:36 +01:00
UpdateConditionGraphMenuWindows(2, GetConditionGraphMenuCurrentLoadIndex(), FALSE);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 7:
2021-11-11 22:50:36 +01:00
if (UpdateConditionGraphMenuWindows(3, GetConditionGraphMenuCurrentLoadIndex(), FALSE) == TRUE)
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
return LT_PAUSE;
2019-07-24 17:02:52 +02:00
case 8:
2021-11-11 22:50:36 +01:00
if (!ConditionMenu_UpdateMonEnter(GetConditionGraphPtr(), &menu->monTransitionX))
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
ResetConditionSparkleSprites(menu->conditionSparkleSprites);
CreateConditionSparkleSprites(menu->conditionSparkleSprites, menu->monPicSpriteId, GetNumConditionMonSparkles());
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
}
2020-10-11 00:17:34 +02:00
return LT_PAUSE;
2019-07-24 17:02:52 +02:00
}
2019-12-07 10:08:21 +01:00
return LT_FINISH;
2019-07-24 17:02:52 +02:00
}
2021-11-10 02:02:12 +01:00
static u32 LoopedTask_SlideMonOut(s32 state)
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_ConditionMenuGfx *menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_GRAPH_MENU_GFX);
2019-07-24 17:02:52 +02:00
switch (state)
{
case 0:
2021-11-11 22:50:36 +01:00
LoadNextConditionMenuMonData(CONDITION_LOAD_MON_INFO);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 1:
2021-11-11 22:50:36 +01:00
LoadNextConditionMenuMonData(CONDITION_LOAD_GRAPH);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 2:
2021-11-11 22:50:36 +01:00
LoadNextConditionMenuMonData(CONDITION_LOAD_MON_PIC);
DestroyConditionSparkleSprites(menu->conditionSparkleSprites);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 3:
2021-11-11 22:50:36 +01:00
if (!ConditionMenu_UpdateMonExit(GetConditionGraphPtr(), &menu->monTransitionX))
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
return LT_PAUSE;
2019-07-24 17:02:52 +02:00
case 4:
2021-11-11 22:50:36 +01:00
UpdateConditionGraphMenuWindows(0, GetConditionGraphMenuCurrentLoadIndex(), FALSE);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 5:
2021-11-11 22:50:36 +01:00
UpdateConditionGraphMenuWindows(1, GetConditionGraphMenuCurrentLoadIndex(), FALSE);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 6:
2021-11-11 22:50:36 +01:00
UpdateConditionGraphMenuWindows(2, GetConditionGraphMenuCurrentLoadIndex(), FALSE);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 7:
2021-11-11 22:50:36 +01:00
if (UpdateConditionGraphMenuWindows(3, GetConditionGraphMenuCurrentLoadIndex(), FALSE) == TRUE)
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
return LT_PAUSE;
2019-07-24 17:02:52 +02:00
}
2019-12-07 10:08:21 +01:00
return LT_FINISH;
2019-07-24 17:02:52 +02:00
}
2021-11-10 02:02:12 +01:00
static u32 LoopedTask_OpenMonMarkingsWindow(s32 state)
2019-07-24 17:02:52 +02:00
{
switch (state)
{
case 0:
2021-02-28 23:22:26 +01:00
OpenMonMarkingsMenu(TryGetMonMarkId(), 176, 32);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 1:
2019-12-07 10:08:21 +01:00
PrintHelpBarText(HELPBAR_CONDITION_MARKINGS);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 2:
2019-12-07 10:08:21 +01:00
if (WaitForHelpBar() == TRUE)
2020-10-11 00:17:34 +02:00
return LT_PAUSE;
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
}
2019-12-07 10:08:21 +01:00
return LT_FINISH;
2019-07-24 17:02:52 +02:00
}
2021-11-10 02:02:12 +01:00
static u32 LoopedTask_CloseMonMarkingsWindow(s32 state)
2019-07-24 17:02:52 +02:00
{
switch (state)
{
case 0:
2021-02-28 23:22:26 +01:00
FreeMonMarkingsMenu();
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 1:
2019-12-07 10:08:21 +01:00
PrintHelpBarText(HELPBAR_CONDITION_MON_STATUS);
2020-10-11 00:17:34 +02:00
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
case 2:
2019-12-07 10:08:21 +01:00
if (WaitForHelpBar() == TRUE)
2020-10-11 00:17:34 +02:00
return LT_PAUSE;
return LT_INC_AND_CONTINUE;
2019-07-24 17:02:52 +02:00
}
2019-12-07 10:08:21 +01:00
return LT_FINISH;
2019-07-24 17:02:52 +02:00
}
2019-12-07 10:08:21 +01:00
static u8 *UnusedPrintNumberString(u8 *dst, u16 num)
2019-07-24 17:02:52 +02:00
{
u8 *txtPtr = ConvertIntToDecimalStringN(dst, num, STR_CONV_MODE_RIGHT_ALIGN, 4);
txtPtr = StringCopy(txtPtr, gText_Number2);
return txtPtr;
}
2021-11-11 22:50:36 +01:00
static bool32 UpdateConditionGraphMenuWindows(u8 mode, u16 bufferIndex, bool8 winMode)
2019-07-24 17:02:52 +02:00
{
u8 text[32];
const u8 *str;
2021-11-11 22:50:36 +01:00
struct Pokenav_ConditionMenuGfx *menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_GRAPH_MENU_GFX);
2019-07-24 17:02:52 +02:00
2020-10-11 00:17:34 +02:00
switch (mode)
2019-07-24 17:02:52 +02:00
{
case 0:
2021-11-11 22:50:36 +01:00
FillWindowPixelBuffer(menu->nameGenderWindowId, 0);
2020-10-11 00:17:34 +02:00
if (IsConditionMenuSearchMode() == TRUE)
2021-11-11 22:50:36 +01:00
FillWindowPixelBuffer(menu->listIndexWindowId, 0);
2019-07-24 17:02:52 +02:00
break;
case 1:
2021-11-11 22:50:36 +01:00
if (GetConditionGraphCurrentListIndex() != GetMonListCount() - 1 || IsConditionMenuSearchMode() == TRUE)
2019-07-24 17:02:52 +02:00
{
2021-11-10 02:02:12 +01:00
str = GetConditionMonNameText(bufferIndex);
2021-11-11 22:50:36 +01:00
AddTextPrinterParameterized(menu->nameGenderWindowId, FONT_NORMAL, str, 0, 1, 0, NULL);
2019-07-24 17:02:52 +02:00
}
break;
case 2:
2020-10-11 00:17:34 +02:00
if (IsConditionMenuSearchMode() == TRUE)
2019-07-24 17:02:52 +02:00
{
2021-11-10 02:02:12 +01:00
str = GetConditionMonLocationText(bufferIndex);
2021-11-11 22:50:36 +01:00
AddTextPrinterParameterized(menu->nameGenderWindowId, FONT_NORMAL, str, 0, 17, 0, NULL);
2019-07-24 17:02:52 +02:00
text[0] = EXT_CTRL_CODE_BEGIN;
2020-08-11 05:50:49 +02:00
text[1] = EXT_CTRL_CODE_COLOR_HIGHLIGHT_SHADOW;
text[2] = TEXT_COLOR_BLUE;
text[3] = TEXT_COLOR_TRANSPARENT;
text[4] = TEXT_COLOR_LIGHT_BLUE;
2021-11-10 02:02:12 +01:00
StringCopy(&text[5], gText_Number2);
2021-11-11 22:50:36 +01:00
AddTextPrinterParameterized(menu->listIndexWindowId, FONT_NORMAL, text, 4, 1, 0, NULL);
2021-11-10 02:02:12 +01:00
ConvertIntToDecimalStringN(&text[5], GetConditionMonDataBuffer(), STR_CONV_MODE_RIGHT_ALIGN, 4);
2021-11-11 22:50:36 +01:00
AddTextPrinterParameterized(menu->listIndexWindowId, FONT_NORMAL, text, 28, 1, 0, NULL);
2019-07-24 17:02:52 +02:00
}
break;
case 3:
2021-11-11 22:50:36 +01:00
switch (menu->windowModeState)
2019-07-24 17:02:52 +02:00
{
case 0:
2020-10-11 00:17:34 +02:00
if (winMode)
2021-11-11 22:50:36 +01:00
CopyWindowToVram(menu->nameGenderWindowId, COPYWIN_FULL);
2019-07-24 17:02:52 +02:00
else
2021-11-11 22:50:36 +01:00
CopyWindowToVram(menu->nameGenderWindowId, COPYWIN_GFX);
2019-07-24 17:02:52 +02:00
2020-10-11 00:17:34 +02:00
if (IsConditionMenuSearchMode() == TRUE)
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
menu->windowModeState++;
2019-07-24 17:02:52 +02:00
return FALSE;
}
else
{
2021-11-11 22:50:36 +01:00
menu->windowModeState = 0;
2019-07-24 17:02:52 +02:00
return TRUE;
}
case 1:
2020-10-11 00:17:34 +02:00
if (winMode)
2021-11-11 22:50:36 +01:00
CopyWindowToVram(menu->listIndexWindowId, COPYWIN_FULL);
2019-07-24 17:02:52 +02:00
else
2021-11-11 22:50:36 +01:00
CopyWindowToVram(menu->listIndexWindowId, COPYWIN_GFX);
2019-07-24 17:02:52 +02:00
2021-11-11 22:50:36 +01:00
menu->windowModeState = 0;
2019-07-24 17:02:52 +02:00
return TRUE;
}
}
return FALSE;
}
2021-11-10 02:02:12 +01:00
static void CopyUnusedConditionWindowsToVram(void)
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_ConditionMenuGfx *menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_GRAPH_MENU_GFX);
2019-07-24 17:02:52 +02:00
2021-11-11 22:50:36 +01:00
CopyWindowToVram(menu->unusedWindowId1, COPYWIN_FULL);
CopyWindowToVram(menu->unusedWindowId2, COPYWIN_FULL);
2019-07-24 17:02:52 +02:00
}
2021-11-11 22:50:36 +01:00
static void SpriteCB_PartyPokeball(struct Sprite *sprite)
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
if (sprite->data[0] == GetConditionGraphCurrentListIndex())
StartSpriteAnim(sprite, CONDITION_ICON_SELECTED);
2019-07-24 17:02:52 +02:00
else
2021-11-11 22:50:36 +01:00
StartSpriteAnim(sprite, CONDITION_ICON_UNSELECTED);
2019-07-24 17:02:52 +02:00
}
2020-10-11 00:17:34 +02:00
void HighlightCurrentPartyIndexPokeball(struct Sprite *sprite)
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
if (GetConditionGraphCurrentListIndex() == GetMonListCount() - 1)
2021-11-10 02:02:12 +01:00
sprite->oam.paletteNum = IndexOfSpritePaletteTag(TAG_CONDITION_BALL);
2019-07-24 17:02:52 +02:00
else
2021-11-10 02:02:12 +01:00
sprite->oam.paletteNum = IndexOfSpritePaletteTag(TAG_CONDITION_CANCEL);
2019-07-24 17:02:52 +02:00
}
2020-10-11 00:17:34 +02:00
void MonMarkingsCallback(struct Sprite *sprite)
2019-07-24 17:02:52 +02:00
{
2020-10-11 00:17:34 +02:00
StartSpriteAnim(sprite, TryGetMonMarkId());
2019-07-24 17:02:52 +02:00
}
2021-11-10 02:02:12 +01:00
static void CreateMonMarkingsOrPokeballIndicators(void)
2019-07-24 17:02:52 +02:00
{
struct SpriteSheet sprSheets[4];
struct SpriteTemplate sprTemplate;
struct SpritePalette sprPals[3];
struct SpriteSheet sprSheet;
struct Sprite *sprite;
u16 i, spriteId;
2021-11-11 22:50:36 +01:00
struct Pokenav_ConditionMenuGfx *menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_GRAPH_MENU_GFX);
2019-07-24 17:02:52 +02:00
2020-08-10 19:48:16 +02:00
LoadConditionSelectionIcons(sprSheets, &sprTemplate, sprPals);
2020-10-11 00:17:34 +02:00
if (IsConditionMenuSearchMode() == TRUE)
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
// Search Mode, load markings menu
menu->marksMenu.baseTileTag = TAG_CONDITION_MARKINGS_MENU;
menu->marksMenu.basePaletteTag = TAG_CONDITION_MARKINGS_MENU;
InitMonMarkingsMenu(&menu->marksMenu);
2021-02-28 23:22:26 +01:00
BufferMonMarkingsMenuTiles();
2021-11-11 22:50:36 +01:00
sprite = CreateMonMarkingAllCombosSprite(TAG_CONDITION_MON_MARKINGS, TAG_CONDITION_MON_MARKINGS, sMonMarkings_Pal);
2019-07-24 17:02:52 +02:00
sprite->oam.priority = 3;
2021-07-07 15:11:52 +02:00
sprite->x = 192;
sprite->y = 32;
2020-10-11 00:17:34 +02:00
sprite->callback = MonMarkingsCallback;
2021-11-11 22:50:36 +01:00
menu->monMarksSprite = sprite;
2021-11-10 02:02:12 +01:00
PokenavFillPalette(IndexOfSpritePaletteTag(TAG_CONDITION_MON_MARKINGS), 0);
2019-07-24 17:02:52 +02:00
}
else
{
2021-11-11 22:50:36 +01:00
// Party Mode, load Pokéball selection icons
2019-07-24 17:02:52 +02:00
LoadSpriteSheets(sprSheets);
Pokenav_AllocAndLoadPalettes(sprPals);
2021-11-11 22:50:36 +01:00
// Add icons for occupied slots
2020-10-11 00:17:34 +02:00
for (i = 0; i < GetMonListCount() - 1; i++)
2019-07-24 17:02:52 +02:00
{
spriteId = CreateSprite(&sprTemplate, 226, (i * 20) + 8, 0);
if (spriteId != MAX_SPRITES)
{
2021-11-11 22:50:36 +01:00
menu->partyPokeballSpriteIds[i] = spriteId;
2019-07-24 17:02:52 +02:00
gSprites[spriteId].data[0] = i;
2021-11-11 22:50:36 +01:00
gSprites[spriteId].callback = SpriteCB_PartyPokeball;
2019-07-24 17:02:52 +02:00
}
else
{
2021-11-11 22:50:36 +01:00
menu->partyPokeballSpriteIds[i] = SPRITE_NONE;
2019-07-24 17:02:52 +02:00
}
}
2021-11-11 22:50:36 +01:00
// Add icons for empty slots
2021-11-10 02:02:12 +01:00
sprTemplate.tileTag = TAG_CONDITION_BALL_PLACEHOLDER;
2019-07-24 17:02:52 +02:00
sprTemplate.callback = SpriteCallbackDummy;
2021-11-11 22:50:36 +01:00
for (; i < PARTY_SIZE; i++)
2019-07-24 17:02:52 +02:00
{
spriteId = CreateSprite(&sprTemplate, 230, (i * 20) + 8, 0);
if (spriteId != MAX_SPRITES)
{
2021-11-11 22:50:36 +01:00
menu->partyPokeballSpriteIds[i] = spriteId;
2019-07-24 17:02:52 +02:00
gSprites[spriteId].oam.size = 0;
}
else
{
2021-11-11 22:50:36 +01:00
menu->partyPokeballSpriteIds[i] = SPRITE_NONE;
2019-07-24 17:02:52 +02:00
}
}
2021-11-11 22:50:36 +01:00
// Add cancel icon
2021-11-10 02:02:12 +01:00
sprTemplate.tileTag = TAG_CONDITION_CANCEL;
2020-10-11 00:17:34 +02:00
sprTemplate.callback = HighlightCurrentPartyIndexPokeball;
2019-07-24 17:02:52 +02:00
spriteId = CreateSprite(&sprTemplate, 222, (i * 20) + 8, 0);
if (spriteId != MAX_SPRITES)
{
2021-11-11 22:50:36 +01:00
menu->partyPokeballSpriteIds[i] = spriteId;
gSprites[spriteId].oam.shape = SPRITE_SHAPE(32x16);
gSprites[spriteId].oam.size = SPRITE_SIZE(32x16);
2019-07-24 17:02:52 +02:00
}
else
{
2021-11-11 22:50:36 +01:00
menu->partyPokeballSpriteIds[i] = SPRITE_NONE;
2019-07-24 17:02:52 +02:00
}
}
2020-08-10 19:48:16 +02:00
LoadConditionSparkle(&sprSheet, &sprPals[0]);
2019-07-24 17:02:52 +02:00
LoadSpriteSheet(&sprSheet);
sprPals[1].data = NULL;
Pokenav_AllocAndLoadPalettes(sprPals);
}
2021-11-11 22:50:36 +01:00
static void FreeConditionMenuGfx(struct Pokenav_ConditionMenuGfx *menu)
2019-07-24 17:02:52 +02:00
{
u8 i;
2020-10-11 00:17:34 +02:00
if (IsConditionMenuSearchMode() == TRUE)
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
DestroySprite(menu->monMarksSprite);
2021-11-10 02:02:12 +01:00
FreeSpriteTilesByTag(TAG_CONDITION_MARKINGS_MENU);
FreeSpriteTilesByTag(TAG_CONDITION_MON_MARKINGS);
FreeSpritePaletteByTag(TAG_CONDITION_MARKINGS_MENU);
FreeSpritePaletteByTag(TAG_CONDITION_MON_MARKINGS);
2019-07-24 17:02:52 +02:00
}
else
{
2021-11-11 22:50:36 +01:00
for (i = 0; i < PARTY_SIZE + 1; i++)
DestroySprite(&gSprites[menu->partyPokeballSpriteIds[i]]);
2019-07-24 17:02:52 +02:00
2021-11-10 02:02:12 +01:00
FreeSpriteTilesByTag(TAG_CONDITION_BALL);
FreeSpriteTilesByTag(TAG_CONDITION_CANCEL);
FreeSpriteTilesByTag(TAG_CONDITION_BALL_PLACEHOLDER);
FreeSpritePaletteByTag(TAG_CONDITION_BALL);
FreeSpritePaletteByTag(TAG_CONDITION_CANCEL);
2019-07-24 17:02:52 +02:00
}
2021-11-11 22:50:36 +01:00
if (menu->monPicSpriteId != SPRITE_NONE)
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
DestroySprite(&gSprites[menu->monPicSpriteId]);
2021-11-10 02:02:12 +01:00
FreeSpriteTilesByTag(TAG_CONDITION_MON);
FreeSpritePaletteByTag(TAG_CONDITION_MON);
2019-07-24 17:02:52 +02:00
}
}
2021-11-11 22:50:36 +01:00
void FreeConditionGraphMenuSubstruct2(void)
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_ConditionMenuGfx *menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_GRAPH_MENU_GFX);
2019-07-24 17:02:52 +02:00
2021-11-11 22:50:36 +01:00
RemoveWindow(menu->nameGenderWindowId);
2020-10-11 00:17:34 +02:00
if (IsConditionMenuSearchMode() == TRUE)
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
RemoveWindow(menu->listIndexWindowId);
RemoveWindow(menu->unusedWindowId1);
RemoveWindow(menu->unusedWindowId2);
2019-07-24 17:02:52 +02:00
}
else
{
2020-10-11 00:17:34 +02:00
SetLeftHeaderSpritesInvisibility();
2019-07-24 17:02:52 +02:00
}
SetGpuReg(REG_OFFSET_DISPCNT, DISPCNT_OBJ_ON | DISPCNT_BG0_ON | DISPCNT_OBJ_1D_MAP);
2021-11-11 22:50:36 +01:00
FreeConditionMenuGfx(menu);
SetExitVBlank();
FreePokenavSubstruct(POKENAV_SUBSTRUCT_CONDITION_GRAPH_MENU_GFX);
2019-07-24 17:02:52 +02:00
}
2020-10-11 00:17:34 +02:00
void MonPicGfxSpriteCallback(struct Sprite *sprite)
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_ConditionMenuGfx *menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_GRAPH_MENU_GFX);
sprite->x = menu->monTransitionX + 38;
2019-07-24 17:02:52 +02:00
}
2021-11-10 02:02:12 +01:00
static void CreateConditionMonPic(u8 id)
2019-07-24 17:02:52 +02:00
{
struct SpriteTemplate sprTemplate;
struct SpriteSheet sprSheet;
struct SpritePalette sprPal;
u8 spriteId;
2021-11-11 22:50:36 +01:00
struct Pokenav_ConditionMenuGfx *menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_GRAPH_MENU_GFX);
2019-07-24 17:02:52 +02:00
2021-11-11 22:50:36 +01:00
if (menu->monPicSpriteId == SPRITE_NONE)
2019-07-24 17:02:52 +02:00
{
2020-08-10 23:05:42 +02:00
LoadConditionMonPicTemplate(&sprSheet, &sprTemplate, &sprPal);
2020-10-11 00:17:34 +02:00
sprSheet.data = GetConditionMonPicGfx(id);
sprPal.data = GetConditionMonPal(id);
2021-11-11 22:50:36 +01:00
menu->monPalIndex = LoadSpritePalette(&sprPal);
menu->monGfxTileStart = LoadSpriteSheet(&sprSheet);
2019-07-24 17:02:52 +02:00
spriteId = CreateSprite(&sprTemplate, 38, 104, 0);
2021-11-11 22:50:36 +01:00
menu->monPicSpriteId = spriteId;
2019-07-24 17:02:52 +02:00
if (spriteId == MAX_SPRITES)
{
2021-11-10 02:02:12 +01:00
FreeSpriteTilesByTag(TAG_CONDITION_MON);
FreeSpritePaletteByTag(TAG_CONDITION_MON);
2021-11-11 22:50:36 +01:00
menu->monPicSpriteId = SPRITE_NONE;
2019-07-24 17:02:52 +02:00
}
else
{
2021-11-11 22:50:36 +01:00
menu->monPicSpriteId = spriteId;
gSprites[menu->monPicSpriteId].callback = MonPicGfxSpriteCallback;
2022-07-29 16:52:35 +02:00
menu->monGfxPtr = (void *)VRAM + BG_VRAM_SIZE + (menu->monGfxTileStart * 32);
2021-11-11 22:50:36 +01:00
menu->monPalIndex = (menu->monPalIndex * 16) + 0x100;
2019-07-24 17:02:52 +02:00
}
}
else
{
2021-11-11 22:50:36 +01:00
DmaCopy16Defvars(3, GetConditionMonPicGfx(id), menu->monGfxPtr, MON_PIC_SIZE);
LoadPalette(GetConditionMonPal(id), menu->monPalIndex, 0x20);
2019-07-24 17:02:52 +02:00
}
}
2021-11-11 00:52:30 +01:00
static void VBlankCB_PokenavConditionGraph(void)
2019-07-24 17:02:52 +02:00
{
2021-11-11 00:52:30 +01:00
struct ConditionGraph *graph = GetConditionGraphPtr();
2019-07-24 17:02:52 +02:00
LoadOam();
ProcessSpriteCopyRequests();
TransferPlttBuffer();
2021-11-11 00:52:30 +01:00
ConditionGraph_Draw(graph);
2019-07-24 17:02:52 +02:00
ScanlineEffect_InitHBlankDmaTransfer();
}
2021-11-11 22:50:36 +01:00
static void SetExitVBlank(void)
2019-07-24 17:02:52 +02:00
{
SetPokenavVBlankCallback();
}
2021-11-10 02:02:12 +01:00
static void ToggleGraphData(bool8 showBg)
2019-07-24 17:02:52 +02:00
{
if (showBg)
ShowBg(2);
else
HideBg(2);
}
2021-11-11 22:50:36 +01:00
static void DoConditionGraphEnterTransition(void)
2019-07-24 17:02:52 +02:00
{
2021-11-11 00:52:30 +01:00
struct ConditionGraph *graph = GetConditionGraphPtr();
2021-11-11 22:50:36 +01:00
u8 id = GetConditionGraphMenuCurrentLoadIndex();
2019-07-24 17:02:52 +02:00
2021-11-11 22:50:36 +01:00
sInitialLoadId = id;
2021-11-11 00:52:30 +01:00
ConditionGraph_SetNewPositions(graph, graph->savedPositions[CONDITION_GRAPH_LOAD_MAX - 1], graph->savedPositions[id]);
ConditionGraph_TryUpdate(graph);
2019-07-24 17:02:52 +02:00
}
2021-11-11 22:50:36 +01:00
// Transition the graph back to empty before exiting.
// This is skipped if the player is in party mode and the cursor
// is on Cancel, in which case the graph is already empty.
static void DoConditionGraphExitTransition(void)
2019-07-24 17:02:52 +02:00
{
2021-11-11 00:52:30 +01:00
struct ConditionGraph *graph = GetConditionGraphPtr();
2019-07-24 17:02:52 +02:00
2021-11-11 22:50:36 +01:00
if (IsConditionMenuSearchMode() || GetConditionGraphCurrentListIndex() != GetMonListCount() - 1)
ConditionGraph_SetNewPositions(graph, graph->savedPositions[GetConditionGraphMenuCurrentLoadIndex()], graph->savedPositions[CONDITION_GRAPH_LOAD_MAX - 1]);
2019-07-24 17:02:52 +02:00
}
2020-10-11 00:17:34 +02:00
u8 GetMonMarkingsData(void)
2019-07-24 17:02:52 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_ConditionMenuGfx *menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_GRAPH_MENU_GFX);
2019-07-24 17:02:52 +02:00
2020-10-11 00:17:34 +02:00
if (IsConditionMenuSearchMode() == 1)
2021-11-11 22:50:36 +01:00
return menu->marksMenu.markings;
2019-07-24 17:02:52 +02:00
else
return 0;
}