From 13173788dae82aff3b827bc58af13354bf1831f9 Mon Sep 17 00:00:00 2001 From: Titus Tscharntke Date: Mon, 30 Aug 2010 20:02:58 +0000 Subject: [PATCH] mapFilter --- source/glest_game/game/game_settings.h | 4 ++ .../menu/menu_state_custom_game.cpp | 71 ++++++++++++++----- .../glest_game/menu/menu_state_custom_game.h | 4 ++ 3 files changed, 61 insertions(+), 18 deletions(-) diff --git a/source/glest_game/game/game_settings.h b/source/glest_game/game/game_settings.h index ecff993e..d1e96dd3 100644 --- a/source/glest_game/game/game_settings.h +++ b/source/glest_game/game/game_settings.h @@ -40,6 +40,7 @@ private: int factionCount; int teams[GameConstants::maxPlayers]; int startLocationIndex[GameConstants::maxPlayers]; + int mapFilterIndex; bool defaultUnits; @@ -101,6 +102,7 @@ public: int getFactionCount() const {return factionCount;} int getTeam(int factionIndex) const {return teams[factionIndex];} int getStartLocationIndex(int factionIndex) const {return startLocationIndex[factionIndex];} + int getMapFilterIndex() const {return mapFilterIndex;} bool getDefaultUnits() const {return defaultUnits;} bool getDefaultResources() const {return defaultResources;} @@ -128,6 +130,7 @@ public: void setFactionCount(int factionCount) {this->factionCount= factionCount;} void setTeam(int factionIndex, int team) {this->teams[factionIndex]= team;} void setStartLocationIndex(int factionIndex, int startLocationIndex) {this->startLocationIndex[factionIndex]= startLocationIndex;} + void setMapFilterIndex(int mapFilterIndex) {this->mapFilterIndex=mapFilterIndex;} void setDefaultUnits(bool defaultUnits) {this->defaultUnits= defaultUnits;} void setDefaultResources(bool defaultResources) {this->defaultResources= defaultResources;} @@ -144,6 +147,7 @@ public: string result = ""; result += "description = " + description + "\n"; + result += "mapFilterIndex = " + intToStr(mapFilterIndex) + "\n"; result += "map = " + map + "\n"; result += "tileset = " + tileset + "\n"; result += "tech = " + tech + "\n"; diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 66caaebb..471e24dc 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -132,7 +132,17 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b } copy(allMaps.begin(), allMaps.end(), std::back_inserter(results)); mapFiles = results; - std::for_each(results.begin(), results.end(), FormatString()); + + copy(mapFiles.begin(), mapFiles.end(), std::back_inserter(playerSortedMaps[0])); + copy(playerSortedMaps[0].begin(), playerSortedMaps[0].end(), std::back_inserter(formattedPlayerSortedMaps[0])); + std::for_each(formattedPlayerSortedMaps[0].begin(), formattedPlayerSortedMaps[0].end(), FormatString()); + + for ( int i = 0 ; isetDescription(formatString(mapFiles[listBoxMap.getSelectedItemIndex()])); - gameSettings->setMap(mapFiles[listBoxMap.getSelectedItemIndex()]); + gameSettings->setMapFilterIndex(listBoxMapFilter.getSelectedItemIndex()); + gameSettings->setDescription(formatString(getCurrentMapFile())); + gameSettings->setMap(getCurrentMapFile()); gameSettings->setTileset(tilesetFiles[listBoxTileset.getSelectedItemIndex()]); gameSettings->setTech(techTreeFiles[listBoxTechTree.getSelectedItemIndex()]); gameSettings->setDefaultUnits(true); @@ -1530,7 +1538,8 @@ void MenuStateCustomGame::saveGameSettingsToFile(std::string fileName) { //ServerInterface* serverInterface= NetworkManager::getInstance().getServerInterface(); saveGameFile << "Description=" << gameSettings.getDescription() << std::endl; - + + saveGameFile << "MapFilterIndex=" << gameSettings.getMapFilterIndex() << std::endl; saveGameFile << "Map=" << gameSettings.getMap() << std::endl; saveGameFile << "Tileset=" << gameSettings.getTileset() << std::endl; saveGameFile << "TechTree=" << gameSettings.getTech() << std::endl; @@ -1583,6 +1592,7 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName) properties.load(fileName); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] fileName = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.c_str()); + gameSettings.setMapFilterIndex(properties.getInt("MapFilterIndex")); gameSettings.setDescription(properties.getString("Description")); gameSettings.setMap(properties.getString("Map")); gameSettings.setTileset(properties.getString("Tileset")); @@ -1611,11 +1621,14 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + listBoxMapFilter.setSelectedItemIndex(gameSettings.getMapFilterIndex()); + listBoxMap.setItems(formattedPlayerSortedMaps[gameSettings.getMapFilterIndex()]); + string mapFile = gameSettings.getMap(); mapFile = formatString(mapFile); listBoxMap.setSelectedItem(mapFile); - loadMapInfo(Map::getMapPath(mapFiles[listBoxMap.getSelectedItemIndex()]), &mapInfo); + loadMapInfo(Map::getMapPath(getCurrentMapFile()), &mapInfo); labelMapInfo.setText(mapInfo.desc); string tilesetFile = gameSettings.getTileset(); @@ -1970,6 +1983,28 @@ void MenuStateCustomGame::showMessageBox(const string &text, const string &heade } } +void MenuStateCustomGame::switchToNextMapGroup(const int direction){ + int i=listBoxMapFilter.getSelectedItemIndex(); + // if there are no maps for the current selection we switch to next selection + while(formattedPlayerSortedMaps[i].empty()){ + i=i+direction; + if(i>GameConstants::maxPlayers){ + i=0; + } + if(i<0){ + i=GameConstants::maxPlayers; + } + } + listBoxMapFilter.setSelectedItemIndex(i); + listBoxMap.setItems(formattedPlayerSortedMaps[i]); +} + +string MenuStateCustomGame::getCurrentMapFile(){ + int i=listBoxMapFilter.getSelectedItemIndex(); + int mapIndex=listBoxMap.getSelectedItemIndex(); + return playerSortedMaps[i].at(mapIndex); +} + void MenuStateCustomGame::setActiveInputLabel(GraphicLabel *newLable) { if(newLable!=NULL) { string text= newLable->getText(); diff --git a/source/glest_game/menu/menu_state_custom_game.h b/source/glest_game/menu/menu_state_custom_game.h index 73838609..e21d826b 100644 --- a/source/glest_game/menu/menu_state_custom_game.h +++ b/source/glest_game/menu/menu_state_custom_game.h @@ -47,6 +47,8 @@ private: GraphicListBox listBoxEnableServerControlledAI; vector mapFiles; + vector playerSortedMaps[GameConstants::maxPlayers+1]; + vector formattedPlayerSortedMaps[GameConstants::maxPlayers+1]; vector techTreeFiles; vector tilesetFiles; vector factionFiles; @@ -147,6 +149,8 @@ private: void showMessageBox(const string &text, const string &header, bool toggle); void saveGameSettingsToFile(std::string fileName); + void switchToNextMapGroup(const int direction); + string getCurrentMapFile(); GameSettings loadGameSettingsFromFile(std::string fileName); void setActiveInputLabel(GraphicLabel *newLable); string getHumanPlayerName(int index=-1);