Skip to content

Commit

Permalink
FITD: Add a Textes class for localization
Browse files Browse the repository at this point in the history
  • Loading branch information
klusark committed Feb 8, 2012
1 parent c38dab1 commit d9546ef
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 123 deletions.
4 changes: 2 additions & 2 deletions src/fitd.cpp
Expand Up @@ -31,6 +31,7 @@
#include "resource.h"
#include "osystem.h"
#include "common.h"
#include "textes.h"
#include "main_loop.h"

namespace Fitd {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -401,7 +401,7 @@ void FitdEngine::sysInit(void) {
}
//////////////////////////////////////////////

allocTextes();
g_textes = new Textes();

// if(musicConfigured)
{
Expand Down
9 changes: 5 additions & 4 deletions src/font.cpp
Expand Up @@ -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.
Expand All @@ -22,6 +22,7 @@

#include "fitd.h"
#include "common.h"
#include "textes.h"

namespace Fitd {

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
115 changes: 5 additions & 110 deletions src/main.cpp
Expand Up @@ -36,6 +36,7 @@
#include "common.h"
#include "version.h"
#include "main_loop.h"
#include "textes.h"
#include "common/forbidden.h"

namespace Fitd {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -926,7 +819,9 @@ void initVars() {

statusScreenAllowed = 1;

initVarsSub1();
for(int i = 0; i < 5; i++) {
messageTable[i].string = NULL;
}
}

void loadCamera(int cameraIdx) {
Expand Down Expand Up @@ -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++) {
Expand Down
2 changes: 1 addition & 1 deletion src/main.h
Expand Up @@ -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);
Expand Down
135 changes: 135 additions & 0 deletions 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

0 comments on commit d9546ef

Please sign in to comment.