From a6d53b12e8a56993f5a9ee309862eff274367b82 Mon Sep 17 00:00:00 2001 From: Josh <32826900+ShinyDragonHunter@users.noreply.github.com> Date: Mon, 24 May 2021 04:43:15 +0100 Subject: [PATCH] =?UTF-8?q?Updated=20Implementing=20the=20=E2=80=9Ctextcol?= =?UTF-8?q?or=E2=80=9D=20script=20command=20from=20FRLG=20and=20give=20obj?= =?UTF-8?q?ect=20events=20their=20own=20text=20colour=20(markdown)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...nd-give-object-events-their-own-text-colour.md | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/Implementing-the-“textcolor”-script-command-from-FRLG-and-give-object-events-their-own-text-colour.md b/Implementing-the-“textcolor”-script-command-from-FRLG-and-give-object-events-their-own-text-colour.md index a89b379..e8660cd 100644 --- a/Implementing-the-“textcolor”-script-command-from-FRLG-and-give-object-events-their-own-text-colour.md +++ b/Implementing-the-“textcolor”-script-command-from-FRLG-and-give-object-events-their-own-text-colour.md @@ -5,7 +5,6 @@ This tutorial will walk you through how to implement this into Emerald whilst al Open field_specials.c and add the following function: ```c - u8 ContextNpcGetTextColor(void) { u8 gfxId; @@ -29,13 +28,11 @@ This function is what handles the context of the text. The `if (gSpecialVar_Text Extern it somewhere in `include/field_specials.h` like so: ```c - u8 ContextNpcGetTextColor(void); ``` Next, we want to open menu.c and add the following function: ```c - void AddTextPrinterForMessageWithTextColor(bool8 allowSkippingDelayWithButtonPress) { u8 color; @@ -46,7 +43,6 @@ void AddTextPrinterForMessageWithTextColor(bool8 allowSkippingDelayWithButtonPre } ``` I put this above `AddTextPrinterForMessage` which is the function base Emerald uses. - In this function, we have the local variable `color`. This variable is what we’re using to call the `ContextNpcGetTextColor` function we added earlier. Because of `ContextNpcGetTextColor` we are able to use `gSpecialVar_TextColor` as the colour value in `AddTextPrinterParameterized2` and because of the logic from the aforementioned functions, the colour value in `AddTextPrinterParameterized2`, will be the value of `graphicsInfo->textColor`. Don’t forget to extern the function somewhere in `menu.h` like this: @@ -54,11 +50,15 @@ Don’t forget to extern the function somewhere in `menu.h` like this: void AddTextPrinterForMessageWithTextColor(bool8 allowSkippingDelayWithButtonPress); ``` +At the top of menu.c, add the following: +```diff +#include "event_data.h" ++ #include "field_specials.h" +``` +This is so we can use the aformentioned `ContextNpcGetTextColor` function. + We need to open `field_message_box.c` and find the function `StartDrawFieldMessage` and make the following change: - - - -```c +```diff static void StartDrawFieldMessage(void) { @@ -67,7 +67,6 @@ static void StartDrawFieldMessage(void) CreateTask_DrawFieldMessage(); } ``` - `StartDrawFieldMessage` is the function that handles message boxes in the overworld. Next, we want to open `field_control_avatar.c` go to the function `ProcessPlayerFieldInput` and make the following change: @@ -116,7 +115,6 @@ We’re gonna implement the `textcolor` scripting command so you can make partic Go to `scrcmd.c` and add the following function: ```c - bool8 ScrCmd_textcolor(struct ScriptContext * ctx) { gSpecialVar_PrevTextColor = gSpecialVar_TextColor; @@ -129,20 +127,17 @@ This is the script command function for the textcolor script command. `ctx` is t We want to go to `data/script_cmd_table.inc` and go to line 202 and change the following: -```c -.4byte ScrCmd_nop1 @ 0xc7 -``` -to -```c -.4byte ScrCmd_textcolor @ 0xc7 +```diff +- .4byte ScrCmd_nop1 @ 0xc7 ++ .4byte ScrCmd_textcolor @ 0xc7 ``` This is so the scripting system knows to use `ScrCmd_textcolor` we added earlier. We want to declare these new special vars we’re using! Go to `event_data.c` on line 15, make the follow change: -```diff +```diff EWRAM_DATA u16 gSpecialVar_0x8000 = 0; EWRAM_DATA u16 gSpecialVar_0x8001 = 0; EWRAM_DATA u16 gSpecialVar_0x8002 = 0; @@ -166,8 +161,8 @@ EWRAM_DATA u16 gSpecialVar_MonBoxPos = 0; EWRAM_DATA static u8 gSpecialFlags[SPECIAL_FLAGS_SIZE] = {0}; ``` And on line 30 in `include/event_data.h`, make the following change: -```c +```diff extern u16 gSpecialVar_0x8000; extern u16 gSpecialVar_0x8001; extern u16 gSpecialVar_0x8002;