2010-05-09 23:23:13 +02:00
// ==============================================================
// This file is part of Glest (www.glest.org)
//
2012-10-30 07:48:12 +01:00
// Copyright (C) 2001-2008 Martiño Figueroa
2010-05-09 23:23:13 +02:00
//
2010-12-10 02:53:51 +01:00
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
2010-05-09 23:23:13 +02:00
// License, or (at your option) any later version
// ==============================================================
# include "menu_state_root.h"
# include "renderer.h"
# include "sound_renderer.h"
# include "core_data.h"
# include "config.h"
# include "menu_state_new_game.h"
2012-03-15 00:53:11 +01:00
# include "menu_state_load_game.h"
2010-05-09 23:23:13 +02:00
# include "menu_state_options.h"
# include "menu_state_about.h"
2011-03-25 11:11:16 +01:00
# include "menu_state_mods.h"
2010-05-09 23:23:13 +02:00
# include "metrics.h"
# include "network_manager.h"
# include "network_message.h"
# include "socket.h"
# include "auto_test.h"
2017-09-24 02:15:44 +02:00
# include "steam.h"
2014-12-30 21:16:35 +01:00
# include <stdio.h>
2010-05-09 23:23:13 +02:00
# include "leak_dumper.h"
namespace Glest { namespace Game {
// =====================================================
// class MenuStateRoot
// =====================================================
2014-12-30 21:16:35 +01:00
bool MenuStateRoot : : gameUpdateChecked = false ;
2017-02-04 21:33:18 +01:00
MenuStateRoot : : MenuStateRoot ( Program * program , MainMenu * mainMenu ) :
MenuState ( program , mainMenu , " root " ) , updatesHttpServerThread ( NULL ) ,
buttonNewGame ( " MainMenu " , " buttonNewGame " ) ,
buttonLoadGame ( " MainMenu " , " buttonLoadGame " ) ,
buttonMods ( " MainMenu " , " buttonMods " ) ,
buttonOptions ( " MainMenu " , " buttonOptions " ) ,
buttonAbout ( " MainMenu " , " buttonAbout " ) ,
buttonExit ( " MainMenu " , " buttonExit " ) ,
labelVersion ( " MainMenu " , " labelVersion " ) ,
2017-09-24 02:15:44 +02:00
labelGreeting ( " MainMenu " , " labelGreeting " ) ,
2017-02-04 21:33:18 +01:00
mainMessageBox ( " MainMenu " , " mainMessageBox " ) ,
errorMessageBox ( " MainMenu " , " errorMessageBox " ) ,
ftpMessageBox ( " MainMenu " , " ftpMessageBox " ) ,
popupMenu ( " MainMenu " , " popupMenu " )
2010-05-09 23:23:13 +02:00
{
2010-09-09 23:07:39 +02:00
containerName = " MainMenu " ;
2014-12-30 21:16:35 +01:00
ftpClientThread = NULL ;
lastDownloadProgress = 0 ;
2010-05-09 23:23:13 +02:00
Lang & lang = Lang : : getInstance ( ) ;
2011-01-12 20:42:25 +01:00
int yPos = 440 ;
2015-02-06 01:14:17 +01:00
int buttonWidth = 200 ;
int buttonXPosition = ( 1000 - buttonWidth ) / 2 ;
2010-09-09 08:42:39 +02:00
2011-01-12 20:42:25 +01:00
2017-02-04 21:33:18 +01:00
//labelVersion.registerGraphicComponent(containerName,"labelVersion");
2011-01-12 20:42:25 +01:00
if ( EndsWith ( glestVersionString , " -dev " ) = = false ) {
labelVersion . init ( 525 , yPos ) ;
labelVersion . setText ( glestVersionString ) ;
}
else {
2015-02-06 01:14:17 +01:00
labelVersion . init ( buttonXPosition , yPos ) ;
2015-11-15 10:23:17 +01:00
//labelVersion.setText(glestVersionString + " [" + getCompileDateTime() + ", " + getGITRevisionString() + "]");
labelVersion . setText ( glestVersionString + " [ " + getGITRevisionString ( ) + " ] " ) ;
2011-01-12 20:42:25 +01:00
}
2017-09-24 02:15:44 +02:00
labelGreeting . init ( labelVersion . getX ( ) , labelVersion . getY ( ) - 16 ) ;
labelGreeting . setText ( " " ) ;
Config & config = Config : : getInstance ( ) ;
if ( config . getBool ( " SteamEnabled " ) ) {
Steam steam ;
string steamPlayerName = steam . userName ( ) ;
labelGreeting . setText ( " Welcome Steam Player: " + steamPlayerName ) ;
}
2011-01-12 20:42:25 +01:00
yPos - = 55 ;
2017-02-04 21:33:18 +01:00
//buttonNewGame.registerGraphicComponent(containerName,"buttonNewGame");
2015-02-06 01:14:17 +01:00
buttonNewGame . init ( buttonXPosition , yPos , buttonWidth ) ;
2011-01-12 20:42:25 +01:00
yPos - = 40 ;
2017-02-04 21:33:18 +01:00
//buttonLoadGame.registerGraphicComponent(containerName,"buttonLoadGame");
2015-02-06 01:14:17 +01:00
buttonLoadGame . init ( buttonXPosition , yPos , buttonWidth ) ;
2012-03-15 00:53:11 +01:00
yPos - = 40 ;
2017-02-04 21:33:18 +01:00
//buttonMods.registerGraphicComponent(containerName,"buttonMods");
2015-02-06 01:14:17 +01:00
buttonMods . init ( buttonXPosition , yPos , buttonWidth ) ;
2011-03-25 11:11:16 +01:00
yPos - = 40 ;
2017-02-04 21:33:18 +01:00
//buttonOptions.registerGraphicComponent(containerName,"buttonOptions");
2015-02-06 01:14:17 +01:00
buttonOptions . init ( buttonXPosition , yPos , buttonWidth ) ;
2011-01-12 20:42:25 +01:00
yPos - = 40 ;
2017-02-04 21:33:18 +01:00
//buttonAbout.registerGraphicComponent(containerName,"buttonAbout");
2015-02-06 01:14:17 +01:00
buttonAbout . init ( buttonXPosition , yPos , buttonWidth ) ;
2011-01-12 20:42:25 +01:00
yPos - = 40 ;
2017-02-04 21:33:18 +01:00
//buttonExit.registerGraphicComponent(containerName,"buttonExit");
2015-02-06 01:14:17 +01:00
buttonExit . init ( buttonXPosition , yPos , buttonWidth ) ;
2010-05-09 23:23:13 +02:00
2013-10-29 07:13:38 +01:00
buttonNewGame . setText ( lang . getString ( " NewGame " ) ) ;
buttonLoadGame . setText ( lang . getString ( " LoadGame " ) ) ;
buttonMods . setText ( lang . getString ( " Mods " ) ) ;
buttonOptions . setText ( lang . getString ( " Options " ) ) ;
buttonAbout . setText ( lang . getString ( " About " ) ) ;
buttonExit . setText ( lang . getString ( " Exit " ) ) ;
2010-12-11 01:20:31 +01:00
2010-06-12 21:27:11 +02:00
//mesage box
2017-02-04 21:33:18 +01:00
//mainMessageBox.registerGraphicComponent(containerName,"mainMessageBox");
2013-10-29 07:13:38 +01:00
mainMessageBox . init ( lang . getString ( " Yes " ) , lang . getString ( " No " ) ) ;
2010-06-12 21:27:11 +02:00
mainMessageBox . setEnabled ( false ) ;
2017-02-04 21:33:18 +01:00
//errorMessageBox.registerGraphicComponent(containerName,"errorMessageBox");
2013-10-29 07:13:38 +01:00
errorMessageBox . init ( lang . getString ( " Ok " ) ) ;
2011-12-05 01:02:32 +01:00
errorMessageBox . setEnabled ( false ) ;
2017-02-04 21:33:18 +01:00
//ftpMessageBox.registerGraphicComponent(containerName,"ftpMessageBox");
2014-12-30 21:16:35 +01:00
ftpMessageBox . init ( lang . getString ( " Yes " ) , lang . getString ( " No " ) ) ;
ftpMessageBox . setEnabled ( false ) ;
2011-09-21 08:51:28 +02:00
//PopupMenu popupMenu;
std : : vector < string > menuItems ;
menuItems . push_back ( " 1 " ) ;
menuItems . push_back ( " 2 " ) ;
menuItems . push_back ( " 3 " ) ;
2017-02-04 21:33:18 +01:00
//popupMenu.registerGraphicComponentOnlyFontCallbacks(containerName, "popupMenu");
2011-09-21 08:51:28 +02:00
popupMenu . setW ( 100 ) ;
popupMenu . setH ( 100 ) ;
popupMenu . init ( " Test Menu " , menuItems ) ;
popupMenu . setEnabled ( false ) ;
popupMenu . setVisible ( false ) ;
2010-09-09 08:42:39 +02:00
GraphicComponent : : applyAllCustomProperties ( containerName ) ;
2010-05-09 23:23:13 +02:00
}
2014-12-30 21:16:35 +01:00
MenuStateRoot : : ~ MenuStateRoot ( ) {
if ( updatesHttpServerThread ! = NULL ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
updatesHttpServerThread - > setSimpleTaskInterfaceValid ( false ) ;
updatesHttpServerThread - > signalQuit ( ) ;
updatesHttpServerThread - > setThreadOwnerValid ( false ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( updatesHttpServerThread - > canShutdown ( true ) = = true & &
updatesHttpServerThread - > shutdownAndWait ( ) = = true ) {
delete updatesHttpServerThread ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
updatesHttpServerThread = NULL ;
}
if ( ftpClientThread ! = NULL ) {
ftpClientThread - > setCallBackObject ( NULL ) ;
ftpClientThread - > signalQuit ( ) ;
sleep ( 0 ) ;
if ( ftpClientThread - > canShutdown ( true ) = = true & &
ftpClientThread - > shutdownAndWait ( ) = = true ) {
delete ftpClientThread ;
}
else {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s %d] Error cannot shutdown ftpClientThread \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
//SystemFlags::OutputDebug(SystemFlags::debugError,szBuf);
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " %s " , szBuf ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s " , szBuf ) ;
//publishToMasterserverThread->cleanup();
}
ftpClientThread = NULL ;
// ftpClientThread->signalQuit();
// ftpClientThread->setCallBackObject(NULL);
// if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
// if( ftpClientThread->shutdownAndWait() == true) {
// if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
// delete ftpClientThread;
// }
// ftpClientThread = NULL;
// if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
}
2011-10-25 20:39:11 +02:00
void MenuStateRoot : : reloadUI ( ) {
Lang & lang = Lang : : getInstance ( ) ;
2011-11-04 00:38:43 +01:00
console . resetFonts ( ) ;
2011-10-25 20:39:11 +02:00
if ( EndsWith ( glestVersionString , " -dev " ) = = false ) {
labelVersion . setText ( glestVersionString ) ;
}
else {
2015-11-15 10:23:17 +01:00
//labelVersion.setText(glestVersionString + " [" + getCompileDateTime() + ", " + getGITRevisionString() + "]");
labelVersion . setText ( glestVersionString + " [ " + getGITRevisionString ( ) + " ] " ) ;
2011-10-25 20:39:11 +02:00
}
2013-10-29 07:13:38 +01:00
buttonNewGame . setText ( lang . getString ( " NewGame " ) ) ;
buttonLoadGame . setText ( lang . getString ( " LoadGame " ) ) ;
buttonMods . setText ( lang . getString ( " Mods " ) ) ;
buttonOptions . setText ( lang . getString ( " Options " ) ) ;
buttonAbout . setText ( lang . getString ( " About " ) ) ;
buttonExit . setText ( lang . getString ( " Exit " ) ) ;
2011-10-25 20:39:11 +02:00
2013-10-29 07:13:38 +01:00
mainMessageBox . init ( lang . getString ( " Yes " ) , lang . getString ( " No " ) ) ;
errorMessageBox . init ( lang . getString ( " Ok " ) ) ;
2014-12-30 21:16:35 +01:00
ftpMessageBox . init ( lang . getString ( " Yes " ) , lang . getString ( " No " ) ) ;
2011-11-04 00:38:43 +01:00
console . resetFonts ( ) ;
2011-10-25 20:39:11 +02:00
GraphicComponent : : reloadFontsForRegisterGraphicComponents ( containerName ) ;
}
2010-05-09 23:23:13 +02:00
void MenuStateRoot : : mouseClick ( int x , int y , MouseButton mouseButton ) {
2011-12-05 01:02:32 +01:00
try {
CoreData & coreData = CoreData : : getInstance ( ) ;
SoundRenderer & soundRenderer = SoundRenderer : : getInstance ( ) ;
2010-05-09 23:23:13 +02:00
2011-12-05 01:02:32 +01:00
if ( popupMenu . mouseClick ( x , y ) ) {
2012-10-06 09:06:40 +02:00
//std::pair<int,string> result = popupMenu.mouseClickedMenuItem(x, y);
popupMenu . mouseClickedMenuItem ( x , y ) ;
2011-09-21 08:51:28 +02:00
2011-12-05 01:02:32 +01:00
//printf("In popup callback menuItemSelected [%s] menuIndexSelected = %d\n",result.second.c_str(),result.first);
}
//exit message box, has to be the last thing to do in this function
else if ( mainMessageBox . getEnabled ( ) ) {
2012-02-19 18:37:53 +01:00
int button = 0 ;
2011-12-05 01:02:32 +01:00
if ( mainMessageBox . mouseClick ( x , y , button ) ) {
2012-02-19 18:37:53 +01:00
if ( button = = 0 ) {
2011-12-05 01:02:32 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
soundRenderer . playFx ( coreData . getClickSoundA ( ) ) ;
program - > exit ( ) ;
}
else {
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
//close message box
mainMessageBox . setEnabled ( false ) ;
}
2010-06-12 21:27:11 +02:00
}
2011-12-05 01:02:32 +01:00
}
//exit message box, has to be the last thing to do in this function
else if ( errorMessageBox . getEnabled ( ) ) {
2012-02-19 18:37:53 +01:00
int button = 0 ;
2011-12-05 01:02:32 +01:00
if ( mainMessageBox . mouseClick ( x , y , button ) ) {
2011-03-29 11:45:15 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-06-12 21:27:11 +02:00
//close message box
2011-12-05 01:02:32 +01:00
errorMessageBox . setEnabled ( false ) ;
2010-06-12 21:27:11 +02:00
}
}
2014-12-30 21:16:35 +01:00
else if ( ftpMessageBox . getEnabled ( ) ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
int button = 0 ;
if ( ftpMessageBox . mouseClick ( x , y , button ) ) {
ftpMessageBox . setEnabled ( false ) ;
if ( button = = 0 ) {
startFTPClientIfRequired ( ) ;
lastDownloadProgress = 0 ;
printf ( " Adding ftpFileName [%s] ftpFileURL [%s] \n " , ftpFileName . c_str ( ) , ftpFileURL . c_str ( ) ) ;
if ( ftpClientThread ! = NULL ) ftpClientThread - > addTempFileToRequests ( ftpFileName , ftpFileURL ) ;
static string mutexOwnerId = string ( __FILE__ ) + string ( " _ " ) + intToStr ( __LINE__ ) ;
MutexSafeWrapper safeMutexFTPProgress ( ( ftpClientThread ! = NULL ? ftpClientThread - > getProgressMutex ( ) : NULL ) , mutexOwnerId ) ;
if ( ftpClientThread ! = NULL & & ftpClientThread - > getProgressMutex ( ) ! = NULL ) ftpClientThread - > getProgressMutex ( ) - > setOwnerId ( mutexOwnerId ) ;
fileFTPProgressList [ ftpFileName ] = pair < int , string > ( 0 , " " ) ;
safeMutexFTPProgress . ReleaseLock ( ) ;
}
}
}
2011-12-05 01:02:32 +01:00
else if ( mainMessageBox . getEnabled ( ) = = false & & buttonNewGame . mouseClick ( x , y ) ) {
soundRenderer . playFx ( coreData . getClickSoundB ( ) ) ;
mainMenu - > setState ( new MenuStateNewGame ( program , mainMenu ) ) ;
}
2012-03-15 00:53:11 +01:00
else if ( mainMessageBox . getEnabled ( ) = = false & & buttonLoadGame . mouseClick ( x , y ) ) {
soundRenderer . playFx ( coreData . getClickSoundB ( ) ) ;
mainMenu - > setState ( new MenuStateLoadGame ( program , mainMenu ) ) ;
}
2011-12-05 01:02:32 +01:00
else if ( mainMessageBox . getEnabled ( ) = = false & & buttonMods . mouseClick ( x , y ) ) {
soundRenderer . playFx ( coreData . getClickSoundB ( ) ) ;
mainMenu - > setState ( new MenuStateMods ( program , mainMenu ) ) ;
}
else if ( mainMessageBox . getEnabled ( ) = = false & & buttonOptions . mouseClick ( x , y ) ) {
soundRenderer . playFx ( coreData . getClickSoundB ( ) ) ;
mainMenu - > setState ( new MenuStateOptions ( program , mainMenu ) ) ;
}
else if ( mainMessageBox . getEnabled ( ) = = false & & buttonAbout . mouseClick ( x , y ) ) {
soundRenderer . playFx ( coreData . getClickSoundB ( ) ) ;
mainMenu - > setState ( new MenuStateAbout ( program , mainMenu ) ) ;
}
else if ( buttonExit . mouseClick ( x , y ) ) {
soundRenderer . playFx ( coreData . getClickSoundA ( ) ) ;
program - > exit ( ) ;
}
}
catch ( exception & e ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s Line: %d] \n Error in menu event: \n %s \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ , e . what ( ) ) ;
2011-12-05 01:02:32 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , szBuf ) ;
showErrorMessageBox ( szBuf , " " , true ) ;
2010-06-12 21:27:11 +02:00
}
2010-05-09 23:23:13 +02:00
}
2014-12-30 21:16:35 +01:00
void MenuStateRoot : : startFTPClientIfRequired ( ) {
if ( ftpClientThread = = NULL ) {
// Setup File Transfer thread
Config & config = Config : : getInstance ( ) ;
vector < string > tilesetFiles ;
vector < string > tilesetFilesUserData ;
vector < string > techTreeFiles ;
vector < string > techTreeFilesUserData ;
findDirs ( config . getPathListForType ( ptTilesets ) , tilesetFiles ) ;
findDirs ( config . getPathListForType ( ptTechs ) , techTreeFiles ) ;
vector < string > mapPathList = config . getPathListForType ( ptMaps ) ;
std : : pair < string , string > mapsPath ;
if ( mapPathList . empty ( ) = = false ) {
mapsPath . first = mapPathList [ 0 ] ;
}
if ( mapPathList . size ( ) > 1 ) {
mapsPath . second = mapPathList [ 1 ] ;
}
std : : pair < string , string > tilesetsPath ;
vector < string > tilesetsList = Config : : getInstance ( ) . getPathListForType ( ptTilesets ) ;
if ( tilesetsList . empty ( ) = = false ) {
tilesetsPath . first = tilesetsList [ 0 ] ;
if ( tilesetsList . size ( ) > 1 ) {
tilesetsPath . second = tilesetsList [ 1 ] ;
}
}
std : : pair < string , string > techtreesPath ;
vector < string > techtreesList = Config : : getInstance ( ) . getPathListForType ( ptTechs ) ;
if ( techtreesList . empty ( ) = = false ) {
techtreesPath . first = techtreesList [ 0 ] ;
if ( techtreesList . size ( ) > 1 ) {
techtreesPath . second = techtreesList [ 1 ] ;
}
}
std : : pair < string , string > scenariosPath ;
vector < string > scenariosList = Config : : getInstance ( ) . getPathListForType ( ptScenarios ) ;
if ( scenariosList . empty ( ) = = false ) {
scenariosPath . first = scenariosList [ 0 ] ;
if ( scenariosList . size ( ) > 1 ) {
scenariosPath . second = scenariosList [ 1 ] ;
}
}
string fileArchiveExtension = config . getString ( " FileArchiveExtension " , " " ) ;
string fileArchiveExtractCommand = config . getString ( " FileArchiveExtractCommand " , " " ) ;
string fileArchiveExtractCommandParameters = config . getString ( " FileArchiveExtractCommandParameters " , " " ) ;
int32 fileArchiveExtractCommandSuccessResult = config . getInt ( " FileArchiveExtractCommandSuccessResult " , " 0 " ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
console . setOnlyChatMessagesInStoredLines ( false ) ;
// Get path to temp files
string tempFilePath = " temp/ " ;
if ( getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) ! = " " ) {
tempFilePath = getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) + tempFilePath ;
}
else {
string userData = config . getString ( " UserData_Root " , " " ) ;
if ( userData ! = " " ) {
endPathWithSlash ( userData ) ;
}
tempFilePath = userData + tempFilePath ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Temp files path [%s] \n " , tempFilePath . c_str ( ) ) ;
ftpClientThread = new FTPClientThread ( - 1 , " " ,
mapsPath , tilesetsPath , techtreesPath , scenariosPath ,
this , fileArchiveExtension , fileArchiveExtractCommand ,
fileArchiveExtractCommandParameters ,
fileArchiveExtractCommandSuccessResult ,
tempFilePath ) ;
ftpClientThread - > start ( ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
}
void MenuStateRoot : : FTPClient_CallbackEvent ( string itemName ,
FTP_Client_CallbackType type , pair < FTP_Client_ResultType , string > result , void * userdata ) {
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
Lang & lang = Lang : : getInstance ( ) ;
if ( type = = ftp_cct_DownloadProgress ) {
FTPClientCallbackInterface : : FtpProgressStats * stats = ( FTPClientCallbackInterface : : FtpProgressStats * ) userdata ;
if ( stats ! = NULL ) {
int fileProgress = 0 ;
if ( stats - > download_total > 0 ) {
fileProgress = ( ( stats - > download_now / stats - > download_total ) * 100.0 ) ;
}
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Got FTP Callback for [%s] current file [%s] fileProgress = %d [now = %f, total = %f]\n",itemName.c_str(),stats->currentFilename.c_str(), fileProgress,stats->download_now,stats->download_total);
static string mutexOwnerId = string ( __FILE__ ) + string ( " _ " ) + intToStr ( __LINE__ ) ;
MutexSafeWrapper safeMutexFTPProgress ( ( ftpClientThread ! = NULL ? ftpClientThread - > getProgressMutex ( ) : NULL ) , mutexOwnerId ) ;
if ( ftpClientThread ! = NULL & & ftpClientThread - > getProgressMutex ( ) ! = NULL ) ftpClientThread - > getProgressMutex ( ) - > setOwnerId ( mutexOwnerId ) ;
pair < int , string > lastProgress = fileFTPProgressList [ itemName ] ;
fileFTPProgressList [ itemName ] = pair < int , string > ( fileProgress , stats - > currentFilename ) ;
safeMutexFTPProgress . ReleaseLock ( ) ;
if ( itemName ! = " " & & ( lastDownloadProgress < fileProgress & & fileProgress % 25 = = 0 ) ) {
lastDownloadProgress = fileProgress ;
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " Downloaded %d%% of file: %s " , fileProgress , itemName . c_str ( ) ) ;
console . addLine ( szBuf ) ;
}
}
}
else if ( type = = ftp_cct_ExtractProgress ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Got FTP extract Callback for [%s] result = %d [%s] \n " , itemName . c_str ( ) , result . first , result . second . c_str ( ) ) ;
printf ( " Got FTP extract Callback for [%s] result = %d [%s] \n " , itemName . c_str ( ) , result . first , result . second . c_str ( ) ) ;
if ( userdata = = NULL ) {
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , lang . getString ( " DataMissingExtractDownloadMod " ) . c_str ( ) , itemName . c_str ( ) ) ;
//printf("%s\n",szBuf);
console . addLine ( szBuf , true ) ;
}
else {
char * szBuf = ( char * ) userdata ;
//printf("%s\n",szBuf);
console . addLine ( szBuf ) ;
}
}
else if ( type = = ftp_cct_TempFile ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Got FTP Callback for [%s] result = %d [%s] \n " , itemName . c_str ( ) , result . first , result . second . c_str ( ) ) ;
static string mutexOwnerId = string ( __FILE__ ) + string ( " _ " ) + intToStr ( __LINE__ ) ;
MutexSafeWrapper safeMutexFTPProgress ( ( ftpClientThread ! = NULL ? ftpClientThread - > getProgressMutex ( ) : NULL ) , mutexOwnerId ) ;
if ( ftpClientThread ! = NULL & & ftpClientThread - > getProgressMutex ( ) ! = NULL ) ftpClientThread - > getProgressMutex ( ) - > setOwnerId ( mutexOwnerId ) ;
fileFTPProgressList . erase ( itemName ) ;
safeMutexFTPProgress . ReleaseLock ( ) ;
2014-12-31 06:40:51 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " ### downloaded TEMP file [%s] result = %d \n " , itemName . c_str ( ) , result . first ) ;
2014-12-30 21:16:35 +01:00
if ( result . first = = ftp_crt_SUCCESS ) {
// Get path to temp files
string tempFilePath = " temp/ " ;
if ( getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) ! = " " ) {
tempFilePath = getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) + tempFilePath ;
}
else {
Config & config = Config : : getInstance ( ) ;
string userData = config . getString ( " UserData_Root " , " " ) ;
if ( userData ! = " " ) {
endPathWithSlash ( userData ) ;
}
tempFilePath = userData + tempFilePath ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Temp files path [%s] \n " , tempFilePath . c_str ( ) ) ;
// Delete the downloaded archive
if ( fileExists ( tempFilePath + itemName ) ) {
removeFile ( tempFilePath + itemName ) ;
}
2014-12-31 00:05:24 +01:00
bool result = upgradeFilesInTemp ( ) ;
if ( result = = false ) {
string binaryName = Properties : : getApplicationPath ( ) + extractFileFromDirectoryPath ( PlatformExceptionHandler : : application_binary ) ;
string binaryNameOld = Properties : : getApplicationPath ( ) + extractFileFromDirectoryPath ( PlatformExceptionHandler : : application_binary ) + " __REMOVE " ;
bool resultRename = renameFile ( binaryName , binaryNameOld ) ;
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Rename: [%s] to [%s] result = %d\n",binaryName.c_str(),binaryNameOld.c_str(),resultRename);
2014-12-31 06:40:51 +01:00
printf ( " #1 Rename: [%s] to [%s] result = %d errno = %d \n " , binaryName . c_str ( ) , binaryNameOld . c_str ( ) , resultRename , errno ) ;
//result = upgradeFilesInTemp();
binaryName = Properties : : getApplicationPath ( ) + extractFileFromDirectoryPath ( PlatformExceptionHandler : : application_binary ) ;
binaryNameOld = tempFilePath + extractFileFromDirectoryPath ( PlatformExceptionHandler : : application_binary ) ;
resultRename = renameFile ( binaryNameOld , binaryName ) ;
2014-12-31 00:05:24 +01:00
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Rename: [%s] to [%s] result = %d\n",binaryName.c_str(),binaryNameOld.c_str(),resultRename);
2014-12-31 07:09:53 +01:00
printf ( " #2 Rename: [%s] to [%s] result = %d errno = %d \n " , binaryNameOld . c_str ( ) , binaryName . c_str ( ) , resultRename , errno ) ;
2014-12-30 21:16:35 +01:00
}
console . addLine ( " Successfully updated, please restart! " , true ) ;
}
else {
curl_version_info_data * curlVersion = curl_version_info ( CURLVERSION_NOW ) ;
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " FAILED to download the updates: [%s] using CURL version [%s] [%s] " , itemName . c_str ( ) , curlVersion - > version , result . second . c_str ( ) ) ;
console . addLine ( szBuf , true ) ;
showErrorMessageBox ( szBuf , " ERROR " , false ) ;
}
}
}
2010-05-09 23:23:13 +02:00
void MenuStateRoot : : mouseMove ( int x , int y , const MouseState * ms ) {
2011-09-21 08:51:28 +02:00
popupMenu . mouseMove ( x , y ) ;
2010-05-09 23:23:13 +02:00
buttonNewGame . mouseMove ( x , y ) ;
2012-03-15 00:53:11 +01:00
buttonLoadGame . mouseMove ( x , y ) ;
2011-03-25 11:11:16 +01:00
buttonMods . mouseMove ( x , y ) ;
2010-05-09 23:23:13 +02:00
buttonOptions . mouseMove ( x , y ) ;
2010-12-10 02:53:51 +01:00
buttonAbout . mouseMove ( x , y ) ;
2010-05-09 23:23:13 +02:00
buttonExit . mouseMove ( x , y ) ;
2010-06-12 21:27:11 +02:00
if ( mainMessageBox . getEnabled ( ) ) {
mainMessageBox . mouseMove ( x , y ) ;
}
2011-12-05 01:02:32 +01:00
if ( errorMessageBox . getEnabled ( ) ) {
errorMessageBox . mouseMove ( x , y ) ;
}
2014-12-30 21:16:35 +01:00
if ( ftpMessageBox . getEnabled ( ) ) {
ftpMessageBox . mouseMove ( x , y ) ;
}
2010-05-09 23:23:13 +02:00
}
2011-09-27 07:29:57 +02:00
bool MenuStateRoot : : isMasterserverMode ( ) const {
2011-12-02 23:04:02 +01:00
return GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) ;
2011-09-27 07:29:57 +02:00
}
2010-09-09 08:42:39 +02:00
void MenuStateRoot : : render ( ) {
2011-09-27 07:29:57 +02:00
if ( isMasterserverMode ( ) = = true ) {
return ;
}
2010-05-09 23:23:13 +02:00
Renderer & renderer = Renderer : : getInstance ( ) ;
CoreData & coreData = CoreData : : getInstance ( ) ;
const Metrics & metrics = Metrics : : getInstance ( ) ;
2010-12-10 02:53:51 +01:00
2015-02-06 01:14:17 +01:00
int w = 400 ;
int h = 200 ;
int yPos = 510 ;
2010-05-09 23:23:13 +02:00
2011-04-13 09:29:45 +02:00
int logoMainX = ( metrics . getVirtualW ( ) - w ) / 2 ;
int logoMainY = yPos - h / 2 ;
int logoMainW = w ;
int logoMainH = h ;
logoMainX = Config : : getInstance ( ) . getInt ( string ( containerName ) + " _MainLogo_x " , intToStr ( logoMainX ) . c_str ( ) ) ;
logoMainY = Config : : getInstance ( ) . getInt ( string ( containerName ) + " _MainLogo_y " , intToStr ( logoMainY ) . c_str ( ) ) ;
logoMainW = Config : : getInstance ( ) . getInt ( string ( containerName ) + " _MainLogo_w " , intToStr ( logoMainW ) . c_str ( ) ) ;
logoMainH = Config : : getInstance ( ) . getInt ( string ( containerName ) + " _MainLogo_h " , intToStr ( logoMainH ) . c_str ( ) ) ;
2010-05-09 23:23:13 +02:00
renderer . renderTextureQuad (
2011-04-13 09:29:45 +02:00
logoMainX , logoMainY , logoMainW , logoMainH ,
2010-05-09 23:23:13 +02:00
coreData . getLogoTexture ( ) , GraphicComponent : : getFade ( ) ) ;
2010-08-06 00:27:26 +02:00
int maxLogoWidth = 0 ;
2013-11-19 07:14:06 +01:00
for ( int idx = 0 ; idx < ( int ) coreData . getLogoTextureExtraCount ( ) ; + + idx ) {
2010-08-06 00:27:26 +02:00
Texture2D * extraLogo = coreData . getLogoTextureExtra ( idx ) ;
maxLogoWidth + = extraLogo - > getPixmap ( ) - > getW ( ) ;
}
int currentX = ( metrics . getVirtualW ( ) - maxLogoWidth ) / 2 ;
int currentY = 50 ;
2013-11-19 07:14:06 +01:00
for ( int idx = 0 ; idx < ( int ) coreData . getLogoTextureExtraCount ( ) ; + + idx ) {
2010-08-06 00:27:26 +02:00
Texture2D * extraLogo = coreData . getLogoTextureExtra ( idx ) ;
2011-04-13 09:29:45 +02:00
logoMainX = currentX ;
logoMainY = currentY ;
logoMainW = extraLogo - > getPixmap ( ) - > getW ( ) ;
logoMainH = extraLogo - > getPixmap ( ) - > getH ( ) ;
string logoTagName = string ( containerName ) + " _ExtraLogo " + intToStr ( idx + 1 ) + " _ " ;
logoMainX = Config : : getInstance ( ) . getInt ( logoTagName + " x " , intToStr ( logoMainX ) . c_str ( ) ) ;
logoMainY = Config : : getInstance ( ) . getInt ( logoTagName + " y " , intToStr ( logoMainY ) . c_str ( ) ) ;
logoMainW = Config : : getInstance ( ) . getInt ( logoTagName + " w " , intToStr ( logoMainW ) . c_str ( ) ) ;
logoMainH = Config : : getInstance ( ) . getInt ( logoTagName + " h " , intToStr ( logoMainH ) . c_str ( ) ) ;
2010-08-06 00:27:26 +02:00
renderer . renderTextureQuad (
2011-04-13 09:29:45 +02:00
logoMainX , logoMainY ,
logoMainW , logoMainH ,
2010-08-06 00:27:26 +02:00
extraLogo , GraphicComponent : : getFade ( ) ) ;
2013-05-17 11:31:47 +02:00
currentX + = extraLogo - > getPixmap ( ) - > getW ( ) ;
2010-08-06 00:27:26 +02:00
}
2011-09-21 08:51:28 +02:00
2010-05-09 23:23:13 +02:00
renderer . renderButton ( & buttonNewGame ) ;
2012-03-15 00:53:11 +01:00
renderer . renderButton ( & buttonLoadGame ) ;
2011-03-25 11:11:16 +01:00
renderer . renderButton ( & buttonMods ) ;
2010-05-09 23:23:13 +02:00
renderer . renderButton ( & buttonOptions ) ;
renderer . renderButton ( & buttonAbout ) ;
renderer . renderButton ( & buttonExit ) ;
renderer . renderLabel ( & labelVersion ) ;
2017-09-24 02:15:44 +02:00
renderer . renderLabel ( & labelGreeting ) ;
2010-06-12 21:27:11 +02:00
2014-10-31 01:08:12 +01:00
renderer . renderConsole ( & console ) ;
2011-04-15 03:05:36 +02:00
2011-09-21 08:51:28 +02:00
renderer . renderPopupMenu ( & popupMenu ) ;
2010-06-12 21:27:11 +02:00
//exit message box
2011-04-24 07:39:13 +02:00
if ( mainMessageBox . getEnabled ( ) ) {
2010-06-12 21:27:11 +02:00
renderer . renderMessageBox ( & mainMessageBox ) ;
}
2011-12-05 01:02:32 +01:00
if ( errorMessageBox . getEnabled ( ) ) {
renderer . renderMessageBox ( & errorMessageBox ) ;
}
2014-12-30 21:16:35 +01:00
if ( ftpMessageBox . getEnabled ( ) ) {
renderer . renderMessageBox ( & ftpMessageBox ) ;
}
2011-09-21 08:51:28 +02:00
2010-07-08 10:29:51 +02:00
if ( program ! = NULL ) program - > renderProgramMsgBox ( ) ;
2010-05-09 23:23:13 +02:00
}
2012-03-17 09:20:17 +01:00
void MenuStateRoot : : update ( ) {
if ( Config : : getInstance ( ) . getBool ( " AutoTest " ) ) {
if ( AutoTest : : getInstance ( ) . mustExitGame ( ) = = false ) {
AutoTest : : getInstance ( ) . updateRoot ( program , mainMenu ) ;
}
else {
program - > exit ( ) ;
}
return ;
2010-05-09 23:23:13 +02:00
}
2014-12-30 21:16:35 +01:00
if ( gameUpdateChecked = = false ) {
gameUpdateChecked = true ;
string updateCheckURL = Config : : getInstance ( ) . getString ( " UpdateCheckURL " , " " ) ;
if ( updateCheckURL ! = " " ) {
static string mutexOwnerId = string ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) ) + string ( " _ " ) + intToStr ( __LINE__ ) ;
updatesHttpServerThread = new SimpleTaskThread ( this , 1 , 200 ) ;
updatesHttpServerThread - > setUniqueID ( mutexOwnerId ) ;
updatesHttpServerThread - > start ( ) ;
}
}
2011-04-15 03:05:36 +02:00
console . update ( ) ;
2010-05-09 23:23:13 +02:00
}
2014-12-30 21:16:35 +01:00
void MenuStateRoot : : simpleTask ( BaseThread * callingThread , void * userdata ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
static string mutexOwnerId = string ( __FILE__ ) + string ( " _ " ) + intToStr ( __LINE__ ) ;
MutexSafeWrapper safeMutexThreadOwner ( callingThread - > getMutexThreadOwnerValid ( ) , mutexOwnerId ) ;
if ( callingThread - > getQuitStatus ( ) = = true | | safeMutexThreadOwner . isValidMutex ( ) = = false ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
return ;
}
callingThread - > getMutexThreadOwnerValid ( ) - > setOwnerId ( mutexOwnerId ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
string updateCheckURL = Config : : getInstance ( ) . getString ( " UpdateCheckURL " , " " ) ;
if ( updateCheckURL ! = " " ) {
string baseURL = updateCheckURL ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] About to call first http url, base [%s].. \n " , __FILE__ , __FUNCTION__ , __LINE__ , baseURL . c_str ( ) ) ;
CURL * handle = SystemFlags : : initHTTP ( ) ;
CURLcode curlResult = CURLE_OK ;
string updateMetaData = SystemFlags : : getHTTP ( baseURL , handle , - 1 , & curlResult ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " techsMetaData [%s] curlResult = %d \n " , updateMetaData . c_str ( ) , curlResult ) ;
if ( callingThread - > getQuitStatus ( ) = = true | | safeMutexThreadOwner . isValidMutex ( ) = = false ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
return ;
}
if ( curlResult ! = CURLE_OK ) {
string curlError = curl_easy_strerror ( curlResult ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line %d] curlError [%s].. \n " , __FILE__ , __FUNCTION__ , __LINE__ , curlError . c_str ( ) ) ;
char szMsg [ 8096 ] = " " ;
snprintf ( szMsg , 8096 , " An error was detected while checking for new updates \n %s " , curlError . c_str ( ) ) ;
showErrorMessageBox ( szMsg , " ERROR " , false ) ;
}
if ( curlResult = = CURLE_OK | |
( curlResult ! = CURLE_COULDNT_RESOLVE_HOST & &
curlResult ! = CURLE_COULDNT_CONNECT ) ) {
Properties props ;
props . loadFromText ( updateMetaData ) ;
2015-01-01 17:16:24 +01:00
int compareResult = compareMajorMinorVersion ( glestVersionString , props . getString ( " LatestGameVersion " , " " ) ) ;
if ( compareResult = = 0 ) {
if ( glestVersionString ! = props . getString ( " LatestGameVersion " , " " ) ) {
compareResult = - 1 ;
}
}
2014-12-30 21:16:35 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " compareResult = %d local [%s] remote [%s] \n " , compareResult , glestVersionString . c_str ( ) , props . getString ( " LatestGameVersion " , " " ) . c_str ( ) ) ;
if ( compareResult < 0 ) {
string downloadBinaryKey = " LatestGameBinaryUpdateArchiveURL- " + getPlatformTypeNameString ( ) + getPlatformArchTypeNameString ( ) ;
if ( props . hasString ( downloadBinaryKey ) ) {
ftpFileName = extractFileFromDirectoryPath ( props . getString ( downloadBinaryKey ) ) ;
ftpFileURL = props . getString ( downloadBinaryKey ) ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Checking update key downloadBinaryKey [%s] ftpFileURL [%s] \n " , downloadBinaryKey . c_str ( ) , ftpFileURL . c_str ( ) ) ;
if ( props . getBool ( " AllowUpdateDownloads " , " false " ) = = false | | ftpFileURL = = " " ) {
char szMsg [ 8096 ] = " " ;
snprintf ( szMsg , 8096 , " A new update was detected: %s \n Update Date: %s \n Please visit megaglest.org for details! " ,
props . getString ( " LatestGameVersion " , " ? " ) . c_str ( ) ,
props . getString ( " LatestGameVersionReleaseDate " , " ? " ) . c_str ( ) ) ;
showFTPMessageBox ( szMsg , " Update " , false , true ) ;
}
else {
char szMsg [ 8096 ] = " " ;
snprintf ( szMsg , 8096 , " A new update was detected: %s \n Update Date: %s \n Download update now? " ,
props . getString ( " LatestGameVersion " , " ? " ) . c_str ( ) ,
props . getString ( " LatestGameVersionReleaseDate " , " ? " ) . c_str ( ) ) ;
showFTPMessageBox ( szMsg , " Update " , false , false ) ;
}
}
}
SystemFlags : : cleanupHTTP ( & handle ) ;
}
}
2011-06-26 03:55:08 +02:00
void MenuStateRoot : : keyDown ( SDL_KeyboardEvent key ) {
2010-06-12 21:27:11 +02:00
2011-06-26 03:55:08 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] key = [%c] [%d] \n " , __FILE__ , __FUNCTION__ , __LINE__ , key . keysym . sym , key . keysym . sym ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] key = [%d - %c] \n " , __FILE__ , __FUNCTION__ , __LINE__ , key . keysym . sym , key . keysym . sym ) ;
//printf("\n\n\nIN MENU STATE ROOT KEYDOWN!!!\n\n\n");
2010-06-12 21:27:11 +02:00
Config & configKeys = Config : : getInstance ( std : : pair < ConfigType , ConfigType > ( cfgMainKeys , cfgUserKeys ) ) ;
//exit
2011-06-26 03:55:08 +02:00
//if(key == configKeys.getCharKey("ExitKey")) {
2015-09-29 15:22:54 +02:00
//printf("Check Root menu exit key!\n");
2011-06-26 03:55:08 +02:00
if ( isKeyPressed ( configKeys . getSDLKey ( " ExitKey " ) , key ) = = true ) {
2010-06-12 21:27:11 +02:00
Lang & lang = Lang : : getInstance ( ) ;
2015-02-06 01:14:17 +01:00
showMessageBox ( lang . getString ( " ExitGameQuestion " ) , " " , true ) ;
2010-06-12 21:27:11 +02:00
}
2011-06-26 03:55:08 +02:00
//else if(mainMessageBox.getEnabled() == true && key == vkReturn) {
else if ( mainMessageBox . getEnabled ( ) = = true & & isKeyPressed ( SDLK_RETURN , key ) = = true ) {
2011-06-28 03:25:14 +02:00
//SDL_keysym keystate = Window::getKeystate();
SDL_keysym keystate = key . keysym ;
2011-05-20 22:02:26 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] keystate.mod [%d] \n " , __FILE__ , __FUNCTION__ , __LINE__ , keystate . mod ) ;
//printf("---> keystate.mod [%d]\n",keystate.mod);
if ( keystate . mod & ( KMOD_LALT | KMOD_RALT ) ) {
}
else {
//printf("EXITING ---> keystate.mod [%d]\n",keystate.mod);
program - > exit ( ) ;
}
2010-06-12 21:27:11 +02:00
}
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("SaveGUILayout")) {
else if ( isKeyPressed ( configKeys . getSDLKey ( " SaveGUILayout " ) , key ) = = true ) {
2011-09-01 03:11:23 +02:00
GraphicComponent : : saveAllCustomProperties ( containerName ) ;
2010-09-09 23:07:39 +02:00
//Lang &lang= Lang::getInstance();
2013-10-29 07:13:38 +01:00
//console.addLine(lang.getString("GUILayoutSaved") + " [" + (saved ? lang.getString("Yes") : lang.getString("No"))+ "]");
2010-09-09 23:07:39 +02:00
}
2010-06-12 21:27:11 +02:00
}
2014-12-30 21:16:35 +01:00
void MenuStateRoot : : showMessageBox ( const string & text , const string & header , bool toggle ) {
if ( toggle = = false ) {
2010-06-12 21:27:11 +02:00
mainMessageBox . setEnabled ( false ) ;
}
2014-12-30 21:16:35 +01:00
if ( mainMessageBox . getEnabled ( ) = = false ) {
2010-06-12 21:27:11 +02:00
mainMessageBox . setText ( text ) ;
mainMessageBox . setHeader ( header ) ;
mainMessageBox . setEnabled ( true ) ;
}
2014-12-30 21:16:35 +01:00
else {
2010-06-12 21:27:11 +02:00
mainMessageBox . setEnabled ( false ) ;
}
}
2014-12-30 21:16:35 +01:00
void MenuStateRoot : : showErrorMessageBox ( const string & text , const string & header , bool toggle ) {
if ( toggle = = false ) {
2011-12-05 01:02:32 +01:00
errorMessageBox . setEnabled ( false ) ;
}
2014-12-30 21:16:35 +01:00
if ( errorMessageBox . getEnabled ( ) = = false ) {
2011-12-05 01:02:32 +01:00
errorMessageBox . setText ( text ) ;
errorMessageBox . setHeader ( header ) ;
errorMessageBox . setEnabled ( true ) ;
}
2014-12-30 21:16:35 +01:00
else {
2011-12-05 01:02:32 +01:00
errorMessageBox . setEnabled ( false ) ;
}
}
2014-12-30 21:16:35 +01:00
void MenuStateRoot : : showFTPMessageBox ( const string & text , const string & header , bool toggle , bool okOnly ) {
if ( toggle = = false ) {
ftpMessageBox . setEnabled ( false ) ;
}
Lang & lang = Lang : : getInstance ( ) ;
if ( okOnly ) {
ftpMessageBox . init ( lang . getString ( " Ok " ) ) ;
}
else {
ftpMessageBox . init ( lang . getString ( " Yes " ) , lang . getString ( " No " ) ) ;
}
if ( ftpMessageBox . getEnabled ( ) = = false ) {
ftpMessageBox . setText ( text ) ;
ftpMessageBox . setHeader ( header ) ;
ftpMessageBox . setEnabled ( true ) ;
}
else {
ftpMessageBox . setEnabled ( false ) ;
}
}
2010-05-09 23:23:13 +02:00
} } //end namespace