diff --git a/source/glest_game/facilities/components.cpp b/source/glest_game/facilities/components.cpp index 3e3581674..299dd40c8 100644 --- a/source/glest_game/facilities/components.cpp +++ b/source/glest_game/facilities/components.cpp @@ -334,6 +334,16 @@ void GraphicListBox::setEditable(bool editable){ GraphicComponent::setEditable(editable); } +bool GraphicListBox::hasItem(string item) const { + bool result = false; + vector::const_iterator iter= find(items.begin(), items.end(), item); + if(iter != items.end()) { + result = true; + } + + return result; +} + void GraphicListBox::setSelectedItem(string item, bool errorOnMissing){ vector::iterator iter; diff --git a/source/glest_game/facilities/components.h b/source/glest_game/facilities/components.h index 4ac1311b3..b38c4104e 100644 --- a/source/glest_game/facilities/components.h +++ b/source/glest_game/facilities/components.h @@ -205,6 +205,8 @@ public: void setSelectedItem(string item, bool errorOnMissing=true); void setEditable(bool editable); + bool hasItem(string item) const; + virtual void setY(int y); virtual bool mouseMove(int x, int y); diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 83500451b..671a5aa12 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -2699,7 +2699,9 @@ void MenuStateCustomGame::setupUIFromGameSettings(const GameSettings &gameSettin if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d] gameSettings.getFactionCount() = %d\n",__FILE__,__FUNCTION__,__LINE__,gameSettings.getFactionCount()); for(int i = 0; i < GameConstants::maxPlayers; ++i) { - listBoxControls[i].setSelectedItemIndex(gameSettings.getFactionControl(i)); + if(gameSettings.getFactionControl(i) < listBoxControls[i].getItemCount()) { + listBoxControls[i].setSelectedItemIndex(gameSettings.getFactionControl(i)); + } updateResourceMultiplier(i); listBoxRMultiplier[i].setSelectedItemIndex(gameSettings.getResourceMultiplierIndex(i)); listBoxTeams[i].setSelectedItemIndex(gameSettings.getTeam(i)); @@ -2710,7 +2712,12 @@ void MenuStateCustomGame::setupUIFromGameSettings(const GameSettings &gameSettin if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] factionName = [%s]\n",__FILE__,__FUNCTION__,__LINE__,factionName.c_str()); - listBoxFactions[i].setSelectedItem(factionName); + if(listBoxFactions[i].hasItem(factionName) == true) { + listBoxFactions[i].setSelectedItem(factionName); + } + else { + listBoxFactions[i].setSelectedItem(formatString(GameConstants::RANDOMFACTION_SLOTNAME)); + } if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] i = %d, gameSettings.getNetworkPlayerName(i) [%s]\n",__FILE__,__FUNCTION__,__LINE__,i,gameSettings.getNetworkPlayerName(i).c_str());