- Blood font refactoring.

This commit is contained in:
Christoph Oelckers 2020-07-31 21:05:09 +02:00
parent 5bae2fcef5
commit 7bf3d5186f
9 changed files with 65 additions and 109 deletions

View file

@ -248,13 +248,6 @@ void PreloadTiles(void)
int skyTile = -1;
memset(gotpic,0,sizeof(gotpic));
// Fonts
for (int i = 0; i < kFontNum; i++)
{
for (int j = 0; j < 96; j++)
{
tilePrecacheTile(gFont[i].tile + j, 0);
}
}
for (int i = 0; i < numsectors; i++)
{
tilePrecacheTile(sector[i].floorpicnum, 0);
@ -976,7 +969,7 @@ static void gameTicker()
static void drawBackground()
{
twod->ClearScreen();
DrawTexture(twod, tileGetTexture(2518), 0, 0, DTA_FullscreenEx, 3, TAG_DONE);
DrawTexture(twod, tileGetTexture(2518, true), 0, 0, DTA_FullscreenEx, 3, TAG_DONE);
if (gQuitRequest && !gQuitGame)
netBroadcastMyLogoff(gQuitRequest == 2);
}

View file

@ -25,20 +25,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "build.h"
#include "compat.h"
#include "common_game.h"
#include "blood.h"
#include "globals.h"
#include "inifile.h"
#include "levels.h"
#include "qav.h"
#include "view.h"
#include "network.h"
#include "mmulti.h"
#include "c_bind.h"
#include "menu.h"
#include "sound.h"
#include "gamestate.h"
#include "blood.h"
#include "globals.h"
#include "qav.h"
#include "view.h"
#include "sound.h"
bool ShowOptionMenu();
BEGIN_BLD_NS
@ -220,19 +217,14 @@ void GameInterface::DrawNativeMenuText(int fontnum, int state, double xpos, doub
int shade = (state != NIT_InactiveState) ? 32 : 48;
int pal = (state != NIT_InactiveState) ? 5 : 5;
if (state == NIT_SelectedState) shade = 32 - ((int)totalclock & 63);
int width, height;
int gamefont = fontnum == NIT_BigFont ? 1 : fontnum == NIT_SmallFont ? 2 : 3;
int x = int(xpos);
int y = int(ypos);
viewGetFontInfo(gamefont, text, &width, &height);
auto gamefont = fontnum == NIT_BigFont ? BigFont : fontnum == NIT_SmallFont ? SmallFont : SmallFont2;
if (flags & LMF_Centered)
{
x -= width / 2;
int width = gamefont->StringWidth(text);
xpos -= width / 2;
}
viewDrawText(gamefont, text, x, y, shade, pal, 0, true);
DrawText(twod, gamefont, CR_UNDEFINED, xpos, ypos, text, DTA_TranslationIndex, TRANSLATION(Translation_Remap, pal), DTA_Color, shadeToLight(shade), TAG_DONE);
}
@ -269,35 +261,28 @@ FSavegameInfo GameInterface::GetSaveSig()
void GameInterface::DrawMenuCaption(const DVector2& origin, const char* text)
{
int height, width;
// font #1, tile #2038.
viewGetFontInfo(1, text, &width, &height);
double scalex = 1.; // Expand the box if the text is longer
int width = BigFont->StringWidth(text);
int boxwidth = tileWidth(2038);
if (boxwidth - 10 < width) scalex = double(width) / (boxwidth - 10);
DrawTexture(twod, tileGetTexture(2038), 160, 20, DTA_FullscreenScale, 3, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_CenterOffsetRel, true, DTA_ScaleX, scalex, TAG_DONE);
viewDrawText(1, text, 160, 20 - height / 2, -128, 0, 1, false);
DrawTexture(twod, tileGetTexture(2038, true), 160, 20, DTA_FullscreenScale, 3, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_CenterOffsetRel, true, DTA_ScaleX, scalex, TAG_DONE);
DrawText(twod, BigFont, CR_UNDEFINED, 160, 29, text, TAG_DONE);
}
void GameInterface::DrawCenteredTextScreen(const DVector2& origin, const char* text, int position, bool bg)
{
if (text)
{
int width, height = 0;
viewGetFontInfo(0, "T", &width, &height);
int height = SmallFont->GetHeight();
auto lines = FString(text).Split("\n");
int y = 100 - (height * lines.Size() / 2);
for (auto& l : lines)
{
int lheight = 0;
viewGetFontInfo(0, l, &width, &lheight);
int width = SmallFont->StringWidth(text);
int x = 160 - width / 2;
viewDrawText(0, l, x, y, 0, 0, 0, false);
DrawText(twod, SmallFont, CR_UNTRANSLATED, y, y, text, TAG_DONE);
y += height;
}
}

View file

@ -55,7 +55,7 @@ void CEndGameMgr::Draw(void)
viewLoadingScreenWide();
int nHeight;
viewGetFontInfo(1, NULL, NULL, &nHeight);
DrawTexture(twod, tileGetTexture(2038), 160, 20, DTA_FullscreenScale, 3, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_CenterOffsetRel, true, TAG_DONE);
DrawTexture(twod, tileGetTexture(2038, true), 160, 20, DTA_FullscreenScale, 3, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_CenterOffsetRel, true, TAG_DONE);
int nY = 20 - nHeight / 2;
if (gGameOptions.nGameType == 0)
{

View file

@ -160,7 +160,7 @@ void sub_2541C(int x, int y, int z, short a)
double x = xdim/2. + x1 / double(1<<12);
double y = ydim/2. + y1 / double(1<<12);
// This very likely needs fixing later
DrawTexture(twod, tileGetTexture(nTile), x, y, DTA_FullscreenScale, 3, DTA_ViewportX, windowxy1.x, DTA_ViewportY, windowxy1.y,
DrawTexture(twod, tileGetTexture(nTile, true), x, y, DTA_FullscreenScale, 3, DTA_ViewportX, windowxy1.x, DTA_ViewportY, windowxy1.y,
DTA_ViewportWidth, windowxy2.x - windowxy1.x+1, DTA_ViewportHeight, windowxy2.y - windowxy1.y+1, DTA_Alpha, (pSprite->cstat&2? 0.5:1.), TAG_DONE);
}
}
@ -216,9 +216,9 @@ void CViewMap::sub_25C74(void)
#if 0 // needs to be generalized
if (gViewMap.bFollowMode)
viewDrawText(3, "MAP FOLLOW MODE", gViewX1S, nViewY+8, -128, 0, 2, 0, 256);
Printf(PRINT_NOTIFY, "MAP FOLLOW MODE\n");
else
viewDrawText(3, "MAP SCROLL MODE", gViewX1S, nViewY+8, -128, 0, 2, 0, 256);
Printf(PRINT_NOTIFY, "MAP SCROLL MODE\n");
#endif
if (tm)
viewResizeView(viewSize);

View file

@ -21,8 +21,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
//-------------------------------------------------------------------------
#pragma once
#include "common_game.h"
#include "db.h"
#include "build.h"
#include "fix16.h"
BEGIN_BLD_NS

View file

@ -442,7 +442,7 @@ void CGameMessageMgr::SetMaxMessages(int nMessages)
void CGameMessageMgr::SetFont(int nFont)
{
this->nFont = nFont;
fontHeight = gFont[nFont].ySize;
fontHeight = gFont[nFont]->GetHeight();
}
void CGameMessageMgr::SetCoordinates(int x, int y)

View file

@ -67,13 +67,13 @@ void DrawFrame(F2DDrawer *twod, int x, int y, TILE_FRAME *pTile, int stat, int s
if (!to3dview)
{
DrawTexture(twod, tex, x, y, DTA_ScaleX, scale, DTA_ScaleY, scale, DTA_Rotate, angle, DTA_LegacyRenderStyle, renderstyle, DTA_Alpha, alpha, DTA_Pin, pin, DTA_TranslationIndex, translation,
DTA_TopLeft, topleft, DTA_CenterOffsetRel, !topleft, DTA_FullscreenScale, 3, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_FlipOffsets, !topleft, DTA_Color, color,
DTA_TopLeft, topleft, DTA_CenterOffsetRel, !topleft, DTA_FullscreenScale, 3, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_FlipOffsets, true, DTA_Color, color,
DTA_FlipX, xflip, DTA_FlipY, yflip, TAG_DONE);
}
else
{
DrawTexture(twod, tex, x, y, DTA_ScaleX, scale, DTA_ScaleY, scale, DTA_Rotate, angle, DTA_LegacyRenderStyle, renderstyle, DTA_Alpha, alpha, DTA_Pin, pin, DTA_TranslationIndex, translation,
DTA_TopLeft, topleft, DTA_CenterOffsetRel, !topleft, DTA_FullscreenScale, 3, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_FlipOffsets, !topleft, DTA_Color, color,
DTA_TopLeft, topleft, DTA_CenterOffsetRel, !topleft, DTA_FullscreenScale, 3, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_FlipOffsets, true, DTA_Color, color,
DTA_FlipX, xflip, DTA_FlipY, yflip, DTA_ViewportX, windowxy1.x, DTA_ViewportY, windowxy1.y, DTA_ViewportWidth, windowxy2.x - windowxy1.x+1, DTA_ViewportHeight, windowxy2.y - windowxy1.y+1, TAG_DONE);
}
}

View file

@ -29,23 +29,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "build.h"
#include "pragmas.h"
#include "mmulti.h"
#include "common_game.h"
#include "v_font.h"
#include "aistate.h"
#include "blood.h"
#include "choke.h"
#include "db.h"
#include "endgame.h"
#include "gameutil.h"
#include "globals.h"
#include "levels.h"
#include "loadsave.h"
#include "aistate.h"
#include "map2d.h"
#include "messages.h"
#include "network.h"
#include "player.h"
#include "screen.h"
#include "loadsave.h"
#include "screen.h"
#include "sectorfx.h"
#include "choke.h"
#include "view.h"
#include "nnexts.h"
#include "zstring.h"
@ -53,6 +45,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "gstrings.h"
#include "v_2ddrawer.h"
#include "v_video.h"
#include "v_font.h"
#include "glbackend/glbackend.h"
CVARD(Bool, hud_powerupduration, true, CVAR_ARCHIVE/*|CVAR_FRONTEND_BLOOD*/, "enable/disable displaying the remaining seconds for power-ups")
@ -176,54 +169,47 @@ void RotateXY(int *pX, int *pY, int *pZ, int ang)
*pY = dmulscale30r(oX,angSin,oY,angCos);
}
FONT gFont[kFontNum];
FFont *gFont[kFontNum];
void FontSet(int id, int tile, int space)
{
if (id < 0 || id >= kFontNum || tile < 0 || tile >= kMaxTiles)
return;
FONT *pFont = &gFont[id];
int xSize = 0;
int ySize = 0;
pFont->tile = tile;
for (int i = 0; i < 96; i++)
GlyphSet glyphs;
for (int i = 1; i < 96; i++)
{
if (tilesiz[tile+i].x > xSize)
xSize = tilesiz[tile+i].x;
if (tilesiz[tile+i].y > ySize)
ySize = tilesiz[tile+i].y;
auto tex = tileGetTexture(tile + i);
if (tex->isValid() && tex->GetTexelWidth() > 0 && tex->GetTexelHeight() > 0)
glyphs.Insert(i + 32, tex);
}
pFont->xSize = xSize;
pFont->ySize = ySize;
pFont->space = space;
const char *names[] = { "smallfont", "bigfont", "gothfont", "smallfont2", "digifont"};
const char *defs[] = { "defsmallfont", "defbigfont", nullptr, "defsmallfont2", nullptr};
const bool kerning[] = { 0, 1, 1, 1, 0};
FFont ** ptrs[] = { &SmallFont, &BigFont, nullptr, &SmallFont2, nullptr};
gFont[id] = new ::FFont(names[id], nullptr, defs[id], 0, 0, 0, kerning[id], tileWidth(tile), false, false, &glyphs);
if (ptrs[id]) *ptrs[id] = gFont[id];
}
void viewGetFontInfo(int id, const char *unk1, int *pXSize, int *pYSize)
{
if (id < 0 || id >= kFontNum)
return;
FONT *pFont = &gFont[id];
FFont *pFont = gFont[id];
if (!unk1)
{
if (pXSize)
*pXSize = pFont->xSize;
*pXSize = pFont->GetCharWidth('N');
if (pYSize)
*pYSize = pFont->ySize;
*pYSize = pFont->GetHeight();
}
else
{
int width = -pFont->space;
for (const char *pBuf = unk1; *pBuf != 0; pBuf++)
{
int tile = ((*pBuf-32)&127)+pFont->tile;
if (tileGetTexture(tile)->isValid())
width += tilesiz[tile].x+pFont->space;
}
if (pXSize)
*pXSize = width;
*pXSize = pFont->StringWidth(unk1);
if (pYSize)
*pYSize = pFont->ySize;
*pYSize = pFont->GetHeight();
}
}
@ -1015,29 +1001,25 @@ void RestoreInterpolations(void)
void viewDrawText(int nFont, const char *pString, int x, int y, int nShade, int nPalette, int position, char shadow, unsigned int nStat, uint8_t alpha)
{
if (nFont < 0 || nFont >= kFontNum || !pString) return;
FONT *pFont = &gFont[nFont];
FFont *pFont = gFont[nFont];
//y += pFont->yoff;
if (position)
{
const char *s = pString;
int width = -pFont->space;
while (*s)
{
int nTile = ((*s-' ')&127)+pFont->tile;
if (tilesiz[nTile].x && tilesiz[nTile].y)
width += tilesiz[nTile].x+pFont->space;
s++;
}
if (position == 1)
width >>= 1;
x -= width;
}
if (position) x -= pFont->StringWidth(pString) / 2;
if (shadow)
{
DrawText(twod, pFont, CR_UNDEFINED, x, y, pString, DTA_FullscreenScale, 3, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_Color, 0, DTA_Alpha, 0.5, TAG_DONE);
}
DrawText(twod, pFont, CR_UNDEFINED, x, y, pString, DTA_FullscreenScale, 3, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200, DTA_TranslationIndex, TRANSLATION(Translation_Remap, nPalette),
DTA_Color, shadeToLight(nShade), TAG_DONE);
// This is just for position comparison
const char *s = pString;
while (*s)
{
int nTile = ((*s-' ')&127) + pFont->tile;
int nTile = 'A' - 32 + 4096 + nFont*96;
//int nTile = ((*s-' ')&127) + ';
if (tilesiz[nTile].x && tilesiz[nTile].y)
{
if (shadow)
@ -1045,7 +1027,7 @@ void viewDrawText(int nFont, const char *pString, int x, int y, int nShade, int
rotatesprite_fs_alpha((x+1)<<16, (y+1)<<16, 65536, 0, nTile, 127, nPalette, 26|nStat, alpha);
}
rotatesprite_fs_alpha(x<<16, y<<16, 65536, 0, nTile, nShade, nPalette, 26|nStat, alpha);
x += tilesiz[nTile].x+pFont->space;
x += pFont->GetDefaultKerning();
}
s++;
}

View file

@ -75,12 +75,8 @@ enum INTERPOLATE_TYPE {
#define kFontNum 5
struct FONT {
int tile, xSize, ySize, space;
};
extern int gZoom;
extern FONT gFont[kFontNum];
extern FFont *gFont[kFontNum];
extern int gViewMode;
extern VIEWPOS gViewPos;
extern int gViewIndex;