#include <maps_list.h>
Collaboration diagram for MapsList:
Public Types | |
typedef std::vector< InfoMap >::iterator | iterator |
Public Member Functions | |
int | FindMapById (const std::string &id) |
void | SelectMapByName (const std::string &nom) |
void | SelectMapByIndex (uint index) |
int | GetActiveMapIndex () |
InfoMap & | ActiveMap () |
Static Public Member Functions | |
static MapsList * | GetInstance () |
Public Attributes | |
std::vector< InfoMap > | lst |
Private Member Functions | |
void | LoadOneMap (const std::string &dir, const std::string &file) |
MapsList () | |
Private Attributes | |
int | terrain_actif |
bool | m_init |
Static Private Attributes | |
static MapsList * | singleton = NULL |
Definition at line 83 of file maps_list.h.
typedef std::vector<InfoMap>::iterator MapsList::iterator |
Definition at line 87 of file maps_list.h.
MapsList::MapsList | ( | ) | [private] |
Definition at line 179 of file maps_list.cpp.
00180 { 00181 lst.clear() ; 00182 00183 std::cout << "o " << _("Load maps:"); 00184 terrain_actif = -1; 00185 00186 Config * config = Config::GetInstance(); 00187 std::string dirname = config->GetDataDir() + PATH_SEPARATOR + "map" + PATH_SEPARATOR; 00188 #if !defined(WIN32) || defined(__MINGW32__) 00189 DIR *dir = opendir(dirname.c_str()); 00190 struct dirent *file; 00191 if (dir != NULL) { 00192 while ((file = readdir(dir)) != NULL) 00193 LoadOneMap (dirname, file->d_name); 00194 closedir (dir); 00195 } else { 00196 Error (Format(_("Unable to open maps directory (%s)!"), 00197 dirname.c_str())); 00198 } 00199 #else 00200 std::string pattern = dirname + "*.*"; 00201 WIN32_FIND_DATA file; 00202 HANDLE file_search; 00203 file_search=FindFirstFile(pattern.c_str(),&file); 00204 if(file_search != INVALID_HANDLE_VALUE) 00205 { 00206 while (FindNextFile(file_search,&file)) 00207 { 00208 if(file.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) 00209 LoadOneMap(dirname,file.cFileName); 00210 } 00211 } else { 00212 Error (Format(_("Unable to open maps directory (%s)!"), 00213 dirname.c_str())); 00214 } 00215 FindClose(file_search); 00216 #endif 00217 00218 #if !defined(WIN32) || defined(__MINGW32__) 00219 // Load personal maps 00220 dirname = config->GetPersonalDir() + PATH_SEPARATOR + "map"; 00221 dir = opendir(dirname.c_str()); 00222 if (dir != NULL) { 00223 while ((file = readdir(dir)) != NULL) 00224 LoadOneMap (dirname, file->d_name); 00225 closedir (dir); 00226 } 00227 #endif 00228 std::cout << std::endl << std::endl; 00229 00230 // On a au moins une carte ? 00231 if (lst.size() < 1) 00232 Error(_("You need at least one valid map !")); 00233 00234 std::sort(lst.begin(), lst.end(), compareMaps); 00235 }
Here is the call graph for this function:
Here is the caller graph for this function:
InfoMap & MapsList::ActiveMap | ( | ) |
Definition at line 294 of file maps_list.cpp.
00295 { 00296 assert (0 <= terrain_actif); 00297 return lst.at(terrain_actif); 00298 }
Here is the caller graph for this function:
int MapsList::FindMapById | ( | const std::string & | id | ) |
int MapsList::GetActiveMapIndex | ( | ) |
Definition at line 289 of file maps_list.cpp.
00290 { 00291 return terrain_actif; 00292 }
Here is the caller graph for this function:
MapsList * MapsList::GetInstance | ( | ) | [static] |
void MapsList::LoadOneMap | ( | const std::string & | dir, | |
const std::string & | file | |||
) | [private] |
Definition at line 237 of file maps_list.cpp.
00238 { 00239 std::string fullname = dir+file; 00240 00241 #if !defined(WIN32) || defined(__MINGW32__) 00242 struct stat stat_file; 00243 if (file[0] == '.') return; 00244 if (stat(fullname.c_str(), &stat_file) != 0) return; 00245 if (!S_ISDIR(stat_file.st_mode)) return; 00246 #endif 00247 00248 InfoMap nv_terrain; 00249 bool ok = nv_terrain.Init (file, fullname + PATH_SEPARATOR); 00250 if (!ok) return; 00251 00252 std::cout << (lst.empty()?" ":", ") << file; 00253 std::cout.flush(); 00254 lst.push_back(nv_terrain); 00255 }
Here is the call graph for this function:
Here is the caller graph for this function:
void MapsList::SelectMapByIndex | ( | uint | index | ) |
Definition at line 280 of file maps_list.cpp.
00281 { 00282 assert (index < lst.size()); 00283 if (terrain_actif == (int)index) 00284 return; 00285 00286 terrain_actif = index; 00287 }
Here is the caller graph for this function:
void MapsList::SelectMapByName | ( | const std::string & | nom | ) |
Definition at line 269 of file maps_list.cpp.
00270 { 00271 int index = FindMapById (nom); 00272 00273 if (index == -1){ 00274 index = 0; 00275 std::cout << Format(_("! Map %s not found :-("), nom.c_str()) << std::endl; 00276 } 00277 SelectMapByIndex (index); 00278 }
Here is the call graph for this function:
Here is the caller graph for this function:
std::vector<InfoMap> MapsList::lst |
Definition at line 86 of file maps_list.h.
bool MapsList::m_init [private] |
Definition at line 91 of file maps_list.h.
MapsList * MapsList::singleton = NULL [static, private] |
Definition at line 92 of file maps_list.h.
int MapsList::terrain_actif [private] |
Definition at line 90 of file maps_list.h.