Contributed maps must be in data/levels/worldmap, included the ones run from the command-line.
It is possible to feed maps with absolute path, but it is just a hack that converts them to relative paths to the worldmap folder. I did this, in order to make it possible for someone to add a mime-type for Konqueror as 'supertux --worldmap' and press a .stwt file from worldmap dir.
About the Contrib Worlds menu, we might consider just making one Contrib menu, and make levels from different folders to create dynamically a map.
Till that day, let's keep this menu.
SVN-Revision: 1555
int joystick_num = 0;
char* level_startup_file = 0;
bool launch_leveleditor_mode = false;
+bool launch_worldmap_mode = false;
/* SuperTux directory ($HOME/.supertux) and save directory($HOME/.supertux/save) */
char *st_dir, *st_save_dir;
extern int joystick_num;
extern char* level_startup_file;
extern bool launch_leveleditor_mode;
+extern bool launch_worldmap_mode;
/* SuperTux directory ($HOME/.supertux) and save directory($HOME/.supertux/save) */
extern char* st_dir;
Menu* highscore_menu = 0;
Menu* load_game_menu = 0;
Menu* save_game_menu = 0;
+Menu* contrib_worldmap_menu = 0;
Menu* contrib_menu = 0;
Menu* contrib_subset_menu = 0;
enum MainMenuIDs {
MNID_STARTGAME,
- MNID_CONTRIB,
+ MNID_WORLDMAP_CONTRIB,
+ MNID_LEVELS_CONTRIB,
MNID_OPTIONMENU,
MNID_LEVELEDITOR,
MNID_CREDITS,
extern Surface* arrow_left;
extern Surface* arrow_right;
+extern Menu* contrib_worldmap_menu;
extern Menu* contrib_menu;
extern Menu* contrib_subset_menu;
extern Menu* main_menu;
game_menu = new Menu();
highscore_menu = new Menu();
contrib_menu = new Menu();
+ contrib_worldmap_menu = new Menu();
contrib_subset_menu = new Menu();
worldmap_menu = new Menu();
main_menu->set_pos(screen->w/2, 335);
main_menu->additem(MN_GOTO, _("Start Game"),0,load_game_menu, MNID_STARTGAME);
- main_menu->additem(MN_GOTO, _("Contrib Levels"),0,contrib_menu, MNID_CONTRIB);
+ main_menu->additem(MN_GOTO, _("Contrib Worlds"),0,contrib_worldmap_menu, MNID_WORLDMAP_CONTRIB);
+ main_menu->additem(MN_GOTO, _("Contrib Levels"),0,contrib_menu, MNID_LEVELS_CONTRIB);
main_menu->additem(MN_GOTO, _("Options"),0,options_menu, MNID_OPTIONMENU);
main_menu->additem(MN_ACTION, _("Level Editor"),0,0, MNID_LEVELEDITOR);
main_menu->additem(MN_ACTION, _("Credits"),0,0, MNID_CREDITS);
delete options_keys_menu;
delete options_joystick_menu;
delete highscore_menu;
+ delete contrib_worldmap_menu;
delete contrib_menu;
delete contrib_subset_menu;
delete worldmap_menu;
{
launch_leveleditor_mode = true;
}
+ else if (strcmp(argv[i], "--worldmap") == 0)
+ {
+ launch_worldmap_mode = true;
+ }
else if (strcmp(argv[i], "--datadir") == 0
|| strcmp(argv[i], "-d") == 0 )
{
" -j, --joystick NUM Use joystick NUM (default: 0)\n"
" --joymap XAXIS:YAXIS:A:B:START\n"
" Define how joystick buttons and axis should be mapped\n"
- " --leveleditor Opens the leveleditor in a file. (Only works when a file is provided.)\n"
+ " --leveleditor Opens the leveleditor in a file.\n"
+ " --worldmap Opens the specified worldmap file.\n"
" -d, --datadir DIR Load Game data from DIR (default: automatic)\n"
" --debug Enables the debug mode, which is useful for developers.\n"
" --help Display a help message summarizing command-line\n"
/* Display the usage message: */
- fprintf(fi, _("Usage: %s [--fullscreen] [--opengl] [--disable-sound] [--disable-music] [--debug] | [--usage | --help | --version] [--leveleditor] FILENAME\n"),
+ fprintf(fi, _("Usage: %s [--fullscreen] [--opengl] [--disable-sound] [--disable-music] [--debug] | [--usage | --help | --version] [--leveleditor] [--worldmap] FILENAME\n"),
prog);
else
leveleditor.run();
}
+ else if (launch_worldmap_mode && level_startup_file)
+ {
+ // hack to make it possible for someone to give an absolute path
+ std::string str(level_startup_file);
+ unsigned int i = str.find_last_of("/", str.size());
+ if(i != std::string::npos)
+ str.erase(0, i+1);
+
+ WorldMapNS::WorldMap worldmap;
+ worldmap.loadmap(str);
+ worldmap.display();
+ }
else if (level_startup_file)
{
GameSession session(level_startup_file, ST_GL_LOAD_LEVEL_FILE);
#include "level.h"
#include "level_subset.h"
#include "gameloop.h"
+#include "worldmap.h"
#include "leveleditor.h"
#include "scene.h"
#include "player.h"
#include "sector.h"
#include "tilemap.h"
#include "resources.h"
+#include "type.h"
#include "gettext.h"
static Surface* bkg_title;
static std::vector<LevelSubset*> contrib_subsets;
static LevelSubset* current_contrib_subset = 0;
+static string_list_type worldmap_list;
+
static LevelEditor* leveleditor;
void free_contrib_menu()
void generate_contrib_menu()
{
+ /** Generating contrib levels list by making use of Level Subset */
string_list_type level_subsets = dsubdirs("/levels", "info");
free_contrib_menu();
string_list_free(&level_subsets);
}
-void check_contrib_menu()
+void check_levels_contrib_menu()
{
static int current_subset = -1;
}
}
+void check_contrib_worldmap_menu()
+{
+ int index = contrib_worldmap_menu->check();
+ if (index != -1)
+ {
+ WorldMapNS::WorldMap worldmap;
+ worldmap.loadmap(worldmap_list.item[index]);
+ worldmap.display();
+
+ Menu::set_current(main_menu);
+ }
+}
+
void draw_demo(double frame_ratio)
{
Sector* world = titlesession->get_current_sector();
logo = new Surface(datadir + "/images/title/logo.png", USE_ALPHA);
img_choose_subset = new Surface(datadir + "/images/status/choose-level-subset.png", USE_ALPHA);
+ /* Generating contrib maps by only using a string_list */
+ worldmap_list = dfiles("levels/worldmap", NULL, NULL);
+
+ contrib_worldmap_menu->additem(MN_LABEL, _("Contrib Worlds"), 0,0);
+ contrib_worldmap_menu->additem(MN_HL, "", 0,0);
+ for(int i = 0; i < worldmap_list.num_items; i++)
+ contrib_worldmap_menu->additem(MN_ACTION, worldmap_list.item[i],0,0,i);
+ contrib_worldmap_menu->additem(MN_HL,"",0,0);
+ contrib_worldmap_menu->additem(MN_BACK,"Back",0,0);
+
+ titlesession->get_current_sector()->activate();
+ titlesession->set_current();
+
/* --- Main title loop: --- */
frame = 0;
// Start Game, ie. goto the slots menu
update_load_save_game_menu(load_game_menu);
break;
- case MNID_CONTRIB:
+ case MNID_WORLDMAP_CONTRIB:
+ break;
+ case MNID_LEVELS_CONTRIB:
// Contrib Menu
puts("Entering contrib menu");
generate_contrib_menu();
}
else if(menu == contrib_menu)
{
- check_contrib_menu();
+ check_levels_contrib_menu();
}
else if (menu == contrib_subset_menu)
{
check_contrib_subset_menu();
}
+ else if(menu == contrib_worldmap_menu)
+ {
+ check_contrib_worldmap_menu();
+ }
}
mouse_cursor->draw(context);
void
WorldMap::load_map()
{
+ std::cout << "Loading map: " << datadir + "/levels/worldmap/" + map_filename << std::endl;
+
lisp_object_t* root_obj = lisp_read_from_file(datadir + "/levels/worldmap/" + map_filename);
if (!root_obj)
st_abort("Couldn't load file", datadir + "/levels/worldmap/" + map_filename);
- std::cout << "Loading map: " << datadir + "/levels/worldmap/" + map_filename << std::endl;
-
if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-worldmap") == 0)
{
lisp_object_t* cur = lisp_cdr(root_obj);
void
WorldMap::savegame(const std::string& filename)
{
+ if(filename != "")
+ return;
+
std::cout << "savegame: " << filename << std::endl;
std::ofstream out(filename.c_str());
lisp_free(savegame);
}
+void
+WorldMap::loadmap(const std::string& filename)
+{
+ savegame_file = "";
+ map_filename = filename;
+ load_map();
+}
+
} // namespace WorldMapNS
/* Local Variables: */
if possible, write the new position to \a new_pos */
bool path_ok(Direction direction, Vector pos, Vector* new_pos);
+ /* Save map to slot */
void savegame(const std::string& filename);
+ /* Load map from slot */
void loadgame(const std::string& filename);
+ /* Load map directly from file */
+ void loadmap(const std::string& filename);
+
private:
void on_escape_press();
};