From 06012e4804eb1fb90eadd0b4980e8b01b9bc100a Mon Sep 17 00:00:00 2001 From: James McCulloch Date: Thu, 4 Mar 2010 13:42:27 +0000 Subject: [PATCH] * looks for 'gbm' (1-4 player) maps & 'mgm' (5-8 player) maps --- .../menu/menu_state_custom_game.cpp | 24 +++++++++++++------ source/glest_game/world/map.cpp | 16 ++++++++++++- source/glest_game/world/map.h | 2 +- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index 5a33f90b..ee3dc3bc 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -44,20 +44,28 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b needToSetChangedGameSettings = false; lastSetChangedGameSettings = time(NULL);; - vector results, teamItems, controlItems; + vector glestMaps, megaMaps, teamItems, controlItems; //create buttonReturn.init(350, 140, 125); buttonPlayNow.init(525, 140, 125); //map listBox - findAll("maps/*.gbm", results, true); - if(results.size()==0){ - throw runtime_error("There is no maps"); + findAll("maps/*.gbm", glestMaps, true); + findAll("maps/*.mgm", megaMaps, true); + mapFiles.resize(glestMaps.size() + megaMaps.size()); + if (!glestMaps.empty()) { + copy(glestMaps.begin(), glestMaps.end(), mapFiles.begin()); } - mapFiles= results; - for(int i= 0; i results; + for(int i= 0; i < mapFiles.size(); ++i){ + results.push_back(formatString(mapFiles[i])); } listBoxMap.init(200, 260, 150); listBoxMap.setItems(results); @@ -205,6 +213,8 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){ } } else if(listBoxMap.mouseClick(x, y)){ + printf("%s\n", mapFiles[listBoxMap.getSelectedItemIndex()].c_str()); + loadMapInfo(Map::getMapPath(mapFiles[listBoxMap.getSelectedItemIndex()]), &mapInfo); labelMapInfo.setText(mapInfo.desc); updateControlers(); diff --git a/source/glest_game/world/map.cpp b/source/glest_game/world/map.cpp index 5580d6fe..3d4136ae 100644 --- a/source/glest_game/world/map.cpp +++ b/source/glest_game/world/map.cpp @@ -20,7 +20,8 @@ #include "tech_tree.h" #include "config.h" #include "leak_dumper.h" - +#include "util.h" + using namespace Shared::Graphics; using namespace Shared::Util; @@ -612,6 +613,19 @@ void Map::computeCellColors(){ } } +// static +string Map::getMapPath(const string &mapName) { + string mega = "maps/" + mapName + ".mgm"; + string glest = "maps/" + mapName + ".gbm"; + if (fileExists(mega)) { + return mega; + } else if (fileExists(glest)) { + return glest; + } else { + throw runtime_error("Map " + mapName + " not found."); + } +} + // ===================================================== // class PosCircularIterator // ===================================================== diff --git a/source/glest_game/world/map.h b/source/glest_game/world/map.h index 010e8795..755be3ae 100644 --- a/source/glest_game/world/map.h +++ b/source/glest_game/world/map.h @@ -223,7 +223,7 @@ public: //static static Vec2i toSurfCoords(Vec2i unitPos) {return unitPos/cellScale;} static Vec2i toUnitCoords(Vec2i surfPos) {return surfPos*cellScale;} - static string getMapPath(const string &mapName) {return "maps/"+mapName+".gbm";} + static string getMapPath(const string &mapName); private: //compute