[Super-tux-commit] supertux/src gameloop.cpp,1.80,1.81 menu.cpp,1.38,1.39 menu.h,1.37,1.38 supertux.
Brought to you by:
wkendrick
From: Ingo R. <gr...@us...> - 2004-04-19 21:21:13
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13812 Modified Files: gameloop.cpp menu.cpp menu.h supertux.cpp title.cpp title.h worldmap.cpp Log Message: - fixed problem with last_menu not being able to handle menues deeper than two submenues - misc other cleanup Index: menu.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/menu.cpp,v retrieving revision 1.38 retrieving revision 1.39 diff -u -d -r1.38 -r1.39 --- menu.cpp 19 Apr 2004 19:22:27 -0000 1.38 +++ menu.cpp 19 Apr 2004 21:21:00 -0000 1.39 @@ -1,20 +1,28 @@ -/* - menu.c - - Super Tux - Menu - - by Tobias Glaesser - tob...@gm... - http://www.newbreedsoftware.com/supertux/ - - December 20, 2003 - March 15, 2004 -*/ +// $Id$ +// +// SuperTux +// Copyright (C) 2004 Tobias Glaesser <tob...@gm...> +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef WIN32 #include <sys/types.h> #include <ctype.h> #endif +#include <iostream> #include <stdlib.h> #include <stdio.h> #include <string.h> @@ -47,6 +55,7 @@ Menu* contrib_menu = 0; Menu* contrib_subset_menu = 0; +std::stack<Menu*> Menu::last_menus; Menu* Menu::current_ = 0; void @@ -54,7 +63,9 @@ { if (menu) { - menu->last_menu = current_; + if (last_menus.empty() || menu != last_menus.top()) + last_menus.push(current_); + menu->effect.start(500); } @@ -136,10 +147,8 @@ pos_x = screen->w/2; pos_y = screen->h/2; has_backitem = false; - last_menu = 0; arrange_left = 0; active_item = 0; - last_menu = 0; effect.init(false); } @@ -242,8 +251,11 @@ break; case MN_BACK: - if(last_menu != NULL) - Menu::set_current(last_menu); + if (!last_menus.empty()) + { + Menu::set_current(last_menus.top()); + last_menus.pop(); + } break; default: break; @@ -581,8 +593,11 @@ case SDLK_ESCAPE: if(Menu::current()) { - if (has_backitem == true && last_menu != NULL) - Menu::set_current(last_menu); + if (has_backitem == true && !last_menus.empty()) + { + Menu::set_current(last_menus.top()); + last_menus.pop(); + } else Menu::set_current(0); } Index: menu.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/menu.h,v retrieving revision 1.37 retrieving revision 1.38 diff -u -d -r1.37 -r1.38 --- menu.h 19 Apr 2004 19:22:27 -0000 1.37 +++ menu.h 19 Apr 2004 21:21:00 -0000 1.38 @@ -1,20 +1,28 @@ -/* - menu.h - - Super Tux - Menu - - by Tobias Glaesser - tob...@gm... - http://www.newbreedsoftware.com/supertux/ - - December 20, 2003 -*/ +// $Id$ +// +// SuperTux +// Copyright (C) 2004 Tobias Glaesser <tob...@gm...> +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef SUPERTUX_MENU_H #define SUPERTUX_MENU_H #include <SDL.h> #include <vector> +#include <stack> #include "texture.h" #include "timer.h" #include "type.h" @@ -55,6 +63,16 @@ class Menu { +private: + static std::stack<Menu*> last_menus; + static Menu* current_; +public: + /** Set the current menu, if pmenu is NULL, hide the current menu */ + static void set_current(Menu* pmenu); + + /** Return the current active menu or NULL if none is active */ + static Menu* current() { return current_; } + private: /* Action done on the menu */ enum MenuAction { @@ -73,27 +91,22 @@ int pos_y; bool has_backitem; - /** input event for the menu */ + /** input event for the menu (up, down, left, right, etc.) */ MenuAction menuaction; /* input implementation variables */ int delete_character; char mn_input_char; - Menu* last_menu; int width(); int height(); - - static Menu* current_; + public: Timer effect; int arrange_left; int active_item; - std::vector<MenuItem> item; - /** Set the current menu, if pmenu is NULL, hide the current menu */ - static void set_current(Menu* pmenu); - static Menu* current() { return current_; } + std::vector<MenuItem> item; Menu(); ~Menu(); @@ -105,8 +118,11 @@ /** Remove all entries from the menu */ void clear(); - /** Check, if the value of the active menu item has changed. */ + /** Check, if the value of the active menu item has changed. FIXME: + Somebody should document the exact meaning of this function a + bit more */ int check (); + void draw (); void draw_item(int index, int menu_width, int menu_height); void set_pos(int x, int y, float rw = 0, float rh = 0); Index: title.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/title.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- title.h 11 Apr 2004 01:24:58 -0000 1.3 +++ title.h 19 Apr 2004 21:21:00 -0000 1.4 @@ -10,4 +10,4 @@ April 11, 2000 - March 15, 2004 */ -bool title(void); +void title(void); Index: title.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/title.cpp,v retrieving revision 1.47 retrieving revision 1.48 diff -u -d -r1.47 -r1.48 --- title.cpp 19 Apr 2004 19:22:27 -0000 1.47 +++ title.cpp 19 Apr 2004 21:21:00 -0000 1.48 @@ -49,8 +49,6 @@ static bool walking; static Timer random_timer; -static SDL_Event event; -static SDLKey key; static int frame, i; static unsigned int last_update_time; static unsigned int update_time; @@ -217,7 +215,7 @@ } /* --- TITLE SCREEN --- */ -bool title(void) +void title(void) { st_subset subset; random_timer.init(true); @@ -232,24 +230,21 @@ updatescreen(); /* Load images: */ - bkg_title = new Surface(datadir + "/images/title/background.jpg", IGNORE_ALPHA); logo = new Surface(datadir + "/images/title/logo.png", USE_ALPHA); img_choose_subset = new Surface(datadir + "/images/status/choose-level-subset.png", USE_ALPHA); /* --- Main title loop: --- */ - bool done = 0; frame = 0; /* Draw the title background: */ bkg_title->draw_bg(); - load_hs(); update_time = st_get_ticks(); random_timer.start(rand() % 2000 + 2000); Menu::set_current(main_menu); - while (!done) + while (Menu::current()) { // Calculate the movement-factor double frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE); @@ -258,29 +253,18 @@ /* Lower the frame_ratio that Tux doesn't jump to hectically throught the demo. */ frame_ratio /= 2; - /* Handle events: */ - + SDL_Event event; while (SDL_PollEvent(&event)) { - if (event.type == SDL_QUIT) + if (Menu::current()) { - done = true; + Menu::current()->event(event); } - else if (event.type == SDL_KEYDOWN) + else { - /* Keypress... */ - key = event.key.keysym.sym; - - if (Menu::current()) - { - Menu::current()->event(event); - } - - if (!Menu::current()) - { - /* Escape: Quit: */ - done = true; - } + // FIXME: QUIT signal should be handled more generic, not locally + if (event.type == SDL_QUIT) + Menu::set_current(0); } } @@ -299,7 +283,7 @@ 0, 420, 0); /* Don't draw menu, if quit is true */ - if(!done) + if(Menu::current()) { Menu::current()->action(); Menu::current()->draw(); @@ -318,15 +302,15 @@ update_contrib_menu(); break; case 3: - done = true; - done = leveleditor(1); + leveleditor(1); Menu::set_current(main_menu); break; case 4: display_credits(); + Menu::set_current(main_menu); break; case 5: - done = true; + Menu::set_current(0); break; } } @@ -371,9 +355,6 @@ delete bkg_title; delete logo; - - /* Return to main! */ - return done; } #define MAX_VEL 10 @@ -427,6 +408,7 @@ while(done == 0) { /* in case of input, exit */ + SDL_Event event; while(SDL_PollEvent(&event)) switch(event.type) { Index: worldmap.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.cpp,v retrieving revision 1.36 retrieving revision 1.37 diff -u -d -r1.36 -r1.37 --- worldmap.cpp 19 Apr 2004 19:22:27 -0000 1.36 +++ worldmap.cpp 19 Apr 2004 21:21:00 -0000 1.37 @@ -364,8 +364,7 @@ void WorldMap::on_escape_press() { - std::cout << "on escape press" << std::endl; - + // Show or hide the menu if(!Menu::current()) Menu::set_current(worldmap_menu); else Index: supertux.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/supertux.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- supertux.cpp 17 Apr 2004 00:49:54 -0000 1.11 +++ supertux.cpp 19 Apr 2004 21:21:00 -0000 1.12 @@ -27,8 +27,6 @@ int main(int argc, char * argv[]) { - bool done; - st_directory_setup(); parseargs(argc, argv); @@ -51,11 +49,7 @@ } else { - done = false; - while (!done) - { - done = title(); - } + title(); } clearscreen(0, 0, 0); Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.80 retrieving revision 1.81 diff -u -d -r1.80 -r1.81 --- gameloop.cpp 19 Apr 2004 19:22:26 -0000 1.80 +++ gameloop.cpp 19 Apr 2004 21:20:57 -0000 1.81 @@ -131,22 +131,14 @@ void GameSession::on_escape_press() { - if(!game_pause) + if(st_gl_mode == ST_GL_TEST) { - if(st_gl_mode == ST_GL_TEST) - { - exit_status = LEVEL_ABORT; - } - else if (!Menu::current()) - { - Menu::set_current(game_menu); - st_pause_ticks_stop(); - } - else - { - Menu::set_current(NULL); - st_pause_ticks_start(); - } + exit_status = LEVEL_ABORT; + } + else if (!Menu::current()) + { + Menu::set_current(game_menu); + st_pause_ticks_stop(); } } @@ -160,151 +152,153 @@ { /* Check for menu-events, if the menu is shown */ if (Menu::current()) - Menu::current()->event(event); - - switch(event.type) { - case SDL_QUIT: /* Quit event - quit: */ - st_abort("Received window close", ""); - break; - - case SDL_KEYDOWN: /* A keypress! */ - { - SDLKey key = event.key.keysym.sym; - - if(tux.key_event(key,DOWN)) + Menu::current()->event(event); + } + else + { + switch(event.type) + { + case SDL_QUIT: /* Quit event - quit: */ + st_abort("Received window close", ""); break; - switch(key) + case SDL_KEYDOWN: /* A keypress! */ { - case SDLK_ESCAPE: /* Escape: Open/Close the menu: */ - on_escape_press(); - break; - default: - break; - } - } - break; - case SDL_KEYUP: /* A keyrelease! */ - { - SDLKey key = event.key.keysym.sym; + SDLKey key = event.key.keysym.sym; + + if(tux.key_event(key,DOWN)) + break; - if(tux.key_event(key, UP)) + switch(key) + { + case SDLK_ESCAPE: /* Escape: Open/Close the menu: */ + on_escape_press(); + break; + default: + break; + } + } break; - - switch(key) + case SDL_KEYUP: /* A keyrelease! */ { - case SDLK_p: - if(!Menu::current()) + SDLKey key = event.key.keysym.sym; + + if(tux.key_event(key, UP)) + break; + + switch(key) { - if(game_pause) - { - game_pause = false; - st_pause_ticks_stop(); - } - else + case SDLK_p: + if(!Menu::current()) { - game_pause = true; - st_pause_ticks_start(); + if(game_pause) + { + game_pause = false; + st_pause_ticks_stop(); + } + else + { + game_pause = true; + st_pause_ticks_start(); + } } - } - break; - case SDLK_TAB: - if(debug_mode) - { - tux.size = !tux.size; - if(tux.size == BIG) + break; + case SDLK_TAB: + if(debug_mode) { - tux.base.height = 64; + tux.size = !tux.size; + if(tux.size == BIG) + { + tux.base.height = 64; + } + else + tux.base.height = 32; } + break; + case SDLK_END: + if(debug_mode) + player_status.distros += 50; + break; + case SDLK_DELETE: + if(debug_mode) + tux.got_coffee = 1; + break; + case SDLK_INSERT: + if(debug_mode) + tux.invincible_timer.start(TUX_INVINCIBLE_TIME); + break; + case SDLK_l: + if(debug_mode) + --player_status.lives; + break; + case SDLK_s: + if(debug_mode) + player_status.score += 1000; + case SDLK_f: + if(debug_fps) + debug_fps = false; else - tux.base.height = 32; + debug_fps = true; + break; + default: + break; } - break; - case SDLK_END: - if(debug_mode) - player_status.distros += 50; - break; - case SDLK_DELETE: - if(debug_mode) - tux.got_coffee = 1; - break; - case SDLK_INSERT: - if(debug_mode) - tux.invincible_timer.start(TUX_INVINCIBLE_TIME); - break; - case SDLK_l: - if(debug_mode) - --player_status.lives; - break; - case SDLK_s: - if(debug_mode) - player_status.score += 1000; - case SDLK_f: - if(debug_fps) - debug_fps = false; - else - debug_fps = true; - break; - default: - break; } - } - break; + break; - case SDL_JOYAXISMOTION: - switch(event.jaxis.axis) - { - case JOY_X: - if (event.jaxis.value < -JOYSTICK_DEAD_ZONE) - { - tux.input.left = DOWN; - tux.input.right = UP; - } - else if (event.jaxis.value > JOYSTICK_DEAD_ZONE) - { - tux.input.left = UP; - tux.input.right = DOWN; - } - else + case SDL_JOYAXISMOTION: + switch(event.jaxis.axis) { - tux.input.left = DOWN; - tux.input.right = DOWN; + case JOY_X: + if (event.jaxis.value < -JOYSTICK_DEAD_ZONE) + { + tux.input.left = DOWN; + tux.input.right = UP; + } + else if (event.jaxis.value > JOYSTICK_DEAD_ZONE) + { + tux.input.left = UP; + tux.input.right = DOWN; + } + else + { + tux.input.left = DOWN; + tux.input.right = DOWN; + } + break; + case JOY_Y: + if (event.jaxis.value > JOYSTICK_DEAD_ZONE) + tux.input.down = DOWN; + else if (event.jaxis.value < -JOYSTICK_DEAD_ZONE) + tux.input.down = UP; + else + tux.input.down = UP; + + break; + default: + break; } break; - case JOY_Y: - if (event.jaxis.value > JOYSTICK_DEAD_ZONE) - tux.input.down = DOWN; - else if (event.jaxis.value < -JOYSTICK_DEAD_ZONE) - tux.input.down = UP; - else - tux.input.down = UP; - - break; - default: + case SDL_JOYBUTTONDOWN: + if (event.jbutton.button == JOY_A) + tux.input.up = DOWN; + else if (event.jbutton.button == JOY_B) + tux.input.fire = DOWN; + else if (event.jbutton.button == JOY_START) + on_escape_press(); + break; + case SDL_JOYBUTTONUP: + if (event.jbutton.button == JOY_A) + tux.input.up = UP; + else if (event.jbutton.button == JOY_B) + tux.input.fire = UP; break; - } - break; - case SDL_JOYBUTTONDOWN: - if (event.jbutton.button == JOY_A) - tux.input.up = DOWN; - else if (event.jbutton.button == JOY_B) - tux.input.fire = DOWN; - else if (event.jbutton.button == JOY_START) - on_escape_press(); - break; - case SDL_JOYBUTTONUP: - if (event.jbutton.button == JOY_A) - tux.input.up = UP; - else if (event.jbutton.button == JOY_B) - tux.input.fire = UP; - break; - - default: - break; - - } /* switch */ + default: + break; + } /* switch */ + } } /* while */ } @@ -331,14 +325,6 @@ { // No more lives!? if(st_gl_mode != ST_GL_TEST) drawendscreen(); - - if(st_gl_mode != ST_GL_TEST) - { - // FIXME: highscore soving doesn't make sense in its - // current form - //if (player_status.score > hs_score) - //save_hs(player_status.score); - } exit_status = GAME_OVER; } @@ -572,13 +558,7 @@ white_text->draw("SCORE", 0, 0, 1); gold_text->draw(str, 96, 0, 1); - if(st_gl_mode != ST_GL_TEST) - { - sprintf(str, "%d", hs_score); - white_text->draw("HIGH", 0, 20, 1); - gold_text->draw(str, 96, 20, 1); - } - else + if(st_gl_mode == ST_GL_TEST) { white_text->draw("Press ESC To Return",0,20,1); } |