Skip to content

Commit 2664c32

Browse files
committed
Namebox Implementation
1 parent b5a0e9c commit 2664c32

13 files changed

+179
-204
lines changed

asm/macros/event.inc

+6
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,12 @@
17281728
.2byte \item
17291729
.2byte \quantity
17301730
.endm
1731+
1732+
@ Sets the text of the name box in the next-shown message box.
1733+
.macro speakername text:req
1734+
.byte 0xe3
1735+
.4byte \text
1736+
.endm
17311737

17321738

17331739
@ Supplementary

data/script_cmd_table.inc

+1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ gScriptCmdTable::
227227
.4byte ScrCmd_warpwhitefade @ 0xe0
228228
.4byte ScrCmd_buffercontestname @ 0xe1
229229
.4byte ScrCmd_bufferitemnameplural @ 0xe2
230+
.4byte ScrCmd_setspeaker @ 0xe3
230231

231232
gScriptCmdTableEnd::
232233
.4byte ScrCmd_nop

gflib/string_util.c

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ EWRAM_DATA u8 gStringVar2[0x100] = {0};
88
EWRAM_DATA u8 gStringVar3[0x100] = {0};
99
EWRAM_DATA u8 gStringVar4[0x3E8] = {0};
1010
EWRAM_DATA static u8 sUnknownStringVar[16] = {0};
11+
EWRAM_DATA u8 gNamePlateBuffer[0x20] = {0};
1112

1213
static const u8 sDigits[] = __("0123456789ABCDEF");
1314

gflib/string_util.h

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ extern u8 gStringVar1[0x100];
55
extern u8 gStringVar2[0x100];
66
extern u8 gStringVar3[0x100];
77
extern u8 gStringVar4[0x3E8];
8+
extern u8 gNamePlateBuffer[0x20];
89

910
enum StringConvertMode
1011
{

graphics/text_window/message_box.png

16 Bytes
Loading

include/constants/flags.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@
13821382
#define FLAG_IS_CHAMPION (SYSTEM_FLAGS + 0x1F) // Seems to be related to linking.
13831383
#define FLAG_NURSE_UNION_ROOM_REMINDER (SYSTEM_FLAGS + 0x20)
13841384

1385-
#define FLAG_UNUSED_0x881 (SYSTEM_FLAGS + 0x21) // Unused Flag
1385+
#define FLAG_SUPPRESS_SPEAKER_NAME (SYSTEM_FLAGS + 0x21) // Unused Flag
13861386
#define FLAG_UNUSED_0x882 (SYSTEM_FLAGS + 0x22) // Unused Flag
13871387
#define FLAG_UNUSED_0x883 (SYSTEM_FLAGS + 0x23) // Unused Flag
13881388
#define FLAG_UNUSED_0x884 (SYSTEM_FLAGS + 0x24) // Unused Flag

include/field_message_box.h

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ enum
99
FIELD_MESSAGE_BOX_AUTO_SCROLL,
1010
};
1111

12+
extern const u8* gSpeakerName;
13+
1214
bool8 ShowFieldMessage(const u8 *message);
1315
bool8 ShowPokenavFieldMessage(const u8 *message);
1416
bool8 ShowFieldMessageFromBuffer(void);
@@ -18,5 +20,6 @@ bool8 IsFieldMessageBoxHidden(void);
1820
u8 GetFieldMessageBoxMode(void);
1921
void StopFieldMessage(void);
2022
void InitFieldMessageBox(void);
23+
void SetSpeakerName(const u8* name);
2124

2225
#endif // GUARD_FIELD_MESSAGE_BOX_H

include/menu.h

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ void InitTextBoxGfxAndPrinters(void);
4848
u16 RunTextPrintersAndIsPrinter0Active(void);
4949
void LoadMessageBoxAndBorderGfx(void);
5050
void DrawDialogueFrame(u8 windowId, bool8 copyToVram);
51+
void DrawDialogueFrameWithNameplate(u8 windowId, bool8 copyToVram);
5152
void ClearStdWindowAndFrame(u8 windowId, bool8 copyToVram);
5253
u16 AddTextPrinterParameterized2(u8 windowId, u8 fontId, const u8 *str, u8 speed, void (*callback)(struct TextPrinterTemplate *, u16), u8 fgColor, u8 bgColor, u8 shadowColor);
5354
void PrintPlayerNameOnWindow(u8, const u8 *, u16, u16);

