From 69ab58f652b9ee0b981d01d79ae74b5371418746 Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Sat, 10 Apr 2004 18:56:17 +0000 Subject: [PATCH] - reorganized menu flow as descripted in the todo, this breaks returning from the game at the moment, since something in loading savegames is broken, but since savegames needs restructuring anyway, it shouldn't be much of a problem SVN-Revision: 451 --- src/gameloop.cpp | 9 +++--- src/gameloop.h | 2 +- src/menu.cpp | 1 + src/menu.h | 2 +- src/setup.cpp | 85 ++++++++++++++++++++++++++++++++++++-------------------- src/setup.h | 7 ++++- src/title.cpp | 35 +++++++++++++++++------ src/worldmap.cpp | 4 +-- 8 files changed, 96 insertions(+), 49 deletions(-) diff --git a/src/gameloop.cpp b/src/gameloop.cpp index b4b4c8170..cf433cf5e 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -701,11 +701,11 @@ int gameloop(const char * subset, int levelnb, int mode) } else if(current_menu == save_game_menu ) { - process_save_load_game_menu(true); + process_save_game_menu(); } else if(current_menu == load_game_menu ) { - process_save_load_game_menu(false); + process_load_game_menu(); } } @@ -1619,7 +1619,7 @@ void loadgame(int slot) } -void slotinfo(char **pinfo, int slot) +std::string slotinfo(int slot) { FILE* fi; char slotfile[1024]; @@ -1648,7 +1648,6 @@ void slotinfo(char **pinfo, int slot) fclose(fi); } - *pinfo = (char*) malloc(sizeof(char) * (strlen(tmp)+1)); - strcpy(*pinfo,tmp); + return tmp; } diff --git a/src/gameloop.h b/src/gameloop.h index 2f3721543..3c9246545 100644 --- a/src/gameloop.h +++ b/src/gameloop.h @@ -35,7 +35,7 @@ void activate_bad_guys(st_level* plevel); int gameloop(const char * subset, int levelnb, int mode); void savegame(int slot); void loadgame(int slot); -void slotinfo(char **pinfo, int slot); +std::string slotinfo(int slot); bool issolid(float x, float y); bool isbrick(float x, float y); bool isice(float x, float y); diff --git a/src/menu.cpp b/src/menu.cpp index f8bfbf1e0..3ea29437f 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -43,6 +43,7 @@ Menu* options_controls_menu = 0; Menu* highscore_menu = 0; Menu* load_game_menu = 0; Menu* save_game_menu = 0; +Menu* contrib_menu = 0; Menu* current_menu = 0; diff --git a/src/menu.h b/src/menu.h index e8a3f4078..b0058d4f8 100644 --- a/src/menu.h +++ b/src/menu.h @@ -64,7 +64,6 @@ private: int width(); int height(); - public: timer_type effect; int arrange_left; @@ -106,6 +105,7 @@ extern bool show_menu; extern bool menu_change; extern texture_type checkbox, checkbox_checked, back, arrow_left, arrow_right; +extern Menu* contrib_menu; extern Menu* main_menu; extern Menu* game_menu; extern Menu* options_menu; diff --git a/src/setup.cpp b/src/setup.cpp index 8350bdf55..82e5d5640 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -11,6 +11,7 @@ */ #include +#include #include #include #include @@ -358,15 +359,24 @@ void st_menu(void) save_game_menu = new Menu(); game_menu = new Menu(); highscore_menu = new Menu(); + contrib_menu = new Menu(); main_menu->set_pos(screen->w/2, 335); - main_menu->additem(MN_ACTION,"Start Game",0,0); - main_menu->additem(MN_GOTO,"Load Game",0,load_game_menu); - main_menu->additem(MN_GOTO,"Options",0,options_menu); + main_menu->additem(MN_GOTO, "Start Game",0,load_game_menu); + main_menu->additem(MN_GOTO, "Contrib Levels",0,contrib_menu); + main_menu->additem(MN_GOTO, "Options",0,options_menu); main_menu->additem(MN_ACTION,"Level editor",0,0); main_menu->additem(MN_ACTION,"Credits",0,0); main_menu->additem(MN_ACTION,"Quit",0,0); + contrib_menu->additem(MN_LABEL,"Contrib Levels",0,0); + contrib_menu->additem(MN_HL,"",0,0); + contrib_menu->additem(MN_ACTION, "Some Levelset", 0, 0); + contrib_menu->additem(MN_ACTION, "Someother Levelset", 0, 0); + contrib_menu->additem(MN_ACTION, "Yet another Levelset", 0, 0); + contrib_menu->additem(MN_HL,"",0,0); + contrib_menu->additem(MN_BACK,"Back",0,0); + options_menu->additem(MN_LABEL,"Options",0,0); options_menu->additem(MN_HL,"",0,0); options_menu->additem(MN_TOGGLE,"Fullscreen",use_fullscreen,0); @@ -391,7 +401,7 @@ void st_menu(void) options_controls_menu->additem(MN_HL,"",0,0); options_controls_menu->additem(MN_BACK,"Back",0,0); - load_game_menu->additem(MN_LABEL,"Load Game",0,0); + load_game_menu->additem(MN_LABEL,"Start Game",0,0); load_game_menu->additem(MN_HL,"",0,0); load_game_menu->additem(MN_DEACTIVE,"Slot 1",0,0); load_game_menu->additem(MN_DEACTIVE,"Slot 2",0,0); @@ -427,43 +437,59 @@ void update_load_save_game_menu(Menu* pmenu, int load) { for(int i = 2; i < 7; ++i) { - char *tmp; - slotinfo(&tmp,i-1); - if(load && strlen(tmp) == strlen("Slot X - Free") ) - pmenu->item[i].kind = MN_DEACTIVE; + // FIXME: Insert a real savegame struct/class here instead of + // doing string vodoo + std::string tmp = slotinfo(i-1); + + if(load && tmp.length() == strlen("Slot X - Free")) + pmenu->item[i].kind = MN_ACTION; else pmenu->item[i].kind = MN_ACTION; - menu_item_change_text(&pmenu->item[i],tmp); - free(tmp); + menu_item_change_text(&pmenu->item[i], tmp.c_str()); } } -void process_save_load_game_menu(int save) +void process_save_game_menu() +{ + int slot = save_game_menu->check(); + if (slot != -1) + savegame(slot - 1); +} + +bool process_load_game_menu() { - int slot; - switch (slot = (save ? save_game_menu->check() : load_game_menu->check())) + int slot = load_game_menu->check(); + + if(slot != -1) { - default: - if(slot != -1) + // FIXME: Insert a real savegame struct/class here instead of + // doing string vodoo + std::string tmp = slotinfo(slot-1); + if (tmp.length() == strlen("Slot X - Free")) + { + gameloop("default", 1, ST_GL_PLAY); + show_menu = true; + Menu::set_current(main_menu); + } + else { - if(save) + if (game_started) { - savegame(slot - 1); + gameloop("default",slot - 1,ST_GL_LOAD_GAME); + show_menu = true; + Menu::set_current(main_menu); } else { - if (game_started) - { - gameloop("default",slot - 1,ST_GL_LOAD_GAME); - show_menu = true; - Menu::set_current(main_menu); - } - else - loadgame(slot - 1); + loadgame(slot - 1); } - st_pause_ticks_stop(); } - break; + st_pause_ticks_stop(); + return true; + } + else + { + return false; } } @@ -608,7 +634,7 @@ void st_video_setup(void) /* Set window manager stuff: */ - SDL_WM_SetCaption("Super Tux", "Super Tux"); + SDL_WM_SetCaption("SuperTux " VERSION, "SuperTux"); } @@ -941,8 +967,7 @@ void parseargs(int argc, char * argv[]) else if (strcmp(argv[i], "--version") == 0) { /* Show version: */ - - printf("Super Tux - version " VERSION "\n"); + printf("SuperTux " VERSION "\n"); exit(0); } else if (strcmp(argv[i], "--disable-sound") == 0) diff --git a/src/setup.h b/src/setup.h index a688ccc19..6e1b165a3 100644 --- a/src/setup.h +++ b/src/setup.h @@ -35,7 +35,12 @@ void st_shutdown(void); void st_menu(void); void st_abort(const std::string& reason, const std::string& details); void process_options_menu(void); -void process_save_load_game_menu(int save); + +void process_save_game_menu(); + +/** Return true if the gameloop() was entered, false otherwise */ +bool process_load_game_menu(); + void update_load_save_game_menu(Menu* pmenu, int load); void parseargs(int argc, char * argv[]); diff --git a/src/title.cpp b/src/title.cpp index 8bc8fa8dd..729851b81 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -190,7 +190,7 @@ int title(void) while (SDL_PollEvent(&event)) { - menu_event(event); + menu_event(event); if (event.type == SDL_QUIT) { /* Quit event - quit: */ @@ -231,10 +231,10 @@ int title(void) /* Draw the high score: */ /* - sprintf(str, "High score: %d", hs_score); - text_drawf(&gold_text, str, 0, -40, A_HMIDDLE, A_BOTTOM, 1); - sprintf(str, "by %s", hs_name); - text_drawf(&gold_text, str, 0, -20, A_HMIDDLE, A_BOTTOM, 1); + sprintf(str, "High score: %d", hs_score); + text_drawf(&gold_text, str, 0, -40, A_HMIDDLE, A_BOTTOM, 1); + sprintf(str, "by %s", hs_name); + text_drawf(&gold_text, str, 0, -20, A_HMIDDLE, A_BOTTOM, 1); */ /* Don't draw menu, if quit is true */ @@ -245,7 +245,10 @@ int title(void) { switch (main_menu->check()) { +#if 0 case 0: + // Quick Play + // FIXME: obsolete done = 0; i = 0; if(level_subsets.num_items != 0) @@ -278,8 +281,7 @@ int title(void) quit = 1; break; case SDL_KEYDOWN: // key pressed - /* Keypress... */ - + // Keypress... key = event.key.keysym.sym; if(key == SDLK_LEFT) @@ -322,9 +324,14 @@ int title(void) titletux.level_begin(); update_time = st_get_ticks(); break; - case 1: +#endif + case 0: + // Start Game, ie. goto the slots menu update_load_save_game_menu(load_game_menu, true); break; + case 1: + // Contrib Menu + break; case 3: done = 1; quit = leveleditor(1); @@ -343,7 +350,17 @@ int title(void) } else if(current_menu == load_game_menu) { - process_save_load_game_menu(false); + if (process_load_game_menu()) + { + // reset tux + scroll_x = 0; + titletux.level_begin(); + update_time = st_get_ticks(); + } + } + else if(current_menu == contrib_menu) + { + } mouse_cursor->draw(); diff --git a/src/worldmap.cpp b/src/worldmap.cpp index f873c9604..6c8d91812 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -105,8 +105,8 @@ Tux::Tux(WorldMap* worldmap_) texture_load(&sprite, datadir + "/images/worldmap/tux.png", USE_ALPHA); offset = 0; moving = false; - tile_pos.x = 0; - tile_pos.y = 0; + tile_pos.x = 5; + tile_pos.y = 5; direction = NONE; input_direction = NONE; } -- 2.11.0