Skip to content

Commit

Permalink
Blackout_PrintMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
red031000 committed Dec 15, 2023
1 parent 7cbd2d4 commit 3ede75f
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 101 deletions.
63 changes: 0 additions & 63 deletions arm9/asm/blackout_asm.s
Original file line number Diff line number Diff line change
@@ -1,73 +1,10 @@
.include "asm/macros.inc"
.include "global.inc"

.extern gSystem
.extern Blackout_DrawMessage

.text

thumb_func_start sub_020482F4
sub_020482F4: ; 0x020482F4
push {r4-r7, lr}
sub sp, #0x14
add r5, r0, #0x0
mov r0, #0x1
str r1, [sp, #0x10]
lsl r0, r0, #0xa
mov r1, #0xb
add r7, r3, #0x0
bl String_New
add r6, r0, #0x0
mov r0, #0x1
lsl r0, r0, #0xa
mov r1, #0xb
bl String_New
add r4, r0, #0x0
add r0, r5, #0x0
add r0, #0xc
mov r1, #0x0
bl FillWindowPixelBuffer
ldr r0, [r5, #0x1c]
ldr r1, [sp, #0x10]
add r2, r6, #0x0
bl ReadMsgDataIntoString
ldr r0, [r5, #0x20]
add r1, r4, #0x0
add r2, r6, #0x0
bl StringExpandPlaceholders
mov r0, #0x0
add r1, r4, #0x0
add r2, r0, #0x0
bl sub_02002F08
add r3, r0, #0x0
str r7, [sp, #0x0]
mov r0, #0xff
str r0, [sp, #0x4]
ldr r0, _02048378 ; =0x000F0200
mov r1, #0x0
str r0, [sp, #0x8]
add r0, r5, #0x0
str r1, [sp, #0xc]
ldrb r5, [r5, #0x13]
add r0, #0xc
add r2, r4, #0x0
lsl r5, r5, #0x3
sub r3, r5, r3
lsl r3, r3, #0x18
lsr r3, r3, #0x19
sub r3, r3, #0x4
lsl r3, r3, #0x18
lsr r3, r3, #0x18
bl AddTextPrinterParameterized2
add r0, r6, #0x0
bl String_Delete
add r0, r4, #0x0
bl String_Delete
add sp, #0x14
pop {r4-r7, pc}
.balign 4
_02048378: .word 0x000F0200

thumb_func_start FieldTask_BlackOut
FieldTask_BlackOut: ; 0x0204837C
push {r3-r7, lr}
Expand Down
2 changes: 1 addition & 1 deletion arm9/global.inc
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
.extern GetFontAttribute
.extern LoadFontPal0
.extern LoadFontPal1
.extern sub_02002F08
.extern FontID_String_GetWidthMultiline
.extern sub_02002F40
.extern sub_02002F90
.extern sub_02002F9C
Expand Down
2 changes: 1 addition & 1 deletion arm9/overlays/15/asm/overlay_15.s
Original file line number Diff line number Diff line change
Expand Up @@ -7762,7 +7762,7 @@ ov15_021DB100: ; 0x021DB100
add r1, r6, #0
mov r2, #0
add r7, r3, #0
bl sub_02002F08
bl FontID_String_GetWidthMultiline
mov r1, #0x58
sub r0, r1, r0
lsr r0, r0, #1
Expand Down
8 changes: 4 additions & 4 deletions arm9/overlays/16/asm/overlay_16.s
Original file line number Diff line number Diff line change
Expand Up @@ -17091,7 +17091,7 @@ _021DF394:
mov r0, #0
add r1, r6, #0
add r2, r0, #0
bl sub_02002F08
bl FontID_String_GetWidthMultiline
mov r1, #0xd0
sub r0, r1, r0
lsr r4, r0, #1
Expand Down Expand Up @@ -17143,7 +17143,7 @@ ov16_021DF3E4: ; 0x021DF3E4
mov r0, #0
add r1, r6, #0
add r2, r0, #0
bl sub_02002F08
bl FontID_String_GetWidthMultiline
mov r1, #0xd0
sub r0, r1, r0
lsr r5, r0, #1
Expand Down Expand Up @@ -29933,7 +29933,7 @@ ov16_021E51AC: ; 0x021E51AC
mov r0, #0
add r1, r4, #0
add r2, r0, #0
bl sub_02002F08
bl FontID_String_GetWidthMultiline
cmp r0, #0xf0
bhs _021E51D8
lsr r1, r0, #1
Expand Down Expand Up @@ -34543,7 +34543,7 @@ ov16_021E739C: ; 0x021E739C
mov r0, #0
add r1, r4, #0
add r2, r0, #0
bl sub_02002F08
bl FontID_String_GetWidthMultiline
cmp r0, #0xf0
bhs _021E73C8
lsr r1, r0, #1
Expand Down
4 changes: 2 additions & 2 deletions arm9/overlays/47/asm/overlay_47.s
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ ov47_02255184: ; 0x02255184
mov r0, #0
ldr r1, [r4, #0x5c]
add r2, r0, #0
bl sub_02002F08
bl FontID_String_GetWidthMultiline
mov r1, #0xc0
sub r0, r1, r0
lsr r3, r0, #1
Expand Down Expand Up @@ -1353,7 +1353,7 @@ ov47_02255250: ; 0x02255250
mov r0, #0
ldr r1, [r4, #0x5c]
add r2, r0, #0
bl sub_02002F08
bl FontID_String_GetWidthMultiline
mov r1, #0xc0
sub r0, r1, r0
lsr r3, r0, #1
Expand Down
2 changes: 1 addition & 1 deletion arm9/overlays/55/asm/overlay_55.s
Original file line number Diff line number Diff line change
Expand Up @@ -3703,7 +3703,7 @@ _021D92CE:
mov r0, #0
ldr r1, [r1]
add r2, r0, #0
bl sub_02002F08
bl FontID_String_GetWidthMultiline
mov r1, #0xa8
sub r0, r1, r0
mov r1, #0
Expand Down
4 changes: 2 additions & 2 deletions arm9/overlays/59/src/ov59_Intro.c
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ BOOL ov59_DisplayControlAdventureMessage(ov59_IntroOverlayData *data, u32 msgNo,
template.height = (u8)(count * 2);
AddWindow(data->bgConfig, &data->window, &template);
FillWindowPixelRect(&data->window, 0, 0, 0, 192, 192);
AddTextPrinterParameterized2(&data->window, 0, data->string, 0, 0, 0, MakeFontColor(1, 2, 0), NULL);
AddTextPrinterParameterized2(&data->window, 0, data->string, 0, 0, TEXT_SPEED_INSTANT, MAKE_TEXT_COLOR(1, 2, 0), NULL);
}
else
{
Expand All @@ -970,7 +970,7 @@ BOOL ov59_DisplayControlAdventureMessage(ov59_IntroOverlayData *data, u32 msgNo,
template.height = (u8)height;
AddWindow(data->bgConfig, &data->window, &template);
FillWindowPixelRect(&data->window, 0, 0, 0, 192, 192);
AddTextPrinterParameterized2(&data->window, 0, data->string, 0, 0, 0, MakeFontColor(15, 2, 0), NULL);
AddTextPrinterParameterized2(&data->window, 0, data->string, 0, 0, TEXT_SPEED_INSTANT, MAKE_TEXT_COLOR(15, 2, 0), NULL);
}
String_Delete(data->string);
data->displayControlMessageCounter = 1;
Expand Down
4 changes: 2 additions & 2 deletions arm9/overlays/59/src/ov59_TV.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,10 @@ BOOL ov59_021D9C74(ov59_TVOverlayData *data, u32 msgNo, u32 param2, u32 param3)
ReadMsgDataIntoString(data->msgData, msgNo, string);
AddWindow(data->bgConfig, &data->window, &ov59_021DA04C);
FillWindowPixelRect(&data->window, 0, 0, 0, 256, 192);
u32 unk0 = (u32)sub_02002F08(0, string, 0);
u32 unk0 = FontID_String_GetWidthMultiline(0, string, 0);

unk0 = (256 - unk0 ) / 2;
AddTextPrinterParameterized2(&data->window, 0, string, unk0, param3, 0, MakeFontColor(15, 2, 0), NULL);
AddTextPrinterParameterized2(&data->window, 0, string, unk0, param3, TEXT_SPEED_INSTANT, MAKE_TEXT_COLOR(15, 2, 0), NULL);
String_Delete(string);
CopyWindowToVram(&data->window);
ToggleBgLayer(GF_BG_LYR_MAIN_2, GX_PLANE_TOGGLE_ON);
Expand Down
26 changes: 23 additions & 3 deletions arm9/src/blackout_src.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
#include "gf_gfx_loader.h"
#include "PAD_pad.h"
#include "render_window.h"
#include "text.h"

static void Blackout_InitDisplays(BgConfig *bgConfig);
/*static*/ void Blackout_DrawMessage(FieldSystem *fieldSystem, TaskManager *taskManager);
static BOOL Task_ShowPrintedBlackoutMessage(TaskManager *taskManager);
static void Blackout_PrintMessage(BlackoutScreenEnvironment *environment, s32 msgNo, u8 x, u8 y);

extern void sub_020482F4(BlackoutScreenEnvironment *environment, s32 msgNo, u8 x, u8 y);
extern void BeginNormalPaletteFade(u32 pattern, u32 typeTop, u32 typeBottom, u16 colour, u32 duration, u32 framesPer, HeapID heapId);
extern BOOL IsPaletteFadeFinished(void);

Expand Down Expand Up @@ -90,10 +91,10 @@ static void Blackout_InitDisplays(BgConfig *bgConfig) {
BufferPlayersName(env->msgFmt, 0, Save_PlayerData_GetProfileAddr(FieldSystem_GetSaveData(fieldSystem)));
if (fieldSystem->location->mapId == MAP_T01R0201) {
// {STRVAR_1 3, 0} scurried back\nhome, protecting the exhausted\nand fainted Pokémon from further\nharm...
sub_020482F4(env, narc_0328_00004, 0, 0);
Blackout_PrintMessage(env, narc_0328_00004, 0, 0);
} else {
// {STRVAR_1 3, 0} scurried to\na Pokémon Center, protecting\nthe exhausted and fainted\nPokémon from further harm...
sub_020482F4(env, narc_0328_00003, 0, 0);
Blackout_PrintMessage(env, narc_0328_00003, 0, 0);
}
CopyWindowToVram(&env->window);
TaskManager_Call(taskManager, Task_ShowPrintedBlackoutMessage, env);
Expand Down Expand Up @@ -136,3 +137,22 @@ static BOOL Task_ShowPrintedBlackoutMessage(TaskManager *taskManager) {

return FALSE;
}

static void Blackout_PrintMessage(BlackoutScreenEnvironment *environment, s32 msgNo, u8 x, u8 y) {
String *tmpStr = String_New(1024, HEAP_ID_FIELD);
String *finStr = String_New(1024, HEAP_ID_FIELD);

FillWindowPixelBuffer(&environment->window, 0);
ReadMsgDataIntoString(environment->msgData, msgNo, tmpStr);
StringExpandPlaceholders(environment->msgFmt, finStr, tmpStr);

u32 width = FontID_String_GetWidthMultiline(0, finStr, 0);
x = (environment->window.width * 8 - width);
x /= 2;
x -= 4;

AddTextPrinterParameterized2(&environment->window, 0, finStr, x, y, TEXT_SPEED_NOTRANSFER, MAKE_TEXT_COLOR(15, 2, 0), NULL);

String_Delete(tmpStr);
String_Delete(finStr);
}
2 changes: 1 addition & 1 deletion arm9/src/font.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void LoadFontPal1(enum GFPalLoadLocation location, enum GFPalSlotOffset palSlotO
GfGfxLoader_GXLoadPal(NARC_GRAPHIC_FONT, NARC_font_narc_0007_NCLR, location, palSlotOffset, 0x20, heapId);
}

s32 sub_02002F08(u32 param0, struct String *str, u32 param2)
u32 FontID_String_GetWidthMultiline(u32 param0, struct String *str, u32 param2)
{
GF_ASSERT(UNK_02106FC8->unk94[param0] != NULL);

Expand Down
14 changes: 3 additions & 11 deletions arm9/src/list_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,7 @@ struct ListMenu * ListMenuInit(const struct ListMenuTemplate * template, u16 cur
list->overrideEnabled = FALSE;
if (list->template.totalItems < list->template.maxShowed)
list->template.maxShowed = list->template.totalItems;
ListMenuCursorSetColor(
list->cursor,
// MakeFontColor(list->template.cursorPal, list->template.cursorShadowPal, list->fillValue)
(u32)(
((u32)(list->template.cursorPal << 24) >> 8)
| ((u32)(list->template.cursorShadowPal << 24) >> 16)
| ((u32)(list->template.fillValue << 24) >> 24)
)
);
ListMenuCursorSetColor(list->cursor, MAKE_TEXT_COLOR(list->template.cursorPal, list->template.cursorShadowPal, list->template.fillValue));
FillWindowPixelBuffer(list->template.window, list->template.fillValue);
ListMenuPrintEntries(list, list->cursorPos, 0, list->template.maxShowed);
ListMenuDrawCursor(list);
Expand Down Expand Up @@ -312,11 +304,11 @@ void ListMenuPrint(struct ListMenu * list, struct String * str, u8 x, u8 y)
{
if (list->overrideEnabled)
{
AddTextPrinterParameterized3(list->template.window, list->fontId, str, x, y, 0xFF, MakeFontColor(list->cursorPal, list->cursorShadowPal, list->fillValue), list->lettersSpacing, 0, NULL);
AddTextPrinterParameterized3(list->template.window, list->fontId, str, x, y, 0xFF, MAKE_TEXT_COLOR(list->cursorPal, list->cursorShadowPal, list->fillValue), list->lettersSpacing, 0, NULL);
}
else
{
AddTextPrinterParameterized3(list->template.window, list->template.fontId, str, x, y, 0xFF, MakeFontColor(list->template.cursorPal, list->template.cursorShadowPal, list->template.fillValue), list->template.lettersSpacing, 0, NULL);
AddTextPrinterParameterized3(list->template.window, list->template.fontId, str, x, y, 0xFF, MAKE_TEXT_COLOR(list->template.cursorPal, list->template.cursorShadowPal, list->template.fillValue), list->template.lettersSpacing, 0, NULL);
}
}
}
Expand Down
11 changes: 1 addition & 10 deletions include/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@
#include "global.h"
#include "text.h"

static inline u32 MakeFontColor(u32 fgPal, u32 shdwPal, u32 bgPal)
{
return (u32)(
((u32)(fgPal << 24) >> 8)
| ((u32)(shdwPal << 24) >> 16)
| ((u32)(bgPal << 24) >> 24)
);
}

struct UnkStruct_02002C14_sub
{
const char buf[0x80];
Expand Down Expand Up @@ -41,7 +32,7 @@ u32 sub_02002E14(u32 param0, struct String *str, u32 param2);
s32 GetFontAttribute(u8 fontId, s32 attr);
void LoadFontPal0(enum GFPalLoadLocation location, enum GFPalSlotOffset palSlotOffset, HeapID heapId);
void LoadFontPal1(enum GFPalLoadLocation location, enum GFPalSlotOffset palSlotOffset, HeapID heapId);
s32 sub_02002F08(u32 param0, struct String *str, u32 param2);
u32 FontID_String_GetWidthMultiline(u32 param0, struct String *str, u32 param2);
u32 sub_02002F40(u32 param0, struct String *str, u32 param2, u32 param3);
u32 sub_02002F58(const u16 *str);
u32 sub_02002F90(struct String *str);
Expand Down
5 changes: 5 additions & 0 deletions include/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
#include "global.h"
#include "bg_window.h"

#define MAKE_TEXT_COLOR(fg, sh, bg) ((((fg) & 0xFF) << 16) | (((sh) & 0xFF) << 8) | (((bg) & 0xFF) << 0))

#define TEXT_SPEED_INSTANT 0 // Transfers to VRAM
#define TEXT_SPEED_NOTRANSFER 0xFF // Defers VRAM transfer

union StrbufForPrint
{
struct String * wrapped;
Expand Down

0 comments on commit 3ede75f

Please sign in to comment.