Document field_message_box.c

This commit is contained in:
GriffinR 2020-06-03 18:25:16 -04:00 committed by huderlem
parent 83336585e2
commit aaf5d91c18
8 changed files with 69 additions and 60 deletions

View File

@ -10,13 +10,13 @@ enum
};
bool8 ShowFieldMessage(const u8 *message);
bool8 sub_8098238(const u8 *message);
bool8 sub_80982B8(void);
bool8 ShowPokenavFieldMessage(const u8 *message);
bool8 ShowFieldMessageFromBuffer(void);
bool8 ShowFieldAutoScrollMessage(const u8 *message);
void HideFieldMessageBox(void);
bool8 IsFieldMessageBoxHidden(void);
u8 GetFieldMessageBoxMode(void);
void sub_8098374(void);
void StopFieldMessage(void);
void InitFieldMessageBox(void);
#endif // GUARD_FIELD_MESSAGE_BOX_H

View File

@ -14,7 +14,7 @@ s32 GetRematchIdxByTrainerIdx(s32 trainerIdx);
void InitMatchCallCounters(void);
bool32 TryStartMatchCall(void);
bool32 IsMatchCallTaskActive(void);
void StartMatchCallFromScript(u8 *message);
void StartMatchCallFromScript(const u8 *message);
void BufferPokedexRatingForMatchCall(u8 *destStr);
bool32 SelectMatchCallMessage(int, u8 *);
void sub_8197184(u32 windowId, u32 destOffset, u32 paletteId);

View File

