From c0c09f272034d61efa38709d0e3fd1ea79bfd98f Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Tue, 31 Mar 2020 08:38:22 +0300 Subject: [PATCH 1/4] Japanese --- src/control/Garages.cpp | 2 +- src/core/Frontend.cpp | 29 +- src/core/Frontend.h | 2 + src/core/MenuScreens.h | 1 + src/render/Font.cpp | 618 +++++++++++++++++++++++++++++++++++----- src/render/Font.h | 47 +-- src/render/Hud.cpp | 30 +- src/render/Hud.h | 4 +- src/text/Messages.cpp | 26 +- src/text/Text.cpp | 9 +- 10 files changed, 650 insertions(+), 118 deletions(-) diff --git a/src/control/Garages.cpp b/src/control/Garages.cpp index 93857b14..c36ecadb 100644 --- a/src/control/Garages.cpp +++ b/src/control/Garages.cpp @@ -1388,7 +1388,7 @@ void CGarages::PrintMessages() CFont::SetBackgroundOff(); CFont::SetCentreSize(SCREEN_SCALE_FROM_RIGHT(50.0f)); CFont::SetCentreOn(); - CFont::SetFontStyle(FONT_BANK); + CFont::SetFontStyle(FONTJAP(FONT_BANK)); CFont::SetColor(CRGBA(0, 0, 0, 255)); #if defined(PS2) || defined (FIX_BUGS) diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp index 4fefe9a9..d4264a05 100644 --- a/src/core/Frontend.cpp +++ b/src/core/Frontend.cpp @@ -576,7 +576,7 @@ void CMenuManager::Draw() if (aScreens[m_nCurrScreen].m_ScreenName[0] != '\0') { CFont::SetRightJustifyOn(); - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONTJAP(FONT_HEADING)); #ifdef PS2_LIKE_MENU CFont::SetColor(CRGBA(0, 0, 0, 255)); CFont::SetScale(MENU_X(MENUHEADER_WIDTH), MENU_Y(1.3f)); @@ -590,7 +590,7 @@ void CMenuManager::Draw() nextYToUse += 24.0f + 10.0f; } - CFont::SetFontStyle(FONT_BANK); + CFont::SetFontStyle(FONTJAP(FONT_BANK)); CFont::SetScale(MENU_X(0.9f * actionTextScaleX), MENU_Y(0.9f * actionTextScaleY)); CFont::SetRightJustifyOff(); // AG used SetAlignment(ALIGN_LEFT); CFont::SetColor(CRGBA(235, 170, 50, FadeIn(255))); @@ -646,7 +646,7 @@ void CMenuManager::Draw() columnWidth = 320; headerHeight = 240; lineHeight = 24; - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONTJAP(FONT_HEADING)); CFont::SetScale(MENU_X(actionTextScaleX = 0.75f), MENU_Y(actionTextScaleY = 0.9f)); CFont::SetCentreOn(); break; @@ -663,7 +663,7 @@ void CMenuManager::Draw() columnWidth = 50; headerHeight = 0; lineHeight = 20; - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONTJAP(FONT_HEADING)); CFont::SetScale(MENU_X(actionTextScaleX = 0.55f), MENU_Y(actionTextScaleY = 0.8f)); CFont::SetRightJustifyOff(); break; @@ -673,7 +673,7 @@ void CMenuManager::Draw() columnWidth = 120; headerHeight = 38; lineHeight = 20; - CFont::SetFontStyle(FONT_BANK); + CFont::SetFontStyle(FONTJAP(FONT_BANK)); CFont::SetScale(MENU_X(actionTextScaleX = 0.45f), MENU_Y(actionTextScaleY = 0.7f)); CFont::SetRightJustifyOff(); break; @@ -685,7 +685,7 @@ void CMenuManager::Draw() columnWidth = 320; headerHeight = 60; lineHeight = 24; - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONTJAP(FONT_HEADING)); CFont::SetScale(MENU_X(actionTextScaleX = 0.75f), MENU_Y(actionTextScaleY = 0.9f)); CFont::SetCentreOn(); break; @@ -693,7 +693,7 @@ void CMenuManager::Draw() columnWidth = 320; headerHeight = 140; lineHeight = 24; - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONTJAP(FONT_HEADING)); CFont::SetScale(MENU_X(actionTextScaleX = 0.75f), MENU_Y(actionTextScaleY = 0.9f)); CFont::SetCentreOn(); break; @@ -701,7 +701,7 @@ void CMenuManager::Draw() columnWidth = 320; headerHeight = 117; lineHeight = 24; - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONTJAP(FONT_HEADING)); CFont::SetScale(MENU_X(actionTextScaleX = 0.75f), MENU_Y(actionTextScaleY = 0.9f)); CFont::SetCentreOn(); break; @@ -710,7 +710,7 @@ void CMenuManager::Draw() columnWidth = 180; headerHeight = 60; lineHeight = 24; - CFont::SetFontStyle(FONT_BANK); + CFont::SetFontStyle(FONTJAP(FONT_BANK)); CFont::SetScale(MENU_X(actionTextScaleX = 0.75f), MENU_Y(actionTextScaleY = 0.9f)); break; #endif @@ -718,7 +718,7 @@ void CMenuManager::Draw() columnWidth = 320; headerHeight = 40; lineHeight = 24; - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONTJAP(FONT_HEADING)); CFont::SetScale(MENU_X(actionTextScaleX = 0.75f), MENU_Y(actionTextScaleY = 0.9f)); CFont::SetCentreOn(); break; @@ -1736,6 +1736,9 @@ void CMenuManager::InitialiseChangedLanguageSettings() case LANGUAGE_RUSSIAN: CFont::ReloadFonts(FONT_LANGSET_RUSSIAN); break; + case LANGUAGE_JAPANESE: + CFont::ReloadFonts(FONT_LANGSET_JAPANESE); + break; default: CFont::ReloadFonts(FONT_LANGSET_EFIGS); break; @@ -2962,6 +2965,12 @@ CMenuManager::ProcessButtonPresses(void) CMenuManager::InitialiseChangedLanguageSettings(); SaveSettings(); break; + case MENUACTION_LANG_JAP: + m_PrefsLanguage = LANGUAGE_JAPANESE; + m_bFrontEnd_ReloadObrTxtGxt = true; + CMenuManager::InitialiseChangedLanguageSettings(); + SaveSettings(); + break; #endif case MENUACTION_POPULATESLOTS_CHANGEMENU: PcSaveHelper.PopulateSlotInfo(); diff --git a/src/core/Frontend.h b/src/core/Frontend.h index 30e4f652..04c24aff 100644 --- a/src/core/Frontend.h +++ b/src/core/Frontend.h @@ -53,6 +53,7 @@ enum eLanguages LANGUAGE_SPANISH, #ifdef MORE_LANGUAGES LANGUAGE_RUSSIAN, + LANGUAGE_JAPANESE, #endif }; @@ -306,6 +307,7 @@ enum eMenuAction MENUACTION_UNK110, #ifdef MORE_LANGUAGES MENUACTION_LANG_RUS, + MENUACTION_LANG_JAP, #endif }; diff --git a/src/core/MenuScreens.h b/src/core/MenuScreens.h index ace6a719..45c5e5d6 100644 --- a/src/core/MenuScreens.h +++ b/src/core/MenuScreens.h @@ -67,6 +67,7 @@ const CMenuScreen aScreens[] = { MENUACTION_LANG_SPA, "FEL_SPA", SAVESLOT_NONE, MENUPAGE_NONE, #ifdef MORE_LANGUAGES MENUACTION_LANG_RUS, "FEL_RUS", SAVESLOT_NONE, MENUPAGE_NONE, + MENUACTION_LANG_JAP, "FEL_JAP", SAVESLOT_NONE, MENUPAGE_NONE, #endif MENUACTION_CHANGEMENU, "FEDS_TB", SAVESLOT_NONE, MENUPAGE_NONE, }, diff --git a/src/render/Font.cpp b/src/render/Font.cpp index 6f336f1e..0544a1b9 100644 --- a/src/render/Font.cpp +++ b/src/render/Font.cpp @@ -6,11 +6,16 @@ CFontDetails &CFont::Details = *(CFontDetails*)0x8F317C; int16 &CFont::NewLine = *(int16*)0x95CC94; +#ifdef MORE_LANGUAGES +CSprite2d CFont::Sprite[4]; +#else CSprite2d *CFont::Sprite = (CSprite2d*)0x95CC04; +#endif #ifdef MORE_LANGUAGES uint8 CFont::LanguageSet = FONT_LANGSET_EFIGS; int32 CFont::Slot = -1; +#define JAP_TERMINATION (0x8000 | '~') int16 CFont::Size[2][3][193] = { { @@ -116,6 +121,24 @@ int16 CFont::Size[3][193] = { #endif }; +int16 Size_jp[] = { + 15, 14, 16, 20, 19, 26, 22, 11, 18, 18, 27, 26, 13, //; 0 + 19, 20, 27, 19, 15, 19, 19, 21, 19, 20, 18, 19, 15, //; 13 + 13, 28, 15, 32, 15, 35, 15, 19, 19, 19, 19, 17, 16, //; 26 + 19, 20, 15, 19, 20, 14, 17, 19, 19, 19, 19, 19, 19, //; 39 + 19, 19, 20, 25, 20, 19, 19, 33, 31, 39, 37, 39, 37, //; 52 + 21, 21, 21, 19, 17, 15, 23, 21, 15, 19, 20, 16, 19, //; 65 + 19, 19, 20, 20, 17, 22, 19, 22, 22, 19, 22, 22, 23, //; 78 + 35, 35, 35, 35, 37, 19, 19, 19, 19, 29, 19, 19, 19, //; 91 + 19, 19, 9, 9, 9, 9, 19, 19, 19, 19, 19, 19, 19, 19, //; 104 + 19, 19, 19, 19, 19, 30, 19, 19, 19, 19, 19, 10, 10, //; 118 + 10, 10, 19, 19, 19, 19, 19, 19, 19, 19, 19, 23, 35, //; 131 + 12, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, //; 144 + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, //; 157 + 19, 19, 19, 11, 19, 19, 19, 19, 19, 19, 19, 19, 19, //; 170 + 19, 19, 19, 19, 19, 19, 19, 19, 19, 21 +}; + wchar foreign_table[128] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -144,6 +167,9 @@ CFont::Initialise(void) case FONT_LANGSET_RUSSIAN: CTxdStore::LoadTxd(slot, "MODELS/FONTS_R.TXD"); break; + case FONT_LANGSET_JAPANESE: + CTxdStore::LoadTxd(slot, "MODELS/FONTS_J.TXD"); + break; } #else CTxdStore::LoadTxd(slot, "MODELS/FONTS.TXD"); @@ -152,7 +178,12 @@ CFont::Initialise(void) CTxdStore::PushCurrentTxd(); CTxdStore::SetCurrentTxd(slot); Sprite[0].SetTexture("font2", "font2_mask"); - Sprite[1].SetTexture("pager", "pager_mask"); + if (LanguageSet == FONT_LANGSET_JAPANESE) { + Sprite[1].SetTexture("FONTJAP", "FONTJAP_mask"); + Sprite[3].SetTexture("FONTJAP", "FONTJAP_mask"); + } + else + Sprite[1].SetTexture("pager", "pager_mask"); Sprite[2].SetTexture("font1", "font1_mask"); SetScale(1.0f, 1.0f); SetSlantRefPoint(SCREEN_WIDTH, 0.0f); @@ -160,8 +191,8 @@ CFont::Initialise(void) SetColor(CRGBA(0xFF, 0xFF, 0xFF, 0)); SetJustifyOff(); SetCentreOff(); - SetWrapx(640.0f); - SetCentreSize(640.0f); + SetWrapx(DEFAULT_SCREEN_WIDTH); + SetCentreSize(DEFAULT_SCREEN_WIDTH); SetBackgroundOff(); SetBackgroundColor(CRGBA(0x80, 0x80, 0x80, 0x80)); SetBackGroundOnlyTextOff(); @@ -181,6 +212,8 @@ CFont::ReloadFonts(uint8 set) Sprite[0].Delete(); Sprite[1].Delete(); Sprite[2].Delete(); + if (LanguageSet == FONT_LANGSET_JAPANESE) + Sprite[3].Delete(); CTxdStore::PushCurrentTxd(); CTxdStore::RemoveTxd(Slot); switch (set) @@ -192,10 +225,18 @@ CFont::ReloadFonts(uint8 set) case FONT_LANGSET_RUSSIAN: CTxdStore::LoadTxd(Slot, "MODELS/FONTS_R.TXD"); break; + case FONT_LANGSET_JAPANESE: + CTxdStore::LoadTxd(Slot, "MODELS/FONTS_J.TXD"); + break; } CTxdStore::SetCurrentTxd(Slot); Sprite[0].SetTexture("font2", "font2_mask"); - Sprite[1].SetTexture("pager", "pager_mask"); + if (set == FONT_LANGSET_JAPANESE) { + Sprite[1].SetTexture("FONTJAP", "FONTJAP_mask"); + Sprite[3].SetTexture("FONTJAP", "FONTJAP_mask"); + } + else + Sprite[1].SetTexture("pager", "pager_mask"); Sprite[2].SetTexture("font1", "font1_mask"); CTxdStore::PopCurrentTxd(); } @@ -209,6 +250,8 @@ CFont::Shutdown(void) Sprite[0].Delete(); Sprite[1].Delete(); Sprite[2].Delete(); + if (LanguageSet == FONT_LANGSET_JAPANESE) + Sprite[3].Delete(); #ifdef MORE_LANGUAGES CTxdStore::RemoveTxdSlot(Slot); Slot = -1; @@ -223,6 +266,8 @@ CFont::InitPerFrame(void) Details.bank = CSprite2d::GetBank(30, Sprite[0].m_pTexture); CSprite2d::GetBank(15, Sprite[1].m_pTexture); CSprite2d::GetBank(15, Sprite[2].m_pTexture); + if (LanguageSet == FONT_LANGSET_JAPANESE) + CSprite2d::GetBank(15, Sprite[3].m_pTexture); SetDropShadowPosition(0); NewLine = 0; } @@ -235,8 +280,13 @@ CFont::PrintChar(float x, float y, wchar c) return; float w = GetCharacterWidth(c) / 32.0f; - float xoff = c & 0xF; - float yoff = c >> 4; + float xoff = c % 16; + float yoff = c / 16; + if (LanguageSet == FONT_LANGSET_JAPANESE && (Details.style == FONT_PAGER || Details.style == FONT_JAPANESE)) { + w = 21.0f; + xoff = (float)(c % 48);// *w / 1024.0f; + yoff = c / 48; + } if(Details.style == FONT_BANK || Details.style == FONT_HEADING){ if(Details.dropShadowPosition != 0){ @@ -260,17 +310,76 @@ CFont::PrintChar(float x, float y, wchar c) (xoff+1.0f)/16.0f - 0.001f, yoff/12.8f, xoff/16.0f, (yoff+1.0f)/12.8f - 0.002f, (xoff+1.0f)/16.0f - 0.001f, (yoff+1.0f)/12.8f - 0.002f); - }else{ + }else if (LanguageSet == FONT_LANGSET_JAPANESE && (Details.style == FONT_PAGER || Details.style == FONT_JAPANESE)) { + if (Details.dropShadowPosition != 0) { + CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank + CRect(x + SCREEN_SCALE_X(Details.dropShadowPosition), + y + SCREEN_SCALE_Y(Details.dropShadowPosition), + x + SCREEN_SCALE_X(Details.dropShadowPosition) + 32.0f * Details.scaleX * 1.0f, + y + SCREEN_SCALE_Y(Details.dropShadowPosition) + 40.0f * Details.scaleY / 2.75f), + Details.dropColor, + xoff * w / 1024.0f, yoff / 25.6f, + xoff * w / 1024.0f + (1.0f / 48.0f) - 0.001f, yoff / 25.6f, + xoff * w / 1024.0f, (yoff + 1.0f) / 25.6f, + xoff * w / 1024.0f + (1.0f / 48.0f) - 0.001f, (yoff + 1.0f) / 25.6f - 0.0001f); + } CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank CRect(x, y, - x + 32.0f * Details.scaleX * w, - y + 32.0f * Details.scaleY * 0.5f), + x + 32.0f * Details.scaleX * 1.0f, + y + 40.0f * Details.scaleY / 2.75f), + Details.color, + xoff * w / 1024.0f, yoff / 25.6f, + xoff * w / 1024.0f + (1.0f / 48.0f) - 0.001f, yoff / 25.6f, + xoff * w / 1024.0f, (yoff + 1.0f) / 25.6f - 0.002f, + xoff * w / 1024.0f + (1.0f / 48.0f) - 0.001f, (yoff + 1.0f) / 25.6f - 0.0001f); + } + else + CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank + CRect(x, y, + x + 32.0f * Details.scaleX * w, + y + 32.0f * Details.scaleY * 0.5f), Details.color, xoff/16.0f, yoff/16.0f, (xoff+w)/16.0f, yoff/16.0f, xoff/16.0f, (yoff+1.0f)/16.0f, (xoff+w)/16.0f - 0.0001f, (yoff+1.0f)/16.0f - 0.0001f); +} + +bool someJapCheck(wchar *a1) +{ + wchar v2; + + v2 = *a1; + if (v2 != 0xE7 + && v2 != 0x124 + && v2 != 0x126 + && v2 != 0x128 + && v2 != 0x104 + && v2 != ',' + && v2 != '>' + && v2 != '!' + && v2 != 0x99 + && v2 != '?' + && v2 != ':') + { + return false; } + return true; +} + +bool sub_511630(wchar *s) +{ + if (*s >= 'A' && *s <= 'Z') + return true; + if (*s >= 'a' && *s <= 'z') + return true; + if (*s >= '0' && *s <= ':') + return true; + if (*s == '(' || *s == ')') + return true; + if (*s == 'D' || *s == '$') + return true; + return false; } void @@ -308,17 +417,19 @@ CFont::PrintString(float xstart, float ystart, wchar *s) for(;;){ if(*s == '\0') return; - int xend = Details.centre ? Details.centreSize : + float xend = Details.centre ? Details.centreSize : Details.rightJustify ? xstart - Details.rightJustifyWrap : Details.wrapX; if(x + GetStringWidth(s) > xend && !first){ + if (LanguageSet == FONT_LANGSET_JAPANESE && someJapCheck(s)) + s--; // flush line float spaceWidth = !Details.justify || Details.centre ? 0.0f : (Details.wrapX - lineLength) / numSpaces; float xleft = Details.centre ? xstart - x/2 : Details.rightJustify ? xstart - x : xstart; - PrintString(xleft, y, start, s, spaceWidth); + PrintString(xleft, y, start, s, spaceWidth, xstart); // reset things lineLength = 0.0f; numSpaces = 0; @@ -327,7 +438,10 @@ CFont::PrintString(float xstart, float ystart, wchar *s) x = 0.0f; else x = xstart; - y += 32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY; + if (LanguageSet == FONT_LANGSET_JAPANESE && (Details.style == FONT_JAPANESE || Details.style == FONT_PAGER)) + y += 32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY; + else + y += 32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY; start = s; }else break; @@ -341,8 +455,32 @@ CFont::PrintString(float xstart, float ystart, wchar *s) numSpaces++; first = false; x += GetStringWidth(s) + GetCharacterSize(*t - ' '); + if (LanguageSet == FONT_LANGSET_JAPANESE && (Details.style == FONT_JAPANESE || Details.style == FONT_PAGER) && sub_511630(s)) + x += 21.0f; lineLength = x; s = t+1; + if (LanguageSet == FONT_LANGSET_JAPANESE && (Details.style == FONT_JAPANESE || Details.style == FONT_PAGER) && !*s) { + x += GetStringWidth(s); + if (sub_511630(s)) + x += 21.0f; + float xleft = Details.centre ? xstart - x / 2 : + Details.rightJustify ? xstart - x : + xstart; + if (PrintString(xleft, y, start, s, 0.0f, xstart)) + { + start = s; + if (!Details.centre && !Details.rightJustify) + x = xstart; + else + x = 0.0f; + + y += 32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY; + numSpaces = 0; + first = true; + lineLength = 0.0f; + } + } + } // print rest if(t[0] == ' ' && t[1] == '\0') @@ -352,7 +490,21 @@ CFont::PrintString(float xstart, float ystart, wchar *s) float xleft = Details.centre ? xstart - x/2 : Details.rightJustify ? xstart - x : xstart; - PrintString(xleft, y, start, s, 0.0f); +#ifdef MORE_LANGUAGES + if (PrintString(xleft, y, start, s, 0.0f, xstart) && LanguageSet == FONT_LANGSET_JAPANESE && (Details.style == FONT_JAPANESE || Details.style == FONT_PAGER)) { + start = s; + if (!Details.centre && !Details.rightJustify) + x = xstart; + else + x = 0.0f; + y += 32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY; + numSpaces = 0; + first = true; + lineLength = 0.0f; + } +#else + PrintString(xleft, y, start, s, 0.0f) +#endif } } @@ -362,8 +514,28 @@ CFont::GetNumberLines(float xstart, float ystart, wchar *s) int n; float x, y; wchar *t; - n = 0; + bool v14 = false; + +#ifdef MORE_LANGUAGES + if (LanguageSet == FONT_LANGSET_JAPANESE) { + t = s; + wchar unused; + while (*t) { + if (*t == JAP_TERMINATION || *t == '~') + t = ParseToken(t, &unused, true); + if (NewLine) { + n++; + NewLine = false; + v14 = true; + } + t++; + } + } +#endif + + if (v14) n--; + if(Details.centre || Details.rightJustify) x = 0.0f; else @@ -371,7 +543,17 @@ CFont::GetNumberLines(float xstart, float ystart, wchar *s) y = ystart; while(*s){ - if(x + GetStringWidth(s) > (Details.centre ? Details.centreSize : Details.wrapX)){ + float f = (Details.centre ? Details.centreSize : Details.wrapX); + if (LanguageSet == FONT_LANGSET_JAPANESE) + { + f -= SCREEN_SCALE_X(21.0f * 2.0f); + } + if(x + GetStringWidth(s) > f){ + if (LanguageSet == FONT_LANGSET_JAPANESE) + { + if (someJapCheck(s)) + s--; + } // reached end of line if(Details.centre || Details.rightJustify) x = 0.0f; @@ -379,19 +561,28 @@ CFont::GetNumberLines(float xstart, float ystart, wchar *s) x = xstart; n++; // Why even? - y += 32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY; + if (LanguageSet == FONT_LANGSET_JAPANESE) + y += 32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY; + else + y += 32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY; }else{ // still space in current line t = GetNextSpace(s); if(*t == '\0'){ // end of string x += GetStringWidth(s); + if ((LanguageSet == FONT_LANGSET_JAPANESE) && sub_511630(s)) + x += 21.0f; n++; s = t; }else{ x += GetStringWidth(s); - x += GetCharacterSize(*t - ' '); + if ((LanguageSet == FONT_LANGSET_JAPANESE) && sub_511630(s)) + x += 21.0f; s = t+1; + x += GetCharacterSize(*t - ' '); + if (LanguageSet == FONT_LANGSET_JAPANESE && !*s) + n++; } } } @@ -409,37 +600,43 @@ CFont::GetTextRect(CRect *rect, float xstart, float ystart, wchar *s) maxlength = 0; numLines = 0; - if(Details.centre || Details.rightJustify) - x = 0.0f; - else - x = xstart; - y = ystart; - while(*s){ - if(x + GetStringWidth(s) > (Details.centre ? Details.centreSize : Details.wrapX)){ - // reached end of line - if(x > maxlength) - maxlength = x; - if(Details.centre || Details.rightJustify) - x = 0.0f; - else - x = xstart; - numLines++; - y += 32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY; - }else{ - // still space in current line - t = GetNextSpace(s); - if(*t == '\0'){ - // end of string - x += GetStringWidth(s); + if (LanguageSet == FONT_LANGSET_JAPANESE) { + numLines = GetNumberLines(xstart, ystart, s); + //maxlength = Details.centreSize; + }else{ + if(Details.centre || Details.rightJustify) + x = 0.0f; + else + x = xstart; + y = ystart; + + while(*s){ + if(x + GetStringWidth(s) > (Details.centre ? Details.centreSize : Details.wrapX)){ + // reached end of line if(x > maxlength) maxlength = x; + if(Details.centre || Details.rightJustify) + x = 0.0f; + else + x = xstart; numLines++; - s = t; + y += 32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY; }else{ - x += GetStringWidth(s); - x += GetCharacterSize(*t - ' '); - s = t+1; + // still space in current line + t = GetNextSpace(s); + if(*t == '\0'){ + // end of string + x += GetStringWidth(s); + if(x > maxlength) + maxlength = x; + numLines++; + s = t; + }else{ + x += GetStringWidth(s); + x += GetCharacterSize(*t - ' '); + s = t+1; + } } } } @@ -448,26 +645,89 @@ CFont::GetTextRect(CRect *rect, float xstart, float ystart, wchar *s) if(Details.backgroundOnlyText){ rect->left = xstart - maxlength/2 - 4.0f; rect->right = xstart + maxlength/2 + 4.0f; - rect->bottom = (32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY) * numLines + - ystart + 2.0f; - rect->top = ystart - 2.0f; + if (LanguageSet == FONT_LANGSET_JAPANESE && (Details.style == FONT_JAPANESE || Details.style == FONT_PAGER)) + { + rect->bottom = (32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY) * numLines + ystart + 1.454545454545455; + rect->top = ystart - 1.454545454545455; + } + else + { + rect->bottom = (32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY) * numLines + ystart + 2.0f; + rect->top = ystart - 2.0f; + } }else{ rect->left = xstart - Details.centreSize*0.5f - 4.0f; rect->right = xstart + Details.centreSize*0.5f + 4.0f; - rect->bottom = (32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY) * numLines + - ystart + 2.0f; - rect->top = ystart - 2.0f; + if (LanguageSet == FONT_LANGSET_JAPANESE && (Details.style == FONT_JAPANESE || Details.style == FONT_PAGER)) + { + rect->bottom = (32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY) * numLines + ystart + 1.454545454545455; + rect->top = ystart - 1.454545454545455; + } + else + { + rect->bottom = (32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY) * numLines + ystart + 2.0f; + rect->top = ystart - 2.0f; + } } }else{ rect->left = xstart - 4.0f; rect->right = Details.wrapX; // WTF? rect->bottom = ystart - 4.0f + 4.0f; - rect->top = (32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY) * numLines + - ystart + 2.0f + 2.0f; + if (LanguageSet == FONT_LANGSET_JAPANESE && (Details.style == FONT_JAPANESE || Details.style == FONT_PAGER)) + rect->top = (32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY) * numLines + ystart + 2.0f + 1.454545454545455; + else + rect->top = (32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY) * numLines + ystart + 2.0f + 2.0f; } } +#ifdef MORE_LANGUAGES +bool +CFont::PrintString(float x, float y, wchar *start, wchar *&end, float spwidth, float japX) +{ + wchar *s, c, unused; + + if (LanguageSet == FONT_LANGSET_JAPANESE) { + float v14 = 0.0f; + for (s = start; s < end; s++) { + if (*s == JAP_TERMINATION || *s == '~') + s = ParseToken(s, &unused, true); + if (NewLine) { + NewLine = false; + break; + } + v14 += GetCharacterSize(*s - ' '); + } + s = start; + if (Details.centre) + { + x = japX - v14 * 0.5; + } + else if (Details.rightJustify) + { + x = japX - v14; + } + } + + for (s = start; s < end; s++) { + if (*s == '~' || (LanguageSet == FONT_LANGSET_JAPANESE && *s == JAP_TERMINATION)) + s = ParseToken(s, &unused); + if (NewLine && LanguageSet == FONT_LANGSET_JAPANESE) { + NewLine = false; + end = s; + return true; + } + c = *s - ' '; + if (Details.slant != 0.0f && LanguageSet != FONT_LANGSET_JAPANESE) + y = (Details.slantRefX - x) * Details.slant + Details.slantRefY; + PrintChar(x, y, c); + x += GetCharacterSize(c); + if (c == 0 && (!NewLine || LanguageSet != FONT_LANGSET_JAPANESE)) // space + x += spwidth; + } + return false; +} +#else void CFont::PrintString(float x, float y, wchar *start, wchar *end, float spwidth) { @@ -485,12 +745,42 @@ CFont::PrintString(float x, float y, wchar *start, wchar *end, float spwidth) x += spwidth; } } +#endif float CFont::GetCharacterWidth(wchar c) { #ifdef MORE_LANGUAGES - if (Details.proportional) + if (CFont::LanguageSet == FONT_LANGSET_JAPANESE) + { + if (!Details.proportional) + return Size[0][Details.style][192]; + if (c <= 94 || Details.style == FONT_HEADING || Details.style == FONT_BANK) { + switch (Details.style) + { + case FONT_JAPANESE: + return Size_jp[c]; + default: + return Size[0][Details.style][c]; + } + } + if (c < 254 && Details.style == FONT_PAGER) + return 29.4f; + + switch (Details.style) + { + case FONT_JAPANESE: + return 29.4f; + case FONT_BANK: + return 10.0f; + case FONT_PAGER: + return 31.5f; + case FONT_HEADING: + return Size[0][Details.style][c]; + } + } + + else if (Details.proportional) return Size[LanguageSet][Details.style][c]; else return Size[LanguageSet][Details.style][192]; @@ -506,7 +796,36 @@ float CFont::GetCharacterSize(wchar c) { #ifdef MORE_LANGUAGES - if(Details.proportional) + + if (CFont::LanguageSet == FONT_LANGSET_JAPANESE) + { + if (!Details.proportional) + return Size[0][Details.style][192] * Details.scaleX; + if (c <= 94 || Details.style == FONT_HEADING || Details.style == FONT_BANK) { + switch (Details.style) + { + case FONT_JAPANESE: + return Size_jp[c] * Details.scaleX; + default: + return Size[0][Details.style][c] * Details.scaleX; + } + } + if (c < 254 && (Details.style == FONT_PAGER)) + return 29.4f * Details.scaleX; + + switch (Details.style) + { + case FONT_JAPANESE: + return 29.4f * Details.scaleX; + case FONT_BANK: + return 10.0f * Details.scaleX; + case FONT_PAGER: + return 31.5f * Details.scaleX; + case FONT_HEADING: + return Size[0][Details.style][c] * Details.scaleX; + } + } + else if(Details.proportional) return Size[LanguageSet][Details.style][c] * Details.scaleX; else return Size[LanguageSet][Details.style][192] * Details.scaleX; @@ -524,15 +843,40 @@ CFont::GetStringWidth(wchar *s, bool spaces) float w; w = 0.0f; - for(; (*s != ' ' || spaces) && *s != '\0'; s++){ - if(*s == '~'){ - s++; - while(*s != '~') s++; - s++; - if(*s == ' ' && !spaces) - break; + + if (LanguageSet == FONT_LANGSET_JAPANESE) + { + do + { + if ((*s != ' ' || spaces) && *s != '\0') { + do { + while (*s == '~' || *s == JAP_TERMINATION) { + s++; + while (!(*s == '~' || *s == JAP_TERMINATION)) s++; + s++; + //if (*s != JAP_TERMINATION && *s != '~') + // ++s; + continue; + } + w += GetCharacterSize(*s - ' '); + //if (*s != JAP_TERMINATION && *s != '~') + ++s; + } while (*s == '~' || *s == JAP_TERMINATION); + } + } while (sub_511630(s)); + } + else + { + for (; (*s != ' ' || spaces) && *s != '\0'; s++) { + if (*s == '~' || (*s == JAP_TERMINATION && LanguageSet == FONT_LANGSET_JAPANESE)) { + s++; + while (!(*s == '~' || (*s == JAP_TERMINATION && LanguageSet == FONT_LANGSET_JAPANESE))) s++; + s++; + if (*s == ' ' && !spaces) + break; + } + w += GetCharacterSize(*s - ' '); } - w += GetCharacterSize(*s - ' '); } return w; } @@ -540,17 +884,116 @@ CFont::GetStringWidth(wchar *s, bool spaces) wchar* CFont::GetNextSpace(wchar *s) { - for(; *s != ' ' && *s != '\0'; s++) - if(*s == '~'){ - s++; - while(*s != '~') s++; - s++; - if(*s == ' ') - break; + if (LanguageSet == FONT_LANGSET_JAPANESE) { + while (*s == ' ' || !*s) { + LABEL_11: + if (!sub_511630(s)) + return s; } + + while (true) + { + if (*s == JAP_TERMINATION || *s == '~') + { + do + ++s; + while (*s != JAP_TERMINATION && *s != '~'); + ++s; + if (*s == ' ') + return s; + } + ++s; + if (*s != JAP_TERMINATION && *s != '~') + goto LABEL_11; + } + return s; + + + //for (; *s != ' ' && *s != '\0';) { + // if (!sub_511630(s)) + // break; + // //for (; *s == '~' || *s == JAP_TERMINATION;s++) { + // // s++; + // // while (!(*s == '~' || *s == JAP_TERMINATION)) s++; + // // s++; + // // if (*s == ' ') + // // return s; + // // if (!sub_511630(s)) + // // return s; + // //} + // while (true) + // { + // if (*s == '~' || *s == JAP_TERMINATION) { + // s++; + // while (*s != '~' || *s == JAP_TERMINATION) s++; + // s++; + // if (*s == ' ') + // return s; + // } + // s++; + // if (!(*s == '~' || *s == JAP_TERMINATION)) + // break; + // } + //} + //return s; + + + for (;*s != ' ' && *s != '\0' && sub_511630(s); s++ ) { + if (*s == '~' || *s == JAP_TERMINATION) + { + s++; + while (*s != '~' && *s != JAP_TERMINATION) s++; + s++; + if (*s == ' ' || ((*s != '~' && *s != JAP_TERMINATION) && !sub_511630(s))) + break; + } + } + } + else + { + for(; *s != ' ' && *s != '\0'; s++) + if(*s == '~' || (*s == JAP_TERMINATION && LanguageSet == FONT_LANGSET_JAPANESE)){ + s++; + while(*s != '~' || (*s == JAP_TERMINATION && LanguageSet == FONT_LANGSET_JAPANESE)) s++; + s++; + if(*s == ' ') + break; + } + } return s; } +#ifdef MORE_LANGUAGES +wchar* +CFont::ParseToken(wchar *s, wchar*, bool japShit) +{ + s++; + if ((Details.color.r || Details.color.g || Details.color.b) && !japShit) { + wchar c = *s; + if (LanguageSet == FONT_LANGSET_JAPANESE) + c &= 0x7FFF; + switch (c) { + case 'N': + case 'n': + NewLine = true; + break; + case 'b': SetColor(CRGBA(128, 167, 243, 255)); break; + case 'g': SetColor(CRGBA(95, 160, 106, 255)); break; + case 'h': SetColor(CRGBA(225, 225, 225, 255)); break; + case 'l': SetColor(CRGBA(0, 0, 0, 255)); break; + case 'p': SetColor(CRGBA(168, 110, 252, 255)); break; + case 'r': SetColor(CRGBA(113, 43, 73, 255)); break; + case 'w': SetColor(CRGBA(175, 175, 175, 255)); break; + case 'y': SetColor(CRGBA(210, 196, 106, 255)); break; + } + } else if (LanguageSet == FONT_LANGSET_JAPANESE) { + if ((*s & 0x7FFF) == 'N' || (*s & 0x7FFF) == 'n') + NewLine = true; + } + while (((LanguageSet != FONT_LANGSET_JAPANESE) || (*s != JAP_TERMINATION)) && *s != '~') s++; + return s + 1; +} +#else wchar* CFont::ParseToken(wchar *s, wchar*) { @@ -573,6 +1016,7 @@ CFont::ParseToken(wchar *s, wchar*) while(*s != '~') s++; return s+1; } +#endif void CFont::DrawFonts(void) @@ -580,6 +1024,8 @@ CFont::DrawFonts(void) CSprite2d::DrawBank(Details.bank); CSprite2d::DrawBank(Details.bank+1); CSprite2d::DrawBank(Details.bank+2); + if (LanguageSet == FONT_LANGSET_JAPANESE) + CSprite2d::DrawBank(Details.bank+3); } wchar @@ -590,6 +1036,40 @@ CFont::character_code(uint8 c) return foreign_table[c-128]; } + +void +CFont::SetScale(float x, float y) +{ + /*if (LanguageSet == FONT_LANGSET_JAPANESE) { + x *= 1.35f; + y *= 1.25f; + }*/ + Details.scaleX = x; + Details.scaleY = y; +} + +void +CFont::SetBackgroundColor(CRGBA col) +{ + Details.backgroundColor = col; +} + +void +CFont::SetColor(CRGBA col) +{ + Details.color = col; + if (Details.alphaFade < 255.0f) + Details.color.a *= Details.alphaFade / 255.0f; +} + +void +CFont::SetDropColor(CRGBA col) +{ + Details.dropColor = col; + if (Details.alphaFade < 255.0f) + Details.dropColor.a *= Details.alphaFade / 255.0f; +} + STARTPATCHES InjectHook(0x500A40, CFont::Initialise, PATCH_JUMP); @@ -599,7 +1079,7 @@ STARTPATCHES InjectHook(0x500F50, (void (*)(float, float, wchar*))CFont::PrintString, PATCH_JUMP); InjectHook(0x501260, CFont::GetNumberLines, PATCH_JUMP); InjectHook(0x5013B0, CFont::GetTextRect, PATCH_JUMP); - InjectHook(0x501730, (void (*)(float, float, wchar*, wchar*, float))CFont::PrintString, PATCH_JUMP); + //InjectHook(0x501730, (void (*)(float, float, wchar*, wchar*, float))CFont::PrintString, PATCH_JUMP); InjectHook(0x5017E0, CFont::GetCharacterWidth, PATCH_JUMP); InjectHook(0x501840, CFont::GetCharacterSize, PATCH_JUMP); InjectHook(0x5018A0, CFont::GetStringWidth, PATCH_JUMP); diff --git a/src/render/Font.h b/src/render/Font.h index 0659dda1..8e7ae16a 100644 --- a/src/render/Font.h +++ b/src/render/Font.h @@ -31,6 +31,9 @@ enum { FONT_BANK, FONT_PAGER, FONT_HEADING, +#ifdef MORE_LANGUAGES + FONT_JAPANESE, +#endif }; enum { @@ -43,21 +46,27 @@ enum { enum { FONT_LANGSET_EFIGS, - FONT_LANGSET_RUSSIAN + FONT_LANGSET_RUSSIAN, + FONT_LANGSET_JAPANESE }; #endif +#define FONTJAP(style) (CFont::LanguageSet == FONT_LANGSET_JAPANESE ? FONT_JAPANESE : style) + class CFont { #ifdef MORE_LANGUAGES static int16 Size[2][3][193]; +public: static uint8 LanguageSet; +private: static int32 Slot; + static CSprite2d Sprite[4]; #else static int16 Size[3][193]; + static CSprite2d* Sprite; //[3] #endif static int16 - static CSprite2d *Sprite; //[3] public: static CFontDetails& Details; @@ -68,17 +77,25 @@ public: static void PrintString(float x, float y, wchar *s); static int GetNumberLines(float xstart, float ystart, wchar *s); static void GetTextRect(CRect *rect, float xstart, float ystart, wchar *s); +#ifdef MORE_LANGUAGES + static bool PrintString(float x, float y, wchar *start, wchar* &end, float spwidth, float japX); +#else static void PrintString(float x, float y, wchar *start, wchar *end, float spwidth); +#endif static float GetCharacterWidth(wchar c); static float GetCharacterSize(wchar c); static float GetStringWidth(wchar *s, bool spaces = false); - static wchar *GetNextSpace(wchar *s); - static wchar *ParseToken(wchar *s, wchar*); + static uint16 *GetNextSpace(wchar *s); +#ifdef MORE_LANGUAGES + static uint16 *ParseToken(wchar *s, wchar*, bool japShit = false); +#else + static uint16 *ParseToken(wchar *s, wchar*); +#endif static void DrawFonts(void); - static wchar character_code(uint8 c); + static uint16 character_code(uint8 c); static CFontDetails GetDetails() { return Details; } - static void SetScale(float x, float y) { Details.scaleX = x; Details.scaleY = y; } + static void SetScale(float x, float y); static void SetSlantRefPoint(float x, float y) { Details.slantRefX = x; Details.slantRefY = y; } static void SetSlant(float s) { Details.slant = s; } static void SetJustifyOn(void) { @@ -137,19 +154,11 @@ public: static void SetRightJustifyWrap(float wrap) { Details.rightJustifyWrap = wrap; } static void SetAlphaFade(float fade) { Details.alphaFade = fade; } static void SetDropShadowPosition(int16 pos) { Details.dropShadowPosition = pos; } + static void SetBackgroundColor(CRGBA col); + static void SetColor(CRGBA col); + static void SetDropColor(CRGBA col); - // TODO: really just CRGBA but that isn't passed correctly - static void SetBackgroundColor(const CRGBA &col) { Details.backgroundColor = col; } - static void SetColor(const CRGBA &col) { - Details.color = col; - if(Details.alphaFade < 255.0f) - Details.color.a *= Details.alphaFade/255.0f; - } - static void SetDropColor(const CRGBA &col) { - Details.dropColor = col; - if(Details.alphaFade < 255.0f) - Details.dropColor.a *= Details.alphaFade/255.0f; - } - +#ifdef MORE_LANGUAGES static void ReloadFonts(uint8 set); +#endif }; diff --git a/src/render/Hud.cpp b/src/render/Hud.cpp index c4aca8e4..3c07039c 100644 --- a/src/render/Hud.cpp +++ b/src/render/Hud.cpp @@ -21,8 +21,11 @@ #include "User.h" #include "World.h" -wchar *CHud::m_HelpMessage = (wchar*)0x86B888; -wchar *CHud::m_LastHelpMessage = (wchar*)0x6E8F28; +//wchar *CHud::m_HelpMessage = (wchar*)0x86B888; +//wchar *CHud::m_LastHelpMessage = (wchar*)0x6E8F28; +wchar CHud::m_HelpMessage[256]; +wchar CHud::m_LastHelpMessage[256]; + int32 &CHud::m_HelpMessageState = *(int32*)0x880E1C; int32 &CHud::m_HelpMessageTimer = *(int32*)0x880FA4; int32 &CHud::m_HelpMessageFadeTimer = *(int32*)0x8F6258; @@ -661,7 +664,7 @@ void CHud::Draw() CFont::SetScale(SCREEN_SCALE_X(0.8f), SCREEN_SCALE_Y(1.35f)); CFont::SetRightJustifyOn(); CFont::SetRightJustifyWrap(0.0f); - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONTJAP(FONT_HEADING)); CFont::SetPropOff(); CFont::SetBackGroundOnlyTextOn(); CFont::SetColor(CRGBA(0, 0, 0, 255)); @@ -702,7 +705,7 @@ void CHud::Draw() CFont::SetCentreOff(); CFont::SetRightJustifyOn(); CFont::SetRightJustifyWrap(0.0f); - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONTJAP(FONT_HEADING)); CFont::SetColor(CRGBA(244, 20, 20, 255)); CFont::SetWrapx(SCREEN_SCALE_X(640.0f)); CFont::SetPropOff(); @@ -857,7 +860,7 @@ void CHud::Draw() else CFont::SetPropOff(); - CFont::SetFontStyle(CTheScripts::IntroTextLines[i].m_nFont); + CFont::SetFontStyle(FONTJAP(CTheScripts::IntroTextLines[i].m_nFont)); CFont::PrintString(SCREEN_SCALE_X(640.0f - CTheScripts::IntroTextLines[i].m_fAtX), SCREEN_SCALE_Y(448.0f - CTheScripts::IntroTextLines[i].m_fAtY), IntroText->m_Text); } } @@ -897,7 +900,7 @@ void CHud::Draw() CFont::SetScale(SCREEN_SCALE_X(0.48f), SCREEN_SCALE_Y(1.120f)); CFont::SetCentreOn(); CFont::SetPropOn(); - CFont::SetFontStyle(FONT_BANK); + CFont::SetFontStyle(FONTJAP(FONT_BANK)); float offsetX = SCREEN_SCALE_X(40.0f) + SCREEN_SCALE_X(8.0f); float center = SCREEN_SCALE_FROM_RIGHT(50.0f) - SCREEN_SCALE_X(8.0f) - offsetX; @@ -1085,12 +1088,17 @@ void CHud::DrawAfterFade() if (CGame::germanGame) CFont::SetScale(SCREEN_SCALE_X(0.52f * 0.85f), SCREEN_SCALE_Y(1.1f * 0.85f)); + else if (CFont::LanguageSet == FONT_LANGSET_JAPANESE) + CFont::SetScale(SCREEN_SCALE_X(0.52f) * 1.35f, SCREEN_SCALE_Y(1.1f) * 1.25f); else CFont::SetScale(SCREEN_SCALE_X(0.52f), SCREEN_SCALE_Y(1.1f)); CFont::SetJustifyOff(); - CFont::SetWrapx(SCREEN_SCALE_X(200.0f + 26.0f - 4.0f)); - CFont::SetFontStyle(FONT_BANK); + if (CFont::LanguageSet == FONT_LANGSET_JAPANESE) + CFont::SetWrapx(SCREEN_SCALE_X(229.0f + 26.0f - 4.0f)); + else + CFont::SetWrapx(SCREEN_SCALE_X(200.0f + 26.0f - 4.0f)); + CFont::SetFontStyle(FONTJAP(FONT_BANK)); CFont::SetBackgroundOn(); CFont::SetBackGroundOnlyTextOff(); CFont::SetBackgroundColor(CRGBA(0, 0, 0, fAlpha * 0.8f)); @@ -1113,7 +1121,7 @@ void CHud::DrawAfterFade() CFont::SetCentreOn(); CFont::SetPropOn(); CFont::SetCentreSize(SCREEN_SCALE_X(600.0f)); - CFont::SetFontStyle(FONT_BANK); + CFont::SetFontStyle(FONTJAP(FONT_BANK)); CFont::SetColor(CRGBA(0, 0, 0, 255)); CFont::PrintString((SCREEN_WIDTH / 2) + SCREEN_SCALE_X(2.0f), (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(84.0f) + SCREEN_SCALE_Y(2.0f), m_BigMessage[3]); @@ -1130,7 +1138,7 @@ void CHud::DrawAfterFade() CFont::SetPropOn(); CFont::SetCentreSize(SCREEN_SCALE_X(620.0f)); CFont::SetColor(CRGBA(0, 0, 0, 255)); - CFont::SetFontStyle(FONT_BANK); + CFont::SetFontStyle(FONTJAP(FONT_BANK)); CFont::PrintString((SCREEN_WIDTH / 2) - SCREEN_SCALE_X(2.0f), (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(84.0f) - SCREEN_SCALE_Y(2.0f), m_BigMessage[4]); @@ -1193,7 +1201,7 @@ void CHud::DrawAfterFade() CFont::SetPropOn(); CFont::SetCentreSize(SCREEN_SCALE_FROM_RIGHT(20.0f)); CFont::SetColor(CRGBA(0, 0, 0, 255)); - CFont::SetFontStyle(FONT_BANK); + CFont::SetFontStyle(FONTJAP(FONT_BANK)); CFont::PrintString(SCREEN_WIDTH / 2 + SCREEN_SCALE_X(2.0f), SCREEN_HEIGHT / 2 - SCREEN_SCALE_Y(20.0f) + SCREEN_SCALE_Y(2.0f), m_BigMessage[5]); diff --git a/src/render/Hud.h b/src/render/Hud.h index d3482ae6..dad3a58d 100644 --- a/src/render/Hud.h +++ b/src/render/Hud.h @@ -35,8 +35,8 @@ class CHud public: static CSprite2d *Sprites; static int32 &SpriteBrightness; - static wchar *m_HelpMessage; - static wchar *m_LastHelpMessage; + static wchar m_HelpMessage[256]; + static wchar m_LastHelpMessage[256]; static int32 &m_HelpMessageState; static int32 &m_HelpMessageTimer; static int32 &m_HelpMessageFadeTimer; diff --git a/src/text/Messages.cpp b/src/text/Messages.cpp index db5b9036..d429ee8a 100644 --- a/src/text/Messages.cpp +++ b/src/text/Messages.cpp @@ -12,6 +12,8 @@ #include "ControllerConfig.h" +#include "Font.h" + tMessage(&CMessages::BriefMessages)[NUMBRIEFMESSAGES] = *(tMessage(*)[NUMBRIEFMESSAGES])*(uintptr*)0x8786E0; tPreviousBrief(&CMessages::PreviousBriefs)[NUMPREVIOUSBRIEFS] = *(tPreviousBrief(*)[NUMPREVIOUSBRIEFS])*(uintptr*)0x713C08; tBigMessage(&CMessages::BIGMessages)[NUMBIGMESSAGES] = *(tBigMessage(*)[NUMBIGMESSAGES])*(uintptr*)0x773628; @@ -53,6 +55,13 @@ CMessages::WideStringCopy(wchar *dst, wchar *src, uint16 size) dst[i] = '\0'; } +wchar jappy(wchar c) +{ + if (CFont::LanguageSet == FONT_LANGSET_JAPANESE) + return c & 0x7fff; + return c; +} + bool CMessages::WideStringCompare(wchar *str1, wchar *str2, uint16 size) { @@ -62,10 +71,10 @@ CMessages::WideStringCompare(wchar *str1, wchar *str2, uint16 size) return false; for (int32 i = 0; i < size; i++) { - if (!str1[i]) + if (!jappy(str1[i])) break; - if (str1[i] != str2[i]) + if (jappy(str1[i]) != jappy(str2[i])) return false; } return true; @@ -371,7 +380,10 @@ CMessages::InsertNumberInString(wchar *str, int32 n1, int32 n2, int32 n3, int32 int32 i = 0; for (int32 c = 0; c < size;) { - if (str[c] == '~' && str[c + 1] == '1' && str[c + 2] == '~') { + if ((CFont::LanguageSet == FONT_LANGSET_JAPANESE && str[c] == (0x8000 | '~') && str[c + 1] == (0x8000 | '1') && str[c + 2] == (0x8000 | '~')) || + (CFont::LanguageSet != FONT_LANGSET_JAPANESE && str[c] == '~' && str[c + 1] == '1' && str[c + 2] == '~')) + { + //if (str[c] == '~' && str[c + 1] == '1' && str[c + 2] == '~') { switch (i) { case 0: sprintf(numStr, "%d", n1); break; case 1: sprintf(numStr, "%d", n2); break; @@ -409,7 +421,10 @@ CMessages::InsertStringInString(wchar *str1, wchar *str2) wchar *_str1 = str1; uint16 i; for (i = 0; i < total_size; ) { - if (*_str1 == '~' && *(_str1 + 1) == 'a' && *(_str1 + 2) == '~') { + if ((CFont::LanguageSet == FONT_LANGSET_JAPANESE && *_str1 == (0x8000 | '~') && *(_str1 + 1) == (0x8000 | 'a') && *(_str1 + 2) == (0x8000 | '~')) + || (CFont::LanguageSet != FONT_LANGSET_JAPANESE && *_str1 == '~' && *(_str1 + 1) == 'a' && *(_str1 + 2) == '~')) + { + //if (*_str1 == '~' && *(_str1 + 1) == 'a' && *(_str1 + 2) == '~') { _str1 += 3; for (int j = 0; j < str2_size; j++) { tempstr[i++] = str2[j]; @@ -440,7 +455,8 @@ CMessages::InsertPlayerControlKeysInString(wchar *str) wchar *_outstr = outstr; for (i = 0; i < strSize;) { - if (str[i] == '~' && str[i + 1] == 'k' && str[i + 2] == '~') { + if ((CFont::LanguageSet == FONT_LANGSET_JAPANESE && str[i] == (0x8000 | '~') && str[i + 1] == (0x8000 | 'k') && str[i + 2] == (0x8000 | '~')) || + (CFont::LanguageSet != FONT_LANGSET_JAPANESE && str[i] == '~' && str[i + 1] == 'k' && str[i + 2] == '~')) { i += 4; for (int32 cont = 0; cont < MAX_CONTROLLERACTIONS; cont++) { uint16 contSize = GetWideStringLength(ControlsManager.m_aActionNames[cont]); diff --git a/src/text/Text.cpp b/src/text/Text.cpp index d0cdb310..ca98c2a5 100644 --- a/src/text/Text.cpp +++ b/src/text/Text.cpp @@ -47,6 +47,9 @@ CText::Load(void) case LANGUAGE_RUSSIAN: sprintf(filename, "RUSSIAN.GXT"); break; + case LANGUAGE_JAPANESE: + sprintf(filename, "JAPANESE.GXT"); + break; #endif } @@ -257,13 +260,15 @@ AsciiToUnicode(const char *src, wchar *dst) while((*dst++ = *src++) != '\0'); } +#include "Game.h" + char* UnicodeToAscii(wchar *src) { static char aStr[256]; int len; for(len = 0; *src != '\0' && len < 256-1; len++, src++) - if(*src < 128) + if(*src < 128 || (CGame::russianGame && *src < 256)) aStr[len] = *src; else aStr[len] = '#'; @@ -321,4 +326,6 @@ STARTPATCHES InjectHook(0x52C120, &CData::Load, PATCH_JUMP); InjectHook(0x52C200, &CData::Unload, PATCH_JUMP); + + InjectHook(0x52C2F0, &UnicodeToAscii, PATCH_JUMP); ENDPATCHES From c9ace44ca8abca62ece0012362b94b115be65e1b Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Tue, 7 Apr 2020 08:20:21 +0300 Subject: [PATCH 2/4] CFont --- src/render/Font.cpp | 6 +++--- src/render/Font.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/render/Font.cpp b/src/render/Font.cpp index 0544a1b9..231008c4 100644 --- a/src/render/Font.cpp +++ b/src/render/Font.cpp @@ -1049,13 +1049,13 @@ CFont::SetScale(float x, float y) } void -CFont::SetBackgroundColor(CRGBA col) +CFont::SetBackgroundColor(const CRGBA &col) { Details.backgroundColor = col; } void -CFont::SetColor(CRGBA col) +CFont::SetColor(const CRGBA &col) { Details.color = col; if (Details.alphaFade < 255.0f) @@ -1063,7 +1063,7 @@ CFont::SetColor(CRGBA col) } void -CFont::SetDropColor(CRGBA col) +CFont::SetDropColor(const CRGBA &col) { Details.dropColor = col; if (Details.alphaFade < 255.0f) diff --git a/src/render/Font.h b/src/render/Font.h index 8e7ae16a..5218e426 100644 --- a/src/render/Font.h +++ b/src/render/Font.h @@ -154,9 +154,9 @@ public: static void SetRightJustifyWrap(float wrap) { Details.rightJustifyWrap = wrap; } static void SetAlphaFade(float fade) { Details.alphaFade = fade; } static void SetDropShadowPosition(int16 pos) { Details.dropShadowPosition = pos; } - static void SetBackgroundColor(CRGBA col); - static void SetColor(CRGBA col); - static void SetDropColor(CRGBA col); + static void SetBackgroundColor(const CRGBA &col); + static void SetColor(const CRGBA &col); + static void SetDropColor(const CRGBA &col); #ifdef MORE_LANGUAGES static void ReloadFonts(uint8 set); From 3e460d94acd6e08301b0be2d4de58fe8f65aff57 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Thu, 16 Apr 2020 00:24:49 +0300 Subject: [PATCH 3/4] More japanese --- src/core/Frontend.cpp | 50 ++--- src/render/Font.cpp | 468 +++++++++++++++++++++++++++++++++++++----- src/render/Font.h | 6 + src/render/Hud.cpp | 7 +- 4 files changed, 449 insertions(+), 82 deletions(-) diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp index 75effc8a..5d5d0af7 100644 --- a/src/core/Frontend.cpp +++ b/src/core/Frontend.cpp @@ -578,7 +578,7 @@ CMenuManager::DisplayHelperText() CFont::SetCentreOn(); CFont::SetScale(SCREEN_SCALE_X(SMALLESTTEXT_X_SCALE), SCREEN_SCALE_Y(SMALLESTTEXT_Y_SCALE)); - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONTJAP(FONT_HEADING)); // TODO: name this cases? switch (m_nHelperTextMsgId) { @@ -846,7 +846,7 @@ CMenuManager::Draw() } #ifdef PS2_LIKE_MENU - CFont::SetFontStyle(FONT_BANK); + CFont::SetFontStyle(FONTJAP(FONT_BANK)); #endif switch (m_nCurrScreen) { @@ -1614,7 +1614,7 @@ CMenuManager::DrawControllerBound(int32 yStart, int32 xStart, int32 unused, int8 } CFont::SetCentreOn(); CFont::SetScale(MENU_X(SMALLESTTEXT_X_SCALE), MENU_Y(SMALLESTTEXT_Y_SCALE)); - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONTJAP(FONT_HEADING)); CFont::SetColor(CRGBA(255, 255, 255, FadeIn(255))); if (m_bKeyChangeNotProcessed) { CFont::PrintString(MENU_X_LEFT_ALIGNED(275.0f), SCREEN_SCALE_FROM_BOTTOM(114.0f), TheText.Get("FET_CIG")); // BACKSPACE TO CLEAR - LMB,RETURN TO CHANGE @@ -1624,7 +1624,7 @@ CMenuManager::DrawControllerBound(int32 yStart, int32 xStart, int32 unused, int8 CFont::SetRightJustifyOff(); CFont::SetScale(MENU_X(SMALLESTTEXT_X_SCALE), MENU_Y(SMALLESTTEXT_Y_SCALE)); - CFont::SetFontStyle(0); + CFont::SetFontStyle(FONTJAP(FONT_BANK)); if (!m_bKeyIsOK) DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_SUCCESS, 0); @@ -1632,24 +1632,24 @@ CMenuManager::DrawControllerBound(int32 yStart, int32 xStart, int32 unused, int8 } else { CFont::SetCentreOn(); CFont::SetScale(MENU_X(SMALLESTTEXT_X_SCALE), MENU_Y(SMALLESTTEXT_Y_SCALE)); - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONTJAP(FONT_HEADING)); CFont::SetColor(CRGBA(255, 255, 255, FadeIn(255))); CFont::PrintString(MENU_X_LEFT_ALIGNED(275.0f), SCREEN_SCALE_FROM_BOTTOM(114.0f), TheText.Get("FET_CIG")); // BACKSPACE TO CLEAR - LMB,RETURN TO CHANGE CFont::SetRightJustifyOff(); CFont::SetScale(MENU_X(SMALLESTTEXT_X_SCALE), MENU_Y(SMALLESTTEXT_Y_SCALE)); - CFont::SetFontStyle(FONT_BANK); + CFont::SetFontStyle(FONTJAP(FONT_BANK)); m_bKeyIsOK = false; m_bKeyChangeNotProcessed = false; } } else if (optionIdx == m_nSelectedListRow) { CFont::SetCentreOn(); CFont::SetScale(MENU_X(SMALLESTTEXT_X_SCALE), MENU_Y(SMALLESTTEXT_Y_SCALE)); - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONTJAP(FONT_HEADING)); CFont::SetColor(CRGBA(55, 55, 55, FadeIn(255))); CFont::PrintString(MENU_X_LEFT_ALIGNED(275.0f), SCREEN_SCALE_FROM_BOTTOM(114.0f), TheText.Get("FET_EIG")); // CANNOT SET A CONTROL FOR THIS ACTION CFont::SetRightJustifyOff(); CFont::SetScale(MENU_X(SMALLESTTEXT_X_SCALE), MENU_Y(SMALLESTTEXT_Y_SCALE)); - CFont::SetFontStyle(FONT_BANK); + CFont::SetFontStyle(FONTJAP(FONT_BANK)); } } } @@ -1739,7 +1739,7 @@ CMenuManager::DrawControllerSetupScreen() CFont::SetColor(CRGBA(0, 0, 0, FadeIn(255))); CFont::SetRightJustifyOn(); CFont::SetScale(MENU_X(MENUHEADER_WIDTH), MENU_Y(MENUHEADER_HEIGHT)); - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONTJAP(FONT_HEADING)); switch (m_ControlMethod) { case CONTROL_STANDARD: CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(MENUHEADER_POS_X), SCREEN_SCALE_FROM_BOTTOM(MENUHEADER_POS_Y), @@ -1807,7 +1807,7 @@ CMenuManager::DrawControllerSetupScreen() CFont::SetColor(CRGBA(235, 170, 50, FadeIn(255))); // List header - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONTJAP(FONT_HEADING)); CFont::SetScale(MENU_X(MENUACTION_SCALE_MULT), MENU_Y(MENUACTION_SCALE_MULT)); CFont::SetRightJustifyOff(); CFont::PrintString(MENU_X_LEFT_ALIGNED(CONTSETUP_COLUMN_1_X), MENU_Y(CONTSETUP_LIST_TOP), TheText.Get("FET_CAC")); @@ -1815,7 +1815,7 @@ CMenuManager::DrawControllerSetupScreen() CFont::PrintString(MENU_X_LEFT_ALIGNED(CONTSETUP_COLUMN_3_X), MENU_Y(CONTSETUP_LIST_TOP), TheText.Get("FET_CCR")); CFont::SetRightJustifyOff(); CFont::SetScale(MENU_X_LEFT_ALIGNED(SMALLESTTEXT_X_SCALE), MENU_Y(SMALLESTTEXT_Y_SCALE)); - CFont::SetFontStyle(FONT_BANK); + CFont::SetFontStyle(FONTJAP(FONT_BANK)); int yStart; if (m_ControlMethod == CONTROL_CLASSIC) yStart = CONTSETUP_LIST_HEADER_HEIGHT + 29; @@ -1904,7 +1904,7 @@ CMenuManager::DrawControllerSetupScreen() } // Back button and it's shadow - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONTJAP(FONT_HEADING)); CFont::SetScale(MENU_X(MENU_TEXT_SIZE_X), MENU_Y(MENU_TEXT_SIZE_Y)); CFont::SetRightJustifyOn(); CFont::SetColor(CRGBA(0, 0, 0, FadeIn(90))); @@ -2162,7 +2162,7 @@ CMenuManager::DrawFrontEndNormal() if (CheckHover(xStart, xStart + optionWidth, optionTop, optionBottom)) hoveredBottomBarOption = i; - CFont::SetFontStyle(FONT_BANK); + CFont::SetFontStyle(FONTJAP(FONT_BANK)); CFont::SetScale(MENU_X(0.35f), MENU_Y(0.7f)); CFont::SetRightJustifyOff(); if (hoveredBottomBarOption == i && hoveredBottomBarOption != curBottomBarOption) @@ -2420,7 +2420,7 @@ CMenuManager::DrawPlayerSetupScreen() CFont::SetColor(CRGBA(0, 0, 0, FadeIn(255))); CFont::SetScale(MENU_X(MENUHEADER_WIDTH), MENU_Y(MENUHEADER_HEIGHT)); CFont::SetRightJustifyOn(); - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONTJAP(FONT_HEADING)); CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(MENUHEADER_POS_X), SCREEN_SCALE_FROM_BOTTOM(MENUHEADER_POS_Y), TheText.Get("FET_PS")); // lstrcpy's changed with strcpy @@ -2515,7 +2515,7 @@ CMenuManager::DrawPlayerSetupScreen() } else { CFont::SetColor(CRGBA(235, 170, 50, FadeIn(255))); } - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONTJAP(FONT_HEADING)); CFont::SetScale(MENU_X(MENUACTION_SCALE_MULT), MENU_Y(MENUACTION_SCALE_MULT)); CFont::SetRightJustifyOn(); CFont::PrintString(MENU_X_RIGHT_ALIGNED(PLAYERSETUP_DATE_COLUMN_RIGHT), MENU_Y(PLAYERSETUP_LIST_TOP), TheText.Get("FES_DAT")); @@ -2534,7 +2534,7 @@ CMenuManager::DrawPlayerSetupScreen() // Skin list CFont::SetRightJustifyOff(); CFont::SetScale(MENU_X(PLAYERSETUP_ROW_TEXT_X_SCALE), MENU_Y(PLAYERSETUP_ROW_TEXT_Y_SCALE)); - CFont::SetFontStyle(FONT_BANK); + CFont::SetFontStyle(FONTJAP(FONT_BANK)); if (m_nSkinsTotal > 0) { for (m_pSelectedSkin = m_pSkinListHead.nextSkin; m_pSelectedSkin->skinId != m_nFirstVisibleRowOnList; m_pSelectedSkin = m_pSelectedSkin->nextSkin); @@ -2688,7 +2688,7 @@ CMenuManager::DrawPlayerSetupScreen() // Big apply button if (strcmp(m_aSkinName, m_PrefsSkinFile) != 0) { - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONTJAP(FONT_HEADING)); switch (m_PrefsLanguage) { case LANGUAGE_FRENCH: CFont::SetScale(MENU_X(1.1f), MENU_Y(1.9f)); @@ -2708,7 +2708,7 @@ CMenuManager::DrawPlayerSetupScreen() CFont::SetRightJustifyOff(); CFont::PrintString(MENU_X_LEFT_ALIGNED(20.0f), MENU_Y(220.0f), TheText.Get("FET_APL")); } - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONTJAP(FONT_HEADING)); CFont::SetScale(MENU_X(SMALLTEXT_X_SCALE), MENU_Y(SMALLTEXT_Y_SCALE)); @@ -2786,7 +2786,7 @@ CMenuManager::DrawPlayerSetupScreen() m_nHoverOption = HOVEROPTION_NOT_HOVERING; } } - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONTJAP(FONT_HEADING)); CFont::SetScale(MENU_X(SMALLTEXT_X_SCALE), MENU_Y(SMALLTEXT_Y_SCALE)); CFont::SetRightJustifyOn(); CFont::SetColor(CRGBA(0, 0, 0, FadeIn(90))); @@ -3146,7 +3146,7 @@ CMenuManager::MessageScreen(const char *text) CFont::SetWrapx(SCREEN_SCALE_FROM_RIGHT(170.0f)); CFont::SetRightJustifyWrap(SCREEN_SCALE_FROM_RIGHT(170.0f)); CSprite2d::DrawRect(CRect(SCREEN_SCALE_X(120.0f), SCREEN_SCALE_Y(150.0f), SCREEN_SCALE_FROM_RIGHT(120.0f), SCREEN_SCALE_FROM_BOTTOM(220.0f)), CRGBA(50, 50, 50, 210)); - CFont::SetFontStyle(FONT_BANK); + CFont::SetFontStyle(FONTJAP(FONT_BANK)); CFont::SetCentreSize(SCREEN_SCALE_X(380.0f)); CFont::SetCentreOn(); CFont::SetColor(CRGBA(255, 217, 106, 255)); @@ -3176,7 +3176,7 @@ void CMenuManager::PrintBriefs() { CFont::SetColor(CRGBA(235, 170, 50, FadeIn(255))); - CFont::SetFontStyle(FONT_BANK); + CFont::SetFontStyle(FONTJAP(FONT_BANK)); CFont::SetRightJustifyOff(); CFont::SetScale(MENU_X(MENU_TEXT_SIZE_X * 0.7), MENU_Y(MENU_TEXT_SIZE_Y * 0.9)); // second mulipliers are double, idk why @@ -3231,7 +3231,7 @@ CMenuManager::PrintErrorMessage() return; CSprite2d::DrawRect(CRect(SCREEN_SCALE_X(20.0f), SCREEN_SCALE_Y(140.0f), SCREEN_SCALE_FROM_RIGHT(20.0f), SCREEN_SCALE_FROM_BOTTOM(120.0f)), CRGBA(64, 16, 16, 224)); - CFont::SetFontStyle(FONT_BANK); + CFont::SetFontStyle(FONTJAP(FONT_BANK)); CFont::SetBackgroundOff(); CFont::SetPropOn(); CFont::SetCentreOff(); @@ -3319,7 +3319,7 @@ CMenuManager::PrintStats() /* CFont::SetColor(CRGBA(0, 0, 0, FadeIn(255))); CFont::SetRightJustifyOn(); - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONTJAP(FONT_HEADING)); CFont::SetScale(MENU_X(MENUHEADER_WIDTH), MENU_Y(MENUHEADER_HEIGHT)); CFont::PrintString(MENU_X_RIGHT_ALIGNED(MENUHEADER_POS_X), SCREEN_SCALE_FROM_BOTTOM(MENUHEADER_POS_Y), TheText.Get(aScreens[m_nCurrScreen].m_ScreenName)); */ @@ -5034,7 +5034,7 @@ CMenuManager::PrintController(void) m_aFrontEndSprites[FE_ARROWS4].Draw(MENU_X_LEFT_ALIGNED(160.0f), MENU_Y(160.0f), MENU_X(235.2f), MENU_Y(175.2f), CRGBA(255, 255, 255, 255)); } - CFont::SetFontStyle(FONT_BANK); // X + CFont::SetFontStyle(FONTJAP(FONT_BANK)); // X // CFont::SetScale(0.4f, 0.4f); CFont::SetScale(MENU_X(SMALLESTTEXT_X_SCALE), MENU_Y(SMALLESTTEXT_Y_SCALE)); // X @@ -5410,7 +5410,7 @@ CMenuManager::PrintMap(void) CRGBA(235, 170, 50, 255)); CFont::SetScale(MENU_X(0.4f), MENU_Y(0.7f)); - CFont::SetFontStyle(FONT_BANK); + CFont::SetFontStyle(FONTJAP(FONT_BANK)); CFont::SetColor(CRGBA(0, 0, 0, FadeIn(255))); float nextX = MENU_X(30.0f), nextY = 95.0f; diff --git a/src/render/Font.cpp b/src/render/Font.cpp index 231008c4..6067a020 100644 --- a/src/render/Font.cpp +++ b/src/render/Font.cpp @@ -345,7 +345,7 @@ CFont::PrintChar(float x, float y, wchar c) (xoff+w)/16.0f - 0.0001f, (yoff+1.0f)/16.0f - 0.0001f); } -bool someJapCheck(wchar *a1) +bool CFont::IsJapanesePunctuation(wchar *a1) { wchar v2; @@ -367,7 +367,7 @@ bool someJapCheck(wchar *a1) return true; } -bool sub_511630(wchar *s) +bool CFont::IsAnsiCharacter(wchar *s) { if (*s >= 'A' && *s <= 'Z') return true; @@ -385,6 +385,196 @@ bool sub_511630(wchar *s) void CFont::PrintString(float xstart, float ystart, wchar *s) { + /* + if (1) + { + wchar* result; // eax + __int16 numSpaces; // bx + wchar* start; // ebp + double v6; // st7 + float v7; // ST2C_4 + float v8; // ST2C_4 + double v9; // st5 + double v10; // st7 + double v11; // st5 + float v12; // ST10_4 + float v13; // ST00_4 + float v14; // ST34_4 + unsigned __int16* v15; // eax + wchar* t; // esi + unsigned __int16 v17; // ax + double v18; // st7 + double v19; // st7 + float v20; // ST34_4 + double v21; // st7 + double v22; // st7 + double v23; // st7 + double xleft_d; // st6 + float xleft; // ST00_4 + float v26; // ST34_4 + float v27; // [esp+24h] [ebp-44h] + float lineLength; // [esp+28h] [ebp-40h] + float v29; // [esp+30h] [ebp-38h] + float x; // [esp+40h] [ebp-28h] + float y; // [esp+44h] [ebp-24h] + char first; // [esp+4Bh] [ebp-1Dh] + CRect v33; // [esp+4Ch] [ebp-1Ch] + + result = s; + if (*s != '*') + { + if (CFont::Details.background == 1) + { + CFont::GetTextRect(&v33, xstart, ystart, s); + CSprite2d::DrawRect(v33, CFont::Details.backgroundColor); + } + numSpaces = 0; + lineLength = 0.0; + start = s; + first = 1; + if (CFont::Details.centre != 1 && CFont::Details.rightJustify != 1) + x = xstart; + else + x = 0.0; + y = ystart; + while (1) + { + while (1) + { + while (1) + { + result = s; + if (!*s) + return;// result; + v27 = CFont::GetStringWidth(s, false); + if (CFont::Details.centre == 1) + v6 = CFont::Details.centreSize; + else + v6 = CFont::Details.rightJustify == 1 ? xstart - CFont::Details.rightJustifyWrap : CFont::Details.wrapX; + v7 = v6; + v8 = v7 - SCREEN_WIDTH * 0.0015625f * 21.0 * 2.0; + if (x + v27 <= v8 || first) + break; + if (someJapCheck(s)) + --s; + if (CFont::Details.justify != 1 || CFont::Details.centre) + v9 = 0.0; + else + v9 = (CFont::Details.wrapX - lineLength) / (double)numSpaces; + v10 = v9; + if (CFont::Details.centre) + { + v11 = xstart - x * 0.5; + } + else if (CFont::Details.rightJustify) + { + v11 = xstart - x; + } + else + { + v11 = xstart; + } + v12 = v10; + v13 = v11; + CFont::PrintString(v13, y, start, s, v12, xstart); + start = s; + if (CFont::Details.centre != 1 && CFont::Details.rightJustify != 1) + x = xstart; + else + x = 0.0; + v14 = 32.0 * CFont::Details.scaleY * 0.3636363636363636 + 2.0 * CFont::Details.scaleY; + numSpaces = 0; + first = 1; + y = v14 + y; + lineLength = 0.0; + } + v15 = CFont::GetNextSpace(s); + t = v15; + v17 = *v15; + if (!v17 || !t[1] && v17 == ' ') + break; + if (!first) + ++numSpaces; + first = 0; + v21 = CFont::GetStringWidth(s, 0); + x = v21 + x; + if (sub_511630(s)) + x = x + 21.0; + s = t; + v22 = CFont::GetCharacterSize(*t - 32); + ++s; + x = v22 + x; + lineLength = x; + if (!*s) + { + v23 = CFont::GetStringWidth(s, 0); + x = v23 + x; + if (sub_511630(s)) + x = x + 21.0; + if (CFont::Details.centre) + { + xleft_d = xstart - x * 0.5; + } + else if (CFont::Details.rightJustify) + { + xleft_d = xstart - x; + } + else + { + xleft_d = xstart; + } + xleft = xleft_d; + if (CFont::PrintString(xleft, y, start, s, 0.0, xstart)) + { + start = s; + if (CFont::Details.centre != 1 && CFont::Details.rightJustify != 1) + x = xstart; + else + x = 0.0; + v26 = 32.0 * CFont::Details.scaleY * 0.3636363636363636 + 2.0 * CFont::Details.scaleY; + numSpaces = 0; + first = 1; + y = v26 + y; + lineLength = 0.0; + } + } + } + if (!t[1] && v17 == ' ') + *t = 0; + v18 = CFont::GetStringWidth(s, 0); + s = t; + x = v18 + x; + if (CFont::Details.centre) + break; + if (CFont::Details.rightJustify) + { + v19 = xstart - x; + LABEL_43: + v29 = v19; + goto LABEL_44; + } + v29 = xstart; + LABEL_44: + if (CFont::PrintString(v29, y, start, s, 0.0, xstart)) + { + start = s; + if (CFont::Details.centre != 1 && CFont::Details.rightJustify != 1) + x = xstart; + else + x = 0.0; + v20 = 32.0 * CFont::Details.scaleY * 0.3636363636363636 + 2.0 * CFont::Details.scaleY; + numSpaces = 0; + first = 1; + y = v20 + y; + lineLength = 0.0; + } + } + v19 = xstart - x * 0.5; + goto LABEL_43; + } + return; + }*/ + CRect rect; int numSpaces; float lineLength; @@ -420,8 +610,10 @@ CFont::PrintString(float xstart, float ystart, wchar *s) float xend = Details.centre ? Details.centreSize : Details.rightJustify ? xstart - Details.rightJustifyWrap : Details.wrapX; + if (LanguageSet == FONT_LANGSET_JAPANESE && (Details.style == FONT_JAPANESE || Details.style == FONT_PAGER)) + xend -= SCREEN_SCALE_X(21.0f * 2.0f); if(x + GetStringWidth(s) > xend && !first){ - if (LanguageSet == FONT_LANGSET_JAPANESE && someJapCheck(s)) + if (LanguageSet == FONT_LANGSET_JAPANESE && IsJapanesePunctuation(s)) s--; // flush line float spaceWidth = !Details.justify || Details.centre ? 0.0f : @@ -455,13 +647,13 @@ CFont::PrintString(float xstart, float ystart, wchar *s) numSpaces++; first = false; x += GetStringWidth(s) + GetCharacterSize(*t - ' '); - if (LanguageSet == FONT_LANGSET_JAPANESE && (Details.style == FONT_JAPANESE || Details.style == FONT_PAGER) && sub_511630(s)) + if (LanguageSet == FONT_LANGSET_JAPANESE && (Details.style == FONT_JAPANESE || Details.style == FONT_PAGER) && IsAnsiCharacter(s)) x += 21.0f; lineLength = x; s = t+1; if (LanguageSet == FONT_LANGSET_JAPANESE && (Details.style == FONT_JAPANESE || Details.style == FONT_PAGER) && !*s) { x += GetStringWidth(s); - if (sub_511630(s)) + if (IsAnsiCharacter(s)) x += 21.0f; float xleft = Details.centre ? xstart - x / 2 : Details.rightJustify ? xstart - x : @@ -518,7 +710,7 @@ CFont::GetNumberLines(float xstart, float ystart, wchar *s) bool v14 = false; #ifdef MORE_LANGUAGES - if (LanguageSet == FONT_LANGSET_JAPANESE) { + if (IsJapanese()) { t = s; wchar unused; while (*t) { @@ -544,14 +736,13 @@ CFont::GetNumberLines(float xstart, float ystart, wchar *s) while(*s){ float f = (Details.centre ? Details.centreSize : Details.wrapX); - if (LanguageSet == FONT_LANGSET_JAPANESE) - { + if (IsJapaneseFont()) f -= SCREEN_SCALE_X(21.0f * 2.0f); - } + if(x + GetStringWidth(s) > f){ if (LanguageSet == FONT_LANGSET_JAPANESE) { - if (someJapCheck(s)) + if (IsJapanesePunctuation(s)) s--; } // reached end of line @@ -571,13 +762,13 @@ CFont::GetNumberLines(float xstart, float ystart, wchar *s) if(*t == '\0'){ // end of string x += GetStringWidth(s); - if ((LanguageSet == FONT_LANGSET_JAPANESE) && sub_511630(s)) + if ((LanguageSet == FONT_LANGSET_JAPANESE) && IsAnsiCharacter(s)) x += 21.0f; n++; s = t; }else{ x += GetStringWidth(s); - if ((LanguageSet == FONT_LANGSET_JAPANESE) && sub_511630(s)) + if ((LanguageSet == FONT_LANGSET_JAPANESE) && IsAnsiCharacter(s)) x += 21.0f; s = t+1; x += GetCharacterSize(*t - ' '); @@ -601,7 +792,7 @@ CFont::GetTextRect(CRect *rect, float xstart, float ystart, wchar *s) maxlength = 0; numLines = 0; - if (LanguageSet == FONT_LANGSET_JAPANESE) { + if (IsJapanese()) { numLines = GetNumberLines(xstart, ystart, s); //maxlength = Details.centreSize; }else{ @@ -645,26 +836,20 @@ CFont::GetTextRect(CRect *rect, float xstart, float ystart, wchar *s) if(Details.backgroundOnlyText){ rect->left = xstart - maxlength/2 - 4.0f; rect->right = xstart + maxlength/2 + 4.0f; - if (LanguageSet == FONT_LANGSET_JAPANESE && (Details.style == FONT_JAPANESE || Details.style == FONT_PAGER)) - { - rect->bottom = (32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY) * numLines + ystart + 1.454545454545455; - rect->top = ystart - 1.454545454545455; - } - else - { + if (IsJapaneseFont()) { + rect->bottom = (32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY) * numLines + ystart + (4.0f / 2.75f); + rect->top = ystart - (4.0f / 2.75f); + } else { rect->bottom = (32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY) * numLines + ystart + 2.0f; rect->top = ystart - 2.0f; } }else{ rect->left = xstart - Details.centreSize*0.5f - 4.0f; rect->right = xstart + Details.centreSize*0.5f + 4.0f; - if (LanguageSet == FONT_LANGSET_JAPANESE && (Details.style == FONT_JAPANESE || Details.style == FONT_PAGER)) - { - rect->bottom = (32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY) * numLines + ystart + 1.454545454545455; - rect->top = ystart - 1.454545454545455; - } - else - { + if (IsJapaneseFont()) { + rect->bottom = (32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY) * numLines + ystart + (4.0f / 2.75f); + rect->top = ystart - (4.0f / 2.75f); + } else { rect->bottom = (32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY) * numLines + ystart + 2.0f; rect->top = ystart - 2.0f; } @@ -674,8 +859,8 @@ CFont::GetTextRect(CRect *rect, float xstart, float ystart, wchar *s) rect->right = Details.wrapX; // WTF? rect->bottom = ystart - 4.0f + 4.0f; - if (LanguageSet == FONT_LANGSET_JAPANESE && (Details.style == FONT_JAPANESE || Details.style == FONT_PAGER)) - rect->top = (32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY) * numLines + ystart + 2.0f + 1.454545454545455; + if (IsJapaneseFont()) + rect->top = (32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY) * numLines + ystart + 2.0f + (4.0f / 2.75f); else rect->top = (32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY) * numLines + ystart + 2.0f + 2.0f; } @@ -710,19 +895,19 @@ CFont::PrintString(float x, float y, wchar *start, wchar *&end, float spwidth, f } for (s = start; s < end; s++) { - if (*s == '~' || (LanguageSet == FONT_LANGSET_JAPANESE && *s == JAP_TERMINATION)) + if (*s == '~' || (IsJapanese() && *s == JAP_TERMINATION)) s = ParseToken(s, &unused); - if (NewLine && LanguageSet == FONT_LANGSET_JAPANESE) { + if (NewLine && IsJapanese()) { NewLine = false; end = s; return true; } c = *s - ' '; - if (Details.slant != 0.0f && LanguageSet != FONT_LANGSET_JAPANESE) + if (Details.slant != 0.0f && !IsJapanese()) y = (Details.slantRefX - x) * Details.slant + Details.slantRefY; PrintChar(x, y, c); x += GetCharacterSize(c); - if (c == 0 && (!NewLine || LanguageSet != FONT_LANGSET_JAPANESE)) // space + if (c == 0 && (!NewLine || !IsJapanese())) // space x += spwidth; } return false; @@ -751,7 +936,7 @@ float CFont::GetCharacterWidth(wchar c) { #ifdef MORE_LANGUAGES - if (CFont::LanguageSet == FONT_LANGSET_JAPANESE) + if (IsJapanese()) { if (!Details.proportional) return Size[0][Details.style][192]; @@ -797,7 +982,7 @@ CFont::GetCharacterSize(wchar c) { #ifdef MORE_LANGUAGES - if (CFont::LanguageSet == FONT_LANGSET_JAPANESE) + if (IsJapanese()) { if (!Details.proportional) return Size[0][Details.style][192] * Details.scaleX; @@ -846,6 +1031,103 @@ CFont::GetStringWidth(wchar *s, bool spaces) if (LanguageSet == FONT_LANGSET_JAPANESE) { + /* unsigned __int16* v2; // ebx + double v3; // st4 + int v4; // edx + double v5; // st7 + unsigned __int16 v6; // ax + unsigned __int16 v7; // ax + double v8; // st3 + float v10; // [esp+0h] [ebp-20h] + float v11; // [esp+4h] [ebp-1Ch] + + v2 = (unsigned __int16*)s; + v10 = 0.0; + do + { + if ((*v2 != ' ' || spaces) && *v2) + { + v3 = CFont::Details.scaleX; + v4 = 193 * (signed __int16)CFont::Details.style; + v5 = 29.4 * CFont::Details.scaleX; + do + { + v6 = *v2; + if (*v2 == 0x807Eu || v6 == '~') + { + do + ++v2; + while (*v2 != 0x807Eu && *v2 != '~'); + ++v2; + goto LABEL_27; + } + v7 = v6 - ' '; + if (CFont::Details.proportional == 1) + { + if (v7 > 94u && CFont::Details.style != FONT_HEADING && CFont::Details.style != FONT_BANK) + { + if (v7 >= 254u || CFont::Details.style != FONT_PAGER) + { + switch (CFont::Details.style) + { + case FONT_JAPANESE: + v8 = v5; + goto LABEL_25; + case FONT_BANK: + v8 = 10.0 * CFont::Details.scaleX; + goto LABEL_25; + case FONT_PAGER: + v8 = 31.5 * CFont::Details.scaleX; + goto LABEL_25; + case FONT_HEADING: + v11 = Size[0][Details.style][v7] * CFont::Details.scaleX; + break; + } + } + else + { + v11 = v5; + } + goto def_510DAD; + } + if (Details.style == FONT_JAPANESE) + v8 = Size_jp[v7] * Details.scaleX; + else + v8 = CFont::Size[0][Details.style][v7] * v3; + } + else + { + v8 = CFont::Size[0][CFont::Details.style][192] * v3; + } + LABEL_25: + v11 = v8; + def_510DAD: + v10 = v10 + v11; + LABEL_27: + if (*v2 != 0x807Eu && *v2 != '~') + ++v2; + } while (*v2 == 0x807Eu || *v2 == '~'); + } + } while (IsAnsiCharacter(v2)); + return v10;*/ + + /*for (;; s++) + { + if (*s == '\0' && (!spaces || (*s == ' ' || !sub_511630(s) && *s != '~' && *s != JAP_TERMINATION))) + return w; + while (*s == '~' || *s == JAP_TERMINATION) { + s++; + while (*s != '~' && *s != JAP_TERMINATION) s++; + s++; + if (*s == ' ' && spaces) + return w; + } + w += GetCharacterSize(*s - ' '); + s++; + if ((*s != '~' && *s != JAP_TERMINATION) && ((*s == ' ' || !sub_511630(s)) && !spaces)) + return w; + }*/ + do { if ((*s != ' ' || spaces) && *s != '\0') { @@ -856,21 +1138,21 @@ CFont::GetStringWidth(wchar *s, bool spaces) s++; //if (*s != JAP_TERMINATION && *s != '~') // ++s; - continue; + //continue; } w += GetCharacterSize(*s - ' '); //if (*s != JAP_TERMINATION && *s != '~') ++s; } while (*s == '~' || *s == JAP_TERMINATION); } - } while (sub_511630(s)); + } while (IsAnsiCharacter(s));//*/ } else { for (; (*s != ' ' || spaces) && *s != '\0'; s++) { - if (*s == '~' || (*s == JAP_TERMINATION && LanguageSet == FONT_LANGSET_JAPANESE)) { + if (*s == '~') { s++; - while (!(*s == '~' || (*s == JAP_TERMINATION && LanguageSet == FONT_LANGSET_JAPANESE))) s++; + while (*s != '~') s++; s++; if (*s == ' ' && !spaces) break; @@ -884,16 +1166,90 @@ CFont::GetStringWidth(wchar *s, bool spaces) wchar* CFont::GetNextSpace(wchar *s) { - if (LanguageSet == FONT_LANGSET_JAPANESE) { - while (*s == ' ' || !*s) { + if (IsJapanese()) { + unsigned __int16* v1; // ebx + + v1 = s; + while (*v1 == ' ' || !*v1) + { + LABEL_11: + if (!IsAnsiCharacter(v1)) + return v1; + } + while (1) + { + if (*v1 == 0x807Eu || *v1 == '~') + { + do + ++v1; + while (*v1 != 0x807Eu && *v1 != '~'); + ++v1; + if (*v1 == ' ') + return v1; + } + ++v1; + if (*v1 != 0x807Eu && *v1 != '~') + goto LABEL_11; + } + + if (*v1 == ' ' || !*v1) + { + if (IsAnsiCharacter(v1)) + { + do + { + if (*v1 == 0x807Eu || *v1 == '~') + { + do + ++v1; + while (*v1 != 0x807Eu && *v1 != '~'); + ++v1; + if (*v1 == ' ') + return v1; + } + ++v1; + if (*v1 != 0x807Eu && *v1 != '~') + if (!IsAnsiCharacter(v1)) + return v1; + } while (*v1 == ' ' || !*v1); + } + } + + /*for (;; s++) + { + if (*s == '\0' || *s == ' ' || (!sub_511630(s) && *s != '~' && *s != JAP_TERMINATION)) + return s; + if (*s == '~' || *s == JAP_TERMINATION) { + s++; + while (*s != '~' && *s != JAP_TERMINATION) s++; + s++; + if (*s == ' ' ) + return s; + } + //s++; + //if (*s == ' ' || (!sub_511630(s) && *s != '~' && *s != JAP_TERMINATION)) + // return s; + }*/ + + /*for (;*s != ' ' && *s != '\0' && sub_511630(s); s++) { + while (*s == '~' || *s == JAP_TERMINATION) { + s++; + while (*s != '~' && *s != JAP_TERMINATION) s++; + s++; + if (*s == ' ' || ((*s != '~' && *s != JAP_TERMINATION) && !sub_511630(s))) + return s; + } + } + return s;*/ + /*while (*s == ' ' || !*s) { LABEL_11: if (!sub_511630(s)) return s; - } + }*/ - while (true) + /*while (*s != ' ' && *s != '\0') { - if (*s == JAP_TERMINATION || *s == '~') + while (*s == JAP_TERMINATION || *s == '~') { do ++s; @@ -903,10 +1259,12 @@ CFont::GetNextSpace(wchar *s) return s; } ++s; - if (*s != JAP_TERMINATION && *s != '~') - goto LABEL_11; + if (!sub_511630(s)) + return s; + //if (*s != JAP_TERMINATION && *s != '~') + // goto LABEL_11; } - return s; + return s;*/ //for (; *s != ' ' && *s != '\0';) { @@ -938,13 +1296,13 @@ CFont::GetNextSpace(wchar *s) //return s; - for (;*s != ' ' && *s != '\0' && sub_511630(s); s++ ) { + for (;*s != ' ' && *s != '\0' && IsAnsiCharacter(s); s++ ) { if (*s == '~' || *s == JAP_TERMINATION) { s++; while (*s != '~' && *s != JAP_TERMINATION) s++; s++; - if (*s == ' ' || ((*s != '~' && *s != JAP_TERMINATION) && !sub_511630(s))) + if (*s == ' ' || ((*s != '~' && *s != JAP_TERMINATION) && !IsAnsiCharacter(s))) break; } } @@ -952,9 +1310,9 @@ CFont::GetNextSpace(wchar *s) else { for(; *s != ' ' && *s != '\0'; s++) - if(*s == '~' || (*s == JAP_TERMINATION && LanguageSet == FONT_LANGSET_JAPANESE)){ + if(*s == '~'){ s++; - while(*s != '~' || (*s == JAP_TERMINATION && LanguageSet == FONT_LANGSET_JAPANESE)) s++; + while(*s != '~') s++; s++; if(*s == ' ') break; @@ -970,7 +1328,7 @@ CFont::ParseToken(wchar *s, wchar*, bool japShit) s++; if ((Details.color.r || Details.color.g || Details.color.b) && !japShit) { wchar c = *s; - if (LanguageSet == FONT_LANGSET_JAPANESE) + if (IsJapanese()) c &= 0x7FFF; switch (c) { case 'N': @@ -986,11 +1344,11 @@ CFont::ParseToken(wchar *s, wchar*, bool japShit) case 'w': SetColor(CRGBA(175, 175, 175, 255)); break; case 'y': SetColor(CRGBA(210, 196, 106, 255)); break; } - } else if (LanguageSet == FONT_LANGSET_JAPANESE) { + } else if (IsJapanese()) { if ((*s & 0x7FFF) == 'N' || (*s & 0x7FFF) == 'n') NewLine = true; } - while (((LanguageSet != FONT_LANGSET_JAPANESE) || (*s != JAP_TERMINATION)) && *s != '~') s++; + while ((!IsJapanese() || (*s != JAP_TERMINATION)) && *s != '~') s++; return s + 1; } #else @@ -1024,7 +1382,7 @@ CFont::DrawFonts(void) CSprite2d::DrawBank(Details.bank); CSprite2d::DrawBank(Details.bank+1); CSprite2d::DrawBank(Details.bank+2); - if (LanguageSet == FONT_LANGSET_JAPANESE) + if (IsJapanese()) CSprite2d::DrawBank(Details.bank+3); } diff --git a/src/render/Font.h b/src/render/Font.h index 5218e426..7c1d089f 100644 --- a/src/render/Font.h +++ b/src/render/Font.h @@ -160,5 +160,11 @@ public: #ifdef MORE_LANGUAGES static void ReloadFonts(uint8 set); + + // japanese stuff + static bool IsAnsiCharacter(wchar* s); + static bool IsJapanesePunctuation(wchar* a1); + static bool IsJapanese() { return LanguageSet == FONT_LANGSET_JAPANESE; } + static bool IsJapaneseFont() { return IsJapanese() && (Details.style == FONT_JAPANESE || Details.style == FONT_PAGER); } #endif }; diff --git a/src/render/Hud.cpp b/src/render/Hud.cpp index 56a024a7..a2db6640 100644 --- a/src/render/Hud.cpp +++ b/src/render/Hud.cpp @@ -21,8 +21,11 @@ #include "User.h" #include "World.h" -//wchar *CHud::m_HelpMessage = (wchar*)0x86B888; -//wchar *CHud::m_LastHelpMessage = (wchar*)0x6E8F28; +wchar CHud::m_HelpMessage[256]; // = (wchar*)0x86B888; +wchar CHud::m_LastHelpMessage[256]; // = (wchar*)0x6E8F28; +uint32 CHud::m_HelpMessageState; // = *(int32*)0x880E1C; +uint32 CHud::m_HelpMessageTimer; // = *(int32*)0x880FA4; +int32 CHud::m_HelpMessageFadeTimer; // = *(int32*)0x8F6258; wchar CHud::m_HelpMessageToPrint[256]; // = (wchar*)0x664480; float CHud::m_fHelpMessageTime; // *(float *)0x8E2C28; bool CHud::m_HelpMessageQuick; // = *(bool*)0x95CCF7; From fe353a7cc9831a09026842106bd3ff0fdb3242b4 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Sun, 26 Apr 2020 23:49:24 +0300 Subject: [PATCH 4/4] Fixes --- src/control/Garages.cpp | 2 +- src/core/Frontend.cpp | 90 +- src/core/Game.cpp | 2 +- src/core/Game.h | 2 +- src/render/Font.cpp | 2599 +++++++++++++++++---------------------- src/render/Font.h | 23 +- src/render/Hud.cpp | 24 +- src/save/PCSave.cpp | 10 +- src/text/Messages.cpp | 1647 +++++++++++++------------ src/text/Text.cpp | 636 +++++----- 10 files changed, 2353 insertions(+), 2682 deletions(-) diff --git a/src/control/Garages.cpp b/src/control/Garages.cpp index 53527503..0367e9bc 100644 --- a/src/control/Garages.cpp +++ b/src/control/Garages.cpp @@ -1390,7 +1390,7 @@ void CGarages::PrintMessages() CFont::SetBackgroundOff(); CFont::SetCentreSize(SCREEN_SCALE_FROM_RIGHT(50.0f)); CFont::SetCentreOn(); - CFont::SetFontStyle(FONTJAP(FONT_BANK)); + CFont::SetFontStyle(FONT_LOCALE(FONT_BANK)); CFont::SetColor(CRGBA(0, 0, 0, 255)); #if defined(PS2) || defined (FIX_BUGS) diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp index f3823f1d..e9125b23 100644 --- a/src/core/Frontend.cpp +++ b/src/core/Frontend.cpp @@ -110,7 +110,7 @@ int8 CMenuManager::m_bFrontEnd_ReloadObrTxtGxt; int32 CMenuManager::m_PrefsMusicVolume = 102; int32 CMenuManager::m_PrefsSfxVolume = 102; -char CMenuManager::m_PrefsSkinFile[256] = "$$\"\""; +char CMenuManager::m_PrefsSkinFile[256] = DEFAULT_SKIN_NAME; int32 CMenuManager::m_KeyPressedCode = -1; @@ -286,7 +286,7 @@ ScaleAndCenterX(float x) CFont::SetColor(CRGBA(0, 0, 0, FadeIn(255))); \ CFont::SetRightJustifyOn(); \ CFont::SetScale(MENU_X(MENUHEADER_WIDTH), MENU_Y(MENUHEADER_HEIGHT)); \ - CFont::SetFontStyle(FONT_HEADING); + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); #define ProcessSlider(value, increaseAction, decreaseAction, hoverStartX, hoverEndX) \ do { \ @@ -596,7 +596,7 @@ CMenuManager::DisplayHelperText() CFont::SetCentreOn(); CFont::SetScale(SCREEN_SCALE_X(SMALLESTTEXT_X_SCALE), SCREEN_SCALE_Y(SMALLESTTEXT_Y_SCALE)); - CFont::SetFontStyle(FONTJAP(FONT_HEADING)); + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); // TODO: name this cases? switch (m_nHelperTextMsgId) { @@ -732,7 +732,7 @@ CMenuManager::Draw() nextYToUse += 24.0f + 10.0f; } - CFont::SetFontStyle(FONTJAP(FONT_BANK)); + CFont::SetFontStyle(FONT_LOCALE(FONT_BANK)); CFont::SetScale(MENU_X(MENUACTION_SCALE_MULT * MENU_TEXT_SIZE_X), MENU_Y(MENUACTION_SCALE_MULT * MENU_TEXT_SIZE_Y)); CFont::SetRightJustifyOff(); CFont::SetColor(CRGBA(235, 170, 50, FadeIn(255))); @@ -788,7 +788,7 @@ CMenuManager::Draw() columnWidth = 320; headerHeight = 240; lineHeight = 24; - CFont::SetFontStyle(FONTJAP(FONT_HEADING)); + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); CFont::SetScale(MENU_X(MENU_TEXT_SIZE_X = BIGTEXT_X_SCALE), MENU_Y(MENU_TEXT_SIZE_Y = BIGTEXT_Y_SCALE)); CFont::SetCentreOn(); break; @@ -805,7 +805,7 @@ CMenuManager::Draw() columnWidth = 50; headerHeight = 0; lineHeight = 20; - CFont::SetFontStyle(FONTJAP(FONT_HEADING)); + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); CFont::SetScale(MENU_X(MENU_TEXT_SIZE_X = MEDIUMTEXT_X_SCALE), MENU_Y(MENU_TEXT_SIZE_Y = MEDIUMTEXT_Y_SCALE)); CFont::SetRightJustifyOff(); break; @@ -815,7 +815,7 @@ CMenuManager::Draw() columnWidth = 120; headerHeight = 38; lineHeight = 20; - CFont::SetFontStyle(FONTJAP(FONT_BANK)); + CFont::SetFontStyle(FONT_LOCALE(FONT_BANK)); CFont::SetScale(MENU_X(MENU_TEXT_SIZE_X = SMALLTEXT_X_SCALE), MENU_Y(MENU_TEXT_SIZE_Y = SMALLTEXT_Y_SCALE)); CFont::SetRightJustifyOff(); break; @@ -827,7 +827,7 @@ CMenuManager::Draw() columnWidth = 320; headerHeight = 60; lineHeight = 24; - CFont::SetFontStyle(FONTJAP(FONT_HEADING)); + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); CFont::SetScale(MENU_X(MENU_TEXT_SIZE_X = BIGTEXT_X_SCALE), MENU_Y(MENU_TEXT_SIZE_Y = BIGTEXT_Y_SCALE)); CFont::SetCentreOn(); break; @@ -835,7 +835,7 @@ CMenuManager::Draw() columnWidth = 320; headerHeight = 140; lineHeight = 24; - CFont::SetFontStyle(FONTJAP(FONT_HEADING)); + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); CFont::SetScale(MENU_X(MENU_TEXT_SIZE_X = BIGTEXT_X_SCALE), MENU_Y(MENU_TEXT_SIZE_Y = BIGTEXT_Y_SCALE)); CFont::SetCentreOn(); break; @@ -843,7 +843,7 @@ CMenuManager::Draw() columnWidth = 320; headerHeight = 117; lineHeight = 24; - CFont::SetFontStyle(FONTJAP(FONT_HEADING)); + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); CFont::SetScale(MENU_X(MENU_TEXT_SIZE_X = BIGTEXT_X_SCALE), MENU_Y(MENU_TEXT_SIZE_Y = BIGTEXT_Y_SCALE)); CFont::SetCentreOn(); break; @@ -852,7 +852,7 @@ CMenuManager::Draw() columnWidth = 180; headerHeight = 60; lineHeight = 24; - CFont::SetFontStyle(FONTJAP(FONT_BANK)); + CFont::SetFontStyle(FONT_LOCALE(FONT_BANK)); CFont::SetScale(MENU_X(MENU_TEXT_SIZE_X = BIGTEXT_X_SCALE), MENU_Y(MENU_TEXT_SIZE_Y = BIGTEXT_Y_SCALE)); break; #endif @@ -860,14 +860,14 @@ CMenuManager::Draw() columnWidth = 320; headerHeight = 40; lineHeight = 24; - CFont::SetFontStyle(FONTJAP(FONT_HEADING)); + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); CFont::SetScale(MENU_X(MENU_TEXT_SIZE_X = BIGTEXT_X_SCALE), MENU_Y(MENU_TEXT_SIZE_Y = BIGTEXT_Y_SCALE)); CFont::SetCentreOn(); break; } #ifdef PS2_LIKE_MENU - CFont::SetFontStyle(FONTJAP(FONT_BANK)); + CFont::SetFontStyle(FONT_LOCALE(FONT_BANK)); #endif switch (m_nCurrScreen) { @@ -1580,7 +1580,12 @@ CMenuManager::DrawControllerBound(int32 yStart, int32 xStart, int32 unused, int8 nextX += CFont::GetStringWidth(seperator, true) + bindingMargin; } CFont::PrintString(nextX, nextY, settingText); - nextX += CFont::GetStringWidth(settingText, true) + bindingMargin; +#ifdef MORE_LANGUAGES + if (CFont::IsJapanese()) + nextX += CFont::GetStringWidth_Jap(settingText) + bindingMargin; + else +#endif + nextX += CFont::GetStringWidth(settingText, true) + bindingMargin; } } if (controllerAction == -1) { @@ -1629,7 +1634,7 @@ CMenuManager::DrawControllerBound(int32 yStart, int32 xStart, int32 unused, int8 } CFont::SetCentreOn(); CFont::SetScale(MENU_X(SMALLESTTEXT_X_SCALE), MENU_Y(SMALLESTTEXT_Y_SCALE)); - CFont::SetFontStyle(FONTJAP(FONT_HEADING)); + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); CFont::SetColor(CRGBA(255, 255, 255, FadeIn(255))); if (m_bKeyChangeNotProcessed) { CFont::PrintString(MENU_X_LEFT_ALIGNED(275.0f), SCREEN_SCALE_FROM_BOTTOM(114.0f), TheText.Get("FET_CIG")); // BACKSPACE TO CLEAR - LMB,RETURN TO CHANGE @@ -1639,7 +1644,7 @@ CMenuManager::DrawControllerBound(int32 yStart, int32 xStart, int32 unused, int8 CFont::SetRightJustifyOff(); CFont::SetScale(MENU_X(SMALLESTTEXT_X_SCALE), MENU_Y(SMALLESTTEXT_Y_SCALE)); - CFont::SetFontStyle(FONTJAP(FONT_BANK)); + CFont::SetFontStyle(FONT_LOCALE(FONT_BANK)); if (!m_bKeyIsOK) DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_SUCCESS, 0); @@ -1647,24 +1652,24 @@ CMenuManager::DrawControllerBound(int32 yStart, int32 xStart, int32 unused, int8 } else { CFont::SetCentreOn(); CFont::SetScale(MENU_X(SMALLESTTEXT_X_SCALE), MENU_Y(SMALLESTTEXT_Y_SCALE)); - CFont::SetFontStyle(FONTJAP(FONT_HEADING)); + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); CFont::SetColor(CRGBA(255, 255, 255, FadeIn(255))); CFont::PrintString(MENU_X_LEFT_ALIGNED(275.0f), SCREEN_SCALE_FROM_BOTTOM(114.0f), TheText.Get("FET_CIG")); // BACKSPACE TO CLEAR - LMB,RETURN TO CHANGE CFont::SetRightJustifyOff(); CFont::SetScale(MENU_X(SMALLESTTEXT_X_SCALE), MENU_Y(SMALLESTTEXT_Y_SCALE)); - CFont::SetFontStyle(FONTJAP(FONT_BANK)); + CFont::SetFontStyle(FONT_LOCALE(FONT_BANK)); m_bKeyIsOK = false; m_bKeyChangeNotProcessed = false; } } else if (optionIdx == m_nSelectedListRow) { CFont::SetCentreOn(); CFont::SetScale(MENU_X(SMALLESTTEXT_X_SCALE), MENU_Y(SMALLESTTEXT_Y_SCALE)); - CFont::SetFontStyle(FONTJAP(FONT_HEADING)); + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); CFont::SetColor(CRGBA(55, 55, 55, FadeIn(255))); CFont::PrintString(MENU_X_LEFT_ALIGNED(275.0f), SCREEN_SCALE_FROM_BOTTOM(114.0f), TheText.Get("FET_EIG")); // CANNOT SET A CONTROL FOR THIS ACTION CFont::SetRightJustifyOff(); CFont::SetScale(MENU_X(SMALLESTTEXT_X_SCALE), MENU_Y(SMALLESTTEXT_Y_SCALE)); - CFont::SetFontStyle(FONTJAP(FONT_BANK)); + CFont::SetFontStyle(FONT_LOCALE(FONT_BANK)); } } } @@ -1819,7 +1824,7 @@ CMenuManager::DrawControllerSetupScreen() CFont::SetColor(CRGBA(235, 170, 50, FadeIn(255))); // List header - CFont::SetFontStyle(FONTJAP(FONT_HEADING)); + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); CFont::SetScale(MENU_X(MENUACTION_SCALE_MULT), MENU_Y(MENUACTION_SCALE_MULT)); CFont::SetRightJustifyOff(); CFont::PrintString(MENU_X_LEFT_ALIGNED(CONTSETUP_COLUMN_1_X), MENU_Y(CONTSETUP_LIST_TOP), TheText.Get("FET_CAC")); @@ -1827,7 +1832,7 @@ CMenuManager::DrawControllerSetupScreen() CFont::PrintString(MENU_X_LEFT_ALIGNED(CONTSETUP_COLUMN_3_X), MENU_Y(CONTSETUP_LIST_TOP), TheText.Get("FET_CCR")); CFont::SetRightJustifyOff(); CFont::SetScale(MENU_X_LEFT_ALIGNED(SMALLESTTEXT_X_SCALE), MENU_Y(SMALLESTTEXT_Y_SCALE)); - CFont::SetFontStyle(FONTJAP(FONT_BANK)); + CFont::SetFontStyle(FONT_LOCALE(FONT_BANK)); int yStart; if (m_ControlMethod == CONTROL_CLASSIC) yStart = CONTSETUP_LIST_HEADER_HEIGHT + 29; @@ -1916,7 +1921,7 @@ CMenuManager::DrawControllerSetupScreen() } // Back button and it's shadow - CFont::SetFontStyle(FONTJAP(FONT_HEADING)); + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); CFont::SetScale(MENU_X(MENU_TEXT_SIZE_X), MENU_Y(MENU_TEXT_SIZE_Y)); CFont::SetRightJustifyOn(); CFont::SetColor(CRGBA(0, 0, 0, FadeIn(90))); @@ -2174,7 +2179,7 @@ CMenuManager::DrawFrontEndNormal() if (CheckHover(xStart, xStart + optionWidth, optionTop, optionBottom)) hoveredBottomBarOption = i; - CFont::SetFontStyle(FONTJAP(FONT_BANK)); + CFont::SetFontStyle(FONT_LOCALE(FONT_BANK)); CFont::SetScale(MENU_X(0.35f), MENU_Y(0.7f)); CFont::SetRightJustifyOff(); if (hoveredBottomBarOption == i && hoveredBottomBarOption != curBottomBarOption) @@ -2442,7 +2447,7 @@ CMenuManager::DrawPlayerSetupScreen() m_pSelectedSkin->nextSkin = new tSkinInfo; m_pSelectedSkin = m_pSelectedSkin->nextSkin; m_pSelectedSkin->skinId = 0; - strcpy(m_pSelectedSkin->skinNameOriginal, "$$\"\""); + strcpy(m_pSelectedSkin->skinNameOriginal, DEFAULT_SKIN_NAME); strcpy(m_pSelectedSkin->skinNameDisplayed, UnicodeToAscii(TheText.Get("FET_DSN"))); int nextSkinId = 1; m_pSelectedSkin->nextSkin = nil; @@ -2451,7 +2456,7 @@ CMenuManager::DrawPlayerSetupScreen() SYSTEMTIME SystemTime; HANDLE handle = FindFirstFile("skins\\*.bmp", &FindFileData); for (int i = 1; handle != INVALID_HANDLE_VALUE && i; i = FindNextFile(handle, &FindFileData)) { - if (strncmp(FindFileData.cFileName, "$$\"\"", 5) != 0) { + if (strncmp(FindFileData.cFileName, DEFAULT_SKIN_NAME, 5) != 0) { m_pSelectedSkin->nextSkin = new tSkinInfo; m_pSelectedSkin = m_pSelectedSkin->nextSkin; m_pSelectedSkin->skinId = nextSkinId; @@ -2525,7 +2530,7 @@ CMenuManager::DrawPlayerSetupScreen() } else { CFont::SetColor(CRGBA(235, 170, 50, FadeIn(255))); } - CFont::SetFontStyle(FONTJAP(FONT_HEADING)); + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); CFont::SetScale(MENU_X(MENUACTION_SCALE_MULT), MENU_Y(MENUACTION_SCALE_MULT)); CFont::SetRightJustifyOn(); CFont::PrintString(MENU_X_RIGHT_ALIGNED(PLAYERSETUP_DATE_COLUMN_RIGHT), MENU_Y(PLAYERSETUP_LIST_TOP), TheText.Get("FES_DAT")); @@ -2544,7 +2549,7 @@ CMenuManager::DrawPlayerSetupScreen() // Skin list CFont::SetRightJustifyOff(); CFont::SetScale(MENU_X(PLAYERSETUP_ROW_TEXT_X_SCALE), MENU_Y(PLAYERSETUP_ROW_TEXT_Y_SCALE)); - CFont::SetFontStyle(FONTJAP(FONT_BANK)); + CFont::SetFontStyle(FONT_LOCALE(FONT_BANK)); if (m_nSkinsTotal > 0) { for (m_pSelectedSkin = m_pSkinListHead.nextSkin; m_pSelectedSkin->skinId != m_nFirstVisibleRowOnList; m_pSelectedSkin = m_pSelectedSkin->nextSkin); @@ -2698,7 +2703,7 @@ CMenuManager::DrawPlayerSetupScreen() // Big apply button if (strcmp(m_aSkinName, m_PrefsSkinFile) != 0) { - CFont::SetFontStyle(FONTJAP(FONT_HEADING)); + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); switch (m_PrefsLanguage) { case LANGUAGE_FRENCH: CFont::SetScale(MENU_X(1.1f), MENU_Y(1.9f)); @@ -2718,7 +2723,7 @@ CMenuManager::DrawPlayerSetupScreen() CFont::SetRightJustifyOff(); CFont::PrintString(MENU_X_LEFT_ALIGNED(20.0f), MENU_Y(220.0f), TheText.Get("FET_APL")); } - CFont::SetFontStyle(FONTJAP(FONT_HEADING)); + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); CFont::SetScale(MENU_X(SMALLTEXT_X_SCALE), MENU_Y(SMALLTEXT_Y_SCALE)); @@ -2796,7 +2801,7 @@ CMenuManager::DrawPlayerSetupScreen() m_nHoverOption = HOVEROPTION_NOT_HOVERING; } } - CFont::SetFontStyle(FONTJAP(FONT_HEADING)); + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); CFont::SetScale(MENU_X(SMALLTEXT_X_SCALE), MENU_Y(SMALLTEXT_Y_SCALE)); CFont::SetRightJustifyOn(); CFont::SetColor(CRGBA(0, 0, 0, FadeIn(90))); @@ -2898,6 +2903,8 @@ CMenuManager::InitialiseChangedLanguageSettings() CGame::frenchGame = false; CGame::germanGame = false; #ifdef MORE_LANGUAGES + CGame::russianGame = false; + CGame::japaneseGame = false; switch (m_PrefsLanguage) { case LANGUAGE_POLISH: CFont::ReloadFonts(FONT_LANGSET_POLISH); @@ -2922,16 +2929,17 @@ CMenuManager::InitialiseChangedLanguageSettings() CGame::germanGame = true; break; #ifdef MORE_LANGUAGES - case LANGUAGE_POLISH: - CGame::polishGame = true; - break; case LANGUAGE_RUSSIAN: CGame::russianGame = true; break; + case LANGUAGE_JAPANESE: + CGame::japaneseGame = true; + break; #endif default: break; } + PcSaveHelper.PopulateSlotInfo(); } } @@ -3087,8 +3095,8 @@ CMenuManager::LoadSettings() if (!SkinFound) { OutputDebugString("Default skin set as no other skins are available OR saved skin not found!"); - strcpy(m_PrefsSkinFile, "$$\"\""); - strcpy(m_aSkinName, "$$\"\""); + strcpy(m_PrefsSkinFile, DEFAULT_SKIN_NAME); + strcpy(m_aSkinName, DEFAULT_SKIN_NAME); } } @@ -3162,7 +3170,7 @@ CMenuManager::MessageScreen(const char *text) CFont::SetWrapx(SCREEN_SCALE_FROM_RIGHT(170.0f)); CFont::SetRightJustifyWrap(SCREEN_SCALE_FROM_RIGHT(170.0f)); CSprite2d::DrawRect(CRect(SCREEN_SCALE_X(120.0f), SCREEN_SCALE_Y(150.0f), SCREEN_SCALE_FROM_RIGHT(120.0f), SCREEN_SCALE_FROM_BOTTOM(220.0f)), CRGBA(50, 50, 50, 210)); - CFont::SetFontStyle(FONTJAP(FONT_BANK)); + CFont::SetFontStyle(FONT_LOCALE(FONT_BANK)); CFont::SetCentreSize(SCREEN_SCALE_X(380.0f)); CFont::SetCentreOn(); CFont::SetColor(CRGBA(255, 217, 106, 255)); @@ -3192,7 +3200,7 @@ void CMenuManager::PrintBriefs() { CFont::SetColor(CRGBA(235, 170, 50, FadeIn(255))); - CFont::SetFontStyle(FONTJAP(FONT_BANK)); + CFont::SetFontStyle(FONT_LOCALE(FONT_BANK)); CFont::SetRightJustifyOff(); CFont::SetScale(MENU_X(MENU_TEXT_SIZE_X * 0.7), MENU_Y(MENU_TEXT_SIZE_Y * 0.9)); // second mulipliers are double, idk why @@ -3247,7 +3255,7 @@ CMenuManager::PrintErrorMessage() return; CSprite2d::DrawRect(CRect(SCREEN_SCALE_X(20.0f), SCREEN_SCALE_Y(140.0f), SCREEN_SCALE_FROM_RIGHT(20.0f), SCREEN_SCALE_FROM_BOTTOM(120.0f)), CRGBA(64, 16, 16, 224)); - CFont::SetFontStyle(FONTJAP(FONT_BANK)); + CFont::SetFontStyle(FONT_LOCALE(FONT_BANK)); CFont::SetBackgroundOff(); CFont::SetPropOn(); CFont::SetCentreOff(); @@ -5063,7 +5071,7 @@ CMenuManager::PrintController(void) m_aFrontEndSprites[FE_ARROWS4].Draw(MENU_X_LEFT_ALIGNED(160.0f), MENU_Y(160.0f), MENU_X(235.2f), MENU_Y(175.2f), CRGBA(255, 255, 255, 255)); } - CFont::SetFontStyle(FONTJAP(FONT_BANK)); // X + CFont::SetFontStyle(FONT_LOCALE(FONT_BANK)); // X // CFont::SetScale(0.4f, 0.4f); CFont::SetScale(MENU_X(SMALLESTTEXT_X_SCALE), MENU_Y(SMALLESTTEXT_Y_SCALE)); // X @@ -5440,7 +5448,7 @@ CMenuManager::PrintMap(void) CRGBA(235, 170, 50, 255)); CFont::SetScale(MENU_X(0.4f), MENU_Y(0.7f)); - CFont::SetFontStyle(FONTJAP(FONT_BANK)); + CFont::SetFontStyle(FONT_LOCALE(FONT_BANK)); CFont::SetColor(CRGBA(0, 0, 0, FadeIn(255))); float nextX = MENU_X(30.0f), nextY = 95.0f; diff --git a/src/core/Game.cpp b/src/core/Game.cpp index 8633d222..3053c761 100644 --- a/src/core/Game.cpp +++ b/src/core/Game.cpp @@ -97,8 +97,8 @@ bool CGame::noProstitutes; bool CGame::playingIntro; char CGame::aDatFile[32]; #ifdef MORE_LANGUAGES -bool CGame::polishGame = false; bool CGame::russianGame = false; +bool CGame::japaneseGame = false; #endif int gameTxdSlot; diff --git a/src/core/Game.h b/src/core/Game.h index 01f5f0e9..48f31abc 100644 --- a/src/core/Game.h +++ b/src/core/Game.h @@ -17,8 +17,8 @@ public: static bool frenchGame; static bool germanGame; #ifdef MORE_LANGUAGES - static bool polishGame; static bool russianGame; + static bool japaneseGame; #endif static bool noProstitutes; static bool playingIntro; diff --git a/src/render/Font.cpp b/src/render/Font.cpp index 458974ae..ef665fae 100644 --- a/src/render/Font.cpp +++ b/src/render/Font.cpp @@ -1,1481 +1,1118 @@ -#include "common.h" - -#include "Sprite2d.h" -#include "TxdStore.h" -#include "Font.h" - -CFontDetails CFont::Details; -int16 CFont::NewLine; -CSprite2d CFont::Sprite[MAX_FONTS]; - -#ifdef MORE_LANGUAGES -uint8 CFont::LanguageSet = FONT_LANGSET_EFIGS; -int32 CFont::Slot = -1; -#define JAP_TERMINATION (0x8000 | '~') - -int16 CFont::Size[LANGSET_MAX][MAX_FONTS][193] = { - { -#else -int16 CFont::Size[MAX_FONTS][193] = { -#endif - { - 13, 12, 31, 35, 23, 35, 31, 9, 14, 15, 25, 30, 11, 17, 13, 31, - 23, 16, 22, 21, 24, 23, 23, 20, 23, 22, 10, 35, 26, 26, 26, 26, - 30, 26, 24, 23, 24, 22, 21, 24, 26, 10, 20, 26, 22, 29, 26, 25, - 23, 25, 24, 24, 22, 25, 24, 29, 29, 23, 25, 37, 22, 37, 35, 37, - 35, 21, 22, 21, 21, 22, 13, 22, 21, 10, 16, 22, 11, 32, 21, 21, - 23, 22, 16, 20, 14, 21, 20, 30, 25, 21, 21, 33, 33, 33, 33, 35, - 27, 27, 27, 27, 32, 24, 23, 23, 23, 23, 11, 11, 11, 11, 26, 26, - 26, 26, 26, 26, 26, 25, 26, 21, 21, 21, 21, 32, 23, 22, 22, 22, - 22, 11, 11, 11, 11, 22, 22, 22, 22, 22, 22, 22, 22, 26, 21, 24, - 12, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, - 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 18, 26, 26, - 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, - 20 - }, - - { - 13, 9, 21, 35, 23, 35, 35, 11, 35, 35, 25, 35, 11, 17, 13, 33, - 28, 14, 22, 21, 24, 23, 23, 21, 23, 22, 10, 35, 13, 35, 13, 33, - 5, 25, 22, 23, 24, 21, 21, 24, 24, 9, 20, 24, 21, 27, 25, 25, - 22, 25, 23, 20, 23, 23, 23, 31, 23, 23, 23, 37, 33, 37, 35, 37, - 35, 21, 19, 19, 21, 19, 17, 21, 21, 8, 17, 18, 14, 24, 21, 21, - 20, 22, 19, 20, 20, 19, 20, 26, 21, 20, 21, 33, 33, 33, 33, 35, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 16 - }, - - { - 15, 14, 16, 25, 19, 26, 22, 11, 18, 18, 27, 26, 13, 19, 9, 27, - 19, 18, 19, 19, 22, 19, 20, 18, 19, 20, 12, 32, 15, 32, 15, 35, - 15, 19, 19, 19, 19, 19, 16, 19, 20, 9, 19, 20, 14, 29, 19, 20, - 19, 19, 19, 19, 21, 19, 20, 32, 20, 19, 19, 33, 31, 39, 37, 39, - 37, 21, 21, 21, 23, 21, 19, 23, 23, 10, 19, 20, 16, 26, 23, 23, - 20, 20, 20, 22, 21, 22, 22, 26, 22, 22, 23, 35, 35, 35, 35, 37, - 19, 19, 19, 19, 29, 19, 19, 19, 19, 19, 9, 9, 9, 9, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 30, 19, 19, 19, 19, - 19, 10, 10, 10, 10, 19, 19, 19, 19, 19, 19, 19, 19, 19, 23, 35, - 12, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 11, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19 - } -#ifdef MORE_LANGUAGES - }, - { - { 13, 12, 31, 35, 23, 35, 31, 9, 14, 15, 25, 30, 11, 17, - 13, 31, 23, 16, 22, 21, 24, 23, 23, 20, 23, 22, 10, - 35, 26, 26, 26, 26, 30, 26, 24, 23, 24, 22, 21, 24, - 26, 10, 20, 26, 22, 29, 26, 25, 23, 25, 24, 24, 22, - 25, 24, 29, 29, 23, 25, 37, 22, 37, 35, 37, 35, 21, - 22, 21, 21, 22, 13, 22, 21, 10, 16, 22, 11, 32, 21, - 21, 23, 22, 16, 20, 14, 21, 20, 30, 25, 21, 21, 13, - 33, 13, 13, 13, 24, 22, 22, 19, 26, 21, 30, 20, 23, - 23, 21, 24, 26, 23, 22, 23, 21, 22, 20, 20, 26, 25, - 24, 22, 31, 32, 23, 30, 22, 22, 32, 23, 19, 18, 18, - 15, 22, 19, 27, 19, 20, 20, 18, 22, 24, 20, 19, 19, - 20, 19, 16, 19, 28, 20, 20, 18, 26, 27, 19, 26, 18, - 19, 27, 19, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, - 26, 26, 26, 18, 26, 26, 26, 26, 26, 26, 26, 26, 26, - 26, 26, 26, 26, 26, 26, 26, 26, 26, 20 }, - { 13, 9, 21, 35, 23, 35, 35, 11, 35, 35, 25, 35, 11, - 17, 13, 33, 28, 14, 22, 21, 24, 23, 23, 21, 23, 22, - 10, 35, 13, 35, 13, 33, 5, 25, 22, 23, 24, 21, 21, 24, - 24, 9, 20, 24, 21, 27, 25, 25, 22, 25, 23, 20, 23, 23, - 23, 31, 23, 23, 23, 37, 33, 37, 35, 37, 35, 21, 19, - 19, 21, 19, 17, 21, 21, 8, 17, 18, 14, 24, 21, 21, 20, - 22, 19, 20, 20, 19, 20, 26, 21, 20, 21, 33, 33, 33, - 33, 35, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 16, }, - { 15, 14, 16, 25, 19, - 26, 22, 11, 18, 18, 27, 26, 13, 19, 9, 27, 19, 18, 19, - 19, 22, 19, 20, 18, 19, 20, 12, 32, 15, 32, 15, 35, - 15, 19, 19, 19, 19, 19, 16, 19, 20, 9, 19, 20, 14, 29, - 19, 20, 19, 19, 19, 19, 21, 19, 20, 32, 20, 19, 19, - 33, 31, 39, 37, 39, 37, 21, 21, 21, 23, 21, 19, 23, 23, 10, 19, 20, 16, 26, 23, - 21, 21, 20, 20, 22, 21, 22, 22, 26, 22, 22, 23, 35, - 35, 35, 35, 37, 19, 19, 19, 19, 19, 19, 29, 19, 19, - 19, 20, 22, 31, 19, 19, 19, 19, 19, 29, 19, 29, 19, - 21, 19, 30, 31, 21, 29, 19, 19, 29, 19, 21, 23, 32, - 21, 21, 30, 31, 22, 21, 32, 33, 23, 32, 21, 21, 32, - 21, 19, 19, 30, 31, 22, 22, 21, 32, 33, 23, 32, 21, - 21, 32, 21, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 11, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19 }, - }, - - { - { - 13, 12, 31, 35, 23, 35, 31, 9, 14, 15, 25, 30, 11, 17, 13, 31, - 23, 16, 22, 21, 24, 23, 23, 20, 23, 22, 10, 35, 26, 26, 26, 26, - 30, 26, 24, 23, 24, 22, 21, 24, 26, 10, 20, 26, 22, 29, 26, 25, - 23, 25, 24, 24, 22, 25, 24, 29, 29, 23, 25, 37, 22, 37, 35, 37, - 35, 21, 22, 21, 21, 22, 13, 22, 21, 10, 16, 22, 11, 32, 21, 21, - 23, 22, 16, 20, 14, 21, 20, 30, 25, 21, 21, 33, 33, 33, 33, 35, - 27, 27, 27, 27, 32, 24, 23, 23, 23, 23, 11, 11, 11, 11, 26, 26, - 26, 26, 26, 26, 26, 25, 26, 21, 21, 21, 21, 32, 23, 22, 22, 22, - 22, 11, 11, 11, 11, 22, 22, 22, 22, 22, 22, 22, 22, 26, 21, 24, - 12, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, - 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 18, 26, 26, - 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, - 20 - }, - - { - 13, 9, 21, 35, 23, 35, 35, 11, 35, 35, 25, 35, 11, 17, 13, 33, - 28, 14, 22, 21, 24, 23, 23, 21, 23, 22, 10, 35, 13, 35, 13, 33, - 5, 25, 22, 23, 24, 21, 21, 24, 24, 9, 20, 24, 21, 27, 25, 25, - 22, 25, 23, 20, 23, 23, 23, 31, 23, 23, 23, 37, 33, 37, 35, 37, - 35, 21, 19, 19, 21, 19, 17, 21, 21, 8, 17, 18, 14, 24, 21, 21, - 20, 22, 19, 20, 20, 19, 20, 26, 21, 20, 21, 33, 33, 33, 33, 35, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 16 - }, - - { - 15, 14, 16, 25, 19, 26, 22, 11, 18, 18, 27, 26, 13, 19, 9, 27, - 19, 18, 19, 19, 22, 19, 20, 18, 19, 20, 12, 32, 15, 32, 15, 35, - 15, 19, 19, 19, 19, 19, 16, 19, 20, 9, 19, 20, 14, 29, 19, 20, - 19, 19, 19, 19, 21, 19, 20, 32, 20, 19, 19, 33, 31, 39, 37, 39, - 37, 21, 21, 21, 23, 21, 19, 23, 23, 10, 19, 20, 16, 26, 23, 23, - 20, 20, 20, 22, 21, 22, 22, 26, 22, 22, 23, 35, 35, 35, 35, 37, - 19, 19, 19, 19, 29, 19, 19, 19, 19, 19, 9, 9, 9, 9, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 30, 19, 19, 19, 19, - 19, 10, 10, 10, 10, 19, 19, 19, 19, 19, 19, 19, 19, 19, 23, 35, - 12, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 11, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19 - } - } -#endif -}; - -int16 Size_jp[] = { - 15, 14, 16, 20, 19, 26, 22, 11, 18, 18, 27, 26, 13, //; 0 - 19, 20, 27, 19, 15, 19, 19, 21, 19, 20, 18, 19, 15, //; 13 - 13, 28, 15, 32, 15, 35, 15, 19, 19, 19, 19, 17, 16, //; 26 - 19, 20, 15, 19, 20, 14, 17, 19, 19, 19, 19, 19, 19, //; 39 - 19, 19, 20, 25, 20, 19, 19, 33, 31, 39, 37, 39, 37, //; 52 - 21, 21, 21, 19, 17, 15, 23, 21, 15, 19, 20, 16, 19, //; 65 - 19, 19, 20, 20, 17, 22, 19, 22, 22, 19, 22, 22, 23, //; 78 - 35, 35, 35, 35, 37, 19, 19, 19, 19, 29, 19, 19, 19, //; 91 - 19, 19, 9, 9, 9, 9, 19, 19, 19, 19, 19, 19, 19, 19, //; 104 - 19, 19, 19, 19, 19, 30, 19, 19, 19, 19, 19, 10, 10, //; 118 - 10, 10, 19, 19, 19, 19, 19, 19, 19, 19, 19, 23, 35, //; 131 - 12, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, //; 144 - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, //; 157 - 19, 19, 19, 11, 19, 19, 19, 19, 19, 19, 19, 19, 19, //; 170 - 19, 19, 19, 19, 19, 19, 19, 19, 19, 21 -}; - -wchar foreign_table[128] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 176, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 177, 0, 0, 0, 0, 0, 95, 0, 0, 0, 0, 175, - 128, 129, 130, 0, 131, 0, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, - 0, 173, 142, 143, 144, 0, 145, 0, 0, 146, 147, 148, 149, 0, 0, 150, - 151, 152, 153, 0, 154, 0, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, - 0, 174, 165, 166, 167, 0, 168, 0, 0, 169, 170, 171, 172, 0, 0, 0, -}; - -void -CFont::Initialise(void) -{ - int slot; - - slot = CTxdStore::AddTxdSlot("fonts"); -#ifdef MORE_LANGUAGES - Slot = slot; - switch (LanguageSet) - { - case FONT_LANGSET_EFIGS: - default: - CTxdStore::LoadTxd(slot, "MODELS/FONTS.TXD"); - break; - case FONT_LANGSET_POLISH: - CTxdStore::LoadTxd(slot, "MODELS/FONTS_P.TXD"); - break; - case FONT_LANGSET_RUSSIAN: - CTxdStore::LoadTxd(slot, "MODELS/FONTS_R.TXD"); - break; - case FONT_LANGSET_JAPANESE: - CTxdStore::LoadTxd(slot, "MODELS/FONTS_J.TXD"); - break; - } -#else - CTxdStore::LoadTxd(slot, "MODELS/FONTS.TXD"); -#endif - CTxdStore::AddRef(slot); - CTxdStore::PushCurrentTxd(); - CTxdStore::SetCurrentTxd(slot); - Sprite[0].SetTexture("font2", "font2_mask"); - if (LanguageSet == FONT_LANGSET_JAPANESE) { - Sprite[1].SetTexture("FONTJAP", "FONTJAP_mask"); - Sprite[3].SetTexture("FONTJAP", "FONTJAP_mask"); - } - else - Sprite[1].SetTexture("pager", "pager_mask"); - Sprite[2].SetTexture("font1", "font1_mask"); - SetScale(1.0f, 1.0f); - SetSlantRefPoint(SCREEN_WIDTH, 0.0f); - SetSlant(0.0f); - SetColor(CRGBA(0xFF, 0xFF, 0xFF, 0)); - SetJustifyOff(); - SetCentreOff(); - SetWrapx(DEFAULT_SCREEN_WIDTH); - SetCentreSize(DEFAULT_SCREEN_WIDTH); - SetBackgroundOff(); - SetBackgroundColor(CRGBA(0x80, 0x80, 0x80, 0x80)); - SetBackGroundOnlyTextOff(); - SetPropOn(); - SetFontStyle(FONT_BANK); - SetRightJustifyWrap(0.0f); - SetAlphaFade(255.0f); - SetDropShadowPosition(0); - CTxdStore::PopCurrentTxd(); -} - -#ifdef MORE_LANGUAGES -void -CFont::ReloadFonts(uint8 set) -{ - if (Slot != -1 && LanguageSet != set) { - Sprite[0].Delete(); - Sprite[1].Delete(); - Sprite[2].Delete(); - if (LanguageSet == FONT_LANGSET_JAPANESE) - Sprite[3].Delete(); - CTxdStore::PushCurrentTxd(); - CTxdStore::RemoveTxd(Slot); - switch (set) - { - case FONT_LANGSET_EFIGS: - default: - CTxdStore::LoadTxd(Slot, "MODELS/FONTS.TXD"); - break; - case FONT_LANGSET_POLISH: - CTxdStore::LoadTxd(Slot, "MODELS/FONTS_P.TXD"); - break; - case FONT_LANGSET_RUSSIAN: - CTxdStore::LoadTxd(Slot, "MODELS/FONTS_R.TXD"); - break; - case FONT_LANGSET_JAPANESE: - CTxdStore::LoadTxd(Slot, "MODELS/FONTS_J.TXD"); - break; - } - CTxdStore::SetCurrentTxd(Slot); - Sprite[0].SetTexture("font2", "font2_mask"); - if (set == FONT_LANGSET_JAPANESE) { - Sprite[1].SetTexture("FONTJAP", "FONTJAP_mask"); - Sprite[3].SetTexture("FONTJAP", "FONTJAP_mask"); - } - else - Sprite[1].SetTexture("pager", "pager_mask"); - Sprite[2].SetTexture("font1", "font1_mask"); - CTxdStore::PopCurrentTxd(); - } - LanguageSet = set; -} -#endif - -void -CFont::Shutdown(void) -{ - Sprite[0].Delete(); - Sprite[1].Delete(); - Sprite[2].Delete(); - if (LanguageSet == FONT_LANGSET_JAPANESE) - Sprite[3].Delete(); -#ifdef MORE_LANGUAGES - CTxdStore::RemoveTxdSlot(Slot); - Slot = -1; -#else - CTxdStore::RemoveTxdSlot(CTxdStore::FindTxdSlot("fonts")); -#endif -} - -void -CFont::InitPerFrame(void) -{ - Details.bank = CSprite2d::GetBank(30, Sprite[0].m_pTexture); - CSprite2d::GetBank(15, Sprite[1].m_pTexture); - CSprite2d::GetBank(15, Sprite[2].m_pTexture); - if (LanguageSet == FONT_LANGSET_JAPANESE) - CSprite2d::GetBank(15, Sprite[3].m_pTexture); - SetDropShadowPosition(0); - NewLine = 0; -} - -void -CFont::PrintChar(float x, float y, wchar c) -{ - if(x <= 0.0f || x > SCREEN_WIDTH || - y <= 0.0f || y > SCREEN_HEIGHT) // BUG: game uses SCREENW again - return; - - float w = GetCharacterWidth(c) / 32.0f; - float xoff = c % 16; - float yoff = c / 16; - if (LanguageSet == FONT_LANGSET_JAPANESE && (Details.style == FONT_PAGER || Details.style == FONT_JAPANESE)) { - w = 21.0f; - xoff = (float)(c % 48);// *w / 1024.0f; - yoff = c / 48; - } - - if(Details.style == FONT_BANK || Details.style == FONT_HEADING){ - if(Details.dropShadowPosition != 0){ - CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank - CRect(x + SCREEN_SCALE_X(Details.dropShadowPosition), - y + SCREEN_SCALE_Y(Details.dropShadowPosition), - x + SCREEN_SCALE_X(Details.dropShadowPosition) + 32.0f * Details.scaleX * 1.0f, - y + SCREEN_SCALE_Y(Details.dropShadowPosition) + 40.0f * Details.scaleY * 0.5f), - Details.dropColor, - xoff/16.0f, yoff/12.8f, - (xoff+1.0f)/16.0f - 0.001f, yoff/12.8f, - xoff/16.0f, (yoff+1.0f)/12.8f, - (xoff+1.0f)/16.0f - 0.001f, (yoff+1.0f)/12.8f - 0.0001f); - } - CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank - CRect(x, y, - x + 32.0f * Details.scaleX * 1.0f, - y + 40.0f * Details.scaleY * 0.5f), - Details.color, - xoff/16.0f, yoff/12.8f, - (xoff+1.0f)/16.0f - 0.001f, yoff/12.8f, - xoff/16.0f, (yoff+1.0f)/12.8f - 0.002f, - (xoff+1.0f)/16.0f - 0.001f, (yoff+1.0f)/12.8f - 0.002f); - }else if (LanguageSet == FONT_LANGSET_JAPANESE && (Details.style == FONT_PAGER || Details.style == FONT_JAPANESE)) { - if (Details.dropShadowPosition != 0) { - CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank - CRect(x + SCREEN_SCALE_X(Details.dropShadowPosition), - y + SCREEN_SCALE_Y(Details.dropShadowPosition), - x + SCREEN_SCALE_X(Details.dropShadowPosition) + 32.0f * Details.scaleX * 1.0f, - y + SCREEN_SCALE_Y(Details.dropShadowPosition) + 40.0f * Details.scaleY / 2.75f), - Details.dropColor, - xoff * w / 1024.0f, yoff / 25.6f, - xoff * w / 1024.0f + (1.0f / 48.0f) - 0.001f, yoff / 25.6f, - xoff * w / 1024.0f, (yoff + 1.0f) / 25.6f, - xoff * w / 1024.0f + (1.0f / 48.0f) - 0.001f, (yoff + 1.0f) / 25.6f - 0.0001f); - } - CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank - CRect(x, y, - x + 32.0f * Details.scaleX * 1.0f, - y + 40.0f * Details.scaleY / 2.75f), - Details.color, - xoff * w / 1024.0f, yoff / 25.6f, - xoff * w / 1024.0f + (1.0f / 48.0f) - 0.001f, yoff / 25.6f, - xoff * w / 1024.0f, (yoff + 1.0f) / 25.6f - 0.002f, - xoff * w / 1024.0f + (1.0f / 48.0f) - 0.001f, (yoff + 1.0f) / 25.6f - 0.0001f); - } - else - CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank - CRect(x, y, - x + 32.0f * Details.scaleX * w, - y + 32.0f * Details.scaleY * 0.5f), - Details.color, - xoff/16.0f, yoff/16.0f, - (xoff+w)/16.0f, yoff/16.0f, - xoff/16.0f, (yoff+1.0f)/16.0f, - (xoff+w)/16.0f - 0.0001f, (yoff+1.0f)/16.0f - 0.0001f); -} - -bool CFont::IsJapanesePunctuation(wchar *a1) -{ - wchar v2; - - v2 = *a1; - if (v2 != 0xE7 - && v2 != 0x124 - && v2 != 0x126 - && v2 != 0x128 - && v2 != 0x104 - && v2 != ',' - && v2 != '>' - && v2 != '!' - && v2 != 0x99 - && v2 != '?' - && v2 != ':') - { - return false; - } - return true; -} - -bool CFont::IsAnsiCharacter(wchar *s) -{ - if (*s >= 'A' && *s <= 'Z') - return true; - if (*s >= 'a' && *s <= 'z') - return true; - if (*s >= '0' && *s <= ':') - return true; - if (*s == '(' || *s == ')') - return true; - if (*s == 'D' || *s == '$') - return true; - return false; -} - -void -CFont::PrintString(float xstart, float ystart, wchar *s) -{ - /* - if (1) - { - wchar* result; // eax - __int16 numSpaces; // bx - wchar* start; // ebp - double v6; // st7 - float v7; // ST2C_4 - float v8; // ST2C_4 - double v9; // st5 - double v10; // st7 - double v11; // st5 - float v12; // ST10_4 - float v13; // ST00_4 - float v14; // ST34_4 - unsigned __int16* v15; // eax - wchar* t; // esi - unsigned __int16 v17; // ax - double v18; // st7 - double v19; // st7 - float v20; // ST34_4 - double v21; // st7 - double v22; // st7 - double v23; // st7 - double xleft_d; // st6 - float xleft; // ST00_4 - float v26; // ST34_4 - float v27; // [esp+24h] [ebp-44h] - float lineLength; // [esp+28h] [ebp-40h] - float v29; // [esp+30h] [ebp-38h] - float x; // [esp+40h] [ebp-28h] - float y; // [esp+44h] [ebp-24h] - char first; // [esp+4Bh] [ebp-1Dh] - CRect v33; // [esp+4Ch] [ebp-1Ch] - - result = s; - if (*s != '*') - { - if (CFont::Details.background == 1) - { - CFont::GetTextRect(&v33, xstart, ystart, s); - CSprite2d::DrawRect(v33, CFont::Details.backgroundColor); - } - numSpaces = 0; - lineLength = 0.0; - start = s; - first = 1; - if (CFont::Details.centre != 1 && CFont::Details.rightJustify != 1) - x = xstart; - else - x = 0.0; - y = ystart; - while (1) - { - while (1) - { - while (1) - { - result = s; - if (!*s) - return;// result; - v27 = CFont::GetStringWidth(s, false); - if (CFont::Details.centre == 1) - v6 = CFont::Details.centreSize; - else - v6 = CFont::Details.rightJustify == 1 ? xstart - CFont::Details.rightJustifyWrap : CFont::Details.wrapX; - v7 = v6; - v8 = v7 - SCREEN_WIDTH * 0.0015625f * 21.0 * 2.0; - if (x + v27 <= v8 || first) - break; - if (someJapCheck(s)) - --s; - if (CFont::Details.justify != 1 || CFont::Details.centre) - v9 = 0.0; - else - v9 = (CFont::Details.wrapX - lineLength) / (double)numSpaces; - v10 = v9; - if (CFont::Details.centre) - { - v11 = xstart - x * 0.5; - } - else if (CFont::Details.rightJustify) - { - v11 = xstart - x; - } - else - { - v11 = xstart; - } - v12 = v10; - v13 = v11; - CFont::PrintString(v13, y, start, s, v12, xstart); - start = s; - if (CFont::Details.centre != 1 && CFont::Details.rightJustify != 1) - x = xstart; - else - x = 0.0; - v14 = 32.0 * CFont::Details.scaleY * 0.3636363636363636 + 2.0 * CFont::Details.scaleY; - numSpaces = 0; - first = 1; - y = v14 + y; - lineLength = 0.0; - } - v15 = CFont::GetNextSpace(s); - t = v15; - v17 = *v15; - if (!v17 || !t[1] && v17 == ' ') - break; - if (!first) - ++numSpaces; - first = 0; - v21 = CFont::GetStringWidth(s, 0); - x = v21 + x; - if (sub_511630(s)) - x = x + 21.0; - s = t; - v22 = CFont::GetCharacterSize(*t - 32); - ++s; - x = v22 + x; - lineLength = x; - if (!*s) - { - v23 = CFont::GetStringWidth(s, 0); - x = v23 + x; - if (sub_511630(s)) - x = x + 21.0; - if (CFont::Details.centre) - { - xleft_d = xstart - x * 0.5; - } - else if (CFont::Details.rightJustify) - { - xleft_d = xstart - x; - } - else - { - xleft_d = xstart; - } - xleft = xleft_d; - if (CFont::PrintString(xleft, y, start, s, 0.0, xstart)) - { - start = s; - if (CFont::Details.centre != 1 && CFont::Details.rightJustify != 1) - x = xstart; - else - x = 0.0; - v26 = 32.0 * CFont::Details.scaleY * 0.3636363636363636 + 2.0 * CFont::Details.scaleY; - numSpaces = 0; - first = 1; - y = v26 + y; - lineLength = 0.0; - } - } - } - if (!t[1] && v17 == ' ') - *t = 0; - v18 = CFont::GetStringWidth(s, 0); - s = t; - x = v18 + x; - if (CFont::Details.centre) - break; - if (CFont::Details.rightJustify) - { - v19 = xstart - x; - LABEL_43: - v29 = v19; - goto LABEL_44; - } - v29 = xstart; - LABEL_44: - if (CFont::PrintString(v29, y, start, s, 0.0, xstart)) - { - start = s; - if (CFont::Details.centre != 1 && CFont::Details.rightJustify != 1) - x = xstart; - else - x = 0.0; - v20 = 32.0 * CFont::Details.scaleY * 0.3636363636363636 + 2.0 * CFont::Details.scaleY; - numSpaces = 0; - first = 1; - y = v20 + y; - lineLength = 0.0; - } - } - v19 = xstart - x * 0.5; - goto LABEL_43; - } - return; - }*/ - - CRect rect; - int numSpaces; - float lineLength; - float x, y; - bool first; - wchar *start, *t; - - if(*s == '*') - return; - - if(Details.background){ - GetNumberLines(xstart, ystart, s); // BUG: result not used - GetTextRect(&rect, xstart, ystart, s); - CSprite2d::DrawRect(rect, Details.backgroundColor); - } - - lineLength = 0.0f; - numSpaces = 0; - first = true; - if(Details.centre || Details.rightJustify) - x = 0.0f; - else - x = xstart; - y = ystart; - start = s; - - // This is super ugly, I blame R* - for(;;){ - for(;;){ - for(;;){ - if(*s == '\0') - return; - float xend = Details.centre ? Details.centreSize : - Details.rightJustify ? xstart - Details.rightJustifyWrap : - Details.wrapX; - if (LanguageSet == FONT_LANGSET_JAPANESE && (Details.style == FONT_JAPANESE || Details.style == FONT_PAGER)) - xend -= SCREEN_SCALE_X(21.0f * 2.0f); - if(x + GetStringWidth(s) > xend && !first){ - if (LanguageSet == FONT_LANGSET_JAPANESE && IsJapanesePunctuation(s)) - s--; - // flush line - float spaceWidth = !Details.justify || Details.centre ? 0.0f : - (Details.wrapX - lineLength) / numSpaces; - float xleft = Details.centre ? xstart - x/2 : - Details.rightJustify ? xstart - x : - xstart; - PrintString(xleft, y, start, s, spaceWidth, xstart); - // reset things - lineLength = 0.0f; - numSpaces = 0; - first = true; - if(Details.centre || Details.rightJustify) - x = 0.0f; - else - x = xstart; - if (LanguageSet == FONT_LANGSET_JAPANESE && (Details.style == FONT_JAPANESE || Details.style == FONT_PAGER)) - y += 32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY; - else - y += 32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY; - start = s; - }else - break; - } - // advance by one word - t = GetNextSpace(s); - if(t[0] == '\0' || - t[0] == ' ' && t[1] == '\0') - break; - if(!first) - numSpaces++; - first = false; - x += GetStringWidth(s) + GetCharacterSize(*t - ' '); - if (LanguageSet == FONT_LANGSET_JAPANESE && (Details.style == FONT_JAPANESE || Details.style == FONT_PAGER) && IsAnsiCharacter(s)) - x += 21.0f; - lineLength = x; - s = t+1; - if (LanguageSet == FONT_LANGSET_JAPANESE && (Details.style == FONT_JAPANESE || Details.style == FONT_PAGER) && !*s) { - x += GetStringWidth(s); - if (IsAnsiCharacter(s)) - x += 21.0f; - float xleft = Details.centre ? xstart - x / 2 : - Details.rightJustify ? xstart - x : - xstart; - if (PrintString(xleft, y, start, s, 0.0f, xstart)) - { - start = s; - if (!Details.centre && !Details.rightJustify) - x = xstart; - else - x = 0.0f; - - y += 32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY; - numSpaces = 0; - first = true; - lineLength = 0.0f; - } - } - - } - // print rest - if(t[0] == ' ' && t[1] == '\0') - t[0] = '\0'; - x += GetStringWidth(s); - s = t; - float xleft = Details.centre ? xstart - x/2 : - Details.rightJustify ? xstart - x : - xstart; -#ifdef MORE_LANGUAGES - if (PrintString(xleft, y, start, s, 0.0f, xstart) && LanguageSet == FONT_LANGSET_JAPANESE && (Details.style == FONT_JAPANESE || Details.style == FONT_PAGER)) { - start = s; - if (!Details.centre && !Details.rightJustify) - x = xstart; - else - x = 0.0f; - y += 32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY; - numSpaces = 0; - first = true; - lineLength = 0.0f; - } -#else - PrintString(xleft, y, start, s, 0.0f) -#endif - } -} - -int -CFont::GetNumberLines(float xstart, float ystart, wchar *s) -{ - int n; - float x, y; - wchar *t; - n = 0; - bool v14 = false; - -#ifdef MORE_LANGUAGES - if (IsJapanese()) { - t = s; - wchar unused; - while (*t) { - if (*t == JAP_TERMINATION || *t == '~') - t = ParseToken(t, &unused, true); - if (NewLine) { - n++; - NewLine = false; - v14 = true; - } - t++; - } - } -#endif - - if (v14) n--; - - if(Details.centre || Details.rightJustify) - x = 0.0f; - else - x = xstart; - y = ystart; - - while(*s){ - float f = (Details.centre ? Details.centreSize : Details.wrapX); - if (IsJapaneseFont()) - f -= SCREEN_SCALE_X(21.0f * 2.0f); - - if(x + GetStringWidth(s) > f){ - if (LanguageSet == FONT_LANGSET_JAPANESE) - { - if (IsJapanesePunctuation(s)) - s--; - } - // reached end of line - if(Details.centre || Details.rightJustify) - x = 0.0f; - else - x = xstart; - n++; - // Why even? - if (LanguageSet == FONT_LANGSET_JAPANESE) - y += 32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY; - else - y += 32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY; - }else{ - // still space in current line - t = GetNextSpace(s); - if(*t == '\0'){ - // end of string - x += GetStringWidth(s); - if ((LanguageSet == FONT_LANGSET_JAPANESE) && IsAnsiCharacter(s)) - x += 21.0f; - n++; - s = t; - }else{ - x += GetStringWidth(s); - if ((LanguageSet == FONT_LANGSET_JAPANESE) && IsAnsiCharacter(s)) - x += 21.0f; - s = t+1; - x += GetCharacterSize(*t - ' '); - if (LanguageSet == FONT_LANGSET_JAPANESE && !*s) - n++; - } - } - } - - return n; -} - -void -CFont::GetTextRect(CRect *rect, float xstart, float ystart, wchar *s) -{ - int numLines; - float x, y; - int16 maxlength; - wchar *t; - - maxlength = 0; - numLines = 0; - - if (IsJapanese()) { - numLines = GetNumberLines(xstart, ystart, s); - //maxlength = Details.centreSize; - }else{ - if(Details.centre || Details.rightJustify) - x = 0.0f; - else - x = xstart; - y = ystart; - - while(*s){ - if(x + GetStringWidth(s) > (Details.centre ? Details.centreSize : Details.wrapX)){ - // reached end of line - if(x > maxlength) - maxlength = x; - if(Details.centre || Details.rightJustify) - x = 0.0f; - else - x = xstart; - numLines++; - y += 32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY; - }else{ - // still space in current line - t = GetNextSpace(s); - if(*t == '\0'){ - // end of string - x += GetStringWidth(s); - if(x > maxlength) - maxlength = x; - numLines++; - s = t; - }else{ - x += GetStringWidth(s); - x += GetCharacterSize(*t - ' '); - s = t+1; - } - } - } - } - - if(Details.centre){ - if(Details.backgroundOnlyText){ - rect->left = xstart - maxlength/2 - 4.0f; - rect->right = xstart + maxlength/2 + 4.0f; - if (IsJapaneseFont()) { - rect->bottom = (32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY) * numLines + ystart + (4.0f / 2.75f); - rect->top = ystart - (4.0f / 2.75f); - } else { - rect->bottom = (32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY) * numLines + ystart + 2.0f; - rect->top = ystart - 2.0f; - } - }else{ - rect->left = xstart - Details.centreSize*0.5f - 4.0f; - rect->right = xstart + Details.centreSize*0.5f + 4.0f; - if (IsJapaneseFont()) { - rect->bottom = (32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY) * numLines + ystart + (4.0f / 2.75f); - rect->top = ystart - (4.0f / 2.75f); - } else { - rect->bottom = (32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY) * numLines + ystart + 2.0f; - rect->top = ystart - 2.0f; - } - } - }else{ - rect->left = xstart - 4.0f; - rect->right = Details.wrapX; - // WTF? - rect->bottom = ystart - 4.0f + 4.0f; - if (IsJapaneseFont()) - rect->top = (32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY) * numLines + ystart + 2.0f + (4.0f / 2.75f); - else - rect->top = (32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY) * numLines + ystart + 2.0f + 2.0f; - } -} - -#ifdef MORE_LANGUAGES -bool -CFont::PrintString(float x, float y, wchar *start, wchar *&end, float spwidth, float japX) -{ - wchar *s, c, unused; - - if (LanguageSet == FONT_LANGSET_JAPANESE) { - float v14 = 0.0f; - for (s = start; s < end; s++) { - if (*s == JAP_TERMINATION || *s == '~') - s = ParseToken(s, &unused, true); - if (NewLine) { - NewLine = false; - break; - } - v14 += GetCharacterSize(*s - ' '); - } - s = start; - if (Details.centre) - { - x = japX - v14 * 0.5; - } - else if (Details.rightJustify) - { - x = japX - v14; - } - } - - for (s = start; s < end; s++) { - if (*s == '~' || (IsJapanese() && *s == JAP_TERMINATION)) - s = ParseToken(s, &unused); - if (NewLine && IsJapanese()) { - NewLine = false; - end = s; - return true; - } - c = *s - ' '; - if (Details.slant != 0.0f && !IsJapanese()) - y = (Details.slantRefX - x) * Details.slant + Details.slantRefY; - PrintChar(x, y, c); - x += GetCharacterSize(c); - if (c == 0 && (!NewLine || !IsJapanese())) // space - x += spwidth; - } - return false; -} -#else -void -CFont::PrintString(float x, float y, wchar *start, wchar *end, float spwidth) -{ - wchar *s, c, unused; - - for(s = start; s < end; s++){ - if(*s == '~') - s = ParseToken(s, &unused); - c = *s - ' '; - if(Details.slant != 0.0f) - y = (Details.slantRefX - x)*Details.slant + Details.slantRefY; - PrintChar(x, y, c); - x += GetCharacterSize(c); - if(c == 0) // space - x += spwidth; - } -} -#endif - -float -CFont::GetCharacterWidth(wchar c) -{ -#ifdef MORE_LANGUAGES - if (IsJapanese()) - { - if (!Details.proportional) - return Size[0][Details.style][192]; - if (c <= 94 || Details.style == FONT_HEADING || Details.style == FONT_BANK) { - switch (Details.style) - { - case FONT_JAPANESE: - return Size_jp[c]; - default: - return Size[0][Details.style][c]; - } - } - if (c < 254 && Details.style == FONT_PAGER) - return 29.4f; - - switch (Details.style) - { - case FONT_JAPANESE: - return 29.4f; - case FONT_BANK: - return 10.0f; - case FONT_PAGER: - return 31.5f; - case FONT_HEADING: - return Size[0][Details.style][c]; - } - } - - else if (Details.proportional) - return Size[LanguageSet][Details.style][c]; - else - return Size[LanguageSet][Details.style][192]; -#else - if (Details.proportional) - return Size[Details.style][c]; - else - return Size[Details.style][192]; -#endif // MORE_LANGUAGES -} - -float -CFont::GetCharacterSize(wchar c) -{ -#ifdef MORE_LANGUAGES - - if (IsJapanese()) - { - if (!Details.proportional) - return Size[0][Details.style][192] * Details.scaleX; - if (c <= 94 || Details.style == FONT_HEADING || Details.style == FONT_BANK) { - switch (Details.style) - { - case FONT_JAPANESE: - return Size_jp[c] * Details.scaleX; - default: - return Size[0][Details.style][c] * Details.scaleX; - } - } - if (c < 254 && (Details.style == FONT_PAGER)) - return 29.4f * Details.scaleX; - - switch (Details.style) - { - case FONT_JAPANESE: - return 29.4f * Details.scaleX; - case FONT_BANK: - return 10.0f * Details.scaleX; - case FONT_PAGER: - return 31.5f * Details.scaleX; - case FONT_HEADING: - return Size[0][Details.style][c] * Details.scaleX; - } - } - else if(Details.proportional) - return Size[LanguageSet][Details.style][c] * Details.scaleX; - else - return Size[LanguageSet][Details.style][192] * Details.scaleX; -#else - if (Details.proportional) - return Size[Details.style][c] * Details.scaleX; - else - return Size[Details.style][192] * Details.scaleX; -#endif // MORE_LANGUAGES -} - -float -CFont::GetStringWidth(wchar *s, bool spaces) -{ - float w; - - w = 0.0f; - - if (LanguageSet == FONT_LANGSET_JAPANESE) - { - /* unsigned __int16* v2; // ebx - double v3; // st4 - int v4; // edx - double v5; // st7 - unsigned __int16 v6; // ax - unsigned __int16 v7; // ax - double v8; // st3 - float v10; // [esp+0h] [ebp-20h] - float v11; // [esp+4h] [ebp-1Ch] - - v2 = (unsigned __int16*)s; - v10 = 0.0; - do - { - if ((*v2 != ' ' || spaces) && *v2) - { - v3 = CFont::Details.scaleX; - v4 = 193 * (signed __int16)CFont::Details.style; - v5 = 29.4 * CFont::Details.scaleX; - do - { - v6 = *v2; - if (*v2 == 0x807Eu || v6 == '~') - { - do - ++v2; - while (*v2 != 0x807Eu && *v2 != '~'); - ++v2; - goto LABEL_27; - } - v7 = v6 - ' '; - if (CFont::Details.proportional == 1) - { - if (v7 > 94u && CFont::Details.style != FONT_HEADING && CFont::Details.style != FONT_BANK) - { - if (v7 >= 254u || CFont::Details.style != FONT_PAGER) - { - switch (CFont::Details.style) - { - case FONT_JAPANESE: - v8 = v5; - goto LABEL_25; - case FONT_BANK: - v8 = 10.0 * CFont::Details.scaleX; - goto LABEL_25; - case FONT_PAGER: - v8 = 31.5 * CFont::Details.scaleX; - goto LABEL_25; - case FONT_HEADING: - v11 = Size[0][Details.style][v7] * CFont::Details.scaleX; - break; - } - } - else - { - v11 = v5; - } - goto def_510DAD; - } - if (Details.style == FONT_JAPANESE) - v8 = Size_jp[v7] * Details.scaleX; - else - v8 = CFont::Size[0][Details.style][v7] * v3; - } - else - { - v8 = CFont::Size[0][CFont::Details.style][192] * v3; - } - LABEL_25: - v11 = v8; - def_510DAD: - v10 = v10 + v11; - LABEL_27: - if (*v2 != 0x807Eu && *v2 != '~') - ++v2; - } while (*v2 == 0x807Eu || *v2 == '~'); - } - } while (IsAnsiCharacter(v2)); - return v10;*/ - - /*for (;; s++) - { - if (*s == '\0' && (!spaces || (*s == ' ' || !sub_511630(s) && *s != '~' && *s != JAP_TERMINATION))) - return w; - while (*s == '~' || *s == JAP_TERMINATION) { - s++; - while (*s != '~' && *s != JAP_TERMINATION) s++; - s++; - if (*s == ' ' && spaces) - return w; - } - w += GetCharacterSize(*s - ' '); - s++; - if ((*s != '~' && *s != JAP_TERMINATION) && ((*s == ' ' || !sub_511630(s)) && !spaces)) - return w; - }*/ - - do - { - if ((*s != ' ' || spaces) && *s != '\0') { - do { - while (*s == '~' || *s == JAP_TERMINATION) { - s++; - while (!(*s == '~' || *s == JAP_TERMINATION)) s++; - s++; - //if (*s != JAP_TERMINATION && *s != '~') - // ++s; - //continue; - } - w += GetCharacterSize(*s - ' '); - //if (*s != JAP_TERMINATION && *s != '~') - ++s; - } while (*s == '~' || *s == JAP_TERMINATION); - } - } while (IsAnsiCharacter(s));//*/ - } - else - { - for (; (*s != ' ' || spaces) && *s != '\0'; s++) { - if (*s == '~') { - s++; - while (*s != '~') s++; - s++; - if (*s == ' ' && !spaces) - break; - } - w += GetCharacterSize(*s - ' '); - } - } - return w; -} - -wchar* -CFont::GetNextSpace(wchar *s) -{ - if (IsJapanese()) { - unsigned __int16* v1; // ebx - - v1 = s; - while (*v1 == ' ' || !*v1) - { - LABEL_11: - if (!IsAnsiCharacter(v1)) - return v1; - } - while (1) - { - if (*v1 == 0x807Eu || *v1 == '~') - { - do - ++v1; - while (*v1 != 0x807Eu && *v1 != '~'); - ++v1; - if (*v1 == ' ') - return v1; - } - ++v1; - if (*v1 != 0x807Eu && *v1 != '~') - goto LABEL_11; - } - - if (*v1 == ' ' || !*v1) - { - if (IsAnsiCharacter(v1)) - { - do - { - if (*v1 == 0x807Eu || *v1 == '~') - { - do - ++v1; - while (*v1 != 0x807Eu && *v1 != '~'); - ++v1; - if (*v1 == ' ') - return v1; - } - ++v1; - if (*v1 != 0x807Eu && *v1 != '~') - if (!IsAnsiCharacter(v1)) - return v1; - } while (*v1 == ' ' || !*v1); - } - } - - /*for (;; s++) - { - if (*s == '\0' || *s == ' ' || (!sub_511630(s) && *s != '~' && *s != JAP_TERMINATION)) - return s; - if (*s == '~' || *s == JAP_TERMINATION) { - s++; - while (*s != '~' && *s != JAP_TERMINATION) s++; - s++; - if (*s == ' ' ) - return s; - } - //s++; - //if (*s == ' ' || (!sub_511630(s) && *s != '~' && *s != JAP_TERMINATION)) - // return s; - }*/ - - /*for (;*s != ' ' && *s != '\0' && sub_511630(s); s++) { - while (*s == '~' || *s == JAP_TERMINATION) { - s++; - while (*s != '~' && *s != JAP_TERMINATION) s++; - s++; - if (*s == ' ' || ((*s != '~' && *s != JAP_TERMINATION) && !sub_511630(s))) - return s; - } - } - return s;*/ - /*while (*s == ' ' || !*s) { - LABEL_11: - if (!sub_511630(s)) - return s; - }*/ - - /*while (*s != ' ' && *s != '\0') - { - while (*s == JAP_TERMINATION || *s == '~') - { - do - ++s; - while (*s != JAP_TERMINATION && *s != '~'); - ++s; - if (*s == ' ') - return s; - } - ++s; - if (!sub_511630(s)) - return s; - //if (*s != JAP_TERMINATION && *s != '~') - // goto LABEL_11; - } - return s;*/ - - - //for (; *s != ' ' && *s != '\0';) { - // if (!sub_511630(s)) - // break; - // //for (; *s == '~' || *s == JAP_TERMINATION;s++) { - // // s++; - // // while (!(*s == '~' || *s == JAP_TERMINATION)) s++; - // // s++; - // // if (*s == ' ') - // // return s; - // // if (!sub_511630(s)) - // // return s; - // //} - // while (true) - // { - // if (*s == '~' || *s == JAP_TERMINATION) { - // s++; - // while (*s != '~' || *s == JAP_TERMINATION) s++; - // s++; - // if (*s == ' ') - // return s; - // } - // s++; - // if (!(*s == '~' || *s == JAP_TERMINATION)) - // break; - // } - //} - //return s; - - - for (;*s != ' ' && *s != '\0' && IsAnsiCharacter(s); s++ ) { - if (*s == '~' || *s == JAP_TERMINATION) - { - s++; - while (*s != '~' && *s != JAP_TERMINATION) s++; - s++; - if (*s == ' ' || ((*s != '~' && *s != JAP_TERMINATION) && !IsAnsiCharacter(s))) - break; - } - } - } - else - { - for(; *s != ' ' && *s != '\0'; s++) - if(*s == '~'){ - s++; - while(*s != '~') s++; - s++; - if(*s == ' ') - break; - } - } - return s; -} - -#ifdef MORE_LANGUAGES -wchar* -CFont::ParseToken(wchar *s, wchar*, bool japShit) -{ - s++; - if ((Details.color.r || Details.color.g || Details.color.b) && !japShit) { - wchar c = *s; - if (IsJapanese()) - c &= 0x7FFF; - switch (c) { - case 'N': - case 'n': - NewLine = true; - break; - case 'b': SetColor(CRGBA(128, 167, 243, 255)); break; - case 'g': SetColor(CRGBA(95, 160, 106, 255)); break; - case 'h': SetColor(CRGBA(225, 225, 225, 255)); break; - case 'l': SetColor(CRGBA(0, 0, 0, 255)); break; - case 'p': SetColor(CRGBA(168, 110, 252, 255)); break; - case 'r': SetColor(CRGBA(113, 43, 73, 255)); break; - case 'w': SetColor(CRGBA(175, 175, 175, 255)); break; - case 'y': SetColor(CRGBA(210, 196, 106, 255)); break; - } - } else if (IsJapanese()) { - if ((*s & 0x7FFF) == 'N' || (*s & 0x7FFF) == 'n') - NewLine = true; - } - while ((!IsJapanese() || (*s != JAP_TERMINATION)) && *s != '~') s++; - return s + 1; -} -#else -wchar* -CFont::ParseToken(wchar *s, wchar*) -{ - s++; - if(Details.color.r || Details.color.g || Details.color.b) - switch(*s){ - case 'N': - case 'n': - NewLine = 1; - break; - case 'b': SetColor(CRGBA(0x80, 0xA7, 0xF3, 0xFF)); break; - case 'g': SetColor(CRGBA(0x5F, 0xA0, 0x6A, 0xFF)); break; - case 'h': SetColor(CRGBA(0xE1, 0xE1, 0xE1, 0xFF)); break; - case 'l': SetColor(CRGBA(0x00, 0x00, 0x00, 0xFF)); break; - case 'p': SetColor(CRGBA(0xA8, 0x6E, 0xFC, 0xFF)); break; - case 'r': SetColor(CRGBA(0x71, 0x2B, 0x49, 0xFF)); break; - case 'w': SetColor(CRGBA(0xAF, 0xAF, 0xAF, 0xFF)); break; - case 'y': SetColor(CRGBA(0xD2, 0xC4, 0x6A, 0xFF)); break; - } - while(*s != '~') s++; - return s+1; -} -#endif - -void -CFont::DrawFonts(void) -{ - CSprite2d::DrawBank(Details.bank); - CSprite2d::DrawBank(Details.bank+1); - CSprite2d::DrawBank(Details.bank+2); - if (IsJapanese()) - CSprite2d::DrawBank(Details.bank+3); -} - -wchar -CFont::character_code(uint8 c) -{ - if(c < 128) - return c; - return foreign_table[c-128]; -} - - -void -CFont::SetScale(float x, float y) -{ - /*if (LanguageSet == FONT_LANGSET_JAPANESE) { - x *= 1.35f; - y *= 1.25f; - }*/ - Details.scaleX = x; - Details.scaleY = y; -} - -void -CFont::SetBackgroundColor(const CRGBA &col) -{ - Details.backgroundColor = col; -} - -void -CFont::SetColor(const CRGBA &col) -{ - Details.color = col; - if (Details.alphaFade < 255.0f) - Details.color.a *= Details.alphaFade / 255.0f; -} - -void -CFont::SetDropColor(const CRGBA &col) -{ - Details.dropColor = col; - if (Details.alphaFade < 255.0f) - Details.dropColor.a *= Details.alphaFade / 255.0f; -} +#include "common.h" + +#include "Sprite2d.h" +#include "TxdStore.h" +#include "Font.h" + +CFontDetails CFont::Details; +int16 CFont::NewLine; +CSprite2d CFont::Sprite[MAX_FONTS]; + +#ifdef MORE_LANGUAGES +uint8 CFont::LanguageSet = FONT_LANGSET_EFIGS; +int32 CFont::Slot = -1; +#define JAP_TERMINATION (0x8000 | '~') + +int16 CFont::Size[LANGSET_MAX][MAX_FONTS][193] = { + { +#else +int16 CFont::Size[MAX_FONTS][193] = { +#endif + { + 13, 12, 31, 35, 23, 35, 31, 9, 14, 15, 25, 30, 11, 17, 13, 31, + 23, 16, 22, 21, 24, 23, 23, 20, 23, 22, 10, 35, 26, 26, 26, 26, + 30, 26, 24, 23, 24, 22, 21, 24, 26, 10, 20, 26, 22, 29, 26, 25, + 23, 25, 24, 24, 22, 25, 24, 29, 29, 23, 25, 37, 22, 37, 35, 37, + 35, 21, 22, 21, 21, 22, 13, 22, 21, 10, 16, 22, 11, 32, 21, 21, + 23, 22, 16, 20, 14, 21, 20, 30, 25, 21, 21, 33, 33, 33, 33, 35, + 27, 27, 27, 27, 32, 24, 23, 23, 23, 23, 11, 11, 11, 11, 26, 26, + 26, 26, 26, 26, 26, 25, 26, 21, 21, 21, 21, 32, 23, 22, 22, 22, + 22, 11, 11, 11, 11, 22, 22, 22, 22, 22, 22, 22, 22, 26, 21, 24, + 12, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 18, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 20 + }, + + { + 13, 9, 21, 35, 23, 35, 35, 11, 35, 35, 25, 35, 11, 17, 13, 33, + 28, 14, 22, 21, 24, 23, 23, 21, 23, 22, 10, 35, 13, 35, 13, 33, + 5, 25, 22, 23, 24, 21, 21, 24, 24, 9, 20, 24, 21, 27, 25, 25, + 22, 25, 23, 20, 23, 23, 23, 31, 23, 23, 23, 37, 33, 37, 35, 37, + 35, 21, 19, 19, 21, 19, 17, 21, 21, 8, 17, 18, 14, 24, 21, 21, + 20, 22, 19, 20, 20, 19, 20, 26, 21, 20, 21, 33, 33, 33, 33, 35, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 16 + }, + + { + 15, 14, 16, 25, 19, 26, 22, 11, 18, 18, 27, 26, 13, 19, 9, 27, + 19, 18, 19, 19, 22, 19, 20, 18, 19, 20, 12, 32, 15, 32, 15, 35, + 15, 19, 19, 19, 19, 19, 16, 19, 20, 9, 19, 20, 14, 29, 19, 20, + 19, 19, 19, 19, 21, 19, 20, 32, 20, 19, 19, 33, 31, 39, 37, 39, + 37, 21, 21, 21, 23, 21, 19, 23, 23, 10, 19, 20, 16, 26, 23, 23, + 20, 20, 20, 22, 21, 22, 22, 26, 22, 22, 23, 35, 35, 35, 35, 37, + 19, 19, 19, 19, 29, 19, 19, 19, 19, 19, 9, 9, 9, 9, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 30, 19, 19, 19, 19, + 19, 10, 10, 10, 10, 19, 19, 19, 19, 19, 19, 19, 19, 19, 23, 35, + 12, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 11, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19 + } +#ifdef MORE_LANGUAGES + }, + { + { 13, 12, 31, 35, 23, 35, 31, 9, 14, 15, 25, 30, 11, 17, + 13, 31, 23, 16, 22, 21, 24, 23, 23, 20, 23, 22, 10, + 35, 26, 26, 26, 26, 30, 26, 24, 23, 24, 22, 21, 24, + 26, 10, 20, 26, 22, 29, 26, 25, 23, 25, 24, 24, 22, + 25, 24, 29, 29, 23, 25, 37, 22, 37, 35, 37, 35, 21, + 22, 21, 21, 22, 13, 22, 21, 10, 16, 22, 11, 32, 21, + 21, 23, 22, 16, 20, 14, 21, 20, 30, 25, 21, 21, 13, + 33, 13, 13, 13, 24, 22, 22, 19, 26, 21, 30, 20, 23, + 23, 21, 24, 26, 23, 22, 23, 21, 22, 20, 20, 26, 25, + 24, 22, 31, 32, 23, 30, 22, 22, 32, 23, 19, 18, 18, + 15, 22, 19, 27, 19, 20, 20, 18, 22, 24, 20, 19, 19, + 20, 19, 16, 19, 28, 20, 20, 18, 26, 27, 19, 26, 18, + 19, 27, 19, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 18, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 20 }, + { 13, 9, 21, 35, 23, 35, 35, 11, 35, 35, 25, 35, 11, + 17, 13, 33, 28, 14, 22, 21, 24, 23, 23, 21, 23, 22, + 10, 35, 13, 35, 13, 33, 5, 25, 22, 23, 24, 21, 21, 24, + 24, 9, 20, 24, 21, 27, 25, 25, 22, 25, 23, 20, 23, 23, + 23, 31, 23, 23, 23, 37, 33, 37, 35, 37, 35, 21, 19, + 19, 21, 19, 17, 21, 21, 8, 17, 18, 14, 24, 21, 21, 20, + 22, 19, 20, 20, 19, 20, 26, 21, 20, 21, 33, 33, 33, + 33, 35, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 16, }, + { 15, 14, 16, 25, 19, + 26, 22, 11, 18, 18, 27, 26, 13, 19, 9, 27, 19, 18, 19, + 19, 22, 19, 20, 18, 19, 20, 12, 32, 15, 32, 15, 35, + 15, 19, 19, 19, 19, 19, 16, 19, 20, 9, 19, 20, 14, 29, + 19, 20, 19, 19, 19, 19, 21, 19, 20, 32, 20, 19, 19, + 33, 31, 39, 37, 39, 37, 21, 21, 21, 23, 21, 19, 23, 23, 10, 19, 20, 16, 26, 23, + 21, 21, 20, 20, 22, 21, 22, 22, 26, 22, 22, 23, 35, + 35, 35, 35, 37, 19, 19, 19, 19, 19, 19, 29, 19, 19, + 19, 20, 22, 31, 19, 19, 19, 19, 19, 29, 19, 29, 19, + 21, 19, 30, 31, 21, 29, 19, 19, 29, 19, 21, 23, 32, + 21, 21, 30, 31, 22, 21, 32, 33, 23, 32, 21, 21, 32, + 21, 19, 19, 30, 31, 22, 22, 21, 32, 33, 23, 32, 21, + 21, 32, 21, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 11, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19 }, + }, + + { + { + 13, 12, 31, 35, 23, 35, 31, 9, 14, 15, 25, 30, 11, 17, 13, 31, + 23, 16, 22, 21, 24, 23, 23, 20, 23, 22, 10, 35, 26, 26, 26, 26, + 30, 26, 24, 23, 24, 22, 21, 24, 26, 10, 20, 26, 22, 29, 26, 25, + 23, 25, 24, 24, 22, 25, 24, 29, 29, 23, 25, 37, 22, 37, 35, 37, + 35, 21, 22, 21, 21, 22, 13, 22, 21, 10, 16, 22, 11, 32, 21, 21, + 23, 22, 16, 20, 14, 21, 20, 30, 25, 21, 21, 33, 33, 33, 33, 35, + 27, 27, 27, 27, 32, 24, 23, 23, 23, 23, 11, 11, 11, 11, 26, 26, + 26, 26, 26, 26, 26, 25, 26, 21, 21, 21, 21, 32, 23, 22, 22, 22, + 22, 11, 11, 11, 11, 22, 22, 22, 22, 22, 22, 22, 22, 26, 21, 24, + 12, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 18, 26, 26, + 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, + 20 + }, + + { + 13, 9, 21, 35, 23, 35, 35, 11, 35, 35, 25, 35, 11, 17, 13, 33, + 28, 14, 22, 21, 24, 23, 23, 21, 23, 22, 10, 35, 13, 35, 13, 33, + 5, 25, 22, 23, 24, 21, 21, 24, 24, 9, 20, 24, 21, 27, 25, 25, + 22, 25, 23, 20, 23, 23, 23, 31, 23, 23, 23, 37, 33, 37, 35, 37, + 35, 21, 19, 19, 21, 19, 17, 21, 21, 8, 17, 18, 14, 24, 21, 21, + 20, 22, 19, 20, 20, 19, 20, 26, 21, 20, 21, 33, 33, 33, 33, 35, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 16 + }, + + { + 15, 14, 16, 25, 19, 26, 22, 11, 18, 18, 27, 26, 13, 19, 9, 27, + 19, 18, 19, 19, 22, 19, 20, 18, 19, 20, 12, 32, 15, 32, 15, 35, + 15, 19, 19, 19, 19, 19, 16, 19, 20, 9, 19, 20, 14, 29, 19, 20, + 19, 19, 19, 19, 21, 19, 20, 32, 20, 19, 19, 33, 31, 39, 37, 39, + 37, 21, 21, 21, 23, 21, 19, 23, 23, 10, 19, 20, 16, 26, 23, 23, + 20, 20, 20, 22, 21, 22, 22, 26, 22, 22, 23, 35, 35, 35, 35, 37, + 19, 19, 19, 19, 29, 19, 19, 19, 19, 19, 9, 9, 9, 9, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 30, 19, 19, 19, 19, + 19, 10, 10, 10, 10, 19, 19, 19, 19, 19, 19, 19, 19, 19, 23, 35, + 12, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 11, 19, 19, + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, + 19 + } + } +#endif +}; + +#ifdef MORE_LANGUAGES +int16 Size_jp[] = { + 15, 14, 16, 20, 19, 26, 22, 11, 18, 18, 27, 26, 13, //; 0 + 19, 20, 27, 19, 15, 19, 19, 21, 19, 20, 18, 19, 15, //; 13 + 13, 28, 15, 32, 15, 35, 15, 19, 19, 19, 19, 17, 16, //; 26 + 19, 20, 15, 19, 20, 14, 17, 19, 19, 19, 19, 19, 19, //; 39 + 19, 19, 20, 25, 20, 19, 19, 33, 31, 39, 37, 39, 37, //; 52 + 21, 21, 21, 19, 17, 15, 23, 21, 15, 19, 20, 16, 19, //; 65 + 19, 19, 20, 20, 17, 22, 19, 22, 22, 19, 22, 22, 23, //; 78 + 35, 35, 35, 35, 37, 19, 19, 19, 19, 29, 19, 19, 19, //; 91 + 19, 19, 9, 9, 9, 9, 19, 19, 19, 19, 19, 19, 19, 19, //; 104 + 19, 19, 19, 19, 19, 30, 19, 19, 19, 19, 19, 10, 10, //; 118 + 10, 10, 19, 19, 19, 19, 19, 19, 19, 19, 19, 23, 35, //; 131 + 12, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, //; 144 + 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, //; 157 + 19, 19, 19, 11, 19, 19, 19, 19, 19, 19, 19, 19, 19, //; 170 + 19, 19, 19, 19, 19, 19, 19, 19, 19, 21 +}; +#endif + +wchar foreign_table[128] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 176, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 177, 0, 0, 0, 0, 0, 95, 0, 0, 0, 0, 175, + 128, 129, 130, 0, 131, 0, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, + 0, 173, 142, 143, 144, 0, 145, 0, 0, 146, 147, 148, 149, 0, 0, 150, + 151, 152, 153, 0, 154, 0, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, + 0, 174, 165, 166, 167, 0, 168, 0, 0, 169, 170, 171, 172, 0, 0, 0, +}; + +void +CFont::Initialise(void) +{ + int slot; + + slot = CTxdStore::AddTxdSlot("fonts"); +#ifdef MORE_LANGUAGES + Slot = slot; + switch (LanguageSet) + { + case FONT_LANGSET_EFIGS: + default: + CTxdStore::LoadTxd(slot, "MODELS/FONTS.TXD"); + break; + case FONT_LANGSET_POLISH: + CTxdStore::LoadTxd(slot, "MODELS/FONTS_P.TXD"); + break; + case FONT_LANGSET_RUSSIAN: + CTxdStore::LoadTxd(slot, "MODELS/FONTS_R.TXD"); + break; + case FONT_LANGSET_JAPANESE: + CTxdStore::LoadTxd(slot, "MODELS/FONTS_J.TXD"); + break; + } +#else + CTxdStore::LoadTxd(slot, "MODELS/FONTS.TXD"); +#endif + CTxdStore::AddRef(slot); + CTxdStore::PushCurrentTxd(); + CTxdStore::SetCurrentTxd(slot); + Sprite[0].SetTexture("font2", "font2_mask"); +#ifdef MORE_LANGUAGES + if (IsJapanese()) { + Sprite[1].SetTexture("FONTJAP", "FONTJAP_mask"); + Sprite[3].SetTexture("FONTJAP", "FONTJAP_mask"); + } + else +#endif // MORE_LANGUAGES + Sprite[1].SetTexture("pager", "pager_mask"); + Sprite[2].SetTexture("font1", "font1_mask"); + SetScale(1.0f, 1.0f); + SetSlantRefPoint(SCREEN_WIDTH, 0.0f); + SetSlant(0.0f); + SetColor(CRGBA(0xFF, 0xFF, 0xFF, 0)); + SetJustifyOff(); + SetCentreOff(); + SetWrapx(DEFAULT_SCREEN_WIDTH); + SetCentreSize(DEFAULT_SCREEN_WIDTH); + SetBackgroundOff(); + SetBackgroundColor(CRGBA(0x80, 0x80, 0x80, 0x80)); + SetBackGroundOnlyTextOff(); + SetPropOn(); + SetFontStyle(FONT_BANK); + SetRightJustifyWrap(0.0f); + SetAlphaFade(255.0f); + SetDropShadowPosition(0); + CTxdStore::PopCurrentTxd(); +} + +#ifdef MORE_LANGUAGES +void +CFont::ReloadFonts(uint8 set) +{ + if (Slot != -1 && LanguageSet != set) { + Sprite[0].Delete(); + Sprite[1].Delete(); + Sprite[2].Delete(); + if (IsJapanese()) + Sprite[3].Delete(); + CTxdStore::PushCurrentTxd(); + CTxdStore::RemoveTxd(Slot); + switch (set) + { + case FONT_LANGSET_EFIGS: + default: + CTxdStore::LoadTxd(Slot, "MODELS/FONTS.TXD"); + break; + case FONT_LANGSET_POLISH: + CTxdStore::LoadTxd(Slot, "MODELS/FONTS_P.TXD"); + break; + case FONT_LANGSET_RUSSIAN: + CTxdStore::LoadTxd(Slot, "MODELS/FONTS_R.TXD"); + break; + case FONT_LANGSET_JAPANESE: + CTxdStore::LoadTxd(Slot, "MODELS/FONTS_J.TXD"); + break; + } + CTxdStore::SetCurrentTxd(Slot); + Sprite[0].SetTexture("font2", "font2_mask"); + if (set == FONT_LANGSET_JAPANESE) { + Sprite[1].SetTexture("FONTJAP", "FONTJAP_mask"); + Sprite[3].SetTexture("FONTJAP", "FONTJAP_mask"); + } + else + Sprite[1].SetTexture("pager", "pager_mask"); + Sprite[2].SetTexture("font1", "font1_mask"); + CTxdStore::PopCurrentTxd(); + } + LanguageSet = set; +} +#endif + +void +CFont::Shutdown(void) +{ + Sprite[0].Delete(); + Sprite[1].Delete(); + Sprite[2].Delete(); +#ifdef MORE_LANGUAGES + if (IsJapanese()) + Sprite[3].Delete(); + CTxdStore::RemoveTxdSlot(Slot); + Slot = -1; +#else + CTxdStore::RemoveTxdSlot(CTxdStore::FindTxdSlot("fonts")); +#endif +} + +void +CFont::InitPerFrame(void) +{ + Details.bank = CSprite2d::GetBank(30, Sprite[0].m_pTexture); + CSprite2d::GetBank(15, Sprite[1].m_pTexture); + CSprite2d::GetBank(15, Sprite[2].m_pTexture); +#ifdef MORE_LANGUAGES + if (IsJapanese()) + CSprite2d::GetBank(15, Sprite[3].m_pTexture); +#endif + SetDropShadowPosition(0); + NewLine = 0; +} + +void +CFont::PrintChar(float x, float y, wchar c) +{ + if(x <= 0.0f || x > SCREEN_WIDTH || + y <= 0.0f || y > SCREEN_HEIGHT) // BUG: game uses SCREENW again + return; + + float w = GetCharacterWidth(c) / 32.0f; + float xoff = c % 16; + float yoff = c / 16; +#ifdef MORE_LANGUAGES + if (IsJapaneseFont()) { + w = 21.0f; + xoff = (float)(c % 48); + yoff = c / 48; + } +#endif + + if(Details.style == FONT_BANK || Details.style == FONT_HEADING){ + if(Details.dropShadowPosition != 0){ + CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank + CRect(x + SCREEN_SCALE_X(Details.dropShadowPosition), + y + SCREEN_SCALE_Y(Details.dropShadowPosition), + x + SCREEN_SCALE_X(Details.dropShadowPosition) + 32.0f * Details.scaleX * 1.0f, + y + SCREEN_SCALE_Y(Details.dropShadowPosition) + 40.0f * Details.scaleY * 0.5f), + Details.dropColor, + xoff/16.0f, yoff/12.8f, + (xoff+1.0f)/16.0f - 0.001f, yoff/12.8f, + xoff/16.0f, (yoff+1.0f)/12.8f, + (xoff+1.0f)/16.0f - 0.001f, (yoff+1.0f)/12.8f - 0.0001f); + } + CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank + CRect(x, y, + x + 32.0f * Details.scaleX * 1.0f, + y + 40.0f * Details.scaleY * 0.5f), + Details.color, + xoff/16.0f, yoff/12.8f, + (xoff+1.0f)/16.0f - 0.001f, yoff/12.8f, + xoff/16.0f, (yoff+1.0f)/12.8f - 0.002f, + (xoff+1.0f)/16.0f - 0.001f, (yoff+1.0f)/12.8f - 0.002f); +#ifdef MORE_LANGUAGES + }else if (IsJapaneseFont()) { + if (Details.dropShadowPosition != 0) { + CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank + CRect(x + SCREEN_SCALE_X(Details.dropShadowPosition), + y + SCREEN_SCALE_Y(Details.dropShadowPosition), + x + SCREEN_SCALE_X(Details.dropShadowPosition) + 32.0f * Details.scaleX * 1.0f, + y + SCREEN_SCALE_Y(Details.dropShadowPosition) + 40.0f * Details.scaleY / 2.75f), + Details.dropColor, + xoff * w / 1024.0f, yoff / 25.6f, + xoff * w / 1024.0f + (1.0f / 48.0f) - 0.001f, yoff / 25.6f, + xoff * w / 1024.0f, (yoff + 1.0f) / 25.6f, + xoff * w / 1024.0f + (1.0f / 48.0f) - 0.001f, (yoff + 1.0f) / 25.6f - 0.0001f); + } + CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank + CRect(x, y, + x + 32.0f * Details.scaleX * 1.0f, + y + 40.0f * Details.scaleY / 2.75f), + Details.color, + xoff * w / 1024.0f, yoff / 25.6f, + xoff * w / 1024.0f + (1.0f / 48.0f) - 0.001f, yoff / 25.6f, + xoff * w / 1024.0f, (yoff + 1.0f) / 25.6f - 0.002f, + xoff * w / 1024.0f + (1.0f / 48.0f) - 0.001f, (yoff + 1.0f) / 25.6f - 0.0001f); +#endif + }else + CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank + CRect(x, y, + x + 32.0f * Details.scaleX * w, + y + 32.0f * Details.scaleY * 0.5f), + Details.color, + xoff/16.0f, yoff/16.0f, + (xoff+w)/16.0f, yoff/16.0f, + xoff/16.0f, (yoff+1.0f)/16.0f, + (xoff+w)/16.0f - 0.0001f, (yoff+1.0f)/16.0f - 0.0001f); +} + +#ifdef MORE_LANGUAGES +bool CFont::IsJapanesePunctuation(wchar *str) +{ + return (*str == 0xE7 || *str == 0x124 || *str == 0x126 || *str == 0x128 || *str == 0x104 || *str == ',' || *str == '>' || *str == '!' || *str == 0x99 || *str == '?' || *str == ':'); +} + +bool CFont::IsAnsiCharacter(wchar *s) +{ + if (*s >= 'A' && *s <= 'Z') + return true; + if (*s >= 'a' && *s <= 'z') + return true; + if (*s >= '0' && *s <= ':') + return true; + if (*s == '(' || *s == ')') + return true; + if (*s == 'D' || *s == '$') + return true; + return false; +} +#endif + +void +CFont::PrintString(float xstart, float ystart, wchar *s) +{ + CRect rect; + int numSpaces; + float lineLength; + float x, y; + bool first; + wchar *start, *t; + + if(*s == '*') + return; + + if(Details.background){ + GetNumberLines(xstart, ystart, s); // BUG: result not used + GetTextRect(&rect, xstart, ystart, s); + CSprite2d::DrawRect(rect, Details.backgroundColor); + } + + lineLength = 0.0f; + numSpaces = 0; + first = true; + if(Details.centre || Details.rightJustify) + x = 0.0f; + else + x = xstart; + y = ystart; + start = s; + + // This is super ugly, I blame R* + for(;;){ + for(;;){ + for(;;){ + if(*s == '\0') + return; + float xend = Details.centre ? Details.centreSize : + Details.rightJustify ? xstart - Details.rightJustifyWrap : + Details.wrapX; +#ifdef MORE_LANGUAGES + if (IsJapaneseFont()) + xend -= SCREEN_SCALE_X(21.0f * 2.0f); +#endif + if(x + GetStringWidth(s) > xend && !first){ +#ifdef MORE_LANGUAGES + if (IsJapanese() && IsJapanesePunctuation(s)) + s--; +#endif + // flush line + float spaceWidth = !Details.justify || Details.centre ? 0.0f : + (Details.wrapX - lineLength) / numSpaces; + float xleft = Details.centre ? xstart - x/2 : + Details.rightJustify ? xstart - x : + xstart; +#ifdef MORE_LANGUAGES + PrintString(xleft, y, start, s, spaceWidth, xstart); +#endif + // reset things + lineLength = 0.0f; + numSpaces = 0; + first = true; + if(Details.centre || Details.rightJustify) + x = 0.0f; + else + x = xstart; +#ifdef MORE_LANGUAGES + if (IsJapaneseFont()) + y += 32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY; + else +#endif + y += 32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY; + start = s; + }else + break; + } + // advance by one word + t = GetNextSpace(s); + if(t[0] == '\0' || + t[0] == ' ' && t[1] == '\0') + break; + if(!first) + numSpaces++; + first = false; + x += GetStringWidth(s) + GetCharacterSize(*t - ' '); +#ifdef MORE_LANGUAGES + if (IsJapaneseFont() && IsAnsiCharacter(s)) + x += 21.0f; +#endif + lineLength = x; + s = t+1; +#ifdef MORE_LANGUAGES + if (IsJapaneseFont() && !*s) { + x += GetStringWidth(s); + if (IsAnsiCharacter(s)) + x += 21.0f; + float xleft = Details.centre ? xstart - x / 2 : + Details.rightJustify ? xstart - x : + xstart; + if (PrintString(xleft, y, start, s, 0.0f, xstart)) + { + start = s; + if (!Details.centre && !Details.rightJustify) + x = xstart; + else + x = 0.0f; + + y += 32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY; + numSpaces = 0; + first = true; + lineLength = 0.0f; + } + } +#endif + } + // print rest + if(t[0] == ' ' && t[1] == '\0') + t[0] = '\0'; + x += GetStringWidth(s); + s = t; + float xleft = Details.centre ? xstart - x/2 : + Details.rightJustify ? xstart - x : + xstart; +#ifdef MORE_LANGUAGES + if (PrintString(xleft, y, start, s, 0.0f, xstart) && IsJapaneseFont()) { + start = s; + if (!Details.centre && !Details.rightJustify) + x = xstart; + else + x = 0.0f; + y += 32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY; + numSpaces = 0; + first = true; + lineLength = 0.0f; + } +#else + PrintString(xleft, y, start, s, 0.0f); +#endif + } +} + +int +CFont::GetNumberLines(float xstart, float ystart, wchar *s) +{ + int n; + float x, y; + wchar *t; + n = 0; + +#ifdef MORE_LANGUAGES + bool bSomeJapBool = false; + + if (IsJapanese()) { + t = s; + wchar unused; + while (*t) { + if (*t == JAP_TERMINATION || *t == '~') + t = ParseToken(t, &unused, true); + if (NewLine) { + n++; + NewLine = false; + bSomeJapBool = true; + } + t++; + } + } + + if (bSomeJapBool) n--; +#endif + + if(Details.centre || Details.rightJustify) + x = 0.0f; + else + x = xstart; + y = ystart; + + while(*s){ + float f = (Details.centre ? Details.centreSize : Details.wrapX); +#ifdef MORE_LANGUAGES + if (IsJapaneseFont()) + f -= SCREEN_SCALE_X(21.0f * 2.0f); +#endif + + if(x + GetStringWidth(s) > f){ +#ifdef MORE_LANGUAGES + if (IsJapanese()) + { + if (IsJapanesePunctuation(s)) + s--; + } +#endif + // reached end of line + if(Details.centre || Details.rightJustify) + x = 0.0f; + else + x = xstart; + n++; + // Why even? +#ifdef MORE_LANGUAGES + if (IsJapanese()) + y += 32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY; + else +#endif + y += 32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY; + }else{ + // still space in current line + t = GetNextSpace(s); + if(*t == '\0'){ + // end of string + x += GetStringWidth(s); +#ifdef MORE_LANGUAGES + if (IsJapanese() && IsAnsiCharacter(s)) + x += 21.0f; +#endif + n++; + s = t; + }else{ + x += GetStringWidth(s); +#ifdef MORE_LANGUAGES + if (IsJapanese() && IsAnsiCharacter(s)) + x += 21.0f; +#endif + s = t+1; + x += GetCharacterSize(*t - ' '); +#ifdef MORE_LANGUAGES + if (IsJapanese() && !*s) + n++; +#endif + } + } + } + + return n; +} + +void +CFont::GetTextRect(CRect *rect, float xstart, float ystart, wchar *s) +{ + int numLines; + float x, y; + int16 maxlength; + wchar *t; + + maxlength = 0; + numLines = 0; + +#ifdef MORE_LANGUAGES + if (IsJapanese()) { + numLines = GetNumberLines(xstart, ystart, s); + }else{ +#endif + if(Details.centre || Details.rightJustify) + x = 0.0f; + else + x = xstart; + y = ystart; + + while(*s){ + if(x + GetStringWidth(s) > (Details.centre ? Details.centreSize : Details.wrapX)){ + // reached end of line + if(x > maxlength) + maxlength = x; + if(Details.centre || Details.rightJustify) + x = 0.0f; + else + x = xstart; + numLines++; + y += 32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY; + }else{ + // still space in current line + t = GetNextSpace(s); + if(*t == '\0'){ + // end of string + x += GetStringWidth(s); + if(x > maxlength) + maxlength = x; + numLines++; + s = t; + }else{ + x += GetStringWidth(s); + x += GetCharacterSize(*t - ' '); + s = t+1; + } + } + } +#ifdef MORE_LANGUAGES + } +#endif + + if(Details.centre){ + if(Details.backgroundOnlyText){ + rect->left = xstart - maxlength/2 - 4.0f; + rect->right = xstart + maxlength/2 + 4.0f; +#ifdef MORE_LANGUAGES + if (IsJapaneseFont()) { + rect->bottom = (32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY) * numLines + ystart + (4.0f / 2.75f); + rect->top = ystart - (4.0f / 2.75f); + } else { +#endif + rect->bottom = (32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY) * numLines + ystart + 2.0f; + rect->top = ystart - 2.0f; +#ifdef MORE_LANGUAGES + } +#endif + }else{ + rect->left = xstart - Details.centreSize*0.5f - 4.0f; + rect->right = xstart + Details.centreSize*0.5f + 4.0f; +#ifdef MORE_LANGUAGES + if (IsJapaneseFont()) { + rect->bottom = (32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY) * numLines + ystart + (4.0f / 2.75f); + rect->top = ystart - (4.0f / 2.75f); + } else { +#endif + rect->bottom = (32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY) * numLines + ystart + 2.0f; + rect->top = ystart - 2.0f; +#ifdef MORE_LANGUAGES + } +#endif + } + }else{ + rect->left = xstart - 4.0f; + rect->right = Details.wrapX; + // WTF? + rect->bottom = ystart - 4.0f + 4.0f; +#ifdef MORE_LANGUAGES + if (IsJapaneseFont()) + rect->top = (32.0f * CFont::Details.scaleY / 2.75f + 2.0f * CFont::Details.scaleY) * numLines + ystart + 2.0f + (4.0f / 2.75f); + else +#endif + rect->top = (32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY) * numLines + ystart + 2.0f + 2.0f; + } +} + +#ifdef MORE_LANGUAGES +bool +CFont::PrintString(float x, float y, wchar *start, wchar *&end, float spwidth, float japX) +{ + wchar *s, c, unused; + + if (IsJapanese()) { + float jx = 0.0f; + for (s = start; s < end; s++) { + if (*s == JAP_TERMINATION || *s == '~') + s = ParseToken(s, &unused, true); + if (NewLine) { + NewLine = false; + break; + } + jx += GetCharacterSize(*s - ' '); + } + s = start; + if (Details.centre) + x = japX - jx / 2.0f; + else if (Details.rightJustify) + x = japX - jx; + } + + for (s = start; s < end; s++) { + if (*s == '~' || (IsJapanese() && *s == JAP_TERMINATION)) + s = ParseToken(s, &unused); + if (NewLine && IsJapanese()) { + NewLine = false; + end = s; + return true; + } + c = *s - ' '; + if (Details.slant != 0.0f && !IsJapanese()) + y = (Details.slantRefX - x) * Details.slant + Details.slantRefY; + PrintChar(x, y, c); + x += GetCharacterSize(c); + if (c == 0 && (!NewLine || !IsJapanese())) // space + x += spwidth; + } + return false; +} +#else +void +CFont::PrintString(float x, float y, wchar *start, wchar *end, float spwidth) +{ + wchar *s, c, unused; + + for(s = start; s < end; s++){ + if(*s == '~') + s = ParseToken(s, &unused); + c = *s - ' '; + if(Details.slant != 0.0f) + y = (Details.slantRefX - x)*Details.slant + Details.slantRefY; + PrintChar(x, y, c); + x += GetCharacterSize(c); + if(c == 0) // space + x += spwidth; + } +} +#endif + +float +CFont::GetCharacterWidth(wchar c) +{ +#ifdef MORE_LANGUAGES + if (IsJapanese()) { + if (!Details.proportional) + return Size[0][Details.style][192]; + if (c <= 94 || Details.style == FONT_HEADING || Details.style == FONT_BANK) { + switch (Details.style) + { + case FONT_JAPANESE: + return Size_jp[c]; + default: + return Size[0][Details.style][c]; + } + } + if (c < 254 && Details.style == FONT_PAGER) + return 29.4f; + + switch (Details.style) + { + case FONT_JAPANESE: + return 29.4f; + case FONT_BANK: + return 10.0f; + case FONT_PAGER: + return 31.5f; + default: + return Size[0][Details.style][c]; + } + } + + else if (Details.proportional) + return Size[LanguageSet][Details.style][c]; + else + return Size[LanguageSet][Details.style][192]; +#else + if (Details.proportional) + return Size[Details.style][c]; + else + return Size[Details.style][192]; +#endif // MORE_LANGUAGES +} + +float +CFont::GetCharacterSize(wchar c) +{ +#ifdef MORE_LANGUAGES + + if (IsJapanese()) + { + if (!Details.proportional) + return Size[0][Details.style][192] * Details.scaleX; + if (c <= 94 || Details.style == FONT_HEADING || Details.style == FONT_BANK) { + switch (Details.style) + { + case FONT_JAPANESE: + return Size_jp[c] * Details.scaleX; + default: + return Size[0][Details.style][c] * Details.scaleX; + } + } + if (c < 254 && (Details.style == FONT_PAGER)) + return 29.4f * Details.scaleX; + + switch (Details.style) + { + case FONT_JAPANESE: + return 29.4f * Details.scaleX; + case FONT_BANK: + return 10.0f * Details.scaleX; + case FONT_PAGER: + return 31.5f * Details.scaleX; + default: + return Size[0][Details.style][c] * Details.scaleX; + } + } + else if(Details.proportional) + return Size[LanguageSet][Details.style][c] * Details.scaleX; + else + return Size[LanguageSet][Details.style][192] * Details.scaleX; +#else + if (Details.proportional) + return Size[Details.style][c] * Details.scaleX; + else + return Size[Details.style][192] * Details.scaleX; +#endif // MORE_LANGUAGES +} + +float +CFont::GetStringWidth(wchar *s, bool spaces) +{ + float w; + + w = 0.0f; +#ifdef MORE_LANGUAGES + if (IsJapanese()) + { + do + { + if ((*s != ' ' || spaces) && *s != '\0') { + do { + while (*s == '~' || *s == JAP_TERMINATION) { + s++; + while (!(*s == '~' || *s == JAP_TERMINATION)) s++; + s++; + } + w += GetCharacterSize(*s - ' '); + ++s; + } while (*s == '~' || *s == JAP_TERMINATION); + } + } while (IsAnsiCharacter(s)); + } else +#endif + { + for (; (*s != ' ' || spaces) && *s != '\0'; s++) { + if (*s == '~') { + s++; + while (*s != '~') s++; + s++; + if (*s == ' ' && !spaces) + break; + } + w += GetCharacterSize(*s - ' '); + } + } + return w; +} + + +#ifdef MORE_LANGUAGES +float +CFont::GetStringWidth_Jap(wchar* s) +{ + float w; + + w = 0.0f; + for (; *s != '\0';) { + do { + while (*s == '~' || *s == JAP_TERMINATION) { + s++; + while (!(*s == '~' || *s == JAP_TERMINATION)) s++; + s++; + } + w += GetCharacterSize(*s - ' '); + ++s; + } while (*s == '~' || *s == JAP_TERMINATION); + } + return w; +} +#endif + +wchar* +CFont::GetNextSpace(wchar *s) +{ +#ifdef MORE_LANGUAGES + if (IsJapanese()) { + do + { + if (*s != ' ' && *s != '\0') { + do { + while (*s == '~' || *s == JAP_TERMINATION) { + s++; + while (!(*s == '~' || *s == JAP_TERMINATION)) s++; + s++; + } + ++s; + } while (*s == '~' || *s == JAP_TERMINATION); + } + } while (IsAnsiCharacter(s)); + } else +#endif + { + for(; *s != ' ' && *s != '\0'; s++) + if(*s == '~'){ + s++; + while(*s != '~') s++; + s++; + if(*s == ' ') + break; + } + } + return s; +} + +#ifdef MORE_LANGUAGES +wchar* +CFont::ParseToken(wchar *s, wchar*, bool japShit) +{ + s++; + if ((Details.color.r || Details.color.g || Details.color.b) && !japShit) { + wchar c = *s; + if (IsJapanese()) + c &= 0x7FFF; + switch (c) { + case 'N': + case 'n': + NewLine = true; + break; + case 'b': SetColor(CRGBA(128, 167, 243, 255)); break; + case 'g': SetColor(CRGBA(95, 160, 106, 255)); break; + case 'h': SetColor(CRGBA(225, 225, 225, 255)); break; + case 'l': SetColor(CRGBA(0, 0, 0, 255)); break; + case 'p': SetColor(CRGBA(168, 110, 252, 255)); break; + case 'r': SetColor(CRGBA(113, 43, 73, 255)); break; + case 'w': SetColor(CRGBA(175, 175, 175, 255)); break; + case 'y': SetColor(CRGBA(210, 196, 106, 255)); break; + } + } else if (IsJapanese()) { + if ((*s & 0x7FFF) == 'N' || (*s & 0x7FFF) == 'n') + NewLine = true; + } + while ((!IsJapanese() || (*s != JAP_TERMINATION)) && *s != '~') s++; + return s + 1; +} +#else +wchar* +CFont::ParseToken(wchar *s, wchar*) +{ + s++; + if(Details.color.r || Details.color.g || Details.color.b) + switch(*s){ + case 'N': + case 'n': + NewLine = 1; + break; + case 'b': SetColor(CRGBA(0x80, 0xA7, 0xF3, 0xFF)); break; + case 'g': SetColor(CRGBA(0x5F, 0xA0, 0x6A, 0xFF)); break; + case 'h': SetColor(CRGBA(0xE1, 0xE1, 0xE1, 0xFF)); break; + case 'l': SetColor(CRGBA(0x00, 0x00, 0x00, 0xFF)); break; + case 'p': SetColor(CRGBA(0xA8, 0x6E, 0xFC, 0xFF)); break; + case 'r': SetColor(CRGBA(0x71, 0x2B, 0x49, 0xFF)); break; + case 'w': SetColor(CRGBA(0xAF, 0xAF, 0xAF, 0xFF)); break; + case 'y': SetColor(CRGBA(0xD2, 0xC4, 0x6A, 0xFF)); break; + } + while(*s != '~') s++; + return s+1; +} +#endif + +void +CFont::DrawFonts(void) +{ + CSprite2d::DrawBank(Details.bank); + CSprite2d::DrawBank(Details.bank+1); + CSprite2d::DrawBank(Details.bank+2); +#ifdef MORE_LANGUAGES + if (IsJapanese()) + CSprite2d::DrawBank(Details.bank+3); +#endif +} + +wchar +CFont::character_code(uint8 c) +{ + if(c < 128) + return c; + return foreign_table[c-128]; +} + + +void +CFont::SetScale(float x, float y) +{ +#ifdef MORE_LANGUAGES + /*if (IsJapanese()) { + x *= 1.35f; + y *= 1.25f; + }*/ +#endif + Details.scaleX = x; + Details.scaleY = y; +} + +void +CFont::SetBackgroundColor(CRGBA col) +{ + Details.backgroundColor = col; +} + +void +CFont::SetColor(CRGBA col) +{ + Details.color = col; + if (Details.alphaFade < 255.0f) + Details.color.a *= Details.alphaFade / 255.0f; +} + +void +CFont::SetDropColor(CRGBA col) +{ + Details.dropColor = col; + if (Details.alphaFade < 255.0f) + Details.dropColor.a *= Details.alphaFade / 255.0f; +} diff --git a/src/render/Font.h b/src/render/Font.h index 73e9522a..9b4e7132 100644 --- a/src/render/Font.h +++ b/src/render/Font.h @@ -49,25 +49,23 @@ enum FONT_LANGSET_EFIGS, FONT_LANGSET_RUSSIAN, FONT_LANGSET_POLISH, - FONT_LANGSET_JAPANESE + FONT_LANGSET_JAPANESE, LANGSET_MAX }; -#endif -#define FONTJAP(style) (CFont::LanguageSet == FONT_LANGSET_JAPANESE ? FONT_JAPANESE : style) +#define FONT_LOCALE(style) (CFont::IsJapanese() ? FONT_JAPANESE : style) +#else +#define FONT_LOCALE(style) (style) +#endif class CFont { #ifdef MORE_LANGUAGES static int16 Size[LANGSET_MAX][MAX_FONTS][193]; -public: static uint8 LanguageSet; -private: static int32 Slot; - static CSprite2d Sprite[4]; #else static int16 Size[MAX_FONTS][193]; - static CSprite2d* Sprite; //[3] #endif static int16 NewLine; static CSprite2d Sprite[MAX_FONTS]; @@ -89,6 +87,9 @@ public: static float GetCharacterWidth(wchar c); static float GetCharacterSize(wchar c); static float GetStringWidth(wchar *s, bool spaces = false); +#ifdef MORE_LANGUAGES + static float GetStringWidth_Jap(wchar* s); +#endif static uint16 *GetNextSpace(wchar *s); #ifdef MORE_LANGUAGES static uint16 *ParseToken(wchar *s, wchar*, bool japShit = false); @@ -158,16 +159,16 @@ public: static void SetRightJustifyWrap(float wrap) { Details.rightJustifyWrap = wrap; } static void SetAlphaFade(float fade) { Details.alphaFade = fade; } static void SetDropShadowPosition(int16 pos) { Details.dropShadowPosition = pos; } - static void SetBackgroundColor(const CRGBA &col); - static void SetColor(const CRGBA &col); - static void SetDropColor(const CRGBA &col); + static void SetBackgroundColor(CRGBA col); + static void SetColor(CRGBA col); + static void SetDropColor(CRGBA col); #ifdef MORE_LANGUAGES static void ReloadFonts(uint8 set); // japanese stuff static bool IsAnsiCharacter(wchar* s); - static bool IsJapanesePunctuation(wchar* a1); + static bool IsJapanesePunctuation(wchar* str); static bool IsJapanese() { return LanguageSet == FONT_LANGSET_JAPANESE; } static bool IsJapaneseFont() { return IsJapanese() && (Details.style == FONT_JAPANESE || Details.style == FONT_PAGER); } #endif diff --git a/src/render/Hud.cpp b/src/render/Hud.cpp index a2a74109..3707f51f 100644 --- a/src/render/Hud.cpp +++ b/src/render/Hud.cpp @@ -660,7 +660,7 @@ void CHud::Draw() CFont::SetScale(SCREEN_SCALE_X(0.8f), SCREEN_SCALE_Y(1.35f)); CFont::SetRightJustifyOn(); CFont::SetRightJustifyWrap(0.0f); - CFont::SetFontStyle(FONTJAP(FONT_HEADING)); + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); CFont::SetPropOff(); CFont::SetBackGroundOnlyTextOn(); CFont::SetColor(CRGBA(0, 0, 0, 255)); @@ -701,7 +701,7 @@ void CHud::Draw() CFont::SetCentreOff(); CFont::SetRightJustifyOn(); CFont::SetRightJustifyWrap(0.0f); - CFont::SetFontStyle(FONTJAP(FONT_HEADING)); + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); CFont::SetColor(CRGBA(244, 20, 20, 255)); CFont::SetWrapx(SCREEN_SCALE_X(640.0f)); CFont::SetPropOff(); @@ -852,7 +852,7 @@ void CHud::Draw() else CFont::SetPropOff(); - CFont::SetFontStyle(FONTJAP(CTheScripts::IntroTextLines[i].m_nFont)); + CFont::SetFontStyle(FONT_LOCALE(CTheScripts::IntroTextLines[i].m_nFont)); CFont::PrintString(SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH - CTheScripts::IntroTextLines[i].m_fAtX), SCREEN_SCALE_Y(DEFAULT_SCREEN_HEIGHT - CTheScripts::IntroTextLines[i].m_fAtY), CTheScripts::IntroTextLines[i].m_Text); } } @@ -892,7 +892,7 @@ void CHud::Draw() CFont::SetScale(SCREEN_SCALE_X(0.48f), SCREEN_SCALE_Y(1.120f)); CFont::SetCentreOn(); CFont::SetPropOn(); - CFont::SetFontStyle(FONTJAP(FONT_BANK)); + CFont::SetFontStyle(FONT_LOCALE(FONT_BANK)); float offsetX = SCREEN_SCALE_X(40.0f) + SCREEN_SCALE_X(8.0f); float center = SCREEN_SCALE_FROM_RIGHT(50.0f) - SCREEN_SCALE_X(8.0f) - offsetX; @@ -1080,18 +1080,22 @@ void CHud::DrawAfterFade() if (CGame::germanGame) CFont::SetScale(SCREEN_SCALE_X(0.52f * 0.85f), SCREEN_SCALE_Y(1.1f * 0.85f)); - else if (CFont::LanguageSet == FONT_LANGSET_JAPANESE) +#ifdef MORE_LANGUAGES + else if (CFont::IsJapanese()) CFont::SetScale(SCREEN_SCALE_X(0.52f) * 1.35f, SCREEN_SCALE_Y(1.1f) * 1.25f); +#endif else CFont::SetScale(SCREEN_SCALE_X(0.52f), SCREEN_SCALE_Y(1.1f)); CFont::SetColor(CRGBA(175, 175, 175, 255)); CFont::SetJustifyOff(); - if (CFont::LanguageSet == FONT_LANGSET_JAPANESE) +#ifdef MORE_LANGUAGES + if (CFont::IsJapanese()) CFont::SetWrapx(SCREEN_SCALE_X(229.0f + 26.0f - 4.0f)); else +#endif CFont::SetWrapx(SCREEN_SCALE_X(200.0f + 26.0f - 4.0f)); - CFont::SetFontStyle(FONTJAP(FONT_BANK)); + CFont::SetFontStyle(FONT_LOCALE(FONT_BANK)); CFont::SetBackgroundOn(); CFont::SetBackGroundOnlyTextOff(); CFont::SetBackgroundColor(CRGBA(0, 0, 0, fAlpha * 0.9f)); @@ -1169,7 +1173,7 @@ void CHud::DrawAfterFade() CFont::SetCentreOn(); CFont::SetPropOn(); CFont::SetCentreSize(SCREEN_SCALE_X(600.0f)); - CFont::SetFontStyle(FONTJAP(FONT_BANK)); + CFont::SetFontStyle(FONT_LOCALE(FONT_BANK)); CFont::SetColor(CRGBA(0, 0, 0, 255)); CFont::PrintString((SCREEN_WIDTH / 2) + SCREEN_SCALE_X(2.0f), (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(84.0f) + SCREEN_SCALE_Y(2.0f), m_BigMessage[3]); @@ -1186,7 +1190,7 @@ void CHud::DrawAfterFade() CFont::SetPropOn(); CFont::SetCentreSize(SCREEN_SCALE_X(620.0f)); CFont::SetColor(CRGBA(0, 0, 0, 255)); - CFont::SetFontStyle(FONTJAP(FONT_BANK)); + CFont::SetFontStyle(FONT_LOCALE(FONT_BANK)); CFont::PrintString((SCREEN_WIDTH / 2) - SCREEN_SCALE_X(2.0f), (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(84.0f) - SCREEN_SCALE_Y(2.0f), m_BigMessage[4]); @@ -1243,7 +1247,7 @@ void CHud::DrawAfterFade() CFont::SetPropOn(); CFont::SetCentreSize(SCREEN_SCALE_FROM_RIGHT(20.0f)); CFont::SetColor(CRGBA(0, 0, 0, 255)); - CFont::SetFontStyle(FONTJAP(FONT_BANK)); + CFont::SetFontStyle(FONT_LOCALE(FONT_BANK)); #ifdef BETA_SLIDING_TEXT CFont::PrintString(SCREEN_WIDTH / 2 + SCREEN_SCALE_X(2.0f) - SCREEN_SCALE_X(OddJob2XOffset), SCREEN_HEIGHT / 2 - SCREEN_SCALE_Y(20.0f) + SCREEN_SCALE_Y(2.0f), m_BigMessage[5]); diff --git a/src/save/PCSave.cpp b/src/save/PCSave.cpp index 6f1b1b45..d3aeee26 100644 --- a/src/save/PCSave.cpp +++ b/src/save/PCSave.cpp @@ -3,6 +3,9 @@ #include "crossplatform.h" #include "FileMgr.h" +#ifdef MORE_LANGUAGES +#include "Game.h" +#endif #include "GenericGameStorage.h" #include "Messages.h" #include "PCSave.h" @@ -131,7 +134,12 @@ C_PcSave::PopulateSlotInfo() default: assert(0); } char date[70]; - sprintf(date, "%02d %s %04d %02d:%02d:%02d", st.wDay, UnicodeToAsciiForSaveLoad(TheText.Get(month)), st.wYear, st.wHour, st.wMinute, st.wSecond); +#ifdef MORE_LANGUAGES + if (CGame::japaneseGame) + sprintf(date, "%02d %02d %04d %02d:%02d:%02d", st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond); + else +#endif // MORE_LANGUAGES + sprintf(date, "%02d %s %04d %02d:%02d:%02d", st.wDay, UnicodeToAsciiForSaveLoad(TheText.Get(month)), st.wYear, st.wHour, st.wMinute, st.wSecond); AsciiToUnicode(date, SlotSaveDate[i]); } else { diff --git a/src/text/Messages.cpp b/src/text/Messages.cpp index 8a667adb..59341b84 100644 --- a/src/text/Messages.cpp +++ b/src/text/Messages.cpp @@ -1,818 +1,829 @@ -#include "common.h" - -#include "Messages.h" -#include "RwHelper.h" -#include "Hud.h" -#include "User.h" -#include "Timer.h" -#include "Text.h" - -#include "ControllerConfig.h" - -#include "Font.h" - -tMessage CMessages::BriefMessages[NUMBRIEFMESSAGES]; -tPreviousBrief CMessages::PreviousBriefs[NUMPREVIOUSBRIEFS]; -tBigMessage CMessages::BIGMessages[NUMBIGMESSAGES]; -char CMessages::PreviousMissionTitle[16]; // unused - -void -CMessages::Init() -{ - ClearMessages(); - - for (int32 i = 0; i < NUMPREVIOUSBRIEFS; i++) { - PreviousBriefs[i].m_pText = nil; - PreviousBriefs[i].m_pString = nil; - } -} - -uint16 -CMessages::GetWideStringLength(wchar *src) -{ - uint16 length = 0; - while (*(src++)) length++; - return length; -} - -void -CMessages::WideStringCopy(wchar *dst, wchar *src, uint16 size) -{ - int32 i = 0; - if (src) { - while (i < size - 1) { - if (!src[i]) break; - dst[i] = src[i]; - i++; - } - } else { - while (i < size - 1) - dst[i++] = '\0'; - } - dst[i] = '\0'; -} - -wchar jappy(wchar c) -{ - if (CFont::LanguageSet == FONT_LANGSET_JAPANESE) - return c & 0x7fff; - return c; -} - -bool -CMessages::WideStringCompare(wchar *str1, wchar *str2, uint16 size) -{ - uint16 len1 = GetWideStringLength(str1); - uint16 len2 = GetWideStringLength(str2); - if (len1 != len2 && (len1 < size || len2 < size)) - return false; - - for (int32 i = 0; i < size; i++) { - if (!jappy(str1[i])) - break; - - if (jappy(str1[i]) != jappy(str2[i])) - return false; - } - return true; -} - -void -CMessages::Process() -{ - for (int32 style = 0; style < 6; style++) { - if (BIGMessages[style].m_Stack[0].m_pText != nil && CTimer::GetTimeInMilliseconds() > BIGMessages[style].m_Stack[0].m_nTime + BIGMessages[style].m_Stack[0].m_nStartTime) { - BIGMessages[style].m_Stack[0].m_pText = nil; - - int32 i = 0; - while (i < 3) { - if (BIGMessages[style].m_Stack[i + 1].m_pText == nil) break; - BIGMessages[style].m_Stack[i] = BIGMessages[style].m_Stack[i + 1]; - i++; - } - - BIGMessages[style].m_Stack[i].m_pText = nil; - BIGMessages[style].m_Stack[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); - } - } - - if (BriefMessages[0].m_pText != nil && CTimer::GetTimeInMilliseconds() > BriefMessages[0].m_nTime + BriefMessages[0].m_nStartTime) { - BriefMessages[0].m_pText = nil; - int32 i = 0; - while (i < NUMBRIEFMESSAGES-1) { - if (BriefMessages[i + 1].m_pText == nil) - break; - - BriefMessages[i] = BriefMessages[i + 1]; - i++; - } - CMessages::BriefMessages[i].m_pText = nil; - CMessages::BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); - if (BriefMessages[0].m_pText != nil) - AddToPreviousBriefArray( - BriefMessages[0].m_pText, - BriefMessages[0].m_nNumber[0], - BriefMessages[0].m_nNumber[1], - BriefMessages[0].m_nNumber[2], - BriefMessages[0].m_nNumber[3], - BriefMessages[0].m_nNumber[4], - BriefMessages[0].m_nNumber[5], - BriefMessages[0].m_pString); - } -} - -void -CMessages::Display() -{ - wchar outstr[256]; - - DefinedState(); - - for (int32 i = 0; i < NUMBIGMESSAGES; i++) { - InsertNumberInString( - BIGMessages[i].m_Stack[0].m_pText, - BIGMessages[i].m_Stack[0].m_nNumber[0], - BIGMessages[i].m_Stack[0].m_nNumber[1], - BIGMessages[i].m_Stack[0].m_nNumber[2], - BIGMessages[i].m_Stack[0].m_nNumber[3], - BIGMessages[i].m_Stack[0].m_nNumber[4], - BIGMessages[i].m_Stack[0].m_nNumber[5], - outstr); - InsertStringInString(outstr, BIGMessages[i].m_Stack[0].m_pString); - InsertPlayerControlKeysInString(outstr); - CHud::SetBigMessage(outstr, i); - } - - InsertNumberInString( - BriefMessages[0].m_pText, - BriefMessages[0].m_nNumber[0], - BriefMessages[0].m_nNumber[1], - BriefMessages[0].m_nNumber[2], - BriefMessages[0].m_nNumber[3], - BriefMessages[0].m_nNumber[4], - BriefMessages[0].m_nNumber[5], - outstr); - InsertStringInString(outstr, BriefMessages[0].m_pString); - InsertPlayerControlKeysInString(outstr); - CHud::SetMessage(outstr); -} - -void -CMessages::AddMessage(wchar *msg, uint32 time, uint16 flag) -{ - wchar outstr[512]; // unused - WideStringCopy(outstr, msg, 256); - InsertPlayerControlKeysInString(outstr); - GetWideStringLength(outstr); - - int32 i = 0; - while (i < NUMBRIEFMESSAGES && BriefMessages[i].m_pText != nil) - i++; - if (i >= NUMBRIEFMESSAGES) return; - - BriefMessages[i].m_pText = msg; - BriefMessages[i].m_nFlag = flag; - BriefMessages[i].m_nTime = time; - BriefMessages[i].m_nStartTime = CTimer::GetTimeInMilliseconds(); - BriefMessages[i].m_nNumber[0] = -1; - BriefMessages[i].m_nNumber[1] = -1; - BriefMessages[i].m_nNumber[2] = -1; - BriefMessages[i].m_nNumber[3] = -1; - BriefMessages[i].m_nNumber[4] = -1; - BriefMessages[i].m_nNumber[5] = -1; - BriefMessages[i].m_pString = nil; - if (i == 0) - AddToPreviousBriefArray( - BriefMessages[0].m_pText, - BriefMessages[0].m_nNumber[0], - BriefMessages[0].m_nNumber[1], - BriefMessages[0].m_nNumber[2], - BriefMessages[0].m_nNumber[3], - BriefMessages[0].m_nNumber[4], - BriefMessages[0].m_nNumber[5], - BriefMessages[0].m_pString); -} - -void -CMessages::AddMessageJumpQ(wchar *msg, uint32 time, uint16 flag) -{ - wchar outstr[512]; // unused - WideStringCopy(outstr, msg, 256); - InsertPlayerControlKeysInString(outstr); - GetWideStringLength(outstr); - - BriefMessages[0].m_pText = msg; - BriefMessages[0].m_nFlag = flag; - BriefMessages[0].m_nTime = time; - BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); - BriefMessages[0].m_nNumber[0] = -1; - BriefMessages[0].m_nNumber[1] = -1; - BriefMessages[0].m_nNumber[2] = -1; - BriefMessages[0].m_nNumber[3] = -1; - BriefMessages[0].m_nNumber[4] = -1; - BriefMessages[0].m_nNumber[5] = -1; - BriefMessages[0].m_pString = nil; - AddToPreviousBriefArray(msg, -1, -1, -1, -1, -1, -1, 0); -} - -void -CMessages::AddMessageSoon(wchar *msg, uint32 time, uint16 flag) -{ - wchar outstr[512]; // unused - WideStringCopy(outstr, msg, 256); - InsertPlayerControlKeysInString(outstr); - GetWideStringLength(outstr); - - if (BriefMessages[0].m_pText != nil) { - for (int i = NUMBRIEFMESSAGES-1; i > 1; i--) - BriefMessages[i] = BriefMessages[i-1]; - - BriefMessages[1].m_pText = msg; - BriefMessages[1].m_nFlag = flag; - BriefMessages[1].m_nTime = time; - BriefMessages[1].m_nStartTime = CTimer::GetTimeInMilliseconds(); - BriefMessages[1].m_nNumber[0] = -1; - BriefMessages[1].m_nNumber[1] = -1; - BriefMessages[1].m_nNumber[2] = -1; - BriefMessages[1].m_nNumber[3] = -1; - BriefMessages[1].m_nNumber[4] = -1; - BriefMessages[1].m_nNumber[5] = -1; - BriefMessages[1].m_pString = nil; - }else{ - BriefMessages[0].m_pText = msg; - BriefMessages[0].m_nFlag = flag; - BriefMessages[0].m_nTime = time; - BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); - BriefMessages[0].m_nNumber[0] = -1; - BriefMessages[0].m_nNumber[1] = -1; - BriefMessages[0].m_nNumber[2] = -1; - BriefMessages[0].m_nNumber[3] = -1; - BriefMessages[0].m_nNumber[4] = -1; - BriefMessages[0].m_nNumber[5] = -1; - BriefMessages[0].m_pString = nil; - AddToPreviousBriefArray(msg, -1, -1, -1, -1, -1, -1, nil); - } -} - -void -CMessages::ClearMessages() -{ - for (int32 i = 0; i < NUMBIGMESSAGES; i++) { - for (int32 j = 0; j < 4; j++) { - BIGMessages[i].m_Stack[j].m_pText = nil; - BIGMessages[i].m_Stack[j].m_pString = nil; - } - } - ClearSmallMessagesOnly(); -} - -void -CMessages::ClearSmallMessagesOnly() -{ - for (int32 i = 0; i < NUMBRIEFMESSAGES; i++) { - BriefMessages[i].m_pText = nil; - BriefMessages[i].m_pString = nil; - } -} - -void -CMessages::AddBigMessage(wchar *msg, uint32 time, uint16 style) -{ - wchar outstr[512]; // unused - WideStringCopy(outstr, msg, 256); - InsertPlayerControlKeysInString(outstr); - GetWideStringLength(outstr); - - BIGMessages[style].m_Stack[0].m_pText = msg; - BIGMessages[style].m_Stack[0].m_nFlag = 0; - BIGMessages[style].m_Stack[0].m_nTime = time; - BIGMessages[style].m_Stack[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); - BIGMessages[style].m_Stack[0].m_nNumber[0] = -1; - BIGMessages[style].m_Stack[0].m_nNumber[1] = -1; - BIGMessages[style].m_Stack[0].m_nNumber[2] = -1; - BIGMessages[style].m_Stack[0].m_nNumber[3] = -1; - BIGMessages[style].m_Stack[0].m_nNumber[4] = -1; - BIGMessages[style].m_Stack[0].m_nNumber[5] = -1; - BIGMessages[style].m_Stack[0].m_pString = nil; -} -void -CMessages::AddBigMessageQ(wchar *msg, uint32 time, uint16 style) -{ - wchar outstr[512]; // unused - WideStringCopy(outstr, msg, 256); - InsertPlayerControlKeysInString(outstr); - GetWideStringLength(outstr); - - int32 i = 0; - while (i < 4 && BIGMessages[style].m_Stack[i].m_pText != nil) - i++; - - if (i >= 4) return; - - BIGMessages[style].m_Stack[i].m_pText = msg; - BIGMessages[style].m_Stack[i].m_nFlag = 0; - BIGMessages[style].m_Stack[i].m_nTime = time; - BIGMessages[style].m_Stack[i].m_nStartTime = CTimer::GetTimeInMilliseconds(); - BIGMessages[style].m_Stack[i].m_nNumber[0] = -1; - BIGMessages[style].m_Stack[i].m_nNumber[1] = -1; - BIGMessages[style].m_Stack[i].m_nNumber[2] = -1; - BIGMessages[style].m_Stack[i].m_nNumber[3] = -1; - BIGMessages[style].m_Stack[i].m_nNumber[4] = -1; - BIGMessages[style].m_Stack[i].m_nNumber[5] = -1; - BIGMessages[style].m_Stack[i].m_pString = nil; -} - -void -CMessages::AddToPreviousBriefArray(wchar *text, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6, wchar *string) -{ - int32 i = 0; - while (i < NUMPREVIOUSBRIEFS) { - if (PreviousBriefs[i].m_pText == nil) - break; - if (PreviousBriefs[i].m_nNumber[0] == n1 - && PreviousBriefs[i].m_nNumber[1] == n2 - && PreviousBriefs[i].m_nNumber[2] == n3 - && PreviousBriefs[i].m_nNumber[3] == n4 - && PreviousBriefs[i].m_nNumber[4] == n5 - && PreviousBriefs[i].m_nNumber[5] == n6 - && PreviousBriefs[i].m_pText == text - && PreviousBriefs[i].m_pString == string) - return; - - i++; - } - - if (i != 0) { - if (i == NUMPREVIOUSBRIEFS) i -= 2; - else i--; - - while (i >= 0) { - PreviousBriefs[i + 1] = PreviousBriefs[i]; - i--; - } - } - PreviousBriefs[0].m_pText = text; - PreviousBriefs[0].m_nNumber[0] = n1; - PreviousBriefs[0].m_nNumber[1] = n2; - PreviousBriefs[0].m_nNumber[2] = n3; - PreviousBriefs[0].m_nNumber[3] = n4; - PreviousBriefs[0].m_nNumber[4] = n5; - PreviousBriefs[0].m_nNumber[5] = n6; - PreviousBriefs[0].m_pString = string; -} - -void -CMessages::InsertNumberInString(wchar *str, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6, wchar *outstr) -{ - char numStr[10]; - wchar wNumStr[10]; - - if (str == nil) { - *outstr = '\0'; - return; - } - - int32 size = GetWideStringLength(str); - - int32 i = 0; - - for (int32 c = 0; c < size;) { - if ((CFont::LanguageSet == FONT_LANGSET_JAPANESE && str[c] == (0x8000 | '~') && str[c + 1] == (0x8000 | '1') && str[c + 2] == (0x8000 | '~')) || - (CFont::LanguageSet != FONT_LANGSET_JAPANESE && str[c] == '~' && str[c + 1] == '1' && str[c + 2] == '~')) - { - //if (str[c] == '~' && str[c + 1] == '1' && str[c + 2] == '~') { - switch (i) { - case 0: sprintf(numStr, "%d", n1); break; - case 1: sprintf(numStr, "%d", n2); break; - case 2: sprintf(numStr, "%d", n3); break; - case 3: sprintf(numStr, "%d", n4); break; - case 4: sprintf(numStr, "%d", n5); break; - case 5: sprintf(numStr, "%d", n6); break; - } - i++; - AsciiToUnicode(numStr, wNumStr); - - int j = 0; - while (wNumStr[j] != '\0') - *(outstr++) = wNumStr[j++]; - - c += 3; - } else { - *(outstr++) = str[c++]; - } - } - *outstr = '\0'; -} - -void -CMessages::InsertStringInString(wchar *str1, wchar *str2) -{ - wchar tempstr[256]; - - if (!str1 || !str2) return; - - int32 str1_size = GetWideStringLength(str1); - int32 str2_size = GetWideStringLength(str2); - int32 total_size = str1_size + str2_size; - - wchar *_str1 = str1; - uint16 i; - for (i = 0; i < total_size; ) { - if ((CFont::LanguageSet == FONT_LANGSET_JAPANESE && *_str1 == (0x8000 | '~') && *(_str1 + 1) == (0x8000 | 'a') && *(_str1 + 2) == (0x8000 | '~')) - || (CFont::LanguageSet != FONT_LANGSET_JAPANESE && *_str1 == '~' && *(_str1 + 1) == 'a' && *(_str1 + 2) == '~')) - { - //if (*_str1 == '~' && *(_str1 + 1) == 'a' && *(_str1 + 2) == '~') { - _str1 += 3; - for (int j = 0; j < str2_size; j++) { - tempstr[i++] = str2[j]; - } - } else { - tempstr[i++] = *(_str1++); - } - } - tempstr[i] = '\0'; - - for (i = 0; i < total_size; i++) - str1[i] = tempstr[i]; - - while (i < 256) - str1[i++] = '\0'; -} - -void -CMessages::InsertPlayerControlKeysInString(wchar *str) -{ - uint16 i; - wchar outstr[256]; - wchar keybuf[256]; - - if (!str) return; - uint16 strSize = GetWideStringLength(str); - memset(keybuf, 0, 256*sizeof(wchar)); - - wchar *_outstr = outstr; - for (i = 0; i < strSize;) { - if ((CFont::LanguageSet == FONT_LANGSET_JAPANESE && str[i] == (0x8000 | '~') && str[i + 1] == (0x8000 | 'k') && str[i + 2] == (0x8000 | '~')) || - (CFont::LanguageSet != FONT_LANGSET_JAPANESE && str[i] == '~' && str[i + 1] == 'k' && str[i + 2] == '~')) { - i += 4; - for (int32 cont = 0; cont < MAX_CONTROLLERACTIONS; cont++) { - uint16 contSize = GetWideStringLength(ControlsManager.m_aActionNames[cont]); - if (contSize != 0) { - if (WideStringCompare(&str[i], ControlsManager.m_aActionNames[cont], contSize)) { - ControlsManager.GetWideStringOfCommandKeys(cont, keybuf, 256); - uint16 keybuf_size = GetWideStringLength(keybuf); - for (uint16 j = 0; j < keybuf_size; j++) { - *(_outstr++) = keybuf[j]; - keybuf[j] = '\0'; - } - i += contSize + 1; - } - } - } - } else { - *(_outstr++) = str[i++]; - } - } - *_outstr = '\0'; - - for (i = 0; i < GetWideStringLength(outstr); i++) - str[i] = outstr[i]; - - while (i < 256) - str[i++] = '\0'; -} - -void -CMessages::AddMessageWithNumber(wchar *str, uint32 time, uint16 flag, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6) -{ - wchar outstr[512]; // unused - InsertNumberInString(str, n1, n2, n3, n4, n5, n6, outstr); - InsertPlayerControlKeysInString(outstr); - GetWideStringLength(outstr); - - uint16 i = 0; - while (i < NUMBRIEFMESSAGES && BriefMessages[i].m_pText) - i++; - - if (i >= NUMBRIEFMESSAGES) return; - - BriefMessages[i].m_pText = str; - BriefMessages[i].m_nFlag = flag; - BriefMessages[i].m_nTime = time; - BriefMessages[i].m_nStartTime = CTimer::GetTimeInMilliseconds(); - BriefMessages[i].m_nNumber[0] = n1; - BriefMessages[i].m_nNumber[1] = n2; - BriefMessages[i].m_nNumber[2] = n3; - BriefMessages[i].m_nNumber[3] = n4; - BriefMessages[i].m_nNumber[4] = n5; - BriefMessages[i].m_nNumber[5] = n6; - BriefMessages[i].m_pString = nil; - if (i == 0) - AddToPreviousBriefArray( - BriefMessages[0].m_pText, - BriefMessages[0].m_nNumber[0], - BriefMessages[0].m_nNumber[1], - BriefMessages[0].m_nNumber[2], - BriefMessages[0].m_nNumber[3], - BriefMessages[0].m_nNumber[4], - BriefMessages[0].m_nNumber[5], - BriefMessages[0].m_pString); -} - -void -CMessages::AddMessageJumpQWithNumber(wchar *str, uint32 time, uint16 flag, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6) -{ - wchar outstr[512]; // unused - InsertNumberInString(str, n1, n2, n3, n4, n5, n6, outstr); - InsertPlayerControlKeysInString(outstr); - GetWideStringLength(outstr); - - BriefMessages[0].m_pText = str; - BriefMessages[0].m_nFlag = flag; - BriefMessages[0].m_nTime = time; - BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); - BriefMessages[0].m_nNumber[0] = n1; - BriefMessages[0].m_nNumber[1] = n2; - BriefMessages[0].m_nNumber[2] = n3; - BriefMessages[0].m_nNumber[3] = n4; - BriefMessages[0].m_nNumber[4] = n5; - BriefMessages[0].m_nNumber[5] = n6; - BriefMessages[0].m_pString = nil; - AddToPreviousBriefArray(str, n1, n2, n3, n4, n5, n6, nil); -} - -void -CMessages::AddMessageSoonWithNumber(wchar *str, uint32 time, uint16 flag, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6) -{ - wchar outstr[512]; // unused - InsertNumberInString(str, n1, n2, n3, n4, n5, n6, outstr); - InsertPlayerControlKeysInString(outstr); - GetWideStringLength(outstr); - - if (BriefMessages[0].m_pText != nil) { - for (int32 i = NUMBRIEFMESSAGES-1; i > 1; i--) - BriefMessages[i] = BriefMessages[i-1]; - - BriefMessages[1].m_pText = str; - BriefMessages[1].m_nFlag = flag; - BriefMessages[1].m_nTime = time; - BriefMessages[1].m_nStartTime = CTimer::GetTimeInMilliseconds(); - BriefMessages[1].m_nNumber[0] = n1; - BriefMessages[1].m_nNumber[1] = n2; - BriefMessages[1].m_nNumber[2] = n3; - BriefMessages[1].m_nNumber[3] = n4; - BriefMessages[1].m_nNumber[4] = n5; - BriefMessages[1].m_nNumber[5] = n6; - BriefMessages[1].m_pString = nil; - } else { - BriefMessages[0].m_pText = str; - BriefMessages[0].m_nFlag = flag; - BriefMessages[0].m_nTime = time; - BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); - BriefMessages[0].m_nNumber[0] = n1; - BriefMessages[0].m_nNumber[1] = n2; - BriefMessages[0].m_nNumber[2] = n3; - BriefMessages[0].m_nNumber[3] = n4; - BriefMessages[0].m_nNumber[4] = n5; - BriefMessages[0].m_nNumber[5] = n6; - BriefMessages[0].m_pString = nil; - AddToPreviousBriefArray(str, n1, n2, n3, n4, n5, n6, nil); - } -} - -void -CMessages::AddBigMessageWithNumber(wchar *str, uint32 time, uint16 style, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6) -{ - wchar outstr[512]; // unused - InsertNumberInString(str, n1, n2, n3, n4, n5, n6, outstr); - InsertPlayerControlKeysInString(outstr); - GetWideStringLength(outstr); - - BIGMessages[style].m_Stack[0].m_pText = str; - BIGMessages[style].m_Stack[0].m_nFlag = 0; - BIGMessages[style].m_Stack[0].m_nTime = time; - BIGMessages[style].m_Stack[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); - BIGMessages[style].m_Stack[0].m_nNumber[0] = n1; - BIGMessages[style].m_Stack[0].m_nNumber[1] = n2; - BIGMessages[style].m_Stack[0].m_nNumber[2] = n3; - BIGMessages[style].m_Stack[0].m_nNumber[3] = n4; - BIGMessages[style].m_Stack[0].m_nNumber[4] = n5; - BIGMessages[style].m_Stack[0].m_nNumber[5] = n6; - BIGMessages[style].m_Stack[0].m_pString = nil; -} - -void -CMessages::AddBigMessageWithNumberQ(wchar *str, uint32 time, uint16 style, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6) -{ - wchar outstr[512]; // unused - InsertNumberInString(str, n1, n2, n3, n4, n5, n6, outstr); - InsertPlayerControlKeysInString(outstr); - GetWideStringLength(outstr); - - int32 i = 0; - - while (i < 4 && BIGMessages[style].m_Stack[i].m_pText != nil) - i++; - - if (i >= 4) return; - - BIGMessages[style].m_Stack[i].m_pText = str; - BIGMessages[style].m_Stack[i].m_nFlag = 0; - BIGMessages[style].m_Stack[i].m_nTime = time; - BIGMessages[style].m_Stack[i].m_nStartTime = CTimer::GetTimeInMilliseconds(); - BIGMessages[style].m_Stack[i].m_nNumber[0] = n1; - BIGMessages[style].m_Stack[i].m_nNumber[1] = n2; - BIGMessages[style].m_Stack[i].m_nNumber[2] = n3; - BIGMessages[style].m_Stack[i].m_nNumber[3] = n4; - BIGMessages[style].m_Stack[i].m_nNumber[4] = n5; - BIGMessages[style].m_Stack[i].m_nNumber[5] = n6; - BIGMessages[style].m_Stack[i].m_pString = nil; -} - -void -CMessages::AddMessageWithString(wchar *text, uint32 time, uint16 flag, wchar *str) -{ - wchar outstr[512]; // unused - WideStringCopy(outstr, text, 256); - InsertStringInString(outstr, str); - InsertPlayerControlKeysInString(outstr); - GetWideStringLength(outstr); - - int32 i = 0; - while (i < NUMBRIEFMESSAGES && BriefMessages[i].m_pText != nil) - i++; - - if (i >= NUMBRIEFMESSAGES) return; - - BriefMessages[i].m_pText = text; - BriefMessages[i].m_nFlag = flag; - BriefMessages[i].m_nTime = time; - BriefMessages[i].m_nStartTime = CTimer::GetTimeInMilliseconds(); - BriefMessages[i].m_nNumber[0] = -1; - BriefMessages[i].m_nNumber[1] = -1; - BriefMessages[i].m_nNumber[2] = -1; - BriefMessages[i].m_nNumber[3] = -1; - BriefMessages[i].m_nNumber[4] = -1; - BriefMessages[i].m_nNumber[5] = -1; - BriefMessages[i].m_pString = str; - if (i == 0) - AddToPreviousBriefArray( - BriefMessages[0].m_pText, - BriefMessages[0].m_nNumber[0], - BriefMessages[0].m_nNumber[1], - BriefMessages[0].m_nNumber[2], - BriefMessages[0].m_nNumber[3], - BriefMessages[0].m_nNumber[4], - BriefMessages[0].m_nNumber[5], - BriefMessages[0].m_pString); -} - -void -CMessages::AddMessageJumpQWithString(wchar *text, uint32 time, uint16 flag, wchar *str) -{ - wchar outstr[512]; // unused - WideStringCopy(outstr, text, 256); - InsertStringInString(outstr, str); - InsertPlayerControlKeysInString(outstr); - GetWideStringLength(outstr); - - BriefMessages[0].m_pText = text; - BriefMessages[0].m_nFlag = flag; - BriefMessages[0].m_nTime = time; - BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); - BriefMessages[0].m_nNumber[0] = -1; - BriefMessages[0].m_nNumber[1] = -1; - BriefMessages[0].m_nNumber[2] = -1; - BriefMessages[0].m_nNumber[3] = -1; - BriefMessages[0].m_nNumber[4] = -1; - BriefMessages[0].m_nNumber[5] = -1; - BriefMessages[0].m_pString = str; - AddToPreviousBriefArray(text, -1, -1, -1, -1, -1, -1, str); -} - -inline bool -FastWideStringComparison(wchar *str1, wchar *str2) -{ - while (*str1 == *str2) { - ++str1; - ++str2; - if (!*str1 && !*str2) return true; - } - return false; -} - -void -CMessages::ClearThisPrint(wchar *str) -{ - bool equal; - - do { - equal = false; - uint16 i = 0; - while (i < NUMBRIEFMESSAGES) { - if (BriefMessages[i].m_pText == nil) - break; - - equal = FastWideStringComparison(str, BriefMessages[i].m_pText); - - if (equal) break; - i++; - } - - if (equal) { - if (i != 0) { - BriefMessages[i].m_pText = nil; - while (i < NUMBRIEFMESSAGES-1) { - if (BriefMessages[i + 1].m_pText == nil) - break; - - BriefMessages[i] = BriefMessages[i + 1]; - i++; - } - BriefMessages[i].m_pText = nil; - } else { - BriefMessages[0].m_pText = nil; - while (i < NUMBRIEFMESSAGES-1) { - if (BriefMessages[i + 1].m_pText == nil) - break; - BriefMessages[i] = BriefMessages[i + 1]; - i++; - } - BriefMessages[i].m_pText = nil; - BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); - if (BriefMessages[0].m_pText == nil) - AddToPreviousBriefArray( - BriefMessages[0].m_pText, - BriefMessages[0].m_nNumber[0], - BriefMessages[0].m_nNumber[1], - BriefMessages[0].m_nNumber[2], - BriefMessages[0].m_nNumber[3], - BriefMessages[0].m_nNumber[4], - BriefMessages[0].m_nNumber[5], - BriefMessages[0].m_pString); - } - } - } while (equal); -} - -void -CMessages::ClearThisBigPrint(wchar *str) -{ - bool equal; - - do { - uint16 i = 0; - equal = false; - uint16 style = 0; - while (style < NUMBIGMESSAGES) - { - if (i >= 4) - break; - - if (CMessages::BIGMessages[style].m_Stack[i].m_pText == nil || equal) - break; - - equal = FastWideStringComparison(str, BIGMessages[style].m_Stack[i].m_pText); - - if (!equal && ++i == 4) { - i = 0; - style++; - } - } - if (equal) { - if (i != 0) { - BIGMessages[style].m_Stack[i].m_pText = nil; - while (i < 3) { - if (BIGMessages[style].m_Stack[i + 1].m_pText == nil) - break; - BIGMessages[style].m_Stack[i] = BIGMessages[style].m_Stack[i + 1]; - i++; - } - BIGMessages[style].m_Stack[i].m_pText = nil; - } else { - BIGMessages[style].m_Stack[0].m_pText = 0; - i = 0; - while (i < 3) { - if (BIGMessages[style].m_Stack[i + 1].m_pText == nil) - break; - BIGMessages[style].m_Stack[i] = BIGMessages[style].m_Stack[i + 1]; - i++; - } - BIGMessages[style].m_Stack[i].m_pText = nil; - BIGMessages[style].m_Stack[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); - } - } - } while (equal); -} - -void -CMessages::ClearAllMessagesDisplayedByGame() -{ - ClearMessages(); - for (int32 i = 0; i < NUMPREVIOUSBRIEFS; i++) { - PreviousBriefs[i].m_pText = nil; - PreviousBriefs[i].m_pString = nil; - } - CHud::GetRidOfAllHudMessages(); - CUserDisplay::Pager.ClearMessages(); -} +#include "common.h" + +#include "Messages.h" +#include "RwHelper.h" +#include "Hud.h" +#include "User.h" +#include "Timer.h" +#include "Text.h" + +#include "ControllerConfig.h" + +#include "Font.h" + +tMessage CMessages::BriefMessages[NUMBRIEFMESSAGES]; +tPreviousBrief CMessages::PreviousBriefs[NUMPREVIOUSBRIEFS]; +tBigMessage CMessages::BIGMessages[NUMBIGMESSAGES]; +char CMessages::PreviousMissionTitle[16]; // unused + +void +CMessages::Init() +{ + ClearMessages(); + + for (int32 i = 0; i < NUMPREVIOUSBRIEFS; i++) { + PreviousBriefs[i].m_pText = nil; + PreviousBriefs[i].m_pString = nil; + } +} + +uint16 +CMessages::GetWideStringLength(wchar *src) +{ + uint16 length = 0; + while (*(src++)) length++; + return length; +} + +void +CMessages::WideStringCopy(wchar *dst, wchar *src, uint16 size) +{ + int32 i = 0; + if (src) { + while (i < size - 1) { + if (!src[i]) break; + dst[i] = src[i]; + i++; + } + } else { + while (i < size - 1) + dst[i++] = '\0'; + } + dst[i] = '\0'; +} + +wchar FixupChar(wchar c) +{ +#ifdef MORE_LANGUAGES + if (CFont::IsJapanese()) + return c & 0x7fff; +#endif + return c; +} + +bool +CMessages::WideStringCompare(wchar *str1, wchar *str2, uint16 size) +{ + uint16 len1 = GetWideStringLength(str1); + uint16 len2 = GetWideStringLength(str2); + if (len1 != len2 && (len1 < size || len2 < size)) + return false; + + for (int32 i = 0; i < size; i++) { + if (FixupChar(str1[i]) == '\0') + break; + + if (FixupChar(str1[i]) != FixupChar(str2[i])) + return false; + } + return true; +} + +void +CMessages::Process() +{ + for (int32 style = 0; style < 6; style++) { + if (BIGMessages[style].m_Stack[0].m_pText != nil && CTimer::GetTimeInMilliseconds() > BIGMessages[style].m_Stack[0].m_nTime + BIGMessages[style].m_Stack[0].m_nStartTime) { + BIGMessages[style].m_Stack[0].m_pText = nil; + + int32 i = 0; + while (i < 3) { + if (BIGMessages[style].m_Stack[i + 1].m_pText == nil) break; + BIGMessages[style].m_Stack[i] = BIGMessages[style].m_Stack[i + 1]; + i++; + } + + BIGMessages[style].m_Stack[i].m_pText = nil; + BIGMessages[style].m_Stack[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); + } + } + + if (BriefMessages[0].m_pText != nil && CTimer::GetTimeInMilliseconds() > BriefMessages[0].m_nTime + BriefMessages[0].m_nStartTime) { + BriefMessages[0].m_pText = nil; + int32 i = 0; + while (i < NUMBRIEFMESSAGES-1) { + if (BriefMessages[i + 1].m_pText == nil) + break; + + BriefMessages[i] = BriefMessages[i + 1]; + i++; + } + CMessages::BriefMessages[i].m_pText = nil; + CMessages::BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); + if (BriefMessages[0].m_pText != nil) + AddToPreviousBriefArray( + BriefMessages[0].m_pText, + BriefMessages[0].m_nNumber[0], + BriefMessages[0].m_nNumber[1], + BriefMessages[0].m_nNumber[2], + BriefMessages[0].m_nNumber[3], + BriefMessages[0].m_nNumber[4], + BriefMessages[0].m_nNumber[5], + BriefMessages[0].m_pString); + } +} + +void +CMessages::Display() +{ + wchar outstr[256]; + + DefinedState(); + + for (int32 i = 0; i < NUMBIGMESSAGES; i++) { + InsertNumberInString( + BIGMessages[i].m_Stack[0].m_pText, + BIGMessages[i].m_Stack[0].m_nNumber[0], + BIGMessages[i].m_Stack[0].m_nNumber[1], + BIGMessages[i].m_Stack[0].m_nNumber[2], + BIGMessages[i].m_Stack[0].m_nNumber[3], + BIGMessages[i].m_Stack[0].m_nNumber[4], + BIGMessages[i].m_Stack[0].m_nNumber[5], + outstr); + InsertStringInString(outstr, BIGMessages[i].m_Stack[0].m_pString); + InsertPlayerControlKeysInString(outstr); + CHud::SetBigMessage(outstr, i); + } + + InsertNumberInString( + BriefMessages[0].m_pText, + BriefMessages[0].m_nNumber[0], + BriefMessages[0].m_nNumber[1], + BriefMessages[0].m_nNumber[2], + BriefMessages[0].m_nNumber[3], + BriefMessages[0].m_nNumber[4], + BriefMessages[0].m_nNumber[5], + outstr); + InsertStringInString(outstr, BriefMessages[0].m_pString); + InsertPlayerControlKeysInString(outstr); + CHud::SetMessage(outstr); +} + +void +CMessages::AddMessage(wchar *msg, uint32 time, uint16 flag) +{ + wchar outstr[512]; // unused + WideStringCopy(outstr, msg, 256); + InsertPlayerControlKeysInString(outstr); + GetWideStringLength(outstr); + + int32 i = 0; + while (i < NUMBRIEFMESSAGES && BriefMessages[i].m_pText != nil) + i++; + if (i >= NUMBRIEFMESSAGES) return; + + BriefMessages[i].m_pText = msg; + BriefMessages[i].m_nFlag = flag; + BriefMessages[i].m_nTime = time; + BriefMessages[i].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BriefMessages[i].m_nNumber[0] = -1; + BriefMessages[i].m_nNumber[1] = -1; + BriefMessages[i].m_nNumber[2] = -1; + BriefMessages[i].m_nNumber[3] = -1; + BriefMessages[i].m_nNumber[4] = -1; + BriefMessages[i].m_nNumber[5] = -1; + BriefMessages[i].m_pString = nil; + if (i == 0) + AddToPreviousBriefArray( + BriefMessages[0].m_pText, + BriefMessages[0].m_nNumber[0], + BriefMessages[0].m_nNumber[1], + BriefMessages[0].m_nNumber[2], + BriefMessages[0].m_nNumber[3], + BriefMessages[0].m_nNumber[4], + BriefMessages[0].m_nNumber[5], + BriefMessages[0].m_pString); +} + +void +CMessages::AddMessageJumpQ(wchar *msg, uint32 time, uint16 flag) +{ + wchar outstr[512]; // unused + WideStringCopy(outstr, msg, 256); + InsertPlayerControlKeysInString(outstr); + GetWideStringLength(outstr); + + BriefMessages[0].m_pText = msg; + BriefMessages[0].m_nFlag = flag; + BriefMessages[0].m_nTime = time; + BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BriefMessages[0].m_nNumber[0] = -1; + BriefMessages[0].m_nNumber[1] = -1; + BriefMessages[0].m_nNumber[2] = -1; + BriefMessages[0].m_nNumber[3] = -1; + BriefMessages[0].m_nNumber[4] = -1; + BriefMessages[0].m_nNumber[5] = -1; + BriefMessages[0].m_pString = nil; + AddToPreviousBriefArray(msg, -1, -1, -1, -1, -1, -1, 0); +} + +void +CMessages::AddMessageSoon(wchar *msg, uint32 time, uint16 flag) +{ + wchar outstr[512]; // unused + WideStringCopy(outstr, msg, 256); + InsertPlayerControlKeysInString(outstr); + GetWideStringLength(outstr); + + if (BriefMessages[0].m_pText != nil) { + for (int i = NUMBRIEFMESSAGES-1; i > 1; i--) + BriefMessages[i] = BriefMessages[i-1]; + + BriefMessages[1].m_pText = msg; + BriefMessages[1].m_nFlag = flag; + BriefMessages[1].m_nTime = time; + BriefMessages[1].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BriefMessages[1].m_nNumber[0] = -1; + BriefMessages[1].m_nNumber[1] = -1; + BriefMessages[1].m_nNumber[2] = -1; + BriefMessages[1].m_nNumber[3] = -1; + BriefMessages[1].m_nNumber[4] = -1; + BriefMessages[1].m_nNumber[5] = -1; + BriefMessages[1].m_pString = nil; + }else{ + BriefMessages[0].m_pText = msg; + BriefMessages[0].m_nFlag = flag; + BriefMessages[0].m_nTime = time; + BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BriefMessages[0].m_nNumber[0] = -1; + BriefMessages[0].m_nNumber[1] = -1; + BriefMessages[0].m_nNumber[2] = -1; + BriefMessages[0].m_nNumber[3] = -1; + BriefMessages[0].m_nNumber[4] = -1; + BriefMessages[0].m_nNumber[5] = -1; + BriefMessages[0].m_pString = nil; + AddToPreviousBriefArray(msg, -1, -1, -1, -1, -1, -1, nil); + } +} + +void +CMessages::ClearMessages() +{ + for (int32 i = 0; i < NUMBIGMESSAGES; i++) { + for (int32 j = 0; j < 4; j++) { + BIGMessages[i].m_Stack[j].m_pText = nil; + BIGMessages[i].m_Stack[j].m_pString = nil; + } + } + ClearSmallMessagesOnly(); +} + +void +CMessages::ClearSmallMessagesOnly() +{ + for (int32 i = 0; i < NUMBRIEFMESSAGES; i++) { + BriefMessages[i].m_pText = nil; + BriefMessages[i].m_pString = nil; + } +} + +void +CMessages::AddBigMessage(wchar *msg, uint32 time, uint16 style) +{ + wchar outstr[512]; // unused + WideStringCopy(outstr, msg, 256); + InsertPlayerControlKeysInString(outstr); + GetWideStringLength(outstr); + + BIGMessages[style].m_Stack[0].m_pText = msg; + BIGMessages[style].m_Stack[0].m_nFlag = 0; + BIGMessages[style].m_Stack[0].m_nTime = time; + BIGMessages[style].m_Stack[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BIGMessages[style].m_Stack[0].m_nNumber[0] = -1; + BIGMessages[style].m_Stack[0].m_nNumber[1] = -1; + BIGMessages[style].m_Stack[0].m_nNumber[2] = -1; + BIGMessages[style].m_Stack[0].m_nNumber[3] = -1; + BIGMessages[style].m_Stack[0].m_nNumber[4] = -1; + BIGMessages[style].m_Stack[0].m_nNumber[5] = -1; + BIGMessages[style].m_Stack[0].m_pString = nil; +} +void +CMessages::AddBigMessageQ(wchar *msg, uint32 time, uint16 style) +{ + wchar outstr[512]; // unused + WideStringCopy(outstr, msg, 256); + InsertPlayerControlKeysInString(outstr); + GetWideStringLength(outstr); + + int32 i = 0; + while (i < 4 && BIGMessages[style].m_Stack[i].m_pText != nil) + i++; + + if (i >= 4) return; + + BIGMessages[style].m_Stack[i].m_pText = msg; + BIGMessages[style].m_Stack[i].m_nFlag = 0; + BIGMessages[style].m_Stack[i].m_nTime = time; + BIGMessages[style].m_Stack[i].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BIGMessages[style].m_Stack[i].m_nNumber[0] = -1; + BIGMessages[style].m_Stack[i].m_nNumber[1] = -1; + BIGMessages[style].m_Stack[i].m_nNumber[2] = -1; + BIGMessages[style].m_Stack[i].m_nNumber[3] = -1; + BIGMessages[style].m_Stack[i].m_nNumber[4] = -1; + BIGMessages[style].m_Stack[i].m_nNumber[5] = -1; + BIGMessages[style].m_Stack[i].m_pString = nil; +} + +void +CMessages::AddToPreviousBriefArray(wchar *text, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6, wchar *string) +{ + int32 i = 0; + while (i < NUMPREVIOUSBRIEFS) { + if (PreviousBriefs[i].m_pText == nil) + break; + if (PreviousBriefs[i].m_nNumber[0] == n1 + && PreviousBriefs[i].m_nNumber[1] == n2 + && PreviousBriefs[i].m_nNumber[2] == n3 + && PreviousBriefs[i].m_nNumber[3] == n4 + && PreviousBriefs[i].m_nNumber[4] == n5 + && PreviousBriefs[i].m_nNumber[5] == n6 + && PreviousBriefs[i].m_pText == text + && PreviousBriefs[i].m_pString == string) + return; + + i++; + } + + if (i != 0) { + if (i == NUMPREVIOUSBRIEFS) i -= 2; + else i--; + + while (i >= 0) { + PreviousBriefs[i + 1] = PreviousBriefs[i]; + i--; + } + } + PreviousBriefs[0].m_pText = text; + PreviousBriefs[0].m_nNumber[0] = n1; + PreviousBriefs[0].m_nNumber[1] = n2; + PreviousBriefs[0].m_nNumber[2] = n3; + PreviousBriefs[0].m_nNumber[3] = n4; + PreviousBriefs[0].m_nNumber[4] = n5; + PreviousBriefs[0].m_nNumber[5] = n6; + PreviousBriefs[0].m_pString = string; +} + +void +CMessages::InsertNumberInString(wchar *str, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6, wchar *outstr) +{ + char numStr[10]; + wchar wNumStr[10]; + + if (str == nil) { + *outstr = '\0'; + return; + } + + int32 size = GetWideStringLength(str); + + int32 i = 0; + + for (int32 c = 0; c < size;) { +#ifdef MORE_LANGUAGES + if ((CFont::IsJapanese() && str[c] == (0x8000 | '~') && str[c + 1] == (0x8000 | '1') && str[c + 2] == (0x8000 | '~')) || + (!CFont::IsJapanese() && str[c] == '~' && str[c + 1] == '1' && str[c + 2] == '~')) { +#else + if (str[c] == '~' && str[c + 1] == '1' && str[c + 2] == '~') { +#endif + switch (i) { + case 0: sprintf(numStr, "%d", n1); break; + case 1: sprintf(numStr, "%d", n2); break; + case 2: sprintf(numStr, "%d", n3); break; + case 3: sprintf(numStr, "%d", n4); break; + case 4: sprintf(numStr, "%d", n5); break; + case 5: sprintf(numStr, "%d", n6); break; + } + i++; + AsciiToUnicode(numStr, wNumStr); + + int j = 0; + while (wNumStr[j] != '\0') + *(outstr++) = wNumStr[j++]; + + c += 3; + } else { + *(outstr++) = str[c++]; + } + } + *outstr = '\0'; +} + +void +CMessages::InsertStringInString(wchar *str1, wchar *str2) +{ + wchar tempstr[256]; + + if (!str1 || !str2) return; + + int32 str1_size = GetWideStringLength(str1); + int32 str2_size = GetWideStringLength(str2); + int32 total_size = str1_size + str2_size; + + wchar *_str1 = str1; + uint16 i; + for (i = 0; i < total_size; ) { +#ifdef MORE_LANGUAGES + if ((CFont::IsJapanese() && *_str1 == (0x8000 | '~') && *(_str1 + 1) == (0x8000 | 'a') && *(_str1 + 2) == (0x8000 | '~')) + || (CFont::IsJapanese() && *_str1 == '~' && *(_str1 + 1) == 'a' && *(_str1 + 2) == '~')) + { +#else + if (*_str1 == '~' && *(_str1 + 1) == 'a' && *(_str1 + 2) == '~') { +#endif + _str1 += 3; + for (int j = 0; j < str2_size; j++) { + tempstr[i++] = str2[j]; + } + } else { + tempstr[i++] = *(_str1++); + } + } + tempstr[i] = '\0'; + + for (i = 0; i < total_size; i++) + str1[i] = tempstr[i]; + + while (i < 256) + str1[i++] = '\0'; +} + +void +CMessages::InsertPlayerControlKeysInString(wchar *str) +{ + uint16 i; + wchar outstr[256]; + wchar keybuf[256]; + + if (!str) return; + uint16 strSize = GetWideStringLength(str); + memset(keybuf, 0, 256*sizeof(wchar)); + + wchar *_outstr = outstr; + for (i = 0; i < strSize;) { +#ifdef MORE_LANGUAGES + if ((CFont::IsJapanese() && str[i] == (0x8000 | '~') && str[i + 1] == (0x8000 | 'k') && str[i + 2] == (0x8000 | '~')) || + (!CFont::IsJapanese() && str[i] == '~' && str[i + 1] == 'k' && str[i + 2] == '~')) { +#else + if (str[i] == '~' && str[i + 1] == 'k' && str[i + 2] == '~') { +#endif + i += 4; + for (int32 cont = 0; cont < MAX_CONTROLLERACTIONS; cont++) { + uint16 contSize = GetWideStringLength(ControlsManager.m_aActionNames[cont]); + if (contSize != 0) { + if (WideStringCompare(&str[i], ControlsManager.m_aActionNames[cont], contSize)) { + ControlsManager.GetWideStringOfCommandKeys(cont, keybuf, 256); + uint16 keybuf_size = GetWideStringLength(keybuf); + for (uint16 j = 0; j < keybuf_size; j++) { + *(_outstr++) = keybuf[j]; + keybuf[j] = '\0'; + } + i += contSize + 1; + } + } + } + } else { + *(_outstr++) = str[i++]; + } + } + *_outstr = '\0'; + + for (i = 0; i < GetWideStringLength(outstr); i++) + str[i] = outstr[i]; + + while (i < 256) + str[i++] = '\0'; +} + +void +CMessages::AddMessageWithNumber(wchar *str, uint32 time, uint16 flag, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6) +{ + wchar outstr[512]; // unused + InsertNumberInString(str, n1, n2, n3, n4, n5, n6, outstr); + InsertPlayerControlKeysInString(outstr); + GetWideStringLength(outstr); + + uint16 i = 0; + while (i < NUMBRIEFMESSAGES && BriefMessages[i].m_pText) + i++; + + if (i >= NUMBRIEFMESSAGES) return; + + BriefMessages[i].m_pText = str; + BriefMessages[i].m_nFlag = flag; + BriefMessages[i].m_nTime = time; + BriefMessages[i].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BriefMessages[i].m_nNumber[0] = n1; + BriefMessages[i].m_nNumber[1] = n2; + BriefMessages[i].m_nNumber[2] = n3; + BriefMessages[i].m_nNumber[3] = n4; + BriefMessages[i].m_nNumber[4] = n5; + BriefMessages[i].m_nNumber[5] = n6; + BriefMessages[i].m_pString = nil; + if (i == 0) + AddToPreviousBriefArray( + BriefMessages[0].m_pText, + BriefMessages[0].m_nNumber[0], + BriefMessages[0].m_nNumber[1], + BriefMessages[0].m_nNumber[2], + BriefMessages[0].m_nNumber[3], + BriefMessages[0].m_nNumber[4], + BriefMessages[0].m_nNumber[5], + BriefMessages[0].m_pString); +} + +void +CMessages::AddMessageJumpQWithNumber(wchar *str, uint32 time, uint16 flag, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6) +{ + wchar outstr[512]; // unused + InsertNumberInString(str, n1, n2, n3, n4, n5, n6, outstr); + InsertPlayerControlKeysInString(outstr); + GetWideStringLength(outstr); + + BriefMessages[0].m_pText = str; + BriefMessages[0].m_nFlag = flag; + BriefMessages[0].m_nTime = time; + BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BriefMessages[0].m_nNumber[0] = n1; + BriefMessages[0].m_nNumber[1] = n2; + BriefMessages[0].m_nNumber[2] = n3; + BriefMessages[0].m_nNumber[3] = n4; + BriefMessages[0].m_nNumber[4] = n5; + BriefMessages[0].m_nNumber[5] = n6; + BriefMessages[0].m_pString = nil; + AddToPreviousBriefArray(str, n1, n2, n3, n4, n5, n6, nil); +} + +void +CMessages::AddMessageSoonWithNumber(wchar *str, uint32 time, uint16 flag, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6) +{ + wchar outstr[512]; // unused + InsertNumberInString(str, n1, n2, n3, n4, n5, n6, outstr); + InsertPlayerControlKeysInString(outstr); + GetWideStringLength(outstr); + + if (BriefMessages[0].m_pText != nil) { + for (int32 i = NUMBRIEFMESSAGES-1; i > 1; i--) + BriefMessages[i] = BriefMessages[i-1]; + + BriefMessages[1].m_pText = str; + BriefMessages[1].m_nFlag = flag; + BriefMessages[1].m_nTime = time; + BriefMessages[1].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BriefMessages[1].m_nNumber[0] = n1; + BriefMessages[1].m_nNumber[1] = n2; + BriefMessages[1].m_nNumber[2] = n3; + BriefMessages[1].m_nNumber[3] = n4; + BriefMessages[1].m_nNumber[4] = n5; + BriefMessages[1].m_nNumber[5] = n6; + BriefMessages[1].m_pString = nil; + } else { + BriefMessages[0].m_pText = str; + BriefMessages[0].m_nFlag = flag; + BriefMessages[0].m_nTime = time; + BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BriefMessages[0].m_nNumber[0] = n1; + BriefMessages[0].m_nNumber[1] = n2; + BriefMessages[0].m_nNumber[2] = n3; + BriefMessages[0].m_nNumber[3] = n4; + BriefMessages[0].m_nNumber[4] = n5; + BriefMessages[0].m_nNumber[5] = n6; + BriefMessages[0].m_pString = nil; + AddToPreviousBriefArray(str, n1, n2, n3, n4, n5, n6, nil); + } +} + +void +CMessages::AddBigMessageWithNumber(wchar *str, uint32 time, uint16 style, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6) +{ + wchar outstr[512]; // unused + InsertNumberInString(str, n1, n2, n3, n4, n5, n6, outstr); + InsertPlayerControlKeysInString(outstr); + GetWideStringLength(outstr); + + BIGMessages[style].m_Stack[0].m_pText = str; + BIGMessages[style].m_Stack[0].m_nFlag = 0; + BIGMessages[style].m_Stack[0].m_nTime = time; + BIGMessages[style].m_Stack[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BIGMessages[style].m_Stack[0].m_nNumber[0] = n1; + BIGMessages[style].m_Stack[0].m_nNumber[1] = n2; + BIGMessages[style].m_Stack[0].m_nNumber[2] = n3; + BIGMessages[style].m_Stack[0].m_nNumber[3] = n4; + BIGMessages[style].m_Stack[0].m_nNumber[4] = n5; + BIGMessages[style].m_Stack[0].m_nNumber[5] = n6; + BIGMessages[style].m_Stack[0].m_pString = nil; +} + +void +CMessages::AddBigMessageWithNumberQ(wchar *str, uint32 time, uint16 style, int32 n1, int32 n2, int32 n3, int32 n4, int32 n5, int32 n6) +{ + wchar outstr[512]; // unused + InsertNumberInString(str, n1, n2, n3, n4, n5, n6, outstr); + InsertPlayerControlKeysInString(outstr); + GetWideStringLength(outstr); + + int32 i = 0; + + while (i < 4 && BIGMessages[style].m_Stack[i].m_pText != nil) + i++; + + if (i >= 4) return; + + BIGMessages[style].m_Stack[i].m_pText = str; + BIGMessages[style].m_Stack[i].m_nFlag = 0; + BIGMessages[style].m_Stack[i].m_nTime = time; + BIGMessages[style].m_Stack[i].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BIGMessages[style].m_Stack[i].m_nNumber[0] = n1; + BIGMessages[style].m_Stack[i].m_nNumber[1] = n2; + BIGMessages[style].m_Stack[i].m_nNumber[2] = n3; + BIGMessages[style].m_Stack[i].m_nNumber[3] = n4; + BIGMessages[style].m_Stack[i].m_nNumber[4] = n5; + BIGMessages[style].m_Stack[i].m_nNumber[5] = n6; + BIGMessages[style].m_Stack[i].m_pString = nil; +} + +void +CMessages::AddMessageWithString(wchar *text, uint32 time, uint16 flag, wchar *str) +{ + wchar outstr[512]; // unused + WideStringCopy(outstr, text, 256); + InsertStringInString(outstr, str); + InsertPlayerControlKeysInString(outstr); + GetWideStringLength(outstr); + + int32 i = 0; + while (i < NUMBRIEFMESSAGES && BriefMessages[i].m_pText != nil) + i++; + + if (i >= NUMBRIEFMESSAGES) return; + + BriefMessages[i].m_pText = text; + BriefMessages[i].m_nFlag = flag; + BriefMessages[i].m_nTime = time; + BriefMessages[i].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BriefMessages[i].m_nNumber[0] = -1; + BriefMessages[i].m_nNumber[1] = -1; + BriefMessages[i].m_nNumber[2] = -1; + BriefMessages[i].m_nNumber[3] = -1; + BriefMessages[i].m_nNumber[4] = -1; + BriefMessages[i].m_nNumber[5] = -1; + BriefMessages[i].m_pString = str; + if (i == 0) + AddToPreviousBriefArray( + BriefMessages[0].m_pText, + BriefMessages[0].m_nNumber[0], + BriefMessages[0].m_nNumber[1], + BriefMessages[0].m_nNumber[2], + BriefMessages[0].m_nNumber[3], + BriefMessages[0].m_nNumber[4], + BriefMessages[0].m_nNumber[5], + BriefMessages[0].m_pString); +} + +void +CMessages::AddMessageJumpQWithString(wchar *text, uint32 time, uint16 flag, wchar *str) +{ + wchar outstr[512]; // unused + WideStringCopy(outstr, text, 256); + InsertStringInString(outstr, str); + InsertPlayerControlKeysInString(outstr); + GetWideStringLength(outstr); + + BriefMessages[0].m_pText = text; + BriefMessages[0].m_nFlag = flag; + BriefMessages[0].m_nTime = time; + BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); + BriefMessages[0].m_nNumber[0] = -1; + BriefMessages[0].m_nNumber[1] = -1; + BriefMessages[0].m_nNumber[2] = -1; + BriefMessages[0].m_nNumber[3] = -1; + BriefMessages[0].m_nNumber[4] = -1; + BriefMessages[0].m_nNumber[5] = -1; + BriefMessages[0].m_pString = str; + AddToPreviousBriefArray(text, -1, -1, -1, -1, -1, -1, str); +} + +inline bool +FastWideStringComparison(wchar *str1, wchar *str2) +{ + while (*str1 == *str2) { + ++str1; + ++str2; + if (!*str1 && !*str2) return true; + } + return false; +} + +void +CMessages::ClearThisPrint(wchar *str) +{ + bool equal; + + do { + equal = false; + uint16 i = 0; + while (i < NUMBRIEFMESSAGES) { + if (BriefMessages[i].m_pText == nil) + break; + + equal = FastWideStringComparison(str, BriefMessages[i].m_pText); + + if (equal) break; + i++; + } + + if (equal) { + if (i != 0) { + BriefMessages[i].m_pText = nil; + while (i < NUMBRIEFMESSAGES-1) { + if (BriefMessages[i + 1].m_pText == nil) + break; + + BriefMessages[i] = BriefMessages[i + 1]; + i++; + } + BriefMessages[i].m_pText = nil; + } else { + BriefMessages[0].m_pText = nil; + while (i < NUMBRIEFMESSAGES-1) { + if (BriefMessages[i + 1].m_pText == nil) + break; + BriefMessages[i] = BriefMessages[i + 1]; + i++; + } + BriefMessages[i].m_pText = nil; + BriefMessages[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); + if (BriefMessages[0].m_pText == nil) + AddToPreviousBriefArray( + BriefMessages[0].m_pText, + BriefMessages[0].m_nNumber[0], + BriefMessages[0].m_nNumber[1], + BriefMessages[0].m_nNumber[2], + BriefMessages[0].m_nNumber[3], + BriefMessages[0].m_nNumber[4], + BriefMessages[0].m_nNumber[5], + BriefMessages[0].m_pString); + } + } + } while (equal); +} + +void +CMessages::ClearThisBigPrint(wchar *str) +{ + bool equal; + + do { + uint16 i = 0; + equal = false; + uint16 style = 0; + while (style < NUMBIGMESSAGES) + { + if (i >= 4) + break; + + if (CMessages::BIGMessages[style].m_Stack[i].m_pText == nil || equal) + break; + + equal = FastWideStringComparison(str, BIGMessages[style].m_Stack[i].m_pText); + + if (!equal && ++i == 4) { + i = 0; + style++; + } + } + if (equal) { + if (i != 0) { + BIGMessages[style].m_Stack[i].m_pText = nil; + while (i < 3) { + if (BIGMessages[style].m_Stack[i + 1].m_pText == nil) + break; + BIGMessages[style].m_Stack[i] = BIGMessages[style].m_Stack[i + 1]; + i++; + } + BIGMessages[style].m_Stack[i].m_pText = nil; + } else { + BIGMessages[style].m_Stack[0].m_pText = 0; + i = 0; + while (i < 3) { + if (BIGMessages[style].m_Stack[i + 1].m_pText == nil) + break; + BIGMessages[style].m_Stack[i] = BIGMessages[style].m_Stack[i + 1]; + i++; + } + BIGMessages[style].m_Stack[i].m_pText = nil; + BIGMessages[style].m_Stack[0].m_nStartTime = CTimer::GetTimeInMilliseconds(); + } + } + } while (equal); +} + +void +CMessages::ClearAllMessagesDisplayedByGame() +{ + ClearMessages(); + for (int32 i = 0; i < NUMPREVIOUSBRIEFS; i++) { + PreviousBriefs[i].m_pText = nil; + PreviousBriefs[i].m_pString = nil; + } + CHud::GetRidOfAllHudMessages(); + CUserDisplay::Pager.ClearMessages(); +} diff --git a/src/text/Text.cpp b/src/text/Text.cpp index 117ba9cf..549f68d9 100644 --- a/src/text/Text.cpp +++ b/src/text/Text.cpp @@ -1,317 +1,319 @@ -#include "common.h" - -#include "FileMgr.h" -#include "Frontend.h" -#include "Messages.h" -#include "Text.h" - -static wchar WideErrorString[25]; - -CText TheText; - -CText::CText(void) -{ - encoding = 'e'; - memset(WideErrorString, 0, sizeof(WideErrorString)); -} - -void -CText::Load(void) -{ - uint8 *filedata; - char filename[32], type[4]; - int length; - int offset, sectlen; - - Unload(); - filedata = new uint8[0x40000]; - - CFileMgr::SetDir("TEXT"); - switch(CMenuManager::m_PrefsLanguage){ - case LANGUAGE_AMERICAN: - sprintf(filename, "AMERICAN.GXT"); - break; - case LANGUAGE_FRENCH: - sprintf(filename, "FRENCH.GXT"); - break; - case LANGUAGE_GERMAN: - sprintf(filename, "GERMAN.GXT"); - break; - case LANGUAGE_ITALIAN: - sprintf(filename, "ITALIAN.GXT"); - break; - case LANGUAGE_SPANISH: - sprintf(filename, "SPANISH.GXT"); - break; -#ifdef MORE_LANGUAGES - case LANGUAGE_POLISH: - sprintf(filename, "POLISH.GXT"); - break; - case LANGUAGE_RUSSIAN: - sprintf(filename, "RUSSIAN.GXT"); - break; - case LANGUAGE_JAPANESE: - sprintf(filename, "JAPANESE.GXT"); - break; -#endif - } - - length = CFileMgr::LoadFile(filename, filedata, 0x40000, "rb"); - CFileMgr::SetDir(""); - - offset = 0; - while(offset < length){ - type[0] = filedata[offset++]; - type[1] = filedata[offset++]; - type[2] = filedata[offset++]; - type[3] = filedata[offset++]; - sectlen = (int)filedata[offset+3]<<24 | (int)filedata[offset+2]<<16 | - (int)filedata[offset+1]<<8 | (int)filedata[offset+0]; - offset += 4; - if(sectlen != 0){ - if(strncmp(type, "TKEY", 4) == 0) - keyArray.Load(sectlen, filedata, &offset); - else if(strncmp(type, "TDAT", 4) == 0) - data.Load(sectlen, filedata, &offset); - else - offset += sectlen; - } - } - - keyArray.Update(data.chars); - - delete[] filedata; -} - -void -CText::Unload(void) -{ - CMessages::ClearAllMessagesDisplayedByGame(); - data.Unload(); - keyArray.Unload(); -} - -wchar* -CText::Get(const char *key) -{ - return keyArray.Search(key); -} - -wchar UpperCaseTable[128] = { - 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, - 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, - 150, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, - 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, - 149, 173, 173, 175, 176, 177, 178, 179, 180, 181, 182, - 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, - 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, - 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, - 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, - 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, - 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, - 249, 250, 251, 252, 253, 254, 255 -}; - -wchar FrenchUpperCaseTable[128] = { - 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, - 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, - 150, 65, 65, 65, 65, 132, 133, 69, 69, 69, 69, 73, 73, - 73, 73, 79, 79, 79, 79, 85, 85, 85, 85, 173, 173, 175, - 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, - 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, - 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, - 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, - 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, - 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, - 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, - 253, 254, 255 -}; - -wchar -CText::GetUpperCase(wchar c) -{ - switch (encoding) - { - case 'e': - if (c >= 'a' && c <= 'z') - return c - 32; - break; - case 'f': - if (c >= 'a' && c <= 'z') - return c - 32; - - if (c >= 128 && c <= 255) - return FrenchUpperCaseTable[c-128]; - break; - case 'g': - case 'i': - case 's': - if (c >= 'a' && c <= 'z') - return c - 32; - - if (c >= 128 && c <= 255) - return UpperCaseTable[c-128]; - break; - default: - break; - } - return c; -} - -void -CText::UpperCase(wchar *s) -{ - while(*s){ - *s = GetUpperCase(*s); - s++; - } -} - - -void -CKeyArray::Load(uint32 length, uint8 *data, int *offset) -{ - uint32 i; - uint8 *rawbytes; - - numEntries = length / sizeof(CKeyEntry); - entries = new CKeyEntry[numEntries]; - rawbytes = (uint8*)entries; - - for(i = 0; i < length; i++) - rawbytes[i] = data[(*offset)++]; -} - -void -CKeyArray::Unload(void) -{ - delete[] entries; - entries = nil; - numEntries = 0; -} - -void -CKeyArray::Update(wchar *chars) -{ - int i; - for(i = 0; i < numEntries; i++) - entries[i].value = (wchar*)((uint8*)chars + (uintptr)entries[i].value); -} - -CKeyEntry* -CKeyArray::BinarySearch(const char *key, CKeyEntry *entries, int16 low, int16 high) -{ - int mid; - int diff; - - if(low > high) - return nil; - - mid = (low + high)/2; - diff = strcmp(key, entries[mid].key); - if(diff == 0) - return &entries[mid]; - if(diff < 0) - return BinarySearch(key, entries, low, mid-1); - if(diff > 0) - return BinarySearch(key, entries, mid+1, high); - return nil; -} - -wchar* -CKeyArray::Search(const char *key) -{ - CKeyEntry *found; - char errstr[25]; - int i; - - found = BinarySearch(key, entries, 0, numEntries-1); - if(found) - return found->value; - sprintf(errstr, "%s missing", key); - for(i = 0; i < 25; i++) - WideErrorString[i] = errstr[i]; - return WideErrorString; -} - - -void -CData::Load(uint32 length, uint8 *data, int *offset) -{ - uint32 i; - uint8 *rawbytes; - - numChars = length / sizeof(wchar); - chars = new wchar[numChars]; - rawbytes = (uint8*)chars; - - for(i = 0; i < length; i++) - rawbytes[i] = data[(*offset)++]; -} - -void -CData::Unload(void) -{ - delete[] chars; - chars = nil; - numChars = 0; -} - -void -AsciiToUnicode(const char *src, wchar *dst) -{ - while((*dst++ = *src++) != '\0'); -} - -#include "Game.h" - -char* -UnicodeToAscii(wchar *src) -{ - static char aStr[256]; - int len; - for(len = 0; *src != '\0' && len < 256-1; len++, src++) - if(*src < 128 || (CGame::russianGame && *src < 256)) - aStr[len] = *src; - else - aStr[len] = '#'; - aStr[len] = '\0'; - return aStr; -} - -char* -UnicodeToAsciiForSaveLoad(wchar *src) -{ - static char aStr[256]; - int len; - for(len = 0; *src != '\0' && len < 256-1; len++, src++) - if(*src < 256) - aStr[len] = *src; - else - aStr[len] = '#'; - aStr[len] = '\0'; - return aStr; -} - -void -UnicodeStrcpy(wchar *dst, const wchar *src) -{ - while((*dst++ = *src++) != '\0'); -} - -int -UnicodeStrlen(const wchar *str) -{ - int len; - for(len = 0; *str != '\0'; len++, str++); - return len; -} - -void -TextCopy(wchar *dst, const wchar *src) -{ - while((*dst++ = *src++) != '\0'); -} - - - InjectHook(0x52C2F0, &UnicodeToAscii, PATCH_JUMP); \ No newline at end of file +#include "common.h" + +#include "FileMgr.h" +#ifdef MORE_LANGUAGES +#include "Game.h" +#endif +#include "Frontend.h" +#include "Messages.h" +#include "Text.h" + +static wchar WideErrorString[25]; + +CText TheText; + +CText::CText(void) +{ + encoding = 'e'; + memset(WideErrorString, 0, sizeof(WideErrorString)); +} + +void +CText::Load(void) +{ + uint8 *filedata; + char filename[32], type[4]; + int length; + int offset, sectlen; + + Unload(); + filedata = new uint8[0x40000]; + + CFileMgr::SetDir("TEXT"); + switch(CMenuManager::m_PrefsLanguage){ + case LANGUAGE_AMERICAN: + sprintf(filename, "AMERICAN.GXT"); + break; + case LANGUAGE_FRENCH: + sprintf(filename, "FRENCH.GXT"); + break; + case LANGUAGE_GERMAN: + sprintf(filename, "GERMAN.GXT"); + break; + case LANGUAGE_ITALIAN: + sprintf(filename, "ITALIAN.GXT"); + break; + case LANGUAGE_SPANISH: + sprintf(filename, "SPANISH.GXT"); + break; +#ifdef MORE_LANGUAGES + case LANGUAGE_POLISH: + sprintf(filename, "POLISH.GXT"); + break; + case LANGUAGE_RUSSIAN: + sprintf(filename, "RUSSIAN.GXT"); + break; + case LANGUAGE_JAPANESE: + sprintf(filename, "JAPANESE.GXT"); + break; +#endif + } + + length = CFileMgr::LoadFile(filename, filedata, 0x40000, "rb"); + CFileMgr::SetDir(""); + + offset = 0; + while(offset < length){ + type[0] = filedata[offset++]; + type[1] = filedata[offset++]; + type[2] = filedata[offset++]; + type[3] = filedata[offset++]; + sectlen = (int)filedata[offset+3]<<24 | (int)filedata[offset+2]<<16 | + (int)filedata[offset+1]<<8 | (int)filedata[offset+0]; + offset += 4; + if(sectlen != 0){ + if(strncmp(type, "TKEY", 4) == 0) + keyArray.Load(sectlen, filedata, &offset); + else if(strncmp(type, "TDAT", 4) == 0) + data.Load(sectlen, filedata, &offset); + else + offset += sectlen; + } + } + + keyArray.Update(data.chars); + + delete[] filedata; +} + +void +CText::Unload(void) +{ + CMessages::ClearAllMessagesDisplayedByGame(); + data.Unload(); + keyArray.Unload(); +} + +wchar* +CText::Get(const char *key) +{ + return keyArray.Search(key); +} + +wchar UpperCaseTable[128] = { + 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, + 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, + 150, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, + 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, + 149, 173, 173, 175, 176, 177, 178, 179, 180, 181, 182, + 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, + 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, + 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, + 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, + 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, + 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, + 249, 250, 251, 252, 253, 254, 255 +}; + +wchar FrenchUpperCaseTable[128] = { + 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, + 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, + 150, 65, 65, 65, 65, 132, 133, 69, 69, 69, 69, 73, 73, + 73, 73, 79, 79, 79, 79, 85, 85, 85, 85, 173, 173, 175, + 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, + 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, + 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, + 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, + 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, + 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, + 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, + 253, 254, 255 +}; + +wchar +CText::GetUpperCase(wchar c) +{ + switch (encoding) + { + case 'e': + if (c >= 'a' && c <= 'z') + return c - 32; + break; + case 'f': + if (c >= 'a' && c <= 'z') + return c - 32; + + if (c >= 128 && c <= 255) + return FrenchUpperCaseTable[c-128]; + break; + case 'g': + case 'i': + case 's': + if (c >= 'a' && c <= 'z') + return c - 32; + + if (c >= 128 && c <= 255) + return UpperCaseTable[c-128]; + break; + default: + break; + } + return c; +} + +void +CText::UpperCase(wchar *s) +{ + while(*s){ + *s = GetUpperCase(*s); + s++; + } +} + + +void +CKeyArray::Load(uint32 length, uint8 *data, int *offset) +{ + uint32 i; + uint8 *rawbytes; + + numEntries = length / sizeof(CKeyEntry); + entries = new CKeyEntry[numEntries]; + rawbytes = (uint8*)entries; + + for(i = 0; i < length; i++) + rawbytes[i] = data[(*offset)++]; +} + +void +CKeyArray::Unload(void) +{ + delete[] entries; + entries = nil; + numEntries = 0; +} + +void +CKeyArray::Update(wchar *chars) +{ + int i; + for(i = 0; i < numEntries; i++) + entries[i].value = (wchar*)((uint8*)chars + (uintptr)entries[i].value); +} + +CKeyEntry* +CKeyArray::BinarySearch(const char *key, CKeyEntry *entries, int16 low, int16 high) +{ + int mid; + int diff; + + if(low > high) + return nil; + + mid = (low + high)/2; + diff = strcmp(key, entries[mid].key); + if(diff == 0) + return &entries[mid]; + if(diff < 0) + return BinarySearch(key, entries, low, mid-1); + if(diff > 0) + return BinarySearch(key, entries, mid+1, high); + return nil; +} + +wchar* +CKeyArray::Search(const char *key) +{ + CKeyEntry *found; + char errstr[25]; + int i; + + found = BinarySearch(key, entries, 0, numEntries-1); + if(found) + return found->value; + sprintf(errstr, "%s missing", key); + for(i = 0; i < 25; i++) + WideErrorString[i] = errstr[i]; + return WideErrorString; +} + + +void +CData::Load(uint32 length, uint8 *data, int *offset) +{ + uint32 i; + uint8 *rawbytes; + + numChars = length / sizeof(wchar); + chars = new wchar[numChars]; + rawbytes = (uint8*)chars; + + for(i = 0; i < length; i++) + rawbytes[i] = data[(*offset)++]; +} + +void +CData::Unload(void) +{ + delete[] chars; + chars = nil; + numChars = 0; +} + +void +AsciiToUnicode(const char *src, wchar *dst) +{ + while((*dst++ = (unsigned char)*src++) != '\0'); +} + +char* +UnicodeToAscii(wchar *src) +{ + static char aStr[256]; + int len; + for(len = 0; *src != '\0' && len < 256-1; len++, src++) +#ifdef MORE_LANGUAGES + if(*src < 128 || ((CGame::russianGame || CGame::japaneseGame) && *src < 256)) +#else + if(*src < 128) +#endif + aStr[len] = *src; + else + aStr[len] = '#'; + aStr[len] = '\0'; + return aStr; +} + +char* +UnicodeToAsciiForSaveLoad(wchar *src) +{ + static char aStr[256]; + int len; + for(len = 0; *src != '\0' && len < 256-1; len++, src++) + if(*src < 256) + aStr[len] = *src; + else + aStr[len] = '#'; + aStr[len] = '\0'; + return aStr; +} + +void +UnicodeStrcpy(wchar *dst, const wchar *src) +{ + while((*dst++ = *src++) != '\0'); +} + +int +UnicodeStrlen(const wchar *str) +{ + int len; + for(len = 0; *str != '\0'; len++, str++); + return len; +} + +void +TextCopy(wchar *dst, const wchar *src) +{ + while((*dst++ = *src++) != '\0'); +} \ No newline at end of file