40 |
//---------------------------------------- |
//---------------------------------------- |
41 |
namespace |
namespace |
42 |
{ |
{ |
|
|
|
|
class LevelPack_Enigma : public LevelPack { |
|
|
public: |
|
|
LevelPack_Enigma (const string &initfile, const string &n); |
|
|
|
|
|
// LevelPack interface |
|
|
void reinit(); |
|
|
|
|
|
string get_name() const { return m_name; } |
|
|
size_t size() const { return m_levels.size(); } |
|
|
|
|
|
bool load_level (size_t index) |
|
|
{ |
|
|
LevelInfo *levelinfo = get_info(index); |
|
|
return world::Load(levelinfo->filename); |
|
|
} |
|
|
|
|
|
LevelInfo *get_info (size_t index) { |
|
|
return &m_levels[index]; |
|
|
}; |
|
|
|
|
|
time_t get_modtime(size_t index) { // filedate of level |
|
|
const LevelInfo *levelinfo = get_info(index); |
|
|
string filename = enigma::FindDataFile(string("levels/")+levelinfo->filename+".lua"); |
|
|
return sysdep::FileModTime(filename); |
|
|
} |
|
|
|
|
|
int get_default_SoundSet() const { return 1; } |
|
|
|
|
|
bool needs_twoplayers() const { return false; } |
|
|
|
|
|
private: |
|
|
// Variables |
|
|
string m_initfile; |
|
|
string m_name; |
|
|
vector<LevelInfo> m_levels; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
43 |
class GameMenu : public gui::Menu { |
class GameMenu : public gui::Menu { |
44 |
public: |
public: |
45 |
GameMenu(); |
GameMenu(); |
164 |
vector<LevelPack *> LevelPacks; |
vector<LevelPack *> LevelPacks; |
165 |
} |
} |
166 |
|
|
167 |
|
void enigma::RegisterLevelPack (LevelPack *lp) |
|
/* |
|
|
** Read list of levels from this->init_file. |
|
|
*/ |
|
|
LevelPack_Enigma::LevelPack_Enigma (const string &initfile, const string &n) |
|
|
: m_initfile(initfile), m_name(n) |
|
|
{ |
|
|
reinit(); |
|
|
} |
|
|
|
|
|
void |
|
|
LevelPack_Enigma::reinit() |
|
|
{ |
|
|
string filename = enigma::FindDataFile(m_initfile); |
|
|
ifstream is(filename.c_str()); |
|
|
|
|
|
if (!is) { |
|
|
fprintf(stderr, "Couldn't load level pack %s.\n", filename.c_str()); |
|
|
return; |
|
|
} |
|
|
m_levels.clear(); |
|
|
|
|
|
string line; |
|
|
vector<string> tokens; |
|
|
while (getline(is, line)) { |
|
|
split_copy(line, '|', back_inserter(tokens)); |
|
|
transform(tokens.begin(), tokens.end(), tokens.begin(), trim<string>); |
|
|
|
|
|
size_t num_tokens = tokens.size(); |
|
|
if (num_tokens>0 && tokens[0].length()>0) { |
|
|
switch (num_tokens) { |
|
|
case 1: // level name only |
|
|
m_levels.push_back(LevelInfo(tokens[0], "", "")); |
|
|
break; |
|
|
case 2: // level name + long name |
|
|
m_levels.push_back(LevelInfo(tokens[0], tokens[1], "")); |
|
|
break; |
|
|
case 3: // level name + long name + author |
|
|
m_levels.push_back(LevelInfo(tokens[0], tokens[1], tokens[2])); |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
tokens.clear(); |
|
|
} |
|
|
} |
|
|
|
|
|
void |
|
|
enigma::AddLevelPack (const char *init_file, const char *name) |
|
168 |
{ |
{ |
|
LevelPack *lp = new LevelPack_Enigma (init_file, name); |
|
169 |
LevelPacks.push_back(lp); |
LevelPacks.push_back(lp); |
170 |
} |
} |
171 |
|
|
262 |
} |
} |
263 |
} |
} |
264 |
|
|
265 |
static string displayedLevelInfo(LevelInfo *info) { |
static string displayedLevelInfo (const LevelInfo *info) |
266 |
string displayed; |
{ |
267 |
|
string displayed = (info->name.empty()) ? |
268 |
if (info->name.empty()) displayed = "Another nameless level"; |
"Another nameless level" : string("\"")+info->name+"\""; |
269 |
else displayed = string("\"")+info->name+"\""; |
if (!info->author.empty()) |
270 |
|
displayed += " by "+info->author; |
|
if (!info->author.empty()) displayed += " by "+info->author; |
|
|
|
|
271 |
return displayed; |
return displayed; |
272 |
} |
} |
273 |
|
|
325 |
} |
} |
326 |
case LEVELINIT: { |
case LEVELINIT: { |
327 |
const int BUFSIZE = 50; |
const int BUFSIZE = 50; |
328 |
LevelInfo *info = level_pack->get_info(icurrent_level); |
const LevelInfo *info = level_pack->get_info(icurrent_level); |
329 |
char buffer[BUFSIZE+1]; |
char buffer[BUFSIZE+1]; |
330 |
|
|
331 |
snprintf(buffer, BUFSIZE, "Enigma - %s ", info->name.c_str()); |
snprintf(buffer, BUFSIZE, "Enigma - %s ", info->name.c_str()); |
424 |
video::HideMouse(); |
video::HideMouse(); |
425 |
|
|
426 |
sound::FadeoutMusic(); |
sound::FadeoutMusic(); |
427 |
if( options::InGameMusic) |
if (options::InGameMusic) { |
|
{ |
|
428 |
sound::PlayMusic( options::LevelMusicFile.c_str()); |
sound::PlayMusic( options::LevelMusicFile.c_str()); |
429 |
} else { |
} else { |
430 |
sound::StopMusic(); |
sound::StopMusic(); |
717 |
if (levelidx >= size) |
if (levelidx >= size) |
718 |
break; |
break; |
719 |
|
|
720 |
LevelInfo *info = lp->get_info(levelidx); |
const LevelInfo *info = lp->get_info(levelidx); |
721 |
|
|
722 |
if (skip_todo_and_unnamed && (info->filename == "todo" || info->name == "")) |
if (skip_todo_and_unnamed && (info->filename == "todo" || info->name == "")) |
723 |
continue; // skip "todo" and unnamed levels |
continue; // skip "todo" and unnamed levels |