- bugfixes related to multi-language text messaging

This commit is contained in:
Mark Vejvoda 2011-04-05 20:19:25 +00:00
parent 4a27e75891
commit 9cb1cd7bc8
7 changed files with 50 additions and 11 deletions

View File

@ -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<GraphicButton *>(iterFind2->second) != NULL) {
GraphicComponent *ctl = dynamic_cast<GraphicComponent *>(iterFind2->second);

View File

@ -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__);
}

View File

@ -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<string> 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) {

View File

@ -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);
}

View File

@ -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());

View File

@ -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<const NetworkMessageText *>(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);
}

View File

@ -792,7 +792,7 @@ void ServerInterface::dispatchPendingChatMessages(std::vector <string> &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);
}