pokeemerald/src/script_menu.c

843 lines
25 KiB
C
Raw Normal View History

#include "global.h"
2018-11-05 21:45:54 +01:00
#include "main.h"
2018-11-01 05:03:41 +01:00
#include "event_data.h"
2018-11-07 03:13:40 +01:00
#include "field_effect.h"
2018-11-05 21:45:54 +01:00
#include "field_specials.h"
#include "item.h"
2018-11-01 05:03:41 +01:00
#include "menu.h"
2018-11-05 21:45:54 +01:00
#include "palette.h"
#include "script.h"
2018-11-01 05:03:41 +01:00
#include "script_menu.h"
2018-11-05 21:45:54 +01:00
#include "sound.h"
2018-11-01 05:03:41 +01:00
#include "string_util.h"
2018-11-05 21:45:54 +01:00
#include "strings.h"
2018-11-01 05:03:41 +01:00
#include "task.h"
#include "text.h"
2019-09-13 20:24:07 +02:00
#include "constants/field_specials.h"
2018-11-05 21:45:54 +01:00
#include "constants/items.h"
2019-09-19 00:57:25 +02:00
#include "constants/script_menu.h"
2018-11-05 21:45:54 +01:00
#include "constants/songs.h"
2019-09-19 00:57:25 +02:00
#include "data/script_menu.h"
2019-09-20 00:31:09 +02:00
static EWRAM_DATA u8 sProcessInputDelay = 0;
2018-11-05 21:45:54 +01:00
2019-09-20 00:31:09 +02:00
static u8 sLilycoveSSTidalSelections[SSTIDAL_SELECTION_COUNT];
2019-09-20 00:31:09 +02:00
static void Task_HandleMultichoiceInput(u8 taskId);
static void Task_HandleYesNoInput(u8 taskId);
static void Task_HandleMultichoiceGridInput(u8 taskId);
static void DrawMultichoiceMenu(u8 left, u8 top, u8 multichoiceId, bool8 ignoreBPress, u8 cursorPos);
static void InitMultichoiceCheckWrap(bool8 ignoreBPress, u8 count, u8 windowId, u8 multichoiceId);
static void DrawLinkServicesMultichoiceMenu(u8 multichoiceId);
static void CreatePCMultichoice(void);
static void CreateLilycoveSSTidalMultichoice(void);
2018-11-07 03:13:40 +01:00
static bool8 IsPicboxClosed(void);
static void CreateStartMenuForPokenavTutorial(void);
2019-09-20 00:31:09 +02:00
static void InitMultichoiceNoWrap(bool8 ignoreBPress, u8 unusedCount, u8 windowId, u8 multichoiceId);
2018-11-01 05:03:41 +01:00
2019-09-20 00:31:09 +02:00
bool8 ScriptMenu_Multichoice(u8 left, u8 top, u8 multichoiceId, bool8 ignoreBPress)
2018-11-01 05:03:41 +01:00
{
if (FuncIsActiveTask(Task_HandleMultichoiceInput) == TRUE)
{
return FALSE;
}
else
{
gSpecialVar_Result = 0xFF;
DrawMultichoiceMenu(left, top, multichoiceId, ignoreBPress, 0);
return TRUE;
}
}
bool8 ScriptMenu_MultichoiceWithDefault(u8 left, u8 top, u8 multichoiceId, bool8 ignoreBPress, u8 defaultChoice)
{
if (FuncIsActiveTask(Task_HandleMultichoiceInput) == TRUE)
{
return FALSE;
}
else
{
gSpecialVar_Result = 0xFF;
DrawMultichoiceMenu(left, top, multichoiceId, ignoreBPress, defaultChoice);
return TRUE;
}
}
2019-09-19 00:57:25 +02:00
// Unused
2019-09-20 00:31:09 +02:00
static u16 GetLengthWithExpandedPlayerName(const u8 *str)
2018-11-01 05:03:41 +01:00
{
u16 length = 0;
while (*str != EOS)
{
if (*str == PLACEHOLDER_BEGIN)
{
str++;
2019-09-20 01:23:24 +02:00
if (*str == PLACEHOLDER_ID_PLAYER)
2018-11-01 05:03:41 +01:00
{
length += StringLength(gSaveBlock2Ptr->playerName);
str++;
}
}
else
{
str++;
length++;
}
}
return length;
}
2022-09-14 05:17:04 +02:00
static void DrawMultichoiceMenuInternal(u8 left, u8 top, u8 multichoiceId, bool8 ignoreBPress, u8 cursorPos, const struct MenuAction *actions, int count)
2018-11-01 05:03:41 +01:00
{
int i;
u8 windowId;
int width = 0;
u8 newWidth;
2018-11-07 21:09:54 +01:00
2018-11-07 21:48:06 +01:00
for (i = 0; i < count; i++)
2018-11-01 05:03:41 +01:00
{
width = DisplayTextAndGetWidth(actions[i].text, width);
2018-11-01 05:03:41 +01:00
}
newWidth = ConvertPixelWidthToTileWidth(width);
left = ScriptMenu_AdjustLeftCoordFromWidth(left, newWidth);
2018-11-01 05:03:41 +01:00
windowId = CreateWindowFromRect(left, top, newWidth, count * 2);
2022-07-25 20:59:14 +02:00
SetStandardWindowBorderStyle(windowId, FALSE);
2018-11-01 05:03:41 +01:00
PrintMenuTable(windowId, count, actions);
2021-11-03 21:06:58 +01:00
InitMenuInUpperLeftCornerNormal(windowId, count, cursorPos);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
2019-09-20 00:31:09 +02:00
InitMultichoiceCheckWrap(ignoreBPress, count, windowId, multichoiceId);
2018-11-01 05:03:41 +01:00
}
2018-11-05 21:45:54 +01:00
2022-09-14 05:17:04 +02:00
static void DrawMultichoiceMenu(u8 left, u8 top, u8 multichoiceId, bool8 ignoreBPress, u8 cursorPos)
{
DrawMultichoiceMenuInternal(left, top, multichoiceId, ignoreBPress, cursorPos, sMultichoiceLists[multichoiceId].list, sMultichoiceLists[multichoiceId].count);
}
#if I_REPEL_LURE_MENU == TRUE
void TryDrawRepelMenu(void)
{
static const u16 repelItems[] = {ITEM_REPEL, ITEM_SUPER_REPEL, ITEM_MAX_REPEL};
struct MenuAction menuItems[ARRAY_COUNT(repelItems) + 1] = {NULL};
int i, count = 0, menuPos = 0;
for (i = 0; i < ARRAY_COUNT(repelItems); i++)
{
if (CheckBagHasItem(repelItems[i], 1))
{
VarSet(VAR_0x8004 + count, repelItems[i]);
#if VAR_LAST_REPEL_LURE_USED != 0
if (VarGet(VAR_LAST_REPEL_LURE_USED) == repelItems[i])
menuPos = count;
#endif
menuItems[count].text = ItemId_GetName(repelItems[i]);
count++;
}
}
if (count > 1)
DrawMultichoiceMenuInternal(0, 0, 0, FALSE, menuPos, menuItems, count);
gSpecialVar_Result = (count > 1);
}
void HandleRepelMenuChoice(void)
{
gSpecialVar_0x8004 = VarGet(VAR_0x8004 + gSpecialVar_Result); // Get item Id;
VarSet(VAR_REPEL_STEP_COUNT, ItemId_GetHoldEffectParam(gSpecialVar_0x8004));
#if VAR_LAST_REPEL_LURE_USED != 0
VarSet(VAR_LAST_REPEL_LURE_USED, gSpecialVar_0x8004);
#endif
}
void TryDrawLureMenu(void)
{
static const u16 lureItems[] = {ITEM_LURE, ITEM_SUPER_LURE, ITEM_MAX_LURE};
struct MenuAction menuItems[ARRAY_COUNT(lureItems) + 1] = {NULL};
int i, count = 0, menuPos = 0;
for (i = 0; i < ARRAY_COUNT(lureItems); i++)
{
if (CheckBagHasItem(lureItems[i], 1))
{
VarSet(VAR_0x8004 + count, lureItems[i]);
#if VAR_LAST_REPEL_LURE_USED != 0
if (VarGet(VAR_LAST_REPEL_LURE_USED) == lureItems[i])
menuPos = count;
#endif
menuItems[count].text = ItemId_GetName(lureItems[i]);
count++;
}
}
if (count > 1)
DrawMultichoiceMenuInternal(0, 0, 0, FALSE, menuPos, menuItems, count);
gSpecialVar_Result = (count > 1);
}
void HandleLureMenuChoice(void)
{
gSpecialVar_0x8004 = VarGet(VAR_0x8004 + gSpecialVar_Result); // Get item Id;
VarSet(VAR_REPEL_STEP_COUNT, ItemId_GetHoldEffectParam(gSpecialVar_0x8004) | REPEL_LURE_MASK);
#if VAR_LAST_REPEL_LURE_USED != 0
VarSet(VAR_LAST_REPEL_LURE_USED, gSpecialVar_0x8004);
#endif
}
#endif //I_REPEL_LURE_MENU == TRUE
2018-11-05 21:45:54 +01:00
#define tLeft data[0]
#define tTop data[1]
#define tRight data[2]
#define tBottom data[3]
#define tIgnoreBPress data[4]
#define tDoWrap data[5]
#define tWindowId data[6]
#define tMultichoiceId data[7]
2019-09-20 00:31:09 +02:00
static void InitMultichoiceCheckWrap(bool8 ignoreBPress, u8 count, u8 windowId, u8 multichoiceId)
2018-11-05 21:45:54 +01:00
{
u8 i;
u8 taskId;
2019-09-20 00:31:09 +02:00
sProcessInputDelay = 2;
2018-11-05 21:45:54 +01:00
2019-09-20 01:23:24 +02:00
for (i = 0; i < ARRAY_COUNT(sLinkServicesMultichoiceIds); i++)
2018-11-05 21:45:54 +01:00
{
2019-09-20 01:23:24 +02:00
if (sLinkServicesMultichoiceIds[i] == multichoiceId)
2018-11-05 21:45:54 +01:00
{
2019-09-20 00:31:09 +02:00
sProcessInputDelay = 12;
2018-11-05 21:45:54 +01:00
}
}
taskId = CreateTask(Task_HandleMultichoiceInput, 80);
gTasks[taskId].tIgnoreBPress = ignoreBPress;
if (count > 3)
gTasks[taskId].tDoWrap = TRUE;
else
gTasks[taskId].tDoWrap = FALSE;
2018-11-07 21:09:54 +01:00
2018-11-05 21:45:54 +01:00
gTasks[taskId].tWindowId = windowId;
gTasks[taskId].tMultichoiceId = multichoiceId;
DrawLinkServicesMultichoiceMenu(multichoiceId);
2018-11-05 21:45:54 +01:00
}
2018-11-07 03:13:40 +01:00
static void Task_HandleMultichoiceInput(u8 taskId)
2018-11-05 21:45:54 +01:00
{
s8 selection;
s16 *data = gTasks[taskId].data;
if (!gPaletteFade.active)
{
2019-09-20 00:31:09 +02:00
if (sProcessInputDelay)
2018-11-05 21:45:54 +01:00
{
2019-09-20 00:31:09 +02:00
sProcessInputDelay--;
2018-11-05 21:45:54 +01:00
}
else
{
if (!tDoWrap)
selection = Menu_ProcessInputNoWrap();
else
selection = Menu_ProcessInput();
2020-09-05 03:11:55 +02:00
if (JOY_NEW(DPAD_UP | DPAD_DOWN))
2018-11-05 21:45:54 +01:00
{
DrawLinkServicesMultichoiceMenu(tMultichoiceId);
2018-11-05 21:45:54 +01:00
}
2019-02-02 11:04:38 +01:00
if (selection != MENU_NOTHING_CHOSEN)
2018-11-05 21:45:54 +01:00
{
2019-02-02 11:04:38 +01:00
if (selection == MENU_B_PRESSED)
2018-11-05 21:45:54 +01:00
{
if (tIgnoreBPress)
return;
PlaySE(SE_SELECT);
2019-09-19 06:56:51 +02:00
gSpecialVar_Result = MULTI_B_PRESSED;
2018-11-05 21:45:54 +01:00
}
else
{
gSpecialVar_Result = selection;
}
ClearToTransparentAndRemoveWindow(tWindowId);
2018-11-05 21:45:54 +01:00
DestroyTask(taskId);
ScriptContext_Enable();
2018-11-05 21:45:54 +01:00
}
}
}
}
bool8 ScriptMenu_YesNo(u8 left, u8 top)
{
u8 taskId;
if (FuncIsActiveTask(Task_HandleYesNoInput) == TRUE)
{
return FALSE;
}
else
{
gSpecialVar_Result = 0xFF;
2019-02-27 04:30:40 +01:00
DisplayYesNoMenuDefaultYes();
2018-11-05 21:45:54 +01:00
taskId = CreateTask(Task_HandleYesNoInput, 0x50);
return TRUE;
}
}
2019-09-19 00:57:25 +02:00
// Unused
2018-11-05 21:45:54 +01:00
bool8 IsScriptActive(void)
{
if (gSpecialVar_Result == 0xFF)
return FALSE;
else
return TRUE;
}
2018-11-07 03:13:40 +01:00
static void Task_HandleYesNoInput(u8 taskId)
2018-11-05 21:45:54 +01:00
{
if (gTasks[taskId].tRight < 5)
{
gTasks[taskId].tRight++;
return;
}
switch (Menu_ProcessInputNoWrapClearOnChoose())
{
case MENU_NOTHING_CHOSEN:
2018-11-05 21:45:54 +01:00
return;
case MENU_B_PRESSED:
2018-11-05 21:45:54 +01:00
case 1:
PlaySE(SE_SELECT);
gSpecialVar_Result = 0;
break;
case 0:
gSpecialVar_Result = 1;
break;
}
DestroyTask(taskId);
ScriptContext_Enable();
2018-11-05 21:45:54 +01:00
}
2019-09-20 00:31:09 +02:00
bool8 ScriptMenu_MultichoiceGrid(u8 left, u8 top, u8 multichoiceId, bool8 ignoreBPress, u8 columnCount)
2018-11-05 21:45:54 +01:00
{
if (FuncIsActiveTask(Task_HandleMultichoiceGridInput) == TRUE)
{
return FALSE;
}
else
{
u8 taskId;
u8 rowCount, newWidth;
int i, width;
2018-11-05 21:45:54 +01:00
gSpecialVar_Result = 0xFF;
width = 0;
2019-09-20 01:23:24 +02:00
for (i = 0; i < sMultichoiceLists[multichoiceId].count; i++)
2018-11-05 21:45:54 +01:00
{
2019-09-20 01:23:24 +02:00
width = DisplayTextAndGetWidth(sMultichoiceLists[multichoiceId].list[i].text, width);
2018-11-05 21:45:54 +01:00
}
newWidth = ConvertPixelWidthToTileWidth(width);
2018-11-05 21:45:54 +01:00
left = ScriptMenu_AdjustLeftCoordFromWidth(left, columnCount * newWidth);
2019-09-20 01:23:24 +02:00
rowCount = sMultichoiceLists[multichoiceId].count / columnCount;
2018-11-05 21:45:54 +01:00
taskId = CreateTask(Task_HandleMultichoiceGridInput, 80);
gTasks[taskId].tIgnoreBPress = ignoreBPress;
gTasks[taskId].tWindowId = CreateWindowFromRect(left, top, columnCount * newWidth, rowCount * 2);
2022-07-25 20:59:14 +02:00
SetStandardWindowBorderStyle(gTasks[taskId].tWindowId, FALSE);
2019-09-20 01:23:24 +02:00
PrintMenuGridTable(gTasks[taskId].tWindowId, newWidth * 8, columnCount, rowCount, sMultichoiceLists[multichoiceId].list);
2021-04-23 00:49:54 +02:00
InitMenuActionGrid(gTasks[taskId].tWindowId, newWidth * 8, columnCount, rowCount, 0);
2021-11-03 20:29:18 +01:00
CopyWindowToVram(gTasks[taskId].tWindowId, COPYWIN_FULL);
2018-11-05 21:45:54 +01:00
return TRUE;
}
}
2018-11-07 03:13:40 +01:00
static void Task_HandleMultichoiceGridInput(u8 taskId)
2018-11-05 21:45:54 +01:00
{
s16 *data = gTasks[taskId].data;
2021-11-04 04:20:59 +01:00
s8 selection = Menu_ProcessGridInput();
2018-11-05 21:45:54 +01:00
switch (selection)
2018-11-05 21:45:54 +01:00
{
case MENU_NOTHING_CHOSEN:
return;
case MENU_B_PRESSED:
if (tIgnoreBPress)
return;
PlaySE(SE_SELECT);
2019-09-19 06:56:51 +02:00
gSpecialVar_Result = MULTI_B_PRESSED;
break;
default:
gSpecialVar_Result = selection;
break;
2018-11-05 21:45:54 +01:00
}
ClearToTransparentAndRemoveWindow(tWindowId);
DestroyTask(taskId);
ScriptContext_Enable();
2018-11-05 21:45:54 +01:00
}
#undef tWindowId
bool16 ScriptMenu_CreatePCMultichoice(void)
2018-11-05 21:45:54 +01:00
{
if (FuncIsActiveTask(Task_HandleMultichoiceInput) == TRUE)
{
return FALSE;
}
else
{
gSpecialVar_Result = 0xFF;
CreatePCMultichoice();
2018-11-05 21:45:54 +01:00
return TRUE;
}
}
static void CreatePCMultichoice(void)
2018-11-05 21:45:54 +01:00
{
u8 x = 8;
2018-11-05 21:45:54 +01:00
u32 pixelWidth = 0;
u8 width;
u8 numChoices;
u8 windowId;
int i;
for (i = 0; i < ARRAY_COUNT(sPCNameStrings); i++)
{
pixelWidth = DisplayTextAndGetWidth(sPCNameStrings[i], pixelWidth);
2018-11-05 21:45:54 +01:00
}
if (FlagGet(FLAG_SYS_GAME_CLEAR))
{
pixelWidth = DisplayTextAndGetWidth(gText_HallOfFame, pixelWidth);
2018-11-05 21:45:54 +01:00
}
width = ConvertPixelWidthToTileWidth(pixelWidth);
2018-11-05 21:45:54 +01:00
2019-09-20 00:31:09 +02:00
// Include Hall of Fame option if player is champion
if (FlagGet(FLAG_SYS_GAME_CLEAR))
2018-11-05 21:45:54 +01:00
{
numChoices = 4;
windowId = CreateWindowFromRect(0, 0, width, 8);
2022-07-25 20:59:14 +02:00
SetStandardWindowBorderStyle(windowId, FALSE);
AddTextPrinterParameterized(windowId, FONT_NORMAL, gText_HallOfFame, x, 33, TEXT_SKIP_DRAW, NULL);
AddTextPrinterParameterized(windowId, FONT_NORMAL, gText_LogOff, x, 49, TEXT_SKIP_DRAW, NULL);
2018-11-05 21:45:54 +01:00
}
else
{
numChoices = 3;
windowId = CreateWindowFromRect(0, 0, width, 6);
2022-07-25 20:59:14 +02:00
SetStandardWindowBorderStyle(windowId, FALSE);
AddTextPrinterParameterized(windowId, FONT_NORMAL, gText_LogOff, x, 33, TEXT_SKIP_DRAW, NULL);
2018-11-05 21:45:54 +01:00
}
2019-09-20 00:31:09 +02:00
// Change PC name if player has met Lanette
if (FlagGet(FLAG_SYS_PC_LANETTE))
AddTextPrinterParameterized(windowId, FONT_NORMAL, gText_LanettesPC, x, 1, TEXT_SKIP_DRAW, NULL);
2018-11-05 21:45:54 +01:00
else
AddTextPrinterParameterized(windowId, FONT_NORMAL, gText_SomeonesPC, x, 1, TEXT_SKIP_DRAW, NULL);
2018-11-05 21:45:54 +01:00
StringExpandPlaceholders(gStringVar4, gText_PlayersPC);
PrintPlayerNameOnWindow(windowId, gStringVar4, x, 17);
2021-11-03 21:06:58 +01:00
InitMenuInUpperLeftCornerNormal(windowId, numChoices, 0);
2021-11-03 20:29:18 +01:00
CopyWindowToVram(windowId, COPYWIN_FULL);
2019-09-20 00:31:09 +02:00
InitMultichoiceCheckWrap(FALSE, numChoices, windowId, MULTI_PC);
2018-11-05 21:45:54 +01:00
}
void ScriptMenu_DisplayPCStartupPrompt(void)
{
2021-11-04 04:20:59 +01:00
LoadMessageBoxAndFrameGfx(0, TRUE);
AddTextPrinterParameterized2(0, FONT_NORMAL, gText_WhichPCShouldBeAccessed, 0, NULL, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY);
2018-11-05 21:45:54 +01:00
}
bool8 ScriptMenu_CreateLilycoveSSTidalMultichoice(void)
2018-11-05 21:45:54 +01:00
{
if (FuncIsActiveTask(Task_HandleMultichoiceInput) == TRUE)
{
return FALSE;
}
else
{
gSpecialVar_Result = 0xFF;
CreateLilycoveSSTidalMultichoice();
2018-11-05 21:45:54 +01:00
return TRUE;
}
}
// gSpecialVar_0x8004 is 1 if the Sailor was shown multiple event tickets at the same time
// otherwise gSpecialVar_0x8004 is 0
static void CreateLilycoveSSTidalMultichoice(void)
2018-11-05 21:45:54 +01:00
{
u8 selectionCount = 0;
2018-11-05 21:45:54 +01:00
u8 count;
u32 pixelWidth;
u8 width;
u8 windowId;
u8 i;
u32 j;
2019-09-20 00:31:09 +02:00
for (i = 0; i < SSTIDAL_SELECTION_COUNT; i++)
2018-11-05 21:45:54 +01:00
{
sLilycoveSSTidalSelections[i] = 0xFF;
2018-11-05 21:45:54 +01:00
}
2021-10-30 22:47:37 +02:00
GetFontAttribute(FONT_NORMAL, FONTATTR_MAX_LETTER_WIDTH);
2018-11-05 21:45:54 +01:00
if (gSpecialVar_0x8004 == 0)
{
sLilycoveSSTidalSelections[selectionCount] = SSTIDAL_SELECTION_SLATEPORT;
selectionCount++;
2019-01-02 22:12:43 +01:00
if (FlagGet(FLAG_MET_SCOTT_ON_SS_TIDAL) == TRUE)
2018-11-05 21:45:54 +01:00
{
sLilycoveSSTidalSelections[selectionCount] = SSTIDAL_SELECTION_BATTLE_FRONTIER;
selectionCount++;
2018-11-05 21:45:54 +01:00
}
}
2020-03-03 07:36:20 +01:00
if (CheckBagHasItem(ITEM_EON_TICKET, 1) == TRUE && FlagGet(FLAG_ENABLE_SHIP_SOUTHERN_ISLAND) == TRUE)
2018-11-05 21:45:54 +01:00
{
if (gSpecialVar_0x8004 == 0)
{
sLilycoveSSTidalSelections[selectionCount] = SSTIDAL_SELECTION_SOUTHERN_ISLAND;
selectionCount++;
2018-11-05 21:45:54 +01:00
}
2020-03-03 07:36:20 +01:00
if (gSpecialVar_0x8004 == 1 && FlagGet(FLAG_SHOWN_EON_TICKET) == FALSE)
2018-11-05 21:45:54 +01:00
{
sLilycoveSSTidalSelections[selectionCount] = SSTIDAL_SELECTION_SOUTHERN_ISLAND;
selectionCount++;
2020-03-03 07:36:20 +01:00
FlagSet(FLAG_SHOWN_EON_TICKET);
2018-11-05 21:45:54 +01:00
}
}
2019-01-02 22:12:43 +01:00
if (CheckBagHasItem(ITEM_MYSTIC_TICKET, 1) == TRUE && FlagGet(FLAG_ENABLE_SHIP_NAVEL_ROCK) == TRUE)
2018-11-05 21:45:54 +01:00
{
if (gSpecialVar_0x8004 == 0)
{
sLilycoveSSTidalSelections[selectionCount] = SSTIDAL_SELECTION_NAVEL_ROCK;
selectionCount++;
2018-11-05 21:45:54 +01:00
}
2020-03-03 07:36:20 +01:00
if (gSpecialVar_0x8004 == 1 && FlagGet(FLAG_SHOWN_MYSTIC_TICKET) == FALSE)
2018-11-05 21:45:54 +01:00
{
sLilycoveSSTidalSelections[selectionCount] = SSTIDAL_SELECTION_NAVEL_ROCK;
selectionCount++;
2020-03-03 07:36:20 +01:00
FlagSet(FLAG_SHOWN_MYSTIC_TICKET);
2018-11-05 21:45:54 +01:00
}
}
2019-01-02 22:12:43 +01:00
if (CheckBagHasItem(ITEM_AURORA_TICKET, 1) == TRUE && FlagGet(FLAG_ENABLE_SHIP_BIRTH_ISLAND) == TRUE)
2018-11-05 21:45:54 +01:00
{
if (gSpecialVar_0x8004 == 0)
{
sLilycoveSSTidalSelections[selectionCount] = SSTIDAL_SELECTION_BIRTH_ISLAND;
selectionCount++;
2018-11-05 21:45:54 +01:00
}
2020-03-03 07:36:20 +01:00
if (gSpecialVar_0x8004 == 1 && FlagGet(FLAG_SHOWN_AURORA_TICKET) == FALSE)
2018-11-05 21:45:54 +01:00
{
sLilycoveSSTidalSelections[selectionCount] = SSTIDAL_SELECTION_BIRTH_ISLAND;
selectionCount++;
2020-03-03 07:36:20 +01:00
FlagSet(FLAG_SHOWN_AURORA_TICKET);
2018-11-05 21:45:54 +01:00
}
}
2019-01-02 22:12:43 +01:00
if (CheckBagHasItem(ITEM_OLD_SEA_MAP, 1) == TRUE && FlagGet(FLAG_ENABLE_SHIP_FARAWAY_ISLAND) == TRUE)
2018-11-05 21:45:54 +01:00
{
if (gSpecialVar_0x8004 == 0)
{
sLilycoveSSTidalSelections[selectionCount] = SSTIDAL_SELECTION_FARAWAY_ISLAND;
selectionCount++;
2018-11-05 21:45:54 +01:00
}
2020-03-03 07:36:20 +01:00
if (gSpecialVar_0x8004 == 1 && FlagGet(FLAG_SHOWN_OLD_SEA_MAP) == FALSE)
2018-11-05 21:45:54 +01:00
{
sLilycoveSSTidalSelections[selectionCount] = SSTIDAL_SELECTION_FARAWAY_ISLAND;
selectionCount++;
2020-03-03 07:36:20 +01:00
FlagSet(FLAG_SHOWN_OLD_SEA_MAP);
2018-11-05 21:45:54 +01:00
}
}
sLilycoveSSTidalSelections[selectionCount] = SSTIDAL_SELECTION_EXIT;
selectionCount++;
2018-11-05 21:45:54 +01:00
2019-01-02 22:12:43 +01:00
if (gSpecialVar_0x8004 == 0 && FlagGet(FLAG_MET_SCOTT_ON_SS_TIDAL) == TRUE)
2018-11-05 21:45:54 +01:00
{
count = selectionCount;
2018-11-05 21:45:54 +01:00
}
count = selectionCount;
if (count == SSTIDAL_SELECTION_COUNT)
2018-11-05 21:45:54 +01:00
{
2019-09-13 20:24:07 +02:00
gSpecialVar_0x8004 = SCROLL_MULTI_SS_TIDAL_DESTINATION;
ShowScrollableMultichoice();
2018-11-05 21:45:54 +01:00
}
else
{
pixelWidth = 0;
2019-09-20 00:31:09 +02:00
for (j = 0; j < SSTIDAL_SELECTION_COUNT; j++)
2018-11-05 21:45:54 +01:00
{
u8 selection = sLilycoveSSTidalSelections[j];
if (selection != 0xFF)
2018-11-05 21:45:54 +01:00
{
2019-09-20 01:23:24 +02:00
pixelWidth = DisplayTextAndGetWidth(sLilycoveSSTidalDestinations[selection], pixelWidth);
2018-11-05 21:45:54 +01:00
}
}
width = ConvertPixelWidthToTileWidth(pixelWidth);
windowId = CreateWindowFromRect(MAX_MULTICHOICE_WIDTH - width, (6 - count) * 2, width, count * 2);
2022-07-25 20:59:14 +02:00
SetStandardWindowBorderStyle(windowId, FALSE);
2018-11-07 21:09:54 +01:00
2019-09-20 00:31:09 +02:00
for (selectionCount = 0, i = 0; i < SSTIDAL_SELECTION_COUNT; i++)
2018-11-05 21:45:54 +01:00
{
if (sLilycoveSSTidalSelections[i] != 0xFF)
2018-11-05 21:45:54 +01:00
{
AddTextPrinterParameterized(windowId, FONT_NORMAL, sLilycoveSSTidalDestinations[sLilycoveSSTidalSelections[i]], 8, selectionCount * 16 + 1, TEXT_SKIP_DRAW, NULL);
selectionCount++;
2018-11-05 21:45:54 +01:00
}
}
2021-11-03 21:06:58 +01:00
InitMenuInUpperLeftCornerNormal(windowId, count, count - 1);
2021-11-03 20:29:18 +01:00
CopyWindowToVram(windowId, COPYWIN_FULL);
2019-09-20 00:31:09 +02:00
InitMultichoiceCheckWrap(FALSE, count, windowId, MULTI_SSTIDAL_LILYCOVE);
2018-11-05 21:45:54 +01:00
}
}
2018-11-07 03:13:40 +01:00
void GetLilycoveSSTidalSelection(void)
2018-11-07 03:13:40 +01:00
{
2019-09-19 06:56:51 +02:00
if (gSpecialVar_Result != MULTI_B_PRESSED)
2018-11-07 03:13:40 +01:00
{
gSpecialVar_Result = sLilycoveSSTidalSelections[gSpecialVar_Result];
2018-11-07 03:13:40 +01:00
}
}
#define tState data[0]
#define tMonSpecies data[1]
#define tMonSpriteId data[2]
#define tWindowX data[3]
#define tWindowY data[4]
#define tWindowId data[5]
static void Task_PokemonPicWindow(u8 taskId)
{
struct Task *task = &gTasks[taskId];
switch (task->tState)
{
case 0:
task->tState++;
break;
case 1:
2021-11-16 16:53:18 +01:00
// Wait until state is advanced by ScriptMenu_HidePokemonPic
2018-11-07 03:13:40 +01:00
break;
case 2:
FreeResourcesAndDestroySprite(&gSprites[task->tMonSpriteId], task->tMonSpriteId);
task->tState++;
break;
case 3:
ClearToTransparentAndRemoveWindow(task->tWindowId);
2018-11-07 03:13:40 +01:00
DestroyTask(taskId);
break;
}
}
bool8 ScriptMenu_ShowPokemonPic(u16 species, u8 x, u8 y)
{
u8 taskId;
u8 spriteId;
2021-02-20 05:22:26 +01:00
if (FindTaskIdByFunc(Task_PokemonPicWindow) != TASK_NONE)
2018-11-07 03:13:40 +01:00
{
return FALSE;
}
else
{
spriteId = CreateMonSprite_PicBox(species, x * 8 + 40, y * 8 + 40, 0);
taskId = CreateTask(Task_PokemonPicWindow, 0x50);
gTasks[taskId].tWindowId = CreateWindowFromRect(x, y, 8, 8);
gTasks[taskId].tState = 0;
gTasks[taskId].tMonSpecies = species;
gTasks[taskId].tMonSpriteId = spriteId;
gSprites[spriteId].callback = SpriteCallbackDummy;
gSprites[spriteId].oam.priority = 0;
2022-07-25 20:59:14 +02:00
SetStandardWindowBorderStyle(gTasks[taskId].tWindowId, TRUE);
2020-05-14 10:37:09 +02:00
ScheduleBgCopyTilemapToVram(0);
2018-11-07 03:13:40 +01:00
return TRUE;
}
2018-11-07 21:09:54 +01:00
}
2018-11-07 03:13:40 +01:00
2021-11-16 16:53:18 +01:00
bool8 (*ScriptMenu_HidePokemonPic(void))(void)
2018-11-07 03:13:40 +01:00
{
u8 taskId = FindTaskIdByFunc(Task_PokemonPicWindow);
2021-02-20 05:22:26 +01:00
if (taskId == TASK_NONE)
2018-11-07 03:13:40 +01:00
return NULL;
gTasks[taskId].tState++;
return IsPicboxClosed;
}
static bool8 IsPicboxClosed(void)
{
2021-02-20 05:22:26 +01:00
if (FindTaskIdByFunc(Task_PokemonPicWindow) == TASK_NONE)
2018-11-07 03:13:40 +01:00
return TRUE;
else
return FALSE;
}
#undef tState
#undef tMonSpecies
#undef tMonSpriteId
#undef tWindowX
#undef tWindowY
#undef tWindowId
u8 CreateWindowFromRect(u8 x, u8 y, u8 width, u8 height)
{
struct WindowTemplate template = CreateWindowTemplate(0, x + 1, y + 1, width, height, 15, 100);
u8 windowId = AddWindow(&template);
PutWindowTilemap(windowId);
return windowId;
}
void ClearToTransparentAndRemoveWindow(u8 windowId)
2018-11-07 03:13:40 +01:00
{
ClearStdWindowAndFrameToTransparent(windowId, TRUE);
2018-11-07 03:13:40 +01:00
RemoveWindow(windowId);
}
static void DrawLinkServicesMultichoiceMenu(u8 multichoiceId)
2018-11-07 03:13:40 +01:00
{
switch (multichoiceId)
{
2019-09-20 01:23:24 +02:00
case MULTI_WIRELESS_NO_BERRY:
FillWindowPixelBuffer(0, PIXEL_FILL(1));
AddTextPrinterParameterized2(0, FONT_NORMAL, sWirelessOptionsNoBerryCrush[Menu_GetCursorPos()], 0, NULL, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY);
break;
2019-09-20 01:23:24 +02:00
case MULTI_CABLE_CLUB_WITH_RECORD_MIX:
FillWindowPixelBuffer(0, PIXEL_FILL(1));
AddTextPrinterParameterized2(0, FONT_NORMAL, sCableClubOptions_WithRecordMix[Menu_GetCursorPos()], 0, NULL, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY);
break;
2019-09-20 01:23:24 +02:00
case MULTI_WIRELESS_NO_RECORD:
FillWindowPixelBuffer(0, PIXEL_FILL(1));
AddTextPrinterParameterized2(0, FONT_NORMAL, sWirelessOptions_NoRecordMix[Menu_GetCursorPos()], 0, NULL, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY);
break;
2019-09-20 01:23:24 +02:00
case MULTI_WIRELESS_ALL_SERVICES:
FillWindowPixelBuffer(0, PIXEL_FILL(1));
AddTextPrinterParameterized2(0, FONT_NORMAL, sWirelessOptions_AllServices[Menu_GetCursorPos()], 0, NULL, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY);
break;
2019-09-20 01:23:24 +02:00
case MULTI_WIRELESS_NO_RECORD_BERRY:
FillWindowPixelBuffer(0, PIXEL_FILL(1));
AddTextPrinterParameterized2(0, FONT_NORMAL, sWirelessOptions_NoRecordMixBerryCrush[Menu_GetCursorPos()], 0, NULL, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY);
break;
2019-09-20 01:23:24 +02:00
case MULTI_CABLE_CLUB_NO_RECORD_MIX:
FillWindowPixelBuffer(0, PIXEL_FILL(1));
AddTextPrinterParameterized2(0, FONT_NORMAL, sCableClubOptions_NoRecordMix[Menu_GetCursorPos()], 0, NULL, TEXT_COLOR_DARK_GRAY, TEXT_COLOR_WHITE, TEXT_COLOR_LIGHT_GRAY);
break;
2018-11-07 03:13:40 +01:00
}
}
bool16 ScriptMenu_CreateStartMenuForPokenavTutorial(void)
2018-11-07 03:13:40 +01:00
{
if (FuncIsActiveTask(Task_HandleMultichoiceInput) == TRUE)
{
return FALSE;
}
else
{
gSpecialVar_Result = 0xFF;
CreateStartMenuForPokenavTutorial();
return TRUE;
}
2018-11-07 03:13:40 +01:00
}
static void CreateStartMenuForPokenavTutorial(void)
2018-11-07 03:13:40 +01:00
{
u8 windowId = CreateWindowFromRect(21, 0, 7, 18);
2022-07-25 20:59:14 +02:00
SetStandardWindowBorderStyle(windowId, FALSE);
AddTextPrinterParameterized(windowId, FONT_NORMAL, gText_MenuOptionPokedex, 8, 9, TEXT_SKIP_DRAW, NULL);
AddTextPrinterParameterized(windowId, FONT_NORMAL, gText_MenuOptionPokemon, 8, 25, TEXT_SKIP_DRAW, NULL);
AddTextPrinterParameterized(windowId, FONT_NORMAL, gText_MenuOptionBag, 8, 41, TEXT_SKIP_DRAW, NULL);
AddTextPrinterParameterized(windowId, FONT_NORMAL, gText_MenuOptionPokenav, 8, 57, TEXT_SKIP_DRAW, NULL);
AddTextPrinterParameterized(windowId, FONT_NORMAL, gSaveBlock2Ptr->playerName, 8, 73, TEXT_SKIP_DRAW, NULL);
AddTextPrinterParameterized(windowId, FONT_NORMAL, gText_MenuOptionSave, 8, 89, TEXT_SKIP_DRAW, NULL);
AddTextPrinterParameterized(windowId, FONT_NORMAL, gText_MenuOptionOption, 8, 105, TEXT_SKIP_DRAW, NULL);
AddTextPrinterParameterized(windowId, FONT_NORMAL, gText_MenuOptionExit, 8, 121, TEXT_SKIP_DRAW, NULL);
2021-11-03 21:06:58 +01:00
InitMenuNormal(windowId, FONT_NORMAL, 0, 9, 16, ARRAY_COUNT(MultichoiceList_ForcedStartMenu), 0);
2019-09-20 00:31:09 +02:00
InitMultichoiceNoWrap(FALSE, ARRAY_COUNT(MultichoiceList_ForcedStartMenu), windowId, MULTI_FORCED_START_MENU);
2021-11-03 20:29:18 +01:00
CopyWindowToVram(windowId, COPYWIN_FULL);
2018-11-07 03:13:40 +01:00
}
#define tWindowId data[6]
2019-09-20 00:31:09 +02:00
static void InitMultichoiceNoWrap(bool8 ignoreBPress, u8 unusedCount, u8 windowId, u8 multichoiceId)
2018-11-07 03:13:40 +01:00
{
u8 taskId;
2019-09-20 00:31:09 +02:00
sProcessInputDelay = 2;
2018-11-07 03:13:40 +01:00
taskId = CreateTask(Task_HandleMultichoiceInput, 80);
gTasks[taskId].tIgnoreBPress = ignoreBPress;
gTasks[taskId].tDoWrap = 0;
gTasks[taskId].tWindowId = windowId;
gTasks[taskId].tMultichoiceId = multichoiceId;
}
#undef tLeft
#undef tTop
#undef tRight
#undef tBottom
#undef tIgnoreBPress
#undef tDoWrap
#undef tWindowId
#undef tMultichoiceId
static int DisplayTextAndGetWidthInternal(const u8 *str)
2018-11-07 03:13:40 +01:00
{
u8 temp[64];
StringExpandPlaceholders(temp, str);
2021-10-30 22:47:37 +02:00
return GetStringWidth(FONT_NORMAL, temp, 0);
2018-11-07 03:13:40 +01:00
}
2019-09-20 00:31:09 +02:00
int DisplayTextAndGetWidth(const u8 *str, int prevWidth)
2018-11-07 03:13:40 +01:00
{
2019-09-20 00:31:09 +02:00
int width = DisplayTextAndGetWidthInternal(str);
if (width < prevWidth)
2018-11-07 03:13:40 +01:00
{
2019-09-20 00:31:09 +02:00
width = prevWidth;
2018-11-07 03:13:40 +01:00
}
2019-09-20 00:31:09 +02:00
return width;
2018-11-07 03:13:40 +01:00
}
int ConvertPixelWidthToTileWidth(int width)
2018-11-07 03:13:40 +01:00
{
return (((width + 9) / 8) + 1) > MAX_MULTICHOICE_WIDTH ? MAX_MULTICHOICE_WIDTH : (((width + 9) / 8) + 1);
2018-11-07 03:13:40 +01:00
}
int ScriptMenu_AdjustLeftCoordFromWidth(int left, int width)
2018-11-07 03:13:40 +01:00
{
int adjustedLeft = left;
2018-11-07 03:13:40 +01:00
if (left + width > MAX_MULTICHOICE_WIDTH)
2018-11-07 03:13:40 +01:00
{
if (MAX_MULTICHOICE_WIDTH - width < 0)
2018-11-07 03:13:40 +01:00
{
adjustedLeft = 0;
2018-11-07 03:13:40 +01:00
}
else
{
adjustedLeft = MAX_MULTICHOICE_WIDTH - width;
2018-11-07 03:13:40 +01:00
}
}
return adjustedLeft;
2018-11-07 03:13:40 +01:00
}