- implemented all needed font overrides for localization.

This commit is contained in:
Christoph Oelckers 2021-05-31 11:51:02 +02:00
parent d174b61c3c
commit 9c60ab791b
22 changed files with 134 additions and 49 deletions

View file

@ -65,6 +65,7 @@
#include "savegamehelp.h"
#include "gi.h"
#include "raze_music.h"
#include "razefont.h"
EXTERN_CVAR(Int, cl_gfxlocalization)
EXTERN_CVAR(Bool, m_quickexit)
@ -412,6 +413,7 @@ static void BuildEpisodeMenu()
double y = ld->mYpos;
// Volume definitions should be sorted by intended menu order.
auto font = PickSmallFont();
for (auto &vol : volumes)
{
if (vol.name.IsNotEmpty() && !(vol.flags & VF_HIDEFROMSP))

View file

@ -36,6 +36,8 @@
#include "gamecontrol.h"
#include "c_cvars.h"
#include "i_interface.h"
#include "vm.h"
#include "gstrings.h"
FGameTexture* GetBaseForChar(FGameTexture* t);
void FontCharCreated(FGameTexture* base, FGameTexture* glyph);
@ -103,3 +105,49 @@ void InitFont()
// todo: Compare small and big fonts with the base font and decide which one to use.
}
FFont* PickBigFont(const char* txt)
{
if (generic_ui) return NewSmallFont; // Note: Support is incomplete. Translations do not exist anyway for most content.
if (!OriginalBigFont || OriginalBigFont == BigFont) return BigFont;
if (txt && *txt == '$') txt = GStrings[txt + 1];
if (!txt || !*txt) txt = GStrings["REQUIRED_CHARACTERS"];
if (!txt || !*txt || BigFont->CanPrint(txt)) return BigFont;
return OriginalBigFont;
}
static FFont* PickBigFont_(const FString& str)
{
return PickBigFont(str.GetChars());
}
DEFINE_ACTION_FUNCTION_NATIVE(_Raze, PickBigFont, PickBigFont_)
{
PARAM_PROLOGUE;
PARAM_STRING(text);
//PARAM_POINTER(cr, int);
ACTION_RETURN_POINTER(PickBigFont(text));
}
FFont* PickSmallFont(const char* txt)
{
if (generic_ui) return NewSmallFont; // Note: Support is incomplete. Translations do not exist anyway for most content.
if (!OriginalSmallFont || OriginalSmallFont == SmallFont) return SmallFont;
if (txt && *txt == '$') txt = GStrings[txt + 1];
if (!txt || !*txt) txt = GStrings["REQUIRED_CHARACTERS"];
if (!txt || !*txt || SmallFont->CanPrint(txt)) return SmallFont;
return OriginalSmallFont;
}
static FFont* PickSmallFont_(const FString& str)
{
return PickSmallFont(str.GetChars());
}
DEFINE_ACTION_FUNCTION_NATIVE(_Raze, PickSmallFont, PickSmallFont_)
{
PARAM_PROLOGUE;
PARAM_STRING(text);
//PARAM_POINTER(cr, int);
ACTION_RETURN_POINTER(PickBigFont(text));
}

View file

@ -8,3 +8,5 @@ extern FFont* IndexFont;
extern FFont* DigiFont;
void InitFont();
FFont* PickBigFont(const char* txt = nullptr);
FFont* PickSmallFont(const char* txt = nullptr);

View file

