From c02854b2f79d987db04073b42f30ce55783750d8 Mon Sep 17 00:00:00 2001 From: Greenphx9 <55181320+Greenphx9@users.noreply.github.com> Date: Mon, 13 Jan 2025 01:23:19 +1100 Subject: [PATCH] FRLG Down Arrow Finally able to impl due to Cawt's PR (https://github.com/pret/pokefirered/pull/682), still no clue how the code before works --- graphics/fonts/down_arrow.png | Bin 156 -> 0 bytes graphics/fonts/down_arrow_3.png | Bin 0 -> 159 bytes graphics/fonts/down_arrow_4.png | Bin 0 -> 160 bytes graphics/fonts/down_arrows.png | Bin 0 -> 237 bytes src/text.c | 132 +++++++++++++++++++++++++++----- 5 files changed, 114 insertions(+), 18 deletions(-) delete mode 100644 graphics/fonts/down_arrow.png create mode 100644 graphics/fonts/down_arrow_3.png create mode 100644 graphics/fonts/down_arrow_4.png create mode 100644 graphics/fonts/down_arrows.png diff --git a/graphics/fonts/down_arrow.png b/graphics/fonts/down_arrow.png deleted file mode 100644 index 5b6c7e7bdd2fc5d4cc51eb5ce2001089defafcf1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 156 zcmeAS@N?(olHy`uVBq!ia0vp^96)Tq!VDzuai~>*H~~H(uEl4U{Qv(yDJkjd)w9ny zIR5V~R+z&v<=Yg)ptDPkegjH9d-n`TGW?&zaCWa(@sd~9*D(V1s(ZRPhH%VGPB_3i zW6G2%5;J0A=1kyV6BTD&&?D>-$GF_jCgA`tD+BXlZp}5WO(8%n44$rjF6*2UngCbb BI#~b! diff --git a/graphics/fonts/down_arrow_3.png b/graphics/fonts/down_arrow_3.png new file mode 100644 index 0000000000000000000000000000000000000000..6345eacfb74c48fd37e37ca09f3a8d3c7eb47c6c GIT binary patch literal 159 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPFP2=EDU{SO97Nl90)o_)r_@qcfz z!W@n%-=-J_on3PD8&DM*IQC=j51^2ir;B3<$IRq}1H3T}2RM%eFd9v9;89!9z{Kq0 m!MUh|Q|rKi1ue%l7BMnxvu8;>Xd&VSGRV`_&t;ucLK6UC^D>73 literal 0 HcmV?d00001 diff --git a/graphics/fonts/down_arrow_4.png b/graphics/fonts/down_arrow_4.png new file mode 100644 index 0000000000000000000000000000000000000000..b6cba25f36a8191712007f802834740aebf7b375 GIT binary patch literal 160 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPFP2=EDU{SO97Nl90)o_)r_@qcfz z!W@n%-=-J_on3PD8&DM*IQC=j51^2?r;B3<$IRq}1H4lj9E6X|U`aW{VrbFGBrKue nWUSa_v5<*}$M~a!s|f>x=0Dbtlk`Q>Kqh&*`njxgN@xNASoSdL literal 0 HcmV?d00001 diff --git a/graphics/fonts/down_arrows.png b/graphics/fonts/down_arrows.png new file mode 100644 index 0000000000000000000000000000000000000000..b89fa6bfe9bbb0eec03ff8bfc984610c004f8b7f GIT binary patch literal 237 zcmeAS@N?(olHy`uVBq!ia0vp^4L~fw!3-o{wzcm9QjEnx?oJHr&dIz4ats1|LR|lY zK~hrE)vITpad749h@rwT1``V3do(mj>UU(K?s4bo_aYy~jxBs%fW?J7>VtH$t RyyzClC7!N+F6*2UngEj^U!wp3 literal 0 HcmV?d00001 diff --git a/src/text.c b/src/text.c index 2de0bab933fd..821ad6c8c0b9 100644 --- a/src/text.c +++ b/src/text.c @@ -13,6 +13,14 @@ #include "dynamic_placeholder_text_util.h" #include "fonts.h" +#define TAG_CURSOR 0x8000 + +#define CURSOR_DELAY 8 + +#define DARK_DOWN_ARROW_OFFSET 256 + +extern const struct OamData gOamData_AffineOff_ObjNormal_16x16; + static u16 RenderText(struct TextPrinter *); static u32 RenderFont(struct TextPrinter *); static u16 FontFunc_Small(struct TextPrinter *); @@ -47,6 +55,7 @@ static u32 GetGlyphWidth_Narrower(u16, bool32); static u32 GetGlyphWidth_SmallNarrower(u16, bool32); static u32 GetGlyphWidth_ShortNarrow(u16, bool32); static u32 GetGlyphWidth_ShortNarrower(u16, bool32); +static void SpriteCB_TextCursor(struct Sprite *sprite); static EWRAM_DATA struct TextPrinter sTempTextPrinter = {0}; static EWRAM_DATA struct TextPrinter sTextPrinters[WINDOWS_MAX] = {0}; @@ -81,11 +90,10 @@ static const u8 sFontHalfRowOffsets[] = 0x00, 0x01, 0x02, 0x00, 0x03, 0x04, 0x05, 0x03, 0x06, 0x07, 0x08, 0x06, 0x00, 0x01, 0x02, 0x00 }; -static const u8 sDownArrowTiles[] = INCBIN_U8("graphics/fonts/down_arrow.4bpp"); -static const u8 sDarkDownArrowTiles[] = INCBIN_U8("graphics/fonts/down_arrow_alt.4bpp"); -static const u8 sUnusedFRLGBlankedDownArrow[] = INCBIN_U8("graphics/fonts/unused_frlg_blanked_down_arrow.4bpp"); -static const u8 sUnusedFRLGDownArrow[] = INCBIN_U8("graphics/fonts/unused_frlg_down_arrow.4bpp"); -static const u8 sDownArrowYCoords[] = { 0, 1, 2, 1 }; +static const u8 sDownArrowTiles[] = INCBIN_U8("graphics/fonts/down_arrows.4bpp"); +static const u8 sDoubleArrowTiles1[] = INCBIN_U8("graphics/fonts/down_arrow_3.4bpp"); +static const u8 sDoubleArrowTiles2[] = INCBIN_U8("graphics/fonts/down_arrow_4.4bpp"); +static const u8 sDownArrowYCoords[] = { 0, 16, 32, 16 }; static const u8 sWindowVerticalScrollSpeeds[] = { [OPTIONS_TEXT_SPEED_SLOW] = 1, [OPTIONS_TEXT_SPEED_MID] = 2, @@ -110,6 +118,30 @@ static const struct GlyphWidthFunc sGlyphWidthFuncs[] = { FONT_BW_SUMMARY_SCREEN, GetGlyphWidth_Short }, }; +static const struct SpriteSheet sSpriteSheets_TextCursor[] = +{ + {sDoubleArrowTiles1, sizeof(sDoubleArrowTiles1), TAG_CURSOR}, + {sDoubleArrowTiles2, sizeof(sDoubleArrowTiles2), TAG_CURSOR}, + {NULL} +}; + +static const struct SpritePalette sSpritePalettes_TextCursor[] = +{ + {gStandardMenuPalette, TAG_CURSOR}, + {NULL} +}; + +static const struct SpriteTemplate sSpriteTemplate_TextCursor = +{ + .tileTag = TAG_CURSOR, + .paletteTag = TAG_CURSOR, + .oam = &gOamData_AffineOff_ObjNormal_16x16, + .anims = gDummySpriteAnimTable, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCB_TextCursor, +}; + struct { u16 tileOffset; @@ -936,8 +968,8 @@ void TextPrinterDrawDownArrow(struct TextPrinter *textPrinter) textPrinter->printerTemplate.bgColor << 4 | textPrinter->printerTemplate.bgColor, textPrinter->printerTemplate.currentX, textPrinter->printerTemplate.currentY, - 8, - 16); + 10, + 12); switch (gTextFlags.useAlternateDownArrow) { @@ -946,21 +978,21 @@ void TextPrinterDrawDownArrow(struct TextPrinter *textPrinter) arrowTiles = sDownArrowTiles; break; case TRUE: - arrowTiles = sDarkDownArrowTiles; + arrowTiles = &sDownArrowTiles[DARK_DOWN_ARROW_OFFSET]; break; } BlitBitmapRectToWindow( textPrinter->printerTemplate.windowId, arrowTiles, - 0, sDownArrowYCoords[subStruct->downArrowYPosIdx], - 8, - 16, + 0, + 0x80, + 0x10, textPrinter->printerTemplate.currentX, textPrinter->printerTemplate.currentY, - 8, - 16); + 10, + 12); CopyWindowToVram(textPrinter->printerTemplate.windowId, COPYWIN_GFX); subStruct->downArrowDelay = 8; @@ -1051,7 +1083,7 @@ void DrawDownArrow(u8 windowId, u16 x, u16 y, u8 bgColor, bool32 drawArrow, u8 * } else { - FillWindowPixelRect(windowId, (bgColor << 4) | bgColor, x, y, 0x8, 0x10); + FillWindowPixelRect(windowId, (bgColor << 4) | bgColor, x, y, 10, 12); if (drawArrow == 0) { switch (gTextFlags.useAlternateDownArrow) @@ -1061,13 +1093,23 @@ void DrawDownArrow(u8 windowId, u16 x, u16 y, u8 bgColor, bool32 drawArrow, u8 * arrowTiles = sDownArrowTiles; break; case TRUE: - arrowTiles = sDarkDownArrowTiles; + arrowTiles = &sDownArrowTiles[DARK_DOWN_ARROW_OFFSET]; break; } - BlitBitmapRectToWindow(windowId, arrowTiles, 0, sDownArrowYCoords[*yCoordIndex & 3], 8, 16, x, y - 2, 8, 16); - CopyWindowToVram(windowId, COPYWIN_GFX); - *counter = 8; + BlitBitmapRectToWindow( + windowId, + arrowTiles, + sDownArrowYCoords[*yCoordIndex & 3], + 0, + 0x80, + 0x10, + x, + y, + 10, + 12); + CopyWindowToVram(windowId, 0x2); + *counter = CURSOR_DELAY; ++*yCoordIndex; } } @@ -2333,3 +2375,57 @@ u8 *WrapFontIdToFit(u8 *start, u8 *end, u32 fontId, u32 width) return end; } } + +#define sDelay data[0] +#define sState data[1] + +static void SpriteCB_TextCursor(struct Sprite *sprite) +{ + if (sprite->sDelay) + { + sprite->sDelay--; + } + else + { + sprite->sDelay = CURSOR_DELAY; + switch(sprite->sState) + { + case 0: + sprite->y2 = 0; + break; + case 1: + sprite->y2 = 1; + break; + case 2: + sprite->y2 = 2; + break; + case 3: + sprite->y2 = 1; + sprite->sState = 0; + return; + } + sprite->sState++; + } +} + +u8 CreateTextCursorSprite(u8 sheetId, u16 x, u16 y, u8 priority, u8 subpriority) +{ + u8 spriteId; + LoadSpriteSheet(&sSpriteSheets_TextCursor[sheetId & 1]); + LoadSpritePalette(&sSpritePalettes_TextCursor[0]); + spriteId = CreateSprite(&sSpriteTemplate_TextCursor, x + 3, y + 4, subpriority); + gSprites[spriteId].oam.priority = (priority & 3); + gSprites[spriteId].oam.matrixNum = 0; + gSprites[spriteId].sDelay = CURSOR_DELAY; + return spriteId; +} + +void DestroyTextCursorSprite(u8 spriteId) +{ + DestroySprite(&gSprites[spriteId]); + FreeSpriteTilesByTag(TAG_CURSOR); + FreeSpritePaletteByTag(TAG_CURSOR); +} + +#undef sDelay +#undef sState \ No newline at end of file