pokeemerald/src/field_message_box.c

164 lines
3.9 KiB
C
Raw Normal View History

2018-01-28 06:22:06 +01:00
#include "global.h"
#include "menu.h"
2018-01-28 06:22:06 +01:00
#include "string_util.h"
#include "task.h"
#include "text.h"
2019-03-02 04:32:50 +01:00
#include "match_call.h"
2020-06-04 00:25:16 +02:00
#include "field_message_box.h"
2018-01-28 06:22:06 +01:00
2018-12-27 23:30:47 +01:00
static EWRAM_DATA u8 sFieldMessageBoxMode = 0;
2018-01-28 06:22:06 +01:00
2020-06-04 00:25:16 +02:00
static void ExpandStringAndStartDrawFieldMessage(const u8*, bool32);
static void StartDrawFieldMessage(void);
2018-01-28 06:22:06 +01:00
2018-12-27 23:30:47 +01:00
void InitFieldMessageBox(void)
2018-01-28 06:22:06 +01:00
{
2020-06-04 00:25:16 +02:00
sFieldMessageBoxMode = FIELD_MESSAGE_BOX_HIDDEN;
gTextFlags.canABSpeedUpPrint = FALSE;
gTextFlags.useAlternateDownArrow = FALSE;
gTextFlags.autoScroll = FALSE;
gTextFlags.forceMidTextSpeed = FALSE;
2018-01-28 06:22:06 +01:00
}
2020-06-04 00:25:16 +02:00
#define tState data[0]
static void Task_DrawFieldMessage(u8 taskId)
2018-01-28 06:22:06 +01:00
{
struct Task *task = &gTasks[taskId];
2018-08-25 20:14:10 +02:00
2020-06-04 00:25:16 +02:00
switch (task->tState)
2018-01-28 06:22:06 +01:00
{
case 0:
2020-02-07 18:48:47 +01:00
LoadMessageBoxAndBorderGfx();
2020-06-04 00:25:16 +02:00
task->tState++;
2018-01-28 06:22:06 +01:00
break;
case 1:
DrawDialogueFrame(0, 1);
2020-06-04 00:25:16 +02:00
task->tState++;
2018-01-28 06:22:06 +01:00
break;
case 2:
2020-06-04 00:25:16 +02:00
if (RunTextPrintersAndIsPrinter0Active() != TRUE)
2018-01-28 06:22:06 +01:00
{
2020-06-04 00:25:16 +02:00
sFieldMessageBoxMode = FIELD_MESSAGE_BOX_HIDDEN;
2018-01-28 06:22:06 +01:00
DestroyTask(taskId);
}
}
}
2020-06-04 00:25:16 +02:00
#undef tState
static void CreateTask_DrawFieldMessage(void)
2018-01-28 06:22:06 +01:00
{
2020-06-04 00:25:16 +02:00
CreateTask(Task_DrawFieldMessage, 0x50);
2018-01-28 06:22:06 +01:00
}
2020-06-04 00:25:16 +02:00
static void DestroyTask_DrawFieldMessage(void)
2018-01-28 06:22:06 +01:00
{
2020-06-04 00:25:16 +02:00
u8 taskId = FindTaskIdByFunc(Task_DrawFieldMessage);
2021-02-20 05:22:26 +01:00
if (taskId != TASK_NONE)
2018-01-28 06:22:06 +01:00
DestroyTask(taskId);
}
2020-06-04 00:25:16 +02:00
bool8 ShowFieldMessage(const u8 *str)
2018-01-28 06:22:06 +01:00
{
2020-06-04 00:25:16 +02:00
if (sFieldMessageBoxMode != FIELD_MESSAGE_BOX_HIDDEN)
2018-01-28 06:22:06 +01:00
return FALSE;
2020-06-04 00:25:16 +02:00
ExpandStringAndStartDrawFieldMessage(str, TRUE);
sFieldMessageBoxMode = FIELD_MESSAGE_BOX_NORMAL;
2018-08-25 20:14:10 +02:00
return TRUE;
2018-01-28 06:22:06 +01:00
}
2020-06-04 00:25:16 +02:00
static void Task_HidePokenavMessageWhenDone(u8 taskId)
2018-01-28 06:22:06 +01:00
{
2019-01-03 02:07:47 +01:00
if (!IsMatchCallTaskActive())
2018-01-28 06:22:06 +01:00
{
2020-06-04 00:25:16 +02:00
sFieldMessageBoxMode = FIELD_MESSAGE_BOX_HIDDEN;
2018-01-28 06:22:06 +01:00
DestroyTask(taskId);
}
}
2020-06-04 00:25:16 +02:00
bool8 ShowPokenavFieldMessage(const u8 *str)
2018-01-28 06:22:06 +01:00
{
2020-06-04 00:25:16 +02:00
if (sFieldMessageBoxMode != FIELD_MESSAGE_BOX_HIDDEN)
2018-01-28 06:22:06 +01:00
return FALSE;
StringExpandPlaceholders(gStringVar4, str);
2020-06-04 00:25:16 +02:00
CreateTask(Task_HidePokenavMessageWhenDone, 0);
2019-01-03 02:07:47 +01:00
StartMatchCallFromScript(str);
2018-12-27 23:30:47 +01:00
sFieldMessageBoxMode = 2;
2018-01-28 06:22:06 +01:00
return TRUE;
}
2020-06-04 00:25:16 +02:00
bool8 ShowFieldAutoScrollMessage(const u8 *str)
2018-01-28 06:22:06 +01:00
{
2020-06-04 00:25:16 +02:00
if (sFieldMessageBoxMode != FIELD_MESSAGE_BOX_HIDDEN)
2018-01-28 06:22:06 +01:00
return FALSE;
2020-06-04 00:25:16 +02:00
sFieldMessageBoxMode = FIELD_MESSAGE_BOX_AUTO_SCROLL;
ExpandStringAndStartDrawFieldMessage(str, FALSE);
2018-01-28 06:22:06 +01:00
return TRUE;
}
2020-06-04 00:25:16 +02:00
// Unused
static bool8 ForceShowFieldAutoScrollMessage(const u8 *str)
2018-01-28 06:22:06 +01:00
{
2020-06-04 00:25:16 +02:00
sFieldMessageBoxMode = FIELD_MESSAGE_BOX_AUTO_SCROLL;
ExpandStringAndStartDrawFieldMessage(str, TRUE);
2018-01-28 06:22:06 +01:00
return TRUE;
}
2020-06-04 00:25:16 +02:00
// Same as ShowFieldMessage, but instead of accepting a
// string arg it just prints whats already in gStringVar4
bool8 ShowFieldMessageFromBuffer(void)
2018-01-28 06:22:06 +01:00
{
2020-06-04 00:25:16 +02:00
if (sFieldMessageBoxMode != FIELD_MESSAGE_BOX_HIDDEN)
2018-01-28 06:22:06 +01:00
return FALSE;
2020-06-04 00:25:16 +02:00
sFieldMessageBoxMode = FIELD_MESSAGE_BOX_NORMAL;
StartDrawFieldMessage();
2018-01-28 06:22:06 +01:00
return TRUE;
}
2020-06-04 00:25:16 +02:00
static void ExpandStringAndStartDrawFieldMessage(const u8* str, bool32 allowSkippingDelayWithButtonPress)
2018-01-28 06:22:06 +01:00
{
StringExpandPlaceholders(gStringVar4, str);
2018-12-27 23:30:47 +01:00
AddTextPrinterForMessage(allowSkippingDelayWithButtonPress);
2020-06-04 00:25:16 +02:00
CreateTask_DrawFieldMessage();
2018-01-28 06:22:06 +01:00
}
2020-06-04 00:25:16 +02:00
static void StartDrawFieldMessage(void)
2018-01-28 06:22:06 +01:00
{
2018-12-27 23:30:47 +01:00
AddTextPrinterForMessage(TRUE);
2020-06-04 00:25:16 +02:00
CreateTask_DrawFieldMessage();
2018-01-28 06:22:06 +01:00
}
void HideFieldMessageBox(void)
{
2020-06-04 00:25:16 +02:00
DestroyTask_DrawFieldMessage();
ClearDialogWindowAndFrame(0, 1);
2020-06-04 00:25:16 +02:00
sFieldMessageBoxMode = FIELD_MESSAGE_BOX_HIDDEN;
2018-01-28 06:22:06 +01:00
}
2018-10-13 19:41:10 +02:00
u8 GetFieldMessageBoxMode(void)
2018-01-28 06:22:06 +01:00
{
2018-12-27 23:30:47 +01:00
return sFieldMessageBoxMode;
2018-01-28 06:22:06 +01:00
}
bool8 IsFieldMessageBoxHidden(void)
{
2020-06-04 00:25:16 +02:00
if (sFieldMessageBoxMode == FIELD_MESSAGE_BOX_HIDDEN)
2018-01-28 06:22:06 +01:00
return TRUE;
return FALSE;
}
2020-06-04 00:25:16 +02:00
// Unused
static void ReplaceFieldMessageWithFrame(void)
2018-01-28 06:22:06 +01:00
{
2020-06-04 00:25:16 +02:00
DestroyTask_DrawFieldMessage();
DrawStdWindowFrame(0, 1);
2020-06-04 00:25:16 +02:00
sFieldMessageBoxMode = FIELD_MESSAGE_BOX_HIDDEN;
2018-01-28 06:22:06 +01:00
}
2020-06-04 00:25:16 +02:00
void StopFieldMessage(void)
2018-01-28 06:22:06 +01:00
{
2020-06-04 00:25:16 +02:00
DestroyTask_DrawFieldMessage();
sFieldMessageBoxMode = FIELD_MESSAGE_BOX_HIDDEN;
2018-01-28 06:22:06 +01:00
}