@ -61,6 +61,7 @@
#include "gamestruct.h"
#include "razemenu.h"
#include "mapinfo.h"
#include "razefont.h"
#include "../version.h"
@ -167,15 +168,16 @@ void drawMapTitle()
{
double scale = (g_gameType & GAMEFLAG_RRALL)? 0.4 : (g_gameType & GAMEFLAG_SW)? 0.7 : 1.0;
auto text = currentLevel->DisplayName();
double x = 160 - BigFont->StringWidth(text) * scale / 2.;
double y = isBlood() ? 50 : 100 - BigFont->GetHeight()/2.;
auto myfont = PickBigFont(text);
double x = 160 - myfont->StringWidth(text) * scale / 2.;
double y = isBlood() ? 50 : 100 - myfont->GetHeight()/2.;
bool shadow = true;
if (shadow)
{
DrawText(twod, BigFont, CR_UNTRANSLATED, x+1, y+1, text, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Color, 0xff000000, DTA_Alpha, alpha / 2., DTA_ScaleX, scale, DTA_ScaleY, scale, TAG_DONE);
DrawText(twod, myfont, CR_UNTRANSLATED, x+1, y+1, text, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Color, 0xff000000, DTA_Alpha, alpha / 2., DTA_ScaleX, scale, DTA_ScaleY, scale, TAG_DONE);
}
DrawText(twod, BigFont, CR_UNTRANSLATED, x, y, text, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Alpha, alpha, DTA_ScaleX, scale, DTA_ScaleY, scale, TAG_DONE);
DrawText(twod, myfont, CR_UNTRANSLATED, x, y, text, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Alpha, alpha, DTA_ScaleX, scale, DTA_ScaleY, scale, TAG_DONE);
}
}

View file

@ -758,12 +758,13 @@ void viewDrawScreen(bool sceneonly)
viewDrawAimedPlayerName();
if (paused)
{
viewDrawText(BigFont, GStrings("TXTB_PAUSED"), 160, 10, 0, 0, 1, 0);
auto text = GStrings("TXTB_PAUSED");
viewDrawText(PickBigFont(text), text, 160, 10, 0, 0, 1, 0);
}
else if (gView != gMe)
{
FStringf gTempStr("] %s [", PlayerName(gView->nPlayer));
viewDrawText(SmallFont, gTempStr, 160, 10, 0, 0, 1, 0);
viewDrawText(OriginalSmallFont, gTempStr, 160, 10, 0, 0, 1, 0);
}
if (cl_interpolate)
{

View file

@ -43,6 +43,7 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au)
#include "gamestate.h"
#include "dukeactor.h"
#include "interpolate.h"
#include "razefont.h"
BEGIN_DUKE_NS
@ -299,8 +300,9 @@ void drawoverlays(double smoothratio)
double x = 160, y = 100;
double scale = isRR() ? 0.4 : 1.;
const char* text = GStrings("Game Paused");
x -= BigFont->StringWidth(text) * 0.5 * scale;
DrawText(twod, BigFont, CR_UNTRANSLATED, x, y - 12, text, DTA_FullscreenScale, FSMode_Fit320x200, DTA_ScaleX, scale, DTA_ScaleY, scale, TAG_DONE);
auto myfont = PickBigFont(text);
x -= myfont->StringWidth(text) * 0.5 * scale;
DrawText(twod, myfont, CR_UNTRANSLATED, x, y - 12, text, DTA_FullscreenScale, FSMode_Fit320x200, DTA_ScaleX, scale, DTA_ScaleY, scale, TAG_DONE);
}
}

View file

