#define JOY_A 0
#define JOY_B 1
+#define JOY_START 9
#define JOY_X 0
#define JOY_Y 1
}
void
+GameSession::on_escape_press()
+{
+ if(!game_pause)
+ {
+ 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();
+ }
+ }
+}
+
+void
GameSession::process_events()
{
Player& tux = *world->get_tux();
while (SDL_PollEvent(&event))
{
/* Check for menu-events, if the menu is shown */
- current_menu->event(event);
+ if (Menu::current())
+ Menu::current()->event(event);
switch(event.type)
{
switch(key)
{
case SDLK_ESCAPE: /* Escape: Open/Close the menu: */
- if(!game_pause)
- {
- if(st_gl_mode == ST_GL_TEST)
- {
- exit_status = LEVEL_ABORT;
- }
- else if(!show_menu)
- {
- Menu::set_current(game_menu);
- show_menu = 0;
- st_pause_ticks_stop();
- }
- else
- {
- Menu::set_current(game_menu);
- show_menu = 1;
- st_pause_ticks_start();
- }
- }
+ on_escape_press();
break;
default:
break;
switch(key)
{
case SDLK_p:
- if(!show_menu)
+ if(!Menu::current())
{
if(game_pause)
{
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:
blue_text->drawf("PAUSE - Press 'P' To Play", 0, 230, A_HMIDDLE, A_TOP, 1);
}
- if(show_menu)
+ if(Menu::current())
{
menu_process_current();
mouse_cursor->draw();
process_events();
- if(show_menu)
+ if(Menu::current())
{
- if(current_menu == game_menu)
+ if(Menu::current() == game_menu)
{
switch (game_menu->check())
{
break;
}
}
- else if(current_menu == options_menu)
+ else if(Menu::current() == options_menu)
{
process_options_menu();
}
- else if(current_menu == load_game_menu )
+ else if(Menu::current() == load_game_menu )
{
process_load_game_menu();
}
}
// Handle actions:
- if(!game_pause && !show_menu)
+ if(!game_pause && !Menu::current())
{
frame_ratio *= game_speed;
frame_ratio += overlap;
draw();
/* Time stops in pause mode */
- if(game_pause || show_menu )
+ if(game_pause || Menu::current())
{
continue;
}
void drawstatus();
void drawendscreen();
void drawresultscreen(void);
+
+ private:
+ void on_escape_press();
};
std::string slotinfo(int slot);
hs_score = score;
- menu_reset();
Menu::set_current(highscore_menu);
if(!highscore_menu->item[0].input)
strcpy(highscore_menu->item[0].input,hs_name.c_str());
/* ask for player's name */
- show_menu = 1;
- while(show_menu)
+ while(Menu::current())
{
bkgd->draw_bg();
while(SDL_PollEvent(&event))
if(event.type == SDL_KEYDOWN)
- current_menu->event(event);
+ Menu::current()->event(event);
switch (highscore_menu->check())
{
updatescreen();
while (SDL_PollEvent(&event))
- {}
+ {}
while(true)
{
le_checkevents();
- if(current_menu == select_tilegroup_menu)
+ if(Menu::current() == select_tilegroup_menu)
{
if(select_tilegroup_menu_effect.check())
{
/* draw editor interface */
le_drawinterface();
- if(show_menu)
+ if(Menu::current())
{
menu_process_current();
- if(current_menu == leveleditor_menu)
+ if(Menu::current() == leveleditor_menu)
{
switch (leveleditor_menu->check())
{
case 2:
- show_menu = false;
+ Menu::set_current(0);
break;
case 3:
update_subset_settings_menu();
break;
}
}
- else if(current_menu == level_settings_menu)
+ else if(Menu::current() == level_settings_menu)
{
switch (level_settings_menu->check())
{
apply_level_settings_menu();
Menu::set_current(leveleditor_menu);
break;
+
default:
- show_menu = true;
+ //show_menu = true;
break;
}
}
- else if(current_menu == select_tilegroup_menu)
+ else if(Menu::current() == select_tilegroup_menu)
{
- int it = -1;
+ int it = -1;
switch (it = select_tilegroup_menu->check())
{
default:
if(it != -1)
- {
- if(select_tilegroup_menu->item[it].kind == MN_ACTION)
- cur_tilegroup = select_tilegroup_menu->item[it].text;
+ {
+ if(select_tilegroup_menu->item[it].kind == MN_ACTION)
+ cur_tilegroup = select_tilegroup_menu->item[it].text;
- show_menu = false;
- }
+ Menu::set_current(0);
+ }
break;
}
}
- else if(current_menu == subset_load_menu)
+ else if(Menu::current() == subset_load_menu)
{
switch (i = subset_load_menu->check())
{
le_set_defaults();
le_current_level->load_gfx();
le_world.activate_bad_guys();
- show_menu = true;
+
+ // FIXME:?
+ Menu::set_current(leveleditor_menu);
}
break;
}
}
- else if(current_menu == subset_new_menu)
+ else if(Menu::current() == subset_new_menu)
{
if(subset_new_menu->item[2].input[0] == '\0')
subset_new_menu->item[3].kind = MN_DEACTIVE;
le_current_level->load_gfx();
le_world.activate_bad_guys();
subset_new_menu->item[2].change_input("");
- show_menu = true;
+ // FIXME:? show_menu = true;
+ Menu::set_current(leveleditor_menu);
break;
}
}
}
- else if(current_menu == subset_settings_menu)
+ else if(Menu::current() == subset_settings_menu)
{
if(le_level_subset.title.compare(subset_settings_menu->item[2].input) == 0 && le_level_subset.description.compare(subset_settings_menu->item[3].input) == 0 )
subset_settings_menu->item[5].kind = MN_DEACTIVE;
{
case 5:
save_subset_settings_menu();
- show_menu = true;
+ //FIXME:show_menu = true;
+ Menu::set_current(leveleditor_menu);
break;
}
}
leveleditor_menu->additem(MN_HL,"",0,0);
leveleditor_menu->additem(MN_ACTION,"Quit Level Editor",0,0);
- menu_reset();
Menu::set_current(leveleditor_menu);
- show_menu = true;
-
+
subset_load_menu->additem(MN_LABEL, "Load Level Subset", 0, 0);
subset_load_menu->additem(MN_HL, "", 0, 0);
}
else
{
- if(show_menu == false)
+ if(!Menu::current())
white_small_text->draw("No Level Subset loaded - Press ESC and choose one in the menu", 10, 430, 1);
else
white_small_text->draw("No Level Subset loaded", 10, 430, 1);
while(SDL_PollEvent(&event))
{
- current_menu->event(event);
- if(!show_menu)
- mouse_cursor->set_state(MC_NORMAL);
-
- /* testing SDL_KEYDOWN, SDL_KEYUP and SDL_QUIT events*/
- if(event.type == SDL_KEYDOWN || ((event.type == SDL_MOUSEBUTTONDOWN || SDL_MOUSEMOTION) && (event.motion.x > 0 && event.motion.x < screen->w - 64 &&
- event.motion.y > 0 && event.motion.y < screen->h)))
+ if (Menu::current())
+ {
+ Menu::current()->event(event);
+ }
+ else
{
- switch(event.type)
+ mouse_cursor->set_state(MC_NORMAL);
+
+ /* testing SDL_KEYDOWN, SDL_KEYUP and SDL_QUIT events*/
+ if(event.type == SDL_KEYDOWN
+ || ((event.type == SDL_MOUSEBUTTONDOWN || SDL_MOUSEMOTION)
+ && (event.motion.x > 0
+ && event.motion.x < screen->w - 64 &&
+ event.motion.y > 0 && event.motion.y < screen->h)))
{
- case SDL_QUIT: // window closed
-printf("window closed\n");
- done = -1;
- break;
- case SDL_KEYDOWN: // key pressed
- key = event.key.keysym.sym;
- switch(key)
+ switch(event.type)
{
- case SDLK_LEFT:
- if(fire == DOWN)
- cursor_x -= KEY_CURSOR_SPEED;
- else
- cursor_x -= KEY_CURSOR_FASTSPEED;
+ case SDL_KEYDOWN: // key pressed
+ key = event.key.keysym.sym;
+ switch(key)
+ {
+ case SDLK_LEFT:
+ if(fire == DOWN)
+ cursor_x -= KEY_CURSOR_SPEED;
+ else
+ cursor_x -= KEY_CURSOR_FASTSPEED;
- if(cursor_x < pos_x + MOUSE_LEFT_MARGIN)
- pos_x = cursor_x - MOUSE_LEFT_MARGIN;
+ if(cursor_x < pos_x + MOUSE_LEFT_MARGIN)
+ pos_x = cursor_x - MOUSE_LEFT_MARGIN;
- break;
- case SDLK_RIGHT:
- if(fire == DOWN)
- cursor_x += KEY_CURSOR_SPEED;
- else
- cursor_x += KEY_CURSOR_FASTSPEED;
+ break;
+ case SDLK_RIGHT:
+ if(fire == DOWN)
+ cursor_x += KEY_CURSOR_SPEED;
+ else
+ cursor_x += KEY_CURSOR_FASTSPEED;
- if(cursor_x > pos_x + MOUSE_RIGHT_MARGIN-32)
- pos_x = cursor_x - MOUSE_RIGHT_MARGIN+32;
+ if(cursor_x > pos_x + MOUSE_RIGHT_MARGIN-32)
+ pos_x = cursor_x - MOUSE_RIGHT_MARGIN+32;
+ break;
+ case SDLK_UP:
+ if(fire == DOWN)
+ cursor_y -= KEY_CURSOR_SPEED;
+ else
+ cursor_y -= KEY_CURSOR_FASTSPEED;
+
+ if(cursor_y < 0)
+ cursor_y = 0;
+ break;
+ case SDLK_DOWN:
+ if(fire == DOWN)
+ cursor_y += KEY_CURSOR_SPEED;
+ else
+ cursor_y += KEY_CURSOR_FASTSPEED;
+
+ if(cursor_y > screen->h-32)
+ cursor_y = screen->h-32;
+ break;
+ case SDLK_LCTRL:
+ fire =UP;
+ break;
+ case SDLK_F1:
+ le_showhelp();
+ break;
+ case SDLK_HOME:
+ cursor_x = 0;
+ pos_x = cursor_x;
+ break;
+ case SDLK_END:
+ cursor_x = (le_current_level->width * 32) - 32;
+ pos_x = cursor_x;
+ break;
+ case SDLK_F9:
+ le_show_grid = !le_show_grid;
+ break;
+ default:
+ break;
+ }
break;
- case SDLK_UP:
- if(fire == DOWN)
- cursor_y -= KEY_CURSOR_SPEED;
- else
- cursor_y -= KEY_CURSOR_FASTSPEED;
-
- if(cursor_y < 0)
- cursor_y = 0;
- break;
- case SDLK_DOWN:
- if(fire == DOWN)
- cursor_y += KEY_CURSOR_SPEED;
- else
- cursor_y += KEY_CURSOR_FASTSPEED;
-
- if(cursor_y > screen->h-32)
- cursor_y = screen->h-32;
- break;
- case SDLK_LCTRL:
- fire =UP;
- break;
- case SDLK_F1:
- le_showhelp();
- break;
- case SDLK_HOME:
- cursor_x = 0;
- pos_x = cursor_x;
- break;
- case SDLK_END:
- cursor_x = (le_current_level->width * 32) - 32;
- pos_x = cursor_x;
- break;
- case SDLK_F9:
- le_show_grid = !le_show_grid;
- break;
- default:
+ case SDL_KEYUP: /* key released */
+ switch(event.key.keysym.sym)
+ {
+ case SDLK_LCTRL:
+ fire = DOWN;
+ break;
+ default:
+ break;
+ }
break;
- }
- break;
- case SDL_KEYUP: /* key released */
- switch(event.key.keysym.sym)
- {
- case SDLK_LCTRL:
- fire = DOWN;
+ case SDL_MOUSEBUTTONDOWN:
+ if(event.button.button == SDL_BUTTON_LEFT)
+ {
+ le_mouse_pressed[LEFT] = true;
+
+ selection.x1 = event.motion.x + pos_x;
+ selection.y1 = event.motion.y;
+ selection.x2 = event.motion.x + pos_x;
+ selection.y2 = event.motion.y;
+ }
+ else if(event.button.button == SDL_BUTTON_RIGHT)
+ {
+ le_mouse_pressed[RIGHT] = true;
+ }
break;
- default:
+ case SDL_MOUSEBUTTONUP:
+ if(event.button.button == SDL_BUTTON_LEFT)
+ le_mouse_pressed[LEFT] = false;
+ else if(event.button.button == SDL_BUTTON_RIGHT)
+ le_mouse_pressed[RIGHT] = false;
break;
- }
- break;
- case SDL_MOUSEBUTTONDOWN:
- if(event.button.button == SDL_BUTTON_LEFT)
- {
- le_mouse_pressed[LEFT] = true;
+ case SDL_MOUSEMOTION:
- selection.x1 = event.motion.x + pos_x;
- selection.y1 = event.motion.y;
- selection.x2 = event.motion.x + pos_x;
- selection.y2 = event.motion.y;
- }
- else if(event.button.button == SDL_BUTTON_RIGHT)
- {
- le_mouse_pressed[RIGHT] = true;
- }
- break;
- case SDL_MOUSEBUTTONUP:
- if(event.button.button == SDL_BUTTON_LEFT)
- le_mouse_pressed[LEFT] = false;
- else if(event.button.button == SDL_BUTTON_RIGHT)
- le_mouse_pressed[RIGHT] = false;
- break;
- case SDL_MOUSEMOTION:
- if(!show_menu)
- {
- x = event.motion.x;
- y = event.motion.y;
+ if(!Menu::current())
+ {
+ x = event.motion.x;
+ y = event.motion.y;
- cursor_x = ((int)(pos_x + x) / 32) * 32;
- cursor_y = ((int) y / 32) * 32;
+ cursor_x = ((int)(pos_x + x) / 32) * 32;
+ cursor_y = ((int) y / 32) * 32;
- if(le_mouse_pressed[LEFT])
- {
- selection.x2 = x + pos_x;
- selection.y2 = y;
- }
+ if(le_mouse_pressed[LEFT])
+ {
+ selection.x2 = x + pos_x;
+ selection.y2 = y;
+ }
- if(le_mouse_pressed[RIGHT])
- {
- pos_x += -1 * event.motion.xrel;
+ if(le_mouse_pressed[RIGHT])
+ {
+ pos_x += -1 * event.motion.xrel;
+ }
}
+ break;
+ case SDL_QUIT: // window closed
+ done = 1;
+ break;
+ default:
+ break;
}
- break;
- default:
- break;
}
}
if(le_current_level != NULL)
{
if(event.type == SDL_KEYDOWN || event.type == SDL_KEYUP || ((event.type == SDL_MOUSEBUTTONDOWN || SDL_MOUSEMOTION) && (event.motion.x > screen->w-64 && event.motion.x < screen->w &&
- event.motion.y > 0 && event.motion.y < screen->h)))
+ event.motion.y > 0 && event.motion.y < screen->h)))
{
le_mouse_pressed[LEFT] = false;
le_mouse_pressed[RIGHT] = false;
- if(show_menu == false)
+ if(!Menu::current())
{
/* Check for button events */
le_test_level_bt->event(event);
le_current_level->save(le_level_subset.name.c_str(),le_level);
le_exit_bt->event(event);
if(le_exit_bt->get_state() == BUTTON_CLICKED)
- {
- Menu::set_current(leveleditor_menu);
- show_menu = true;
- }
+ {
+ Menu::set_current(leveleditor_menu);
+ }
le_next_level_bt->event(event);
if(le_next_level_bt->get_state() == BUTTON_CLICKED)
{
Menu::set_current(select_tilegroup_menu);
select_tilegroup_menu_effect.start(200);
select_tilegroup_menu->set_pos(screen->w - 64,100,-0.5,0.5);
- show_menu = true;
}
le_settings_bt->event(event);
{
update_level_settings_menu();
Menu::set_current(level_settings_menu);
- show_menu = true;
}
if(!cur_tilegroup.empty())
- if((pbutton = tilegroups_map[cur_tilegroup]->event(event)) != NULL)
- {
- if(pbutton->get_state() == BUTTON_CLICKED)
- {
- le_current_tile = pbutton->get_tag();
- }
- }
+ if((pbutton = tilegroups_map[cur_tilegroup]->event(event)) != NULL)
+ {
+ if(pbutton->get_state() == BUTTON_CLICKED)
+ {
+ le_current_tile = pbutton->get_tag();
+ }
+ }
if((pbutton = le_tilemap_panel->event(event)) != NULL)
- {
- if(pbutton->get_state() == BUTTON_CLICKED)
- {
- active_tm = static_cast<TileMapType>(pbutton->get_tag());
- }
- }
+ {
+ if(pbutton->get_state() == BUTTON_CLICKED)
+ {
+ active_tm = static_cast<TileMapType>(pbutton->get_tag());
+ }
+ }
}
else
{
le_settings_bt->event(event);
if(le_settings_bt->get_state() == BUTTON_CLICKED)
{
- Menu::set_current(leveleditor_menu);
- show_menu = false;
+ Menu::set_current(0);
}
le_tilegroup_bt->event(event);
if(le_tilegroup_bt->get_state() == BUTTON_CLICKED)
{
- Menu::set_current(leveleditor_menu);
- show_menu = false;
+ Menu::set_current(0);
}
}
}
- if(show_menu == false)
+
+ if(!Menu::current())
{
le_move_left_bt->event(event);
le_move_right_bt->event(event);
}
}
}
- if(show_menu == false)
+ if(!Menu::current())
{
if(le_move_left_bt->get_state() == BUTTON_PRESSED)
{
#include "timer.h"
#include "high_scores.h"
-/* (global) menu variables */
-MenuAction menuaction = MENU_ACTION_NONE;
-bool show_menu;
-bool menu_change;
-
Surface* checkbox;
Surface* checkbox_checked;
Surface* back;
Menu* contrib_menu = 0;
Menu* contrib_subset_menu = 0;
-Menu* current_menu = 0;
-
-/* input implementation variables */
-int delete_character;
-char mn_input_char;
+Menu* Menu::current_ = 0;
-/* Set the current menu */
void
-Menu::set_current(Menu* pmenu)
+Menu::set_current(Menu* menu)
{
- if(pmenu != current_menu)
+ if (menu)
{
- menu_change = true;
- Menu* tmp = current_menu;
- current_menu = pmenu;
- if(tmp)
- if(tmp->last_menu != pmenu)
- current_menu->last_menu = tmp;
-
- pmenu->effect.start(500);
+ menu->last_menu = current_;
+ menu->effect.start(500);
}
+
+ current_ = menu;
}
/* Return a pointer to a new menu item */
}
}
+
Menu::Menu()
{
+ menuaction = MENU_ACTION_NONE;
+ delete_character = 0;
+ mn_input_char = '\0';
+
pos_x = screen->w/2;
pos_y = screen->h/2;
has_backitem = false;
case MN_TOGGLE:
item[active_item].toggled = !item[active_item].toggled;
- menu_change = true;
break;
case MN_ACTION:
|| new_item.kind == MN_HL)
{
// Skip the horzontal line item
- if(menuaction != MENU_ACTION_UP && menuaction != MENU_ACTION_DOWN)
+ if (menuaction != MENU_ACTION_UP && menuaction != MENU_ACTION_DOWN)
menuaction = MENU_ACTION_DOWN;
- if(item.size() > 1)
+ if (item.size() > 1)
action();
}
+
+ menuaction = MENU_ACTION_NONE;
}
int
&& item[active_item].toggled)
{
item[active_item].toggled = false;
- show_menu = 0;
+ Menu::set_current(0);
return active_item;
}
else if(item[active_item].kind == MN_TOGGLE || item[active_item].kind == MN_GOTO)
}
}
-/* Reset/Set global defaults */
-void menu_reset(void)
-{
- menu_change = false;
- show_menu = false;
- menuaction = MENU_ACTION_NONE;
- current_menu = NULL;
-
- delete_character = 0;
- mn_input_char = '\0';
-}
-
/* --- MENU --- */
/* Draw the current menu and execute the (menu)events */
-void menu_process_current(void)
+void menu_process_current()
{
- if(!show_menu)
- return;
-
- menu_change = false;
-
- if(current_menu != NULL)
+ if(Menu::current())
{
- current_menu->action();
- current_menu->draw();
+ Menu::current()->action();
+ Menu::current()->draw();
}
-
- menuaction = MENU_ACTION_NONE;
}
/* Check for menu event */
void
Menu::event(SDL_Event& event)
{
- if(show_menu == false && event.key.keysym.sym != SDLK_ESCAPE)
- return;
-
SDLKey key;
switch(event.type)
{
{
case SDLK_UP: /* Menu Up */
menuaction = MENU_ACTION_UP;
- menu_change = true;
break;
case SDLK_DOWN: /* Menu Down */
menuaction = MENU_ACTION_DOWN;
- menu_change = true;
break;
case SDLK_LEFT: /* Menu Up */
menuaction = MENU_ACTION_LEFT;
- menu_change = true;
break;
case SDLK_RIGHT: /* Menu Down */
menuaction = MENU_ACTION_RIGHT;
- menu_change = true;
break;
case SDLK_SPACE:
if(item[active_item].kind == MN_TEXTFIELD)
{
menuaction = MENU_ACTION_INPUT;
- menu_change = true;
mn_input_char = ' ';
break;
}
case SDLK_RETURN: /* Menu Hit */
menuaction = MENU_ACTION_HIT;
- menu_change = true;
break;
case SDLK_DELETE:
case SDLK_BACKSPACE:
menuaction = MENU_ACTION_REMOVE;
- menu_change = true;
delete_character++;
break;
case SDLK_ESCAPE:
- if(show_menu && has_backitem == true && last_menu != NULL)
- Menu::set_current(last_menu);
- else if(show_menu)
- show_menu = false;
- else
- show_menu = true;
+ if(Menu::current())
+ {
+ if (has_backitem == true && last_menu != NULL)
+ Menu::set_current(last_menu);
+ else
+ Menu::set_current(0);
+ }
default:
if( (key >= SDLK_0 && key <= SDLK_9) || (key >= SDLK_a && key <= SDLK_z) || (key >= SDLK_SPACE && key <= SDLK_SLASH))
{
menuaction = MENU_ACTION_INPUT;
- menu_change = true;
mn_input_char = *ch;
}
else
x = event.motion.x;
y = event.motion.y;
if(x > pos_x - width()/2 &&
- x < pos_x + width()/2 &&
- y > pos_y - height()/2 &&
- y < pos_y + height()/2)
+ x < pos_x + width()/2 &&
+ y > pos_y - height()/2 &&
+ y < pos_y + height()/2)
{
menuaction = MENU_ACTION_HIT;
}
x = event.motion.x;
y = event.motion.y;
if(x > pos_x - width()/2 &&
- x < pos_x + width()/2 &&
- y > pos_y - height()/2 &&
- y < pos_y + height()/2)
+ x < pos_x + width()/2 &&
+ y > pos_y - height()/2 &&
+ y < pos_y + height()/2)
{
active_item = (y - (pos_y - height()/2)) / 24;
- menu_change = true;
- mouse_cursor->set_state(MC_LINK);
+ mouse_cursor->set_state(MC_LINK);
}
- else
+ else
{
mouse_cursor->set_state(MC_NORMAL);
}
class Menu
{
private:
+ /* Action done on the menu */
+ enum MenuAction {
+ MENU_ACTION_NONE = -1,
+ MENU_ACTION_UP,
+ MENU_ACTION_DOWN,
+ MENU_ACTION_LEFT,
+ MENU_ACTION_RIGHT,
+ MENU_ACTION_HIT,
+ MENU_ACTION_INPUT,
+ MENU_ACTION_REMOVE
+ };
+
// position of the menu (ie. center of the menu, not top/left)
int pos_x;
int pos_y;
bool has_backitem;
+
+ /** input event for the menu */
+ 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_; }
Menu();
~Menu();
void draw_item(int index, int menu_width, int menu_height);
void set_pos(int x, int y, float rw = 0, float rh = 0);
- /* Check for a menu event */
+ /** translate a SDL_Event into a menu_action */
void event(SDL_Event& event);
};
-
-/* Action done on the menu */
-enum MenuAction {
- MENU_ACTION_NONE = -1,
- MENU_ACTION_UP,
- MENU_ACTION_DOWN,
- MENU_ACTION_LEFT,
- MENU_ACTION_RIGHT,
- MENU_ACTION_HIT,
- MENU_ACTION_INPUT,
- MENU_ACTION_REMOVE
-};
-
-/* (global) menu variables */
-extern MenuAction menuaction;
-extern bool show_menu;
-extern bool menu_change;
-
extern Surface* checkbox;
extern Surface* checkbox_checked;
extern Surface* back;
extern Menu* highscore_menu;
extern Menu* load_game_menu;
extern Menu* save_game_menu;
-extern Menu* current_menu;
-
-/* input implementation variables */
-extern int delete_character;
-extern char mn_input_char;
-
-/* Reset the global menu variables */
-void menu_reset(void);
/* "Calculate" and draw the menu */
void menu_process_current(void);
worldmap.display();
- show_menu = true;
Menu::set_current(main_menu);
st_pause_ticks_stop();
std::cout << "Sarting level: " << index << std::endl;
GameSession session(current_contrib_subset, index, ST_GL_PLAY);
session.run();
- menu_reset();
Menu::set_current(main_menu);
- show_menu = 1;
}
}
scroll_x = tux->base.x - 320;
}
-
-
float last_tux_x_pos = tux->base.x;
tux->action(frame_ratio);
GameSession session(datadir + "/levels/misc/menu.stl", 0, ST_GL_DEMO_GAME);
- //FIXME:activate_particle_systems();
-
- /* Reset menu variables */
- menu_reset();
- Menu::set_current(main_menu);
-
clearscreen(0, 0, 0);
updatescreen();
/* --- Main title loop: --- */
bool done = 0;
- show_menu = 1;
frame = 0;
/* Draw the title background: */
update_time = st_get_ticks();
random_timer.start(rand() % 2000 + 2000);
+ Menu::set_current(main_menu);
while (!done)
{
- /* Calculate the movement-factor */
+ // Calculate the movement-factor
double frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE);
if(frame_ratio > 1.5) /* Quick hack to correct the unprecise CPU clocks a little bit. */
frame_ratio = 1.5 + (frame_ratio - 1.5) * 0.85;
while (SDL_PollEvent(&event))
{
- current_menu->event(event);
if (event.type == SDL_QUIT)
{
done = true;
/* Keypress... */
key = event.key.keysym.sym;
- /* Check for menu events */
- //menu_event(event);
+ if (Menu::current())
+ {
+ Menu::current()->event(event);
+ }
- if (!show_menu)
+ if (!Menu::current())
{
/* Escape: Quit: */
done = true;
draw_background();
draw_demo(&session, frame_ratio);
- if (current_menu == main_menu)
+ if (Menu::current() == main_menu)
logo->draw( 160, 30);
- white_small_text->draw(
- " SuperTux " VERSION "\n"
- "Copyright (c) 2003 SuperTux Devel Team\n"
- "This game comes with ABSOLUTELY NO WARRANTY. This is free software, and you\n"
- "are welcome to redistribute it under certain conditions; see the file COPYING\n"
- "for details.\n",
- 0, 420, 0);
-
- /* 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);
- */
+ white_small_text->draw(" SuperTux " VERSION "\n"
+ "Copyright (c) 2003 SuperTux Devel Team\n"
+ "This game comes with ABSOLUTELY NO WARRANTY. This is free software, and you\n"
+ "are welcome to redistribute it under certain conditions; see the file COPYING\n"
+ "for details.\n",
+ 0, 420, 0);
/* Don't draw menu, if quit is true */
- if(show_menu && !done)
+ if(!done)
menu_process_current();
- if(current_menu == main_menu)
+ if(Menu::current() == main_menu)
{
switch (main_menu->check())
{
-#if 0
- case 0:
- string_list_type level_subsets;
- level_subsets = dsubdirs("/levels", "info");
-
- // Quick Play
- // FIXME: obsolete
- done = 0;
- i = 0;
- if(level_subsets.num_items != 0)
- {
- subset.load(level_subsets.item[0]);
- while(!done)
- {
- img_choose_subset->draw((screen->w - img_choose_subset.w) / 2, 0);
- if(level_subsets.num_items != 0)
- {
- subset.image->draw((screen->w - subset.image.w) / 2 + 25,78);
- if(level_subsets.num_items > 1)
- {
- if(i > 0)
- arrow_left->draw((screen->w / 2) - ((subset.title.length()+2)*16)/2,20);
- if(i < level_subsets.num_items-1)
- arrow_right->draw((screen->w / 2) + ((subset.description.length())*16)/2,20);
- }
- text_drawf(&gold_text, subset.title.c_str(), 0, 20, A_HMIDDLE, A_TOP, 1);
- text_drawf(&gold_text, subset.description.c_str(), 20, -20, A_HMIDDLE, A_BOTTOM, 1);
- }
- updatescreen();
- SDL_Delay(50);
- while(SDL_PollEvent(&event) && !done)
- {
- switch(event.type)
- {
- case SDL_QUIT:
- done = true;
- break;
- case SDL_KEYDOWN: // key pressed
- // Keypress...
- key = event.key.keysym.sym;
-
- if(key == SDLK_LEFT)
- {
- if(i > 0)
- {
- --i;
- subset.free();
- subset.load(level_subsets.item[i]);
- }
- }
- else if(key == SDLK_RIGHT)
- {
- if(i < level_subsets.num_items -1)
- {
- ++i;
- subset.free();
- subset.load(level_subsets.item[i]);
- }
- }
- else if(key == SDLK_SPACE || key == SDLK_RETURN)
- {
- done = true;
- quit = gameloop(subset.name.c_str(),1,ST_GL_PLAY);
- subset.free();
- }
- else if(key == SDLK_ESCAPE)
- {
- done = true;
- }
- break;
- default:
- break;
- }
- }
- }
- }
- // reset tux
- scroll_x = 0;
- titletux.level_begin();
- update_time = st_get_ticks();
- break;
-#endif
case 0:
// Start Game, ie. goto the slots menu
update_load_save_game_menu(load_game_menu);
case 3:
done = true;
done = leveleditor(1);
- menu_reset();
- show_menu = 1;
Menu::set_current(main_menu);
break;
case 4:
break;
}
}
- else if(current_menu == options_menu)
+ else if(Menu::current() == options_menu)
{
process_options_menu();
}
- else if(current_menu == load_game_menu)
+ else if(Menu::current() == load_game_menu)
{
if (process_load_game_menu())
{
update_time = st_get_ticks();
}
}
- else if(current_menu == contrib_menu)
+ else if(Menu::current() == contrib_menu)
{
check_contrib_menu();
}
- else if (current_menu == contrib_subset_menu)
+ else if (Menu::current() == contrib_subset_menu)
{
check_contrib_subset_menu();
}
string_list_free(&names);
SDL_EnableKeyRepeat(0, 0); // disables key repeating
- show_menu = 1;
Menu::set_current(main_menu);
}
}
void
+WorldMap::on_escape_press()
+{
+ std::cout << "on escape press" << std::endl;
+
+ if(!Menu::current())
+ Menu::set_current(worldmap_menu);
+ else
+ Menu::set_current(0);
+}
+
+void
WorldMap::get_input()
{
enter_level = false;
SDL_Event event;
while (SDL_PollEvent(&event))
{
- if(!show_menu && event.key.keysym.sym == SDLK_ESCAPE)
- Menu::set_current(worldmap_menu);
-
- current_menu->event(event);
- if(!show_menu)
+ if (Menu::current())
+ {
+ Menu::current()->event(event);
+ }
+ else
{
switch(event.type)
{
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
+ case SDLK_ESCAPE:
+ on_escape_press();
+ break;
case SDLK_LCTRL:
case SDLK_RETURN:
enter_level = true;
case SDL_JOYBUTTONDOWN:
if (event.jbutton.button == JOY_B)
enter_level = true;
+ else if (event.jbutton.button == JOY_START)
+ on_escape_press();
break;
default:
}
}
- if (!show_menu)
+ if (!Menu::current())
{
Uint8 *keystate = SDL_GetKeyState(NULL);
}
play_music(song, 1);
- show_menu = 0;
- menu_reset();
+ Menu::set_current(0);
if (!savegame_file.empty())
savegame(savegame_file);
return;
tux->update(0.33f);
}
- if(show_menu)
+ if(Menu::current())
{
- if(current_menu == worldmap_menu)
+ if(Menu::current() == worldmap_menu)
{
switch (worldmap_menu->check())
{
case 2: // Return to game
- menu_reset();
break;
case 3:
if (!savegame_file.empty())
void
WorldMap::display()
{
- show_menu = false;
+ Menu::set_current(0);
quit = false;
get_input();
update();
- if(show_menu)
+ if(Menu::current())
{
menu_process_current();
mouse_cursor->draw();
void savegame(const std::string& filename);
void loadgame(const std::string& filename);
+private:
+ void on_escape_press();
};
} // namespace WorldMapNS