From d9546ef5de31428810ba28a3f3415002cca6d51f Mon Sep 17 00:00:00 2001 From: Joel Teichroeb Date: Tue, 7 Feb 2012 17:00:32 -0800 Subject: [PATCH] FITD: Add a Textes class for localization --- src/fitd.cpp | 4 +- src/font.cpp | 9 ++-- src/main.cpp | 115 ++--------------------------------------- src/main.h | 2 +- src/textes.cpp | 135 +++++++++++++++++++++++++++++++++++++++++++++++++ src/textes.h | 42 +++++++++++++++ src/vars.cpp | 3 -- src/vars.h | 3 -- 8 files changed, 190 insertions(+), 123 deletions(-) create mode 100644 src/textes.cpp create mode 100644 src/textes.h diff --git a/src/fitd.cpp b/src/fitd.cpp index 75f27c3..1fab8ac 100644 --- a/src/fitd.cpp +++ b/src/fitd.cpp @@ -31,6 +31,7 @@ #include "resource.h" #include "osystem.h" #include "common.h" +#include "textes.h" #include "main_loop.h" namespace Fitd { @@ -78,7 +79,6 @@ enumCVars AITD2KnownCVars[] = { // TODO: Move this around to a usefull place: void makeIntroScreens(); -void allocTextes(void); void sysInitSub1(char *var0, char *var1); FitdEngine::FitdEngine() { @@ -401,7 +401,7 @@ void FitdEngine::sysInit(void) { } ////////////////////////////////////////////// - allocTextes(); + g_textes = new Textes(); // if(musicConfigured) { diff --git a/src/font.cpp b/src/font.cpp index 326372f..7d5716f 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -22,6 +22,7 @@ #include "fitd.h" #include "common.h" +#include "textes.h" namespace Fitd { @@ -192,7 +193,7 @@ void drawSlectedText(int x, int y, int index, int color1, int color2) { textEntryStruct *entryPtr; char *textPtr; - entryPtr = getTextFromIdx(index); + entryPtr = g_textes->getTextFromIdx(index); if(!entryPtr) return; @@ -213,7 +214,7 @@ void drawText(int x, int y, int index, int color) { textEntryStruct *entryPtr; char *textPtr; - entryPtr = getTextFromIdx(index); + entryPtr = g_textes->getTextFromIdx(index); if(!entryPtr) return; diff --git a/src/main.cpp b/src/main.cpp index 2040c3e..067aaa7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,6 +36,7 @@ #include "common.h" #include "version.h" #include "main_loop.h" +#include "textes.h" #include "common/forbidden.h" namespace Fitd { @@ -148,96 +149,6 @@ void sysInitSub1(char *var0, char *var1) { screenSm5 = var1; } -void allocTextes(void) { - int currentIndex; - char *currentPosInTextes; - int textCounter; - int stringIndex; - char *stringPtr; - int textLength; - - tabTextes = (textEntryStruct *)malloc(NUM_MAX_TEXT_ENTRY * sizeof(textEntryStruct)); // 2000 = 250 * 8 - - ASSERT_PTR(tabTextes); - - if(!tabTextes) { - theEnd(1, "TabTextes"); - } - - // setup languageNameString - if(g_fitd->getGameType() == GType_AITD3) { - strcpy(languageNameString, "TEXTES"); - } else { - int i = 0; - - while(languageNameTable[i]) { - char tempString[20]; - - strcpy(tempString, languageNameTable[i]); - strcat(tempString, ".PAK"); - - if(g_resourceLoader->getFileExists(tempString)) { - strcpy(languageNameString, languageNameTable[i]); - break; - } - - i++; - } - } - - if(!languageNameString[0]) { - error("Unable to detect language file..\n"); - } - - systemTextes = g_resourceLoader->loadPakSafe(languageNameString, 0); // todo: use real language name - textLength = getPakSize(languageNameString, 0); - - for(currentIndex = 0; currentIndex < NUM_MAX_TEXT_ENTRY; currentIndex++) { - tabTextes[currentIndex].index = -1; - tabTextes[currentIndex].textPtr = NULL; - tabTextes[currentIndex].width = 0; - } - - currentPosInTextes = systemTextes; - - textCounter = 0; - - while(currentPosInTextes < systemTextes + textLength) { - currentIndex = *(currentPosInTextes++); - - if(currentIndex == 26) - break; - - if(currentIndex == '@') { // start of string marker - stringIndex = 0; - - while((currentIndex = *(currentPosInTextes++)) >= '0' && currentIndex <= '9') { // parse string number - stringIndex = stringIndex * 10 + currentIndex - 48; - } - - if(currentIndex == ':') { // start of string - stringPtr = currentPosInTextes; - - do { - currentPosInTextes ++; - } while((unsigned char)*(currentPosInTextes - 1) >= ' '); // detect the end of the string - - *(currentPosInTextes - 1) = 0; // add the end of string - - tabTextes[textCounter].index = stringIndex; - tabTextes[textCounter].textPtr = stringPtr; - tabTextes[textCounter].width = computeStringWidth(stringPtr); - - textCounter++; - } - - if(currentIndex == 26) { - return; - } - } - } -} - void freeAll(void) { /* HQR_Free(hqrUnk); @@ -267,18 +178,6 @@ void freeAll(void) { //TODO: implement all the code that restore the interrupts & all } -textEntryStruct *getTextFromIdx(int index) { - int currentIndex; - - for(currentIndex = 0; currentIndex < NUM_MAX_TEXT_ENTRY; currentIndex++) { - if(tabTextes[currentIndex].index == index) { - return(&tabTextes[currentIndex]); - } - } - - return(NULL); -} - void fillBox(int x1, int y1, int x2, int y2, char color) { // fast recode. No RE int width = x2 - x1 + 1; int height = y2 - y1 + 1; @@ -884,12 +783,6 @@ void initEngine() { } } -void initVarsSub1(void) { - for(int i = 0; i < 5; i++) { - messageTable[i].string = NULL; - } -} - void initVars() { giveUp = 0; if(g_fitd->getGameType() == GType_AITD1) { @@ -926,7 +819,9 @@ void initVars() { statusScreenAllowed = 1; - initVarsSub1(); + for(int i = 0; i < 5; i++) { + messageTable[i].string = NULL; + } } void loadCamera(int cameraIdx) { @@ -3419,7 +3314,7 @@ int drawTextOverlay(void) { void makeMessage(int messageIdx) { textEntryStruct *messagePtr; - messagePtr = getTextFromIdx(messageIdx); + messagePtr = g_textes->getTextFromIdx(messageIdx); if(messagePtr) { for(int i = 0; i < 5; i++) { diff --git a/src/main.h b/src/main.h index 98f0f05..4755dc8 100644 --- a/src/main.h +++ b/src/main.h @@ -48,7 +48,7 @@ void initVars(); void configureHqrHero(hqrEntryStruct *hqrPtr, const char *name); void flushScreen(void); int parseAllSaves(int arg); -textEntryStruct *getTextFromIdx(int index); + void cleanupAndExit(void); void drawProjectedBox(int x1, int x2, int y1, int y2, int z1, int z2, int color, int transparency); void printTextSub6(hqrEntryStruct *hqrPtr, int index); diff --git a/src/textes.cpp b/src/textes.cpp new file mode 100644 index 0000000..ac49eb5 --- /dev/null +++ b/src/textes.cpp @@ -0,0 +1,135 @@ +/* ResidualVM - A 3D game interpreter + * + * ResidualVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the AUTHORS + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "common/textconsole.h" +#include "common.h" +#include "fitd.h" +#include "resource.h" +#include "textes.h" + +namespace Fitd { + +Textes *g_textes = NULL; + +Textes::Textes() { + int currentIndex; + char *currentPosInTextes; + int textCounter; + int stringIndex; + char *stringPtr; + int textLength; + + _tabTextes = new textEntryStruct[NUM_MAX_TEXT_ENTRY]; // 2000 = 250 * 8 + + ASSERT_PTR(_tabTextes); + + if(!_tabTextes) { + theEnd(1, "TabTextes"); + } + + // setup languageNameString + if(g_fitd->getGameType() == GType_AITD3) { + strcpy(languageNameString, "TEXTES"); + } else { + int i = 0; + + while(languageNameTable[i]) { + char tempString[20]; + + strcpy(tempString, languageNameTable[i]); + strcat(tempString, ".PAK"); + + if(g_resourceLoader->getFileExists(tempString)) { + strcpy(languageNameString, languageNameTable[i]); + break; + } + + i++; + } + } + + if(!languageNameString[0]) { + error("Unable to detect language file..\n"); + } + + _systemTextes = g_resourceLoader->loadPakSafe(languageNameString, 0); // todo: use real language name + textLength = getPakSize(languageNameString, 0); + + for(currentIndex = 0; currentIndex < NUM_MAX_TEXT_ENTRY; currentIndex++) { + _tabTextes[currentIndex].index = -1; + _tabTextes[currentIndex].textPtr = NULL; + _tabTextes[currentIndex].width = 0; + } + + currentPosInTextes = _systemTextes; + + textCounter = 0; + + while(currentPosInTextes < _systemTextes + textLength) { + currentIndex = *(currentPosInTextes++); + + if(currentIndex == 26) + break; + + if(currentIndex == '@') { // start of string marker + stringIndex = 0; + + while((currentIndex = *(currentPosInTextes++)) >= '0' && currentIndex <= '9') { // parse string number + stringIndex = stringIndex * 10 + currentIndex - 48; + } + + if(currentIndex == ':') { // start of string + stringPtr = currentPosInTextes; + + do { + currentPosInTextes ++; + } while((unsigned char)*(currentPosInTextes - 1) >= ' '); // detect the end of the string + + *(currentPosInTextes - 1) = 0; // add the end of string + + _tabTextes[textCounter].index = stringIndex; + _tabTextes[textCounter].textPtr = stringPtr; + _tabTextes[textCounter].width = computeStringWidth(stringPtr); + + textCounter++; + } + + if(currentIndex == 26) { + return; + } + } + } +} + +textEntryStruct *Textes::getTextFromIdx(int index) { + int currentIndex; + + for(currentIndex = 0; currentIndex < NUM_MAX_TEXT_ENTRY; currentIndex++) { + if(_tabTextes[currentIndex].index == index) { + return(&_tabTextes[currentIndex]); + } + } + + return(NULL); +} + +} // end of namespace Fitd diff --git a/src/textes.h b/src/textes.h new file mode 100644 index 0000000..c1bd936 --- /dev/null +++ b/src/textes.h @@ -0,0 +1,42 @@ +/* ResidualVM - A 3D game interpreter + * + * ResidualVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the AUTHORS + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef _TEXTES_ +#define _TEXTES_ +namespace Fitd { + +struct textEntryStruct; + +class Textes { +public: + Textes(); + textEntryStruct *getTextFromIdx(int index); +private: + textEntryStruct *_tabTextes; + char *_systemTextes; +}; + +extern Textes *g_textes; + +} // end of namespace Fitd + +#endif diff --git a/src/vars.cpp b/src/vars.cpp index bdc1c08..b875387 100644 --- a/src/vars.cpp +++ b/src/vars.cpp @@ -63,9 +63,6 @@ int32 currentMenuTop; int32 currentMenuRight; int32 currentMenuBottom; -textEntryStruct *tabTextes; -char *systemTextes; - char inputKey = 0; char input1 = 0; char input2 = 0; diff --git a/src/vars.h b/src/vars.h index 93b0445..d86eacf 100644 --- a/src/vars.h +++ b/src/vars.h @@ -212,9 +212,6 @@ extern int32 currentMenuTop; extern int32 currentMenuRight; extern int32 currentMenuBottom; -extern textEntryStruct *tabTextes; -extern char *systemTextes; - extern char inputKey; extern char input1; extern char input2;