@ -41,6 +41,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "gamefuncs.h"
#include "c_bind.h"
#include "vm.h"
#include "razefont.h"
#include <string>
@ -328,6 +329,7 @@ void TextOverlay::Create(const FString& text, int pal)
{
lastclock = 0;
FString ttext = GStrings(text);
font = PickSmallFont(ttext);
screentext = ttext.Split("\n");
ComputeCinemaText();
}
@ -367,7 +369,7 @@ void TextOverlay::DisplayText()
while (i < screentext.Size() && y <= 199)
{
if (y >= -10) {
DrawText(twod, SmallFont, CR_NATIVEPAL, nLeft[i], y, screentext[i], DTA_FullscreenScale, FSMode_Fit320x200, DTA_TranslationIndex, TRANSLATION(Translation_BasePalettes, currentCinemaPalette), TAG_DONE);
DrawText(twod, font, CR_NATIVEPAL, nLeft[i], y, screentext[i], DTA_FullscreenScale, FSMode_Fit320x200, DTA_TranslationIndex, TRANSLATION(Translation_BasePalettes, currentCinemaPalette), TAG_DONE);
}
i++;

View file

@ -176,6 +176,7 @@ enum {
class TextOverlay
{
FFont* font;
double nCrawlY;
short nLeft[50];
int nHeight;

View file

@ -84,8 +84,9 @@ void GameInterface::Render()
if (paused && !M_Active())
{
auto tex = GStrings("TXTB_PAUSED");
int nStringWidth = SmallFont->StringWidth(tex);
DrawText(twod, SmallFont, CR_UNTRANSLATED, 160 - nStringWidth / 2, 100, tex, DTA_FullscreenScale, FSMode_Fit320x200, TAG_DONE);
auto font = PickSmallFont(tex);
int nStringWidth = font->StringWidth(tex);
DrawText(twod, font, CR_UNTRANSLATED, 160 - nStringWidth / 2, 100, tex, DTA_FullscreenScale, FSMode_Fit320x200, TAG_DONE);
}
drawtime.Unclock();

View file

@ -56,6 +56,7 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
#include "v_video.h"
#include "v_draw.h"
#include "render.h"
#include "razefont.h"
EXTERN_CVAR(Bool, testnewrenderer)
BEGIN_SW_NS
@ -1672,8 +1673,9 @@ drawscreen(PLAYERp pp, double smoothratio)
if (paused && !M_Active())
{
auto str = GStrings("Game Paused");
int w = SmallFont->StringWidth(str);
DrawText(twod, SmallFont, CR_UNTRANSLATED, 160-w, 100, str, DTA_FullscreenScale, FSMode_Fit320x200, TAG_DONE);
auto font = PickSmallFont(str);
int w = font->StringWidth(str);
DrawText(twod, font, CR_UNTRANSLATED, 160-w, 100, str, DTA_FullscreenScale, FSMode_Fit320x200, TAG_DONE);
}
if (!CommEnabled && TEST(pp->Flags, PF_DEAD))

View file

@ -599,10 +599,12 @@ class TextOverlay
int crange;
bool drawclean;
BrokenLines screentext;
Font myfont;
void Init(String text, int cr = Font.CR_NATIVEPAL, int pal = 0, bool clean = false)
{
screentext = SmallFont.BreakLines(StringTable.Localize(text), 320);
myfont = SmallFont; // todo
screentext = myfont.BreakLines(StringTable.Localize(text), 320);
nCrawlY = 199;
nHeight = screentext.Count() * 10;
palette = pal;
@ -620,8 +622,8 @@ class TextOverlay
if (y >= -10)
{
int x = 160 - screenText.StringWidth(i)/2;
if (!drawclean) Screen.DrawText(SmallFont, crange, x, y, screentext.StringAt(i), DTA_FullscreenScale, FSMode_Fit320x200, DTA_TranslationIndex, palette);
else Screen.DrawText(SmallFont, crange, x, y, screentext.StringAt(i), DTA_Clean, true, DTA_TranslationIndex, palette);
if (!drawclean) Screen.DrawText(myfont, crange, x, y, screentext.StringAt(i), DTA_FullscreenScale, FSMode_Fit320x200, DTA_TranslationIndex, palette);
else Screen.DrawText(myfont, crange, x, y, screentext.StringAt(i), DTA_Clean, true, DTA_TranslationIndex, palette);
}
y += 10;
}

View file

@ -59,7 +59,7 @@ class ListMenuItemBloodTextItem : ListMenuItemTextItem
{
int shade = Selectable()? 32: 48;
int pal = 5;
let gamefont = generic_ui ? NewSmallFont : BigFont;
let gamefont = Raze.PickBigFont();
int xpos = mXpos - gamefont.StringWidth(mText) / 2;
int cr = generic_ui? Font.CR_GRAY : Font.CR_NATIVEPAL;
int trans = generic_ui? 0 : Translation.MakeID(Translation_Remap, pal);

View file

@ -151,7 +151,11 @@ class BloodStatusBar : RazeStatusBar
{
// For non-English languages force use of the text font. The tiny one is simply too small to ever add localized characters to it.
let p = StringTable.Localize("$REQUIRED_CHARACTERS");
if (p.length() > 0) textfont = true;
if (p.length() > 0)
{
stats.statfont = Raze.PickSmallFont();
textfont = true;
}
}
if (!textfont)

View file

@ -87,7 +87,7 @@ struct BloodScreen
static int DrawCaption(String title, int y, bool drawit)
{
let font = generic_ui? NewConsoleFont : BigFont;
let font = Raze.PickBigFont();
let texid = TexMan.CheckForTexture("MENUBAR");
let texsize = TexMan.GetScaledSize(texid);
let fonth = font.GetGlyphHeight("A");
@ -133,7 +133,7 @@ struct BloodScreen
{
let text = StringTable.Localize(text);
if (hud_textfont || !SmallFont2.CanPrint(text))
DrawText(SmallFont, text, x, y, 1);
DrawText(Raze.PickSmallFont(text), text, x, y, 1);
else
DrawText(SmallFont2, text, x, y, 1, shadow: true);
}
@ -147,6 +147,8 @@ struct BloodScreen
class BloodSummaryScreen : SummaryScreenBase
{
Font myfont;
ScreenJob Init(MapRecord map, SummaryInfo info)
{
Super.Init(fadein|fadeout);
@ -172,28 +174,29 @@ class BloodSummaryScreen : SummaryScreenBase
void DrawKills()
{
String pBuffer;
BloodScreen.DrawText(BigFont, Stringtable.Localize("$KILLS") .. ":", 75, 50);
BloodScreen.DrawText(myfont, Stringtable.Localize("$KILLS") .. ":", 75, 50);
pBuffer = String.Format("%2d", stats.Kills);
BloodScreen.DrawText(BigFont, pBuffer, 160, 50);
BloodScreen.DrawText(BigFont, "$OF", 190, 50);
BloodScreen.DrawText(myfont, pBuffer, 160, 50);
BloodScreen.DrawText(myfont, "$OF", 190, 50);
pBuffer = String.Format( "%2d", stats.MaxKills);
BloodScreen.DrawText(BigFont, pBuffer, 220, 50);
BloodScreen.DrawText(myfont, pBuffer, 220, 50);
}
void DrawSecrets()
{
String pBuffer;
BloodScreen.DrawText(BigFont, StringTable.Localize("$TXT_SECRETS") .. ":", 75, 70);
BloodScreen.DrawText(myfont, StringTable.Localize("$TXT_SECRETS") .. ":", 75, 70);
pBuffer = String.Format( "%2d", stats.secrets);
BloodScreen.DrawText(BigFont, pBuffer, 160, 70);
BloodScreen.DrawText(BigFont, "$OF", 190, 70);
BloodScreen.DrawText(myfont, pBuffer, 160, 70);
BloodScreen.DrawText(myfont, "$OF", 190, 70);
pBuffer = String.Format( "%2d", stats.maxsecrets);
BloodScreen.DrawText(BigFont, pBuffer, 220, 70);
if (stats.SuperSecrets > 0) BloodScreen.DrawText(BigFont, "$TXT_SUPERSECRET", 160, 100, 1, 0, 2);
BloodScreen.DrawText(myfont, pBuffer, 220, 70);
if (stats.SuperSecrets > 0) BloodScreen.DrawText(myfont, "$TXT_SUPERSECRET", 160, 100, 1, 0, 2);
}
override void Draw(double sm)
{
myfont = Raze.PickBigFont();
BloodScreen.DrawBackground();
BloodScreen.DrawCaption("$TXTB_LEVELSTATS", 0, true);
if (stats.cheated)
@ -275,7 +278,7 @@ class BloodLoadScreen : ScreenJob
{
BloodScreen.DrawBackground();
BloodScreen.DrawCaption(loadtext, 0, true);
BloodScreen.DrawText(BigFont, rec.DisplayName(), 160, 50, 1);
BloodScreen.DrawText(Raze.PickBigFont(), rec.DisplayName(), 160, 50, 1);
BloodScreen.DrawLocalizedText(160, 134, "$TXTB_PLSWAIT");
}
}

View file

@ -85,21 +85,22 @@ struct Duke native
static void BigText(double x, double y, String text, int align = -1, double alpha = 1.)
{
let myfont = Raze.PickBigFont();
if (!Raze.isRR())
{
if (align != -1) x -= BigFont.StringWidth(text) * (align == 0 ? 0.5 : 1);
Screen.DrawText(BigFont, Font.CR_UNTRANSLATED, x, y - 12, text, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Alpha, alpha);
if (align != -1) x -= myfont.StringWidth(text) * (align == 0 ? 0.5 : 1);
Screen.DrawText(myfont, Font.CR_UNTRANSLATED, x, y - 12, text, DTA_FullscreenScale, FSMode_Fit320x200, DTA_Alpha, alpha);
}
else
{
if (align != -1) x -= BigFont.StringWidth(text) * (align == 0 ? 0.2 : 0.4);
Screen.DrawText(BigFont, Font.CR_UNTRANSLATED, x, y - 12, text, DTA_FullscreenScale, FSMode_Fit320x200, DTA_ScaleX, 0.4, DTA_ScaleY, 0.4, DTA_Alpha, alpha);
if (align != -1) x -= myfont.StringWidth(text) * (align == 0 ? 0.2 : 0.4);
Screen.DrawText(myfont, Font.CR_UNTRANSLATED, x, y - 12, text, DTA_FullscreenScale, FSMode_Fit320x200, DTA_ScaleX, 0.4, DTA_ScaleY, 0.4, DTA_Alpha, alpha);
}
}
static void GameText(double x, double y, String t, int shade, int align = -1, int trans = 0)
{
let myfont = Raze.PickSmallFont();
int fsmode = FSMode_Fit320x200;
if (Raze.isRR())
{
@ -107,8 +108,8 @@ struct Duke native
y *= 2;
fsmode = FSMode_Fit640x400;
}
if (align != -1) x -= SmallFont.StringWidth(t) * (align == 0 ? 0.5 : 1);
Screen.DrawText(SmallFont, Font.CR_NATIVEPAL, x, y + 2, t, DTA_FullscreenScale, fsmode, DTA_TranslationIndex, Translation.MakeID(Translation_Remap, trans), DTA_Color, Raze.shadeToLight(shade));
if (align != -1) x -= myfont.StringWidth(t) * (align == 0 ? 0.5 : 1);
Screen.DrawText(myfont, Font.CR_NATIVEPAL, x, y + 2, t, DTA_FullscreenScale, fsmode, DTA_TranslationIndex, Translation.MakeID(Translation_Remap, trans), DTA_Color, Raze.shadeToLight(shade));
}
}

View file

@ -30,7 +30,7 @@ class DukeMenuDelegate : RazeMenuDelegate
{
override int DrawCaption(String title, Font fnt, int y, bool drawit)
{
let font = generic_ui? NewConsoleFont : BigFont; // this ignores the passed font intentionally.
let font = Raze.PickBigFont(); // this ignores the passed font intentionally.
let texid = TexMan.CheckForTexture("MENUBAR");
let texsize = TexMan.GetScaledSize(texid);
let fonth = font.GetGlyphHeight("A");
@ -82,7 +82,7 @@ class DukeMenuDelegate : RazeMenuDelegate
//----------------------------------------------------------------------------
//
//
// not used for any localized content.
//
//----------------------------------------------------------------------------
@ -167,10 +167,11 @@ class ListMenuItemDukeTextItem : ListMenuItemTextItem
override void Draw(bool selected, ListMenuDescriptor desc)
{
int trans = mColorSelected? Translation.MakeID(Translation_Remap, 1) : 0;
let font = Raze.PickBigFont();
int trans = mColorSelected? Translation.MakeID(Translation_Remap, 1) : 0;
Color pe;
double scale = (gameinfo.gametype & GAMEFLAG_RRALL) ? 0.4 : 1.;
let xpos = 160 - BigFont.StringWidth(mText) * scale * 0.5;
let xpos = 160 - font.StringWidth(mText) * scale * 0.5;
if (selected)
{
@ -183,7 +184,7 @@ class ListMenuItemDukeTextItem : ListMenuItemTextItem
pe = Color(255, 160, 160, 160);
}
Screen.DrawText(BigFont, Font.CR_NATIVEPAL, xpos, mYpos, mText, DTA_FullscreenScale, FSMode_Fit320x200, DTA_ScaleX, scale, DTA_ScaleY, scale, DTA_Color, pe, DTA_TranslationIndex, trans);
Screen.DrawText(font, Font.CR_NATIVEPAL, xpos, mYpos, mText, DTA_FullscreenScale, FSMode_Fit320x200, DTA_ScaleX, scale, DTA_ScaleY, scale, DTA_Color, pe, DTA_TranslationIndex, trans);
}
}

View file

@ -179,7 +179,11 @@ class DukeCommonStatusBar : RazeStatusBar
{
// For non-English languages force use of the text font. The tiny one is simply too small to ever add localized characters to it.
let p = StringTable.Localize("$REQUIRED_CHARACTERS");
if (p.length() > 0) textfont = true;
if (p.length() > 0)
{
stats.statfont = Raze.PickSmallFont();
textfont = true;
}
}
if (!textfont)

View file

@ -5,7 +5,7 @@ class ExhumedMenuDelegate : RazeMenuDelegate
override int DrawCaption(String title, Font fnt, int y, bool drawit)
{
let font = generic_ui? NewConsoleFont : BigFont; // this ignores the passed font intentionally.
let font = Raze.PickBigFont();
let cr = generic_ui ? Font.CR_FIRE : Font.CR_UNTRANSLATED; // this ignores the passed font intentionally.
let texid = TexMan.CheckForTexture("MENUBLANK");
let texsize = TexMan.GetScaledSize(texid);
@ -87,7 +87,7 @@ class ListMenuItemExhumedTextItem : ListMenuItemTextItem
override void Draw(bool selected, ListMenuDescriptor desc)
{
let font = generic_ui ? NewConsoleFont : BigFont; // this ignores the passed font intentionally.
let font = Raze.PickBigFont();
let cr = generic_ui ? Font.CR_FIRE : Font.CR_UNTRANSLATED; // this ignores the passed font intentionally.
let tex = TexMan.CheckForTexture("MENUBLANK");
let texsize = TexMan.GetScaledSize(tex);

View file

@ -448,6 +448,7 @@ class ExhumedStatusBar : RazeStatusBar
if (automapMode == am_full)
{
stats.statfont = Raze.PickSmallFont();
PrintAutomapInfo(stats, true);
}
else if (automapMode == am_off && hud_stats)

View file

@ -3,7 +3,7 @@ class SWMenuDelegate : RazeMenuDelegate
{
override int DrawCaption(String title, Font fnt, int y, bool drawit)
{
let font = generic_ui? NewConsoleFont : BigFont; // this ignores the passed font intentionally.
let font = Raze.PickBigFont();
let texid = TexMan.CheckForTexture("MENUBAR");
let texsize = TexMan.GetScaledSize(texid);
let fonth = font.GetGlyphHeight("A");
@ -100,7 +100,7 @@ class ListMenuItemSWTextItem : ListMenuItemTextItem
override void Draw(bool selected, ListMenuDescriptor desc)
{
let gamefont = generic_ui ? NewSmallFont : mFont;
let gamefont = generic_ui ? NewSmallFont : mFont == SmallFont? Raze.PickSmallFont() : mFont == BigFont? Raze.PickBigFont() : mFont;
int cr = mColor != Font.CR_UNDEFINED? mColor : generic_ui? Font.CR_RED : Font.CR_UNTRANSLATED;
double scalex = generic_ui && mFont == SmallFont? 0.5 : 1.;

View file

@ -864,7 +864,11 @@ class SWStatusBar : RazeStatusBar
{
// For non-English languages force use of the text font. The tiny one is simply too small to ever add localized characters to it.
let p = StringTable.Localize("$REQUIRED_CHARACTERS");
if (p.length() > 0) textfont = true;
if (p.length() > 0)
{
stats.statfont = Raze.PickSmallFont();
textfont = true;
}
}
if (!textfont)

View file

@ -147,7 +147,9 @@ struct Raze
native static int bcos(int angle, int shift = 0);
native static TextureID PickTexture(TextureID texid);
native static int GetBuildTime();
native static Font PickBigFont(String cmptext = "");
native static Font PickSmallFont(String cmptext = "");
// game check shortcuts
static bool isNam()
{