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();
}
}
{
/* 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 */
}
{ // 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;
}
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);
}
-/*
- menu.c
-
- Super Tux - Menu
-
- by Tobias Glaesser
- tobi.web@gmx.de
- http://www.newbreedsoftware.com/supertux/
-
- December 20, 2003 - March 15, 2004
-*/
+// $Id$
+//
+// SuperTux
+// Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
+//
+// 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>
Menu* contrib_menu = 0;
Menu* contrib_subset_menu = 0;
+std::stack<Menu*> Menu::last_menus;
Menu* Menu::current_ = 0;
void
{
if (menu)
{
- menu->last_menu = current_;
+ if (last_menus.empty() || menu != last_menus.top())
+ last_menus.push(current_);
+
menu->effect.start(500);
}
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);
}
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;
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);
}
-/*
- menu.h
-
- Super Tux - Menu
-
- by Tobias Glaesser
- tobi.web@gmx.de
- http://www.newbreedsoftware.com/supertux/
-
- December 20, 2003
-*/
+// $Id$
+//
+// SuperTux
+// Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
+//
+// 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"
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 {
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();
/** 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);
int main(int argc, char * argv[])
{
- bool done;
-
st_directory_setup();
parseargs(argc, argv);
}
else
{
- done = false;
- while (!done)
- {
- done = title();
- }
+ title();
}
clearscreen(0, 0, 0);
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;
}
/* --- TITLE SCREEN --- */
-bool title(void)
+void title(void)
{
st_subset subset;
random_timer.init(true);
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);
/* 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);
}
}
0, 420, 0);
/* Don't draw menu, if quit is true */
- if(!done)
+ if(Menu::current())
{
Menu::current()->action();
Menu::current()->draw();
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;
}
}
delete bkg_title;
delete logo;
-
- /* Return to main! */
- return done;
}
#define MAX_VEL 10
while(done == 0)
{
/* in case of input, exit */
+ SDL_Event event;
while(SDL_PollEvent(&event))
switch(event.type)
{
April 11, 2000 - March 15, 2004
*/
-bool title(void);
+void title(void);
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