2010-04-22 01:13:39 +02:00
// ==============================================================
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2005 Marti<74> o Figueroa
//
// 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
// License, or (at your option) any later version
// ==============================================================
# include "menu_state_connected_game.h"
# include "menu_state_join_game.h"
2010-05-09 23:23:13 +02:00
# include "menu_state_masterserver.h"
2010-04-22 01:13:39 +02:00
# include "renderer.h"
# include "sound_renderer.h"
# include "core_data.h"
# include "config.h"
# include "menu_state_new_game.h"
# include "metrics.h"
# include "network_manager.h"
# include "network_message.h"
# include "client_interface.h"
# include "conversion.h"
# include "socket.h"
# include "game.h"
# include <algorithm>
# include <time.h>
# include "leak_dumper.h"
namespace Glest { namespace Game {
using namespace Shared : : Util ;
struct FormatString {
void operator ( ) ( string & s ) {
s = formatString ( s ) ;
}
} ;
// =====================================================
// class MenuStateConnectedGame
// =====================================================
2010-05-09 23:23:13 +02:00
MenuStateConnectedGame : : MenuStateConnectedGame ( Program * program , MainMenu * mainMenu , JoinMenu joinMenuInfo , bool openNetworkSlots ) :
2010-05-16 18:40:21 +02:00
MenuState ( program , mainMenu , " connected-game " ) //← set on connected-game
2010-04-22 01:13:39 +02:00
{
2010-08-23 06:33:21 +02:00
switchSetupRequestFlagType | = ssrft_NetworkPlayerName ;
2010-08-22 10:00:05 +02:00
updateDataSynchDetailText = false ;
2010-08-21 15:04:52 +02:00
activeInputLabel = NULL ;
2010-07-09 20:02:31 +02:00
lastNetworkSendPing = 0 ;
2010-07-09 20:49:01 +02:00
pingCount = 0 ;
2010-04-22 01:13:39 +02:00
needToSetChangedGameSettings = false ;
2010-04-29 01:59:37 +02:00
lastSetChangedGameSettings = time ( NULL ) ;
2010-06-09 00:50:37 +02:00
showFullConsole = false ;
2010-04-23 01:18:04 +02:00
currentFactionName = " " ;
currentMap = " " ;
settingsReceivedFromServer = false ;
2010-08-05 02:48:46 +02:00
initialSettingsReceivedFromServer = false ;
returnMenuInfo = joinMenuInfo ;
Lang & lang = Lang : : getInstance ( ) ;
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
Config & config = Config : : getInstance ( ) ;
2010-08-23 06:33:21 +02:00
defaultPlayerName = config . getString ( " NetPlayerName " , Socket : : getHostName ( ) . c_str ( ) ) ;
2010-04-23 01:18:04 +02:00
2010-08-05 02:48:46 +02:00
labelMapInfo . setText ( " ? " ) ;
2010-04-23 01:18:04 +02:00
2010-04-22 01:13:39 +02:00
vector < string > teamItems , controlItems , results ;
//state
2010-08-05 07:58:14 +02:00
labelStatus . init ( 230 , 700 ) ;
2010-04-22 01:13:39 +02:00
labelStatus . setText ( " " ) ;
labelInfo . init ( 30 , 700 ) ;
labelInfo . setText ( " " ) ;
//create
2010-08-06 00:27:26 +02:00
buttonDisconnect . init ( 350 , 180 , 125 ) ;
buttonPlayNow . init ( 525 , 180 , 125 ) ;
2010-04-22 01:13:39 +02:00
//map listBox
// put them all in a set, to weed out duplicates (gbm & mgm with same name)
// will also ensure they are alphabetically listed (rather than how the OS provides them)
listBoxMap . init ( 100 , 260 , 200 ) ;
listBoxMap . setEditable ( false ) ;
2010-08-05 01:39:12 +02:00
int setupPos = 610 ;
2010-08-06 00:27:26 +02:00
int mapHeadPos = 330 ;
2010-08-05 01:39:12 +02:00
int mapPos = mapHeadPos - 30 ;
2010-08-06 00:27:26 +02:00
int aHeadPos = 260 ;
2010-08-05 01:39:12 +02:00
int aPos = aHeadPos - 30 ;
int networkHeadPos = 670 ;
int networkPos = networkHeadPos - 30 ;
2010-04-22 01:13:39 +02:00
//listBoxMap.setItems(results);
2010-08-05 01:39:12 +02:00
labelMap . init ( 100 , mapHeadPos ) ;
listBoxMap . init ( 100 , mapPos , 200 ) ;
2010-04-22 01:13:39 +02:00
// fog - o - war
// @350 ? 300 ?
2010-08-05 01:39:12 +02:00
labelFogOfWar . init ( 300 , aHeadPos , 80 ) ;
listBoxFogOfWar . init ( 300 , aPos , 80 ) ;
2010-04-22 01:13:39 +02:00
listBoxFogOfWar . pushBackItem ( lang . get ( " Yes " ) ) ;
listBoxFogOfWar . pushBackItem ( lang . get ( " No " ) ) ;
listBoxFogOfWar . setSelectedItemIndex ( 0 ) ;
listBoxFogOfWar . setEditable ( false ) ;
2010-08-05 01:39:12 +02:00
// Enable Observer Mode
labelEnableObserverMode . init ( 400 , aHeadPos , 80 ) ;
listBoxEnableObserverMode . init ( 400 , aPos , 110 ) ;
listBoxEnableObserverMode . pushBackItem ( lang . get ( " Yes " ) ) ;
listBoxEnableObserverMode . pushBackItem ( lang . get ( " No " ) ) ;
listBoxEnableObserverMode . setSelectedItemIndex ( 0 ) ;
listBoxEnableObserverMode . setEditable ( false ) ;
labelEnableObserverMode . setText ( lang . get ( " EnableObserverMode " ) ) ;
labelPathFinderType . init ( 540 , aHeadPos , 80 ) ;
labelPathFinderType . setText ( lang . get ( " PathFinderType " ) ) ;
listBoxPathFinderType . init ( 540 , aPos , 140 ) ;
listBoxPathFinderType . pushBackItem ( lang . get ( " PathFinderTypeRegular " ) ) ;
listBoxPathFinderType . pushBackItem ( lang . get ( " PathFinderTypeRoutePlanner " ) ) ;
listBoxPathFinderType . setSelectedItemIndex ( 0 ) ;
listBoxPathFinderType . setEditable ( false ) ;
// Network Frame Period
labelNetworkFramePeriod . init ( 370 , networkHeadPos , 80 ) ;
labelNetworkFramePeriod . setText ( lang . get ( " NetworkFramePeriod " ) ) ;
listBoxNetworkFramePeriod . init ( 380 , networkPos , 80 ) ;
listBoxNetworkFramePeriod . pushBackItem ( " 10 " ) ;
listBoxNetworkFramePeriod . pushBackItem ( " 20 " ) ;
listBoxNetworkFramePeriod . pushBackItem ( " 30 " ) ;
listBoxNetworkFramePeriod . pushBackItem ( " 40 " ) ;
listBoxNetworkFramePeriod . setSelectedItem ( " 20 " ) ;
listBoxNetworkFramePeriod . setEditable ( false ) ;
// Network Frame Period
labelNetworkPauseGameForLaggedClients . init ( 530 , networkHeadPos , 80 ) ;
labelNetworkPauseGameForLaggedClients . setText ( lang . get ( " NetworkPauseGameForLaggedClients " ) ) ;
listBoxNetworkPauseGameForLaggedClients . init ( 540 , networkPos , 80 ) ;
listBoxNetworkPauseGameForLaggedClients . pushBackItem ( lang . get ( " No " ) ) ;
listBoxNetworkPauseGameForLaggedClients . pushBackItem ( lang . get ( " Yes " ) ) ;
listBoxNetworkPauseGameForLaggedClients . setSelectedItem ( lang . get ( " No " ) ) ;
listBoxNetworkPauseGameForLaggedClients . setEditable ( false ) ;
// Enable Server Controlled AI
labelEnableServerControlledAI . init ( 670 , networkHeadPos , 80 ) ;
labelEnableServerControlledAI . setText ( lang . get ( " EnableServerControlledAI " ) ) ;
listBoxEnableServerControlledAI . init ( 680 , networkPos , 80 ) ;
listBoxEnableServerControlledAI . pushBackItem ( lang . get ( " Yes " ) ) ;
listBoxEnableServerControlledAI . pushBackItem ( lang . get ( " No " ) ) ;
listBoxEnableServerControlledAI . setSelectedItemIndex ( 0 ) ;
listBoxEnableServerControlledAI . setEditable ( false ) ;
2010-04-22 01:13:39 +02:00
//tileset listBox
2010-08-05 01:39:12 +02:00
//listBoxTileset.init(500, 260, 150);
listBoxTileset . init ( 400 , mapPos , 150 ) ;
2010-04-22 01:13:39 +02:00
listBoxTileset . setEditable ( false ) ;
//listBoxTileset.setItems(results);
2010-08-05 01:39:12 +02:00
//labelTileset.init(500, 290);
labelTileset . init ( 400 , mapHeadPos ) ;
2010-04-22 01:13:39 +02:00
//tech Tree listBox
2010-08-05 01:39:12 +02:00
//listBoxTechTree.init(700, 260, 150);
2010-04-22 01:13:39 +02:00
listBoxTechTree . setEditable ( false ) ;
//listBoxTechTree.setItems(results);
2010-08-05 01:39:12 +02:00
//labelTechTree.init(700, 290);
listBoxTechTree . init ( 600 , mapPos , 150 ) ;
labelTechTree . init ( 600 , mapHeadPos ) ;
2010-04-22 01:13:39 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
//list boxes
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
2010-08-21 15:04:52 +02:00
labelPlayers [ i ] . init ( 50 , setupPos - 30 - i * 30 ) ;
2010-04-22 01:13:39 +02:00
labelPlayers [ i ] . setEditable ( false ) ;
2010-08-21 15:04:52 +02:00
labelPlayerNames [ i ] . init ( 100 , setupPos - 30 - i * 30 ) ;
2010-08-06 00:27:26 +02:00
listBoxControls [ i ] . init ( 200 , setupPos - 30 - i * 30 ) ;
2010-04-22 01:13:39 +02:00
listBoxControls [ i ] . setEditable ( false ) ;
2010-08-06 00:27:26 +02:00
listBoxFactions [ i ] . init ( 400 , setupPos - 30 - i * 30 ) ;
2010-04-22 01:13:39 +02:00
listBoxFactions [ i ] . setEditable ( false ) ;
2010-08-06 00:27:26 +02:00
listBoxTeams [ i ] . init ( 600 , setupPos - 30 - i * 30 , 60 ) ;
2010-04-22 01:13:39 +02:00
listBoxTeams [ i ] . setEditable ( false ) ;
2010-08-06 00:27:26 +02:00
labelNetStatus [ i ] . init ( 700 , setupPos - 30 - i * 30 , 60 ) ;
grabSlotButton [ i ] . init ( 700 , setupPos - 30 - i * 30 , 30 ) ;
2010-04-29 01:59:37 +02:00
grabSlotButton [ i ] . setText ( " > " ) ;
2010-04-22 01:13:39 +02:00
}
2010-08-06 00:27:26 +02:00
labelControl . init ( 200 , setupPos , GraphicListBox : : defW , GraphicListBox : : defH , true ) ;
labelFaction . init ( 400 , setupPos , GraphicListBox : : defW , GraphicListBox : : defH , true ) ;
labelTeam . init ( 600 , setupPos , 60 , GraphicListBox : : defH , true ) ;
labelControl . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
labelFaction . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
labelTeam . setFont ( CoreData : : getInstance ( ) . getMenuFontBig ( ) ) ;
2010-04-22 01:13:39 +02:00
//texts
buttonDisconnect . setText ( lang . get ( " Return " ) ) ;
buttonPlayNow . setText ( lang . get ( " PlayNow " ) ) ;
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 ( " Human " ) ) ;
teamItems . push_back ( " 1 " ) ;
teamItems . push_back ( " 2 " ) ;
teamItems . push_back ( " 3 " ) ;
teamItems . push_back ( " 4 " ) ;
teamItems . push_back ( " 5 " ) ;
teamItems . push_back ( " 6 " ) ;
teamItems . push_back ( " 7 " ) ;
teamItems . push_back ( " 8 " ) ;
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
labelPlayers [ i ] . setText ( lang . get ( " Player " ) + " " + intToStr ( i ) ) ;
2010-08-21 15:04:52 +02:00
labelPlayerNames [ i ] . setText ( " " ) ;
2010-04-22 01:13:39 +02:00
listBoxTeams [ i ] . setItems ( teamItems ) ;
listBoxTeams [ i ] . setSelectedItemIndex ( i ) ;
listBoxControls [ i ] . setItems ( controlItems ) ;
2010-04-23 01:18:04 +02:00
labelNetStatus [ i ] . setText ( " V " ) ;
2010-04-22 01:13:39 +02:00
}
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
labelMap . setText ( lang . get ( " Map " ) ) ;
labelFogOfWar . setText ( lang . get ( " FogOfWar " ) ) ;
labelTileset . setText ( lang . get ( " Tileset " ) ) ;
labelTechTree . setText ( lang . get ( " TechTree " ) ) ;
labelControl . setText ( lang . get ( " Control " ) ) ;
labelFaction . setText ( lang . get ( " Faction " ) ) ;
labelTeam . setText ( lang . get ( " Team " ) ) ;
2010-08-05 02:48:46 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
labelMapInfo . setText ( mapInfo . desc ) ;
//init controllers
listBoxControls [ 0 ] . setSelectedItemIndex ( ctHuman ) ;
2010-08-21 15:04:52 +02:00
2010-06-09 00:50:37 +02:00
chatManager . init ( & console , - 1 , true ) ;
2010-04-22 01:13:39 +02:00
}
void MenuStateConnectedGame : : mouseClick ( int x , int y , MouseButton mouseButton ) {
CoreData & coreData = CoreData : : getInstance ( ) ;
SoundRenderer & soundRenderer = SoundRenderer : : getInstance ( ) ;
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
if ( buttonDisconnect . mouseClick ( x , y ) ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
soundRenderer . playFx ( coreData . getClickSoundA ( ) ) ;
if ( clientInterface - > getSocket ( ) ! = NULL )
{
if ( clientInterface - > isConnected ( ) = = true )
{
2010-08-22 10:00:05 +02:00
string sQuitText = " chose to leave the game! " ;
2010-04-22 01:13:39 +02:00
clientInterface - > sendTextMessage ( sQuitText , - 1 ) ;
2010-07-02 18:54:28 +02:00
sleep ( 1 ) ;
2010-04-22 01:13:39 +02:00
}
clientInterface - > close ( ) ;
}
clientInterface - > reset ( ) ;
networkManager . end ( ) ;
currentFactionName = " " ;
currentMap = " " ;
2010-05-09 23:23:13 +02:00
returnToJoinMenu ( ) ;
2010-08-05 02:48:46 +02:00
return ;
2010-04-22 01:13:39 +02:00
}
2010-08-05 02:48:46 +02:00
if ( ! initialSettingsReceivedFromServer ) return ;
2010-06-30 16:51:30 +02:00
// Only allow changes after we get game settings from the server
2010-08-05 12:42:31 +02:00
//if( clientInterface->isConnected() == true &&
// clientInterface->getGameSettingsReceived() == true) {
if ( clientInterface - > isConnected ( ) = = true ) {
2010-06-30 16:51:30 +02:00
if ( buttonPlayNow . mouseClick ( x , y ) & & buttonPlayNow . getEnabled ( ) ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
soundRenderer . playFx ( coreData . getClickSoundC ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-04-30 03:08:29 +02:00
}
2010-06-30 16:51:30 +02:00
else
2010-04-29 01:59:37 +02:00
{
2010-06-30 16:51:30 +02:00
int myCurrentIndex = - 1 ;
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i )
{ // find my current index by looking at editable listBoxes
if ( listBoxFactions [ i ] . getEditable ( ) ) {
myCurrentIndex = i ;
2010-04-29 01:59:37 +02:00
}
}
2010-06-30 16:51:30 +02:00
if ( myCurrentIndex ! = - 1 )
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i )
{
2010-08-23 06:33:21 +02:00
if ( listBoxFactions [ i ] . getEditable ( ) ) {
if ( listBoxFactions [ i ] . mouseClick ( x , y ) ) {
2010-06-30 16:51:30 +02:00
soundRenderer . playFx ( coreData . getClickSoundA ( ) ) ;
ClientInterface * clientInterface = NetworkManager : : getInstance ( ) . getClientInterface ( ) ;
2010-08-23 06:33:21 +02:00
if ( clientInterface - > isConnected ( ) ) {
2010-06-30 16:51:30 +02:00
clientInterface - > setGameSettingsReceived ( false ) ;
2010-08-23 06:33:21 +02:00
clientInterface - > sendSwitchSetupRequest ( listBoxFactions [ i ] . getSelectedItem ( ) , i , - 1 , listBoxTeams [ i ] . getSelectedItemIndex ( ) , getHumanPlayerName ( ) , switchSetupRequestFlagType ) ;
switchSetupRequestFlagType = ssrft_None ;
2010-06-30 16:51:30 +02:00
}
break ;
2010-04-29 01:59:37 +02:00
}
2010-04-30 03:08:29 +02:00
}
2010-08-23 06:33:21 +02:00
if ( listBoxTeams [ i ] . getEditable ( ) ) {
if ( listBoxTeams [ i ] . mouseClick ( x , y ) ) {
2010-06-30 16:51:30 +02:00
soundRenderer . playFx ( coreData . getClickSoundA ( ) ) ;
2010-08-23 06:33:21 +02:00
if ( clientInterface - > isConnected ( ) ) {
2010-06-30 16:51:30 +02:00
clientInterface - > setGameSettingsReceived ( false ) ;
2010-08-23 06:33:21 +02:00
clientInterface - > sendSwitchSetupRequest ( listBoxFactions [ i ] . getSelectedItem ( ) , i , - 1 , listBoxTeams [ i ] . getSelectedItemIndex ( ) , getHumanPlayerName ( ) , switchSetupRequestFlagType ) ;
switchSetupRequestFlagType = ssrft_None ;
2010-06-30 16:51:30 +02:00
}
break ;
}
}
if ( ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork ) & &
( labelNetStatus [ i ] . getText ( ) = = GameConstants : : NETWORK_SLOT_UNCONNECTED_SLOTNAME ) ) {
if ( grabSlotButton [ i ] . mouseClick ( x , y ) )
{
soundRenderer . playFx ( coreData . getClickSoundA ( ) ) ;
clientInterface - > setGameSettingsReceived ( false ) ;
settingsReceivedFromServer = false ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] sending a switchSlot request from %d to %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , clientInterface - > getGameSettings ( ) - > getThisFactionIndex ( ) , i ) ;
2010-08-23 06:33:21 +02:00
clientInterface - > sendSwitchSetupRequest ( listBoxFactions [ myCurrentIndex ] . getSelectedItem ( ) , myCurrentIndex , i , listBoxTeams [ myCurrentIndex ] . getSelectedItemIndex ( ) , getHumanPlayerName ( ) , switchSetupRequestFlagType ) ;
switchSetupRequestFlagType = ssrft_None ;
2010-06-30 16:51:30 +02:00
break ;
}
2010-04-29 01:59:37 +02:00
}
2010-08-21 15:04:52 +02:00
if ( labelPlayerNames [ i ] . mouseClick ( x , y ) & & ( activeInputLabel ! = & labelPlayerNames [ i ] ) ) {
if ( clientInterface - > getGameSettings ( ) ! = NULL & &
i = = clientInterface - > getGameSettings ( ) - > getThisFactionIndex ( ) ) {
setActiveInputLabel ( & labelPlayerNames [ i ] ) ;
}
}
2010-04-29 01:59:37 +02:00
}
}
2010-04-22 01:13:39 +02:00
}
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
2010-07-02 18:54:28 +02:00
void MenuStateConnectedGame : : returnToJoinMenu ( ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( returnMenuInfo = = jmSimple ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-05-09 23:23:13 +02:00
mainMenu - > setState ( new MenuStateJoinGame ( program , mainMenu ) ) ;
}
2010-07-02 18:54:28 +02:00
else {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-05-09 23:23:13 +02:00
mainMenu - > setState ( new MenuStateMasterserver ( program , mainMenu ) ) ;
}
}
2010-04-22 01:13:39 +02:00
void MenuStateConnectedGame : : mouseMove ( int x , int y , const MouseState * ms ) {
buttonDisconnect . mouseMove ( x , y ) ;
buttonPlayNow . mouseMove ( x , y ) ;
2010-08-21 15:04:52 +02:00
bool editingPlayerName = false ;
2010-04-22 01:13:39 +02:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
listBoxControls [ i ] . mouseMove ( x , y ) ;
listBoxFactions [ i ] . mouseMove ( x , y ) ;
listBoxTeams [ i ] . mouseMove ( x , y ) ;
2010-04-30 03:08:29 +02:00
grabSlotButton [ i ] . mouseMove ( x , y ) ;
2010-08-21 15:04:52 +02:00
if ( labelPlayerNames [ i ] . mouseMove ( x , y ) = = true ) {
editingPlayerName = true ;
}
2010-04-22 01:13:39 +02:00
}
2010-08-21 15:04:52 +02:00
if ( editingPlayerName = = false ) {
setActiveInputLabel ( NULL ) ;
}
2010-04-22 01:13:39 +02:00
listBoxMap . mouseMove ( x , y ) ;
listBoxFogOfWar . mouseMove ( x , y ) ;
listBoxTileset . mouseMove ( x , y ) ;
listBoxTechTree . mouseMove ( x , y ) ;
2010-08-05 01:39:12 +02:00
2010-04-22 01:13:39 +02:00
}
void MenuStateConnectedGame : : render ( ) {
try {
2010-07-09 17:59:49 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
2010-07-08 10:29:51 +02:00
2010-08-05 02:48:46 +02:00
if ( ! initialSettingsReceivedFromServer ) return ;
2010-07-08 10:29:51 +02:00
2010-07-09 17:59:49 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
2010-07-08 10:29:51 +02:00
2010-04-22 01:13:39 +02:00
Renderer & renderer = Renderer : : getInstance ( ) ;
2010-07-09 17:59:49 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
2010-07-08 10:29:51 +02:00
2010-04-22 01:13:39 +02:00
int i ;
renderer . renderButton ( & buttonDisconnect ) ;
2010-04-30 03:08:29 +02:00
//renderer.renderButton(&buttonPlayNow);
2010-04-22 01:13:39 +02:00
2010-07-09 17:59:49 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
2010-07-08 10:29:51 +02:00
2010-04-22 01:13:39 +02:00
for ( i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
renderer . renderLabel ( & labelPlayers [ i ] ) ;
renderer . renderListBox ( & listBoxControls [ i ] ) ;
if ( listBoxControls [ i ] . getSelectedItemIndex ( ) ! = ctClosed ) {
renderer . renderListBox ( & listBoxFactions [ i ] ) ;
renderer . renderListBox ( & listBoxTeams [ i ] ) ;
2010-04-23 01:18:04 +02:00
//renderer.renderLabel(&labelNetStatus[i]);
2010-06-29 08:50:35 +02:00
if ( ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork ) & &
( labelNetStatus [ i ] . getText ( ) = = GameConstants : : NETWORK_SLOT_UNCONNECTED_SLOTNAME ) ) {
2010-04-29 01:59:37 +02:00
renderer . renderButton ( & grabSlotButton [ i ] ) ;
}
else if ( ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork ) | |
2010-04-23 01:18:04 +02:00
( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctHuman ) ) {
renderer . renderLabel ( & labelNetStatus [ i ] ) ;
}
2010-08-21 15:04:52 +02:00
if ( ( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctNetwork ) | |
( listBoxControls [ i ] . getSelectedItemIndex ( ) = = ctHuman ) ) {
if ( labelNetStatus [ i ] . getText ( ) ! = GameConstants : : NETWORK_SLOT_UNCONNECTED_SLOTNAME ) {
renderer . renderLabel ( & labelPlayerNames [ i ] ) ;
}
}
2010-04-22 01:13:39 +02:00
}
}
2010-07-09 17:59:49 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
2010-07-08 10:29:51 +02:00
2010-04-22 01:13:39 +02:00
renderer . renderLabel ( & labelStatus ) ;
renderer . renderLabel ( & labelInfo ) ;
renderer . renderLabel ( & labelMap ) ;
renderer . renderLabel ( & labelFogOfWar ) ;
renderer . renderLabel ( & labelTileset ) ;
renderer . renderLabel ( & labelTechTree ) ;
renderer . renderLabel ( & labelControl ) ;
renderer . renderLabel ( & labelFaction ) ;
renderer . renderLabel ( & labelTeam ) ;
2010-08-05 02:51:39 +02:00
//renderer.renderLabel(&labelMapInfo);
2010-04-22 01:13:39 +02:00
renderer . renderListBox ( & listBoxMap ) ;
renderer . renderListBox ( & listBoxFogOfWar ) ;
renderer . renderListBox ( & listBoxTileset ) ;
renderer . renderListBox ( & listBoxTechTree ) ;
2010-08-05 01:39:12 +02:00
renderer . renderLabel ( & labelEnableObserverMode ) ;
renderer . renderLabel ( & labelPathFinderType ) ;
renderer . renderListBox ( & listBoxEnableObserverMode ) ;
renderer . renderListBox ( & listBoxPathFinderType ) ;
renderer . renderListBox ( & listBoxEnableServerControlledAI ) ;
renderer . renderLabel ( & labelEnableServerControlledAI ) ;
renderer . renderLabel ( & labelNetworkFramePeriod ) ;
renderer . renderListBox ( & listBoxNetworkFramePeriod ) ;
renderer . renderLabel ( & labelNetworkPauseGameForLaggedClients ) ;
renderer . renderListBox ( & listBoxNetworkPauseGameForLaggedClients ) ;
2010-07-08 10:29:51 +02:00
if ( program ! = NULL ) program - > renderProgramMsgBox ( ) ;
2010-04-22 01:13:39 +02:00
renderer . renderChatManager ( & chatManager ) ;
2010-06-09 00:50:37 +02:00
renderer . renderConsole ( & console , showFullConsole , true ) ;
2010-04-22 01:13:39 +02:00
}
catch ( const std : : exception & ex ) {
char szBuf [ 1024 ] = " " ;
sprintf ( szBuf , " In [%s::%s %d] error [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
throw runtime_error ( szBuf ) ;
}
}
2010-08-23 06:33:21 +02:00
void MenuStateConnectedGame : : update ( ) {
2010-04-22 01:13:39 +02:00
ClientInterface * clientInterface = NetworkManager : : getInstance ( ) . getClientInterface ( ) ;
Lang & lang = Lang : : getInstance ( ) ;
2010-07-09 20:02:31 +02:00
if ( clientInterface ! = NULL & & clientInterface - > isConnected ( ) ) {
if ( difftime ( time ( NULL ) , lastNetworkSendPing ) > = GameConstants : : networkPingInterval ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] about to sendPingMessage... \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-07-09 17:59:49 +02:00
2010-07-09 20:02:31 +02:00
lastNetworkSendPing = time ( NULL ) ;
clientInterface - > sendPingMessage ( GameConstants : : networkPingInterval , time ( NULL ) ) ;
2010-07-09 19:12:57 +02:00
2010-07-09 20:49:01 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] pingCount = %d, clientInterface->getLastPingLag() = %f, GameConstants::networkPingInterval = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , pingCount , clientInterface - > getLastPingLag ( ) , GameConstants : : networkPingInterval ) ;
// Starting checking timeout after sending at least 3 pings to server
if ( pingCount > = 3 & & clientInterface - > getLastPingLag ( ) > = ( GameConstants : : networkPingInterval * 3 ) ) {
2010-08-21 15:04:52 +02:00
string playerNameStr = getHumanPlayerName ( ) ;
clientInterface - > sendTextMessage ( " connection timed out communicating with server. " , - 1 ) ;
2010-07-09 20:02:31 +02:00
clientInterface - > close ( ) ;
}
2010-07-09 20:49:01 +02:00
pingCount + + ;
2010-07-09 19:12:57 +02:00
}
2010-07-09 17:01:49 +02:00
}
2010-04-22 01:13:39 +02:00
//update status label
2010-07-08 10:29:51 +02:00
if ( clientInterface ! = NULL & & clientInterface - > isConnected ( ) ) {
2010-04-22 01:13:39 +02:00
buttonDisconnect . setText ( lang . get ( " Disconnect " ) ) ;
2010-08-22 10:00:05 +02:00
if ( clientInterface - > getAllowDownloadDataSynch ( ) = = false ) {
2010-04-22 01:13:39 +02:00
string label = lang . get ( " ConnectedToServer " ) ;
2010-08-22 10:00:05 +02:00
if ( ! clientInterface - > getServerName ( ) . empty ( ) ) {
2010-04-22 01:13:39 +02:00
label = label + " " + clientInterface - > getServerName ( ) ;
}
2010-08-05 07:58:14 +02:00
label = label + " , " + clientInterface - > getVersionString ( ) ;
2010-04-22 01:13:39 +02:00
if ( clientInterface - > getAllowGameDataSynchCheck ( ) = = true & &
2010-08-22 10:00:05 +02:00
clientInterface - > getNetworkGameDataSynchCheckOk ( ) = = false ) {
label = label + " -synch mismatch for: " ;
if ( clientInterface - > getNetworkGameDataSynchCheckOkMap ( ) = = false ) {
2010-04-22 01:13:39 +02:00
label = label + " map " ;
2010-08-22 10:00:05 +02:00
if ( updateDataSynchDetailText = = true & &
clientInterface - > getReceivedDataSynchCheck ( ) & &
lastMapDataSynchError ! = " map CRC mismatch " ) {
lastMapDataSynchError = " map CRC mismatch " ;
clientInterface - > sendTextMessage ( lastMapDataSynchError , - 1 , true ) ;
}
2010-04-22 01:13:39 +02:00
}
2010-08-22 10:00:05 +02:00
else {
lastMapDataSynchError = " " ;
}
if ( clientInterface - > getNetworkGameDataSynchCheckOkTile ( ) = = false ) {
2010-04-22 01:13:39 +02:00
label = label + " tile " ;
2010-08-22 10:00:05 +02:00
if ( updateDataSynchDetailText = = true & &
clientInterface - > getReceivedDataSynchCheck ( ) & &
lastTileDataSynchError ! = " tile CRC mismatch " ) {
lastTileDataSynchError = " tile CRC mismatch " ;
clientInterface - > sendTextMessage ( lastTileDataSynchError , - 1 , true ) ;
}
2010-04-22 01:13:39 +02:00
}
2010-08-22 10:00:05 +02:00
else {
lastTileDataSynchError = " " ;
}
if ( clientInterface - > getNetworkGameDataSynchCheckOkTech ( ) = = false ) {
2010-04-22 01:13:39 +02:00
label = label + " techtree " ;
2010-08-22 10:00:05 +02:00
if ( updateDataSynchDetailText = = true & &
clientInterface - > getReceivedDataSynchCheck ( ) ) {
string report = clientInterface - > getNetworkGameDataSynchCheckTechMismatchReport ( ) ;
if ( lastTechtreeDataSynchError ! = " techtree CRC mismatch " + report ) {
lastTechtreeDataSynchError = " techtree CRC mismatch " + report ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] report: %s \n " , __FILE__ , __FUNCTION__ , __LINE__ , report . c_str ( ) ) ;
clientInterface - > sendTextMessage ( " techtree CRC mismatch " , - 1 , true ) ;
vector < string > reportLineTokens ;
Tokenize ( report , reportLineTokens , " \n " ) ;
for ( int reportLine = 0 ; reportLine < reportLineTokens . size ( ) ; + + reportLine ) {
clientInterface - > sendTextMessage ( reportLineTokens [ reportLine ] , - 1 , true ) ;
}
}
}
}
else {
lastTechtreeDataSynchError = " " ;
}
if ( clientInterface - > getReceivedDataSynchCheck ( ) = = true ) {
updateDataSynchDetailText = false ;
2010-04-22 01:13:39 +02:00
}
//if(clientInterface->getNetworkGameDataSynchCheckOkFogOfWar() == false)
//{
// label = label + " FogOfWar == false";
//}
}
2010-08-23 06:33:21 +02:00
else if ( clientInterface - > getAllowGameDataSynchCheck ( ) = = true ) {
2010-04-22 01:13:39 +02:00
label + = " - data synch is ok " ;
}
2010-08-05 01:39:12 +02:00
//std::string networkFrameString = lang.get("NetworkFramePeriod") + " " + intToStr(clientInterface->getGameSettings()->getNetworkFramePeriod());
2010-07-02 04:50:20 +02:00
//float pingTime = clientInterface->getThreadedPingMS(clientInterface->getServerIpAddress().c_str());
2010-08-05 01:39:12 +02:00
//char szBuf[1024]="";
2010-07-02 04:50:20 +02:00
//sprintf(szBuf,"%s, ping = %.2fms, %s",label.c_str(),pingTime,networkFrameString.c_str());
2010-08-05 01:39:12 +02:00
//sprintf(szBuf,"%s, %s",label.c_str(),networkFrameString.c_str());
2010-06-04 21:42:58 +02:00
2010-08-05 01:39:12 +02:00
//labelStatus.setText(szBuf);
labelStatus . setText ( label ) ;
2010-04-22 01:13:39 +02:00
}
2010-08-23 06:33:21 +02:00
else {
2010-04-22 01:13:39 +02:00
string label = lang . get ( " ConnectedToServer " ) ;
2010-08-23 06:33:21 +02:00
if ( ! clientInterface - > getServerName ( ) . empty ( ) ) {
2010-04-22 01:13:39 +02:00
label = label + " " + clientInterface - > getServerName ( ) ;
}
if ( clientInterface - > getAllowGameDataSynchCheck ( ) = = true & &
clientInterface - > getNetworkGameDataSynchCheckOk ( ) = = false )
{
2010-08-22 10:00:05 +02:00
label = label + " -waiting to synch: " ;
2010-04-22 01:13:39 +02:00
if ( clientInterface - > getNetworkGameDataSynchCheckOkMap ( ) = = false )
{
label = label + " map " ;
}
if ( clientInterface - > getNetworkGameDataSynchCheckOkTile ( ) = = false )
{
label = label + " tile " ;
}
if ( clientInterface - > getNetworkGameDataSynchCheckOkTech ( ) = = false )
{
label = label + " techtree " ;
}
//if(clientInterface->getNetworkGameDataSynchCheckOkFogOfWar() == false)
//{
// label = label + " FogOfWar == false";
//}
}
else if ( clientInterface - > getAllowGameDataSynchCheck ( ) = = true )
{
label + = " - data synch is ok " ;
}
2010-08-05 01:39:12 +02:00
//std::string networkFrameString = lang.get("NetworkFramePeriod") + " " + intToStr(clientInterface->getGameSettings()->getNetworkFramePeriod());
2010-07-02 04:50:20 +02:00
//float pingTime = clientInterface->getThreadedPingMS(clientInterface->getServerIpAddress().c_str());
2010-08-05 01:39:12 +02:00
//char szBuf[1024]="";
2010-07-02 04:50:20 +02:00
//sprintf(szBuf,"%s, ping = %.2fms, %s",label.c_str(),pingTime,networkFrameString.c_str());
2010-08-05 01:39:12 +02:00
//sprintf(szBuf,"%s, %s",label.c_str(),networkFrameString.c_str());
2010-06-04 21:42:58 +02:00
2010-08-05 01:39:12 +02:00
//labelStatus.setText(szBuf);
labelStatus . setText ( label ) ;
2010-04-22 01:13:39 +02:00
}
}
2010-07-08 10:29:51 +02:00
else {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( clientInterface ! = NULL & & clientInterface - > isConnected ( ) = = true ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
clientInterface - > close ( ) ;
}
2010-07-08 10:29:51 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-05-09 23:23:13 +02:00
returnToJoinMenu ( ) ;
2010-04-23 01:18:04 +02:00
return ;
2010-04-22 01:13:39 +02:00
}
//process network messages
2010-08-21 15:04:52 +02:00
if ( clientInterface - > isConnected ( ) ) {
bool mustSwitchPlayerName = false ;
2010-08-23 06:33:21 +02:00
if ( clientInterface - > getGameSettingsReceived ( ) ) {
2010-08-22 10:00:05 +02:00
updateDataSynchDetailText = true ;
2010-04-29 09:59:44 +02:00
bool errorOnMissingData = ( clientInterface - > getAllowGameDataSynchCheck ( ) = = false ) ;
2010-04-22 01:13:39 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
vector < string > maps , tilesets , techtree ;
const GameSettings * gameSettings = clientInterface - > getGameSettings ( ) ;
// tileset
tilesets . push_back ( formatString ( gameSettings - > getTileset ( ) ) ) ;
listBoxTileset . setItems ( tilesets ) ;
// techtree
techtree . push_back ( formatString ( gameSettings - > getTech ( ) ) ) ;
listBoxTechTree . setItems ( techtree ) ;
// factions
2010-04-29 09:59:44 +02:00
bool hasFactions = true ;
if ( currentFactionName ! = gameSettings - > getTech ( ) )
2010-04-22 01:13:39 +02:00
{
2010-06-04 00:52:56 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] hasFactions = %d, currentFactionName [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , hasFactions , currentFactionName . c_str ( ) ) ;
2010-04-29 09:59:44 +02:00
currentFactionName = gameSettings - > getTech ( ) ;
2010-06-03 08:03:41 +02:00
hasFactions = loadFactions ( gameSettings , false ) ;
2010-04-22 01:13:39 +02:00
}
2010-07-09 17:59:49 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] hasFactions = %d, currentFactionName [%s]\n",__FILE__,__FUNCTION__,__LINE__,hasFactions,currentFactionName.c_str());
2010-04-29 09:59:44 +02:00
2010-04-22 01:13:39 +02:00
// map
maps . push_back ( formatString ( gameSettings - > getMap ( ) ) ) ;
listBoxMap . setItems ( maps ) ;
2010-04-29 09:59:44 +02:00
if ( currentMap ! = gameSettings - > getMap ( ) )
2010-04-22 01:13:39 +02:00
{ // load the setup again
2010-04-29 09:59:44 +02:00
currentMap = gameSettings - > getMap ( ) ;
2010-04-22 01:13:39 +02:00
}
2010-07-09 17:59:49 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
2010-04-29 09:59:44 +02:00
2010-04-22 01:13:39 +02:00
// FogOfWar
if ( gameSettings - > getFogOfWar ( ) ) {
listBoxFogOfWar . setSelectedItemIndex ( 0 ) ;
}
else
{
listBoxFogOfWar . setSelectedItemIndex ( 1 ) ;
}
2010-04-29 09:59:44 +02:00
2010-08-05 01:39:12 +02:00
if ( gameSettings - > getEnableObserverModeAtEndGame ( ) ) {
listBoxEnableObserverMode . setSelectedItemIndex ( 0 ) ;
}
else {
listBoxEnableObserverMode . setSelectedItemIndex ( 1 ) ;
}
if ( gameSettings - > getEnableServerControlledAI ( ) ) {
listBoxEnableServerControlledAI . setSelectedItemIndex ( 0 ) ;
}
else {
listBoxEnableServerControlledAI . setSelectedItemIndex ( 1 ) ;
}
if ( gameSettings - > getNetworkPauseGameForLaggedClients ( ) ) {
listBoxNetworkPauseGameForLaggedClients . setSelectedItemIndex ( 1 ) ;
}
else {
listBoxNetworkPauseGameForLaggedClients . setSelectedItemIndex ( 0 ) ;
}
if ( gameSettings - > getPathFinderType ( ) = = pfBasic ) {
listBoxPathFinderType . setSelectedItemIndex ( 0 ) ;
}
else {
listBoxPathFinderType . setSelectedItemIndex ( 1 ) ;
}
listBoxNetworkFramePeriod . setSelectedItem ( intToStr ( gameSettings - > getNetworkFramePeriod ( ) ) , false ) ;
2010-05-31 08:11:31 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
2010-04-29 09:59:44 +02:00
2010-04-22 01:13:39 +02:00
// Control
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
listBoxControls [ i ] . setSelectedItemIndex ( ctClosed ) ;
2010-04-29 01:59:37 +02:00
listBoxFactions [ i ] . setEditable ( false ) ;
listBoxTeams [ i ] . setEditable ( false ) ;
2010-04-22 01:13:39 +02:00
}
2010-07-09 17:59:49 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
2010-04-29 09:59:44 +02:00
if ( hasFactions = = true ) {
2010-06-14 08:38:24 +02:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] errorOnMissingData = %d\n",__FILE__,__FUNCTION__,__LINE__,errorOnMissingData);
2010-04-29 09:59:44 +02:00
for ( int i = 0 ; i < gameSettings - > getFactionCount ( ) ; + + i ) {
int slot = gameSettings - > getStartLocationIndex ( i ) ;
listBoxControls [ slot ] . setSelectedItemIndex ( gameSettings - > getFactionControl ( i ) , errorOnMissingData ) ;
listBoxTeams [ slot ] . setSelectedItemIndex ( gameSettings - > getTeam ( i ) , errorOnMissingData ) ;
2010-06-04 00:52:56 +02:00
//listBoxFactions[slot].setSelectedItem(formatString(gameSettings->getFactionTypeName(i)),errorOnMissingData);
listBoxFactions [ slot ] . setSelectedItem ( formatString ( gameSettings - > getFactionTypeName ( i ) ) , false ) ;
2010-04-29 09:59:44 +02:00
if ( gameSettings - > getFactionControl ( i ) = = ctNetwork ) {
labelNetStatus [ slot ] . setText ( gameSettings - > getNetworkPlayerName ( i ) ) ;
2010-08-21 15:04:52 +02:00
if ( gameSettings - > getThisFactionIndex ( ) ! = i & &
gameSettings - > getNetworkPlayerName ( i ) ! = " " ) {
labelPlayerNames [ slot ] . setText ( gameSettings - > getNetworkPlayerName ( i ) ) ;
}
2010-04-29 09:59:44 +02:00
}
2010-08-21 15:04:52 +02:00
if ( gameSettings - > getFactionControl ( i ) = = ctNetwork & &
gameSettings - > getThisFactionIndex ( ) = = i ) {
2010-04-29 09:59:44 +02:00
// set my current slot to ctHuman
listBoxControls [ slot ] . setSelectedItemIndex ( ctHuman ) ;
listBoxFactions [ slot ] . setEditable ( true ) ;
listBoxTeams [ slot ] . setEditable ( true ) ;
2010-08-21 15:04:52 +02:00
if ( labelPlayerNames [ slot ] . getText ( ) = = " " & &
gameSettings - > getNetworkPlayerName ( i ) ! = " " ) {
labelPlayerNames [ slot ] . setText ( gameSettings - > getNetworkPlayerName ( i ) ) ;
}
2010-04-29 09:59:44 +02:00
}
settingsReceivedFromServer = true ;
2010-08-05 02:48:46 +02:00
initialSettingsReceivedFromServer = true ;
2010-08-21 15:04:52 +02:00
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
mustSwitchPlayerName = true ;
}
}
}
2010-04-22 01:13:39 +02:00
//update lobby
clientInterface - > updateLobby ( ) ;
2010-07-08 10:29:51 +02:00
clientInterface = NetworkManager : : getInstance ( ) . getClientInterface ( ) ;
if ( clientInterface ! = NULL & & clientInterface - > isConnected ( ) ) {
2010-08-23 06:33:21 +02:00
//if(mustSwitchPlayerName == true ||
// (needToSetChangedGameSettings == true &&
// difftime(time(NULL),lastSetChangedGameSettings) >= 2)) {
if ( clientInterface - > getIntroDone ( ) = = true & &
( switchSetupRequestFlagType & ssrft_NetworkPlayerName ) = = ssrft_NetworkPlayerName ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
//needToSetChangedGameSettings = false;
//lastSetChangedGameSettings = time(NULL);
clientInterface - > sendSwitchSetupRequest ( " " , clientInterface - > getPlayerIndex ( ) , - 1 , - 1 , getHumanPlayerName ( ) , switchSetupRequestFlagType ) ;
switchSetupRequestFlagType = ssrft_None ;
}
2010-07-08 10:29:51 +02:00
//call the chat manager
chatManager . updateNetwork ( ) ;
2010-04-22 01:13:39 +02:00
2010-08-21 15:04:52 +02:00
//console732
2010-07-08 10:29:51 +02:00
console . update ( ) ;
2010-04-22 01:13:39 +02:00
2010-07-08 10:29:51 +02:00
//intro
if ( clientInterface - > getIntroDone ( ) )
{
labelInfo . setText ( lang . get ( " WaitingHost " ) ) ;
//servers.setString(clientInterface->getServerName(), Ip(labelServerIp.getText()).getString());
}
2010-04-22 01:13:39 +02:00
2010-07-08 10:29:51 +02:00
//launch
if ( clientInterface - > getLaunchGame ( ) )
{
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
2010-07-08 10:29:51 +02:00
//servers.save(serversSavedFile);
2010-04-22 01:13:39 +02:00
2010-07-08 10:29:51 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-06-01 18:54:44 +02:00
2010-07-08 10:29:51 +02:00
assert ( clientInterface ! = NULL ) ;
2010-06-01 18:54:44 +02:00
2010-07-08 10:29:51 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
2010-07-08 10:29:51 +02:00
program - > setState ( new Game ( program , clientInterface - > getGameSettings ( ) ) ) ;
2010-04-22 01:13:39 +02:00
2010-07-08 10:29:51 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
2010-04-22 01:13:39 +02:00
}
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
2010-07-08 10:29:51 +02:00
if ( clientInterface ! = NULL & & clientInterface - > getLaunchGame ( ) ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s] clientInterface->getLaunchGame() - D \n " , __FILE__ , __FUNCTION__ ) ;
2010-04-22 01:13:39 +02:00
}
2010-06-03 08:03:41 +02:00
bool MenuStateConnectedGame : : loadFactions ( const GameSettings * gameSettings , bool errorOnNoFactions ) {
2010-04-22 01:13:39 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-06-04 00:52:56 +02:00
bool foundFactions = false ;
2010-04-22 01:13:39 +02:00
vector < string > results ;
Config & config = Config : : getInstance ( ) ;
vector < string > techPaths = config . getPathListForType ( ptTechs ) ;
for ( int idx = 0 ; idx < techPaths . size ( ) ; idx + + ) {
string & techPath = techPaths [ idx ] ;
2010-06-03 09:52:17 +02:00
findAll ( techPath + " / " + gameSettings - > getTech ( ) + " /factions/*. " , results , false , false ) ;
2010-04-22 01:13:39 +02:00
if ( results . size ( ) > 0 ) {
break ;
}
}
if ( results . size ( ) = = 0 ) {
2010-04-29 09:59:44 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
2010-04-29 09:59:44 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
if ( clientInterface - > getAllowGameDataSynchCheck ( ) = = false ) {
2010-06-03 08:03:41 +02:00
if ( errorOnNoFactions = = true ) {
throw runtime_error ( " (2) There are no factions for the tech tree [ " + gameSettings->getTech() + " ] " ) ;
}
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] (2)There are no factions for the tech tree [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , gameSettings - > getTech ( ) . c_str ( ) ) ;
}
results . push_back ( " ***missing*** " ) ;
factionFiles = results ;
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
listBoxFactions [ i ] . setItems ( results ) ;
2010-04-29 09:59:44 +02:00
}
2010-04-22 01:13:39 +02:00
2010-06-03 08:03:41 +02:00
char szMsg [ 1024 ] = " " ;
2010-08-21 15:04:52 +02:00
sprintf ( szMsg , " Player: %s is missing the techtree: %s " , getHumanPlayerName ( ) . c_str ( ) , gameSettings - > getTech ( ) . c_str ( ) ) ;
2010-07-01 02:08:59 +02:00
clientInterface - > sendTextMessage ( szMsg , - 1 , true ) ;
2010-06-03 08:03:41 +02:00
2010-06-04 00:52:56 +02:00
foundFactions = false ;
2010-04-29 09:59:44 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
else {
factionFiles = results ;
for ( int i = 0 ; i < results . size ( ) ; + + i ) {
results [ i ] = formatString ( results [ i ] ) ;
2010-04-22 01:13:39 +02:00
2010-04-29 09:59:44 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " Tech [%s] has faction [%s] \n " , gameSettings - > getTech ( ) . c_str ( ) , results [ i ] . c_str ( ) ) ;
}
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
listBoxFactions [ i ] . setItems ( results ) ;
}
2010-06-04 00:52:56 +02:00
foundFactions = ( results . size ( ) > 0 ) ;
2010-04-29 09:59:44 +02:00
}
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
2010-06-04 00:52:56 +02:00
return foundFactions ;
2010-04-29 09:59:44 +02:00
}
2010-04-22 01:13:39 +02:00
// ============ PRIVATE ===========================
bool MenuStateConnectedGame : : hasNetworkGameSettings ( )
{
bool hasNetworkSlot = false ;
try {
for ( int i = 0 ; i < mapInfo . players ; + + i )
{
ControlType ct = static_cast < ControlType > ( listBoxControls [ i ] . getSelectedItemIndex ( ) ) ;
if ( ct ! = ctClosed )
{
if ( ct = = ctNetwork )
{
hasNetworkSlot = true ;
break ;
}
}
}
}
catch ( const std : : exception & ex ) {
char szBuf [ 1024 ] = " " ;
sprintf ( szBuf , " In [%s::%s %d] error [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , ex . what ( ) ) ;
throw runtime_error ( szBuf ) ;
}
return hasNetworkSlot ;
}
2010-08-23 06:33:21 +02:00
void MenuStateConnectedGame : : reloadFactions ( ) {
2010-04-22 01:13:39 +02:00
vector < string > results ;
Config & config = Config : : getInstance ( ) ;
2010-04-29 09:59:44 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
vector < string > techPaths = config . getPathListForType ( ptTechs ) ;
for ( int idx = 0 ; idx < techPaths . size ( ) ; idx + + ) {
string & techPath = techPaths [ idx ] ;
findAll ( techPath + " / " + techTreeFiles [ listBoxTechTree . getSelectedItemIndex ( ) ] + " /factions/*. " , results , false , false ) ;
if ( results . size ( ) > 0 ) {
break ;
}
}
2010-04-29 09:59:44 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
if ( results . size ( ) = = 0 ) {
throw runtime_error ( " (2) There are no factions for the tech tree [ " + techTreeFiles[listBoxTechTree.getSelectedItemIndex()] + " ] " ) ;
}
factionFiles = results ;
for ( int i = 0 ; i < results . size ( ) ; + + i ) {
results [ i ] = formatString ( results [ i ] ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " Tech [%s] has faction [%s] \n " , techTreeFiles [ listBoxTechTree . getSelectedItemIndex ( ) ] . c_str ( ) , results [ i ] . c_str ( ) ) ;
}
2010-04-29 09:59:44 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
listBoxFactions [ i ] . setItems ( results ) ;
listBoxFactions [ i ] . setSelectedItemIndex ( i % results . size ( ) ) ;
}
2010-04-29 09:59:44 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2010-04-22 01:13:39 +02:00
}
2010-08-21 15:04:52 +02:00
void MenuStateConnectedGame : : keyDown ( char key ) {
if ( activeInputLabel ! = NULL ) {
if ( key = = vkBack ) {
string text = activeInputLabel - > getText ( ) ;
if ( text . size ( ) > 1 ) {
text . erase ( text . end ( ) - 2 ) ;
2010-06-09 00:50:37 +02:00
}
2010-08-21 15:04:52 +02:00
activeInputLabel - > setText ( text ) ;
2010-08-23 06:33:21 +02:00
switchSetupRequestFlagType | = ssrft_NetworkPlayerName ;
2010-08-21 15:04:52 +02:00
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
}
else {
//send key to the chat manager
chatManager . keyDown ( key ) ;
if ( ! chatManager . getEditEnabled ( ) ) {
if ( key = = ' M ' ) {
showFullConsole = true ;
}
}
2010-06-09 00:50:37 +02:00
}
2010-04-22 01:13:39 +02:00
}
2010-08-21 15:04:52 +02:00
void MenuStateConnectedGame : : keyPress ( char c ) {
if ( activeInputLabel ! = NULL ) {
int maxTextSize = 16 ;
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
if ( & labelPlayerNames [ i ] = = activeInputLabel ) {
if ( ( c > = ' 0 ' & & c < = ' 9 ' ) | | ( c > = ' a ' & & c < = ' z ' ) | | ( c > = ' A ' & & c < = ' Z ' ) | |
( c = = ' - ' ) | | ( c = = ' ( ' ) | | ( c = = ' ) ' ) ) {
2010-08-23 06:33:21 +02:00
if ( activeInputLabel - > getText ( ) . size ( ) < maxTextSize ) {
2010-08-21 15:04:52 +02:00
string text = activeInputLabel - > getText ( ) ;
text . insert ( text . end ( ) - 1 , c ) ;
activeInputLabel - > setText ( text ) ;
2010-08-23 06:33:21 +02:00
switchSetupRequestFlagType | = ssrft_NetworkPlayerName ;
2010-08-21 15:04:52 +02:00
needToSetChangedGameSettings = true ;
lastSetChangedGameSettings = time ( NULL ) ;
}
}
}
}
}
else {
chatManager . keyPress ( c ) ;
}
2010-04-22 01:13:39 +02:00
}
2010-08-21 15:04:52 +02:00
void MenuStateConnectedGame : : keyUp ( char key ) {
if ( activeInputLabel = = NULL ) {
2010-06-09 00:50:37 +02:00
chatManager . keyUp ( key ) ;
2010-08-21 15:04:52 +02:00
if ( chatManager . getEditEnabled ( ) ) {
//send key to the chat manager
chatManager . keyUp ( key ) ;
}
else if ( key = = ' M ' ) {
showFullConsole = false ;
}
2010-06-09 00:50:37 +02:00
}
2010-08-21 15:04:52 +02:00
}
2010-08-23 06:33:21 +02:00
void MenuStateConnectedGame : : setActiveInputLabel ( GraphicLabel * newLable ) {
if ( newLable ! = NULL ) {
2010-08-21 15:04:52 +02:00
string text = newLable - > getText ( ) ;
size_t found ;
found = text . find_last_of ( " _ " ) ;
2010-08-23 06:33:21 +02:00
if ( found = = string : : npos ) {
2010-08-21 15:04:52 +02:00
text = text + " _ " ;
}
newLable - > setText ( text ) ;
2010-06-09 00:50:37 +02:00
}
2010-08-23 06:33:21 +02:00
if ( activeInputLabel ! = NULL & & ! activeInputLabel - > getText ( ) . empty ( ) ) {
2010-08-21 15:04:52 +02:00
string text = activeInputLabel - > getText ( ) ;
size_t found ;
found = text . find_last_of ( " _ " ) ;
2010-08-23 06:33:21 +02:00
if ( found ! = string : : npos ) {
2010-08-21 15:04:52 +02:00
text = text . substr ( 0 , found ) ;
}
activeInputLabel - > setText ( text ) ;
}
activeInputLabel = newLable ;
}
string MenuStateConnectedGame : : getHumanPlayerName ( ) {
2010-08-23 06:33:21 +02:00
string result = defaultPlayerName ;
2010-08-21 15:04:52 +02:00
NetworkManager & networkManager = NetworkManager : : getInstance ( ) ;
ClientInterface * clientInterface = networkManager . getClientInterface ( ) ;
for ( int j = 0 ; j < GameConstants : : maxPlayers ; + + j ) {
2010-08-23 06:33:21 +02:00
if ( clientInterface ! = NULL & &
clientInterface - > getGameSettings ( ) ! = NULL & &
2010-08-21 15:04:52 +02:00
j = = clientInterface - > getGameSettings ( ) - > getThisFactionIndex ( ) & &
labelPlayerNames [ j ] . getText ( ) ! = " " ) {
result = labelPlayerNames [ j ] . getText ( ) ;
2010-08-23 06:33:21 +02:00
if ( activeInputLabel ! = NULL ) {
size_t found = result . find_last_of ( " _ " ) ;
if ( found ! = string : : npos ) {
result = result . substr ( 0 , found ) ;
}
}
2010-08-21 15:04:52 +02:00
break ;
}
}
return result ;
2010-06-08 02:00:28 +02:00
}
2010-04-22 01:13:39 +02:00
} } //end namespace