pokeemerald/src/field_message_box.c

158 lines
3.2 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.h"
#include "string_util.h"
#include "task.h"
#include "text.h"
2018-08-25 20:14:10 +02:00
2019-01-03 02:07:47 +01:00
extern bool32 IsMatchCallTaskActive(void);
extern void StartMatchCallFromScript(u8*);
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
2018-12-27 23:30:47 +01:00
static void textbox_fdecode_auto_and_task_add(u8*, bool32);
static void textbox_auto_and_task_add(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
{
2018-12-27 23:30:47 +01:00
sFieldMessageBoxMode = 0;
2018-11-06 17:44:48 +01:00
gTextFlags.canABSpeedUpPrint = 0;
2018-11-06 18:30:21 +01:00
gTextFlags.useAlternateDownArrow = 0;
gTextFlags.autoScroll = 0;
gTextFlags.forceMidTextSpeed = 0;
2018-01-28 06:22:06 +01:00
}
2018-12-27 23:30:47 +01:00
static void sub_8098154(u8 taskId)
2018-01-28 06:22:06 +01:00
{
struct Task *task = &gTasks[taskId];
2018-08-25 20:14:10 +02:00
2018-01-28 06:22:06 +01:00
switch (task->data[0])
{
case 0:
sub_81973A4();
task->data[0]++;
break;
case 1:
NewMenuHelpers_DrawDialogueFrame(0, 1);
2018-01-28 06:22:06 +01:00
task->data[0]++;
break;
case 2:
2018-09-14 19:15:46 +02:00
if (RunTextPrintersAndIsPrinter0Active() != 1)
2018-01-28 06:22:06 +01:00
{
2018-12-27 23:30:47 +01:00
sFieldMessageBoxMode = 0;
2018-01-28 06:22:06 +01:00
DestroyTask(taskId);
}
}
}
2018-12-27 23:30:47 +01:00
static void task_add_textbox(void)
2018-01-28 06:22:06 +01:00
{
CreateTask(sub_8098154, 0x50);
}
2018-12-27 23:30:47 +01:00
static void task_del_textbox(void)
2018-01-28 06:22:06 +01:00
{
u8 taskId = FindTaskIdByFunc(sub_8098154);
if (taskId != 0xFF)
DestroyTask(taskId);
}
bool8 ShowFieldMessage(u8 *str)
{
2018-12-27 23:30:47 +01:00
if (sFieldMessageBoxMode != 0)
2018-01-28 06:22:06 +01:00
return FALSE;
textbox_fdecode_auto_and_task_add(str, 1);
2018-12-27 23:30:47 +01:00
sFieldMessageBoxMode = 2;
2018-08-25 20:14:10 +02:00
return TRUE;
2018-01-28 06:22:06 +01:00
}
void sub_8098214(u8 taskId)
{
2019-01-03 02:07:47 +01:00
if (!IsMatchCallTaskActive())
2018-01-28 06:22:06 +01:00
{
2018-12-27 23:30:47 +01:00
sFieldMessageBoxMode = 0;
2018-01-28 06:22:06 +01:00
DestroyTask(taskId);
}
}
bool8 sub_8098238(u8 *str)
{
2018-12-27 23:30:47 +01:00
if (sFieldMessageBoxMode != 0)
2018-01-28 06:22:06 +01:00
return FALSE;
StringExpandPlaceholders(gStringVar4, str);
CreateTask(sub_8098214, 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;
}
bool8 ShowFieldAutoScrollMessage(u8 *str)
{
2018-12-27 23:30:47 +01:00
if (sFieldMessageBoxMode != 0)
2018-01-28 06:22:06 +01:00
return FALSE;
2018-12-27 23:30:47 +01:00
sFieldMessageBoxMode = 3;
2018-01-28 06:22:06 +01:00
textbox_fdecode_auto_and_task_add(str, 0);
return TRUE;
}
bool8 sub_80982A0(u8 *str)
{
2018-12-27 23:30:47 +01:00
sFieldMessageBoxMode = 3;
2018-01-28 06:22:06 +01:00
textbox_fdecode_auto_and_task_add(str, 1);
return TRUE;
}
bool8 sub_80982B8(void)
{
2018-12-27 23:30:47 +01:00
if (sFieldMessageBoxMode != 0)
2018-01-28 06:22:06 +01:00
return FALSE;
2018-12-27 23:30:47 +01:00
sFieldMessageBoxMode = 2;
2018-01-28 06:22:06 +01:00
textbox_auto_and_task_add();
return TRUE;
}
2018-12-27 23:30:47 +01:00
static void textbox_fdecode_auto_and_task_add(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);
2018-01-28 06:22:06 +01:00
task_add_textbox();
}
2018-12-27 23:30:47 +01:00
static void textbox_auto_and_task_add(void)
2018-01-28 06:22:06 +01:00
{
2018-12-27 23:30:47 +01:00
AddTextPrinterForMessage(TRUE);
2018-01-28 06:22:06 +01:00
task_add_textbox();
}
void HideFieldMessageBox(void)
{
task_del_textbox();
ClearWindowAndWideBorder(0, 1);
2018-12-27 23:30:47 +01:00
sFieldMessageBoxMode = 0;
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)
{
2018-12-27 23:30:47 +01:00
if (sFieldMessageBoxMode == 0)
2018-01-28 06:22:06 +01:00
return TRUE;
return FALSE;
}
void sub_8098358(void)
{
task_del_textbox();
NewMenuHelpers_DrawStdWindowFrame(0, 1);
2018-12-27 23:30:47 +01:00
sFieldMessageBoxMode = 0;
2018-01-28 06:22:06 +01:00
}
void sub_8098374(void)
{
task_del_textbox();
2018-12-27 23:30:47 +01:00
sFieldMessageBoxMode = 0;
2018-01-28 06:22:06 +01:00
}