This makes the Back button to be used in case there is one (when Esc is pressed).
Because of that, the menu is now much more independent.
Currently, everything seems to be working just fine and smooth.
SVN-Revision: 551
while (SDL_PollEvent(&event))
{
/* Check for menu-events, if the menu is shown */
- if(show_menu)
- current_menu->event(event);
+ current_menu->event(event);
switch(event.type)
{
{
exit_status = LEVEL_ABORT;
}
- else if(show_menu)
+ else if(!show_menu)
{
Menu::set_current(game_menu);
show_menu = 0;
/* definitions to aid development */
#define DONE_LEVELEDITOR 1
#define DONE_QUIT 2
-#define DONE_CHANGELEVEL 3
/* definitions that affect gameplay */
#define KEY_CURSOR_SPEED 32
return 0;
}
- if(done == DONE_QUIT)
- {
- le_quit();
- return 1;
- }
-
++global_frame_counter;
SDL_Delay(25);
while(SDL_PollEvent(&event))
{
- if(show_menu)
- current_menu->event(event);
- else
+ current_menu->event(event);
+ if(!show_menu)
mouse_cursor->set_state(MC_NORMAL);
/* testing SDL_KEYDOWN, SDL_KEYUP and SDL_QUIT events*/
{
case SDL_KEYDOWN: // key pressed
key = event.key.keysym.sym;
- if(show_menu)
- {
- if(key == SDLK_ESCAPE)
- {
- show_menu = false;
- Menu::set_current(leveleditor_menu);
- }
- break;
- }
switch(key)
{
- case SDLK_ESCAPE:
- if(!show_menu)
- show_menu = true;
- else
- show_menu = false;
- break;
case SDLK_LEFT:
if(fire == DOWN)
cursor_x -= KEY_CURSOR_SPEED;
{
pos_x = screen->w/2;
pos_y = screen->h/2;
+ has_backitem = false;
last_menu = 0;
arrange_left = 0;
active_item = 0;
void
Menu::additem(MenuItemKind kind_, const std::string& text_, int toggle_, Menu* menu_)
{
+ if(kind_ == MN_BACK)
+ has_backitem = true;
+
additem(MenuItem::create(kind_, text_.c_str(), toggle_, menu_));
}
void
Menu::additem(MenuItem* pmenu_item)
{
+ if(pmenu_item->kind == MN_BACK)
+ has_backitem = true;
+
item.push_back(*pmenu_item);
delete pmenu_item;
}
/* Draw the current menu and execute the (menu)events */
void menu_process_current(void)
{
+ if(!show_menu)
+ return;
+
menu_change = false;
if(current_menu != NULL)
void
Menu::event(SDL_Event& event)
{
+ if(show_menu == false && event.key.keysym.sym != SDLK_ESCAPE)
+ return;
+
SDLKey key;
switch(event.type)
{
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;
default:
if( (key >= SDLK_0 && key <= SDLK_9) || (key >= SDLK_a && key <= SDLK_z) || (key >= SDLK_SPACE && key <= SDLK_SLASH))
{
// position of the menu (ie. center of the menu, not top/left)
int pos_x;
int pos_y;
+ bool has_backitem;
Menu* last_menu;
int width();
void st_pause_ticks_start(void)
{
- st_pause_count = SDL_GetTicks();
+ if(st_pause_count == 0)
+ st_pause_count = SDL_GetTicks();
}
void st_pause_ticks_stop(void)
/* Check for menu events */
//menu_event(event);
- if (key == SDLK_ESCAPE)
+ if (!show_menu)
{
/* Escape: Quit: */
done = true;
SDL_Event event;
while (SDL_PollEvent(&event))
{
- if(show_menu)
- {
- current_menu->event(event);
- }
- else
+ if(!show_menu && event.key.keysym.sym == SDLK_ESCAPE)
+ Menu::set_current(worldmap_menu);
+
+ current_menu->event(event);
+ if(!show_menu)
{
switch(event.type)
{
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
- case SDLK_ESCAPE:
- Menu::set_current(worldmap_menu);
- show_menu = !show_menu;
- break;
case SDLK_LCTRL:
case SDLK_RETURN:
enter_level = true;
void
WorldMap::display()
{
- show_menu = 0;
- menu_reset();
+ show_menu = false;
quit = false;
get_input();
update();
- menu_process_current();
+ if(show_menu)
+ {
+ menu_process_current();
+ mouse_cursor->draw();
+ }
flipscreen();
SDL_Delay(20);