mirror of
https://github.com/glest/glest-source.git
synced 2025-09-01 12:02:36 +02:00
- bugfix for saving of last game settings
This commit is contained in:
@@ -49,6 +49,8 @@ struct FormatString {
|
|||||||
MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, bool openNetworkSlots,bool parentMenuIsMasterserver):
|
MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, bool openNetworkSlots,bool parentMenuIsMasterserver):
|
||||||
MenuState(program, mainMenu, "new-game")
|
MenuState(program, mainMenu, "new-game")
|
||||||
{
|
{
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
publishToMasterserverThread = NULL;
|
publishToMasterserverThread = NULL;
|
||||||
Lang &lang= Lang::getInstance();
|
Lang &lang= Lang::getInstance();
|
||||||
NetworkManager &networkManager= NetworkManager::getInstance();
|
NetworkManager &networkManager= NetworkManager::getInstance();
|
||||||
@@ -215,6 +217,8 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
|
|||||||
|
|
||||||
labelMapInfo.setText(mapInfo.desc);
|
labelMapInfo.setText(mapInfo.desc);
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
//initialize network interface
|
//initialize network interface
|
||||||
networkManager.init(nrServer);
|
networkManager.init(nrServer);
|
||||||
|
|
||||||
@@ -231,28 +235,43 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
|
|||||||
updateControlers();
|
updateControlers();
|
||||||
updateNetworkSlots();
|
updateNetworkSlots();
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
// Ensure we have set the gamesettings at least once
|
// Ensure we have set the gamesettings at least once
|
||||||
GameSettings gameSettings = loadGameSettingsFromFile("lastCustomGamSettings.mgg");
|
GameSettings gameSettings = loadGameSettingsFromFile("lastCustomGamSettings.mgg");
|
||||||
if(gameSettings.getMap() == "") {
|
if(gameSettings.getMap() == "") {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
loadGameSettings(&gameSettings);
|
loadGameSettings(&gameSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
|
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
|
||||||
serverInterface->setGameSettings(&gameSettings,false);
|
serverInterface->setGameSettings(&gameSettings,false);
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
//chatManager.init(&console, world.getThisTeamIndex());
|
//chatManager.init(&console, world.getThisTeamIndex());
|
||||||
chatManager.init(&console, -1);
|
chatManager.init(&console, -1);
|
||||||
|
|
||||||
publishToMasterserverThread = new SimpleTaskThread(this,0,100);
|
publishToMasterserverThread = new SimpleTaskThread(this,0,150);
|
||||||
publishToMasterserverThread->start();
|
publishToMasterserverThread->start();
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuStateCustomGame::~MenuStateCustomGame() {
|
MenuStateCustomGame::~MenuStateCustomGame() {
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
needToBroadcastServerSettings = false;
|
needToBroadcastServerSettings = false;
|
||||||
needToRepublishToMasterserver = false;
|
needToRepublishToMasterserver = false;
|
||||||
BaseThread::shutdownAndWait(publishToMasterserverThread);
|
BaseThread::shutdownAndWait(publishToMasterserverThread);
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
delete publishToMasterserverThread;
|
delete publishToMasterserverThread;
|
||||||
publishToMasterserverThread = NULL;
|
publishToMasterserverThread = NULL;
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -337,10 +356,14 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
|
|||||||
if( listBoxPublishServer.getEditable() &&
|
if( listBoxPublishServer.getEditable() &&
|
||||||
listBoxPublishServer.getSelectedItemIndex() == 0) {
|
listBoxPublishServer.getSelectedItemIndex() == 0) {
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
needToRepublishToMasterserver = true;
|
needToRepublishToMasterserver = true;
|
||||||
lastMasterserverPublishing = 0;
|
lastMasterserverPublishing = 0;
|
||||||
publishToMasterserver();
|
publishToMasterserver();
|
||||||
simpleTask();
|
simpleTask();
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
needToBroadcastServerSettings = false;
|
needToBroadcastServerSettings = false;
|
||||||
needToRepublishToMasterserver = false;
|
needToRepublishToMasterserver = false;
|
||||||
@@ -508,7 +531,7 @@ void MenuStateCustomGame::render(){
|
|||||||
Renderer &renderer= Renderer::getInstance();
|
Renderer &renderer= Renderer::getInstance();
|
||||||
|
|
||||||
if(mainMessageBox.getEnabled()){
|
if(mainMessageBox.getEnabled()){
|
||||||
renderer.renderMessageBox(&mainMessageBox);
|
renderer.renderMessageBox(&mainMessageBox);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -560,7 +583,7 @@ void MenuStateCustomGame::render(){
|
|||||||
void MenuStateCustomGame::update()
|
void MenuStateCustomGame::update()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
//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__);
|
||||||
|
|
||||||
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
|
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
|
||||||
Lang& lang= Lang::getInstance();
|
Lang& lang= Lang::getInstance();
|
||||||
@@ -582,6 +605,8 @@ void MenuStateCustomGame::update()
|
|||||||
showMessageBox( masterServererErrorToShow, lang.get("ErrorFromMasterserver"), false);
|
showMessageBox( masterServererErrorToShow, lang.get("ErrorFromMasterserver"), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
// handle setting changes from clients
|
// handle setting changes from clients
|
||||||
SwitchSetupRequest** switchSetupRequests=serverInterface->getSwitchSetupRequests();
|
SwitchSetupRequest** switchSetupRequests=serverInterface->getSwitchSetupRequests();
|
||||||
for(int i= 0; i<mapInfo.players; ++i)
|
for(int i= 0; i<mapInfo.players; ++i)
|
||||||
@@ -634,14 +659,21 @@ void MenuStateCustomGame::update()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] mapInfo.players = %d\n",__FILE__,__FUNCTION__,__LINE__,mapInfo.players);
|
||||||
|
|
||||||
for(int i= 0; i<mapInfo.players; ++i)
|
for(int i= 0; i<mapInfo.players; ++i)
|
||||||
{
|
{
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork)
|
if(listBoxControls[i].getSelectedItemIndex() == ctNetwork)
|
||||||
{
|
{
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START - ctNetwork\n",__FILE__,__FUNCTION__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
ConnectionSlot* connectionSlot= serverInterface->getSlot(i);
|
ConnectionSlot* connectionSlot= serverInterface->getSlot(i);
|
||||||
assert(connectionSlot!=NULL);
|
assert(connectionSlot!=NULL);
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
hasOneNetworkSlotOpen=true;
|
hasOneNetworkSlotOpen=true;
|
||||||
|
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] A - ctNetwork\n",__FILE__,__FUNCTION__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] A - ctNetwork\n",__FILE__,__FUNCTION__);
|
||||||
@@ -727,6 +759,8 @@ void MenuStateCustomGame::update()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
// Send the game settings to each client if we have at least one networked client
|
// Send the game settings to each client if we have at least one networked client
|
||||||
if( serverInterface->getAllowGameDataSynchCheck() == true &&
|
if( serverInterface->getAllowGameDataSynchCheck() == true &&
|
||||||
//haveAtLeastOneNetworkClientConnected == true &&
|
//haveAtLeastOneNetworkClientConnected == true &&
|
||||||
@@ -740,6 +774,8 @@ void MenuStateCustomGame::update()
|
|||||||
needToSetChangedGameSettings = false;
|
needToSetChangedGameSettings = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
if(hasOneNetworkSlotOpen)
|
if(hasOneNetworkSlotOpen)
|
||||||
{
|
{
|
||||||
//listBoxPublishServer.setSelectedItemIndex(0);
|
//listBoxPublishServer.setSelectedItemIndex(0);
|
||||||
@@ -778,7 +814,7 @@ void MenuStateCustomGame::update()
|
|||||||
{// reset timer here on bottom becasue used for different things
|
{// reset timer here on bottom becasue used for different things
|
||||||
lastSetChangedGameSettings = time(NULL);
|
lastSetChangedGameSettings = time(NULL);
|
||||||
}
|
}
|
||||||
//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__);
|
||||||
|
|
||||||
if(currentConnectionCount>soundConnectionCount){
|
if(currentConnectionCount>soundConnectionCount){
|
||||||
soundConnectionCount=currentConnectionCount;
|
soundConnectionCount=currentConnectionCount;
|
||||||
@@ -846,9 +882,14 @@ void MenuStateCustomGame::publishToMasterserver()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MenuStateCustomGame::simpleTask() {
|
void MenuStateCustomGame::simpleTask() {
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
if( needToRepublishToMasterserver == true &&
|
if( needToRepublishToMasterserver == true &&
|
||||||
publishToServerInfo != "") {
|
publishToServerInfo != "") {
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
needToRepublishToMasterserver = false;
|
needToRepublishToMasterserver = false;
|
||||||
string request = Config::getInstance().getString("Masterserver") + "addServerInfo.php?" + publishToServerInfo;
|
string request = Config::getInstance().getString("Masterserver") + "addServerInfo.php?" + publishToServerInfo;
|
||||||
publishToServerInfo = "";
|
publishToServerInfo = "";
|
||||||
@@ -865,8 +906,13 @@ void MenuStateCustomGame::simpleTask() {
|
|||||||
masterServererErrorToShow=serverInfo;
|
masterServererErrorToShow=serverInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
if(needToBroadcastServerSettings)
|
if(needToBroadcastServerSettings)
|
||||||
{
|
{
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
needToBroadcastServerSettings=false;
|
needToBroadcastServerSettings=false;
|
||||||
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
|
ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface();
|
||||||
if(serverInterface->hasClientConnection() == true) {
|
if(serverInterface->hasClientConnection() == true) {
|
||||||
@@ -879,6 +925,8 @@ void MenuStateCustomGame::simpleTask() {
|
|||||||
serverInterface->broadcastGameSetup(&gameSettings);
|
serverInterface->broadcastGameSetup(&gameSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) {
|
void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) {
|
||||||
@@ -1031,12 +1079,13 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName)
|
|||||||
|
|
||||||
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__);
|
||||||
|
|
||||||
Lang &lang= Lang::getInstance();
|
|
||||||
|
|
||||||
string mapFile = gameSettings.getMap();
|
string mapFile = gameSettings.getMap();
|
||||||
mapFile = formatString(mapFile);
|
mapFile = formatString(mapFile);
|
||||||
listBoxMap.setSelectedItem(mapFile);
|
listBoxMap.setSelectedItem(mapFile);
|
||||||
|
|
||||||
|
loadMapInfo(Map::getMapPath(mapFiles[listBoxMap.getSelectedItemIndex()]), &mapInfo);
|
||||||
|
labelMapInfo.setText(mapInfo.desc);
|
||||||
|
|
||||||
string tilesetFile = gameSettings.getTileset();
|
string tilesetFile = gameSettings.getTileset();
|
||||||
tilesetFile = formatString(tilesetFile);
|
tilesetFile = formatString(tilesetFile);
|
||||||
|
|
||||||
@@ -1053,6 +1102,7 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName)
|
|||||||
//gameSettings->setDefaultResources(true);
|
//gameSettings->setDefaultResources(true);
|
||||||
//gameSettings->setDefaultVictoryConditions(true);
|
//gameSettings->setDefaultVictoryConditions(true);
|
||||||
|
|
||||||
|
Lang &lang= Lang::getInstance();
|
||||||
listBoxFogOfWar.setSelectedItem(gameSettings.getFogOfWar() == true ? lang.get("Yes") : lang.get("No"));
|
listBoxFogOfWar.setSelectedItem(gameSettings.getFogOfWar() == true ? lang.get("Yes") : lang.get("No"));
|
||||||
listBoxEnableObserverMode.setSelectedItem(gameSettings.getEnableObserverModeAtEndGame() == true ? lang.get("Yes") : lang.get("No"));
|
listBoxEnableObserverMode.setSelectedItem(gameSettings.getEnableObserverModeAtEndGame() == true ? lang.get("Yes") : lang.get("No"));
|
||||||
|
|
||||||
@@ -1073,6 +1123,17 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName)
|
|||||||
|
|
||||||
listBoxFactions[i].setSelectedItem(factionName);
|
listBoxFactions[i].setSelectedItem(factionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateControlers();
|
||||||
|
updateNetworkSlots();
|
||||||
|
needToRepublishToMasterserver = true;
|
||||||
|
|
||||||
|
if(hasNetworkGameSettings() == true)
|
||||||
|
{
|
||||||
|
needToSetChangedGameSettings = true;
|
||||||
|
lastSetChangedGameSettings = time(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
//!!!
|
//!!!
|
||||||
}
|
}
|
||||||
catch(const exception &ex) {
|
catch(const exception &ex) {
|
||||||
|
Reference in New Issue
Block a user