From 3df2ebfa854a7bc13d37819950da0ae69e74192e Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 18 Jun 2025 16:14:50 +0200 Subject: [PATCH] macro troubles --- include/data_script.h | 1 + include/textbox.h | 9 +++++++++ src/ground_script.c | 10 +++++----- src/textbox.c | 34 +++++++++++++++++++--------------- 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/include/data_script.h b/include/data_script.h index f935df7cb..b9f0a59ee 100644 --- a/include/data_script.h +++ b/include/data_script.h @@ -37,6 +37,7 @@ // 22..2f: ??? #define TEXTBOX_AUTO_PRESS(endF, midF) { 0x2b, 0, 0, endF, midF, NULL} // Waits specified number of frames, then automatically does a button press without waiting for player's input. -1 disables it. // 30..39: various text printing +#define MSG_NPC(id, msg) { 0x41, 0, id, 0, 0, msg } // ID is portrait id of the npc. -1 means no portrait // 3a: yes/no choice (only used for saving) // 3b: uber command (conditional jump) // 3c: unknown textbox-related cjump diff --git a/include/textbox.h b/include/textbox.h index fce7f5337..9a7fac852 100644 --- a/include/textbox.h +++ b/include/textbox.h @@ -1,6 +1,15 @@ #ifndef GUARD_TEXTBOX_H #define GUARD_TEXTBOX_H +enum +{ + SCRIPT_TEXT_TYPE_INSTANT, // 0x32 Used for narration and signposts + SCRIPT_TEXT_TYPE_PLAYER, // 0x33 Used for player's thoughts, player's dialogue and Murky Cave's judge of darkness + SCRIPT_TEXT_TYPE_NPC, // 0x34 Used for all NPCs, has the speaker's name and dialogue sound + SCRIPT_TEXT_TYPE_LETTER, // 0x35 Used for Mails/Letters. Has a dialogue sound when priting text, similarly to SCRIPT_TEXT_TYPE_NPC + SCRIPT_TEXT_TYPE_4, // 0x36 Used for sound-like texts such as "Flap-flap" or roars "Gyaaaaaaaah". It doesn't wait for button press, so the message just closes after printing unless WAIT command is used afterwards. +}; + void TextboxInit(void); void TextboxFree(void); diff --git a/src/ground_script.c b/src/ground_script.c index 7bf4d8706..8d98afc2d 100644 --- a/src/ground_script.c +++ b/src/ground_script.c @@ -1949,11 +1949,11 @@ s32 ExecuteScriptCommand(Action *action) case 0x32 ... 0x38: { s8 ret = 0; switch (scriptData->curScriptOp) { - case 0x32: ret = ScriptPrintText(0, curCmd.argShort, curCmd.argPtr); break; - case 0x33: ret = ScriptPrintText(1, curCmd.argShort, curCmd.argPtr); break; - case 0x34: ret = ScriptPrintText(2, curCmd.argShort, curCmd.argPtr); break; - case 0x35: ret = ScriptPrintText(3, curCmd.argShort, curCmd.argPtr); break; - case 0x36: ret = ScriptPrintText(4, curCmd.argShort, curCmd.argPtr); break; + case 0x32: ret = ScriptPrintText(SCRIPT_TEXT_TYPE_INSTANT, curCmd.argShort, curCmd.argPtr); break; + case 0x33: ret = ScriptPrintText(SCRIPT_TEXT_TYPE_PLAYER, curCmd.argShort, curCmd.argPtr); break; + case 0x34: ret = ScriptPrintText(SCRIPT_TEXT_TYPE_NPC, curCmd.argShort, curCmd.argPtr); break; + case 0x35: ret = ScriptPrintText(SCRIPT_TEXT_TYPE_LETTER, curCmd.argShort, curCmd.argPtr); break; + case 0x36: ret = ScriptPrintText(SCRIPT_TEXT_TYPE_4, curCmd.argShort, curCmd.argPtr); break; case 0x37: ret = sub_809AEEC(curCmd.argPtr); break; case 0x38: ret = sub_809AF2C(curCmd.argPtr); break; } diff --git a/src/textbox.c b/src/textbox.c index 34fc0d65a..51e32e391 100644 --- a/src/textbox.c +++ b/src/textbox.c @@ -273,18 +273,22 @@ static const MenuItem sEmptyMenuItems[] = {NULL, 0}, }; -static const u32 sTextboxTypes[] = +static const u32 sScriptTextboxTypes[] = { - 1, 1, 1, 1, 1 + [SCRIPT_TEXT_TYPE_INSTANT] = 1, + [SCRIPT_TEXT_TYPE_PLAYER] = 1, + [SCRIPT_TEXT_TYPE_NPC] = 1, + [SCRIPT_TEXT_TYPE_LETTER] = 1, + [SCRIPT_TEXT_TYPE_4] = 1, }; -static const u16 sFlagSets[] = +static const u16 sScriptFlagSets[] = { - TEXTBOX_FLAG_UNUSED_x2 | TEXTBOX_FLAG_WAIT_FOR_BUTTON_PRESS_2 | TEXTBOX_FLAG_WAIT_FOR_BUTTON_PRESS | TEXTBOX_FLAG_INSTANT_TEXT, - TEXTBOX_FLAG_UNUSED_x2 | TEXTBOX_FLAG_WAIT_FOR_BUTTON_PRESS_2 | TEXTBOX_FLAG_WAIT_FOR_BUTTON_PRESS, - TEXTBOX_FLAG_UNUSED_x2 | TEXTBOX_FLAG_WAIT_FOR_BUTTON_PRESS_2 | TEXTBOX_FLAG_WAIT_FOR_BUTTON_PRESS | TEXTBOX_FLAG_SPEAKER, - TEXTBOX_FLAG_UNUSED_x2 | TEXTBOX_FLAG_WAIT_FOR_BUTTON_PRESS_2 | TEXTBOX_FLAG_WAIT_FOR_BUTTON_PRESS | TEXTBOX_FLAG_DIALOGUE_SOUND, - 0x01, + [SCRIPT_TEXT_TYPE_INSTANT] = TEXTBOX_FLAG_UNUSED_x2 | TEXTBOX_FLAG_WAIT_FOR_BUTTON_PRESS_2 | TEXTBOX_FLAG_WAIT_FOR_BUTTON_PRESS | TEXTBOX_FLAG_INSTANT_TEXT, + [SCRIPT_TEXT_TYPE_PLAYER] = TEXTBOX_FLAG_UNUSED_x2 | TEXTBOX_FLAG_WAIT_FOR_BUTTON_PRESS_2 | TEXTBOX_FLAG_WAIT_FOR_BUTTON_PRESS, + [SCRIPT_TEXT_TYPE_NPC] = TEXTBOX_FLAG_UNUSED_x2 | TEXTBOX_FLAG_WAIT_FOR_BUTTON_PRESS_2 | TEXTBOX_FLAG_WAIT_FOR_BUTTON_PRESS | TEXTBOX_FLAG_SPEAKER, + [SCRIPT_TEXT_TYPE_LETTER] = TEXTBOX_FLAG_UNUSED_x2 | TEXTBOX_FLAG_WAIT_FOR_BUTTON_PRESS_2 | TEXTBOX_FLAG_WAIT_FOR_BUTTON_PRESS | TEXTBOX_FLAG_DIALOGUE_SOUND, + [SCRIPT_TEXT_TYPE_4] = 0x01, // These are effectively unused 0x121, 0x101, 0x10D, 0x105, 0 }; @@ -798,8 +802,8 @@ bool8 ScriptPrintText(s32 scriptMsgType, s32 speakerId_, const char *text) return ScriptClearTextbox2(); } else { - ResetTextboxType(sTextboxTypes[scriptMsgType], 0); - return ScriptPrintTextInternal(&sTextbox->unkC, sFlagSets[scriptMsgType], speakerId, text); + ResetTextboxType(sScriptTextboxTypes[scriptMsgType], 0); + return ScriptPrintTextInternal(&sTextbox->unkC, sScriptFlagSets[scriptMsgType], speakerId, text); } } @@ -874,7 +878,7 @@ void sub_809B028(const MenuItem * menuItems, s32 a1_, s32 a2, s32 a3, s32 a4_, c s32 a1 = (u8) a1_; s32 a4 = (s16) a4_; - ResetTextboxType(sTextboxTypes[a3], 0); + ResetTextboxType(sScriptTextboxTypes[a3], 0); sTextbox->unk414 = 1; sTextbox->unk418 = NULL; sTextbox->unk41C = menuItems; @@ -882,7 +886,7 @@ void sub_809B028(const MenuItem * menuItems, s32 a1_, s32 a2, s32 a3, s32 a4_, c sTextbox->unk424 = (a1 != 0) ? 2 : 0; sTextbox->unk428 = 0; sTextbox->unk430 = a2; - if (sFlagSets[a3] & TEXTBOX_FLAG_SPEAKER) { + if (sScriptFlagSets[a3] & TEXTBOX_FLAG_SPEAKER) { if (a4 < 0) { strcpy(gSpeakerNameBuffer, sYellowSpeechBubbleText); } @@ -892,9 +896,9 @@ void sub_809B028(const MenuItem * menuItems, s32 a1_, s32 a2, s32 a3, s32 a4_, c } CreateMenuDialogueBoxAndPortrait(text, sub_809B428, a2, menuItems, 0, 4, 0, GetSpeakerPortrait(a4), - ((sFlagSets[a3] & TEXTBOX_FLAG_SPEAKER) ? STR_FORMAT_FLAG_SPEAKER_NAME | STR_FORMAT_FLAG_DIALOGUE_SOUND : 0) - | ((sFlagSets[a3] & TEXTBOX_FLAG_DIALOGUE_SOUND) ? STR_FORMAT_FLAG_DIALOGUE_SOUND : 0) - | ((sFlagSets[a3] & TEXTBOX_FLAG_INSTANT_TEXT) ? STR_FORMAT_FLAG_INSTANT_TEXT | STR_FORMAT_FLAG_WAIT_FOR_BUTTON_PRESS_2 : STR_FORMAT_FLAG_WAIT_FOR_BUTTON_PRESS_2)); + ((sScriptFlagSets[a3] & TEXTBOX_FLAG_SPEAKER) ? STR_FORMAT_FLAG_SPEAKER_NAME | STR_FORMAT_FLAG_DIALOGUE_SOUND : 0) + | ((sScriptFlagSets[a3] & TEXTBOX_FLAG_DIALOGUE_SOUND) ? STR_FORMAT_FLAG_DIALOGUE_SOUND : 0) + | ((sScriptFlagSets[a3] & TEXTBOX_FLAG_INSTANT_TEXT) ? STR_FORMAT_FLAG_INSTANT_TEXT | STR_FORMAT_FLAG_WAIT_FOR_BUTTON_PRESS_2 : STR_FORMAT_FLAG_WAIT_FOR_BUTTON_PRESS_2)); if (sTextbox->unk424 & 2) { sub_809A6E4(1);