From 4f60d046ba7a0db37cce28e9fb7dd983fa28863d Mon Sep 17 00:00:00 2001 From: James R Date: Sun, 20 Aug 2023 15:18:26 -0700 Subject: [PATCH] V_DrawTitleCardString, V_TitleCardStringWidth: add 4P font support --- src/hu_stuff.c | 10 +++++++-- src/hu_stuff.h | 3 +++ src/lua_hudlib.c | 8 +++++--- src/lua_hudlib_drawlist.c | 7 +++++-- src/lua_hudlib_drawlist.h | 3 ++- src/st_stuff.c | 8 ++++---- src/v_video.cpp | 43 +++++++++++++++++++++++++++------------ src/v_video.h | 4 ++-- src/y_inter.c | 4 ++-- 9 files changed, 61 insertions(+), 29 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index fd9fa3c97..a32365fb6 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -283,6 +283,12 @@ void HU_Init(void) PR ("GTFN"); REG; + PR ("4GTOL"); + REG; + + PR ("4GTFN"); + REG; + DIG (1); DIM (0, 10); @@ -1874,8 +1880,8 @@ static void HU_DrawTitlecardCEcho(void) *line = '\0'; - w = V_TitleCardStringWidth(echoptr); - V_DrawTitleCardString(BASEVIDWIDTH/2 -w/2, y, echoptr, 0, false, timer, TICRATE*4); + w = V_TitleCardStringWidth(echoptr, false); + V_DrawTitleCardString(BASEVIDWIDTH/2 -w/2, y, echoptr, 0, false, timer, TICRATE*4, false); y += 32; diff --git a/src/hu_stuff.h b/src/hu_stuff.h index 92ecdbc41..ed483c3a6 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -77,6 +77,9 @@ enum X (GTOL), X (GTFN), + X (GTOL4), + X (GTFN4), + X (TALLNUM), X (NIGHTSNUM), X (PINGNUM), diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 5a5583f1a..a95ff78c2 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -948,6 +948,7 @@ static int libd_drawTitleCardString(lua_State *L) boolean rightalign = lua_optboolean(L, 5); INT32 timer = luaL_optinteger(L, 6, 0); INT32 threshold = luaL_optinteger(L, 7, 0); + boolean p4 = lua_optboolean(L, 8); huddrawlist_h list; flags &= ~V_PARAMMASK; // Don't let crashes happen. @@ -958,9 +959,9 @@ static int libd_drawTitleCardString(lua_State *L) lua_pop(L, 1); if (LUA_HUD_IsDrawListValid(list)) - LUA_HUD_AddDrawTitleCardString(list, x, y, flags, str, rightalign, timer, threshold); + LUA_HUD_AddDrawTitleCardString(list, x, y, flags, str, rightalign, timer, threshold, p4); else - V_DrawTitleCardString(x, y, str, flags, rightalign, timer, threshold); + V_DrawTitleCardString(x, y, str, flags, rightalign, timer, threshold, p4); return 0; } @@ -989,9 +990,10 @@ static int libd_drawKartString(lua_State *L) static int libd_titleCardStringWidth(lua_State *L) { const char *str = luaL_checkstring(L, 1); + boolean p4 = lua_optboolean(L, 2); HUDONLY - lua_pushinteger(L, V_TitleCardStringWidth(str)); + lua_pushinteger(L, V_TitleCardStringWidth(str, p4)); return 1; } diff --git a/src/lua_hudlib_drawlist.c b/src/lua_hudlib_drawlist.c index 68515ae20..8418f1b5a 100644 --- a/src/lua_hudlib_drawlist.c +++ b/src/lua_hudlib_drawlist.c @@ -61,6 +61,7 @@ typedef struct drawitem_s { INT32 timer; INT32 threshold; boolean bossmode; + boolean p4; } drawitem_t; // The internal structure of a drawlist. @@ -358,7 +359,8 @@ void LUA_HUD_AddDrawTitleCardString( const char *str, boolean bossmode, INT32 timer, - INT32 threshold + INT32 threshold, + boolean p4 ) { size_t i = AllocateDrawItem(list); @@ -371,6 +373,7 @@ void LUA_HUD_AddDrawTitleCardString( item->bossmode = bossmode; item->timer = timer; item->threshold = threshold; + item->p4 = p4; } void LUA_HUD_AddDrawKartString( @@ -465,7 +468,7 @@ void LUA_HUD_DrawList(huddrawlist_h list) V_DrawFadeScreen(item->color, item->strength); break; case DI_DrawTitleCardString: - V_DrawTitleCardString(item->x, item->y, itemstr, item->flags, item->bossmode, item->timer, item->threshold); + V_DrawTitleCardString(item->x, item->y, itemstr, item->flags, item->bossmode, item->timer, item->threshold, item->p4); break; case DI_DrawKartString: V_DrawTimerString(item->x, item->y, item->flags, itemstr); diff --git a/src/lua_hudlib_drawlist.h b/src/lua_hudlib_drawlist.h index 15249e4f9..bf2a161e2 100644 --- a/src/lua_hudlib_drawlist.h +++ b/src/lua_hudlib_drawlist.h @@ -111,7 +111,8 @@ void LUA_HUD_AddDrawTitleCardString( const char *str, boolean bossmode, INT32 timer, - INT32 threshold + INT32 threshold, + boolean p4 ); void LUA_HUD_AddDrawKartString( huddrawlist_h list, diff --git a/src/st_stuff.c b/src/st_stuff.c index c1ff32972..1e738dc5f 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -943,10 +943,10 @@ void ST_drawTitleCard(void) // Everything else... if (bossinfo.enemyname) { - bx = V_TitleCardStringWidth(bossinfo.enemyname); + bx = V_TitleCardStringWidth(bossinfo.enemyname, false); // Name. - V_DrawTitleCardString((BASEVIDWIDTH - bx)/2, 75, bossinfo.enemyname, 0, true, bossinfo.titleshow, lt_exitticker); + V_DrawTitleCardString((BASEVIDWIDTH - bx)/2, 75, bossinfo.enemyname, 0, true, bossinfo.titleshow, lt_exitticker, false); // Under-bar. { @@ -1067,10 +1067,10 @@ void ST_drawTitleCard(void) V_DrawFixedPatch(eggx2*FRACUNIT, eggy2*FRACUNIT, FRACUNIT, V_SNAPTOBOTTOM|V_SNAPTOLEFT, tccirclebottom, NULL); // Now the level name. - V_DrawTitleCardString((actnum) ? 265 : 280, 60, lvlttl, V_SNAPTORIGHT, false, lt_ticker, TTANIMENDTHRESHOLD); + V_DrawTitleCardString((actnum) ? 265 : 280, 60, lvlttl, V_SNAPTORIGHT, false, lt_ticker, TTANIMENDTHRESHOLD, false); if (!(mapheaderinfo[gamemap-1]->levelflags & LF_NOZONE)) - V_DrawTitleCardString((actnum) ? 265 : 280, 60+32, strlen(zonttl) ? zonttl : "ZONE", V_SNAPTORIGHT, false, lt_ticker - strlen(lvlttl), TTANIMENDTHRESHOLD); + V_DrawTitleCardString((actnum) ? 265 : 280, 60+32, strlen(zonttl) ? zonttl : "ZONE", V_SNAPTORIGHT, false, lt_ticker - strlen(lvlttl), TTANIMENDTHRESHOLD, false); // the act has a similar graphic animation, but we'll handle it here since it's only like 2 graphics lmfao. if (actnum && actnum < 10) diff --git a/src/v_video.cpp b/src/v_video.cpp index 9c6583916..224530269 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -1854,8 +1854,17 @@ void V_DrawChatCharacter(INT32 x, INT32 y, INT32 c, boolean lowercase, UINT8 *co // V_TitleCardStringWidth // Get the string's width using the titlecard font. -INT32 V_TitleCardStringWidth(const char *str) +INT32 V_TitleCardStringWidth(const char *str, boolean p4) { + int bg_font = GTOL_FONT; + int fg_font = GTFN_FONT; + + if (p4) + { + bg_font = GTOL4_FONT; + fg_font = GTFN4_FONT; + } + INT32 xoffs = 0; const char *ch = str; char c; @@ -1877,15 +1886,15 @@ INT32 V_TitleCardStringWidth(const char *str) c -= LT_FONTSTART; // check if character exists, if not, it's a space. - if (c < 0 || c >= LT_FONTSIZE || !fontv[GTOL_FONT].font[(INT32)c]) + if (c < 0 || c >= LT_FONTSIZE || !fontv[bg_font].font[(INT32)c]) { - xoffs += 10; + xoffs += p4 ? 5 : 10; continue; } - pp = fontv[GTFN_FONT].font[(INT32)c]; + pp = fontv[fg_font].font[(INT32)c]; - xoffs += pp->width-5; + xoffs += pp->width - (p4 ? 3 : 5); } return xoffs; @@ -1894,8 +1903,16 @@ INT32 V_TitleCardStringWidth(const char *str) // V_DrawTitleCardScreen. // see v_video.h's prototype for more information. // -void V_DrawTitleCardString(INT32 x, INT32 y, const char *str, INT32 flags, boolean bossmode, INT32 timer, INT32 threshold) +void V_DrawTitleCardString(INT32 x, INT32 y, const char *str, INT32 flags, boolean bossmode, INT32 timer, INT32 threshold, boolean p4) { + int bg_font = GTOL_FONT; + int fg_font = GTFN_FONT; + + if (p4) + { + bg_font = GTOL4_FONT; + fg_font = GTFN4_FONT; + } INT32 xoffs = 0; INT32 yoffs = 0; @@ -1916,7 +1933,7 @@ void V_DrawTitleCardString(INT32 x, INT32 y, const char *str, INT32 flags, boole x -= 2; // Account for patch width... if (flags & V_SNAPTORIGHT) - x -= V_TitleCardStringWidth(str); + x -= V_TitleCardStringWidth(str, p4); for (;;ch++, i++) @@ -1933,7 +1950,7 @@ void V_DrawTitleCardString(INT32 x, INT32 y, const char *str, INT32 flags, boole if (*ch == '\n') { xoffs = x; - yoffs += 32; + yoffs += p4 ? 18 : 32; continue; } @@ -1944,14 +1961,14 @@ void V_DrawTitleCardString(INT32 x, INT32 y, const char *str, INT32 flags, boole c -= LT_FONTSTART; // check if character exists, if not, it's a space. - if (c < 0 || c >= LT_FONTSIZE || !fontv[GTFN_FONT].font[(INT32)c]) + if (c < 0 || c >= LT_FONTSIZE || !fontv[fg_font].font[(INT32)c]) { - xoffs += 10; + xoffs += p4 ? 5 : 10; continue; } - ol = fontv[GTOL_FONT].font[(INT32)c]; - pp = fontv[GTFN_FONT].font[(INT32)c]; + ol = fontv[bg_font].font[(INT32)c]; + pp = fontv[fg_font].font[(INT32)c]; if (bossmode) { @@ -2004,7 +2021,7 @@ void V_DrawTitleCardString(INT32 x, INT32 y, const char *str, INT32 flags, boole V_DrawStretchyFixedPatch((x + xoffs)*FRACUNIT + offs, (y+yoffs)*FRACUNIT, abs(scalex), FRACUNIT, flags|flipflag, pp, NULL); } - xoffs += pp->width -5; + xoffs += pp->width - (p4 ? 3 : 5); } } diff --git a/src/v_video.h b/src/v_video.h index f7c32505c..b1e47b73d 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -347,10 +347,10 @@ void V_DrawRightAlignedThinStringAtFixed(fixed_t x, fixed_t y, INT32 option, con // threshold: when the letters start disappearing (leave to 0 to disable) (both are INT32 in case you supply negative values...) // NOTE: This function ignores most conventional string flags (V_RETURN8, V_FORCEUPPERCASE ...) // NOTE: This font only works with uppercase letters. -void V_DrawTitleCardString(INT32 x, INT32 y, const char *str, INT32 flags, boolean bossmode, INT32 timer, INT32 threshold); +void V_DrawTitleCardString(INT32 x, INT32 y, const char *str, INT32 flags, boolean bossmode, INT32 timer, INT32 threshold, boolean p4); // returns thr width of a string drawn using the above function. -INT32 V_TitleCardStringWidth(const char *str); +INT32 V_TitleCardStringWidth(const char *str, boolean p4); // Draw tall nums, used for menu, HUD, intermission void V_DrawTallNum(INT32 x, INT32 y, INT32 flags, INT32 num); diff --git a/src/y_inter.c b/src/y_inter.c index 6c980a7ee..9ea49d4a0 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -1462,7 +1462,7 @@ void Y_IntermissionDrawer(void) } else { - headerwidth = V_TitleCardStringWidth(data.headerstring); + headerwidth = V_TitleCardStringWidth(data.headerstring, false); headerx = (BASEVIDWIDTH - headerwidth)/2; headery = 17; @@ -1490,7 +1490,7 @@ void Y_IntermissionDrawer(void) V_DrawMappedPatch(x + roundx, 39, 0, roundpatch, NULL); } - V_DrawTitleCardString(x + headerx, headery, data.headerstring, 0, false, 0, 0); + V_DrawTitleCardString(x + headerx, headery, data.headerstring, 0, false, 0, 0, false); } // Returns early if there's no players to draw