pokeemerald/src/unk_text_util_2.c

221 lines
9.9 KiB
C
Raw Normal View History

2017-09-22 05:43:13 +02:00
#include "global.h"
#include "main.h"
#include "window.h"
#include "text.h"
#include "sound.h"
2018-08-26 15:27:06 +02:00
ALIGNED(4)
2021-03-29 18:20:00 +02:00
static const u8 sScrollDistances[] = {1, 2, 4};
static const u16 sFont6BrailleGlyphs[] = INCBIN_U16("graphics/fonts/font6.fwjpnfont");
2017-09-22 05:43:13 +02:00
2017-09-22 06:01:07 +02:00
static void DecompressGlyphFont6(u16);
2017-09-22 05:43:13 +02:00
u16 Font6Func(struct TextPrinter *textPrinter)
{
u16 char_;
2020-05-21 04:28:17 +02:00
struct TextPrinterSubStruct *subStruct;
subStruct = (struct TextPrinterSubStruct *)(&textPrinter->subStructFields);
2017-12-17 23:45:27 +01:00
2017-09-22 05:43:13 +02:00
switch (textPrinter->state)
{
case 0:
2020-09-05 03:11:55 +02:00
if (JOY_HELD(A_BUTTON | B_BUTTON) && subStruct->hasPrintBeenSpedUp)
2017-09-22 05:43:13 +02:00
{
textPrinter->delayCounter = 0;
}
2018-11-05 21:42:12 +01:00
if (textPrinter->delayCounter && textPrinter->textSpeed)
2017-09-22 05:43:13 +02:00
{
textPrinter->delayCounter --;
2020-09-05 03:11:55 +02:00
if (gTextFlags.canABSpeedUpPrint && JOY_NEW(A_BUTTON | B_BUTTON))
2017-09-22 05:43:13 +02:00
{
2020-05-21 04:28:17 +02:00
subStruct->hasPrintBeenSpedUp = TRUE;
2017-09-22 05:43:13 +02:00
textPrinter->delayCounter = 0;
}
return 3;
}
2018-11-06 18:30:21 +01:00
if (gTextFlags.autoScroll)
2017-09-22 05:43:13 +02:00
{
textPrinter->delayCounter = 3;
}
else
{
2018-11-05 21:42:12 +01:00
textPrinter->delayCounter = textPrinter->textSpeed;
2017-09-22 05:43:13 +02:00
}
2018-11-06 17:44:48 +01:00
char_ = *textPrinter->printerTemplate.currentChar++;
2017-09-22 05:43:13 +02:00
switch (char_)
{
case EOS:
return 1;
case CHAR_NEWLINE:
2018-11-06 17:44:48 +01:00
textPrinter->printerTemplate.currentX = textPrinter->printerTemplate.x;
textPrinter->printerTemplate.currentY += gFonts[textPrinter->printerTemplate.fontId].maxLetterHeight + textPrinter->printerTemplate.lineSpacing;
2017-09-22 05:43:13 +02:00
return 2;
case PLACEHOLDER_BEGIN:
2018-11-06 17:44:48 +01:00
textPrinter->printerTemplate.currentChar++;
2017-09-22 05:43:13 +02:00
return 2;
case EXT_CTRL_CODE_BEGIN:
2018-11-06 17:44:48 +01:00
char_ = *textPrinter->printerTemplate.currentChar++;
2017-09-22 05:43:13 +02:00
switch (char_)
{
2020-08-11 05:50:49 +02:00
case EXT_CTRL_CODE_COLOR:
2018-11-06 17:44:48 +01:00
textPrinter->printerTemplate.fgColor = *textPrinter->printerTemplate.currentChar++;
GenerateFontHalfRowLookupTable(textPrinter->printerTemplate.fgColor, textPrinter->printerTemplate.bgColor, textPrinter->printerTemplate.shadowColor);
2017-09-22 05:43:13 +02:00
return 2;
2020-08-11 05:50:49 +02:00
case EXT_CTRL_CODE_HIGHLIGHT:
2018-11-06 17:44:48 +01:00
textPrinter->printerTemplate.bgColor = *textPrinter->printerTemplate.currentChar++;
GenerateFontHalfRowLookupTable(textPrinter->printerTemplate.fgColor, textPrinter->printerTemplate.bgColor, textPrinter->printerTemplate.shadowColor);
2017-09-22 05:43:13 +02:00
return 2;
2020-08-11 05:50:49 +02:00
case EXT_CTRL_CODE_SHADOW:
2018-11-06 17:44:48 +01:00
textPrinter->printerTemplate.shadowColor = *textPrinter->printerTemplate.currentChar++;
GenerateFontHalfRowLookupTable(textPrinter->printerTemplate.fgColor, textPrinter->printerTemplate.bgColor, textPrinter->printerTemplate.shadowColor);
2017-09-22 05:43:13 +02:00
return 2;
2020-08-11 05:50:49 +02:00
case EXT_CTRL_CODE_COLOR_HIGHLIGHT_SHADOW:
2018-11-06 17:44:48 +01:00
textPrinter->printerTemplate.fgColor = *textPrinter->printerTemplate.currentChar;
textPrinter->printerTemplate.bgColor = *++textPrinter->printerTemplate.currentChar;
textPrinter->printerTemplate.shadowColor = *++textPrinter->printerTemplate.currentChar;
textPrinter->printerTemplate.currentChar++;
2017-09-22 05:43:13 +02:00
2018-11-06 17:44:48 +01:00
GenerateFontHalfRowLookupTable(textPrinter->printerTemplate.fgColor, textPrinter->printerTemplate.bgColor, textPrinter->printerTemplate.shadowColor);
2017-09-22 05:43:13 +02:00
return 2;
2020-08-11 05:50:49 +02:00
case EXT_CTRL_CODE_PALETTE:
2018-11-06 17:44:48 +01:00
textPrinter->printerTemplate.currentChar++;
2017-09-22 05:43:13 +02:00
return 2;
2020-08-11 05:50:49 +02:00
case EXT_CTRL_CODE_SIZE:
2020-05-21 04:28:17 +02:00
subStruct->glyphId = *textPrinter->printerTemplate.currentChar;
2018-11-06 17:44:48 +01:00
textPrinter->printerTemplate.currentChar++;
2017-09-22 05:43:13 +02:00
return 2;
2020-08-11 05:50:49 +02:00
case EXT_CTRL_CODE_RESET_SIZE:
2017-09-22 05:43:13 +02:00
return 2;
2020-08-11 05:50:49 +02:00
case EXT_CTRL_CODE_PAUSE:
2018-11-06 17:44:48 +01:00
textPrinter->delayCounter = *textPrinter->printerTemplate.currentChar++;
2017-09-22 05:43:13 +02:00
textPrinter->state = 6;
return 2;
2020-08-11 05:50:49 +02:00
case EXT_CTRL_CODE_PAUSE_UNTIL_PRESS:
2017-09-22 05:43:13 +02:00
textPrinter->state = 1;
2018-11-06 18:30:21 +01:00
if (gTextFlags.autoScroll)
2017-09-22 05:43:13 +02:00
{
2020-05-21 04:28:17 +02:00
subStruct->autoScrollDelay = 0;
2017-09-22 05:43:13 +02:00
}
return 3;
2020-08-11 05:50:49 +02:00
case EXT_CTRL_CODE_WAIT_SE:
2017-09-22 05:43:13 +02:00
textPrinter->state = 5;
return 3;
2020-08-11 05:50:49 +02:00
case EXT_CTRL_CODE_PLAY_BGM:
case EXT_CTRL_CODE_PLAY_SE:
2018-11-06 17:44:48 +01:00
textPrinter->printerTemplate.currentChar += 2;
2017-09-22 05:43:13 +02:00
return 2;
2020-08-11 05:50:49 +02:00
case EXT_CTRL_CODE_ESCAPE:
2018-11-06 17:44:48 +01:00
char_ = *++textPrinter->printerTemplate.currentChar;
2017-09-22 05:43:13 +02:00
break;
2020-08-11 05:50:49 +02:00
case EXT_CTRL_CODE_SHIFT_TEXT:
2018-11-06 17:44:48 +01:00
textPrinter->printerTemplate.currentX = textPrinter->printerTemplate.x + *textPrinter->printerTemplate.currentChar++;
2017-09-22 05:43:13 +02:00
return 2;
2020-08-11 05:50:49 +02:00
case EXT_CTRL_CODE_SHIFT_DOWN:
2018-11-06 17:44:48 +01:00
textPrinter->printerTemplate.currentY = textPrinter->printerTemplate.y + *textPrinter->printerTemplate.currentChar++;
2017-09-22 05:43:13 +02:00
return 2;
2020-08-11 05:50:49 +02:00
case EXT_CTRL_CODE_FILL_WINDOW:
FillWindowPixelBuffer(textPrinter->printerTemplate.windowId, PIXEL_FILL(textPrinter->printerTemplate.bgColor));
2017-09-22 05:43:13 +02:00
return 2;
}
break;
case CHAR_PROMPT_CLEAR:
textPrinter->state = 2;
TextPrinterInitDownArrowCounters(textPrinter);
return 3;
case CHAR_PROMPT_SCROLL:
textPrinter->state = 3;
TextPrinterInitDownArrowCounters(textPrinter);
return 3;
2020-08-11 05:50:49 +02:00
case CHAR_EXTRA_SYMBOL:
2018-11-06 17:44:48 +01:00
char_ = *textPrinter->printerTemplate.currentChar++| 0x100;
2017-09-22 05:43:13 +02:00
break;
2020-08-11 05:50:49 +02:00
case CHAR_KEYPAD_ICON:
2018-11-06 17:44:48 +01:00
textPrinter->printerTemplate.currentChar++;
2017-09-22 05:43:13 +02:00
return 0;
}
DecompressGlyphFont6(char_);
CopyGlyphToWindow(textPrinter);
2021-03-29 18:20:00 +02:00
textPrinter->printerTemplate.currentX += gCurGlyph.width + textPrinter->printerTemplate.letterSpacing;
2017-09-22 05:43:13 +02:00
return 0;
case 1:
if (TextPrinterWait(textPrinter))
{
textPrinter->state = 0;
}
return 3;
case 2:
if (TextPrinterWaitWithDownArrow(textPrinter))
{
FillWindowPixelBuffer(textPrinter->printerTemplate.windowId, PIXEL_FILL(textPrinter->printerTemplate.bgColor));
2018-11-06 17:44:48 +01:00
textPrinter->printerTemplate.currentX = textPrinter->printerTemplate.x;
textPrinter->printerTemplate.currentY = textPrinter->printerTemplate.y;
2017-09-22 05:43:13 +02:00
textPrinter->state = 0;
}
return 3;
case 3:
if (TextPrinterWaitWithDownArrow(textPrinter))
{
TextPrinterClearDownArrow(textPrinter);
2018-11-06 17:44:48 +01:00
textPrinter->scrollDistance = gFonts[textPrinter->printerTemplate.fontId].maxLetterHeight + textPrinter->printerTemplate.lineSpacing;
textPrinter->printerTemplate.currentX = textPrinter->printerTemplate.x;
2017-09-22 05:43:13 +02:00
textPrinter->state = 4;
}
return 3;
case 4:
if (textPrinter->scrollDistance)
{
2021-03-29 18:20:00 +02:00
if (textPrinter->scrollDistance < sScrollDistances[gSaveBlock2Ptr->optionsTextSpeed])
2017-09-22 05:43:13 +02:00
{
ScrollWindow(textPrinter->printerTemplate.windowId, 0, textPrinter->scrollDistance, PIXEL_FILL(textPrinter->printerTemplate.bgColor));
2017-09-22 05:43:13 +02:00
textPrinter->scrollDistance = 0;
}
else
{
2021-03-29 18:20:00 +02:00
ScrollWindow(textPrinter->printerTemplate.windowId, 0, sScrollDistances[gSaveBlock2Ptr->optionsTextSpeed], PIXEL_FILL(textPrinter->printerTemplate.bgColor));
textPrinter->scrollDistance -= sScrollDistances[gSaveBlock2Ptr->optionsTextSpeed];
2017-09-22 05:43:13 +02:00
}
2018-11-06 17:44:48 +01:00
CopyWindowToVram(textPrinter->printerTemplate.windowId, 2);
2017-09-22 05:43:13 +02:00
}
else
{
textPrinter->state = 0;
}
return 3;
case 5:
if (!IsSEPlaying())
{
textPrinter->state = 0;
}
return 3;
case 6:
if (textPrinter->delayCounter)
{
textPrinter->delayCounter --;
}
else
{
textPrinter->state = 0;
}
return 3;
}
return 1;
}
2017-09-22 06:01:07 +02:00
static void DecompressGlyphFont6(u16 glyph)
{
const u16 *glyphs;
2017-12-17 23:45:27 +01:00
glyphs = sFont6BrailleGlyphs + 0x100 * (glyph / 8) + 0x10 * (glyph % 8);
2021-03-29 18:20:00 +02:00
DecompressGlyphTile(glyphs, gCurGlyph.gfxBufferTop);
DecompressGlyphTile(glyphs + 0x8, gCurGlyph.gfxBufferTop + 8);
DecompressGlyphTile(glyphs + 0x80, gCurGlyph.gfxBufferBottom);
DecompressGlyphTile(glyphs + 0x88, gCurGlyph.gfxBufferBottom + 8);
gCurGlyph.width = 0x10;
gCurGlyph.height = 0x10;
2017-09-22 06:01:07 +02:00
}
2019-03-02 09:18:08 +01:00
u32 GetGlyphWidthFont6(u16 glyphId, bool32 isJapanese)
2017-09-22 06:01:07 +02:00
{
return 0x10;
}