From e44170ea0072ffe26d74690d06729cb8285bc63c Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 2 Sep 2011 00:08:35 +0000 Subject: [PATCH] - bugfixes for lobby UI when map changes and player index is invalid --- source/glest_game/game/game_settings.h | 2 +- .../menu/menu_state_connected_game.cpp | 39 +++++++++++++++---- .../menu/menu_state_custom_game.cpp | 2 +- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/source/glest_game/game/game_settings.h b/source/glest_game/game/game_settings.h index 4ed8f78e..bfa02341 100644 --- a/source/glest_game/game/game_settings.h +++ b/source/glest_game/game/game_settings.h @@ -158,7 +158,7 @@ public: bool isNetworkGame() const { bool result = false; for(int idx = 0; idx < GameConstants::maxPlayers; ++idx) { - if(factionControls[idx] == ctNetwork) { + if(factionControls[idx] == ctNetwork || factionControls[idx] == ctNetworkUnassigned) { result = true; break; } diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index e3249303..de370469 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -1808,7 +1808,7 @@ void MenuStateConnectedGame::update() { listBoxNetworkFramePeriod.setSelectedItem(intToStr(gameSettings->getNetworkFramePeriod()),false); // Control - for(int i=0; igetFactionCount(); ++i){ + NetworkManager &networkManager= NetworkManager::getInstance(); + ClientInterface *clientInterface = networkManager.getClientInterface(); + + //for(int i=0; i < gameSettings->getFactionCount(); ++i){ + for(int i=0; i < GameConstants::maxPlayers; ++i) { int slot = gameSettings->getStartLocationIndex(i); + //printf("Control = %d\n",gameSettings->getFactionControl(i)); +// if(gameSettings->getFactionControl(i) == ctNetworkUnassigned) { +// printf("#1 Index = %d, Control = %d, Count = %d, slot = %d, gameSettings->getThisFactionIndex() = %d\n",i,gameSettings->getFactionControl(i),gameSettings->getFactionCount(),slot,gameSettings->getThisFactionIndex()); +// } + + if(i >= gameSettings->getFactionCount()) { + if( gameSettings->getFactionControl(i) != ctNetworkUnassigned) { + continue; + } + else if(clientInterface->getPlayerIndex() != i) { + continue; + } + } + +// if(gameSettings->getFactionControl(i) == ctNetworkUnassigned) { +// printf("#2 Index = %d, Control = %d, Count = %d, slot = %d, gameSettings->getThisFactionIndex() = %d\n",i,gameSettings->getFactionControl(i),gameSettings->getFactionCount(),slot,gameSettings->getThisFactionIndex()); +// } + if( gameSettings->getFactionControl(i) == ctNetwork || - //gameSettings->getFactionControl(i) == ctNetworkUnassigned || + gameSettings->getFactionControl(i) == ctNetworkUnassigned || gameSettings->getFactionControl(i) == ctHuman) { switch(gameSettings->getNetworkPlayerStatuses(i)) { case npst_BeRightBack: @@ -1847,8 +1869,8 @@ void MenuStateConnectedGame::update() { listBoxTeams[slot].setSelectedItemIndex(gameSettings->getTeam(i),errorOnMissingData); //listBoxFactions[slot].setSelectedItem(formatString(gameSettings->getFactionTypeName(i)),errorOnMissingData); listBoxFactions[slot].setSelectedItem(formatString(gameSettings->getFactionTypeName(i)),false); - if( gameSettings->getFactionControl(i) == ctNetwork) { - //gameSettings->getFactionControl(i) == ctNetworkUnassigned) { + if( gameSettings->getFactionControl(i) == ctNetwork || + gameSettings->getFactionControl(i) == ctNetworkUnassigned) { labelNetStatus[slot].setText(gameSettings->getNetworkPlayerName(i)); if( gameSettings->getThisFactionIndex() != i && gameSettings->getNetworkPlayerName(i) != "" && @@ -1858,7 +1880,7 @@ void MenuStateConnectedGame::update() { } ControlType ct= gameSettings->getFactionControl(i); - if (ct == ctHuman || ct == ctNetwork || ct == ctNetworkUnassigned || ct == ctClosed) { + if (ct == ctHuman || ct == ctNetwork || ct == ctClosed) { listBoxRMultiplier[slot].setEnabled(false); listBoxRMultiplier[slot].setVisible(false); } else { @@ -1869,8 +1891,11 @@ void MenuStateConnectedGame::update() { if((gameSettings->getFactionControl(i) == ctNetwork || gameSettings->getFactionControl(i) == ctNetworkUnassigned) && gameSettings->getThisFactionIndex() == i) { + // set my current slot to ctHuman - listBoxControls[slot].setSelectedItemIndex(ctHuman); + if(gameSettings->getFactionControl(i) != ctNetworkUnassigned) { + listBoxControls[slot].setSelectedItemIndex(ctHuman); + } listBoxFactions[slot].setEditable(true); listBoxTeams[slot].setEditable(true); diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 7933f90a..ecd2711a 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -1541,7 +1541,7 @@ void MenuStateCustomGame::switchSetupForSlots(SwitchSetupRequest **switchSetupRe } if(listBoxControls[switchFactionIdx].getSelectedItemIndex() == ctNetworkUnassigned) { - serverInterface->removeSlot(i); + serverInterface->removeSlot(switchFactionIdx); listBoxControls[switchFactionIdx].setSelectedItemIndex(ctClosed); labelPlayers[switchFactionIdx].setVisible(switchFactionIdx+1 <= mapInfo.players);