From c55cb02a6a0961e491536f293ffea9933b65432c Mon Sep 17 00:00:00 2001 From: Flugente Date: Tue, 5 Nov 2013 19:06:29 +0000 Subject: [PATCH] Backgrounds.xml can now be localized. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@6560 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Init.cpp | 21 ++++++++++++++++++++- Tactical/XML.h | 2 +- Tactical/XML_Background.cpp | 23 ++++++++++++++++++----- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/Init.cpp b/Init.cpp index b2bd507f1..b083241f3 100644 --- a/Init.cpp +++ b/Init.cpp @@ -1002,7 +1002,26 @@ BOOLEAN LoadExternalGameplayData(STR directoryName) strcpy(fileName, directoryName); strcat(fileName, BACKGROUNDSFILENAME); DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("LoadExternalGameplayData, fileName = %s", fileName)); - SGP_THROW_IFFALSE(ReadInBackgrounds(fileName), BACKGROUNDSFILENAME); + SGP_THROW_IFFALSE(ReadInBackgrounds(fileName,FALSE), BACKGROUNDSFILENAME); + + //Madd: Simple localization + // The idea here is that we can have a separate xml file that's named differently + // but only contains the relevant tags that need to be localized + // then when the file is read in using the same xml reader code, it will only overwrite + // the tags that are contained in the localized file. This only works for items.xml + // since I tweaked the xml_items.cpp to make it work :p + // So for instance, the german file would be called German.Items.xml and would only contain + // the uiIndex (for reference), szItemName, szLongItemName, szItemDesc, szBRName, and szBRDesc tags + +#ifndef ENGLISH + AddLanguagePrefix(fileName); + if ( FileExists(fileName) ) + { + DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("LoadExternalGameplayData, fileName = %s", fileName)); + SGP_THROW_IFFALSE(ReadInBackgrounds(fileName,TRUE), BACKGROUNDSFILENAME); + } +#endif + ////////////////// // IMP Portraits List by Jazz strcpy(fileName, directoryName); diff --git a/Tactical/XML.h b/Tactical/XML.h index bfeb57f24..cd432e812 100644 --- a/Tactical/XML.h +++ b/Tactical/XML.h @@ -465,7 +465,7 @@ extern BOOLEAN ReadInIMPPortraits(STR fileName, BOOLEAN localizedVersion); extern void LoadIMPPortraitsTEMP(); // Flugente: backgrounds -extern BOOLEAN ReadInBackgrounds(STR fileName ); +extern BOOLEAN ReadInBackgrounds(STR fileName, BOOLEAN localizedVersion ); extern BOOLEAN WriteBackgrounds( STR fileName); //Enabled\Disabled profile sound by Jazz diff --git a/Tactical/XML_Background.cpp b/Tactical/XML_Background.cpp index 65c44ac9b..6cc3e0ed7 100644 --- a/Tactical/XML_Background.cpp +++ b/Tactical/XML_Background.cpp @@ -24,6 +24,8 @@ struct } typedef enemyRankParseData; +BOOLEAN localizedTextOnly_BG; + UINT16 num_found_background = 0; // the correct number is set on reading the xml #define XML_BACKGROUND_AP_MAX 8 @@ -43,7 +45,8 @@ backgroundStartElementHandle(void *userData, const XML_Char *name, const XML_Cha { pData->curElement = ELEMENT_LIST; - memset(pData->curArray,0,sizeof(BACKGROUND_VALUES)*pData->maxArraySize); + if ( !localizedTextOnly_BG ) + memset(pData->curArray,0,sizeof(BACKGROUND_VALUES)*pData->maxArraySize); pData->maxReadDepth++; //we are not skipping this element } @@ -51,7 +54,8 @@ backgroundStartElementHandle(void *userData, const XML_Char *name, const XML_Cha { pData->curElement = ELEMENT; - memset(&pData->curBackground,0,sizeof(BACKGROUND_VALUES)); + if ( !localizedTextOnly_BG ) + memset(&pData->curBackground,0,sizeof(BACKGROUND_VALUES)); pData->maxReadDepth++; //we are not skipping this element } @@ -168,10 +172,17 @@ backgroundEndElementHandle(void *userData, const XML_Char *name) if(pData->curBackground.uiIndex < pData->maxArraySize) { - pData->curArray[pData->curBackground.uiIndex] = pData->curBackground; + if ( localizedTextOnly_BG ) + { + wcscpy(pData->curArray[pData->curBackground.uiIndex].szName,pData->curBackground.szName); + wcscpy(pData->curArray[pData->curBackground.uiIndex].szShortName,pData->curBackground.szShortName); + wcscpy(pData->curArray[pData->curBackground.uiIndex].szDescription,pData->curBackground.szDescription); + } + else + pData->curArray[pData->curBackground.uiIndex] = pData->curBackground; } - num_found_background = pData->curBackground.uiIndex; + num_found_background = pData->curBackground.uiIndex; } else if(strcmp(name, "uiIndex") == 0) { @@ -540,7 +551,7 @@ backgroundEndElementHandle(void *userData, const XML_Char *name) pData->currentDepth--; } -BOOLEAN ReadInBackgrounds(STR fileName) +BOOLEAN ReadInBackgrounds(STR fileName, BOOLEAN localizedVersion) { HWFILE hFile; UINT32 uiBytesRead; @@ -551,6 +562,8 @@ BOOLEAN ReadInBackgrounds(STR fileName) enemyRankParseData pData; DebugMsg(TOPIC_JA2, DBG_LEVEL_3, "Loading Backgrounds.xml" ); + + localizedTextOnly_BG = localizedVersion; // Open file hFile = FileOpen( fileName, FILE_ACCESS_READ, FALSE );