From aaf5d91c18727f9a542f90ec0e7ca5a5f6247815 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 3 Jun 2020 18:25:16 -0400 Subject: [PATCH] Document field_message_box.c --- include/field_message_box.h | 6 +- include/match_call.h | 2 +- src/battle_setup.c | 4 +- src/cable_club.c | 2 +- src/field_message_box.c | 109 +++++++++++++++++++----------------- src/match_call.c | 2 +- src/scrcmd.c | 2 +- src/trainer_hill.c | 2 +- 8 files changed, 69 insertions(+), 60 deletions(-) diff --git a/include/field_message_box.h b/include/field_message_box.h index 58f782d9c..34b3324e7 100644 --- a/include/field_message_box.h +++ b/include/field_message_box.h @@ -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 diff --git a/include/match_call.h b/include/match_call.h index 8214e03b7..bc5f374bd 100644 --- a/include/match_call.h +++ b/include/match_call.h @@ -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); diff --git a/src/battle_setup.c b/src/battle_setup.c index b44c7b9ec..40e36d302 100644 --- a/src/battle_setup.c +++ b/src/battle_setup.c @@ -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 { diff --git a/src/cable_club.c b/src/cable_club.c index c2ac72883..b9c948a9c 100644 --- a/src/cable_club.c +++ b/src/cable_club.c @@ -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); diff --git a/src/field_message_box.c b/src/field_message_box.c index be76b0c19..1b760c7df 100755 --- a/src/field_message_box.c +++ b/src/field_message_box.c @@ -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; } diff --git a/src/match_call.c b/src/match_call.c index 9d8523576..033276684 100644 --- a/src/match_call.c +++ b/src/match_call.c @@ -1098,7 +1098,7 @@ bool32 TryStartMatchCall(void) return FALSE; } -void StartMatchCallFromScript(u8 *message) +void StartMatchCallFromScript(const u8 *message) { gMatchCallState.triggeredFromScript = 1; StartMatchCall(); diff --git a/src/scrcmd.c b/src/scrcmd.c index ad01791a9..9e62c45c5 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -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; } diff --git a/src/trainer_hill.c b/src/trainer_hill.c index 87866b02e..d6cb49837 100644 --- a/src/trainer_hill.c +++ b/src/trainer_hill.c @@ -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)