Updated Implementing the “textcolor” script command from FRLG and give object events their own text colour (markdown)

Josh 2021-05-24 04:43:15 +01:00
parent d83883f84c
commit a6d53b12e8
1 changed files with 13 additions and 18 deletions

@ -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 were 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`.
Dont forget to extern the function somewhere in `menu.h` like this:
@ -54,11 +50,15 @@ Dont 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 @@ Were 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 were 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;