- bugfix when reloading saved settings and item doesn't exist in listbox (thanks tomryen)

This commit is contained in:
Mark Vejvoda 2011-09-07 16:55:49 +00:00
parent b8010a18af
commit 56a384e365
3 changed files with 21 additions and 2 deletions

View File

@ -334,6 +334,16 @@ void GraphicListBox::setEditable(bool editable){
GraphicComponent::setEditable(editable);
}
bool GraphicListBox::hasItem(string item) const {
bool result = false;
vector<string>::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<string>::iterator iter;

View File

@ -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);

View File

@ -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());