@ -1360,7 +1360,7 @@ void ShowTrainerIntroSpeech(void)
else
CopyPyramidTrainerSpeechBefore(LocalIdToPyramidTrainerId(gObjectEvents[gApproachingTrainers[gApproachingTrainerId].objectEventId].localId));
sub_80982B8();
ShowFieldMessageFromBuffer();
}
else if (InTrainerHillChallenge())
{
@ -1369,7 +1369,7 @@ void ShowTrainerIntroSpeech(void)
else
CopyTrainerHillTrainerText(TRAINER_HILL_TEXT_INTRO, LocalIdToHillTrainerId(gObjectEvents[gApproachingTrainers[gApproachingTrainerId].objectEventId].localId));
sub_80982B8();
ShowFieldMessageFromBuffer();
}
else
{

View File

@ -524,7 +524,7 @@ static void sub_80B2CEC(u8 taskId)
{
gSpecialVar_Result = 5;
sub_80B241C(gTasks[taskId].data[5]);
sub_8098374();
StopFieldMessage();
RemoveWindow(gTasks[taskId].data[5]);
EnableBothScriptContexts();
DestroyTask(taskId);

View File

@ -5,128 +5,136 @@
#include "task.h"
#include "text.h"
#include "match_call.h"
#include "field_message_box.h"
static EWRAM_DATA u8 sFieldMessageBoxMode = 0;
static void textbox_fdecode_auto_and_task_add(u8*, bool32);
static void textbox_auto_and_task_add(void);
static void ExpandStringAndStartDrawFieldMessage(const u8*, bool32);
static void StartDrawFieldMessage(void);
void InitFieldMessageBox(void)
{
sFieldMessageBoxMode = 0;
gTextFlags.canABSpeedUpPrint = 0;
gTextFlags.useAlternateDownArrow = 0;
gTextFlags.autoScroll = 0;
gTextFlags.forceMidTextSpeed = 0;
sFieldMessageBoxMode = FIELD_MESSAGE_BOX_HIDDEN;
gTextFlags.canABSpeedUpPrint = FALSE;
gTextFlags.useAlternateDownArrow = FALSE;
gTextFlags.autoScroll = FALSE;
gTextFlags.forceMidTextSpeed = FALSE;
}
static void sub_8098154(u8 taskId)
#define tState data[0]
static void Task_DrawFieldMessage(u8 taskId)
{
struct Task *task = &gTasks[taskId];
switch (task->data[0])
switch (task->tState)
{
case 0:
LoadMessageBoxAndBorderGfx();
task->data[0]++;
task->tState++;
break;
case 1:
DrawDialogueFrame(0, 1);
task->data[0]++;
task->tState++;
break;
case 2:
if (RunTextPrintersAndIsPrinter0Active() != 1)
if (RunTextPrintersAndIsPrinter0Active() != TRUE)
{
sFieldMessageBoxMode = 0;
sFieldMessageBoxMode = FIELD_MESSAGE_BOX_HIDDEN;
DestroyTask(taskId);
}
}
}
static void task_add_textbox(void)
#undef tState
static void CreateTask_DrawFieldMessage(void)
{
CreateTask(sub_8098154, 0x50);
CreateTask(Task_DrawFieldMessage, 0x50);
}
static void task_del_textbox(void)
static void DestroyTask_DrawFieldMessage(void)
{
u8 taskId = FindTaskIdByFunc(sub_8098154);
u8 taskId = FindTaskIdByFunc(Task_DrawFieldMessage);
if (taskId != 0xFF)
DestroyTask(taskId);
}
bool8 ShowFieldMessage(u8 *str)
bool8 ShowFieldMessage(const u8 *str)
{
if (sFieldMessageBoxMode != 0)
if (sFieldMessageBoxMode != FIELD_MESSAGE_BOX_HIDDEN)
return FALSE;
textbox_fdecode_auto_and_task_add(str, 1);
sFieldMessageBoxMode = 2;
ExpandStringAndStartDrawFieldMessage(str, TRUE);
sFieldMessageBoxMode = FIELD_MESSAGE_BOX_NORMAL;
return TRUE;
}
void sub_8098214(u8 taskId)
static void Task_HidePokenavMessageWhenDone(u8 taskId)
{
if (!IsMatchCallTaskActive())
{
sFieldMessageBoxMode = 0;
sFieldMessageBoxMode = FIELD_MESSAGE_BOX_HIDDEN;
DestroyTask(taskId);
}
}
bool8 sub_8098238(u8 *str)
bool8 ShowPokenavFieldMessage(const u8 *str)
{
if (sFieldMessageBoxMode != 0)
if (sFieldMessageBoxMode != FIELD_MESSAGE_BOX_HIDDEN)
return FALSE;
StringExpandPlaceholders(gStringVar4, str);
CreateTask(sub_8098214, 0);
CreateTask(Task_HidePokenavMessageWhenDone, 0);
StartMatchCallFromScript(str);
sFieldMessageBoxMode = 2;
return TRUE;
}
bool8 ShowFieldAutoScrollMessage(u8 *str)
bool8 ShowFieldAutoScrollMessage(const u8 *str)
{
if (sFieldMessageBoxMode != 0)
if (sFieldMessageBoxMode != FIELD_MESSAGE_BOX_HIDDEN)
return FALSE;
sFieldMessageBoxMode = 3;
textbox_fdecode_auto_and_task_add(str, 0);
sFieldMessageBoxMode = FIELD_MESSAGE_BOX_AUTO_SCROLL;
ExpandStringAndStartDrawFieldMessage(str, FALSE);
return TRUE;
}
bool8 sub_80982A0(u8 *str)
// Unused
static bool8 ForceShowFieldAutoScrollMessage(const u8 *str)
{
sFieldMessageBoxMode = 3;
textbox_fdecode_auto_and_task_add(str, 1);
sFieldMessageBoxMode = FIELD_MESSAGE_BOX_AUTO_SCROLL;
ExpandStringAndStartDrawFieldMessage(str, TRUE);
return TRUE;
}
bool8 sub_80982B8(void)
// Same as ShowFieldMessage, but instead of accepting a
// string arg it just prints whats already in gStringVar4
bool8 ShowFieldMessageFromBuffer(void)
{
if (sFieldMessageBoxMode != 0)
if (sFieldMessageBoxMode != FIELD_MESSAGE_BOX_HIDDEN)
return FALSE;
sFieldMessageBoxMode = 2;
textbox_auto_and_task_add();
sFieldMessageBoxMode = FIELD_MESSAGE_BOX_NORMAL;
StartDrawFieldMessage();
return TRUE;
}
static void textbox_fdecode_auto_and_task_add(u8* str, bool32 allowSkippingDelayWithButtonPress)
static void ExpandStringAndStartDrawFieldMessage(const u8* str, bool32 allowSkippingDelayWithButtonPress)
{
StringExpandPlaceholders(gStringVar4, str);
AddTextPrinterForMessage(allowSkippingDelayWithButtonPress);
task_add_textbox();
CreateTask_DrawFieldMessage();
}
static void textbox_auto_and_task_add(void)
static void StartDrawFieldMessage(void)
{
AddTextPrinterForMessage(TRUE);
task_add_textbox();
CreateTask_DrawFieldMessage();
}
void HideFieldMessageBox(void)
{
task_del_textbox();
DestroyTask_DrawFieldMessage();
ClearDialogWindowAndFrame(0, 1);
sFieldMessageBoxMode = 0;
sFieldMessageBoxMode = FIELD_MESSAGE_BOX_HIDDEN;
}
u8 GetFieldMessageBoxMode(void)
@ -136,20 +144,21 @@ u8 GetFieldMessageBoxMode(void)
bool8 IsFieldMessageBoxHidden(void)
{
if (sFieldMessageBoxMode == 0)
if (sFieldMessageBoxMode == FIELD_MESSAGE_BOX_HIDDEN)
return TRUE;
return FALSE;
}
void sub_8098358(void)
// Unused
static void ReplaceFieldMessageWithFrame(void)
{
task_del_textbox();
DestroyTask_DrawFieldMessage();
DrawStdWindowFrame(0, 1);
sFieldMessageBoxMode = 0;
sFieldMessageBoxMode = FIELD_MESSAGE_BOX_HIDDEN;
}
void sub_8098374(void)
void StopFieldMessage(void)
{
task_del_textbox();
sFieldMessageBoxMode = 0;
DestroyTask_DrawFieldMessage();
sFieldMessageBoxMode = FIELD_MESSAGE_BOX_HIDDEN;
}

View File

@ -1098,7 +1098,7 @@ bool32 TryStartMatchCall(void)
return FALSE;
}
void StartMatchCallFromScript(u8 *message)
void StartMatchCallFromScript(const u8 *message)
{
gMatchCallState.triggeredFromScript = 1;
StartMatchCall();

View File

@ -1282,7 +1282,7 @@ bool8 ScrCmd_pokenavcall(struct ScriptContext *ctx)
if (msg == NULL)
msg = (const u8 *)ctx->data[0];
sub_8098238(msg);
ShowPokenavFieldMessage(msg);
return FALSE;
}

View File

@ -904,7 +904,7 @@ const u8 *GetTrainerHillTrainerScript(void)
static void ShowTrainerHillPostBattleText(void)
{
CopyTrainerHillTrainerText(TRAINER_HILL_TEXT_AFTER, gSpecialVar_LastTalked);
sub_80982B8();
ShowFieldMessageFromBuffer();
}
static void CreateNPCTrainerHillParty(u16 trainerId, u8 firstMonId)