diff --git a/mk/linux/glestkeys.ini b/mk/linux/glestkeys.ini index 47d62072..56230666 100644 --- a/mk/linux/glestkeys.ini +++ b/mk/linux/glestkeys.ini @@ -45,6 +45,7 @@ ToggleMusic=K SaveGUILayout=f11 ReloadINI=f5 TogglePhotoMode=f8 +SwitchLanguage=L ; === propertyMap File === diff --git a/source/glest_game/facilities/components.cpp b/source/glest_game/facilities/components.cpp index 5ee56dd3..5290dd71 100644 --- a/source/glest_game/facilities/components.cpp +++ b/source/glest_game/facilities/components.cpp @@ -206,13 +206,30 @@ bool GraphicComponent::saveCustomProperties(std::string containerName) { return savedChange; } +void GraphicComponent::reloadFonts() { + font= CoreData::getInstance().getMenuFontNormal(); + font3D= CoreData::getInstance().getMenuFontNormal3D(); +} + +void GraphicComponent::reloadFontsForRegisterGraphicComponents(std::string containerName) { + std::map >::iterator iterFind1 = GraphicComponent::registeredGraphicComponentList.find(containerName); + if(iterFind1 != GraphicComponent::registeredGraphicComponentList.end()) { + for(std::map::iterator iterFind2 = iterFind1->second.begin(); + iterFind2 != iterFind1->second.end(); ++iterFind2) { + GraphicComponent *ctl = dynamic_cast(iterFind2->second); + if(ctl) { + ctl->reloadFonts(); + } + } + } +} + void GraphicComponent::init(int x, int y, int w, int h) { this->x= x; this->y= y; this->w= w; this->h= h; - font= CoreData::getInstance().getMenuFontNormal(); - font3D= CoreData::getInstance().getMenuFontNormal3D(); + reloadFonts(); enabled= true; } diff --git a/source/glest_game/facilities/components.h b/source/glest_game/facilities/components.h index 8116dc29..b9a996bc 100644 --- a/source/glest_game/facilities/components.h +++ b/source/glest_game/facilities/components.h @@ -102,6 +102,9 @@ public: virtual void setEditable(bool editable) {this->editable= editable;} virtual void setVisible(bool value) {this->visible = value;} + virtual void reloadFonts(); + static void reloadFontsForRegisterGraphicComponents(std::string containerName); + virtual bool mouseMove(int x, int y); virtual bool mouseClick(int x, int y); diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 644bc577..e9f3e3f5 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -1678,11 +1678,27 @@ void Game::mouseDownLeft(int x, int y) { //this->setPaused(!paused); //printf("popup paused = %d\n",paused); - if(paused == false) { - commander.tryPauseGame(); + bool allowAdminMenuItems = false; + NetworkRole role = networkManager.getNetworkRole(); + if(role == nrServer) { + allowAdminMenuItems = true; } - else { - commander.tryResumeGame(); + else if(role == nrClient) { + ClientInterface *clientInterface = dynamic_cast(networkManager.getClientInterface()); + + if(clientInterface != NULL && + gameSettings.getMasterserver_admin() == clientInterface->getSessionKey()) { + allowAdminMenuItems = true; + } + } + + if(allowAdminMenuItems) { + if(paused == false) { + commander.tryPauseGame(); + } + else { + commander.tryResumeGame(); + } } } } @@ -2271,6 +2287,30 @@ void Game::keyDown(SDL_KeyboardEvent key) { else if(isKeyPressed(configKeys.getSDLKey("PauseGame"),key, false) == true) { //printf("Toggle pause paused = %d\n",paused); setPaused(!paused); + +// bool allowAdminMenuItems = false; +// NetworkManager &networkManager= NetworkManager::getInstance(); +// NetworkRole role = networkManager.getNetworkRole(); +// if(role == nrServer) { +// allowAdminMenuItems = true; +// } +// else if(role == nrClient) { +// ClientInterface *clientInterface = dynamic_cast(networkManager.getClientInterface()); +// +// if(clientInterface != NULL && +// gameSettings.getMasterserver_admin() == clientInterface->getSessionKey()) { +// allowAdminMenuItems = true; +// } +// } +// +// if(allowAdminMenuItems) { +// if(paused == false) { +// commander.tryPauseGame(); +// } +// else { +// commander.tryResumeGame(); +// } +// } } else if(isKeyPressed(configKeys.getSDLKey("ExtraTeamColorMarker"),key, false) == true) { //printf("Toggle ExtraTeamColorMarker\n"); diff --git a/source/glest_game/global/core_data.cpp b/source/glest_game/global/core_data.cpp index 33147869..94718d06 100644 --- a/source/glest_game/global/core_data.cpp +++ b/source/glest_game/global/core_data.cpp @@ -39,6 +39,44 @@ CoreData &CoreData::getInstance() { return coreData; } +CoreData::CoreData() { + logoTexture=NULL; + logoTextureList.clear(); + backgroundTexture=NULL; + fireTexture=NULL; + teamColorTexture=NULL; + snowTexture=NULL; + waterSplashTexture=NULL; + customTexture=NULL; + buttonSmallTexture=NULL; + buttonBigTexture=NULL; + horizontalLineTexture=NULL; + verticalLineTexture=NULL; + checkBoxTexture=NULL; + checkedCheckBoxTexture=NULL; + gameWinnerTexture=NULL; + notOnServerTexture=NULL; + onServerDifferentTexture=NULL; + onServerTexture=NULL; + onServerInstalledTexture=NULL; + + miscTextureList.clear(); + + displayFont=NULL; + menuFontNormal=NULL; + displayFontSmall=NULL; + menuFontBig=NULL; + menuFontVeryBig=NULL; + consoleFont=NULL; + + displayFont3D=NULL; + menuFontNormal3D=NULL; + displayFontSmall3D=NULL; + menuFontBig3D=NULL; + menuFontVeryBig3D=NULL; + consoleFont3D=NULL; +} + CoreData::~CoreData() { deleteValues(waterSounds.getSoundsPtr()->begin(), waterSounds.getSoundsPtr()->end()); waterSounds.getSoundsPtr()->clear(); @@ -190,212 +228,7 @@ void CoreData::load() { gameWinnerTexture->getPixmap()->load(dir+"/misc_textures/game_winner.png"); } - Lang &lang= Lang::getInstance(); - - //display font - Config &config= Config::getInstance(); - - string displayFontNamePrefix = config.getString("FontDisplayPrefix"); - string displayFontNamePostfix = config.getString("FontDisplayPostfix"); - int displayFontSize = computeFontSize(config.getInt("FontDisplayBaseSize")); - - //printf("Checking if langfile has custom FontDisplayPostfix\n"); - - if(lang.hasString("FontDisplayPrefix") == true) { - displayFontNamePrefix = lang.get("FontDisplayPrefix"); - } - if(lang.hasString("FontDisplayPostfix") == true) { - displayFontNamePostfix = lang.get("FontDisplayPostfix"); - } - if(lang.hasString("FontDisplayBaseSize") == true) { - displayFontSize = strToInt(lang.get("FontDisplayBaseSize")); - } - - //printf("displayFontNamePostfix [%s]\n",displayFontNamePostfix.c_str()); - - string displayFontName = displayFontNamePrefix + intToStr(displayFontSize) + displayFontNamePostfix; - - displayFont= renderer.newFont(rsGlobal); - if(displayFont) { - displayFont->setType(displayFontName,config.getString("FontDisplay","")); - displayFont->setSize(displayFontSize); - //displayFont->setYOffsetFactor(config.getFloat("FontDisplayYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str())); - } - - displayFont3D= renderer.newFont3D(rsGlobal); - if(displayFont3D) { - displayFont3D->setType(displayFontName,config.getString("FontDisplay","")); - displayFont3D->setSize(displayFontSize); - //displayFont3D->setYOffsetFactor(config.getFloat("FontDisplayYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str())); - } - - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] displayFontName = [%s] displayFontSize = %d\n",__FILE__,__FUNCTION__,__LINE__,displayFontName.c_str(),displayFontSize); - - //menu fonts - string displayFontNameSmallPrefix = config.getString("FontDisplayPrefix"); - string displayFontNameSmallPostfix = config.getString("FontDisplayPostfix"); - int displayFontNameSmallSize = computeFontSize(config.getInt("FontDisplaySmallBaseSize")); - - if(lang.hasString("FontDisplayPrefix") == true) { - displayFontNameSmallPrefix = lang.get("FontDisplayPrefix"); - } - if(lang.hasString("FontDisplayPostfix") == true) { - displayFontNameSmallPostfix = lang.get("FontDisplayPostfix"); - } - if(lang.hasString("FontDisplaySmallBaseSize") == true) { - displayFontNameSmallSize = strToInt(lang.get("FontDisplaySmallBaseSize")); - } - - string displayFontNameSmall = displayFontNameSmallPrefix + intToStr(displayFontNameSmallSize) + displayFontNameSmallPostfix; - - displayFontSmall= renderer.newFont(rsGlobal); - if(displayFontSmall) { - displayFontSmall->setType(displayFontNameSmall,config.getString("FontSmallDisplay","")); - displayFontSmall->setSize(displayFontNameSmallSize); - //displayFontSmall->setYOffsetFactor(config.getFloat("FontSmallDisplayYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str())); - } - - displayFontSmall3D= renderer.newFont3D(rsGlobal); - if(displayFontSmall3D) { - displayFontSmall3D->setType(displayFontNameSmall,config.getString("FontSmallDisplay","")); - displayFontSmall3D->setSize(displayFontNameSmallSize); - //displayFontSmall3D->setYOffsetFactor(config.getFloat("FontSmallDisplayYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str())); - } - - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] displayFontSmallName = [%s] displayFontSmallNameSize = %d\n",__FILE__,__FUNCTION__,__LINE__,displayFontNameSmall.c_str(),displayFontNameSmallSize); - - string menuFontNameNormalPrefix = config.getString("FontMenuNormalPrefix"); - string menuFontNameNormalPostfix = config.getString("FontMenuNormalPostfix"); - int menuFontNameNormalSize = computeFontSize(config.getInt("FontMenuNormalBaseSize")); - - if(lang.hasString("FontMenuNormalPrefix") == true) { - menuFontNameNormalPrefix = lang.get("FontMenuNormalPrefix"); - } - if(lang.hasString("FontMenuNormalPostfix") == true) { - menuFontNameNormalPostfix = lang.get("FontMenuNormalPostfix"); - } - if(lang.hasString("FontMenuNormalBaseSize") == true) { - menuFontNameNormalSize = strToInt(lang.get("FontMenuNormalBaseSize")); - } - - string menuFontNameNormal= menuFontNameNormalPrefix + intToStr(menuFontNameNormalSize) + menuFontNameNormalPostfix; - - menuFontNormal= renderer.newFont(rsGlobal); - if(menuFontNormal) { - menuFontNormal->setType(menuFontNameNormal,config.getString("FontMenuNormal","")); - menuFontNormal->setSize(menuFontNameNormalSize); - menuFontNormal->setWidth(Font::wBold); - //menuFontNormal->setYOffsetFactor(config.getFloat("FontMenuNormalYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str())); - } - - menuFontNormal3D= renderer.newFont3D(rsGlobal); - if(menuFontNormal3D) { - menuFontNormal3D->setType(menuFontNameNormal,config.getString("FontMenuNormal","")); - menuFontNormal3D->setSize(menuFontNameNormalSize); - menuFontNormal3D->setWidth(Font::wBold); - //menuFontNormal3D->setYOffsetFactor(config.getFloat("FontMenuNormalYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str())); - } - - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] menuFontNormalName = [%s] menuFontNormalNameSize = %d\n",__FILE__,__FUNCTION__,__LINE__,menuFontNameNormal.c_str(),menuFontNameNormalSize); - - string menuFontNameBigPrefix = config.getString("FontMenuBigPrefix"); - string menuFontNameBigPostfix = config.getString("FontMenuBigPostfix"); - int menuFontNameBigSize = computeFontSize(config.getInt("FontMenuBigBaseSize")); - - if(lang.hasString("FontMenuBigPrefix") == true) { - menuFontNameBigPrefix = lang.get("FontMenuBigPrefix"); - } - if(lang.hasString("FontMenuBigPostfix") == true) { - menuFontNameBigPostfix = lang.get("FontMenuBigPostfix"); - } - if(lang.hasString("FontMenuBigBaseSize") == true) { - menuFontNameBigSize = strToInt(lang.get("FontMenuBigBaseSize")); - } - - string menuFontNameBig= menuFontNameBigPrefix+intToStr(menuFontNameBigSize)+menuFontNameBigPostfix; - - menuFontBig= renderer.newFont(rsGlobal); - if(menuFontBig) { - menuFontBig->setType(menuFontNameBig,config.getString("FontMenuBig","")); - menuFontBig->setSize(menuFontNameBigSize); - //menuFontBig->setYOffsetFactor(config.getFloat("FontMenuBigYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str())); - } - - menuFontBig3D= renderer.newFont3D(rsGlobal); - if(menuFontBig3D) { - menuFontBig3D->setType(menuFontNameBig,config.getString("FontMenuBig","")); - menuFontBig3D->setSize(menuFontNameBigSize); - //menuFontBig3D->setYOffsetFactor(config.getFloat("FontMenuBigYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str())); - } - - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] menuFontNameBig = [%s] menuFontNameBigSize = %d\n",__FILE__,__FUNCTION__,__LINE__,menuFontNameBig.c_str(),menuFontNameBigSize); - - string menuFontNameVeryBigPrefix = config.getString("FontMenuBigPrefix"); - string menuFontNameVeryBigPostfix = config.getString("FontMenuBigPostfix"); - int menuFontNameVeryBigSize = computeFontSize(config.getInt("FontMenuVeryBigBaseSize")); - - if(lang.hasString("FontMenuBigPrefix") == true) { - menuFontNameVeryBigPrefix = lang.get("FontMenuBigPrefix"); - } - if(lang.hasString("FontMenuBigPostfix") == true) { - menuFontNameVeryBigPostfix = lang.get("FontMenuBigPostfix"); - } - if(lang.hasString("FontMenuVeryBigBaseSize") == true) { - menuFontNameVeryBigSize = strToInt(lang.get("FontMenuVeryBigBaseSize")); - } - - string menuFontNameVeryBig= menuFontNameVeryBigPrefix + intToStr(menuFontNameVeryBigSize) + menuFontNameVeryBigPostfix; - - menuFontVeryBig= renderer.newFont(rsGlobal); - if(menuFontVeryBig) { - menuFontVeryBig->setType(menuFontNameVeryBig,config.getString("FontMenuVeryBig","")); - menuFontVeryBig->setSize(menuFontNameVeryBigSize); - //menuFontVeryBig->setYOffsetFactor(config.getFloat("FontMenuVeryBigYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str())); - } - - menuFontVeryBig3D= renderer.newFont3D(rsGlobal); - if(menuFontVeryBig3D) { - menuFontVeryBig3D->setType(menuFontNameVeryBig,config.getString("FontMenuVeryBig","")); - menuFontVeryBig3D->setSize(menuFontNameVeryBigSize); - //menuFontVeryBig3D->setYOffsetFactor(config.getFloat("FontMenuVeryBigYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str())); - } - - //printf("CoreData menuFontVeryBig3D [%d] menuFontVeryBig3D [%p]\n",menuFontVeryBig3D->getSize(),menuFontVeryBig3D); - - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] menuFontNameVeryBig = [%s] menuFontNameVeryBigSize = %d\n",__FILE__,__FUNCTION__,__LINE__,menuFontNameVeryBig.c_str(),menuFontNameVeryBigSize); - - //console font - string consoleFontNamePrefix = config.getString("FontConsolePrefix"); - string consoleFontNamePostfix = config.getString("FontConsolePostfix"); - int consoleFontNameSize = computeFontSize(config.getInt("FontConsoleBaseSize")); - - if(lang.hasString("FontConsolePrefix") == true) { - consoleFontNamePrefix = lang.get("FontConsolePrefix"); - } - if(lang.hasString("FontConsolePostfix") == true) { - consoleFontNamePostfix = lang.get("FontConsolePostfix"); - } - if(lang.hasString("FontConsoleBaseSize") == true) { - consoleFontNameSize = strToInt(lang.get("FontConsoleBaseSize")); - } - - string consoleFontName= consoleFontNamePrefix + intToStr(consoleFontNameSize) + consoleFontNamePostfix; - - consoleFont= renderer.newFont(rsGlobal); - if(consoleFont) { - consoleFont->setType(consoleFontName,config.getString("FontConsole","")); - consoleFont->setSize(consoleFontNameSize); - //consoleFont->setYOffsetFactor(config.getFloat("FontConsoleYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str())); - } - - consoleFont3D= renderer.newFont3D(rsGlobal); - if(consoleFont3D) { - consoleFont3D->setType(consoleFontName,config.getString("FontConsole","")); - consoleFont3D->setSize(consoleFontNameSize); - //consoleFont3D->setYOffsetFactor(config.getFloat("FontConsoleYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str())); - } - - if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] consoleFontName = [%s] consoleFontNameSize = %d\n",__FILE__,__FUNCTION__,__LINE__,consoleFontName.c_str(),consoleFontNameSize); + loadFonts(); //sounds XmlTree xmlTree; @@ -434,6 +267,252 @@ void CoreData::load() { } +void CoreData::loadFonts() { + Renderer &renderer= Renderer::getInstance(); + Lang &lang= Lang::getInstance(); + + //display font + Config &config= Config::getInstance(); + + string displayFontNamePrefix = config.getString("FontDisplayPrefix"); + string displayFontNamePostfix = config.getString("FontDisplayPostfix"); + int displayFontSize = computeFontSize(config.getInt("FontDisplayBaseSize")); + + //printf("Checking if langfile has custom FontDisplayPostfix\n"); + + if(lang.hasString("FontDisplayPrefix") == true) { + displayFontNamePrefix = lang.get("FontDisplayPrefix"); + } + if(lang.hasString("FontDisplayPostfix") == true) { + displayFontNamePostfix = lang.get("FontDisplayPostfix"); + } + if(lang.hasString("FontDisplayBaseSize") == true) { + displayFontSize = strToInt(lang.get("FontDisplayBaseSize")); + } + + //printf("displayFontNamePostfix [%s]\n",displayFontNamePostfix.c_str()); + + string displayFontName = displayFontNamePrefix + intToStr(displayFontSize) + displayFontNamePostfix; + + if(displayFont) { + renderer.endFont(displayFont, rsGlobal); + } + displayFont= renderer.newFont(rsGlobal); + if(displayFont) { + displayFont->setType(displayFontName,config.getString("FontDisplay","")); + displayFont->setSize(displayFontSize); + //displayFont->setYOffsetFactor(config.getFloat("FontDisplayYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str())); + } + + if(displayFont3D) { + renderer.endFont(displayFont3D, rsGlobal); + } + displayFont3D= renderer.newFont3D(rsGlobal); + if(displayFont3D) { + displayFont3D->setType(displayFontName,config.getString("FontDisplay","")); + displayFont3D->setSize(displayFontSize); + //displayFont3D->setYOffsetFactor(config.getFloat("FontDisplayYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str())); + } + + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] displayFontName = [%s] displayFontSize = %d\n",__FILE__,__FUNCTION__,__LINE__,displayFontName.c_str(),displayFontSize); + + //menu fonts + string displayFontNameSmallPrefix = config.getString("FontDisplayPrefix"); + string displayFontNameSmallPostfix = config.getString("FontDisplayPostfix"); + int displayFontNameSmallSize = computeFontSize(config.getInt("FontDisplaySmallBaseSize")); + + if(lang.hasString("FontDisplayPrefix") == true) { + displayFontNameSmallPrefix = lang.get("FontDisplayPrefix"); + } + if(lang.hasString("FontDisplayPostfix") == true) { + displayFontNameSmallPostfix = lang.get("FontDisplayPostfix"); + } + if(lang.hasString("FontDisplaySmallBaseSize") == true) { + displayFontNameSmallSize = strToInt(lang.get("FontDisplaySmallBaseSize")); + } + + string displayFontNameSmall = displayFontNameSmallPrefix + intToStr(displayFontNameSmallSize) + displayFontNameSmallPostfix; + + if(displayFontSmall) { + renderer.endFont(displayFontSmall, rsGlobal); + } + displayFontSmall= renderer.newFont(rsGlobal); + if(displayFontSmall) { + displayFontSmall->setType(displayFontNameSmall,config.getString("FontSmallDisplay","")); + displayFontSmall->setSize(displayFontNameSmallSize); + //displayFontSmall->setYOffsetFactor(config.getFloat("FontSmallDisplayYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str())); + } + + if(displayFontSmall3D) { + renderer.endFont(displayFontSmall3D, rsGlobal); + } + displayFontSmall3D= renderer.newFont3D(rsGlobal); + if(displayFontSmall3D) { + displayFontSmall3D->setType(displayFontNameSmall,config.getString("FontSmallDisplay","")); + displayFontSmall3D->setSize(displayFontNameSmallSize); + //displayFontSmall3D->setYOffsetFactor(config.getFloat("FontSmallDisplayYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str())); + } + + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] displayFontSmallName = [%s] displayFontSmallNameSize = %d\n",__FILE__,__FUNCTION__,__LINE__,displayFontNameSmall.c_str(),displayFontNameSmallSize); + + string menuFontNameNormalPrefix = config.getString("FontMenuNormalPrefix"); + string menuFontNameNormalPostfix = config.getString("FontMenuNormalPostfix"); + int menuFontNameNormalSize = computeFontSize(config.getInt("FontMenuNormalBaseSize")); + + if(lang.hasString("FontMenuNormalPrefix") == true) { + menuFontNameNormalPrefix = lang.get("FontMenuNormalPrefix"); + } + if(lang.hasString("FontMenuNormalPostfix") == true) { + menuFontNameNormalPostfix = lang.get("FontMenuNormalPostfix"); + } + if(lang.hasString("FontMenuNormalBaseSize") == true) { + menuFontNameNormalSize = strToInt(lang.get("FontMenuNormalBaseSize")); + } + + string menuFontNameNormal= menuFontNameNormalPrefix + intToStr(menuFontNameNormalSize) + menuFontNameNormalPostfix; + + if(menuFontNormal) { + renderer.endFont(menuFontNormal, rsGlobal); + } + menuFontNormal= renderer.newFont(rsGlobal); + if(menuFontNormal) { + menuFontNormal->setType(menuFontNameNormal,config.getString("FontMenuNormal","")); + menuFontNormal->setSize(menuFontNameNormalSize); + menuFontNormal->setWidth(Font::wBold); + //menuFontNormal->setYOffsetFactor(config.getFloat("FontMenuNormalYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str())); + } + + if(menuFontNormal3D) { + renderer.endFont(menuFontNormal3D, rsGlobal); + } + menuFontNormal3D= renderer.newFont3D(rsGlobal); + if(menuFontNormal3D) { + menuFontNormal3D->setType(menuFontNameNormal,config.getString("FontMenuNormal","")); + menuFontNormal3D->setSize(menuFontNameNormalSize); + menuFontNormal3D->setWidth(Font::wBold); + //menuFontNormal3D->setYOffsetFactor(config.getFloat("FontMenuNormalYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str())); + } + + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] menuFontNormalName = [%s] menuFontNormalNameSize = %d\n",__FILE__,__FUNCTION__,__LINE__,menuFontNameNormal.c_str(),menuFontNameNormalSize); + + string menuFontNameBigPrefix = config.getString("FontMenuBigPrefix"); + string menuFontNameBigPostfix = config.getString("FontMenuBigPostfix"); + int menuFontNameBigSize = computeFontSize(config.getInt("FontMenuBigBaseSize")); + + if(lang.hasString("FontMenuBigPrefix") == true) { + menuFontNameBigPrefix = lang.get("FontMenuBigPrefix"); + } + if(lang.hasString("FontMenuBigPostfix") == true) { + menuFontNameBigPostfix = lang.get("FontMenuBigPostfix"); + } + if(lang.hasString("FontMenuBigBaseSize") == true) { + menuFontNameBigSize = strToInt(lang.get("FontMenuBigBaseSize")); + } + + string menuFontNameBig= menuFontNameBigPrefix+intToStr(menuFontNameBigSize)+menuFontNameBigPostfix; + + if(menuFontBig) { + renderer.endFont(menuFontBig, rsGlobal); + } + menuFontBig= renderer.newFont(rsGlobal); + if(menuFontBig) { + menuFontBig->setType(menuFontNameBig,config.getString("FontMenuBig","")); + menuFontBig->setSize(menuFontNameBigSize); + //menuFontBig->setYOffsetFactor(config.getFloat("FontMenuBigYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str())); + } + + if(menuFontBig3D) { + renderer.endFont(menuFontBig3D, rsGlobal); + } + menuFontBig3D= renderer.newFont3D(rsGlobal); + if(menuFontBig3D) { + menuFontBig3D->setType(menuFontNameBig,config.getString("FontMenuBig","")); + menuFontBig3D->setSize(menuFontNameBigSize); + //menuFontBig3D->setYOffsetFactor(config.getFloat("FontMenuBigYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str())); + } + + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] menuFontNameBig = [%s] menuFontNameBigSize = %d\n",__FILE__,__FUNCTION__,__LINE__,menuFontNameBig.c_str(),menuFontNameBigSize); + + string menuFontNameVeryBigPrefix = config.getString("FontMenuBigPrefix"); + string menuFontNameVeryBigPostfix = config.getString("FontMenuBigPostfix"); + int menuFontNameVeryBigSize = computeFontSize(config.getInt("FontMenuVeryBigBaseSize")); + + if(lang.hasString("FontMenuBigPrefix") == true) { + menuFontNameVeryBigPrefix = lang.get("FontMenuBigPrefix"); + } + if(lang.hasString("FontMenuBigPostfix") == true) { + menuFontNameVeryBigPostfix = lang.get("FontMenuBigPostfix"); + } + if(lang.hasString("FontMenuVeryBigBaseSize") == true) { + menuFontNameVeryBigSize = strToInt(lang.get("FontMenuVeryBigBaseSize")); + } + + string menuFontNameVeryBig= menuFontNameVeryBigPrefix + intToStr(menuFontNameVeryBigSize) + menuFontNameVeryBigPostfix; + + if(menuFontVeryBig) { + renderer.endFont(menuFontVeryBig, rsGlobal); + } + menuFontVeryBig= renderer.newFont(rsGlobal); + if(menuFontVeryBig) { + menuFontVeryBig->setType(menuFontNameVeryBig,config.getString("FontMenuVeryBig","")); + menuFontVeryBig->setSize(menuFontNameVeryBigSize); + //menuFontVeryBig->setYOffsetFactor(config.getFloat("FontMenuVeryBigYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str())); + } + + if(menuFontVeryBig3D) { + renderer.endFont(menuFontVeryBig3D, rsGlobal); + } + menuFontVeryBig3D= renderer.newFont3D(rsGlobal); + if(menuFontVeryBig3D) { + menuFontVeryBig3D->setType(menuFontNameVeryBig,config.getString("FontMenuVeryBig","")); + menuFontVeryBig3D->setSize(menuFontNameVeryBigSize); + //menuFontVeryBig3D->setYOffsetFactor(config.getFloat("FontMenuVeryBigYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str())); + } + + //printf("CoreData menuFontVeryBig3D [%d] menuFontVeryBig3D [%p]\n",menuFontVeryBig3D->getSize(),menuFontVeryBig3D); + + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] menuFontNameVeryBig = [%s] menuFontNameVeryBigSize = %d\n",__FILE__,__FUNCTION__,__LINE__,menuFontNameVeryBig.c_str(),menuFontNameVeryBigSize); + + //console font + string consoleFontNamePrefix = config.getString("FontConsolePrefix"); + string consoleFontNamePostfix = config.getString("FontConsolePostfix"); + int consoleFontNameSize = computeFontSize(config.getInt("FontConsoleBaseSize")); + + if(lang.hasString("FontConsolePrefix") == true) { + consoleFontNamePrefix = lang.get("FontConsolePrefix"); + } + if(lang.hasString("FontConsolePostfix") == true) { + consoleFontNamePostfix = lang.get("FontConsolePostfix"); + } + if(lang.hasString("FontConsoleBaseSize") == true) { + consoleFontNameSize = strToInt(lang.get("FontConsoleBaseSize")); + } + + string consoleFontName= consoleFontNamePrefix + intToStr(consoleFontNameSize) + consoleFontNamePostfix; + + if(consoleFont) { + renderer.endFont(consoleFont, rsGlobal); + } + consoleFont= renderer.newFont(rsGlobal); + if(consoleFont) { + consoleFont->setType(consoleFontName,config.getString("FontConsole","")); + consoleFont->setSize(consoleFontNameSize); + //consoleFont->setYOffsetFactor(config.getFloat("FontConsoleYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str())); + } + + if(consoleFont3D) { + renderer.endFont(consoleFont3D, rsGlobal); + } + consoleFont3D= renderer.newFont3D(rsGlobal); + if(consoleFont3D) { + consoleFont3D->setType(consoleFontName,config.getString("FontConsole","")); + consoleFont3D->setSize(consoleFontNameSize); + //consoleFont3D->setYOffsetFactor(config.getFloat("FontConsoleYOffsetFactor",floatToStr(FontMetrics::DEFAULT_Y_OFFSET_FACTOR).c_str())); + } + + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] consoleFontName = [%s] consoleFontNameSize = %d\n",__FILE__,__FUNCTION__,__LINE__,consoleFontName.c_str(),consoleFontNameSize); +} + int CoreData::computeFontSize(int size) { int rs = size; Config &config= Config::getInstance(); diff --git a/source/glest_game/global/core_data.h b/source/glest_game/global/core_data.h index 116f6896..34f8bba8 100644 --- a/source/glest_game/global/core_data.h +++ b/source/glest_game/global/core_data.h @@ -35,7 +35,7 @@ using Shared::Sound::StaticSound; /// Data shared ammont all the ProgramStates // ===================================================== -class CoreData{ +class CoreData { private: StrSound introMusic; StrSound menuMusic; @@ -83,10 +83,12 @@ private: Font3D *consoleFont3D; public: - static CoreData &getInstance(); + ~CoreData(); + static CoreData &getInstance(); void load(); + void loadFonts(); Texture2D *getBackgroundTexture() const {return backgroundTexture;} Texture2D *getFireTexture() const {return fireTexture;} @@ -137,7 +139,7 @@ public: Font3D *getConsoleFont3D() const {return consoleFont3D;} private: - CoreData(){}; + CoreData(); int computeFontSize(int size); }; diff --git a/source/glest_game/global/lang.cpp b/source/glest_game/global/lang.cpp index 88980819..0d1b7a03 100644 --- a/source/glest_game/global/lang.cpp +++ b/source/glest_game/global/lang.cpp @@ -19,6 +19,10 @@ #include "game_constants.h" #include "game_util.h" #include "platform_common.h" +#include "conversion.h" +#include "gl_wrap.h" +#include "core_data.h" +#include "renderer.h" #include "leak_dumper.h" using namespace std; @@ -42,8 +46,117 @@ Lang &Lang::getInstance() { } void Lang::loadStrings(const string &language) { + bool languageChanged = (language != this->language); this->language= language; loadStrings(language, strings, true); + + if(languageChanged == true) { + Font::resetToDefaults(); + Lang &lang = Lang::getInstance(); + if( lang.hasString("FONT_BASE_SIZE")) { + Font::baseSize = strToInt(lang.get("FONT_BASE_SIZE")); + } + + if( lang.hasString("FONT_SCALE_SIZE")) { + Font::scaleFontValue = strToFloat(lang.get("FONT_SCALE_SIZE")); + } + if( lang.hasString("FONT_SCALE_CENTERH_FACTOR")) { + Font::scaleFontValueCenterHFactor = strToFloat(lang.get("FONT_SCALE_CENTERH_FACTOR")); + } + + if( lang.hasString("FONT_CHARCOUNT")) { + // 256 for English + // 30000 for Chinese + Font::charCount = strToInt(lang.get("FONT_CHARCOUNT")); + } + if( lang.hasString("FONT_TYPENAME")) { + Font::fontTypeName = lang.get("FONT_TYPENAME"); + } + if( lang.hasString("FONT_CHARSET")) { + // Example values: + // DEFAULT_CHARSET (English) = 1 + // GB2312_CHARSET (Chinese) = 134 + Shared::Platform::charSet = strToInt(lang.get("FONT_CHARSET")); + } + if( lang.hasString("FONT_MULTIBYTE")) { + Font::fontIsMultibyte = strToBool(lang.get("FONT_MULTIBYTE")); + } + + if( lang.hasString("FONT_RIGHTTOLEFT")) { + Font::fontIsRightToLeft = strToBool(lang.get("FONT_RIGHTTOLEFT")); + } + + if( lang.hasString("MEGAGLEST_FONT")) { + //setenv("MEGAGLEST_FONT","/usr/share/fonts/truetype/ttf-japanese-gothic.ttf",0); // Japanese + #if defined(WIN32) + string newEnvValue = "MEGAGLEST_FONT=" + lang.get("MEGAGLEST_FONT"); + _putenv(newEnvValue.c_str()); + #else + setenv("MEGAGLEST_FONT",lang.get("MEGAGLEST_FONT").c_str(),0); + #endif + } + + // if( lang.hasString("FONT_YOFFSET_FACTOR")) { + // FontMetrics::DEFAULT_Y_OFFSET_FACTOR = strToFloat(lang.get("FONT_YOFFSET_FACTOR")); + // } + + #if defined(WIN32) + // Win32 overrides for fonts (just in case they must be different) + + if( lang.hasString("FONT_BASE_SIZE_WINDOWS")) { + // 256 for English + // 30000 for Chinese + Font::baseSize = strToInt(lang.get("FONT_BASE_SIZE_WINDOWS")); + } + + if( lang.hasString("FONT_SCALE_SIZE_WINDOWS")) { + Font::scaleFontValue = strToFloat(lang.get("FONT_SCALE_SIZE_WINDOWS")); + } + if( lang.hasString("FONT_SCALE_CENTERH_FACTOR_WINDOWS")) { + Font::scaleFontValueCenterHFactor = strToFloat(lang.get("FONT_SCALE_CENTERH_FACTOR_WINDOWS")); + } + + if( lang.hasString("FONT_HEIGHT_TEXT_WINDOWS")) { + Font::langHeightText = config.getString("FONT_HEIGHT_TEXT_WINDOWS",Font::langHeightText.c_str()); + } + + if( lang.hasString("FONT_CHARCOUNT_WINDOWS")) { + // 256 for English + // 30000 for Chinese + Font::charCount = strToInt(lang.get("FONT_CHARCOUNT_WINDOWS")); + } + if( lang.hasString("FONT_TYPENAME_WINDOWS")) { + Font::fontTypeName = lang.get("FONT_TYPENAME_WINDOWS"); + } + if( lang.hasString("FONT_CHARSET_WINDOWS")) { + // Example values: + // DEFAULT_CHARSET (English) = 1 + // GB2312_CHARSET (Chinese) = 134 + Shared::Platform::charSet = strToInt(lang.get("FONT_CHARSET_WINDOWS")); + } + if( lang.hasString("FONT_MULTIBYTE_WINDOWS")) { + Font::fontIsMultibyte = strToBool(lang.get("FONT_MULTIBYTE_WINDOWS")); + } + if( lang.hasString("FONT_RIGHTTOLEFT_WINDOWS")) { + Font::fontIsRightToLeft = strToBool(lang.get("FONT_RIGHTTOLEFT_WINDOWS")); + } + + if( lang.hasString("MEGAGLEST_FONT_WINDOWS")) { + //setenv("MEGAGLEST_FONT","/usr/share/fonts/truetype/ttf-japanese-gothic.ttf",0); // Japanese + string newEnvValue = "MEGAGLEST_FONT=" + lang.get("MEGAGLEST_FONT_WINDOWS"); + _putenv(newEnvValue.c_str()); + } + + // if( lang.hasString("FONT_YOFFSET_FACTOR_WINDOWS")) { + // FontMetrics::DEFAULT_Y_OFFSET_FACTOR = strToFloat(lang.get("FONT_YOFFSET_FACTOR_WINDOWS")); + // } + + // end win32 + #endif + + CoreData &coreData= CoreData::getInstance(); + coreData.loadFonts(); + } } void Lang::loadStrings(const string &language, Properties &properties, bool fileMustExist) { @@ -139,7 +252,7 @@ string Lang::get(const string &s, string language) { } catch(exception &ex) { if(strings.getpath() != "") { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s] language [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what(),language.c_str()); + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s] language [%s] text [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what(),language.c_str(),s.c_str()); } return "???" + s + "???"; } diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index e3595b70..4f2fa360 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -729,6 +729,19 @@ Font3D *Renderer::newFont3D(ResourceScope rs){ return fontManager[rs]->newFont3D(); } +void Renderer::endFont(Font *font, ResourceScope rs, bool mustExistInList) { + if(this->masterserverMode == true) { + return; + } + + fontManager[rs]->endFont(font,mustExistInList); +} + +void Renderer::resetFontManager(ResourceScope rs) { + fontManager[rs]->end(); + fontManager[rsGlobal]->init(); +} + void Renderer::manageParticleSystem(ParticleSystem *particleSystem, ResourceScope rs){ particleManager[rs]->manage(particleSystem); } diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index 4c8f0124..283663c6 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -384,6 +384,8 @@ public: Texture3D *newTexture3D(ResourceScope rs); Font2D *newFont(ResourceScope rs); Font3D *newFont3D(ResourceScope rs); + void endFont(Font *font, ResourceScope rs, bool mustExistInList=false); + void resetFontManager(ResourceScope rs); TextRenderer2D *getTextRenderer() const {return textRenderer;} TextRenderer3D *getTextRenderer3D() const {return textRenderer3D;} diff --git a/source/glest_game/main/battle_end.cpp b/source/glest_game/main/battle_end.cpp index 0c474cb8..cfd4df5d 100644 --- a/source/glest_game/main/battle_end.cpp +++ b/source/glest_game/main/battle_end.cpp @@ -35,6 +35,9 @@ namespace Glest{ namespace Game{ // ===================================================== BattleEnd::BattleEnd(Program *program, const Stats *stats,ProgramState *originState): ProgramState(program) { + + containerName= "BattleEnd"; + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d] stats = %p\n",__FILE__,__FUNCTION__,__LINE__,stats); this->originState = originState; @@ -58,6 +61,16 @@ BattleEnd::BattleEnd(Program *program, const Stats *stats,ProgramState *originSt mainMessageBox.setEnabled(false); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); + + GraphicComponent::applyAllCustomProperties(containerName); +} + +void BattleEnd::reloadUI() { + Lang &lang= Lang::getInstance(); + buttonExit.setText(lang.get("Exit")); + mainMessageBox.init(lang.get("Yes"), lang.get("No")); + + GraphicComponent::reloadFontsForRegisterGraphicComponents(containerName); } BattleEnd::~BattleEnd() { diff --git a/source/glest_game/main/battle_end.h b/source/glest_game/main/battle_end.h index d65305e2..e2c4add6 100644 --- a/source/glest_game/main/battle_end.h +++ b/source/glest_game/main/battle_end.h @@ -35,6 +35,7 @@ private: GraphicMessageBox mainMessageBox; Texture2D *renderToTexture; ProgramState *originState; + const char *containerName; void showMessageBox(const string &text, const string &header, bool toggle); @@ -48,6 +49,7 @@ public: virtual void mouseDownLeft(int x, int y); virtual void mouseMove(int x, int y, const MouseState *ms); //virtual void tick(); + virtual void reloadUI(); }; }}//end namespace diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index ba76d22f..442699ac 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -655,8 +655,9 @@ void handleSIGSEGV(int sig) { MainWindow::MainWindow(Program *program) : WindowGl() { this->program= program; + this->popupMenu.setEnabled(false); + this->popupMenu.setVisible(false); } - MainWindow::~MainWindow(){ if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); delete program; @@ -673,6 +674,23 @@ void MainWindow::eventMouseDown(int x, int y, MouseButton mouseButton){ throw runtime_error("In [MainWindow::eventMouseDown] ERROR, program == NULL!"); } + //printf("eventMouseDown popupMenu.getVisible() = %d\n",popupMenu.getVisible()); + if(popupMenu.getVisible() == true && popupMenu.mouseClick(vx, vy)) { + std::pair result = popupMenu.mouseClickedMenuItem(vx, vy); + //printf("In popup callback menuItemSelected [%s] menuIndexSelected = %d\n",result.second.c_str(),result.first); + + popupMenu.setEnabled(false); + popupMenu.setVisible(false); + + //printf("result.first = %d [%s] cancelLanguageSelection = %d\n",result.first,result.second.c_str(),cancelLanguageSelection); + + // Exit game + if(result.first != cancelLanguageSelection) { + toggleLanguage(result.second); + } + + return; + } SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); switch(mouseButton) { @@ -827,6 +845,79 @@ void MainWindow::eventMouseWheel(int x, int y, int zDelta) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } +void MainWindow::render() { + if(popupMenu.getVisible() == true) { + Renderer &renderer= Renderer::getInstance(); + renderer.renderPopupMenu(&popupMenu); + + //printf("Render lang popup\n"); + } +} + +void MainWindow::showLanguages() { + Lang &lang= Lang::getInstance(); + //PopupMenu popupMenu; + std::vector menuItems; + + vector langResults; + string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); + findAll(data_path + "data/lang/*.lng", langResults, true); + if(langResults.empty()){ + throw runtime_error("There is no lang file"); + } + + for(unsigned int i = 0; i < langResults.size(); ++i) { + string testLanguage = langResults[i]; + menuItems.push_back(testLanguage); + } + menuItems.push_back(lang.get("ExitGame?")); + cancelLanguageSelection = menuItems.size()-1; + + popupMenu.setW(100); + popupMenu.setH(100); + popupMenu.init(lang.get("GameMenuTitle"),menuItems); + popupMenu.setEnabled(true); + popupMenu.setVisible(true); +} + +void MainWindow::toggleLanguage(string language) { + popupMenu.setEnabled(false); + popupMenu.setVisible(false); + + Lang &lang= Lang::getInstance(); + string currentLanguage = lang.getLanguage(); + + string newLanguageSelected = language; + if(language == "") { + newLanguageSelected = currentLanguage; + + vector langResults; + string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); + findAll(data_path + "data/lang/*.lng", langResults, true); + if(langResults.empty()){ + throw runtime_error("There is no lang file"); + } + + for(unsigned int i = 0; i < langResults.size(); ++i) { + string testLanguage = langResults[i]; + if(testLanguage == currentLanguage) { + if( i+1 < langResults.size()) { + newLanguageSelected = langResults[i+1]; + } + else { + newLanguageSelected = langResults[0]; + } + break; + } + } + } + if(newLanguageSelected != currentLanguage) { + lang.loadStrings(newLanguageSelected); + program->reloadUI(); + program->consoleAddLine(lang.get("Language") + " " + newLanguageSelected); + } +} + void MainWindow::eventKeyDown(SDL_KeyboardEvent key) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key.keysym.sym); @@ -839,6 +930,12 @@ void MainWindow::eventKeyDown(SDL_KeyboardEvent key) { throw runtime_error("In [MainWindow::eventKeyDown] ERROR, program == NULL!"); } + if(popupMenu.getVisible() == true && isKeyPressed(SDLK_ESCAPE,key) == true) { + this->popupMenu.setEnabled(false); + this->popupMenu.setVisible(false); + return; + } + //{ //Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); //printf("----------------------- key [%d] CameraModeLeft [%d]\n",key,configKeys.getCharKey("CameraModeLeft")); @@ -883,6 +980,15 @@ void MainWindow::eventKeyDown(SDL_KeyboardEvent key) { renderer.setShowDebugUI(!showDebugUI); } } + else if(keystate.mod & (KMOD_LCTRL | KMOD_RCTRL) && + isKeyPressed(configKeys.getSDLKey("SwitchLanguage"),key) == true) { + if(keystate.mod & (KMOD_LSHIFT | KMOD_RSHIFT)) { + toggleLanguage(""); + } + else { + showLanguages(); + } + } //else if(key == configKeys.getCharKey("ReloadINI")) { else if(isKeyPressed(configKeys.getSDLKey("ReloadINI"),key) == true) { Config &config = Config::getInstance(); @@ -2727,111 +2833,11 @@ int glestMain(int argc, char** argv) { } lang.loadStrings(language); - if( lang.hasString("FONT_BASE_SIZE")) { - Font::baseSize = strToInt(lang.get("FONT_BASE_SIZE")); - } - - if( lang.hasString("FONT_SCALE_SIZE")) { - Font::scaleFontValue = strToFloat(lang.get("FONT_SCALE_SIZE")); - } - if( lang.hasString("FONT_SCALE_CENTERH_FACTOR")) { - Font::scaleFontValueCenterHFactor = strToFloat(lang.get("FONT_SCALE_CENTERH_FACTOR")); - } if( lang.hasString("FONT_HEIGHT_TEXT")) { Font::langHeightText = config.getString("FONT_HEIGHT_TEXT",Font::langHeightText.c_str()); } - if( lang.hasString("FONT_CHARCOUNT")) { - // 256 for English - // 30000 for Chinese - Font::charCount = strToInt(lang.get("FONT_CHARCOUNT")); - } - if( lang.hasString("FONT_TYPENAME")) { - Font::fontTypeName = lang.get("FONT_TYPENAME"); - } - if( lang.hasString("FONT_CHARSET")) { - // Example values: - // DEFAULT_CHARSET (English) = 1 - // GB2312_CHARSET (Chinese) = 134 - Shared::Platform::charSet = strToInt(lang.get("FONT_CHARSET")); - } - if( lang.hasString("FONT_MULTIBYTE")) { - Font::fontIsMultibyte = strToBool(lang.get("FONT_MULTIBYTE")); - } - - if( lang.hasString("FONT_RIGHTTOLEFT")) { - Font::fontIsRightToLeft = strToBool(lang.get("FONT_RIGHTTOLEFT")); - } - - if( lang.hasString("MEGAGLEST_FONT")) { - //setenv("MEGAGLEST_FONT","/usr/share/fonts/truetype/ttf-japanese-gothic.ttf",0); // Japanese -#if defined(WIN32) - string newEnvValue = "MEGAGLEST_FONT=" + lang.get("MEGAGLEST_FONT"); - _putenv(newEnvValue.c_str()); -#else - setenv("MEGAGLEST_FONT",lang.get("MEGAGLEST_FONT").c_str(),0); -#endif - } - -// if( lang.hasString("FONT_YOFFSET_FACTOR")) { -// FontMetrics::DEFAULT_Y_OFFSET_FACTOR = strToFloat(lang.get("FONT_YOFFSET_FACTOR")); -// } - -#if defined(WIN32) - // Win32 overrides for fonts (just in case they must be different) - - if( lang.hasString("FONT_BASE_SIZE_WINDOWS")) { - // 256 for English - // 30000 for Chinese - Font::baseSize = strToInt(lang.get("FONT_BASE_SIZE_WINDOWS")); - } - - if( lang.hasString("FONT_SCALE_SIZE_WINDOWS")) { - Font::scaleFontValue = strToFloat(lang.get("FONT_SCALE_SIZE_WINDOWS")); - } - if( lang.hasString("FONT_SCALE_CENTERH_FACTOR_WINDOWS")) { - Font::scaleFontValueCenterHFactor = strToFloat(lang.get("FONT_SCALE_CENTERH_FACTOR_WINDOWS")); - } - - if( lang.hasString("FONT_HEIGHT_TEXT_WINDOWS")) { - Font::langHeightText = config.getString("FONT_HEIGHT_TEXT_WINDOWS",Font::langHeightText.c_str()); - } - - if( lang.hasString("FONT_CHARCOUNT_WINDOWS")) { - // 256 for English - // 30000 for Chinese - Font::charCount = strToInt(lang.get("FONT_CHARCOUNT_WINDOWS")); - } - if( lang.hasString("FONT_TYPENAME_WINDOWS")) { - Font::fontTypeName = lang.get("FONT_TYPENAME_WINDOWS"); - } - if( lang.hasString("FONT_CHARSET_WINDOWS")) { - // Example values: - // DEFAULT_CHARSET (English) = 1 - // GB2312_CHARSET (Chinese) = 134 - Shared::Platform::charSet = strToInt(lang.get("FONT_CHARSET_WINDOWS")); - } - if( lang.hasString("FONT_MULTIBYTE_WINDOWS")) { - Font::fontIsMultibyte = strToBool(lang.get("FONT_MULTIBYTE_WINDOWS")); - } - if( lang.hasString("FONT_RIGHTTOLEFT_WINDOWS")) { - Font::fontIsRightToLeft = strToBool(lang.get("FONT_RIGHTTOLEFT_WINDOWS")); - } - - if( lang.hasString("MEGAGLEST_FONT_WINDOWS")) { - //setenv("MEGAGLEST_FONT","/usr/share/fonts/truetype/ttf-japanese-gothic.ttf",0); // Japanese - string newEnvValue = "MEGAGLEST_FONT=" + lang.get("MEGAGLEST_FONT_WINDOWS"); - _putenv(newEnvValue.c_str()); - } - -// if( lang.hasString("FONT_YOFFSET_FACTOR_WINDOWS")) { -// FontMetrics::DEFAULT_Y_OFFSET_FACTOR = strToFloat(lang.get("FONT_YOFFSET_FACTOR_WINDOWS")); -// } - - // end win32 -#endif - if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_FONT_BASESIZE]) == true) { int foundParamIndIndex = -1; hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_FONT_BASESIZE]) + string("="),&foundParamIndIndex); @@ -3415,6 +3421,7 @@ int glestMain(int argc, char** argv) { } program->loop(); + // Because OpenGL really doesn't do multi-threading well // if(difftime(time(NULL),lastTextureLoadEvent) >= 3) { // lastTextureLoadEvent = time(NULL); diff --git a/source/glest_game/main/main.h b/source/glest_game/main/main.h index 08129f1e..0fda4cfd 100644 --- a/source/glest_game/main/main.h +++ b/source/glest_game/main/main.h @@ -29,9 +29,14 @@ namespace Glest{ namespace Game{ /// Main program window // ===================================================== -class MainWindow: public WindowGl{ +class MainWindow: public WindowGl { private: Program* program; + PopupMenu popupMenu; + int cancelLanguageSelection; + + void showLanguages(); + void toggleLanguage(string language); public: MainWindow(Program *program); @@ -50,6 +55,8 @@ public: virtual void eventActivate(bool active); virtual void eventResize(SizeState sizeState); virtual void eventClose(); + + virtual void render(); }; }}//end namespace diff --git a/source/glest_game/main/program.cpp b/source/glest_game/main/program.cpp index ab6a1a0a..b9d85850 100644 --- a/source/glest_game/main/program.cpp +++ b/source/glest_game/main/program.cpp @@ -418,10 +418,18 @@ void Program::resize(SizeState sizeState){ // ==================== misc ==================== void Program::renderProgramMsgBox() { + Renderer &renderer= Renderer::getInstance(); if(msgBox.getEnabled()) { - Renderer &renderer= Renderer::getInstance(); renderer.renderMessageBox(&msgBox); } + + if(renderer.isMasterserverMode() == false && window) { + MainWindow *mainWindow = dynamic_cast(window); + if(mainWindow) { + mainWindow->render(); + } + } + } void Program::setState(ProgramState *programStateNew, bool cleanupOldState) @@ -631,6 +639,12 @@ void Program::init(WindowGl *window, bool initSound, bool toggleFullScreen){ if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } +void Program::reloadUI() { + if(programState) { + programState->reloadUI(); + } +} + void Program::setDisplaySettings(){ Config &config= Config::getInstance(); diff --git a/source/glest_game/main/program.h b/source/glest_game/main/program.h index 9d6bcf70..87e63845 100644 --- a/source/glest_game/main/program.h +++ b/source/glest_game/main/program.h @@ -98,6 +98,8 @@ public: virtual void setForceMouseRender(bool value) { forceMouseRender=value;} virtual void consoleAddLine(string line) { }; + virtual void reloadUI() {}; + protected: virtual void incrementFps(); }; @@ -202,6 +204,7 @@ public: virtual void consoleAddLine(string line); virtual SimpleTaskThread * getSoundThreadManager(bool takeOwnership); + virtual void reloadUI(); private: diff --git a/source/glest_game/menu/main_menu.cpp b/source/glest_game/menu/main_menu.cpp index fa9ba188..bffce914 100644 --- a/source/glest_game/menu/main_menu.cpp +++ b/source/glest_game/menu/main_menu.cpp @@ -62,6 +62,12 @@ MainMenu::MainMenu(Program *program): if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); } +void MainMenu::reloadUI() { + if(state) { + state->reloadUI(); + } +} + MainMenu::~MainMenu() { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/glest_game/menu/main_menu.h b/source/glest_game/menu/main_menu.h index 632713fe..dfed7e27 100644 --- a/source/glest_game/menu/main_menu.h +++ b/source/glest_game/menu/main_menu.h @@ -88,7 +88,7 @@ public: int getMouseY() const {return mouseY;} int getMouse2dAnim() const {return mouse2dAnim;} virtual void consoleAddLine(string line); - + virtual void reloadUI(); }; @@ -122,6 +122,7 @@ public: virtual bool isInSpecialKeyCaptureEvent() { return false; } virtual void consoleAddLine(string line); + virtual void reloadUI() {}; }; }}//end namespace diff --git a/source/glest_game/menu/menu_state_about.cpp b/source/glest_game/menu/menu_state_about.cpp index a39058a3..01cee5b1 100644 --- a/source/glest_game/menu/menu_state_about.cpp +++ b/source/glest_game/menu/menu_state_about.cpp @@ -96,6 +96,41 @@ MenuStateAbout::MenuStateAbout(Program *program, MainMenu *mainMenu) : GraphicComponent::applyAllCustomProperties(containerName); } +void MenuStateAbout::reloadUI() { + Lang &lang= Lang::getInstance(); + + string additionalCredits= loadAdditionalCredits(); + + buttonReturn.setText(lang.get("Return")); + labelAdditionalCredits.setText(additionalCredits); + + if(additionalCredits == "") { + for(int i= 0; i < aboutStringCount1; ++i){ + labelAbout1[i].setText(getAboutString1(i)); + } + + for(int i= 0; i < aboutStringCount2; ++i){ + labelAbout2[i].setText(getAboutString2(i)); + } + } + else { + for(int i= 0; i < aboutStringCount1; ++i){ + labelAbout1[i].setText(getAboutString1(i)); + } + + for(int i= 0; i < aboutStringCount2; ++i){ + labelAbout2[i].setText(getAboutString2(i)); + } + } + + for(int i= 0; i < teammateCount; ++i){ + labelTeammateName[i].setText(getTeammateName(i)); + labelTeammateRole[i].setText(getTeammateRole(i)); + } + + GraphicComponent::reloadFontsForRegisterGraphicComponents(containerName); +} + string MenuStateAbout::loadAdditionalCredits(){ string data_path= getGameReadWritePath(GameConstants::path_data_CacheLookupKey); if(data_path != ""){ diff --git a/source/glest_game/menu/menu_state_about.h b/source/glest_game/menu/menu_state_about.h index 299570f4..97700cc8 100644 --- a/source/glest_game/menu/menu_state_about.h +++ b/source/glest_game/menu/menu_state_about.h @@ -44,6 +44,8 @@ public: void mouseMove(int x, int y, const MouseState *mouseState); void render(); virtual void keyDown(SDL_KeyboardEvent key); + + virtual void reloadUI(); }; }}//end namespace diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index bb5721b7..1b21a88d 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -524,6 +524,127 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); } +void MenuStateConnectedGame::reloadUI() { + Config &config = Config::getInstance(); + Lang &lang= Lang::getInstance(); + + mainMessageBox.init(lang.get("Ok")); + ftpMessageBox.init(lang.get("Yes"),lang.get("No")); + + labelInfo.setFont(CoreData::getInstance().getMenuFontBig()); + labelInfo.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + + labelDataSynchInfo.setFont(CoreData::getInstance().getMenuFontBig()); + labelDataSynchInfo.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + + buttonCancelDownloads.setText(lang.get("CancelDownloads")); + + labelFogOfWar.setText(lang.get("FogOfWar")); + + vector fowItems; + fowItems.push_back(lang.get("Enabled")); + fowItems.push_back(lang.get("Explored")); + fowItems.push_back(lang.get("Disabled")); + listBoxFogOfWar.setItems(fowItems); + + labelAllowObservers.setText(lang.get("AllowObservers")); + + vector observerItems; + observerItems.push_back(lang.get("No")); + observerItems.push_back(lang.get("Yes")); + listBoxAllowObservers.setItems(observerItems); + + vector observerModeItems; + observerModeItems.push_back(lang.get("Yes")); + observerModeItems.push_back(lang.get("No")); + listBoxEnableObserverMode.setItems(observerModeItems); + + labelEnableObserverMode.setText(lang.get("EnableObserverMode")); + + labelEnableSwitchTeamMode.setText(lang.get("EnableSwitchTeamMode")); + + vector switchteamModeItems; + switchteamModeItems.push_back(lang.get("Yes")); + switchteamModeItems.push_back(lang.get("No")); + listBoxEnableSwitchTeamMode.setItems(switchteamModeItems); + + labelAISwitchTeamAcceptPercent.setText(lang.get("AISwitchTeamAcceptPercent")); + + vector aiswitchteamModeItems; + for(int i = 0; i <= 100; i = i + 10) { + aiswitchteamModeItems.push_back(intToStr(i)); + } + listBoxAISwitchTeamAcceptPercent.setItems(aiswitchteamModeItems); + + labelPathFinderType.setText(lang.get("PathFinderType")); + + vector pathfinderItems; + pathfinderItems.push_back(lang.get("PathFinderTypeRegular")); + if(config.getBool("EnableRoutePlannerPathfinder","false") == true) { + pathfinderItems.push_back(lang.get("PathFinderTypeRoutePlanner")); + } + listBoxPathFinderType.setItems(pathfinderItems); + + labelMap.setText(lang.get("Map")); + + labelTileset.setText(lang.get("Tileset")); + + labelTechTree.setText(lang.get("TechTree")); + + vector playerstatusItems; + playerstatusItems.push_back(lang.get("PlayerStatusSetup")); + playerstatusItems.push_back(lang.get("PlayerStatusBeRightBack")); + playerstatusItems.push_back(lang.get("PlayerStatusReady")); + listBoxPlayerStatus.setItems(playerstatusItems); + + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + + labelControl.setText(lang.get("Control")); + + labelFaction.setText(lang.get("Faction")); + + labelTeam.setText(lang.get("Team")); + + labelControl.setFont(CoreData::getInstance().getMenuFontBig()); + labelControl.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + labelFaction.setFont(CoreData::getInstance().getMenuFontBig()); + labelFaction.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + labelTeam.setFont(CoreData::getInstance().getMenuFontBig()); + labelTeam.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + + //texts + buttonDisconnect.setText(lang.get("Return")); + + vector controlItems; + controlItems.push_back(lang.get("Closed")); + controlItems.push_back(lang.get("CpuEasy")); + controlItems.push_back(lang.get("Cpu")); + controlItems.push_back(lang.get("CpuUltra")); + controlItems.push_back(lang.get("CpuMega")); + controlItems.push_back(lang.get("Network")); + controlItems.push_back(lang.get("NetworkUnassigned")); + controlItems.push_back(lang.get("Human")); + + if(config.getBool("EnableNetworkCpu","false") == true) { + controlItems.push_back(lang.get("NetworkCpuEasy")); + controlItems.push_back(lang.get("NetworkCpu")); + controlItems.push_back(lang.get("NetworkCpuUltra")); + controlItems.push_back(lang.get("NetworkCpuMega")); + } + + for(int i=0; i < GameConstants::maxPlayers; ++i) { + labelPlayers[i].setText(lang.get("Player") + " " + intToStr(i)); + listBoxControls[i].setItems(controlItems); + } + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + + buttonPlayNow.setText(lang.get("PlayNow")); + + chatManager.init(&console, -1,true); + + GraphicComponent::reloadFontsForRegisterGraphicComponents(containerName); +} + MenuStateConnectedGame::~MenuStateConnectedGame() { if(ftpClientThread != NULL) { ftpClientThread->setCallBackObject(NULL); diff --git a/source/glest_game/menu/menu_state_connected_game.h b/source/glest_game/menu/menu_state_connected_game.h index 09816efa..56d4569a 100644 --- a/source/glest_game/menu/menu_state_connected_game.h +++ b/source/glest_game/menu/menu_state_connected_game.h @@ -200,6 +200,8 @@ public: virtual bool isInSpecialKeyCaptureEvent(); + virtual void reloadUI(); + private: bool hasNetworkGameSettings(); diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 3b9b40af..8c6f3cff 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -632,6 +632,178 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); } +void MenuStateCustomGame::reloadUI() { + Lang &lang= Lang::getInstance(); + Config &config = Config::getInstance(); + mainMessageBox.init(lang.get("Ok")); + + vector teamItems, controlItems, results , rMultiplier; + + string ipText = "none"; + std::vector ipList = Socket::getLocalIPAddressList(); + if(ipList.empty() == false) { + ipText = ""; + for(int idx = 0; idx < ipList.size(); idx++) { + string ip = ipList[idx]; + if(ipText != "") { + ipText += ", "; + } + ipText += ip; + } + } + string externalPort=config.getString("MasterServerExternalPort", "61357"); + string serverPort=config.getString("ServerPort", "61357"); + labelLocalIP.setText(lang.get("LanIP") + ipText + " ( "+serverPort+" / "+externalPort+" )"); + + labelMap.setText(lang.get("Map")+":"); + + labelMapFilter.setText(lang.get("MapFilter")+":"); + + labelTileset.setText(lang.get("Tileset")); + + labelTechTree.setText(lang.get("TechTree")); + + labelFogOfWar.setText(lang.get("FogOfWar")); + + std::vector listBoxData; + listBoxData.push_back(lang.get("Enabled")); + listBoxData.push_back(lang.get("Explored")); + listBoxData.push_back(lang.get("Disabled")); + listBoxFogOfWar.setItems(listBoxData); + + // Allow Observers + labelAllowObservers.setText(lang.get("AllowObservers")); + + listBoxData.clear(); + listBoxData.push_back(lang.get("No")); + listBoxData.push_back(lang.get("Yes")); + listBoxAllowObservers.setItems(listBoxData); + + // View Map At End Of Game + listBoxData.clear(); + listBoxData.push_back(lang.get("Yes")); + listBoxData.push_back(lang.get("No")); + listBoxEnableObserverMode.setItems(listBoxData); + + // Allow Switch Team Mode + labelEnableSwitchTeamMode.setText(lang.get("EnableSwitchTeamMode")); + + listBoxData.clear(); + listBoxData.push_back(lang.get("Yes")); + listBoxData.push_back(lang.get("No")); + listBoxEnableSwitchTeamMode.setItems(listBoxData); + + labelAISwitchTeamAcceptPercent.setText(lang.get("AISwitchTeamAcceptPercent")); + + labelPathFinderType.setText(lang.get("PathFinderType")); + + listBoxData.clear(); + listBoxData.push_back(lang.get("PathFinderTypeRegular")); + if(config.getBool("EnableRoutePlannerPathfinder","false") == true) { + listBoxData.push_back(lang.get("PathFinderTypeRoutePlanner")); + } + listBoxPathFinderType.setItems(listBoxData); + + // Advanced Options + labelAdvanced.setText(lang.get("AdvancedGameOptions")); + + listBoxData.clear(); + listBoxData.push_back(lang.get("No")); + listBoxData.push_back(lang.get("Yes")); + listBoxAdvanced.setItems(listBoxData); + + labelPublishServer.setText(lang.get("PublishServer")); + + listBoxData.clear(); + listBoxData.push_back(lang.get("Yes")); + listBoxData.push_back(lang.get("No")); + listBoxPublishServer.setItems(listBoxData); + + labelGameNameLabel.setText(lang.get("MGGameTitle")+":"); + + labelGameName.setFont(CoreData::getInstance().getMenuFontBig()); + labelGameName.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + if(this->masterserverMode == false) { + labelGameName.setText(defaultPlayerName+"'s game"); + } + else { + labelGameName.setText("headless ("+defaultPlayerName+")"); + } + + labelNetworkPauseGameForLaggedClients.setText(lang.get("NetworkPauseGameForLaggedClients")); + + listBoxData.clear(); + listBoxData.push_back(lang.get("No")); + listBoxData.push_back(lang.get("Yes")); + listBoxNetworkPauseGameForLaggedClients.setItems(listBoxData); + + for(int i=0; i < GameConstants::maxPlayers; ++i) { + buttonBlockPlayers[i].setText(lang.get("BlockPlayer")); + } + + labelControl.setText(lang.get("Control")); + + labelFaction.setText(lang.get("Faction")); + + labelTeam.setText(lang.get("Team")); + + labelControl.setFont(CoreData::getInstance().getMenuFontBig()); + labelControl.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + labelRMultiplier.setFont(CoreData::getInstance().getMenuFontBig()); + labelRMultiplier.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + labelFaction.setFont(CoreData::getInstance().getMenuFontBig()); + labelFaction.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + labelTeam.setFont(CoreData::getInstance().getMenuFontBig()); + labelTeam.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + + //texts + buttonClearBlockedPlayers.setText(lang.get("BlockPlayerClear")); + buttonReturn.setText(lang.get("Return")); + buttonPlayNow.setText(lang.get("PlayNow")); + buttonRestoreLastSettings.setText(lang.get("ReloadLastGameSettings")); + + controlItems.push_back(lang.get("Closed")); + controlItems.push_back(lang.get("CpuEasy")); + controlItems.push_back(lang.get("Cpu")); + controlItems.push_back(lang.get("CpuUltra")); + controlItems.push_back(lang.get("CpuMega")); + controlItems.push_back(lang.get("Network")); + controlItems.push_back(lang.get("NetworkUnassigned")); + controlItems.push_back(lang.get("Human")); + + if(config.getBool("EnableNetworkCpu","false") == true) { + controlItems.push_back(lang.get("NetworkCpuEasy")); + controlItems.push_back(lang.get("NetworkCpu")); + controlItems.push_back(lang.get("NetworkCpuUltra")); + controlItems.push_back(lang.get("NetworkCpuMega")); + } + + for(int i=0; i < GameConstants::maxPlayers; ++i) { + labelPlayers[i].setText(lang.get("Player")+" "+intToStr(i)); + + listBoxControls[i].setItems(controlItems); + } + + labelEnableObserverMode.setText(lang.get("EnableObserverMode")); + + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + + vector playerStatuses; + playerStatuses.push_back(lang.get("PlayerStatusSetup")); + playerStatuses.push_back(lang.get("PlayerStatusBeRightBack")); + playerStatuses.push_back(lang.get("PlayerStatusReady")); + listBoxPlayerStatus.setItems(playerStatuses); + + // write hint to console: + Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); + + console.addLine(lang.get("To switch off music press") + " - \"" + configKeys.getString("ToggleMusic") + "\""); + + chatManager.init(&console, -1,true); + + GraphicComponent::reloadFontsForRegisterGraphicComponents(containerName); +} + void MenuStateCustomGame::cleanup() { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); if(publishToMasterserverThread != NULL) { diff --git a/source/glest_game/menu/menu_state_custom_game.h b/source/glest_game/menu/menu_state_custom_game.h index 50252c52..70b21f2d 100644 --- a/source/glest_game/menu/menu_state_custom_game.h +++ b/source/glest_game/menu/menu_state_custom_game.h @@ -231,6 +231,7 @@ private: ServerInterface *& serverInterface, int startIndex, int endIndex, bool onlyNetworkUnassigned); + void reloadUI(); }; }}//end namespace diff --git a/source/glest_game/menu/menu_state_graphic_info.cpp b/source/glest_game/menu/menu_state_graphic_info.cpp index 609ab3e1..b9a4442e 100644 --- a/source/glest_game/menu/menu_state_graphic_info.cpp +++ b/source/glest_game/menu/menu_state_graphic_info.cpp @@ -28,10 +28,14 @@ namespace Glest{ namespace Game{ MenuStateGraphicInfo::MenuStateGraphicInfo(Program *program, MainMenu *mainMenu): MenuState(program, mainMenu, "info") { + Lang &lang= Lang::getInstance(); + containerName = "GraphicInfo"; buttonReturn.registerGraphicComponent(containerName,"buttonReturn"); buttonReturn.init(100, 540, 125); + buttonReturn.setText(lang.get("Return")); + labelInfo.registerGraphicComponent(containerName,"labelInfo"); labelInfo.init(100, 700); @@ -73,6 +77,45 @@ MenuStateGraphicInfo::MenuStateGraphicInfo(Program *program, MainMenu *mainMenu) labelInternalInfo.setText(strInternalInfo); } +void MenuStateGraphicInfo::reloadUI() { + Lang &lang= Lang::getInstance(); + + buttonReturn.setText(lang.get("Return")); + + labelMoreInfo.setFont(CoreData::getInstance().getDisplayFontSmall()); + labelMoreInfo.setFont3D(CoreData::getInstance().getDisplayFontSmall3D()); + + labelInternalInfo.setFont(CoreData::getInstance().getDisplayFontSmall()); + labelInternalInfo.setFont3D(CoreData::getInstance().getDisplayFontSmall3D()); + + Renderer &renderer= Renderer::getInstance(); + + string glInfo= renderer.getGlInfo(); + string glMoreInfo= renderer.getGlMoreInfo(); + labelInfo.setText(glInfo); + labelMoreInfo.setText(glMoreInfo); + + string strInternalInfo = ""; + strInternalInfo += "VBOSupported: " + boolToStr(getVBOSupported()); + if(getenv("MEGAGLEST_FONT") != NULL) { + char *tryFont = getenv("MEGAGLEST_FONT"); + strInternalInfo += "\nMEGAGLEST_FONT: " + string(tryFont); + } + strInternalInfo += "\nforceLegacyFonts: " + boolToStr(Font::forceLegacyFonts); + strInternalInfo += "\nrenderText3DEnabled: " + boolToStr(Renderer::renderText3DEnabled); + strInternalInfo += "\nuseTextureCompression: " + boolToStr(Texture::useTextureCompression); + strInternalInfo += "\nfontIsRightToLeft: " + boolToStr(Font::fontIsRightToLeft); + strInternalInfo += "\nscaleFontValue: " + boolToStr(Font::scaleFontValue); + strInternalInfo += "\nscaleFontValueCenterHFactor: " + boolToStr(Font::scaleFontValueCenterHFactor); + strInternalInfo += "\nlangHeightText: " + Font::langHeightText; + strInternalInfo += "\nAllowAltEnterFullscreenToggle: " + boolToStr(Window::getAllowAltEnterFullscreenToggle()); + strInternalInfo += "\nTryVSynch: " + boolToStr(Window::getTryVSynch()); + strInternalInfo += "\nVERBOSE_MODE_ENABLED: " + boolToStr(SystemFlags::VERBOSE_MODE_ENABLED); + labelInternalInfo.setText(strInternalInfo); + + GraphicComponent::reloadFontsForRegisterGraphicComponents(containerName); +} + void MenuStateGraphicInfo::mouseClick(int x, int y, MouseButton mouseButton){ CoreData &coreData= CoreData::getInstance(); SoundRenderer &soundRenderer= SoundRenderer::getInstance(); @@ -92,8 +135,6 @@ void MenuStateGraphicInfo::render(){ Renderer &renderer= Renderer::getInstance(); Lang &lang= Lang::getInstance(); - buttonReturn.setText(lang.get("Return")); - renderer.renderButton(&buttonReturn); renderer.renderLabel(&labelInfo); renderer.renderLabel(&labelInternalInfo); diff --git a/source/glest_game/menu/menu_state_graphic_info.h b/source/glest_game/menu/menu_state_graphic_info.h index 3fdae022..71ec9cb4 100644 --- a/source/glest_game/menu/menu_state_graphic_info.h +++ b/source/glest_game/menu/menu_state_graphic_info.h @@ -41,6 +41,8 @@ public: void mouseMove(int x, int y, const MouseState *mouseState); void render(); virtual void keyDown(SDL_KeyboardEvent key); + + virtual void reloadUI(); }; }}//end namespace diff --git a/source/glest_game/menu/menu_state_join_game.cpp b/source/glest_game/menu/menu_state_join_game.cpp index bf5c5fdb..f7fe699a 100644 --- a/source/glest_game/menu/menu_state_join_game.cpp +++ b/source/glest_game/menu/menu_state_join_game.cpp @@ -155,6 +155,40 @@ MenuStateJoinGame::MenuStateJoinGame(Program *program, MainMenu *mainMenu, bool chatManager.init(&console, -1); } +void MenuStateJoinGame::reloadUI() { + Lang &lang= Lang::getInstance(); + + Config &config= Config::getInstance(); + + buttonReturn.setText(lang.get("Return")); + buttonConnect.setText(lang.get("Connect")); + buttonAutoFindServers.setText(lang.get("FindLANGames")); + labelServerType.setText(lang.get("ServerType") + ":"); + + std::vector listboxData; + listboxData.push_back(lang.get("ServerTypeNew")); + listboxData.push_back(lang.get("ServerTypePrevious")); + listboxData.push_back(lang.get("ServerTypeFound")); + listBoxServerType.setItems(listboxData); + + labelServer.setText(lang.get("Server") + ": "); + + labelServerPortLabel.setText(lang.get("ServerPort")); + + string port=intToStr(config.getInt("ServerPort")); + if(port != "61357") { + port = port +" ("+lang.get("NonStandardPort")+")"; + } + else { + port = port +" ("+lang.get("StandardPort")+")"; + } + labelServerPort.setText(port); + + chatManager.init(&console, -1); + + GraphicComponent::reloadFontsForRegisterGraphicComponents(containerName); +} + MenuStateJoinGame::~MenuStateJoinGame() { abortAutoFind = true; } diff --git a/source/glest_game/menu/menu_state_join_game.h b/source/glest_game/menu/menu_state_join_game.h index 032385c7..a859612c 100644 --- a/source/glest_game/menu/menu_state_join_game.h +++ b/source/glest_game/menu/menu_state_join_game.h @@ -76,6 +76,8 @@ public: virtual bool isInSpecialKeyCaptureEvent() { return chatManager.getEditEnabled(); } + void reloadUI(); + private: void connectToServer(); virtual void DiscoveredServers(std::vector serverList); diff --git a/source/glest_game/menu/menu_state_keysetup.cpp b/source/glest_game/menu/menu_state_keysetup.cpp index a9a26939..d74f703e 100644 --- a/source/glest_game/menu/menu_state_keysetup.cpp +++ b/source/glest_game/menu/menu_state_keysetup.cpp @@ -159,6 +159,32 @@ MenuStateKeysetup::MenuStateKeysetup(Program *program, MainMenu *mainMenu, } } +void MenuStateKeysetup::reloadUI() { + Lang &lang= Lang::getInstance(); + + labelTitle.setFont(CoreData::getInstance().getMenuFontBig()); + labelTitle.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + labelTitle.setText(lang.get("Keyboardsetup")); + + labelTestTitle.setFont(CoreData::getInstance().getMenuFontBig()); + labelTestTitle.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + labelTestTitle.setText(lang.get("KeyboardsetupTest")); + + labelTestValue.setFont(CoreData::getInstance().getMenuFontBig()); + labelTestValue.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + labelTestValue.setText(""); + + // mainMassegeBox + mainMessageBox.init(lang.get("Ok")); + + buttonOk.setText(lang.get("Ok")); + + buttonDefaults.setText(lang.get("Defaults")); + + buttonReturn.setText(lang.get("Abort")); + + GraphicComponent::reloadFontsForRegisterGraphicComponents(containerName); +} void MenuStateKeysetup::cleanup() { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/glest_game/menu/menu_state_keysetup.h b/source/glest_game/menu/menu_state_keysetup.h index e94f3936..9246b903 100644 --- a/source/glest_game/menu/menu_state_keysetup.h +++ b/source/glest_game/menu/menu_state_keysetup.h @@ -76,6 +76,8 @@ public: //static void setDisplayMessageFunction(DisplayMessageFunction pDisplayMessage) { pCB_DisplayMessage = pDisplayMessage; } + void reloadUI(); + private: void showMessageBox(const string &text, const string &header, bool toggle); void clearUserButtons(); diff --git a/source/glest_game/menu/menu_state_masterserver.cpp b/source/glest_game/menu/menu_state_masterserver.cpp index 0712e82e..14299945 100644 --- a/source/glest_game/menu/menu_state_masterserver.cpp +++ b/source/glest_game/menu/menu_state_masterserver.cpp @@ -270,9 +270,39 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen updateFromMasterserverThread->setUniqueID(__FILE__); updateFromMasterserverThread->start(); - ircArgs.push_back(IRC_SERVER); - ircArgs.push_back(szIRCNick); - ircArgs.push_back(IRC_CHANNEL); + if(Config::getInstance().getString("IRCServer","") != "") { + ircArgs.push_back(Config::getInstance().getString("IRCServer")); + } + else { + ircArgs.push_back(IRC_SERVER); + } + + if(Config::getInstance().getString("IRCNick","") != "") { + ircArgs.push_back(Config::getInstance().getString("IRCNick")); + } + else { + ircArgs.push_back(szIRCNick); + } + + if(Config::getInstance().getString("IRCChannel","") != "") { + ircArgs.push_back(Config::getInstance().getString("IRCChannel")); + } + else { + ircArgs.push_back(IRC_CHANNEL); + } + + if(Config::getInstance().getString("IRCUsername","") != "") { + ircArgs.push_back(Config::getInstance().getString("IRCUsername")); + } + else { + ircArgs.push_back(szIRCNick); + } + if(Config::getInstance().getString("IRCPassword","") != "") { + ircArgs.push_back("identify " + Config::getInstance().getString("IRCPassword")); + } + else { + ircArgs.push_back(""); + } MutexSafeWrapper safeMutexIRCPtr(&mutexIRCClient,string(__FILE__) + "_" + intToStr(__LINE__)); ircClient = new IRCThread(ircArgs,this); @@ -282,6 +312,63 @@ MenuStateMasterserver::MenuStateMasterserver(Program *program, MainMenu *mainMen if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } +void MenuStateMasterserver::reloadUI() { + Lang &lang= Lang::getInstance(); + + consoleIRC.setFont(CoreData::getInstance().getMenuFontNormal()); + consoleIRC.setFont3D(CoreData::getInstance().getMenuFontNormal3D()); + + mainMessageBox.init(lang.get("Ok")); + + announcementLabel.setFont(CoreData::getInstance().getMenuFontBig()); + announcementLabel.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + + versionInfoLabel.setFont(CoreData::getInstance().getMenuFontBig()); + versionInfoLabel.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + + labelTitle.setFont(CoreData::getInstance().getMenuFontBig()); + labelTitle.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + labelTitle.setText(lang.get("AvailableServers")); + + if(Config::getInstance().getString("Masterserver","") == "") { + labelTitle.setText("*** " + lang.get("AvailableServers")); + } + + glestVersionLabel.setText(lang.get("MGVersion")); + + platformLabel.setText(lang.get("MGPlatform")); + + serverTitleLabel.setText(lang.get("MGGameTitle")); + + countryLabel.setText(lang.get("MGGameCountry")); + + techLabel.setText(lang.get("TechTree")); + + mapLabel.setText(lang.get("Map")); + + activeSlotsLabel.setText(lang.get("MGGameSlots")); + + externalConnectPort.setText(lang.get("Port")); + + statusLabel.setText(lang.get("MGGameStatus")); + + selectButton.setText(lang.get("MGJoinGameSlots")); + + // Titles for current games - END + + buttonRefresh.setText(lang.get("RefreshList")); + buttonReturn.setText(lang.get("Return")); + buttonCreateGame.setText(lang.get("CustomGame")); + labelAutoRefresh.setText(lang.get("AutoRefreshRate")); + + ircOnlinePeopleLabel.setText(lang.get("IRCPeopleOnline")); + + chatManager.setFont(CoreData::getInstance().getMenuFontNormal()); + chatManager.setFont3D(CoreData::getInstance().getMenuFontNormal3D()); + + GraphicComponent::reloadFontsForRegisterGraphicComponents(containerName); +} + void MenuStateMasterserver::setConsolePos(int yPos){ consoleIRC.setYPos(yPos); lines[2].setY(consoleIRC.getYPos()-10); diff --git a/source/glest_game/menu/menu_state_masterserver.h b/source/glest_game/menu/menu_state_masterserver.h index 5280b23f..f5ade8f1 100644 --- a/source/glest_game/menu/menu_state_masterserver.h +++ b/source/glest_game/menu/menu_state_masterserver.h @@ -128,6 +128,8 @@ public: static void setDisplayMessageFunction(DisplayMessageFunction pDisplayMessage) { pCB_DisplayMessage = pDisplayMessage; } + virtual void reloadUI(); + private: void showMessageBox(const string &text, const string &header, bool toggle); bool connectToServer(string ipString, int port); diff --git a/source/glest_game/menu/menu_state_mods.cpp b/source/glest_game/menu/menu_state_mods.cpp index 3c0be7d8..ec9afdbd 100644 --- a/source/glest_game/menu/menu_state_mods.cpp +++ b/source/glest_game/menu/menu_state_mods.cpp @@ -304,6 +304,60 @@ MenuStateMods::MenuStateMods(Program *program, MainMenu *mainMenu) : if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); } +void MenuStateMods::reloadUI() { + Lang &lang= Lang::getInstance(); + + keyTechScrollBarTitle1.setText(lang.get("TechTitle1")); + keyTechScrollBarTitle1.setFont(CoreData::getInstance().getMenuFontBig()); + keyTechScrollBarTitle1.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + keyTechScrollBarTitle2.setText(lang.get("TechTitle2")); + keyTechScrollBarTitle2.setFont(CoreData::getInstance().getMenuFontNormal()); + keyTechScrollBarTitle2.setFont3D(CoreData::getInstance().getMenuFontNormal3D()); + + keyMapScrollBarTitle1.setText(lang.get("MapTitle1")); + keyMapScrollBarTitle1.setFont(CoreData::getInstance().getMenuFontBig()); + keyMapScrollBarTitle1.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + keyMapScrollBarTitle2.setText(lang.get("MapTitle2")); + keyMapScrollBarTitle2.setFont(CoreData::getInstance().getMenuFontNormal()); + keyMapScrollBarTitle2.setFont3D(CoreData::getInstance().getMenuFontNormal3D()); + + keyTilesetScrollBarTitle1.setText(lang.get("TilesetTitle1")); + keyTilesetScrollBarTitle1.setFont(CoreData::getInstance().getMenuFontBig()); + keyTilesetScrollBarTitle1.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + + keyScenarioScrollBarTitle1.setText(lang.get("ScenarioTitle1")); + keyScenarioScrollBarTitle1.setFont(CoreData::getInstance().getMenuFontBig()); + keyScenarioScrollBarTitle1.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + + mainMessageBox.init(lang.get("Yes"),lang.get("No")); + + modDescrLabel.setText("description is empty"); + + buttonReturn.setText(lang.get("Return")); + + buttonInstalled.setText(lang.get("ModInstalled")); + + buttonAvailable.setText(lang.get("ModAvailable")); + + buttonOnlyLocal.setText(lang.get("ModOnlyLocal")); + + buttonConflict.setText(lang.get("ModHasConflict")); + + buttonInstallTech.setText(lang.get("Install")); + buttonRemoveTech.setText(lang.get("Remove")); + + buttonInstallTileset.setText(lang.get("Install")); + buttonRemoveTileset.setText(lang.get("Remove")); + + buttonInstallMap.setText(lang.get("Install")); + buttonRemoveMap.setText(lang.get("Remove")); + + buttonInstallScenario.setText(lang.get("Install")); + buttonRemoveScenario.setText(lang.get("Remove")); + + GraphicComponent::reloadFontsForRegisterGraphicComponents(containerName); +} + void MenuStateMods::simpleTask(BaseThread *callingThread) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/glest_game/menu/menu_state_mods.h b/source/glest_game/menu/menu_state_mods.h index 1af00227..fec542fc 100644 --- a/source/glest_game/menu/menu_state_mods.h +++ b/source/glest_game/menu/menu_state_mods.h @@ -204,6 +204,8 @@ public: virtual void simpleTask(BaseThread *callingThread); + virtual void reloadUI(); + private: void cleanUp(); diff --git a/source/glest_game/menu/menu_state_new_game.cpp b/source/glest_game/menu/menu_state_new_game.cpp index 8bf49ce7..b99e9ce3 100644 --- a/source/glest_game/menu/menu_state_new_game.cpp +++ b/source/glest_game/menu/menu_state_new_game.cpp @@ -72,6 +72,19 @@ MenuStateNewGame::MenuStateNewGame(Program *program, MainMenu *mainMenu): NetworkManager::getInstance().end(); } +void MenuStateNewGame::reloadUI() { + Lang &lang= Lang::getInstance(); + + buttonCustomGame.setText(lang.get("CustomGame")); + buttonScenario.setText(lang.get("Scenario")); + buttonJoinGame.setText(lang.get("JoinGame")); + buttonMasterserverGame.setText(lang.get("JoinInternetGame")); + buttonTutorial.setText(lang.get("Tutorial")); + buttonReturn.setText(lang.get("Return")); + + GraphicComponent::reloadFontsForRegisterGraphicComponents(containerName); +} + void MenuStateNewGame::mouseClick(int x, int y, MouseButton mouseButton){ CoreData &coreData= CoreData::getInstance(); diff --git a/source/glest_game/menu/menu_state_new_game.h b/source/glest_game/menu/menu_state_new_game.h index 8405e703..5b88f3e1 100644 --- a/source/glest_game/menu/menu_state_new_game.h +++ b/source/glest_game/menu/menu_state_new_game.h @@ -38,6 +38,8 @@ public: void update(); void render(); virtual void keyDown(SDL_KeyboardEvent key); + + void reloadUI(); }; diff --git a/source/glest_game/menu/menu_state_options.cpp b/source/glest_game/menu/menu_state_options.cpp index a8b6e8e6..bdeb450f 100644 --- a/source/glest_game/menu/menu_state_options.cpp +++ b/source/glest_game/menu/menu_state_options.cpp @@ -508,6 +508,132 @@ MenuStateOptions::MenuStateOptions(Program *program, MainMenu *mainMenu): GraphicComponent::applyAllCustomProperties(containerName); } +void MenuStateOptions::reloadUI() { + Lang &lang= Lang::getInstance(); + + mainMessageBox.init(lang.get("Ok")); + + labelAudioSection.setFont(CoreData::getInstance().getMenuFontVeryBig()); + labelAudioSection.setFont3D(CoreData::getInstance().getMenuFontVeryBig3D()); + labelAudioSection.setText(lang.get("Audio")); + + labelSoundFactory.setText(lang.get("SoundAndMusic")); + + std::vector listboxData; + listboxData.push_back("None"); + listboxData.push_back("OpenAL"); +#ifdef WIN32 + listboxData.push_back("DirectSound8"); +#endif + + listBoxSoundFactory.setItems(listboxData); + + labelVolumeFx.setText(lang.get("FxVolume")); + + labelVolumeAmbient.setText(lang.get("AmbientVolume")); + labelVolumeMusic.setText(lang.get("MusicVolume")); + + labelVideoSection.setFont(CoreData::getInstance().getMenuFontVeryBig()); + labelVideoSection.setFont3D(CoreData::getInstance().getMenuFontVeryBig3D()); + labelVideoSection.setText(lang.get("Video")); + + labelScreenModes.setText(lang.get("Resolution")); + + labelFullscreenWindowed.setText(lang.get("Windowed")); + labelFilter.setText(lang.get("Filter")); + + listboxData.clear(); + listboxData.push_back("Bilinear"); + listboxData.push_back("Trilinear"); + listBoxFilter.setItems(listboxData); + + labelShadows.setText(lang.get("Shadows")); + + listboxData.clear(); + for(int i= 0; i(i)))); + } + listBoxShadows.setItems(listboxData); + + labelTextures3D.setText(lang.get("Textures3D")); + + labelLights.setText(lang.get("MaxLights")); + + labelUnitParticles.setText(lang.get("ShowUnitParticles")); + + labelTilesetParticles.setText(lang.get("ShowTilesetParticles")); + + labelMapPreview.setText(lang.get("ShowMapPreview")); + + labelEnableTextureCompression.setText(lang.get("EnableTextureCompression")); + + labelVisibleHud.setText(lang.get("VisibleHUD")); + + labelRainEffect.setText(lang.get("RainEffect")); + + labelMiscSection.setFont(CoreData::getInstance().getMenuFontVeryBig()); + labelMiscSection.setFont3D(CoreData::getInstance().getMenuFontVeryBig3D()); + labelMiscSection.setText(lang.get("Misc")); + + labelLang.setText(lang.get("Language")); + + labelPlayerNameLabel.setText(lang.get("Playername")); + + labelPlayerName.setFont(CoreData::getInstance().getMenuFontBig()); + labelPlayerName.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + + labelFontSizeAdjustment.setText(lang.get("FontSizeAdjustment")); + + labelScreenShotType.setText(lang.get("ScreenShotFileType")); + + labelDisableScreenshotConsoleText.setText(lang.get("ScreenShotConsoleText")); + + labelMouseMoveScrollsWorld.setText(lang.get("MouseScrollsWorld")); + + labelNetworkSettings.setFont(CoreData::getInstance().getMenuFontVeryBig()); + labelNetworkSettings.setFont3D(CoreData::getInstance().getMenuFontVeryBig3D()); + labelNetworkSettings.setText(lang.get("Network")); + + labelServerPortLabel.setText(lang.get("ServerPort")); + Config &config= Config::getInstance(); + string port = intToStr(config.getInt("ServerPort")); + if(port != "61357") { + port = port +" ("+lang.get("NonStandardPort")+"!!)"; + } + else{ + port = port +" ("+lang.get("StandardPort")+")"; + } + + labelServerPort.setText(port); + + labelPublishServerExternalPort.setText(lang.get("PublishServerExternalPort")); + + labelEnableFTP.setText(lang.get("EnableFTP")); + + labelEnableFTPServer.setText(lang.get("EnableFTPServer")); + + labelFTPServerPortLabel.setText(lang.get("FTPServerPort")); + + labelFTPServerDataPortsLabel.setText(lang.get("FTPServerDataPort")); + + labelEnableFTPServerInternetTilesetXfer.setText(lang.get("EnableFTPServerInternetTilesetXfer")); + + labelEnableFTPServerInternetTechtreeXfer.setText(lang.get("EnableFTPServerInternetTechtreeXfer")); + + labelEnablePrivacy.setText(lang.get("PrivacyPlease")); + + buttonOk.setText(lang.get("Ok")); + buttonAbort.setText(lang.get("Abort")); + + buttonAutoConfig.setText(lang.get("AutoConfig")); + + buttonVideoInfo.setText(lang.get("VideoInfo")); + + buttonKeyboardSetup.setText(lang.get("Keyboardsetup")); + + GraphicComponent::reloadFontsForRegisterGraphicComponents(containerName); +} + void MenuStateOptions::showMessageBox(const string &text, const string &header, bool toggle){ if(!toggle){ mainMessageBox.setEnabled(false); diff --git a/source/glest_game/menu/menu_state_options.h b/source/glest_game/menu/menu_state_options.h index 82cefeda..cca35306 100644 --- a/source/glest_game/menu/menu_state_options.h +++ b/source/glest_game/menu/menu_state_options.h @@ -134,6 +134,9 @@ public: virtual void keyPress(SDL_KeyboardEvent c); virtual bool isInSpecialKeyCaptureEvent(); + virtual void reloadUI(); + + private: void saveConfig(); void setActiveInputLable(GraphicLabel* newLable); diff --git a/source/glest_game/menu/menu_state_root.cpp b/source/glest_game/menu/menu_state_root.cpp index 82b72b88..382eebc7 100644 --- a/source/glest_game/menu/menu_state_root.cpp +++ b/source/glest_game/menu/menu_state_root.cpp @@ -92,6 +92,26 @@ MenuStateRoot::MenuStateRoot(Program *program, MainMenu *mainMenu): GraphicComponent::applyAllCustomProperties(containerName); } +void MenuStateRoot::reloadUI() { + Lang &lang= Lang::getInstance(); + if(EndsWith(glestVersionString, "-dev") == false){ + labelVersion.setText(glestVersionString); + } + else { + labelVersion.setText(glestVersionString + " [" + getCompileDateTime() + ", " + getSVNRevisionString() + "]"); + } + + buttonNewGame.setText(lang.get("NewGame")); + buttonMods.setText(lang.get("Mods")); + buttonOptions.setText(lang.get("Options")); + buttonAbout.setText(lang.get("About")); + buttonExit.setText(lang.get("Exit")); + + mainMessageBox.init(lang.get("Yes"), lang.get("No")); + + GraphicComponent::reloadFontsForRegisterGraphicComponents(containerName); +} + void MenuStateRoot::mouseClick(int x, int y, MouseButton mouseButton){ CoreData &coreData= CoreData::getInstance(); diff --git a/source/glest_game/menu/menu_state_root.h b/source/glest_game/menu/menu_state_root.h index 9f2b4f6e..14140baa 100644 --- a/source/glest_game/menu/menu_state_root.h +++ b/source/glest_game/menu/menu_state_root.h @@ -48,6 +48,7 @@ public: void showMessageBox(const string &text, const string &header, bool toggle); virtual bool isMasterserverMode() const; + virtual void reloadUI(); }; diff --git a/source/glest_game/menu/menu_state_scenario.cpp b/source/glest_game/menu/menu_state_scenario.cpp index 8ede1b1d..8916807a 100644 --- a/source/glest_game/menu/menu_state_scenario.cpp +++ b/source/glest_game/menu/menu_state_scenario.cpp @@ -110,6 +110,21 @@ MenuStateScenario::MenuStateScenario(Program *program, MainMenu *mainMenu, const } } +void MenuStateScenario::reloadUI() { + Lang &lang= Lang::getInstance(); + + mainMessageBox.init(lang.get("Ok")); + labelInfo.setFont(CoreData::getInstance().getMenuFontNormal()); + labelInfo.setFont3D(CoreData::getInstance().getMenuFontNormal3D()); + + buttonReturn.setText(lang.get("Return")); + buttonPlayNow.setText(lang.get("PlayNow")); + + labelScenario.setText(lang.get("Scenario")); + + GraphicComponent::reloadFontsForRegisterGraphicComponents(containerName); +} + MenuStateScenario::~MenuStateScenario() { cleanupPreviewTexture(); } diff --git a/source/glest_game/menu/menu_state_scenario.h b/source/glest_game/menu/menu_state_scenario.h index 975a2b09..f1e23027 100644 --- a/source/glest_game/menu/menu_state_scenario.h +++ b/source/glest_game/menu/menu_state_scenario.h @@ -62,6 +62,8 @@ public: virtual void keyDown(SDL_KeyboardEvent key); + virtual void reloadUI(); + private: void loadScenarioInfo(string file, ScenarioInfo *scenarioInfo); diff --git a/source/glest_game/menu/server_line.cpp b/source/glest_game/menu/server_line.cpp index 651b881c..1f31ed3e 100644 --- a/source/glest_game/menu/server_line.cpp +++ b/source/glest_game/menu/server_line.cpp @@ -133,6 +133,32 @@ ServerLine::ServerLine(MasterServerInfo *mServerInfo, int lineIndex, int baseY, } +void ServerLine::reloadUI() { + Lang &lang= Lang::getInstance(); + + glestVersionLabel.setText(masterServerInfo.getGlestVersion()); + + platformLabel.setText(masterServerInfo.getPlatform()); + + serverTitleLabel.setText(masterServerInfo.getServerTitle()); + + country.setText(masterServerInfo.getCountry()); + + wrongVersionLabel.setText(lang.get("IncompatibleVersion")); + + techLabel.setText(masterServerInfo.getTech()); + + mapLabel.setText(masterServerInfo.getMap()); + activeSlotsLabel.setText(intToStr(masterServerInfo.getActiveSlots()) + "/" + intToStr( + masterServerInfo.getNetworkSlots()) + "/" + intToStr(masterServerInfo.getConnectedClients())); + + externalConnectPort.setText(intToStr(masterServerInfo.getExternalConnectPort())); + + status.setText(lang.get("MGGameStatus" + intToStr(masterServerInfo.getStatus()))); + + GraphicComponent::reloadFontsForRegisterGraphicComponents(containerName); +} + ServerLine::~ServerLine(){ //delete masterServerInfo; diff --git a/source/glest_game/menu/server_line.h b/source/glest_game/menu/server_line.h index ed2d89fe..b21b2477 100644 --- a/source/glest_game/menu/server_line.h +++ b/source/glest_game/menu/server_line.h @@ -69,6 +69,8 @@ public: void setY(int y); //void setIndex(int value); void render(); + + virtual void reloadUI(); }; }}//end namespace diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index 3b57b96f..4950518c 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -142,7 +142,7 @@ ServerInterface::ServerInterface(bool publishEnabled) :GameNetworkInterface() { if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); int portNumber = Config::getInstance().getInt("FTPServerPort",intToStr(ServerSocket::getFTPServerPort()).c_str()); ServerSocket::setFTPServerPort(portNumber); - printf("In [%s::%s] portNumber = %d ServerSocket::getFTPServerPort() = %d\n",__FILE__,__FUNCTION__,__LINE__,portNumber,ServerSocket::getFTPServerPort()); + //printf("In [%s::%s] portNumber = %d ServerSocket::getFTPServerPort() = %d\n",__FILE__,__FUNCTION__,__LINE__,portNumber,ServerSocket::getFTPServerPort()); bool allowInternetTilesetFileTransfers = Config::getInstance().getBool("EnableFTPServerInternetTilesetXfer","true"); bool allowInternetTechtreeFileTransfers = Config::getInstance().getBool("EnableFTPServerInternetTechtreeXfer","true"); diff --git a/source/shared_lib/include/graphics/font.h b/source/shared_lib/include/graphics/font.h index adc4bd1a..0f914529 100644 --- a/source/shared_lib/include/graphics/font.h +++ b/source/shared_lib/include/graphics/font.h @@ -105,6 +105,8 @@ public: int getSize() const; void setSize(int size); + + static void resetToDefaults(); }; // ===================================================== diff --git a/source/shared_lib/include/graphics/font_manager.h b/source/shared_lib/include/graphics/font_manager.h index 01f16a44..a966dc0a 100644 --- a/source/shared_lib/include/graphics/font_manager.h +++ b/source/shared_lib/include/graphics/font_manager.h @@ -40,6 +40,8 @@ public: Font2D *newFont2D(); Font3D *newFont3D(); + void endFont(Font *font,bool mustExistInList=false); + void init(); void end(); }; diff --git a/source/shared_lib/include/platform/posix/ircclient.h b/source/shared_lib/include/platform/posix/ircclient.h index bd9c4ab0..8f03ae60 100644 --- a/source/shared_lib/include/platform/posix/ircclient.h +++ b/source/shared_lib/include/platform/posix/ircclient.h @@ -49,6 +49,9 @@ protected: std::vector argv; irc_session_t *ircSession; + string execute_cmd_onconnect; + //string password; + string username; string channel; string nick; @@ -86,6 +89,9 @@ public: string getChannel() const { return channel;} string getNick() const { return nick;} + string getExecute_cmd_onconnect() const { return execute_cmd_onconnect; } + void setExecute_cmd_onconnect(string value) { execute_cmd_onconnect = value; } + std::vector getArgs() const { return argv;} Mutex * getMutexNickList() { return &mutexNickList; } diff --git a/source/shared_lib/sources/graphics/font.cpp b/source/shared_lib/sources/graphics/font.cpp index 2fea1e0e..6caffb48 100644 --- a/source/shared_lib/sources/graphics/font.cpp +++ b/source/shared_lib/sources/graphics/font.cpp @@ -52,6 +52,34 @@ int Font::faceResolution = 72; string Font::langHeightText = "yW"; // +void Font::resetToDefaults() { + Font::charCount = 256; + Font::fontTypeName = "Times New Roman"; + Font::fontIsMultibyte = false; + Font::forceLegacyFonts = false; + Font::fontIsRightToLeft = false; + + // This value is used to scale the font text rendering + // in 3D render mode + Font::scaleFontValue = 0.80f; + // This value is used for centering font text vertically (height) + Font::scaleFontValueCenterHFactor = 4.0f; + //float Font::scaleFontValue = 1.0; + //float Font::scaleFontValueCenterHFactor = 4.0; + + Font::baseSize = 3; + + Font::faceResolution = 72; + Font::langHeightText = "yW"; + +#if defined(WIN32) + string newEnvValue = "MEGAGLEST_FONT="; + _putenv(newEnvValue.c_str()); +#else + unsetenv("MEGAGLEST_FONT"); +#endif +} + // ===================================================== // class FontMetrics // ===================================================== diff --git a/source/shared_lib/sources/graphics/font_manager.cpp b/source/shared_lib/sources/graphics/font_manager.cpp index 4ba85e9c..09d60f5a 100644 --- a/source/shared_lib/sources/graphics/font_manager.cpp +++ b/source/shared_lib/sources/graphics/font_manager.cpp @@ -13,6 +13,7 @@ #include "graphics_interface.h" #include "graphics_factory.h" +#include #include "leak_dumper.h" namespace Shared { namespace Graphics { @@ -40,6 +41,26 @@ Font3D *FontManager::newFont3D() { return font; } +void FontManager::endFont(Font *font,bool mustExistInList) { + if(font != NULL) { + bool found = false; + for(unsigned int i=0; i < fonts.size(); ++i) { + if(fonts[i] != NULL && font == fonts[i]) { + found = true; + fonts.erase(fonts.begin() + i); + break; + } + } + if(found == false && mustExistInList == true) { + throw std::runtime_error("found == false in endFont"); + } + if(found == true) { + font->end(); + delete font; + } + } +} + void FontManager::init() { for(size_t i=0; iFaceSize()); assertGl(); + ftFont->Render(str, len); //assertGl(); GLenum error = glGetError(); diff --git a/source/shared_lib/sources/graphics/gl/text_renderer_gl.cpp b/source/shared_lib/sources/graphics/gl/text_renderer_gl.cpp index 8187ba28..a1e47416 100644 --- a/source/shared_lib/sources/graphics/gl/text_renderer_gl.cpp +++ b/source/shared_lib/sources/graphics/gl/text_renderer_gl.cpp @@ -393,6 +393,11 @@ void TextRenderer3DGl::render(const string &text, float x, float y, bool center //} //if(isRLM == true) { if(is_string_all_ascii(renderText) == false) { + //printf("\n\nORIGINAL TEXT [%s]\n\n",text.c_str()); + //for(int i = 0; i < renderText.size(); ++i) { + // printf("i = %d c [%c][%d][%X]\n",i,renderText[i],renderText[i],renderText[i]); + //} + strrev_utf8(renderText); } } diff --git a/source/shared_lib/sources/platform/posix/ircclient.cpp b/source/shared_lib/sources/platform/posix/ircclient.cpp index a9b369c6..8b0e2cc4 100644 --- a/source/shared_lib/sources/platform/posix/ircclient.cpp +++ b/source/shared_lib/sources/platform/posix/ircclient.cpp @@ -83,6 +83,41 @@ void get_nickname(const char *sourceNick,char *destNick,size_t maxDestBufferSize irc_target_get_nick(sourceNickStr.c_str(),destNick,maxDestBufferSize); } +void event_notice (irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count) { + dump_event (session, event, origin, params, count); + + if(origin == NULL) { + return; + } + + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("NOTICE from '%s': %s", origin, params[1]); + + if(strcasecmp (origin, "nickserv")) { + return; + } + + if(strstr (params[1], "This nick is not registered") == params[1]) { + //std::string regcmd = "REGISTER " + gCfg.irc_nickserv_pass + " NOMAIL"; + //gLog.Add (CLog::INFO, "Registering our nick with NICKSERV"); + //irc_cmd_msg (session, "nickserv", regcmd.c_str()); + } + else if(strstr (params[1], "This nickname is registered and protected") == params[1]) { + //std::string identcmd = "IDENTIFY " + gCfg.irc_nickserv_pass; + //gLog.Add (CLog::INFO, "Identifying our nick with NICKSERV"); + //irc_cmd_msg (session, "nickserv", identcmd.c_str()); + +// IRCThread *ctx = (IRCThread *)irc_get_ctx(session); +// if(ctx != NULL) { +// if(ctx->getExecute_cmd_onconnect() != "") { +// irc_cmd_msg(session, "nickserv", ctx->getExecute_cmd_onconnect().c_str()); +// } +// } + } + else if(strstr (params[1], "Password accepted - you are now recognized") == params[1]) { + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Nickserv authentication succeed."); + } +} + void event_join(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count) { dump_event (session, event, origin, params, count); @@ -125,7 +160,18 @@ void event_connect (irc_session_t * session, const char * event, const char * or dump_event(session, event, origin, params, count); - if(ctx != NULL) { + //IRC: Event "433", origin: "leguin.freenode.net", params: 3 [*|softcoder|Nickname is already in use.] +// printf("In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); +// if(strstr (params[1], "Nickname is already in use") == params[1]) { +// IRCThread *ctx = (IRCThread *)irc_get_ctx(session); +// if(ctx != NULL) { +// if(ctx->getExecute_cmd_onconnect() != "") { +// irc_cmd_msg(session, "nickserv", ctx->getExecute_cmd_onconnect().c_str()); +// } +// } +// } +// else + if(ctx != NULL) { irc_cmd_join(session, ctx->getChannel().c_str(), 0); } } @@ -188,6 +234,9 @@ void dcc_file_recv_callback (irc_session_t * session, irc_dcc_t id, int status, } void event_channel(irc_session_t * session, const char * event, const char * origin, const char ** params, unsigned int count) { + //IRC: Event "433", origin: "leguin.freenode.net", params: 3 [*|softcoder|Nickname is already in use.] + printf("In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + if ( count != 2 ) return; @@ -309,8 +358,40 @@ void event_numeric(irc_session_t * session, unsigned int event, const char * ori //irc_auto_rename_nick(session); //IRCThread *ctx = (IRCThread *)irc_get_ctx(session); //if(ctx != NULL) { - +// { +// //IRC: Event "433", origin: "leguin.freenode.net", params: 3 [*|softcoder|Nickname is already in use.] +// printf("In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); +// //if(strstr (params[1], "Nickname is already in use") == params[1]) { +// IRCThread *ctx = (IRCThread *)irc_get_ctx(session); +// if(ctx != NULL) { +// if(ctx->getExecute_cmd_onconnect() != "") { +// irc_cmd_msg(session, "nickserv", ctx->getExecute_cmd_onconnect().c_str()); +// } +// } +// //} +// } break; + + case LIBIRC_RFC_ERR_NOTREGISTERED : + //irc_auto_rename_nick(session); + //IRCThread *ctx = (IRCThread *)irc_get_ctx(session); + //if(ctx != NULL) { +// { + //===> IRC: Event "451", origin: "leguin.freenode.net", params: 2 [*|You have not registered] +// printf("In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); +// //if(strstr (params[1], "Nickname is already in use") == params[1]) { +// IRCThread *ctx = (IRCThread *)irc_get_ctx(session); +// if(ctx != NULL) { +// //if(ctx->getExecute_cmd_onconnect() != "") { +// //irc_cmd_msg(session, "nickserv", ctx->getExecute_cmd_onconnect().c_str()); +// string cmd = "REGISTER " + ctx->getNick() + " NOMAIL"; +// irc_cmd_msg (session, "nickserv", cmd.c_str()); +// //} +// } +// //} +// } + break; + case LIBIRC_RFC_RPL_TOPIC : break; case LIBIRC_RFC_RPL_NAMREPLY : @@ -462,7 +543,7 @@ void IRCThread::execute() { irc_callbacks_t callbacks; ircSession=NULL; - if(argv.size() != 3) { + if(argv.size() != 5) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> IRC Usage: : got params [%ld]\n",(long int)argv.size()); return; } @@ -479,7 +560,7 @@ void IRCThread::execute() { callbacks.event_kick = dump_event; callbacks.event_channel = event_channel; callbacks.event_privmsg = event_privmsg; - callbacks.event_notice = dump_event; + callbacks.event_notice = event_notice; callbacks.event_invite = dump_event; callbacks.event_umode = dump_event; callbacks.event_ctcp_rep = dump_event; @@ -500,6 +581,19 @@ void IRCThread::execute() { return; } +// this->execute_cmd_onconnect = ""; +// if(argv.size() >= 5) { +// this->execute_cmd_onconnect = argv[4]; // /msg NickServ identify . +// } + +// this->password = ""; +// if(argv.size() >= 5) { +// this->password = argv[4]; +// } + this->username = argv[1]; + if(argv.size() >= 4) { + this->username = argv[3]; + } this->channel = argv[2]; this->nick = argv[1]; irc_set_ctx(ircSession, this); @@ -508,7 +602,7 @@ void IRCThread::execute() { return; } - if(irc_connect(ircSession, argv[0].c_str(), IRC_SERVER_PORT, 0, this->nick.c_str(), this->nick.c_str(), "megaglest")) { + if(irc_connect(ircSession, argv[0].c_str(), IRC_SERVER_PORT, 0, this->nick.c_str(), this->username.c_str(), "megaglest")) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> IRC Could not connect: %s\n", irc_strerror (irc_errno(ircSession))); return; } diff --git a/source/shared_lib/sources/util/string_utils.cpp b/source/shared_lib/sources/util/string_utils.cpp index 0f7d39e9..3cb39860 100644 --- a/source/shared_lib/sources/util/string_utils.cpp +++ b/source/shared_lib/sources/util/string_utils.cpp @@ -816,39 +816,71 @@ namespace Shared { namespace Util { #define SWP(x,y) (x^=y, y^=x, x^=y) void strrev_utf8(char *p) { + //printf("In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); fflush(stdout); + char *q = p; strrev(p); /* call base case */ + //printf("In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); fflush(stdout); + /* Ok, now fix bass-ackwards UTF chars. */ while(q && *q) ++q; /* find eos */ - while(p < --q) + + //printf("In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); fflush(stdout); + while(p < --q) { + //printf("In [%s::%s] Line: %d p [%s] q [%s]\n",__FILE__,__FUNCTION__,__LINE__,p,q); fflush(stdout); + switch( (*q & 0xF0) >> 4 ) { case 0xF: /* U+010000-U+10FFFF: four bytes. */ + //printf("In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); fflush(stdout); SWP(*(q-0), *(q-3)); + //printf("In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); fflush(stdout); SWP(*(q-1), *(q-2)); + //printf("In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); fflush(stdout); q -= 3; break; case 0xE: /* U+000800-U+00FFFF: three bytes. */ + //printf("In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); fflush(stdout); SWP(*(q-0), *(q-2)); + //printf("In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); fflush(stdout); q -= 2; break; case 0xC: /* fall-through */ case 0xD: /* U+000080-U+0007FF: two bytes. */ + //printf("In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); fflush(stdout); SWP(*(q-0), *(q-1)); + //printf("In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); fflush(stdout); q--; break; } + + //printf("In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); fflush(stdout); + } + //printf("In [%s::%s] Line: %d p [%s]\n",__FILE__,__FUNCTION__,__LINE__,p); fflush(stdout); } void strrev_utf8(std::string &p) { - int bufSize = p.size()+1; - char *szBuf = new char[bufSize]; - strcpy(szBuf,p.c_str()); - szBuf[bufSize] = '\0'; - strrev_utf8(&szBuf[0]); - p = szBuf; + //printf("In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); fflush(stdout); - delete [] szBuf; + if(p.length() > 0) { + //printf("In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); fflush(stdout); + + int bufSize = p.length()*4; + char *szBuf = new char[bufSize]; + memset(szBuf,0,bufSize); + strcpy(szBuf,p.c_str()); + //szBuf[bufSize] = '\0'; + strrev_utf8(szBuf); + //printf("In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); fflush(stdout); + p = std::string(szBuf); + + //printf("In [%s::%s] Line: %d bufSize = %d p.size() = %d p [%s]\n",__FILE__,__FUNCTION__,__LINE__,bufSize,p.length(),p.c_str()); fflush(stdout); + + delete [] szBuf; + + //printf("In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); fflush(stdout); + } + //printf("In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); fflush(stdout); } bool is_string_all_ascii(std::string str) {