[Super-tux-commit] supertux/src globals.cpp,1.22,1.23 globals.h,1.34,1.35 menu.cpp,1.83,1.84 menu.h,
Brought to you by:
wkendrick
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12892/src Modified Files: globals.cpp globals.h menu.cpp menu.h setup.cpp supertux.cpp title.cpp worldmap.cpp worldmap.h Log Message: 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. Index: menu.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/menu.cpp,v retrieving revision 1.83 retrieving revision 1.84 diff -u -d -r1.83 -r1.84 --- menu.cpp 2 Jul 2004 15:14:48 -0000 1.83 +++ menu.cpp 9 Jul 2004 14:43:44 -0000 1.84 @@ -59,6 +59,7 @@ 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; Index: setup.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/setup.cpp,v retrieving revision 1.106 retrieving revision 1.107 diff -u -d -r1.106 -r1.107 --- setup.cpp 7 Jul 2004 17:56:47 -0000 1.106 +++ setup.cpp 9 Jul 2004 14:43:44 -0000 1.107 @@ -383,12 +383,14 @@ 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 @@ 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 @@ { 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 @@ " -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 @@ /* 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); Index: menu.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/menu.h,v retrieving revision 1.67 retrieving revision 1.68 diff -u -d -r1.67 -r1.68 --- menu.h 14 Jun 2004 22:45:23 -0000 1.67 +++ menu.h 9 Jul 2004 14:43:44 -0000 1.68 @@ -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* arrow_left; extern Surface* arrow_right; +extern Menu* contrib_worldmap_menu; extern Menu* contrib_menu; extern Menu* contrib_subset_menu; extern Menu* main_menu; Index: globals.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/globals.cpp,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- globals.cpp 28 Jun 2004 17:12:34 -0000 1.22 +++ globals.cpp 9 Jul 2004 14:43:44 -0000 1.23 @@ -58,6 +58,7 @@ 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; Index: globals.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/globals.h,v retrieving revision 1.34 retrieving revision 1.35 diff -u -d -r1.34 -r1.35 --- globals.h 28 Jun 2004 17:12:34 -0000 1.34 +++ globals.h 9 Jul 2004 14:43:44 -0000 1.35 @@ -69,6 +69,7 @@ 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; Index: title.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/title.cpp,v retrieving revision 1.101 retrieving revision 1.102 diff -u -d -r1.101 -r1.102 --- title.cpp 9 Jul 2004 11:07:41 -0000 1.101 +++ title.cpp 9 Jul 2004 14:43:44 -0000 1.102 @@ -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 std::vector<LevelSubset*> 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 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 @@ 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_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 @@ 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 @@ // 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 @@ } 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); Index: worldmap.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.cpp,v retrieving revision 1.90 retrieving revision 1.91 diff -u -d -r1.90 -r1.91 --- worldmap.cpp 9 Jul 2004 10:38:58 -0000 1.90 +++ worldmap.cpp 9 Jul 2004 14:43:44 -0000 1.91 @@ -378,12 +378,12 @@ 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 @@ 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 @@ lisp_free(savegame); } +void +WorldMap::loadmap(const std::string& filename) +{ + savegame_file = ""; + map_filename = filename; + load_map(); +} + } // namespace WorldMapNS /* Local Variables: */ Index: worldmap.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.h,v retrieving revision 1.33 retrieving revision 1.34 diff -u -d -r1.33 -r1.34 --- worldmap.h 7 Jul 2004 17:56:01 -0000 1.33 +++ worldmap.h 9 Jul 2004 14:43:44 -0000 1.34 @@ -192,8 +192,13 @@ 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(); }; Index: supertux.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/supertux.cpp,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- supertux.cpp 28 Jun 2004 11:30:27 -0000 1.24 +++ supertux.cpp 9 Jul 2004 14:43:44 -0000 1.25 @@ -67,6 +67,18 @@ 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); |