pokeemerald/src/pokenav_menu_handler_1.c

514 lines
16 KiB
C
Raw Normal View History

#include "global.h"
#include "pokenav.h"
#include "event_data.h"
#include "main.h"
#include "sound.h"
#include "constants/songs.h"
struct Pokenav1Struct
{
2019-04-13 22:54:05 +02:00
u16 menuType;
s16 cursorPos;
2020-02-01 06:25:50 +01:00
u16 currMenuItem;
2019-04-13 22:54:05 +02:00
u16 helpBarIndex;
2020-02-05 08:47:32 +01:00
u32 menuId;
2019-04-13 22:54:05 +02:00
u32 (*callback)(struct Pokenav1Struct*);
};
2020-02-01 06:25:50 +01:00
static bool32 UpdateMenuCursorPos(struct Pokenav1Struct *state);
static void ReturnToConditionMenu(struct Pokenav1Struct *state);
static void ReturnToMainMenu(struct Pokenav1Struct *state);
2020-02-05 08:47:32 +01:00
static u32 GetMenuId(struct Pokenav1Struct *state);
static void SetMenuIdAndCB(struct Pokenav1Struct *state, u32 a1);
2020-02-01 06:25:50 +01:00
static u32 CB2_ReturnToConditionMenu(struct Pokenav1Struct *state);
static u32 CB2_ReturnToMainMenu(struct Pokenav1Struct *state);
static u32 HandleConditionSearchMenuInput(struct Pokenav1Struct *state);
static u32 HandleConditionMenuInput(struct Pokenav1Struct *state);
static u32 HandleCantOpenRibbonsInput(struct Pokenav1Struct *state);
static u32 HandleMainMenuInputEndTutorial(struct Pokenav1Struct *state);
static u32 HandleMainMenuInputTutorial(struct Pokenav1Struct *state);
static u32 HandleMainMenuInput(struct Pokenav1Struct *state);
static u32 (*GetMainMenuInputHandler(void))(struct Pokenav1Struct*);
static void SetMenuInputHandler(struct Pokenav1Struct *state);
// Number of entries - 1 for that menu type
static const u8 sLastCursorPositions[] =
2019-04-13 21:46:46 +02:00
{
[POKENAV_MENU_TYPE_DEFAULT] = 2,
[POKENAV_MENU_TYPE_UNLOCK_MC] = 3,
[POKENAV_MENU_TYPE_UNLOCK_MC_RIBBONS] = 4,
[POKENAV_MENU_TYPE_CONDITION] = 2,
2020-02-01 06:25:50 +01:00
[POKENAV_MENU_TYPE_CONDITION_SEARCH] = 5
};
static const u8 sMenuItems[][6] =
{
[POKENAV_MENU_TYPE_DEFAULT] =
{
POKENAV_MENUITEM_MAP,
POKENAV_MENUITEM_CONDITION,
2020-02-01 06:25:50 +01:00
[2 ... 5] = POKENAV_MENUITEM_SWITCH_OFF
},
[POKENAV_MENU_TYPE_UNLOCK_MC] =
{
POKENAV_MENUITEM_MAP,
POKENAV_MENUITEM_CONDITION,
POKENAV_MENUITEM_MATCH_CALL,
2020-02-01 06:25:50 +01:00
[3 ... 5] = POKENAV_MENUITEM_SWITCH_OFF
},
[POKENAV_MENU_TYPE_UNLOCK_MC_RIBBONS] =
{
POKENAV_MENUITEM_MAP,
POKENAV_MENUITEM_CONDITION,
POKENAV_MENUITEM_MATCH_CALL,
POKENAV_MENUITEM_RIBBONS,
2020-02-01 06:25:50 +01:00
[4 ... 5] = POKENAV_MENUITEM_SWITCH_OFF
},
[POKENAV_MENU_TYPE_CONDITION] =
{
POKENAV_MENUITEM_CONDITION_PARTY,
POKENAV_MENUITEM_CONDITION_SEARCH,
POKENAV_MENUITEM_CONDITION_CANCEL,
2020-02-01 06:25:50 +01:00
[3 ... 5] = POKENAV_MENUITEM_SWITCH_OFF
},
[POKENAV_MENU_TYPE_CONDITION_SEARCH] =
{
POKENAV_MENUITEM_CONDITION_SEARCH_COOL,
POKENAV_MENUITEM_CONDITION_SEARCH_BEAUTY,
POKENAV_MENUITEM_CONDITION_SEARCH_CUTE,
POKENAV_MENUITEM_CONDITION_SEARCH_SMART,
POKENAV_MENUITEM_CONDITION_SEARCH_TOUGH,
POKENAV_MENUITEM_CONDITION_SEARCH_CANCEL
2020-02-01 06:25:50 +01:00
},
2019-04-13 21:46:46 +02:00
};
2019-04-13 22:54:05 +02:00
static u8 GetPokenavMainMenuType(void)
{
2020-02-01 06:25:50 +01:00
u8 menuType = POKENAV_MENU_TYPE_DEFAULT;
if (FlagGet(FLAG_ADDED_MATCH_CALL_TO_POKENAV))
{
2020-02-01 06:25:50 +01:00
menuType = POKENAV_MENU_TYPE_UNLOCK_MC;
if (FlagGet(FLAG_SYS_RIBBON_GET))
2020-02-01 06:25:50 +01:00
menuType = POKENAV_MENU_TYPE_UNLOCK_MC_RIBBONS;
}
2020-02-01 06:25:50 +01:00
return menuType;
}
2020-02-05 08:47:32 +01:00
bool32 PokenavCallback_Init_MainMenuCursorOnMap(void)
{
2020-10-11 00:17:34 +02:00
struct Pokenav1Struct *state = AllocSubstruct(POKENAV_SUBSTRUCT_MAIN_MENU_HANDLER, sizeof(struct Pokenav1Struct));
2019-04-13 21:46:46 +02:00
if (!state)
return FALSE;
2019-04-13 22:54:05 +02:00
state->menuType = GetPokenavMainMenuType();
2020-10-11 00:17:34 +02:00
state->cursorPos = POKENAV_MENUITEM_MAP;
2020-02-01 06:25:50 +01:00
state->currMenuItem = POKENAV_MENUITEM_MAP;
2019-12-07 10:08:21 +01:00
state->helpBarIndex = HELPBAR_NONE;
2020-02-01 06:25:50 +01:00
SetMenuInputHandler(state);
2019-04-13 21:46:46 +02:00
return TRUE;
}
2020-02-05 08:47:32 +01:00
bool32 PokenavCallback_Init_MainMenuCursorOnMatchCall(void)
{
2020-10-11 00:17:34 +02:00
struct Pokenav1Struct *state = AllocSubstruct(POKENAV_SUBSTRUCT_MAIN_MENU_HANDLER, sizeof(struct Pokenav1Struct));
2019-04-13 21:46:46 +02:00
if (!state)
return FALSE;
2019-04-13 22:54:05 +02:00
state->menuType = GetPokenavMainMenuType();
2020-10-11 00:17:34 +02:00
state->cursorPos = POKENAV_MENUITEM_MATCH_CALL;
2020-02-01 06:25:50 +01:00
state->currMenuItem = POKENAV_MENUITEM_MATCH_CALL;
2019-12-07 10:08:21 +01:00
state->helpBarIndex = HELPBAR_NONE;
2020-02-01 06:25:50 +01:00
SetMenuInputHandler(state);
2019-04-13 21:46:46 +02:00
return TRUE;
}
2020-02-05 08:47:32 +01:00
bool32 PokenavCallback_Init_MainMenuCursorOnRibbons(void)
{
2020-10-11 00:17:34 +02:00
struct Pokenav1Struct *state = AllocSubstruct(POKENAV_SUBSTRUCT_MAIN_MENU_HANDLER, sizeof(struct Pokenav1Struct));
2019-04-13 21:46:46 +02:00
if (!state)
return FALSE;
2019-04-13 22:54:05 +02:00
state->menuType = GetPokenavMainMenuType();
2020-10-11 00:17:34 +02:00
state->cursorPos = POKENAV_MENUITEM_RIBBONS;
2020-02-01 06:25:50 +01:00
state->currMenuItem = POKENAV_MENUITEM_RIBBONS;
SetMenuInputHandler(state);
2019-04-13 21:46:46 +02:00
return TRUE;
}
2020-02-05 08:47:32 +01:00
bool32 PokenavCallback_Init_ConditionMenu(void)
{
2020-10-11 00:17:34 +02:00
struct Pokenav1Struct *state = AllocSubstruct(POKENAV_SUBSTRUCT_MAIN_MENU_HANDLER, sizeof(struct Pokenav1Struct));
2019-04-13 21:46:46 +02:00
if (!state)
return FALSE;
2020-02-01 06:25:50 +01:00
state->menuType = POKENAV_MENU_TYPE_CONDITION;
2020-10-11 00:17:34 +02:00
state->cursorPos = 0; //party
2020-02-01 06:25:50 +01:00
state->currMenuItem = POKENAV_MENUITEM_CONDITION_PARTY;
2019-12-07 10:08:21 +01:00
state->helpBarIndex = HELPBAR_NONE;
2020-02-01 06:25:50 +01:00
SetMenuInputHandler(state);
2019-04-13 21:46:46 +02:00
return TRUE;
}
2020-02-05 08:47:32 +01:00
bool32 PokenavCallback_Init_ConditionSearchMenu(void)
{
2020-10-11 00:17:34 +02:00
struct Pokenav1Struct *state = AllocSubstruct(POKENAV_SUBSTRUCT_MAIN_MENU_HANDLER, sizeof(struct Pokenav1Struct));
2019-04-13 21:46:46 +02:00
if (!state)
return FALSE;
2020-02-01 06:25:50 +01:00
state->menuType = POKENAV_MENU_TYPE_CONDITION_SEARCH;
state->cursorPos = GetSelectedConditionSearch();
state->currMenuItem = state->cursorPos + POKENAV_MENUITEM_CONDITION_SEARCH_COOL;
2019-12-07 10:08:21 +01:00
state->helpBarIndex = HELPBAR_NONE;
2020-02-01 06:25:50 +01:00
SetMenuInputHandler(state);
2019-04-13 21:46:46 +02:00
return TRUE;
}
2020-02-01 06:25:50 +01:00
static void SetMenuInputHandler(struct Pokenav1Struct *state)
{
2019-04-13 22:54:05 +02:00
switch (state->menuType)
{
2020-02-01 06:25:50 +01:00
case POKENAV_MENU_TYPE_DEFAULT:
2019-04-13 22:54:05 +02:00
SetPokenavMode(POKENAV_MODE_NORMAL);
// fallthrough
2020-02-01 06:25:50 +01:00
case POKENAV_MENU_TYPE_UNLOCK_MC:
case POKENAV_MENU_TYPE_UNLOCK_MC_RIBBONS:
state->callback = GetMainMenuInputHandler();
break;
2020-02-01 06:25:50 +01:00
case POKENAV_MENU_TYPE_CONDITION:
state->callback = HandleConditionMenuInput;
break;
2020-02-01 06:25:50 +01:00
case POKENAV_MENU_TYPE_CONDITION_SEARCH:
state->callback = HandleConditionSearchMenuInput;
break;
}
}
2020-02-01 06:25:50 +01:00
static u32 (*GetMainMenuInputHandler(void))(struct Pokenav1Struct*)
{
switch (GetPokenavMode())
{
default:
2019-04-13 22:54:05 +02:00
case POKENAV_MODE_NORMAL:
2020-02-01 06:25:50 +01:00
return HandleMainMenuInput;
2019-12-05 21:33:36 +01:00
case POKENAV_MODE_FORCE_CALL_READY:
2020-02-01 06:25:50 +01:00
return HandleMainMenuInputTutorial;
2019-12-05 21:33:36 +01:00
case POKENAV_MODE_FORCE_CALL_EXIT:
2020-02-01 06:25:50 +01:00
return HandleMainMenuInputEndTutorial;
}
}
2020-02-05 08:47:32 +01:00
u32 GetMenuHandlerCallback(void)
{
2020-10-11 00:17:34 +02:00
struct Pokenav1Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MAIN_MENU_HANDLER);
2019-04-13 22:54:05 +02:00
return state->callback(state);
}
2020-02-05 08:47:32 +01:00
void FreeMenuHandlerSubstruct1(void)
{
2020-10-11 00:17:34 +02:00
FreePokenavSubstruct(POKENAV_SUBSTRUCT_MAIN_MENU_HANDLER);
}
2020-02-01 06:25:50 +01:00
static u32 HandleMainMenuInput(struct Pokenav1Struct *state)
{
2020-02-01 06:25:50 +01:00
if (UpdateMenuCursorPos(state))
return POKENAV_MENU_FUNC_MOVE_CURSOR;
if (JOY_NEW(A_BUTTON))
{
2020-02-01 06:25:50 +01:00
switch (sMenuItems[state->menuType][state->cursorPos])
{
2020-02-01 06:25:50 +01:00
case POKENAV_MENUITEM_MAP:
state->helpBarIndex = gSaveBlock2Ptr->regionMapZoom ? HELPBAR_MAP_ZOOMED_IN : HELPBAR_MAP_ZOOMED_OUT;
2020-02-05 08:47:32 +01:00
SetMenuIdAndCB(state, POKENAV_REGION_MAP);
2020-02-01 06:25:50 +01:00
return POKENAV_MENU_FUNC_OPEN_FEATURE;
case POKENAV_MENUITEM_CONDITION:
state->menuType = POKENAV_MENU_TYPE_CONDITION;
state->cursorPos = 0;
state->currMenuItem = sMenuItems[POKENAV_MENU_TYPE_CONDITION][0];
state->callback = HandleConditionMenuInput;
return POKENAV_MENU_FUNC_OPEN_CONDITION;
case POKENAV_MENUITEM_MATCH_CALL:
state->helpBarIndex = HELPBAR_MC_TRAINER_LIST;
2020-02-05 08:47:32 +01:00
SetMenuIdAndCB(state, POKENAV_MATCH_CALL);
2020-02-01 06:25:50 +01:00
return POKENAV_MENU_FUNC_OPEN_FEATURE;
case POKENAV_MENUITEM_RIBBONS:
if (CanViewRibbonsMenu())
{
2020-02-01 06:25:50 +01:00
state->helpBarIndex = HELPBAR_RIBBONS_MON_LIST;
2020-02-05 08:47:32 +01:00
SetMenuIdAndCB(state, POKENAV_RIBBONS_MON_LIST);
2020-02-01 06:25:50 +01:00
return POKENAV_MENU_FUNC_OPEN_FEATURE;
}
else
{
2020-02-01 06:25:50 +01:00
state->callback = HandleCantOpenRibbonsInput;
return POKENAV_MENU_FUNC_NO_RIBBON_WINNERS;
}
2020-02-01 06:25:50 +01:00
case POKENAV_MENUITEM_SWITCH_OFF:
2020-10-11 00:17:34 +02:00
return POKENAV_MENU_FUNC_EXIT;
}
}
2020-10-26 16:16:36 +01:00
if (JOY_NEW(B_BUTTON))
return POKENAV_MENU_FUNC_EXIT;
2020-02-01 06:25:50 +01:00
return POKENAV_MENU_FUNC_NONE;
}
2020-02-01 06:25:50 +01:00
// Force the player to select Match Call during the call Mr. Stone pokenav tutorial
static u32 HandleMainMenuInputTutorial(struct Pokenav1Struct *state)
{
2020-02-01 06:25:50 +01:00
if (UpdateMenuCursorPos(state))
return POKENAV_MENU_FUNC_MOVE_CURSOR;
2020-10-26 16:16:36 +01:00
if (JOY_NEW(A_BUTTON))
{
2020-02-01 06:25:50 +01:00
if (sMenuItems[state->menuType][state->cursorPos] == POKENAV_MENUITEM_MATCH_CALL)
{
2020-02-01 06:25:50 +01:00
state->helpBarIndex = HELPBAR_MC_TRAINER_LIST;
2020-02-05 08:47:32 +01:00
SetMenuIdAndCB(state, POKENAV_MATCH_CALL);
2020-02-01 06:25:50 +01:00
return POKENAV_MENU_FUNC_OPEN_FEATURE;
}
else
{
2020-08-21 00:02:00 +02:00
PlaySE(SE_FAILURE);
2020-02-01 06:25:50 +01:00
return POKENAV_MENU_FUNC_NONE;
}
}
if (JOY_NEW(B_BUTTON))
{
2020-08-21 00:02:00 +02:00
PlaySE(SE_FAILURE);
2020-02-01 06:25:50 +01:00
return POKENAV_MENU_FUNC_NONE;
}
2020-02-01 06:25:50 +01:00
return POKENAV_MENU_FUNC_NONE;
}
2020-02-01 06:25:50 +01:00
// After calling Mr. Stone during the pokenav tutorial, force player to exit or use Match Call again
static u32 HandleMainMenuInputEndTutorial(struct Pokenav1Struct *state)
{
2020-02-01 06:25:50 +01:00
if (UpdateMenuCursorPos(state))
return POKENAV_MENU_FUNC_MOVE_CURSOR;
if (JOY_NEW(A_BUTTON))
{
2020-02-01 06:25:50 +01:00
u32 menuItem = sMenuItems[state->menuType][state->cursorPos];
if (menuItem != POKENAV_MENUITEM_MATCH_CALL && menuItem != POKENAV_MENUITEM_SWITCH_OFF)
{
2020-08-21 00:02:00 +02:00
PlaySE(SE_FAILURE);
2020-02-01 06:25:50 +01:00
return POKENAV_MENU_FUNC_NONE;
}
2020-02-01 06:25:50 +01:00
else if (menuItem == POKENAV_MENUITEM_MATCH_CALL)
{
2020-02-01 06:25:50 +01:00
state->helpBarIndex = HELPBAR_MC_TRAINER_LIST;
2020-02-05 08:47:32 +01:00
SetMenuIdAndCB(state, POKENAV_MATCH_CALL);
2020-02-01 06:25:50 +01:00
return POKENAV_MENU_FUNC_OPEN_FEATURE;
}
else
{
return -1;
}
}
else if (JOY_NEW(B_BUTTON))
{
return -1;
}
2020-02-01 06:25:50 +01:00
return POKENAV_MENU_FUNC_NONE;
}
2020-02-01 06:25:50 +01:00
// Handles input after selecting Ribbons when there are no ribbon winners left
// Selecting it again just reprints the Ribbon description to replace the "No Ribbon winners" message
static u32 HandleCantOpenRibbonsInput(struct Pokenav1Struct *state)
{
2020-02-01 06:25:50 +01:00
if (UpdateMenuCursorPos(state))
{
2020-02-01 06:25:50 +01:00
state->callback = GetMainMenuInputHandler();
return POKENAV_MENU_FUNC_MOVE_CURSOR;
}
if (JOY_NEW(A_BUTTON | B_BUTTON))
{
2020-02-01 06:25:50 +01:00
state->callback = GetMainMenuInputHandler();
return POKENAV_MENU_FUNC_RESHOW_DESCRIPTION;
}
2020-02-01 06:25:50 +01:00
return POKENAV_MENU_FUNC_NONE;
2019-04-10 18:18:44 +02:00
}
2020-02-01 06:25:50 +01:00
static u32 HandleConditionMenuInput(struct Pokenav1Struct *state)
2019-04-10 18:18:44 +02:00
{
2020-02-01 06:25:50 +01:00
if (UpdateMenuCursorPos(state))
return POKENAV_MENU_FUNC_MOVE_CURSOR;
if (JOY_NEW(A_BUTTON))
2019-04-10 18:18:44 +02:00
{
2020-02-01 06:25:50 +01:00
switch (sMenuItems[state->menuType][state->cursorPos])
2019-04-10 18:18:44 +02:00
{
2020-02-01 06:25:50 +01:00
case POKENAV_MENUITEM_CONDITION_SEARCH:
state->menuType = POKENAV_MENU_TYPE_CONDITION_SEARCH;
state->cursorPos = 0;
state->currMenuItem = sMenuItems[POKENAV_MENU_TYPE_CONDITION_SEARCH][0];
state->callback = HandleConditionSearchMenuInput;
return POKENAV_MENU_FUNC_OPEN_CONDITION_SEARCH;
case POKENAV_MENUITEM_CONDITION_PARTY:
state->helpBarIndex = 0;
2020-02-05 08:47:32 +01:00
SetMenuIdAndCB(state, POKENAV_CONDITION_PARTY);
2020-02-01 06:25:50 +01:00
return POKENAV_MENU_FUNC_OPEN_FEATURE;
case POKENAV_MENUITEM_CONDITION_CANCEL:
2019-04-10 18:18:44 +02:00
PlaySE(SE_SELECT);
2020-02-01 06:25:50 +01:00
ReturnToMainMenu(state);
return POKENAV_MENU_FUNC_RETURN_TO_MAIN;
2019-04-10 18:18:44 +02:00
}
}
if (JOY_NEW(B_BUTTON))
2019-04-10 18:18:44 +02:00
{
2020-02-01 06:25:50 +01:00
if (state->cursorPos != sLastCursorPositions[state->menuType])
2019-04-10 18:18:44 +02:00
{
2020-02-01 06:25:50 +01:00
state->cursorPos = sLastCursorPositions[state->menuType];
state->callback = CB2_ReturnToMainMenu;
return POKENAV_MENU_FUNC_MOVE_CURSOR;
2019-04-10 18:18:44 +02:00
}
else
{
PlaySE(SE_SELECT);
2020-02-01 06:25:50 +01:00
ReturnToMainMenu(state);
return POKENAV_MENU_FUNC_RETURN_TO_MAIN;
2019-04-10 18:18:44 +02:00
}
}
2020-02-01 06:25:50 +01:00
return POKENAV_MENU_FUNC_NONE;
2019-04-10 18:18:44 +02:00
}
2020-02-01 06:25:50 +01:00
static u32 HandleConditionSearchMenuInput(struct Pokenav1Struct *state)
2019-04-10 18:18:44 +02:00
{
2020-02-01 06:25:50 +01:00
if (UpdateMenuCursorPos(state))
return POKENAV_MENU_FUNC_MOVE_CURSOR;
if (JOY_NEW(A_BUTTON))
2019-04-10 18:18:44 +02:00
{
2020-02-01 06:25:50 +01:00
u8 menuItem = sMenuItems[state->menuType][state->cursorPos];
if (menuItem != POKENAV_MENUITEM_CONDITION_SEARCH_CANCEL)
2019-04-10 18:18:44 +02:00
{
2020-02-01 06:25:50 +01:00
SetSelectedConditionSearch(menuItem - POKENAV_MENUITEM_CONDITION_SEARCH_COOL);
2020-02-05 08:47:32 +01:00
SetMenuIdAndCB(state, POKENAV_CONDITION_SEARCH_RESULTS);
2020-02-01 06:25:50 +01:00
state->helpBarIndex = HELPBAR_CONDITION_MON_LIST;
return POKENAV_MENU_FUNC_OPEN_FEATURE;
2019-04-10 18:18:44 +02:00
}
else
{
PlaySE(SE_SELECT);
2020-02-01 06:25:50 +01:00
ReturnToConditionMenu(state);
return POKENAV_MENU_FUNC_RETURN_TO_CONDITION;
2019-04-10 18:18:44 +02:00
}
}
if (JOY_NEW(B_BUTTON))
2019-04-10 18:18:44 +02:00
{
2020-02-01 06:25:50 +01:00
if (state->cursorPos != sLastCursorPositions[state->menuType])
2019-04-10 18:18:44 +02:00
{
2020-02-01 06:25:50 +01:00
state->cursorPos = sLastCursorPositions[state->menuType];
state->callback = CB2_ReturnToConditionMenu;
return POKENAV_MENU_FUNC_MOVE_CURSOR;
2019-04-10 18:18:44 +02:00
}
else
{
PlaySE(SE_SELECT);
2020-02-01 06:25:50 +01:00
ReturnToConditionMenu(state);
return POKENAV_MENU_FUNC_RETURN_TO_CONDITION;
2019-04-10 18:18:44 +02:00
}
}
2020-02-01 06:25:50 +01:00
return POKENAV_MENU_FUNC_NONE;
2019-04-10 18:18:44 +02:00
}
2020-02-01 06:25:50 +01:00
static u32 CB2_ReturnToMainMenu(struct Pokenav1Struct *state)
2019-04-10 18:18:44 +02:00
{
2020-02-01 06:25:50 +01:00
ReturnToMainMenu(state);
return POKENAV_MENU_FUNC_RETURN_TO_MAIN;
2019-04-10 18:18:44 +02:00
}
2020-02-01 06:25:50 +01:00
static u32 CB2_ReturnToConditionMenu(struct Pokenav1Struct *state)
2019-04-10 18:18:44 +02:00
{
2020-02-01 06:25:50 +01:00
ReturnToConditionMenu(state);
return POKENAV_MENU_FUNC_RETURN_TO_CONDITION;
2019-04-10 18:18:44 +02:00
}
2020-02-05 08:47:32 +01:00
static void SetMenuIdAndCB(struct Pokenav1Struct *state, u32 menuId)
2019-04-10 18:18:44 +02:00
{
2020-02-05 08:47:32 +01:00
state->menuId = menuId;
state->callback = GetMenuId;
2019-04-10 18:18:44 +02:00
}
2020-02-05 08:47:32 +01:00
static u32 GetMenuId(struct Pokenav1Struct *state)
2019-04-10 18:18:44 +02:00
{
2020-02-05 08:47:32 +01:00
return state->menuId;
2019-04-10 18:18:44 +02:00
}
2020-02-01 06:25:50 +01:00
static void ReturnToMainMenu(struct Pokenav1Struct *state)
2019-04-10 18:18:44 +02:00
{
2020-02-01 06:25:50 +01:00
state->menuType = GetPokenavMainMenuType();
state->cursorPos = 1;
state->currMenuItem = sMenuItems[state->menuType][state->cursorPos];
state->callback = HandleMainMenuInput;
2019-04-10 18:18:44 +02:00
}
2020-02-01 06:25:50 +01:00
static void ReturnToConditionMenu(struct Pokenav1Struct *state)
2019-04-10 18:18:44 +02:00
{
2020-02-01 06:25:50 +01:00
state->menuType = POKENAV_MENU_TYPE_CONDITION;
state->cursorPos = 1;
state->currMenuItem = sMenuItems[POKENAV_MENU_TYPE_CONDITION][1];
state->callback = HandleConditionMenuInput;
2019-04-13 21:46:46 +02:00
}
2020-02-01 06:25:50 +01:00
static bool32 UpdateMenuCursorPos(struct Pokenav1Struct *state)
2019-04-13 21:46:46 +02:00
{
if (JOY_NEW(DPAD_UP))
2019-04-13 21:46:46 +02:00
{
2020-02-01 06:25:50 +01:00
if (--state->cursorPos < 0)
state->cursorPos = sLastCursorPositions[state->menuType];
2019-04-13 21:46:46 +02:00
2020-02-01 06:25:50 +01:00
state->currMenuItem = sMenuItems[state->menuType][state->cursorPos];
2019-04-13 21:46:46 +02:00
return TRUE;
}
else if (JOY_NEW(DPAD_DOWN))
2019-04-13 21:46:46 +02:00
{
2020-02-01 06:25:50 +01:00
state->cursorPos++;
if (state->cursorPos > sLastCursorPositions[state->menuType])
state->cursorPos = 0;
2019-04-13 21:46:46 +02:00
2020-02-01 06:25:50 +01:00
state->currMenuItem = sMenuItems[state->menuType][state->cursorPos];
2019-04-13 21:46:46 +02:00
return TRUE;
}
else
{
return FALSE;
}
}
2020-02-01 06:25:50 +01:00
int GetPokenavMenuType(void)
2019-04-13 21:46:46 +02:00
{
2020-10-11 00:17:34 +02:00
struct Pokenav1Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MAIN_MENU_HANDLER);
2019-04-13 22:54:05 +02:00
return state->menuType;
2019-04-13 21:46:46 +02:00
}
2020-02-01 06:25:50 +01:00
// Position of cursor relative to number of current menu options
int GetPokenavCursorPos(void)
2019-04-13 21:46:46 +02:00
{
2020-10-11 00:17:34 +02:00
struct Pokenav1Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MAIN_MENU_HANDLER);
2019-04-13 22:54:05 +02:00
return state->cursorPos;
2019-04-13 21:46:46 +02:00
}
2020-02-01 06:25:50 +01:00
// ID of menu item the cursor is currently on
int GetCurrentMenuItemId(void)
2019-04-13 21:46:46 +02:00
{
2020-10-11 00:17:34 +02:00
struct Pokenav1Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MAIN_MENU_HANDLER);
2020-02-01 06:25:50 +01:00
return state->currMenuItem;
2019-04-13 21:46:46 +02:00
}
2019-12-07 10:08:21 +01:00
u16 GetHelpBarTextId(void)
2019-04-13 21:46:46 +02:00
{
2020-10-11 00:17:34 +02:00
struct Pokenav1Struct *state = GetSubstructPtr(POKENAV_SUBSTRUCT_MAIN_MENU_HANDLER);
2019-04-13 22:54:05 +02:00
return state->helpBarIndex;
2019-04-13 21:46:46 +02:00
}