real match RenderText

This commit is contained in:
jiangzhengwenjz
2019-08-30 03:05:21 +08:00
parent 6c0fd9884c
commit a26299645a
4 changed files with 449 additions and 929 deletions
+25 -23
View File
@@ -83,7 +83,16 @@
#define TEXT_COLOR_DARK_GREY 0x2
// battle placeholders are located in battle_message.h
#define EXT_CTRL_CODE_COLOR 0x1
#define EXT_CTRL_CODE_HIGHLIGHT 0x2
#define EXT_CTRL_CODE_SHADOW 0x3
//
#define EXT_CTRL_CODE_UNKNOWN_7 0x7
//
#define EXT_CTRL_CODE_CLEAR 0x11
//
#define EXT_CTRL_CODE_CLEAR_TO 0x13
#define EXT_CTRL_CODE_MIN_LETTER_SPACING 0x14
#define EXT_CTRL_CODE_JPN 0x15
#define EXT_CTRL_CODE_ENG 0x16
@@ -105,18 +114,13 @@ enum
struct TextPrinterSubStruct
{
u8 font_type:4; // 0x14
u8 font_type_upper:1;
u8 glyphId:4; // 0x14
bool8 hasPrintBeenSpedUp:1;
u8 font_type_5:3;
u8 field_1:5;
u8 field_1_upmid:2;
u8 field_1_top:1;
u8 frames_visible_counter;
u8 field_3;
u8 field_4; // 0x18
u8 field_5;
u8 field_6;
u8 active;
u8 downArrowDelay:5;
u8 downArrowYPosIdx:2;
u8 hasGlyphIdBeenSet:1;
u8 autoScrollDelay;
};
struct TextPrinterTemplate // TODO: Better name
@@ -138,18 +142,15 @@ struct TextPrinterTemplate // TODO: Better name
struct TextPrinter
{
struct TextPrinterTemplate subPrinter;
struct TextPrinterTemplate printerTemplate;
void (*callback)(struct TextPrinterTemplate *, u16); // 0x10
union {
union __attribute__((packed)) {
struct TextPrinterSubStruct sub;
u8 sub_fields[8];
} sub_union;
u8 fields[7];
} subUnion;
u8 active;
u8 state; // 0x1C
u8 text_speed;
u8 textSpeed;
u8 delayCounter;
u8 scrollDistance;
u8 minLetterSpacing; // 0x20
@@ -173,13 +174,13 @@ extern const struct FontInfo *gFonts;
struct GlyphWidthFunc
{
u32 font_id;
u32 fontId;
s32 (*func)(u16 glyphId, bool32 isJapanese);
};
struct KeypadIcon
{
u16 tile_offset;
u16 tileOffset;
u8 width;
u8 height;
};
@@ -262,5 +263,6 @@ s32 GetGlyphWidthFont5(u16 glyphId, bool32 isJapanese);
void sub_80062B0(struct Sprite *sprite);
u8 CreateTextCursorSpriteForOakSpeech(u8 sheetId, u16 x, u16 y, u8 priority, u8 subpriority);
void sub_8006398(u8 spriteId);
s32 GetGlyphWidthFont6(u16 font_type, bool32 isJapanese);
#endif // GUARD_TEXT_H
+43 -43
View File
@@ -17,20 +17,20 @@ u16 Font6Func(struct TextPrinter *textPrinter)
u16 char_;
struct TextPrinterSubStruct *sub;
sub = &textPrinter->sub_union.sub;
sub = &textPrinter->subUnion.sub;
switch (textPrinter->state)
{
case 0:
if (gMain.heldKeys & (A_BUTTON | B_BUTTON) && sub->font_type_upper)
if (gMain.heldKeys & (A_BUTTON | B_BUTTON) && sub->hasPrintBeenSpedUp)
{
textPrinter->delayCounter = 0;
}
if (textPrinter->delayCounter && textPrinter->text_speed)
if (textPrinter->delayCounter && textPrinter->textSpeed)
{
textPrinter->delayCounter --;
if (gTextFlags.canABSpeedUpPrint && gMain.newKeys & (A_BUTTON | B_BUTTON))
{
sub->font_type_upper = TRUE;
sub->hasPrintBeenSpedUp = TRUE;
textPrinter->delayCounter = 0;
}
return 3;
@@ -41,62 +41,62 @@ u16 Font6Func(struct TextPrinter *textPrinter)
}
else
{
textPrinter->delayCounter = textPrinter->text_speed;
textPrinter->delayCounter = textPrinter->textSpeed;
}
char_ = *textPrinter->subPrinter.currentChar++;
char_ = *textPrinter->printerTemplate.currentChar++;
switch (char_)
{
case EOS:
return 1;
case CHAR_NEWLINE:
textPrinter->subPrinter.currentX = textPrinter->subPrinter.x;
textPrinter->subPrinter.currentY += gFonts[textPrinter->subPrinter.fontId].maxLetterHeight + textPrinter->subPrinter.lineSpacing;
textPrinter->printerTemplate.currentX = textPrinter->printerTemplate.x;
textPrinter->printerTemplate.currentY += gFonts[textPrinter->printerTemplate.fontId].maxLetterHeight + textPrinter->printerTemplate.lineSpacing;
return 2;
case PLACEHOLDER_BEGIN:
textPrinter->subPrinter.currentChar++;
textPrinter->printerTemplate.currentChar++;
return 2;
case EXT_CTRL_CODE_BEGIN:
char_ = *textPrinter->subPrinter.currentChar++;
char_ = *textPrinter->printerTemplate.currentChar++;
switch (char_)
{
case 1:
textPrinter->subPrinter.fgColor = *textPrinter->subPrinter.currentChar++;
GenerateFontHalfRowLookupTable(textPrinter->subPrinter.fgColor, textPrinter->subPrinter.bgColor, textPrinter->subPrinter.shadowColor);
textPrinter->printerTemplate.fgColor = *textPrinter->printerTemplate.currentChar++;
GenerateFontHalfRowLookupTable(textPrinter->printerTemplate.fgColor, textPrinter->printerTemplate.bgColor, textPrinter->printerTemplate.shadowColor);
return 2;
case 2:
textPrinter->subPrinter.bgColor = *textPrinter->subPrinter.currentChar++;
GenerateFontHalfRowLookupTable(textPrinter->subPrinter.fgColor, textPrinter->subPrinter.bgColor, textPrinter->subPrinter.shadowColor);
textPrinter->printerTemplate.bgColor = *textPrinter->printerTemplate.currentChar++;
GenerateFontHalfRowLookupTable(textPrinter->printerTemplate.fgColor, textPrinter->printerTemplate.bgColor, textPrinter->printerTemplate.shadowColor);
return 2;
case 3:
textPrinter->subPrinter.shadowColor = *textPrinter->subPrinter.currentChar++;
GenerateFontHalfRowLookupTable(textPrinter->subPrinter.fgColor, textPrinter->subPrinter.bgColor, textPrinter->subPrinter.shadowColor);
textPrinter->printerTemplate.shadowColor = *textPrinter->printerTemplate.currentChar++;
GenerateFontHalfRowLookupTable(textPrinter->printerTemplate.fgColor, textPrinter->printerTemplate.bgColor, textPrinter->printerTemplate.shadowColor);
return 2;
case 4:
textPrinter->subPrinter.fgColor = *textPrinter->subPrinter.currentChar;
textPrinter->subPrinter.bgColor = *++textPrinter->subPrinter.currentChar;
textPrinter->subPrinter.shadowColor = *++textPrinter->subPrinter.currentChar;
textPrinter->subPrinter.currentChar++;
textPrinter->printerTemplate.fgColor = *textPrinter->printerTemplate.currentChar;
textPrinter->printerTemplate.bgColor = *++textPrinter->printerTemplate.currentChar;
textPrinter->printerTemplate.shadowColor = *++textPrinter->printerTemplate.currentChar;
textPrinter->printerTemplate.currentChar++;
GenerateFontHalfRowLookupTable(textPrinter->subPrinter.fgColor, textPrinter->subPrinter.bgColor, textPrinter->subPrinter.shadowColor);
GenerateFontHalfRowLookupTable(textPrinter->printerTemplate.fgColor, textPrinter->printerTemplate.bgColor, textPrinter->printerTemplate.shadowColor);
return 2;
case 5:
textPrinter->subPrinter.currentChar++;
textPrinter->printerTemplate.currentChar++;
return 2;
case 6:
sub->font_type = *textPrinter->subPrinter.currentChar;
textPrinter->subPrinter.currentChar++;
sub->glyphId = *textPrinter->printerTemplate.currentChar;
textPrinter->printerTemplate.currentChar++;
return 2;
case 7:
return 2;
case 8:
textPrinter->delayCounter = *textPrinter->subPrinter.currentChar++;
textPrinter->delayCounter = *textPrinter->printerTemplate.currentChar++;
textPrinter->state = 6;
return 2;
case 9:
textPrinter->state = 1;
if (gTextFlags.autoScroll)
{
sub->frames_visible_counter = 0;
sub->autoScrollDelay = 0;
}
return 3;
case 10:
@@ -104,19 +104,19 @@ u16 Font6Func(struct TextPrinter *textPrinter)
return 3;
case 11:
case 16:
textPrinter->subPrinter.currentChar += 2;
textPrinter->printerTemplate.currentChar += 2;
return 2;
case 12:
char_ = *++textPrinter->subPrinter.currentChar;
char_ = *++textPrinter->printerTemplate.currentChar;
break;
case 13:
textPrinter->subPrinter.currentX = textPrinter->subPrinter.x + *textPrinter->subPrinter.currentChar++;
textPrinter->printerTemplate.currentX = textPrinter->printerTemplate.x + *textPrinter->printerTemplate.currentChar++;
return 2;
case 14:
textPrinter->subPrinter.currentY = textPrinter->subPrinter.y + *textPrinter->subPrinter.currentChar++;
textPrinter->printerTemplate.currentY = textPrinter->printerTemplate.y + *textPrinter->printerTemplate.currentChar++;
return 2;
case 15:
FillWindowPixelBuffer(textPrinter->subPrinter.windowId, PIXEL_FILL(textPrinter->subPrinter.bgColor));
FillWindowPixelBuffer(textPrinter->printerTemplate.windowId, PIXEL_FILL(textPrinter->printerTemplate.bgColor));
return 2;
}
break;
@@ -129,15 +129,15 @@ u16 Font6Func(struct TextPrinter *textPrinter)
TextPrinterInitDownArrowCounters(textPrinter);
return 3;
case 0xF9:
char_ = *textPrinter->subPrinter.currentChar++| 0x100;
char_ = *textPrinter->printerTemplate.currentChar++| 0x100;
break;
case 0xF8:
textPrinter->subPrinter.currentChar++;
textPrinter->printerTemplate.currentChar++;
return 0;
}
DecompressGlyphFont6(char_);
CopyGlyphToWindow(textPrinter);
textPrinter->subPrinter.currentX += gGlyphInfo[0x80] + textPrinter->subPrinter.letterSpacing;
textPrinter->printerTemplate.currentX += gGlyphInfo[0x80] + textPrinter->printerTemplate.letterSpacing;
return 0;
case 1:
if (TextPrinterWait(textPrinter))
@@ -148,9 +148,9 @@ u16 Font6Func(struct TextPrinter *textPrinter)
case 2:
if (TextPrinterWaitWithDownArrow(textPrinter))
{
FillWindowPixelBuffer(textPrinter->subPrinter.windowId, PIXEL_FILL(textPrinter->subPrinter.bgColor));
textPrinter->subPrinter.currentX = textPrinter->subPrinter.x;
textPrinter->subPrinter.currentY = textPrinter->subPrinter.y;
FillWindowPixelBuffer(textPrinter->printerTemplate.windowId, PIXEL_FILL(textPrinter->printerTemplate.bgColor));
textPrinter->printerTemplate.currentX = textPrinter->printerTemplate.x;
textPrinter->printerTemplate.currentY = textPrinter->printerTemplate.y;
textPrinter->state = 0;
}
return 3;
@@ -158,8 +158,8 @@ u16 Font6Func(struct TextPrinter *textPrinter)
if (TextPrinterWaitWithDownArrow(textPrinter))
{
TextPrinterClearDownArrow(textPrinter);
textPrinter->scrollDistance = gFonts[textPrinter->subPrinter.fontId].maxLetterHeight + textPrinter->subPrinter.lineSpacing;
textPrinter->subPrinter.currentX = textPrinter->subPrinter.x;
textPrinter->scrollDistance = gFonts[textPrinter->printerTemplate.fontId].maxLetterHeight + textPrinter->printerTemplate.lineSpacing;
textPrinter->printerTemplate.currentX = textPrinter->printerTemplate.x;
textPrinter->state = 4;
}
return 3;
@@ -168,15 +168,15 @@ u16 Font6Func(struct TextPrinter *textPrinter)
{
if (textPrinter->scrollDistance < gUnknown_846FB08[gSaveBlock2Ptr->optionsTextSpeed])
{
ScrollWindow(textPrinter->subPrinter.windowId, 0, textPrinter->scrollDistance, PIXEL_FILL(textPrinter->subPrinter.bgColor));
ScrollWindow(textPrinter->printerTemplate.windowId, 0, textPrinter->scrollDistance, PIXEL_FILL(textPrinter->printerTemplate.bgColor));
textPrinter->scrollDistance = 0;
}
else
{
ScrollWindow(textPrinter->subPrinter.windowId, 0, gUnknown_846FB08[gSaveBlock2Ptr->optionsTextSpeed], PIXEL_FILL(textPrinter->subPrinter.bgColor));
ScrollWindow(textPrinter->printerTemplate.windowId, 0, gUnknown_846FB08[gSaveBlock2Ptr->optionsTextSpeed], PIXEL_FILL(textPrinter->printerTemplate.bgColor));
textPrinter->scrollDistance -= gUnknown_846FB08[gSaveBlock2Ptr->optionsTextSpeed];
}
CopyWindowToVram(textPrinter->subPrinter.windowId, 2);
CopyWindowToVram(textPrinter->printerTemplate.windowId, 2);
}
else
{
@@ -216,7 +216,7 @@ static void DecompressGlyphFont6(u16 glyph)
gGlyphInfo[0x81] = 0x10;
}
u32 GetGlyphWidthFont6(u16 font_type, bool32 isJapanese)
s32 GetGlyphWidthFont6(u16 font_type, bool32 isJapanese)
{
return 0x10;
}
+351 -833
View File
File diff suppressed because it is too large Load Diff
+30 -30
View File
@@ -45,27 +45,27 @@ void DeactivateAllTextPrinters (void)
{
int printer;
for (printer = 0; printer < NUM_TEXT_PRINTERS; ++printer)
sTextPrinters[printer].sub_union.sub.active = 0;
sTextPrinters[printer].active = 0;
}
u16 AddTextPrinterParameterized(u8 windowId, u8 fontId, const u8 *str, u8 x, u8 y, u8 speed, void (*callback)(struct TextPrinterTemplate *, u16))
{
struct TextPrinterTemplate subPrinter;
struct TextPrinterTemplate printerTemplate;
subPrinter.currentChar = str;
subPrinter.windowId = windowId;
subPrinter.fontId = fontId;
subPrinter.x = x;
subPrinter.y = y;
subPrinter.currentX = x;
subPrinter.currentY = y;
subPrinter.letterSpacing = gFonts[fontId].letterSpacing;
subPrinter.lineSpacing = gFonts[fontId].lineSpacing;
subPrinter.unk = gFonts[fontId].unk;
subPrinter.fgColor = gFonts[fontId].fgColor;
subPrinter.bgColor = gFonts[fontId].bgColor;
subPrinter.shadowColor = gFonts[fontId].shadowColor;
return AddTextPrinter(&subPrinter, speed, callback);
printerTemplate.currentChar = str;
printerTemplate.windowId = windowId;
printerTemplate.fontId = fontId;
printerTemplate.x = x;
printerTemplate.y = y;
printerTemplate.currentX = x;
printerTemplate.currentY = y;
printerTemplate.letterSpacing = gFonts[fontId].letterSpacing;
printerTemplate.lineSpacing = gFonts[fontId].lineSpacing;
printerTemplate.unk = gFonts[fontId].unk;
printerTemplate.fgColor = gFonts[fontId].fgColor;
printerTemplate.bgColor = gFonts[fontId].bgColor;
printerTemplate.shadowColor = gFonts[fontId].shadowColor;
return AddTextPrinter(&printerTemplate, speed, callback);
}
bool16 AddTextPrinter(struct TextPrinterTemplate *textSubPrinter, u8 speed, void (*callback)(struct TextPrinterTemplate *, u16))
@@ -76,18 +76,18 @@ bool16 AddTextPrinter(struct TextPrinterTemplate *textSubPrinter, u8 speed, void
if (!gFonts)
return FALSE;
sTempTextPrinter.sub_union.sub.active = 1;
sTempTextPrinter.active = 1;
sTempTextPrinter.state = 0;
sTempTextPrinter.text_speed = speed;
sTempTextPrinter.textSpeed = speed;
sTempTextPrinter.delayCounter = 0;
sTempTextPrinter.scrollDistance = 0;
for (i = 0; i < 7; ++i)
{
sTempTextPrinter.sub_union.sub_fields[i] = 0;
sTempTextPrinter.subUnion.fields[i] = 0;
}
sTempTextPrinter.subPrinter = *textSubPrinter;
sTempTextPrinter.printerTemplate = *textSubPrinter;
sTempTextPrinter.callback = callback;
sTempTextPrinter.minLetterSpacing = 0;
sTempTextPrinter.japanese = 0;
@@ -95,12 +95,12 @@ bool16 AddTextPrinter(struct TextPrinterTemplate *textSubPrinter, u8 speed, void
GenerateFontHalfRowLookupTable(textSubPrinter->fgColor, textSubPrinter->bgColor, textSubPrinter->shadowColor);
if (speed != TEXT_SPEED_FF && speed != 0x0)
{
--sTempTextPrinter.text_speed;
--sTempTextPrinter.textSpeed;
sTextPrinters[textSubPrinter->windowId] = sTempTextPrinter;
}
else
{
sTempTextPrinter.text_speed = 0;
sTempTextPrinter.textSpeed = 0;
for (j = 0; j < 0x400; ++j)
{
if ((u32)RenderFont(&sTempTextPrinter) == 1)
@@ -108,8 +108,8 @@ bool16 AddTextPrinter(struct TextPrinterTemplate *textSubPrinter, u8 speed, void
}
if (speed != TEXT_SPEED_FF)
CopyWindowToVram(sTempTextPrinter.subPrinter.windowId, 2);
sTextPrinters[textSubPrinter->windowId].sub_union.sub.active = 0;
CopyWindowToVram(sTempTextPrinter.printerTemplate.windowId, 2);
sTextPrinters[textSubPrinter->windowId].active = 0;
}
return TRUE;
}
@@ -121,18 +121,18 @@ void RunTextPrinters(void)
for (i = 0; i < 0x20; ++i)
{
if (sTextPrinters[i].sub_union.sub.active != 0)
if (sTextPrinters[i].active != 0)
{
temp = RenderFont(&sTextPrinters[i]);
switch (temp) {
case 0:
CopyWindowToVram(sTextPrinters[i].subPrinter.windowId, 2);
CopyWindowToVram(sTextPrinters[i].printerTemplate.windowId, 2);
case 3:
if (sTextPrinters[i].callback != 0)
sTextPrinters[i].callback(&sTextPrinters[i].subPrinter, temp);
sTextPrinters[i].callback(&sTextPrinters[i].printerTemplate, temp);
break;
case 1:
sTextPrinters[i].sub_union.sub.active = 0;
sTextPrinters[i].active = 0;
break;
}
}
@@ -141,7 +141,7 @@ void RunTextPrinters(void)
bool16 IsTextPrinterActive(u8 id)
{
return sTextPrinters[id].sub_union.sub.active;
return sTextPrinters[id].active;
}
u32 RenderFont(struct TextPrinter *textPrinter)
@@ -149,7 +149,7 @@ u32 RenderFont(struct TextPrinter *textPrinter)
u32 ret;
while (TRUE)
{
ret = gFonts[textPrinter->subPrinter.fontId].fontFunction(textPrinter);
ret = gFonts[textPrinter->printerTemplate.fontId].fontFunction(textPrinter);
if (ret != 2)
return ret;
}