From: Ricardo Cruz Date: Fri, 9 Jul 2004 14:43:44 +0000 (+0000) Subject: Added worldmap choosing from command-line and menu. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=e43b147d6a1557b535b035ef5c8c4a3a1cb898f1;p=supertux.git Added worldmap choosing from command-line and menu. 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 --- diff --git a/src/globals.cpp b/src/globals.cpp index 6a4aaab4c..80775faa5 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -58,6 +58,7 @@ float game_speed = 1.0f; 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; diff --git a/src/globals.h b/src/globals.h index e2c4fff88..329c4a102 100644 --- a/src/globals.h +++ b/src/globals.h @@ -69,6 +69,7 @@ extern bool show_fps; 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; diff --git a/src/menu.cpp b/src/menu.cpp index a4e7ceb8b..d0eb6a87e 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -59,6 +59,7 @@ Menu* options_joystick_menu = 0; 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; diff --git a/src/menu.h b/src/menu.h index a3b99e021..8957f105e 100644 --- a/src/menu.h +++ b/src/menu.h @@ -33,7 +33,8 @@ enum MainMenuIDs { MNID_STARTGAME, - MNID_CONTRIB, + MNID_WORLDMAP_CONTRIB, + MNID_LEVELS_CONTRIB, MNID_OPTIONMENU, MNID_LEVELEDITOR, MNID_CREDITS, @@ -235,6 +236,7 @@ extern Surface* back; 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; diff --git a/src/setup.cpp b/src/setup.cpp index 5421cef01..f8c63c95a 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -383,12 +383,14 @@ void st_menu(void) 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); @@ -641,6 +643,7 @@ void st_general_free(void) 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; @@ -988,6 +991,10 @@ void parseargs(int argc, char * argv[]) { 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 ) { @@ -1065,7 +1072,8 @@ void parseargs(int argc, char * argv[]) " -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" @@ -1106,7 +1114,7 @@ void usage(char * prog, int ret) /* 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); diff --git a/src/supertux.cpp b/src/supertux.cpp index 7c46b7494..00fd2e1ad 100644 --- a/src/supertux.cpp +++ b/src/supertux.cpp @@ -67,6 +67,18 @@ int main(int argc, char * argv[]) 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); diff --git a/src/title.cpp b/src/title.cpp index e173d36d6..8be58de8b 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -45,6 +45,7 @@ #include "level.h" #include "level_subset.h" #include "gameloop.h" +#include "worldmap.h" #include "leveleditor.h" #include "scene.h" #include "player.h" @@ -53,6 +54,7 @@ #include "sector.h" #include "tilemap.h" #include "resources.h" +#include "type.h" #include "gettext.h" static Surface* bkg_title; @@ -71,6 +73,8 @@ static GameSession* titlesession; static std::vector contrib_subsets; static LevelSubset* current_contrib_subset = 0; +static string_list_type worldmap_list; + static LevelEditor* leveleditor; void free_contrib_menu() @@ -85,6 +89,7 @@ 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(); @@ -107,7 +112,7 @@ void generate_contrib_menu() string_list_free(&level_subsets); } -void check_contrib_menu() +void check_levels_contrib_menu() { static int current_subset = -1; @@ -172,6 +177,19 @@ void check_contrib_subset_menu() } } +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(); @@ -233,6 +251,19 @@ void title(void) 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; @@ -295,7 +326,9 @@ void title(void) // 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(); @@ -350,12 +383,16 @@ void title(void) } 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); diff --git a/src/worldmap.cpp b/src/worldmap.cpp index c12218435..546db1edd 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -378,12 +378,12 @@ WorldMap::~WorldMap() 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); @@ -960,6 +960,9 @@ WorldMap::display() void WorldMap::savegame(const std::string& filename) { + if(filename != "") + return; + std::cout << "savegame: " << filename << std::endl; std::ofstream out(filename.c_str()); @@ -1087,6 +1090,14 @@ WorldMap::loadgame(const std::string& filename) lisp_free(savegame); } +void +WorldMap::loadmap(const std::string& filename) +{ + savegame_file = ""; + map_filename = filename; + load_map(); +} + } // namespace WorldMapNS /* Local Variables: */ diff --git a/src/worldmap.h b/src/worldmap.h index 7a85f0fab..2186c495f 100644 --- a/src/worldmap.h +++ b/src/worldmap.h @@ -192,8 +192,13 @@ public: 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(); };