diff --git a/source/glest_game/menu/main_menu.h b/source/glest_game/menu/main_menu.h index 8499b16bf..a4d91ace3 100644 --- a/source/glest_game/menu/main_menu.h +++ b/source/glest_game/menu/main_menu.h @@ -24,10 +24,18 @@ namespace Glest{ namespace Game{ //misc consts -struct MapInfo{ +class MapInfo { +public: + Vec2i size; int players; string desc; + + MapInfo() { + size = Vec2i(0,0); + players = 0; + desc = ""; + } }; struct ScenarioInfo diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 44e4773d7..a2b72dc30 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -50,11 +50,6 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM { lastNetworkSendPing = 0; pingCount = 0; - - returnMenuInfo=joinMenuInfo; - Lang &lang= Lang::getInstance(); - NetworkManager &networkManager= NetworkManager::getInstance(); - Config &config = Config::getInstance(); needToSetChangedGameSettings = false; lastSetChangedGameSettings = time(NULL); showFullConsole=false; @@ -62,7 +57,14 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM currentFactionName=""; currentMap=""; settingsReceivedFromServer=false; + initialSettingsReceivedFromServer=false; + returnMenuInfo=joinMenuInfo; + Lang &lang= Lang::getInstance(); + NetworkManager &networkManager= NetworkManager::getInstance(); + Config &config = Config::getInstance(); + + labelMapInfo.setText("?"); vector teamItems, controlItems, results; //state @@ -225,7 +227,7 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM labelFaction.setText(lang.get("Faction")); labelTeam.setText(lang.get("Team")); -SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); labelMapInfo.setText(mapInfo.desc); //init controllers @@ -240,8 +242,6 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){ NetworkManager &networkManager= NetworkManager::getInstance(); ClientInterface* clientInterface= networkManager.getClientInterface(); - //if (!settingsReceivedFromServer) return; - if(buttonDisconnect.mouseClick(x,y)){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -261,9 +261,13 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){ currentFactionName=""; currentMap=""; returnToJoinMenu(); + return; } + + if (!initialSettingsReceivedFromServer) return; + // Only allow changes after we get game settings from the server - else if( clientInterface->isConnected() == true && + if( clientInterface->isConnected() == true && clientInterface->getGameSettingsReceived() == true) { if(buttonPlayNow.mouseClick(x,y) && buttonPlayNow.getEnabled()) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -358,7 +362,7 @@ void MenuStateConnectedGame::render(){ try { //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); - if (!settingsReceivedFromServer) return; + if (!initialSettingsReceivedFromServer) return; //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -672,6 +676,7 @@ void MenuStateConnectedGame::update() } settingsReceivedFromServer=true; + initialSettingsReceivedFromServer=true; } } } diff --git a/source/glest_game/menu/menu_state_connected_game.h b/source/glest_game/menu/menu_state_connected_game.h index 1f8291ee1..4aeaa79d2 100644 --- a/source/glest_game/menu/menu_state_connected_game.h +++ b/source/glest_game/menu/menu_state_connected_game.h @@ -86,6 +86,7 @@ private: bool settingsReceivedFromServer; time_t lastNetworkSendPing; int pingCount; + bool initialSettingsReceivedFromServer; public: diff --git a/source/shared_lib/sources/graphics/font.cpp b/source/shared_lib/sources/graphics/font.cpp index 485942e23..59ad0a5ce 100644 --- a/source/shared_lib/sources/graphics/font.cpp +++ b/source/shared_lib/sources/graphics/font.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest Shared Library (www.glest.org) // -// Copyright (C) 2001-2007 Martiņo Figueroa +// Copyright (C) 2001-2007 Martio Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -10,11 +10,18 @@ // ============================================================== #include "font.h" - +#include +#include "conversion.h" #include "leak_dumper.h" +using namespace std; +using namespace Shared::Util; + namespace Shared{ namespace Graphics{ +int Font::charCount= 256; +std::string Font::fontTypeName = "Times New Roman"; + // ===================================================== // class FontMetrics // ===================================================== @@ -30,11 +37,16 @@ FontMetrics::FontMetrics(){ FontMetrics::~FontMetrics(){ delete [] widths; + widths = NULL; } float FontMetrics::getTextWidth(const string &str) const{ float width= 0.f; - for(unsigned int i=0; i= Font::charCount) { + string sError = "str[i] >= Font::charCount, [" + str + "] i = " + intToStr(i); + throw runtime_error(sError); + } width+= widths[str[i]]; } return width; @@ -48,9 +60,6 @@ float FontMetrics::getHeight() const{ // class Font // =============================================== -int Font::charCount= 256; -std::string Font::fontTypeName = "Times New Roman"; - Font::Font(){ inited= false; type= fontTypeName;