pokeemerald/src/braille.c

213 lines
9.4 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"
2021-10-31 06:44:18 +01:00
// This file handles the braille font.
// For printing braille messages, see ScrCmd_braillemessage
2018-08-26 15:27:06 +02:00
ALIGNED(4)
2021-11-14 15:55:30 +01:00
static const u8 sScrollDistances[] = {
[OPTIONS_TEXT_SPEED_SLOW] = 1,
[OPTIONS_TEXT_SPEED_MID] = 2,
[OPTIONS_TEXT_SPEED_FAST] = 4,
};
2021-10-31 06:44:18 +01:00
static const u16 sFont_Braille[] = INCBIN_U16("graphics/fonts/braille.fwjpnfont");
2017-09-22 05:43:13 +02:00
2021-10-30 22:47:37 +02:00
static void DecompressGlyph_Braille(u16);
2017-09-22 05:43:13 +02:00
2021-10-30 22:47:37 +02:00
u16 FontFunc_Braille(struct TextPrinter *textPrinter)
2017-09-22 05:43:13 +02:00
{
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 RENDER_STATE_HANDLE_CHAR:
if (JOY_HELD(A_BUTTON | B_BUTTON) && subStruct->hasPrintBeenSpedUp)
{
textPrinter->delayCounter = 0;
}
if (textPrinter->delayCounter && textPrinter->textSpeed)
{
textPrinter->delayCounter --;
if (gTextFlags.canABSpeedUpPrint && JOY_NEW(A_BUTTON | B_BUTTON))
2017-09-22 05:43:13 +02:00
{
subStruct->hasPrintBeenSpedUp = TRUE;
2017-09-22 05:43:13 +02:00
textPrinter->delayCounter = 0;
}
return RENDER_UPDATE;
}
if (gTextFlags.autoScroll)
textPrinter->delayCounter = 3;
else
textPrinter->delayCounter = textPrinter->textSpeed;
char_ = *textPrinter->printerTemplate.currentChar++;
switch (char_)
{
case EOS:
return RENDER_FINISH;
case CHAR_NEWLINE:
textPrinter->printerTemplate.currentX = textPrinter->printerTemplate.x;
textPrinter->printerTemplate.currentY += gFonts[textPrinter->printerTemplate.fontId].maxLetterHeight + textPrinter->printerTemplate.lineSpacing;
return RENDER_REPEAT;
case PLACEHOLDER_BEGIN:
textPrinter->printerTemplate.currentChar++;
return RENDER_REPEAT;
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_)
{
case EXT_CTRL_CODE_COLOR:
textPrinter->printerTemplate.fgColor = *textPrinter->printerTemplate.currentChar++;
GenerateFontHalfRowLookupTable(textPrinter->printerTemplate.fgColor, textPrinter->printerTemplate.bgColor, textPrinter->printerTemplate.shadowColor);
return RENDER_REPEAT;
case EXT_CTRL_CODE_HIGHLIGHT:
textPrinter->printerTemplate.bgColor = *textPrinter->printerTemplate.currentChar++;
GenerateFontHalfRowLookupTable(textPrinter->printerTemplate.fgColor, textPrinter->printerTemplate.bgColor, textPrinter->printerTemplate.shadowColor);
return RENDER_REPEAT;
case EXT_CTRL_CODE_SHADOW:
textPrinter->printerTemplate.shadowColor = *textPrinter->printerTemplate.currentChar++;
GenerateFontHalfRowLookupTable(textPrinter->printerTemplate.fgColor, textPrinter->printerTemplate.bgColor, textPrinter->printerTemplate.shadowColor);
return RENDER_REPEAT;
case EXT_CTRL_CODE_COLOR_HIGHLIGHT_SHADOW:
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
GenerateFontHalfRowLookupTable(textPrinter->printerTemplate.fgColor, textPrinter->printerTemplate.bgColor, textPrinter->printerTemplate.shadowColor);
return RENDER_REPEAT;
case EXT_CTRL_CODE_PALETTE:
textPrinter->printerTemplate.currentChar++;
return RENDER_REPEAT;
case EXT_CTRL_CODE_FONT:
subStruct->fontId = *textPrinter->printerTemplate.currentChar;
textPrinter->printerTemplate.currentChar++;
return RENDER_REPEAT;
2022-11-24 03:13:00 +01:00
case EXT_CTRL_CODE_RESET_FONT:
return RENDER_REPEAT;
case EXT_CTRL_CODE_PAUSE:
textPrinter->delayCounter = *textPrinter->printerTemplate.currentChar++;
textPrinter->state = RENDER_STATE_PAUSE;
return RENDER_REPEAT;
case EXT_CTRL_CODE_PAUSE_UNTIL_PRESS:
textPrinter->state = RENDER_STATE_WAIT;
if (gTextFlags.autoScroll)
subStruct->autoScrollDelay = 0;
return RENDER_UPDATE;
case EXT_CTRL_CODE_WAIT_SE:
textPrinter->state = RENDER_STATE_WAIT_SE;
return RENDER_UPDATE;
case EXT_CTRL_CODE_PLAY_BGM:
case EXT_CTRL_CODE_PLAY_SE:
textPrinter->printerTemplate.currentChar += 2;
return RENDER_REPEAT;
case EXT_CTRL_CODE_ESCAPE:
char_ = *++textPrinter->printerTemplate.currentChar;
break;
2022-11-24 03:13:00 +01:00
case EXT_CTRL_CODE_SHIFT_RIGHT:
textPrinter->printerTemplate.currentX = textPrinter->printerTemplate.x + *textPrinter->printerTemplate.currentChar++;
return RENDER_REPEAT;
case EXT_CTRL_CODE_SHIFT_DOWN:
textPrinter->printerTemplate.currentY = textPrinter->printerTemplate.y + *textPrinter->printerTemplate.currentChar++;
return RENDER_REPEAT;
case EXT_CTRL_CODE_FILL_WINDOW:
FillWindowPixelBuffer(textPrinter->printerTemplate.windowId, PIXEL_FILL(textPrinter->printerTemplate.bgColor));
return RENDER_REPEAT;
2017-09-22 05:43:13 +02:00
}
break;
case CHAR_PROMPT_CLEAR:
textPrinter->state = RENDER_STATE_CLEAR;
TextPrinterInitDownArrowCounters(textPrinter);
return RENDER_UPDATE;
case CHAR_PROMPT_SCROLL:
textPrinter->state = RENDER_STATE_SCROLL_START;
TextPrinterInitDownArrowCounters(textPrinter);
return RENDER_UPDATE;
case CHAR_EXTRA_SYMBOL:
char_ = *textPrinter->printerTemplate.currentChar++| 0x100;
break;
case CHAR_KEYPAD_ICON:
textPrinter->printerTemplate.currentChar++;
return RENDER_PRINT;
}
DecompressGlyph_Braille(char_);
CopyGlyphToWindow(textPrinter);
textPrinter->printerTemplate.currentX += gCurGlyph.width + textPrinter->printerTemplate.letterSpacing;
return RENDER_PRINT;
case RENDER_STATE_WAIT:
if (TextPrinterWait(textPrinter))
textPrinter->state = RENDER_STATE_HANDLE_CHAR;
return RENDER_UPDATE;
case RENDER_STATE_CLEAR:
if (TextPrinterWaitWithDownArrow(textPrinter))
{
FillWindowPixelBuffer(textPrinter->printerTemplate.windowId, PIXEL_FILL(textPrinter->printerTemplate.bgColor));
textPrinter->printerTemplate.currentX = textPrinter->printerTemplate.x;
textPrinter->printerTemplate.currentY = textPrinter->printerTemplate.y;
textPrinter->state = RENDER_STATE_HANDLE_CHAR;
}
return RENDER_UPDATE;
case RENDER_STATE_SCROLL_START:
if (TextPrinterWaitWithDownArrow(textPrinter))
{
TextPrinterClearDownArrow(textPrinter);
textPrinter->scrollDistance = gFonts[textPrinter->printerTemplate.fontId].maxLetterHeight + textPrinter->printerTemplate.lineSpacing;
textPrinter->printerTemplate.currentX = textPrinter->printerTemplate.x;
textPrinter->state = RENDER_STATE_SCROLL;
}
return RENDER_UPDATE;
case RENDER_STATE_SCROLL:
if (textPrinter->scrollDistance)
{
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));
textPrinter->scrollDistance = 0;
2017-09-22 05:43:13 +02:00
}
else
{
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
}
CopyWindowToVram(textPrinter->printerTemplate.windowId, COPYWIN_GFX);
}
else
{
textPrinter->state = RENDER_STATE_HANDLE_CHAR;
}
return RENDER_UPDATE;
case RENDER_STATE_WAIT_SE:
if (!IsSEPlaying())
textPrinter->state = RENDER_STATE_HANDLE_CHAR;
return RENDER_UPDATE;
case RENDER_STATE_PAUSE:
if (textPrinter->delayCounter)
textPrinter->delayCounter --;
else
textPrinter->state = RENDER_STATE_HANDLE_CHAR;
return RENDER_UPDATE;
2017-09-22 05:43:13 +02:00
}
return RENDER_FINISH;
2017-09-22 05:43:13 +02:00
}
2017-09-22 06:01:07 +02:00
2021-10-30 22:47:37 +02:00
static void DecompressGlyph_Braille(u16 glyph)
2017-09-22 06:01:07 +02:00
{
2021-10-30 22:47:37 +02:00
const u16 *glyphs = sFont_Braille + 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);
2021-10-30 22:47:37 +02:00
gCurGlyph.width = 16;
gCurGlyph.height = 16;
2017-09-22 06:01:07 +02:00
}
2021-10-30 22:47:37 +02:00
u32 GetGlyphWidth_Braille(u16 glyphId, bool32 isJapanese)
2017-09-22 06:01:07 +02:00
{
2021-10-30 22:47:37 +02:00
return 16;
2017-09-22 06:01:07 +02:00
}