From 9cb1cd7bc8274925b43c6266a02b272e907811f7 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 5 Apr 2011 20:19:25 +0000 Subject: [PATCH] - bugfixes related to multi-language text messaging --- source/glest_game/facilities/components.cpp | 4 ++- source/glest_game/game/chat_manager.cpp | 6 +++- source/glest_game/main/main.cpp | 31 ++++++++++++++----- .../menu/menu_state_connected_game.cpp | 2 ++ .../menu/menu_state_custom_game.cpp | 3 ++ source/glest_game/network/connection_slot.cpp | 13 ++++++++ .../glest_game/network/server_interface.cpp | 2 +- 7 files changed, 50 insertions(+), 11 deletions(-) diff --git a/source/glest_game/facilities/components.cpp b/source/glest_game/facilities/components.cpp index 99374a71..a956f78d 100644 --- a/source/glest_game/facilities/components.cpp +++ b/source/glest_game/facilities/components.cpp @@ -19,6 +19,7 @@ #include "platform_util.h" #include "util.h" #include "conversion.h" +#include "lang.h" #include "leak_dumper.h" using namespace std; @@ -113,7 +114,8 @@ void GraphicComponent::applyCustomProperties(std::string containerName) { if(iterFind2 != iterFind1->second.end()) { Config &config = Config::getInstance(); - string languageToken = config.getString("Lang"); + //string languageToken = config.getString("Lang"); + string languageToken = Lang::getInstance().getLanguage(); //if(dynamic_cast(iterFind2->second) != NULL) { GraphicComponent *ctl = dynamic_cast(iterFind2->second); diff --git a/source/glest_game/game/chat_manager.cpp b/source/glest_game/game/chat_manager.cpp index b9bf2f8d..4900028f 100644 --- a/source/glest_game/game/chat_manager.cpp +++ b/source/glest_game/game/chat_manager.cpp @@ -202,6 +202,7 @@ void ChatManager::updateNetwork() { //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] gameNetworkInterface->getChatText() [%s]\n",__FILE__,__FUNCTION__,__LINE__,gameNetworkInterface->getChatText().c_str()); if(gameNetworkInterface != NULL && gameNetworkInterface->getChatTextList().empty() == false) { + Lang &lang= Lang::getInstance(); for(int idx = 0; idx < gameNetworkInterface->getChatTextList().size(); idx++) { const ChatMsgInfo &msg = gameNetworkInterface->getChatTextList()[idx]; int teamIndex= msg.chatTeamIndex; @@ -210,7 +211,10 @@ void ChatManager::updateNetwork() { if(teamIndex == -1 || teamIndex == thisTeamIndex) { //console->addLine(msg.chatSender + ": " + msg.chatText, true, msg.chatPlayerIndex); - console->addLine(msg.chatText, true, msg.chatPlayerIndex); + + if(msg.targetLanguage == "" || lang.isLanguageLocal(msg.targetLanguage) == true) { + console->addLine(msg.chatText, true, msg.chatPlayerIndex); + } SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Added text to console\n",__FILE__,__FUNCTION__); } diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 66dfc055..64e233a2 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -109,6 +109,7 @@ const char *GAME_ARGS[] = { "--log-path", "--show-ini-settings", "--convert-models", + "--use-language", "--disable-backtrace", "--disable-vbo", "--disable-sound", @@ -134,6 +135,7 @@ enum GAME_ARG_TYPE { GAME_ARG_LOG_PATH, GAME_ARG_SHOW_INI_SETTINGS, GAME_ARG_CONVERT_MODELS, + GAME_ARG_USE_LANGUAGE, GAME_ARG_DISABLE_BACKTRACE, GAME_ARG_DISABLE_VBO, GAME_ARG_DISABLE_SOUND, @@ -964,6 +966,10 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) { printf("\n \t\tWhere keepsmallest is an optional flag indicating to keep original texture if its filesize is smaller than the converted format."); printf("\n \t\texample: %s %s=techs/megapack/factions/tech/units/castle/models/castle.g3d=png=keepsmallest",argv0,GAME_ARGS[GAME_ARG_CONVERT_MODELS]); + printf("\n%s=x\t\tforce the language to be the language specified by x.",GAME_ARGS[GAME_ARG_USE_LANGUAGE]); + printf("\n \t\tWhere x is a supported language (such as english)."); + printf("\n \t\texample: %s %s=english",argv0,GAME_ARGS[GAME_ARG_USE_LANGUAGE]); + printf("\n%s\t\tdisables stack backtrace on errors.",GAME_ARGS[GAME_ARG_DISABLE_BACKTRACE]); printf("\n%s\t\t\tdisables trying to use Vertex Buffer Objects.",GAME_ARGS[GAME_ARG_DISABLE_VBO]); printf("\n%s\t\t\tdisables the sound system.",GAME_ARGS[GAME_ARG_DISABLE_SOUND]); @@ -2015,7 +2021,23 @@ int glestMain(int argc, char** argv) { // Load the language strings Lang &lang= Lang::getInstance(); - lang.loadStrings(config.getString("Lang")); + string language = config.getString("Lang"); + if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_USE_LANGUAGE]) == true) { + int foundParamIndIndex = -1; + hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_USE_LANGUAGE]) + string("="),&foundParamIndIndex); + if(foundParamIndIndex < 0) { + hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_USE_LANGUAGE]),&foundParamIndIndex); + } + string paramValue = argv[foundParamIndIndex]; + vector paramPartTokens; + Tokenize(paramValue,paramPartTokens,"="); + if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) { + language = paramPartTokens[1]; + printf("Forcing language [%s]\n",language.c_str()); + } + } + + lang.loadStrings(language); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -2214,13 +2236,6 @@ int glestMain(int argc, char** argv) { } } -// if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_CONVERT_TEXTURES]) == true) { -// //!!! -// printf("\nComing soon (not yet implemented)\n\n"); -// delete mainWindow; -// return -1; -// } - if( hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]) == true || hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]) == true) { diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 41ab70f6..1361ba0e 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -585,6 +585,8 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){ for(unsigned int i = 0; i < languageList.size(); ++i) { string sQuitText = lang.get("QuitGame",languageList[i]); clientInterface->sendTextMessage(sQuitText,-1,false,languageList[i]); + + //printf("~~~ langList[%s] localLang[%s] msg[%s]\n",languageList[i].c_str(),lang.getLanguage().c_str(), sQuitText.c_str()); } sleep(1); } diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 6417936b..31b79bbc 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -2145,6 +2145,9 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) { Lang &lang= Lang::getInstance(); gameSettings->setNetworkPlayerLanguages(slotIndex, lang.getLanguage()); } + else if(serverInterface->getSlot(i) != NULL) { + gameSettings->setNetworkPlayerLanguages(slotIndex, serverInterface->getSlot(i)->getNetworkPlayerLanguage()); + } gameSettings->setResourceMultiplierIndex(slotIndex, listBoxRMultiplier[i].getSelectedItemIndex()); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] i = %d, factionFiles[listBoxFactions[i].getSelectedItemIndex()] [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,factionFiles[listBoxFactions[i].getSelectedItemIndex()].c_str()); diff --git a/source/glest_game/network/connection_slot.cpp b/source/glest_game/network/connection_slot.cpp index a4a0ac69..8cd31c67 100644 --- a/source/glest_game/network/connection_slot.cpp +++ b/source/glest_game/network/connection_slot.cpp @@ -486,6 +486,7 @@ void ConnectionSlot::update(bool checkForNewClients,int lockedSlotIndex) { this->connectedRemoteIPAddress = networkMessageIntro.getExternalIp(); this->playerLanguage = networkMessageIntro.getPlayerLanguage(); + //printf("\n\n\n ##### GOT this->playerLanguage [%s]\n\n\n",this->playerLanguage.c_str()); if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s] got name [%s] versionString [%s], msgSessionId = %d\n",__FILE__,__FUNCTION__,name.c_str(),versionString.c_str(),msgSessionId); if(msgSessionId != sessionKey) { @@ -850,6 +851,18 @@ bool ConnectionSlot::updateCompleted(ConnectionSlotEvent *event) { void ConnectionSlot::sendMessage(const NetworkMessage* networkMessage) { static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__); MutexSafeWrapper safeMutex(&socketSynchAccessor,mutexOwnerId); + + // Skip text messages not intended for the players preferred language + const NetworkMessageText *textMsg = dynamic_cast(networkMessage); + if(textMsg != NULL) { + //printf("\n\n\n~~~ SERVER HAS NetworkMessageText target [%s] player [%s] msg[%s]\n\n\n",textMsg->getTargetLanguage().c_str(),this->getNetworkPlayerLanguage().c_str(), textMsg->getText().c_str()); + + if(textMsg->getTargetLanguage() != "" && + textMsg->getTargetLanguage() != this->getNetworkPlayerLanguage()) { + return; + } + } + NetworkInterface::sendMessage(networkMessage); } diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index b35e5226..e89eed28 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -792,7 +792,7 @@ void ServerInterface::dispatchPendingChatMessages(std::vector &errorMsg if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] #1 about to broadcast nmtText chatText [%s] chatTeamIndex = %d, newChatPlayerIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,newChatText.c_str(),newChatTeamIndex,newChatPlayerIndex); if(newChatLanguage == "" || newChatLanguage == connectionSlot->getNetworkPlayerLanguage()) { - NetworkMessageText networkMessageText(newChatText.c_str(),newChatTeamIndex,newChatPlayerIndex,""); + NetworkMessageText networkMessageText(newChatText.c_str(),newChatTeamIndex,newChatPlayerIndex,newChatLanguage); broadcastMessage(&networkMessageText, connectionSlot->getPlayerIndex(),i); }