* looks for 'gbm' (1-4 player) maps & 'mgm' (5-8 player) maps

This commit is contained in:
James McCulloch 2010-03-04 13:42:27 +00:00
parent b4ffb67c03
commit 06012e4804
3 changed files with 33 additions and 9 deletions

View File

@ -44,20 +44,28 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, b
needToSetChangedGameSettings = false;
lastSetChangedGameSettings = time(NULL);;
vector<string> results, teamItems, controlItems;
vector<string> 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.size(); ++i){
results[i]= formatString(results[i]);
if (!megaMaps.empty()) {
copy(megaMaps.begin(), megaMaps.end(), mapFiles.begin() + glestMaps.size());
}
if(mapFiles.size()==0){
throw runtime_error("There are no maps");
}
vector<string> 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();

View File

@ -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
// =====================================================

View File

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