src/battle_setup.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,9 @@ void SetMapVarsToTrainer(void)
10971097
gSpecialVar_LastTalked = sTrainerObjectEventLocalId;
10981098
gSelectedObjectEvent = GetObjectEventIdByLocalIdAndMap(sTrainerObjectEventLocalId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup);
10991099
}
1100+
if (gTrainerBattleOpponent_A != 0) {
1101+
gSpeakerName = gTrainers[gTrainerBattleOpponent_A].trainerName;
1102+
}
11001103
}
11011104

11021105
const u8 *BattleSetup_ConfigureTrainerBattle(const u8 *data)
@@ -1507,10 +1510,14 @@ static const u8 *ReturnEmptyStringIfNull(const u8 *string)
15071510

15081511
static const u8 *GetIntroSpeechOfApproachingTrainer(void)
15091512
{
1510-
if (gApproachingTrainerId == 0)
1513+
if (gApproachingTrainerId == 0) {
1514+
gSpeakerName = gTrainers[gTrainerBattleOpponent_A].trainerName;
15111515
return ReturnEmptyStringIfNull(sTrainerAIntroSpeech);
1512-
else
1516+
}
1517+
else {
1518+
gSpeakerName = gTrainers[gTrainerBattleOpponent_B].trainerName;
15131519
return ReturnEmptyStringIfNull(sTrainerBIntroSpeech);
1520+
}
15141521
}
15151522

15161523
const u8 *GetTrainerALoseText(void)

src/field_message_box.c

+35-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
#include "menu.h"
33
#include "string_util.h"
44
#include "task.h"
5+
#include "event_data.h"
56
#include "text.h"
67
#include "match_call.h"
78
#include "field_message_box.h"
89

910
static EWRAM_DATA u8 sFieldMessageBoxMode = 0;
11+
EWRAM_DATA const u8* gSpeakerName = NULL;
1012

1113
static void ExpandStringAndStartDrawFieldMessage(const u8 *, bool32);
1214
static void StartDrawFieldMessage(void);
@@ -33,8 +35,15 @@ static void Task_DrawFieldMessage(u8 taskId)
3335
task->tState++;
3436
break;
3537
case 1:
36-
DrawDialogueFrame(0, TRUE);
37-
task->tState++;
38+
if (gSpeakerName != NULL && !FlagGet(FLAG_SUPPRESS_SPEAKER_NAME)) {
39+
DrawDialogueFrameWithNameplate(0, TRUE);
40+
PutWindowTilemap(1);
41+
CopyWindowToVram(1, COPYWIN_FULL);
42+
}
43+
else {
44+
DrawDialogueFrame(0, TRUE);
45+
}
46+
task->tState++;
3847
break;
3948
case 2:
4049
if (RunTextPrintersAndIsPrinter0Active() != TRUE)
@@ -116,8 +125,26 @@ bool8 ShowFieldMessageFromBuffer(void)
116125
return TRUE;
117126
}
118127

128+
extern void FillDialogFramePlate();
129+
extern int GetDialogFramePlateWidth();
119130
static void ExpandStringAndStartDrawFieldMessage(const u8 *str, bool32 allowSkippingDelayWithButtonPress)
120131
{
132+
if (gSpeakerName != NULL && !FlagGet(FLAG_SUPPRESS_SPEAKER_NAME)) {
133+
int strLen = GetStringWidth(FONT_SMALL, gSpeakerName, -1);
134+
if (strLen > 0) {
135+
strLen = GetDialogFramePlateWidth()/2 - strLen/2;
136+
gNamePlateBuffer[0] = EXT_CTRL_CODE_BEGIN;
137+
gNamePlateBuffer[1] = EXT_CTRL_CODE_CLEAR_TO;
138+
gNamePlateBuffer[2] = strLen;
139+
StringExpandPlaceholders(&gNamePlateBuffer[3], gSpeakerName);
140+
} else {
141+
StringExpandPlaceholders(&gNamePlateBuffer[0], gSpeakerName);
142+
}
143+
FillDialogFramePlate();
144+
AddTextPrinterParameterized2(1, FONT_SMALL, gNamePlateBuffer, 0, NULL, 1, 0, 2);
145+
PutWindowTilemap(1);
146+
CopyWindowToVram(1, COPYWIN_FULL);
147+
}
121148
StringExpandPlaceholders(gStringVar4, str);
122149
AddTextPrinterForMessage(allowSkippingDelayWithButtonPress);
123150
CreateTask_DrawFieldMessage();
@@ -134,6 +161,7 @@ void HideFieldMessageBox(void)
134161
DestroyTask_DrawFieldMessage();
135162
ClearDialogWindowAndFrame(0, TRUE);
136163
sFieldMessageBoxMode = FIELD_MESSAGE_BOX_HIDDEN;
164+
gSpeakerName = NULL;
137165
}
138166

