1
/***************************************************************************
2
* Copyright (C) 2005 by Bjorn Hansen *
3
* holomorph@users.sourceforge.net *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
22
#include "menu/widgets/maplistmodel.h"
25
using namespace Balder;
27
MapListModel::MapListModel(): numMaps(0)
31
MapListModel::~MapListModel()
34
bool find_file( const std::string map_dir, const std::string & file_name)
36
char **files = PHYSFS_enumerateFiles(map_dir.c_str());
38
for (i = files; *i != NULL; i++){
41
PHYSFS_freeList(files);
45
PHYSFS_freeList(files);
49
void MapListModel::FindMaps()
51
std::string map_dir("maps/");
52
char **files = PHYSFS_enumerateFiles(map_dir.c_str());
55
Log::output("Importing map list...");
56
for (i = files; *i != NULL; i++){
58
if (PHYSFS_isDirectory((map_dir+mapname).c_str())){
59
// lets try to check that this directory really contains a map
60
if (find_file(map_dir+mapname, "maptags.xml")
61
&& find_file(map_dir+mapname, "geometry.png")
62
&& find_file(map_dir+mapname, "background.png") ) {
63
mapnames.push_back(mapname);
68
PHYSFS_freeList(files);
71
std::string Balder::MapListModel::getElementAt (int i)
75
Log::output("tried to get map at index higher than number of maps");
76
Log::output("numMaps: "+numMaps);
77
// Log::output("i :" +i);
78
return "--Map Not Found--";
84
\fn Balder::MapListModel::FindMapIndex(std::string mapname)
86
int Balder::MapListModel::FindMapIndex(std::string mapname)
88
for (int i = 0; i < numMaps; ++i) {
89
if (!mapname.compare(mapnames[i])) return i;