pokeemerald/src/pokenav_conditions_search_results.c

735 lines
23 KiB
C
Raw Normal View History

2019-07-20 04:06:42 +02:00
#include "global.h"
#include "pokenav.h"
#include "bg.h"
2019-08-05 19:47:04 +02:00
#include "menu.h"
2019-07-20 04:06:42 +02:00
#include "window.h"
2019-08-05 19:47:04 +02:00
#include "sound.h"
#include "dynamic_placeholder_text_util.h"
#include "strings.h"
#include "string_util.h"
#include "international_string_util.h"
#include "constants/songs.h"
2019-07-20 04:06:42 +02:00
2020-10-11 00:17:34 +02:00
enum
{
CONDITION_SEARCH_FUNC_NONE,
CONDITION_SEARCH_FUNC_MOVE_UP,
CONDITION_SEARCH_FUNC_MOVE_DOWN,
CONDITION_SEARCH_FUNC_PAGE_UP,
CONDITION_SEARCH_FUNC_PAGE_DOWN,
CONDITION_SEARCH_FUNC_EXIT,
CONDITION_SEARCH_FUNC_SELECT_MON,
};
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResults
2019-08-05 16:54:56 +02:00
{
2021-11-11 22:50:36 +01:00
u32 (*callback)(struct Pokenav_SearchResults *);
2019-08-05 16:54:56 +02:00
u32 loopedTaskId;
u8 fill1[4];
2020-10-11 00:17:34 +02:00
s32 boxId;
s32 monId;
u32 conditionDataId;
2021-11-11 22:50:36 +01:00
bool32 returnFromGraph;
bool32 saveResultsList;
2021-11-13 02:24:14 +01:00
struct PokenavMonList *monList;
2019-08-05 16:54:56 +02:00
};
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResultsGfx
{
bool32 (*callback)(void);
2021-11-11 22:50:36 +01:00
u32 loopedTaskId;
u16 winid;
2020-10-11 00:17:34 +02:00
bool32 fromGraph;
2019-08-06 15:26:55 +02:00
u8 buff[BG_SCREEN_SIZE];
}; // size: 0x810
2021-11-11 22:50:36 +01:00
static u32 HandleConditionSearchInput_WaitSetup(struct Pokenav_SearchResults *);
static u32 HandleConditionSearchInput(struct Pokenav_SearchResults *);
static u32 OpenConditionGraphFromSearchList(struct Pokenav_SearchResults *);
static u32 ReturnToConditionSearchList(struct Pokenav_SearchResults *);
static u32 GetConditionSearchLoopedTask(s32);
static u32 BuildPartyMonSearchResults(s32);
static u32 InitBoxMonSearchResults(s32);
static u32 BuildBoxMonSearchResults(s32);
static u32 ConvertConditionsToListRanks(s32);
static u32 LoopedTask_MoveSearchListCursorUp(s32);
static u32 LoopedTask_MoveSearchListCursorDown(s32);
static u32 LoopedTask_MoveSearchListPageUp(s32);
static u32 LoopedTask_MoveSearchListPageDown(s32);
static u32 LoopedTask_ExitConditionSearchMenu(s32);
static u32 LoopedTask_SelectSearchResult(s32);
2021-11-13 02:24:14 +01:00
static void InsertMonListItem(struct Pokenav_SearchResults *, struct PokenavMonListItem *);
2020-10-11 00:17:34 +02:00
static bool32 GetSearchResultCurrentLoopedTaskActive(void);
2021-11-11 22:50:36 +01:00
static u32 LoopedTask_OpenConditionSearchResults(s32);
static void AddSearchResultListMenuWindow(struct Pokenav_SearchResultsGfx *);
static void PrintSearchResultListMenuItems(struct Pokenav_SearchResultsGfx *);
2021-11-13 18:52:41 +01:00
static void CreateSearchResultsList(void);
2021-11-13 02:24:14 +01:00
static void BufferSearchMonListItem(struct PokenavMonListItem *, u8 *);
2020-10-11 00:17:34 +02:00
static const u32 sSearchMonDataIds[] = {MON_DATA_COOL, MON_DATA_BEAUTY, MON_DATA_CUTE, MON_DATA_SMART, MON_DATA_TOUGH};
2020-10-11 00:17:34 +02:00
static const LoopedTask sConditionSearchLoopedTaskFuncs[] =
2019-07-20 04:06:42 +02:00
{
2020-10-11 00:17:34 +02:00
BuildPartyMonSearchResults,
InitBoxMonSearchResults,
BuildBoxMonSearchResults,
2021-11-11 22:50:36 +01:00
ConvertConditionsToListRanks
2019-07-20 04:06:42 +02:00
};
2021-11-11 22:50:36 +01:00
static const u16 sConditionSearchResultFramePal[] = INCBIN_U16("graphics/pokenav/condition/search_results.gbapal");
static const u32 sConditionSearchResultTiles[] = INCBIN_U32("graphics/pokenav/condition/search_results.4bpp.lz");
static const u32 sConditionSearchResultTilemap[] = INCBIN_U32("graphics/pokenav/condition/search_results.bin.lz");
static const u16 sListBg_Pal[] = INCBIN_U16("graphics/pokenav/condition/search_results_list.gbapal");
2019-07-20 04:06:42 +02:00
2020-10-11 00:17:34 +02:00
static const struct BgTemplate sConditionSearchResultBgTemplates[] =
2019-07-20 04:06:42 +02:00
{
2019-08-05 19:47:04 +02:00
{
.bg = 1,
.charBaseIndex = 1,
.mapBaseIndex = 0x06,
.screenSize = 0,
.paletteMode = 0,
.priority = 2,
.baseTile = 0
}, {
.bg = 2,
.charBaseIndex = 2,
.mapBaseIndex = 0x07,
.screenSize = 0,
.paletteMode = 0,
.priority = 3,
.baseTile = 0
}
2019-07-20 04:06:42 +02:00
};
static const LoopedTask sSearchResultLoopTaskFuncs[] =
2019-07-20 04:06:42 +02:00
{
[CONDITION_SEARCH_FUNC_NONE] = NULL,
[CONDITION_SEARCH_FUNC_MOVE_UP] = LoopedTask_MoveSearchListCursorUp,
[CONDITION_SEARCH_FUNC_MOVE_DOWN] = LoopedTask_MoveSearchListCursorDown,
[CONDITION_SEARCH_FUNC_PAGE_UP] = LoopedTask_MoveSearchListPageUp,
[CONDITION_SEARCH_FUNC_PAGE_DOWN] = LoopedTask_MoveSearchListPageDown,
[CONDITION_SEARCH_FUNC_EXIT] = LoopedTask_ExitConditionSearchMenu,
2020-10-11 00:17:34 +02:00
[CONDITION_SEARCH_FUNC_SELECT_MON] = LoopedTask_SelectSearchResult
2019-07-20 04:06:42 +02:00
};
static const struct WindowTemplate sSearchResultListMenuWindowTemplate =
2019-07-20 04:06:42 +02:00
{
.bg = 1,
.tilemapLeft = 1,
.tilemapTop = 6,
.width = 7,
.height = 2,
.paletteNum = 1,
.baseBlock = 20
};
2021-04-10 04:39:34 +02:00
static const u8 sText_MaleSymbol[] = _("{COLOR_HIGHLIGHT_SHADOW}{LIGHT_RED}{WHITE}{GREEN}♂{COLOR_HIGHLIGHT_SHADOW}{DARK_GRAY}{WHITE}{LIGHT_GRAY}");
static const u8 sText_FemaleSymbol[] = _("{COLOR_HIGHLIGHT_SHADOW}{LIGHT_GREEN}{WHITE}{BLUE}♀{COLOR_HIGHLIGHT_SHADOW}{DARK_GRAY}{WHITE}{LIGHT_GRAY}");
2020-02-01 06:25:50 +01:00
static const u8 sText_NoGenderSymbol[] = _("{UNK_SPACER}");
2019-07-25 21:41:02 +02:00
2020-10-11 00:17:34 +02:00
bool32 PokenavCallback_Init_ConditionSearch(void)
2019-07-25 21:41:02 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResults *menu = AllocSubstruct(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS, sizeof(struct Pokenav_SearchResults));
if (menu == NULL)
2019-07-25 21:41:02 +02:00
return FALSE;
2021-11-13 02:24:14 +01:00
menu->monList = AllocSubstruct(POKENAV_SUBSTRUCT_MON_LIST, sizeof(struct PokenavMonList));
2021-11-11 22:50:36 +01:00
if (menu->monList == NULL)
2019-07-25 21:41:02 +02:00
return FALSE;
2021-11-11 22:50:36 +01:00
menu->callback = HandleConditionSearchInput_WaitSetup;
menu->loopedTaskId = CreateLoopedTask(GetConditionSearchLoopedTask, 1);
menu->returnFromGraph = FALSE;
menu->conditionDataId = sSearchMonDataIds[GetSelectedConditionSearch()];
2019-07-25 21:41:02 +02:00
return TRUE;
}
2020-10-11 00:17:34 +02:00
// return to search results from condition graph
bool32 PokenavCallback_Init_ReturnToMonSearchList(void)
2019-07-25 21:41:02 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResults *menu = AllocSubstruct(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS, sizeof(struct Pokenav_SearchResults));
if (menu == NULL)
2019-07-25 21:41:02 +02:00
return FALSE;
2021-11-11 22:50:36 +01:00
menu->monList = GetSubstructPtr(POKENAV_SUBSTRUCT_MON_LIST);
menu->callback = HandleConditionSearchInput;
menu->returnFromGraph = TRUE;
menu->conditionDataId = sSearchMonDataIds[GetSelectedConditionSearch()];
2019-07-25 21:41:02 +02:00
return TRUE;
}
2020-10-11 00:17:34 +02:00
u32 GetConditionSearchResultsCallback(void)
2019-07-25 21:41:02 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResults *menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS);
return menu->callback(menu);
2019-07-25 21:41:02 +02:00
}
2020-10-11 00:17:34 +02:00
void FreeSearchResultSubstruct1(void)
2019-07-25 21:41:02 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResults *menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS);
if (!menu->saveResultsList)
2020-10-11 00:17:34 +02:00
FreePokenavSubstruct(POKENAV_SUBSTRUCT_MON_LIST);
FreePokenavSubstruct(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS);
2019-07-25 21:41:02 +02:00
}
2021-11-11 22:50:36 +01:00
static bool32 HandleConditionSearchInput_WaitSetup(struct Pokenav_SearchResults *menu)
2019-07-25 21:41:02 +02:00
{
2021-11-11 22:50:36 +01:00
if (!IsLoopedTaskActive(menu->loopedTaskId))
menu->callback = HandleConditionSearchInput;
2019-07-25 21:41:02 +02:00
return FALSE;
}
2021-11-11 22:50:36 +01:00
static u32 HandleConditionSearchInput(struct Pokenav_SearchResults *menu)
2019-07-25 21:41:02 +02:00
{
if (JOY_REPEAT(DPAD_UP))
return CONDITION_SEARCH_FUNC_MOVE_UP;
else if (JOY_REPEAT(DPAD_DOWN))
return CONDITION_SEARCH_FUNC_MOVE_DOWN;
else if (JOY_NEW(DPAD_LEFT))
return CONDITION_SEARCH_FUNC_PAGE_UP;
else if (JOY_NEW(DPAD_RIGHT))
return CONDITION_SEARCH_FUNC_PAGE_DOWN;
else if (JOY_NEW(B_BUTTON))
2019-07-25 21:41:02 +02:00
{
2021-11-11 22:50:36 +01:00
// Exiting back to main search menu
menu->saveResultsList = FALSE;
menu->callback = ReturnToConditionSearchList;
2020-10-11 00:17:34 +02:00
return CONDITION_SEARCH_FUNC_EXIT;
2019-07-25 21:41:02 +02:00
}
else if (JOY_NEW(A_BUTTON))
2019-07-25 21:41:02 +02:00
{
2021-11-11 22:50:36 +01:00
// Entering graph menu
2021-11-15 04:21:50 +01:00
menu->monList->currIndex = PokenavList_GetSelectedIndex();
2021-11-11 22:50:36 +01:00
menu->saveResultsList = TRUE;
menu->callback = OpenConditionGraphFromSearchList;
2020-10-11 00:17:34 +02:00
return CONDITION_SEARCH_FUNC_SELECT_MON;
2019-07-25 21:41:02 +02:00
}
else
return CONDITION_SEARCH_FUNC_NONE;
2019-07-25 21:41:02 +02:00
}
2021-11-11 22:50:36 +01:00
static u32 ReturnToConditionSearchList(struct Pokenav_SearchResults *menu)
2019-07-25 21:41:02 +02:00
{
2020-02-05 08:47:32 +01:00
return POKENAV_CONDITION_SEARCH_MENU;
2019-07-25 21:41:02 +02:00
}
2021-11-11 22:50:36 +01:00
static u32 OpenConditionGraphFromSearchList(struct Pokenav_SearchResults *menu)
2019-07-25 21:41:02 +02:00
{
2021-11-11 22:50:36 +01:00
return POKENAV_CONDITION_GRAPH_SEARCH;
2019-07-25 21:41:02 +02:00
}
2021-11-11 22:50:36 +01:00
static u32 GetReturningFromGraph(void)
2019-07-25 21:41:02 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResults *menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS);
return menu->returnFromGraph;
2019-07-25 21:41:02 +02:00
}
2019-08-05 16:54:56 +02:00
2021-11-13 02:24:14 +01:00
static struct PokenavMonListItem * GetSearchResultsMonDataList(void)
2019-08-05 16:54:56 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResults * menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS);
return menu->monList->monData;
2019-08-05 16:54:56 +02:00
}
2020-10-11 00:17:34 +02:00
static u16 GetSearchResultsMonListCount(void)
2019-08-05 16:54:56 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResults * menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS);
return menu->monList->listCount;
2019-08-05 16:54:56 +02:00
}
2021-11-11 22:50:36 +01:00
// data below has been set by ConvertConditionsToListRanks
static s32 GetSearchResultsSelectedMonRank(void)
2019-08-05 16:54:56 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResults * menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS);
2021-11-15 04:21:50 +01:00
s32 i = PokenavList_GetSelectedIndex();
2021-11-11 22:50:36 +01:00
return menu->monList->monData[i].data;
2019-08-05 16:54:56 +02:00
}
2021-11-11 22:50:36 +01:00
static u16 GetSearchResultsCurrentListIndex(void)
2019-08-05 16:54:56 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResults * menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS);
return menu->monList->currIndex;
2019-08-05 16:54:56 +02:00
}
2020-10-11 00:17:34 +02:00
static u32 GetConditionSearchLoopedTask(s32 state)
2019-08-05 16:54:56 +02:00
{
2020-10-11 00:17:34 +02:00
return sConditionSearchLoopedTaskFuncs[state](state);
2019-08-05 16:54:56 +02:00
}
2020-10-11 00:17:34 +02:00
static u32 BuildPartyMonSearchResults(s32 state)
2019-08-05 16:54:56 +02:00
{
s32 i;
2021-11-13 02:24:14 +01:00
struct PokenavMonListItem item;
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResults * menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS);
2019-08-05 16:54:56 +02:00
2021-11-11 22:50:36 +01:00
menu->monList->listCount = 0;
menu->monList->currIndex = 0;
item.boxId = TOTAL_BOXES_COUNT;
2019-08-05 16:54:56 +02:00
for (i = 0; i < PARTY_SIZE; i++)
{
struct Pokemon * pokemon = &gPlayerParty[i];
if (!GetMonData(pokemon, MON_DATA_SANITY_HAS_SPECIES))
return LT_INC_AND_CONTINUE;
if (!GetMonData(pokemon, MON_DATA_SANITY_IS_EGG))
{
item.monId = i;
2021-11-11 22:50:36 +01:00
item.data = GetMonData(pokemon, menu->conditionDataId);
InsertMonListItem(menu, &item);
2019-08-05 16:54:56 +02:00
}
}
return LT_INC_AND_CONTINUE;
}
2020-10-11 00:17:34 +02:00
static u32 InitBoxMonSearchResults(s32 state)
2019-08-05 16:54:56 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResults * menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS);
menu->monId = 0;
menu->boxId = 0;
2019-08-05 16:54:56 +02:00
return LT_INC_AND_CONTINUE;
}
2020-10-11 00:17:34 +02:00
static u32 BuildBoxMonSearchResults(s32 state)
2019-08-05 16:54:56 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResults * menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS);
s32 boxId = menu->boxId;
s32 monId = menu->monId;
2019-08-05 16:54:56 +02:00
s32 boxCount = 0;
2021-11-13 02:24:14 +01:00
struct PokenavMonListItem item;
2019-08-05 16:54:56 +02:00
while (boxId < TOTAL_BOXES_COUNT)
{
while (monId < IN_BOX_COUNT)
{
if (CheckBoxMonSanityAt(boxId, monId))
{
item.boxId = boxId;
item.monId = monId;
2021-11-11 22:50:36 +01:00
item.data = GetBoxMonDataAt(boxId, monId, menu->conditionDataId);
InsertMonListItem(menu, &item);
2019-08-05 16:54:56 +02:00
}
boxCount++;
monId++;
2021-11-11 22:50:36 +01:00
if (boxCount > TOTAL_BOXES_COUNT)
2019-08-05 16:54:56 +02:00
{
2021-11-11 22:50:36 +01:00
menu->boxId = boxId;
menu->monId = monId;
2019-08-05 16:54:56 +02:00
return LT_CONTINUE;
}
}
monId = 0;
boxId++;
}
return LT_INC_AND_CONTINUE;
}
2021-11-11 22:50:36 +01:00
// Data below is initially set by BuildPartyMonSearchResults / BuildBoxMonSearchResults, and
// is the Pokémon's condition value for the condition they are sorted by.
// The condition value in data is then overwritten with their ranking.
static u32 ConvertConditionsToListRanks(s32 state)
2019-08-05 16:54:56 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResults * menu = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS);
s32 listCount = menu->monList->listCount;
s32 prevCondition = menu->monList->monData[0].data;
2019-08-05 16:54:56 +02:00
s32 i;
2021-11-11 22:50:36 +01:00
menu->monList->monData[0].data = 1;
for (i = 1; i < listCount; i++)
2019-08-05 16:54:56 +02:00
{
2021-11-11 22:50:36 +01:00
if (menu->monList->monData[i].data == prevCondition)
2019-08-05 16:54:56 +02:00
{
2021-11-11 22:50:36 +01:00
// Same condition value as prev, share rank
menu->monList->monData[i].data = menu->monList->monData[i - 1].data;
2019-08-05 16:54:56 +02:00
}
else
{
2021-11-11 22:50:36 +01:00
prevCondition = menu->monList->monData[i].data;
menu->monList->monData[i].data = i + 1;
2019-08-05 16:54:56 +02:00
}
}
2021-11-11 22:50:36 +01:00
menu->returnFromGraph = TRUE;
2019-08-05 16:54:56 +02:00
return LT_FINISH;
}
2019-08-05 18:21:45 +02:00
2021-11-13 02:24:14 +01:00
static void InsertMonListItem(struct Pokenav_SearchResults *menu, struct PokenavMonListItem *item)
2019-08-05 18:21:45 +02:00
{
u32 left = 0;
2021-11-11 22:50:36 +01:00
u32 right = menu->monList->listCount;
2019-08-05 18:21:45 +02:00
u32 insertionIdx = left + (right - left) / 2;
while (right != insertionIdx)
{
2021-11-11 22:50:36 +01:00
if (item->data > menu->monList->monData[insertionIdx].data)
2019-08-05 18:21:45 +02:00
right = insertionIdx;
else
left = insertionIdx + 1;
insertionIdx = left + (right - left) / 2;
}
2021-11-11 22:50:36 +01:00
for (right = menu->monList->listCount; right > insertionIdx; right--)
menu->monList->monData[right] = menu->monList->monData[right - 1];
menu->monList->monData[insertionIdx] = *item;
menu->monList->listCount++;
2019-08-05 18:21:45 +02:00
}
2020-10-11 00:17:34 +02:00
bool32 OpenConditionSearchResults(void)
2019-08-05 18:21:45 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResultsGfx *gfx = AllocSubstruct(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS_GFX, sizeof(struct Pokenav_SearchResultsGfx));
if (gfx == NULL)
2019-08-05 18:21:45 +02:00
return FALSE;
2021-11-11 22:50:36 +01:00
gfx->loopedTaskId = CreateLoopedTask(LoopedTask_OpenConditionSearchResults, 1);
gfx->callback = GetSearchResultCurrentLoopedTaskActive;
gfx->fromGraph = FALSE;
2019-08-05 18:21:45 +02:00
return TRUE;
}
2020-10-11 00:17:34 +02:00
bool32 OpenConditionSearchListFromGraph(void)
2019-08-05 18:21:45 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResultsGfx *gfx = AllocSubstruct(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS_GFX, sizeof(struct Pokenav_SearchResultsGfx));
if (gfx == NULL)
2019-08-05 18:21:45 +02:00
return FALSE;
2021-11-11 22:50:36 +01:00
gfx->loopedTaskId = CreateLoopedTask(LoopedTask_OpenConditionSearchResults, 1);
gfx->callback = GetSearchResultCurrentLoopedTaskActive;
gfx->fromGraph = TRUE;
2019-08-05 18:21:45 +02:00
return TRUE;
}
2020-10-11 00:17:34 +02:00
void CreateSearchResultsLoopedTask(s32 idx)
2019-08-05 18:21:45 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResultsGfx *gfx = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS_GFX);
gfx->loopedTaskId = CreateLoopedTask(sSearchResultLoopTaskFuncs[idx], 1);
gfx->callback = GetSearchResultCurrentLoopedTaskActive;
2019-08-05 18:21:45 +02:00
}
2020-10-11 00:17:34 +02:00
bool32 IsSearchResultLoopedTaskActive(void)
2019-08-05 18:21:45 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResultsGfx *gfx = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS_GFX);
return gfx->callback();
2019-08-05 18:21:45 +02:00
}
2020-10-11 00:17:34 +02:00
bool32 GetSearchResultCurrentLoopedTaskActive(void)
2019-08-05 18:21:45 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResultsGfx *gfx = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS_GFX);
return IsLoopedTaskActive(gfx->loopedTaskId);
2019-08-05 18:21:45 +02:00
}
2020-10-11 00:17:34 +02:00
void FreeSearchResultSubstruct2(void)
2019-08-05 18:21:45 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResultsGfx *gfx = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS_GFX);
2021-11-13 18:52:41 +01:00
DestroyPokenavList();
2021-11-11 22:50:36 +01:00
RemoveWindow(gfx->winid);
FreePokenavSubstruct(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS_GFX);
2019-08-05 18:21:45 +02:00
}
2019-08-05 19:47:04 +02:00
2020-10-11 00:17:34 +02:00
static u32 LoopedTask_OpenConditionSearchResults(s32 state)
2019-08-05 19:47:04 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResultsGfx *gfx = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS_GFX);
2019-08-05 19:47:04 +02:00
switch (state)
{
case 0:
InitBgTemplates(sConditionSearchResultBgTemplates, ARRAY_COUNT(sConditionSearchResultBgTemplates));
2020-10-11 00:17:34 +02:00
DecompressAndCopyTileDataToVram(1, sConditionSearchResultTiles, 0, 0, 0);
2021-11-11 22:50:36 +01:00
SetBgTilemapBuffer(1, gfx->buff);
2020-10-11 00:17:34 +02:00
CopyToBgTilemapBuffer(1, sConditionSearchResultTilemap, 0, 0);
2019-08-05 19:47:04 +02:00
CopyBgTilemapBufferToVram(1);
2020-10-11 00:17:34 +02:00
CopyPaletteIntoBufferUnfaded(sConditionSearchResultFramePal, 0x10, 0x20);
2019-08-05 19:47:04 +02:00
CopyBgTilemapBufferToVram(1);
return LT_INC_AND_PAUSE;
case 1:
2020-05-14 10:37:09 +02:00
if (FreeTempTileDataBuffersIfPossible())
2019-08-05 19:47:04 +02:00
return LT_PAUSE;
2021-11-11 22:50:36 +01:00
if (!GetReturningFromGraph())
2019-08-05 19:47:04 +02:00
return LT_PAUSE;
return LT_INC_AND_PAUSE;
case 2:
2020-05-14 10:37:09 +02:00
if (FreeTempTileDataBuffersIfPossible())
2019-08-05 19:47:04 +02:00
return LT_PAUSE;
2021-11-11 22:50:36 +01:00
CopyPaletteIntoBufferUnfaded(sListBg_Pal, 0x20, 32);
2021-11-13 18:52:41 +01:00
CreateSearchResultsList();
2019-08-05 19:47:04 +02:00
return LT_INC_AND_PAUSE;
case 3:
2021-11-13 18:52:41 +01:00
if (IsCreatePokenavListTaskActive())
2019-08-05 19:47:04 +02:00
return LT_PAUSE;
2021-11-11 22:50:36 +01:00
AddSearchResultListMenuWindow(gfx);
2019-12-07 10:08:21 +01:00
PrintHelpBarText(HELPBAR_CONDITION_MON_LIST);
2019-08-05 19:47:04 +02:00
return LT_INC_AND_PAUSE;
case 4:
2020-05-14 10:37:09 +02:00
if (FreeTempTileDataBuffersIfPossible())
2019-08-05 19:47:04 +02:00
return LT_PAUSE;
2021-11-04 04:02:06 +01:00
ChangeBgX(1, 0, BG_COORD_SET);
ChangeBgY(1, 0, BG_COORD_SET);
2019-08-05 19:47:04 +02:00
ShowBg(1);
ShowBg(2);
HideBg(3);
2021-11-11 22:50:36 +01:00
if (!gfx->fromGraph)
2019-08-05 19:47:04 +02:00
{
2020-10-11 00:17:34 +02:00
u8 searchGfxId = GetSelectedConditionSearch() + POKENAV_MENUITEM_CONDITION_SEARCH_COOL;
LoadLeftHeaderGfxForIndex(searchGfxId);
ShowLeftHeaderGfx(searchGfxId, 1, 0);
ShowLeftHeaderGfx(POKENAV_GFX_CONDITION_MENU, 1, 0);
2019-08-05 19:47:04 +02:00
}
2021-11-12 23:28:06 +01:00
PokenavFadeScreen(POKENAV_FADE_FROM_BLACK);
2019-08-05 19:47:04 +02:00
return LT_INC_AND_PAUSE;
case 5:
if (IsPaletteFadeActive())
return LT_PAUSE;
2020-10-11 00:17:34 +02:00
if (AreLeftHeaderSpritesMoving())
2019-08-05 19:47:04 +02:00
return LT_PAUSE;
break;
}
return LT_FINISH;
}
2020-10-11 00:17:34 +02:00
static u32 LoopedTask_MoveSearchListCursorUp(s32 state)
2019-08-05 19:47:04 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResultsGfx *gfx = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS_GFX);
2019-08-05 19:47:04 +02:00
switch (state)
{
case 0:
2021-11-13 18:52:41 +01:00
switch (PokenavList_MoveCursorUp())
2019-08-05 19:47:04 +02:00
{
case 0:
return LT_FINISH;
case 1:
PlaySE(SE_SELECT);
return LT_SET_STATE(2);
case 2:
PlaySE(SE_SELECT);
break;
}
return LT_INC_AND_PAUSE;
case 1:
2021-11-15 04:21:50 +01:00
if (PokenavList_IsMoveWindowTaskActive())
2019-08-05 19:47:04 +02:00
return LT_PAUSE;
// fallthrough
case 2:
2021-11-11 22:50:36 +01:00
PrintSearchResultListMenuItems(gfx);
2019-08-05 19:47:04 +02:00
return LT_INC_AND_PAUSE;
case 3:
if (IsDma3ManagerBusyWithBgCopy())
return LT_PAUSE;
break;
}
return LT_FINISH;
}
2020-10-11 00:17:34 +02:00
static u32 LoopedTask_MoveSearchListCursorDown(s32 state)
2019-08-05 19:47:04 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResultsGfx *gfx = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS_GFX);
2019-08-05 19:47:04 +02:00
switch (state)
{
case 0:
2021-11-13 18:52:41 +01:00
switch (PokenavList_MoveCursorDown())
2019-08-05 19:47:04 +02:00
{
case 0:
return LT_FINISH;
case 1:
PlaySE(SE_SELECT);
return LT_SET_STATE(2);
case 2:
PlaySE(SE_SELECT);
break;
}
return LT_INC_AND_PAUSE;
case 1:
2021-11-15 04:21:50 +01:00
if (PokenavList_IsMoveWindowTaskActive())
2019-08-05 19:47:04 +02:00
return LT_PAUSE;
// fallthrough
case 2:
2021-11-11 22:50:36 +01:00
PrintSearchResultListMenuItems(gfx);
2019-08-05 19:47:04 +02:00
return LT_INC_AND_PAUSE;
case 3:
if (IsDma3ManagerBusyWithBgCopy())
return LT_PAUSE;
break;
}
return LT_FINISH;
}
2020-10-11 00:17:34 +02:00
static u32 LoopedTask_MoveSearchListPageUp(s32 state)
2019-08-05 19:47:04 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResultsGfx *gfx = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS_GFX);
2019-08-05 19:47:04 +02:00
switch (state)
{
case 0:
2021-11-13 18:52:41 +01:00
switch (PokenavList_PageUp())
2019-08-05 19:47:04 +02:00
{
case 0:
return LT_FINISH;
case 1:
PlaySE(SE_SELECT);
return LT_SET_STATE(2);
case 2:
PlaySE(SE_SELECT);
break;
}
return LT_INC_AND_PAUSE;
case 1:
2021-11-15 04:21:50 +01:00
if (PokenavList_IsMoveWindowTaskActive())
2019-08-05 19:47:04 +02:00
return LT_PAUSE;
// fallthrough
case 2:
2021-11-11 22:50:36 +01:00
PrintSearchResultListMenuItems(gfx);
2019-08-05 19:47:04 +02:00
return LT_INC_AND_PAUSE;
case 3:
if (IsDma3ManagerBusyWithBgCopy())
return LT_PAUSE;
break;
}
return LT_FINISH;
}
2020-10-11 00:17:34 +02:00
static u32 LoopedTask_MoveSearchListPageDown(s32 state)
2019-08-05 19:47:04 +02:00
{
2021-11-11 22:50:36 +01:00
struct Pokenav_SearchResultsGfx *gfx = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS_GFX);
2019-08-05 19:47:04 +02:00
switch (state)
{
case 0:
2021-11-13 18:52:41 +01:00
switch (PokenavList_PageDown())
2019-08-05 19:47:04 +02:00
{
case 0:
return LT_FINISH;
case 1:
PlaySE(SE_SELECT);
return LT_SET_STATE(2);
case 2:
PlaySE(SE_SELECT);
break;
}
return LT_INC_AND_PAUSE;
case 1:
2021-11-15 04:21:50 +01:00
if (PokenavList_IsMoveWindowTaskActive())
2019-08-05 19:47:04 +02:00
return LT_PAUSE;
// fallthrough
case 2:
2021-11-11 22:50:36 +01:00
PrintSearchResultListMenuItems(gfx);
2019-08-05 19:47:04 +02:00
return LT_INC_AND_PAUSE;
case 3:
if (IsDma3ManagerBusyWithBgCopy())
return LT_PAUSE;
break;
}
return LT_FINISH;
}
2020-10-11 00:17:34 +02:00
static u32 LoopedTask_ExitConditionSearchMenu(s32 state)
2019-08-05 19:47:04 +02:00
{
switch (state)
{
case 0:
PlaySE(SE_SELECT);
2021-11-12 23:28:06 +01:00
PokenavFadeScreen(POKENAV_FADE_TO_BLACK);
2020-10-11 00:17:34 +02:00
SlideMenuHeaderDown();
2019-08-05 19:47:04 +02:00
return LT_INC_AND_PAUSE;
case 1:
if (IsPaletteFadeActive())
return LT_PAUSE;
if (MainMenuLoopedTaskIsBusy())
return LT_PAUSE;
2020-10-11 00:17:34 +02:00
SetLeftHeaderSpritesInvisibility();
2019-08-05 19:47:04 +02:00
break;
}
return LT_FINISH;
}
2020-10-11 00:17:34 +02:00
static u32 LoopedTask_SelectSearchResult(s32 state)
2019-08-05 19:47:04 +02:00
{
switch (state)
{
case 0:
PlaySE(SE_SELECT);
2021-11-12 23:28:06 +01:00
PokenavFadeScreen(POKENAV_FADE_TO_BLACK);
2019-08-05 19:47:04 +02:00
return LT_INC_AND_PAUSE;
case 1:
if (IsPaletteFadeActive())
return LT_PAUSE;
break;
}
return LT_FINISH;
}
2021-11-11 22:50:36 +01:00
static void AddSearchResultListMenuWindow(struct Pokenav_SearchResultsGfx *gfx)
2019-08-05 19:47:04 +02:00
{
2021-11-11 22:50:36 +01:00
gfx->winid = AddWindow(&sSearchResultListMenuWindowTemplate);
PutWindowTilemap(gfx->winid);
CopyWindowToVram(gfx->winid, COPYWIN_MAP);
PrintSearchResultListMenuItems(gfx);
2019-08-05 19:47:04 +02:00
}
2021-11-11 22:50:36 +01:00
static void PrintSearchResultListMenuItems(struct Pokenav_SearchResultsGfx *gfx)
2019-08-05 19:47:04 +02:00
{
2021-11-11 22:50:36 +01:00
s32 rank = GetSearchResultsSelectedMonRank();
2019-08-05 19:47:04 +02:00
DynamicPlaceholderTextUtil_Reset();
DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, gStringVar1);
*gStringVar1 = EOS;
2021-11-11 22:50:36 +01:00
DynamicPlaceholderTextUtil_ExpandPlaceholders(gStringVar2, gText_NumberIndex);
AddTextPrinterParameterized(gfx->winid, FONT_NORMAL, gStringVar2, 4, 1, TEXT_SKIP_DRAW, NULL);
ConvertIntToDecimalStringN(gStringVar1, rank, STR_CONV_MODE_RIGHT_ALIGN, 3);
AddTextPrinterParameterized(gfx->winid, FONT_NORMAL, gStringVar1, 34, 1, TEXT_SKIP_DRAW, NULL);
CopyWindowToVram(gfx->winid, COPYWIN_GFX);
2019-08-05 19:47:04 +02:00
}
2021-11-13 18:52:41 +01:00
static void CreateSearchResultsList(void)
2019-08-05 19:47:04 +02:00
{
struct PokenavListTemplate template;
template.list = (struct PokenavListItem *)GetSearchResultsMonDataList();
2020-10-11 00:17:34 +02:00
template.count = GetSearchResultsMonListCount();
2021-11-13 18:52:41 +01:00
template.itemSize = sizeof(struct PokenavListItem);
template.startIndex = GetSearchResultsCurrentListIndex();
2020-10-11 00:17:34 +02:00
template.item_X = 13;
template.windowWidth = 17;
template.listTop = 1;
template.maxShowed = 8;
template.fillValue = 2;
2021-10-30 22:47:37 +02:00
template.fontId = FONT_NORMAL;
2021-11-13 18:52:41 +01:00
template.bufferItemFunc = (PokenavListBufferItemFunc)BufferSearchMonListItem;
template.iconDrawFunc = NULL;
CreatePokenavList(&sConditionSearchResultBgTemplates[1], &template, 0);
2019-08-05 19:47:04 +02:00
}
2021-11-13 02:24:14 +01:00
static void BufferSearchMonListItem(struct PokenavMonListItem * item, u8 * dest)
2019-08-05 19:47:04 +02:00
{
u8 gender;
u8 level;
u8 * s;
const u8 * genderStr;
2020-02-01 06:25:50 +01:00
// Mon is in party
if (item->boxId == TOTAL_BOXES_COUNT)
2019-08-05 19:47:04 +02:00
{
struct Pokemon * mon = &gPlayerParty[item->monId];
gender = GetMonGender(mon);
level = GetLevelFromMonExp(mon);
GetMonData(mon, MON_DATA_NICKNAME, gStringVar3);
}
2020-02-01 06:25:50 +01:00
// Mon is in PC
2019-08-05 19:47:04 +02:00
else
{
struct BoxPokemon * mon = GetBoxedMonPtr(item->boxId, item->monId);
gender = GetBoxMonGender(mon);
level = GetLevelFromBoxMonExp(mon);
GetBoxMonData(mon, MON_DATA_NICKNAME, gStringVar3);
}
2020-02-01 06:25:50 +01:00
StringGet_Nickname(gStringVar3);
2021-10-30 22:47:37 +02:00
dest = GetStringClearToWidth(dest, FONT_NORMAL, gStringVar3, 60);
2019-08-05 19:47:04 +02:00
switch (gender)
{
default:
2020-02-01 06:25:50 +01:00
genderStr = sText_NoGenderSymbol;
2019-08-05 19:47:04 +02:00
break;
case MON_MALE:
2020-02-01 06:25:50 +01:00
genderStr = sText_MaleSymbol;
2019-08-05 19:47:04 +02:00
break;
case MON_FEMALE:
2020-02-01 06:25:50 +01:00
genderStr = sText_FemaleSymbol;
2019-08-05 19:47:04 +02:00
break;
}
s = StringCopy(gStringVar1, genderStr);
*s++ = CHAR_SLASH;
2020-08-11 05:50:49 +02:00
*s++ = CHAR_EXTRA_SYMBOL;
2020-02-01 06:25:50 +01:00
*s++ = CHAR_LV_2;
2019-08-05 19:47:04 +02:00
ConvertIntToDecimalStringN(s, level, STR_CONV_MODE_LEFT_ALIGN, 3);
2021-10-30 22:47:37 +02:00
GetStringClearToWidth(dest, FONT_NORMAL, gStringVar1, 40);
2019-08-05 19:47:04 +02:00
}