139167
u8 GetFieldMessageBoxMode(void)
@@ -161,3 +189,8 @@ void StopFieldMessage(void)
161189
DestroyTask_DrawFieldMessage();
162190
sFieldMessageBoxMode = FIELD_MESSAGE_BOX_HIDDEN;
163191
}
192+
193+
void SetSpeakerName(const u8* name)
194+
{
195+
gSpeakerName = name;
196+
}

src/main_menu.c

+13-13
Original file line numberDiff line numberDiff line change
@@ -2277,20 +2277,20 @@ static void NewGameBirchSpeech_ShowDialogueWindow(u8 windowId, u8 copyToVram)
22772277

22782278
static void NewGameBirchSpeech_CreateDialogueWindowBorder(u8 bg, u8 x, u8 y, u8 width, u8 height, u8 palNum)
22792279
{
2280-
FillBgTilemapBufferRect(bg, 0xFD, x-2, y-1, 1, 1, palNum);
2281-
FillBgTilemapBufferRect(bg, 0xFF, x-1, y-1, 1, 1, palNum);
2282-
FillBgTilemapBufferRect(bg, 0x100, x, y-1, width, 1, palNum);
2283-
FillBgTilemapBufferRect(bg, 0x101, x+width-1, y-1, 1, 1, palNum);
2284-
FillBgTilemapBufferRect(bg, 0x102, x+width, y-1, 1, 1, palNum);
2280+
FillBgTilemapBufferRect(bg, 0x0FC, x-2, y-1, 1, 1, palNum);
2281+
FillBgTilemapBufferRect(bg, 0x0FD, x-1, y-1, 1, 1, palNum);
2282+
FillBgTilemapBufferRect(bg, 0x0FE, x, y-1, width, 1, palNum);
2283+
FillBgTilemapBufferRect(bg, 0x0FF, x+width-1, y-1, 1, 1, palNum);
2284+
FillBgTilemapBufferRect(bg, 0x100, x+width, y-1, 1, 1, palNum);
22852285
FillBgTilemapBufferRect(bg, 0x103, x-2, y, 1, 5, palNum);
2286-
FillBgTilemapBufferRect(bg, 0x105, x-1, y, width+1, 5, palNum);
2287-
FillBgTilemapBufferRect(bg, 0x106, x+width, y, 1, 5, palNum);
2288-
2289-
FillBgTilemapBufferRect(bg, BG_TILE_V_FLIP(0xFD), x-2, y+height, 1, 1, palNum);
2290-
FillBgTilemapBufferRect(bg, BG_TILE_V_FLIP(0xFF), x-1, y+height, 1, 1, palNum);
2291-
FillBgTilemapBufferRect(bg, BG_TILE_V_FLIP(0x100), x, y+height, width-1, 1, palNum);
2292-
FillBgTilemapBufferRect(bg, BG_TILE_V_FLIP(0x101), x+width-1, y+height, 1, 1, palNum);
2293-
FillBgTilemapBufferRect(bg, BG_TILE_V_FLIP(0x102), x+width, y+height, 1, 1, palNum);
2286+
FillBgTilemapBufferRect(bg, 0x104, x-1, y, width+1, 5, palNum);
2287+
FillBgTilemapBufferRect(bg, 0x105, x+width, y, 1, 5, palNum);
2288+
2289+
FillBgTilemapBufferRect(bg, BG_TILE_V_FLIP(0x0FC), x-2, y+height, 1, 1, palNum);
2290+
FillBgTilemapBufferRect(bg, BG_TILE_V_FLIP(0x0FD), x-1, y+height, 1, 1, palNum);
2291+
FillBgTilemapBufferRect(bg, BG_TILE_V_FLIP(0x0FE), x, y+height, width-1, 1, palNum);
2292+
FillBgTilemapBufferRect(bg, BG_TILE_V_FLIP(0x0FF), x+width-1, y+height, 1, 1, palNum);
2293+
FillBgTilemapBufferRect(bg, BG_TILE_V_FLIP(0x100), x+width, y+height, 1, 1, palNum);
22942294
}
22952295

22962296
static void Task_NewGameBirchSpeech_ReturnFromNamingScreenShowTextbox(u8 taskId)

0 commit comments

Comments
 (0)