pokeemerald/src/pokenav_conditions_3.c

728 lines
22 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,
};
2019-08-05 16:54:56 +02:00
struct PokenavSub7
{
2020-10-11 00:17:34 +02:00
u32 (*callback)(struct PokenavSub7 *);
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;
u32 returnFromGraph;
2020-10-11 00:17:34 +02:00
u32 isPartyCondition;
struct PokenavSub18 *monList;
2019-08-05 16:54:56 +02:00
};
struct PokenavSub8
{
bool32 (*callback)(void);
2020-10-11 00:17:34 +02:00
u32 ltid; //looped task Id
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
2020-10-11 00:17:34 +02:00
static u32 HandleConditionSearchInput_WaitSetup(struct PokenavSub7 *structPtr);
static u32 HandleConditionSearchInput(struct PokenavSub7 *structPtr);
static u32 OpenConditionGraphFromSearchList(struct PokenavSub7 *structPtr);
2020-10-11 00:17:34 +02:00
static u32 ReturnToConditionSearchList(struct PokenavSub7 *structPtr);
static u32 GetConditionSearchLoopedTask(s32 state);
static u32 BuildPartyMonSearchResults(s32 state);
static u32 InitBoxMonSearchResults(s32 state);
static u32 BuildBoxMonSearchResults(s32 state);
static u32 sub_81CF278(s32 state);
2020-10-11 00:17:34 +02:00
static u32 LoopedTask_MoveSearchListCursorUp(s32 state);
static u32 LoopedTask_MoveSearchListCursorDown(s32 state);
static u32 LoopedTask_MoveSearchListPageUp(s32 state);
static u32 LoopedTask_MoveSearchListPageDown(s32 state);
static u32 LoopedTask_ExitConditionSearchMenu(s32 state);
static u32 LoopedTask_SelectSearchResult(s32 state);
static void sub_81CF2C4(struct PokenavSub7 *structPtr, struct PokenavMonList *item);
2020-10-11 00:17:34 +02:00
static bool32 GetSearchResultCurrentLoopedTaskActive(void);
static u32 LoopedTask_OpenConditionSearchResults(s32 state);
static void AddSearchResultListMenuWindow(struct PokenavSub8 *);
static void PrintSearchResultListMenuItems(struct PokenavSub8 *);
static void InitConditionSearchListMenuTemplate(void);
static void PrintSearchMonListItem(struct PokenavMonList *, 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,
2019-07-20 04:06:42 +02:00
sub_81CF278
};
2020-10-11 00:17:34 +02:00
static const u16 sConditionSearchResultFramePal[] = INCBIN_U16("graphics/pokenav/condition_search2.gbapal");
static const u32 sConditionSearchResultTiles[] = INCBIN_U32("graphics/pokenav/condition_search2.4bpp.lz");
static const u32 sConditionSearchResultTilemap[] = INCBIN_U32("graphics/pokenav/condition_search2.bin.lz");
static const u16 gUnknown_08623570[] = INCBIN_U16("graphics/pokenav/8623570.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
};
2020-10-11 00:17:34 +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
};
2020-10-11 00:17:34 +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
{
struct PokenavSub7 *structPtr = AllocSubstruct(7, sizeof(struct PokenavSub7));
if (structPtr == NULL)
return FALSE;
2020-10-11 00:17:34 +02:00
structPtr->monList = AllocSubstruct(POKENAV_SUBSTRUCT_MON_LIST, sizeof(struct PokenavSub18));
if (structPtr->monList == NULL)
2019-07-25 21:41:02 +02:00
return FALSE;
2020-10-11 00:17:34 +02:00
structPtr->callback = HandleConditionSearchInput_WaitSetup;
structPtr->loopedTaskId = CreateLoopedTask(GetConditionSearchLoopedTask, 1);
structPtr->returnFromGraph = 0;
2020-10-11 00:17:34 +02:00
structPtr->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
{
2020-10-11 00:17:34 +02:00
struct PokenavSub7 *structPtr = AllocSubstruct(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS, sizeof(struct PokenavSub7));
2019-07-25 21:41:02 +02:00
if (structPtr == NULL)
return FALSE;
2020-10-11 00:17:34 +02:00
structPtr->monList = GetSubstructPtr(POKENAV_SUBSTRUCT_MON_LIST);
structPtr->callback = HandleConditionSearchInput;
structPtr->returnFromGraph = 1;
2020-10-11 00:17:34 +02:00
structPtr->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
{
2020-10-11 00:17:34 +02:00
struct PokenavSub7 *structPtr = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS);
return structPtr->callback(structPtr);
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
{
2020-10-11 00:17:34 +02:00
struct PokenavSub7 *structPtr = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS);
if (structPtr->isPartyCondition == 0)
FreePokenavSubstruct(POKENAV_SUBSTRUCT_MON_LIST);
FreePokenavSubstruct(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS);
2019-07-25 21:41:02 +02:00
}
2020-10-11 00:17:34 +02:00
static bool32 HandleConditionSearchInput_WaitSetup(struct PokenavSub7 *structPtr)
2019-07-25 21:41:02 +02:00
{
if (!IsLoopedTaskActive(structPtr->loopedTaskId))
2020-10-11 00:17:34 +02:00
structPtr->callback = HandleConditionSearchInput;
2019-07-25 21:41:02 +02:00
return FALSE;
}
2020-10-11 00:17:34 +02:00
static u32 HandleConditionSearchInput(struct PokenavSub7 *structPtr)
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
{
2020-10-11 00:17:34 +02:00
structPtr->isPartyCondition = 0;
structPtr->callback = ReturnToConditionSearchList;
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
{
2020-10-11 00:17:34 +02:00
structPtr->monList->currIndex = GetSelectedPokenavListIndex();
structPtr->isPartyCondition = 1;
structPtr->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
}
2020-10-11 00:17:34 +02:00
static u32 ReturnToConditionSearchList(struct PokenavSub7 *structPtr)
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
}
static u32 OpenConditionGraphFromSearchList(struct PokenavSub7 *structPtr)
2019-07-25 21:41:02 +02:00
{
return POKENAV_CONDITION_GRAPH_FROM_SEARCH;
2019-07-25 21:41:02 +02:00
}
static u32 sub_81CF0C0(void)
2019-07-25 21:41:02 +02:00
{
2020-10-11 00:17:34 +02:00
struct PokenavSub7 *structPtr = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS);
return structPtr->returnFromGraph;
2019-07-25 21:41:02 +02:00
}
2019-08-05 16:54:56 +02:00
2020-10-11 00:17:34 +02:00
static struct PokenavMonList * GetSearchResultsMonDataList(void)
2019-08-05 16:54:56 +02:00
{
2020-10-11 00:17:34 +02:00
struct PokenavSub7 * ptr = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS);
return ptr->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
{
2020-10-11 00:17:34 +02:00
struct PokenavSub7 * ptr = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS);
return ptr->monList->listCount;
2019-08-05 16:54:56 +02:00
}
2020-10-11 00:17:34 +02:00
static s32 GetSearchResultsSelectedMonData(void)
2019-08-05 16:54:56 +02:00
{
2020-10-11 00:17:34 +02:00
struct PokenavSub7 * ptr = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS);
s32 i = GetSelectedPokenavListIndex();
return ptr->monList->monData[i].data;
2019-08-05 16:54:56 +02:00
}
static u16 sub_81CF10C(void)
2019-08-05 16:54:56 +02:00
{
2020-10-11 00:17:34 +02:00
struct PokenavSub7 * ptr = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS);
return ptr->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;
struct PokenavMonList item;
2020-10-11 00:17:34 +02:00
struct PokenavSub7 * ptr = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS);
2019-08-05 16:54:56 +02:00
2020-10-11 00:17:34 +02:00
ptr->monList->listCount = 0;
ptr->monList->currIndex = 0;
2019-08-05 16:54:56 +02:00
item.boxId = 14;
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;
2020-10-11 00:17:34 +02:00
item.data = GetMonData(pokemon, ptr->conditionDataId);
2019-08-05 16:54:56 +02:00
sub_81CF2C4(ptr, &item);
}
}
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
{
2020-10-11 00:17:34 +02:00
struct PokenavSub7 * ptr = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS);
ptr->monId = 0;
ptr->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
{
2020-10-11 00:17:34 +02:00
struct PokenavSub7 * ptr = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS);
s32 boxId = ptr->boxId;
s32 monId = ptr->monId;
2019-08-05 16:54:56 +02:00
s32 boxCount = 0;
struct PokenavMonList item;
while (boxId < TOTAL_BOXES_COUNT)
{
while (monId < IN_BOX_COUNT)
{
if (CheckBoxMonSanityAt(boxId, monId))
{
item.boxId = boxId;
item.monId = monId;
2020-10-11 00:17:34 +02:00
item.data = GetBoxMonDataAt(boxId, monId, ptr->conditionDataId);
2019-08-05 16:54:56 +02:00
sub_81CF2C4(ptr, &item);
}
boxCount++;
monId++;
if (boxCount > 14)
{
2020-10-11 00:17:34 +02:00
ptr->boxId = boxId;
ptr->monId = monId;
2019-08-05 16:54:56 +02:00
return LT_CONTINUE;
}
}
monId = 0;
boxId++;
}
return LT_INC_AND_CONTINUE;
}
static u32 sub_81CF278(s32 state)
2019-08-05 16:54:56 +02:00
{
2020-10-11 00:17:34 +02:00
struct PokenavSub7 * ptr = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULTS);
s32 r6 = ptr->monList->listCount;
s32 r4 = ptr->monList->monData[0].data;
2019-08-05 16:54:56 +02:00
s32 i;
2020-10-11 00:17:34 +02:00
ptr->monList->monData[0].data = 1;
2019-08-05 16:54:56 +02:00
for (i = 1; i < r6; i++)
{
2020-10-11 00:17:34 +02:00
if (ptr->monList->monData[i].data == r4)
2019-08-05 16:54:56 +02:00
{
2020-10-11 00:17:34 +02:00
ptr->monList->monData[i].data = ptr->monList->monData[i - 1].data;
2019-08-05 16:54:56 +02:00
}
else
{
2020-10-11 00:17:34 +02:00
r4 = ptr->monList->monData[i].data;
ptr->monList->monData[i].data = i + 1;
2019-08-05 16:54:56 +02:00
}
}
ptr->returnFromGraph = 1;
2019-08-05 16:54:56 +02:00
return LT_FINISH;
}
2019-08-05 18:21:45 +02:00
static void sub_81CF2C4(struct PokenavSub7 *structPtr, struct PokenavMonList *item)
2019-08-05 18:21:45 +02:00
{
u32 left = 0;
2020-10-11 00:17:34 +02:00
u32 right = structPtr->monList->listCount;
2019-08-05 18:21:45 +02:00
u32 insertionIdx = left + (right - left) / 2;
while (right != insertionIdx)
{
2020-10-11 00:17:34 +02:00
if (item->data > structPtr->monList->monData[insertionIdx].data)
2019-08-05 18:21:45 +02:00
right = insertionIdx;
else
left = insertionIdx + 1;
insertionIdx = left + (right - left) / 2;
}
2020-10-11 00:17:34 +02:00
for (right = structPtr->monList->listCount; right > insertionIdx; right--)
structPtr->monList->monData[right] = structPtr->monList->monData[right - 1];
structPtr->monList->monData[insertionIdx] = *item;
structPtr->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
{
2020-10-11 00:17:34 +02:00
struct PokenavSub8 *searchList = AllocSubstruct(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULT_LIST, sizeof(struct PokenavSub8));
if (searchList == NULL)
2019-08-05 18:21:45 +02:00
return FALSE;
2020-10-11 00:17:34 +02:00
searchList->ltid = CreateLoopedTask(LoopedTask_OpenConditionSearchResults, 1);
searchList->callback = GetSearchResultCurrentLoopedTaskActive;
searchList->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
{
2020-10-11 00:17:34 +02:00
struct PokenavSub8 *searchList = AllocSubstruct(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULT_LIST, sizeof(struct PokenavSub8));
if (searchList == NULL)
2019-08-05 18:21:45 +02:00
return FALSE;
2020-10-11 00:17:34 +02:00
searchList->ltid = CreateLoopedTask(LoopedTask_OpenConditionSearchResults, 1);
searchList->callback = GetSearchResultCurrentLoopedTaskActive;
searchList->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
{
2020-10-11 00:17:34 +02:00
struct PokenavSub8 *searchList = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULT_LIST);
searchList->ltid = CreateLoopedTask(sSearchResultLoopTaskFuncs[idx], 1);
searchList->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
{
2020-10-11 00:17:34 +02:00
struct PokenavSub8 *searchList = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULT_LIST);
return searchList->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
{
2020-10-11 00:17:34 +02:00
struct PokenavSub8 *searchList = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULT_LIST);
return IsLoopedTaskActive(searchList->ltid);
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
{
2020-10-11 00:17:34 +02:00
struct PokenavSub8 *searchList = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULT_LIST);
2019-08-05 18:21:45 +02:00
sub_81C8234();
2020-10-11 00:17:34 +02:00
RemoveWindow(searchList->winid);
FreePokenavSubstruct(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULT_LIST);
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
{
2020-10-11 00:17:34 +02:00
struct PokenavSub8 *searchList = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULT_LIST);
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);
SetBgTilemapBuffer(1, searchList->buff);
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;
if (!sub_81CF0C0())
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;
2020-10-11 00:17:34 +02:00
CopyPaletteIntoBufferUnfaded(gUnknown_08623570, 0x20, 32);
InitConditionSearchListMenuTemplate();
2019-08-05 19:47:04 +02:00
return LT_INC_AND_PAUSE;
case 3:
if (sub_81C8224())
return LT_PAUSE;
2020-10-11 00:17:34 +02:00
AddSearchResultListMenuWindow(searchList);
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;
ChangeBgX(1, 0, 0);
ChangeBgY(1, 0, 0);
ShowBg(1);
ShowBg(2);
HideBg(3);
2020-10-11 00:17:34 +02:00
if (!searchList->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
}
2020-02-05 08:47:32 +01:00
PokenavFadeScreen(1);
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
{
2020-10-11 00:17:34 +02:00
struct PokenavSub8 *searchList = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULT_LIST);
2019-08-05 19:47:04 +02:00
switch (state)
{
case 0:
switch (MatchCall_MoveCursorUp())
{
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:
2020-10-11 00:17:34 +02:00
if (IsMonListLoopedTaskActive())
2019-08-05 19:47:04 +02:00
return LT_PAUSE;
// fallthrough
case 2:
2020-10-11 00:17:34 +02:00
PrintSearchResultListMenuItems(searchList);
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
{
2020-10-11 00:17:34 +02:00
struct PokenavSub8 *searchList = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULT_LIST);
2019-08-05 19:47:04 +02:00
switch (state)
{
case 0:
switch (MatchCall_MoveCursorDown())
{
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:
2020-10-11 00:17:34 +02:00
if (IsMonListLoopedTaskActive())
2019-08-05 19:47:04 +02:00
return LT_PAUSE;
// fallthrough
case 2:
2020-10-11 00:17:34 +02:00
PrintSearchResultListMenuItems(searchList);
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
{
2020-10-11 00:17:34 +02:00
struct PokenavSub8 *searchList = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULT_LIST);
2019-08-05 19:47:04 +02:00
switch (state)
{
case 0:
switch (MatchCall_PageUp())
{
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:
2020-10-11 00:17:34 +02:00
if (IsMonListLoopedTaskActive())
2019-08-05 19:47:04 +02:00
return LT_PAUSE;
// fallthrough
case 2:
2020-10-11 00:17:34 +02:00
PrintSearchResultListMenuItems(searchList);
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
{
2020-10-11 00:17:34 +02:00
struct PokenavSub8 *searchList = GetSubstructPtr(POKENAV_SUBSTRUCT_CONDITION_SEARCH_RESULT_LIST);
2019-08-05 19:47:04 +02:00
switch (state)
{
case 0:
switch (MatchCall_PageDown())
{
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:
2020-10-11 00:17:34 +02:00
if (IsMonListLoopedTaskActive())
2019-08-05 19:47:04 +02:00
return LT_PAUSE;
// fallthrough
case 2:
2020-10-11 00:17:34 +02:00
PrintSearchResultListMenuItems(searchList);
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);
2020-02-05 08:47:32 +01:00
PokenavFadeScreen(0);
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);
2020-02-05 08:47:32 +01:00
PokenavFadeScreen(0);
2019-08-05 19:47:04 +02:00
return LT_INC_AND_PAUSE;
case 1:
if (IsPaletteFadeActive())
return LT_PAUSE;
break;
}
return LT_FINISH;
}
2020-10-11 00:17:34 +02:00
static void AddSearchResultListMenuWindow(struct PokenavSub8 *searchList)
2019-08-05 19:47:04 +02:00
{
2020-10-11 00:17:34 +02:00
searchList->winid = AddWindow(&sSearchResultListMenuWindowTemplate);
PutWindowTilemap(searchList->winid);
CopyWindowToVram(searchList->winid, 1);
PrintSearchResultListMenuItems(searchList);
2019-08-05 19:47:04 +02:00
}
2020-10-11 00:17:34 +02:00
static void PrintSearchResultListMenuItems(struct PokenavSub8 *searchList)
2019-08-05 19:47:04 +02:00
{
2020-10-11 00:17:34 +02:00
s32 r7 = GetSearchResultsSelectedMonData();
2019-08-05 19:47:04 +02:00
DynamicPlaceholderTextUtil_Reset();
DynamicPlaceholderTextUtil_SetPlaceholderPtr(0, gStringVar1);
*gStringVar1 = EOS;
DynamicPlaceholderTextUtil_ExpandPlaceholders(gStringVar2, gText_NumberF700);
2020-10-11 00:17:34 +02:00
AddTextPrinterParameterized(searchList->winid, 1, gStringVar2, 4, 1, 0xFF, NULL);
2019-08-05 19:47:04 +02:00
ConvertIntToDecimalStringN(gStringVar1, r7, STR_CONV_MODE_RIGHT_ALIGN, 3);
2020-10-11 00:17:34 +02:00
AddTextPrinterParameterized(searchList->winid, 1, gStringVar1, 34, 1, 0xFF, NULL);
CopyWindowToVram(searchList->winid, 2);
2019-08-05 19:47:04 +02:00
}
2020-10-11 00:17:34 +02:00
static void InitConditionSearchListMenuTemplate(void)
2019-08-05 19:47:04 +02:00
{
struct PokenavListTemplate template;
2020-10-11 00:17:34 +02:00
template.list.monList = GetSearchResultsMonDataList();
template.count = GetSearchResultsMonListCount();
2019-08-05 19:47:04 +02:00
template.unk8 = 4;
template.unk6 = sub_81CF10C();
2020-10-11 00:17:34 +02:00
template.item_X = 13;
template.windowWidth = 17;
template.listTop = 1;
template.maxShowed = 8;
template.fillValue = 2;
template.fontId = 1;
template.listFunc.printMonFunc = PrintSearchMonListItem;
2019-08-05 19:47:04 +02:00
template.unk14 = NULL;
2020-10-11 00:17:34 +02:00
sub_81C81D4(&sConditionSearchResultBgTemplates[1], &template, 0);
2019-08-05 19:47:04 +02:00
}
2020-10-11 00:17:34 +02:00
static void PrintSearchMonListItem(struct PokenavMonList * 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
2019-08-05 19:47:04 +02:00
StringGetEnd10(gStringVar3);
dest = sub_81DB494(dest, 1, gStringVar3, 60);
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);
sub_81DB494(dest, 1, gStringVar1, 40);
}