From b56d18cd12b1892a7588b1fe620b1df26f7e7d4f Mon Sep 17 00:00:00 2001 From: Ricardo Cruz Date: Sun, 18 Apr 2004 12:03:07 +0000 Subject: [PATCH] Finally!! 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 --- src/gameloop.cpp | 5 ++--- src/leveleditor.cpp | 27 ++------------------------- src/menu.cpp | 20 ++++++++++++++++++++ src/menu.h | 1 + src/timer.cpp | 3 ++- src/title.cpp | 2 +- src/worldmap.cpp | 23 +++++++++++------------ 7 files changed, 39 insertions(+), 42 deletions(-) diff --git a/src/gameloop.cpp b/src/gameloop.cpp index f8b96eb11..d0368f016 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -134,8 +134,7 @@ GameSession::process_events() 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) { @@ -159,7 +158,7 @@ GameSession::process_events() { exit_status = LEVEL_ABORT; } - else if(show_menu) + else if(!show_menu) { Menu::set_current(game_menu); show_menu = 0; diff --git a/src/leveleditor.cpp b/src/leveleditor.cpp index 836158e04..3173e9a20 100644 --- a/src/leveleditor.cpp +++ b/src/leveleditor.cpp @@ -40,7 +40,6 @@ /* 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 @@ -340,12 +339,6 @@ int leveleditor(int levelnb) return 0; } - if(done == DONE_QUIT) - { - le_quit(); - return 1; - } - ++global_frame_counter; SDL_Delay(25); @@ -791,9 +784,8 @@ void le_checkevents() 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*/ @@ -804,23 +796,8 @@ void le_checkevents() { 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; diff --git a/src/menu.cpp b/src/menu.cpp index 276f49fcf..896591bc1 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -144,6 +144,7 @@ Menu::Menu() { pos_x = screen->w/2; pos_y = screen->h/2; + has_backitem = false; last_menu = 0; arrange_left = 0; active_item = 0; @@ -160,6 +161,9 @@ void Menu::set_pos(int x, int y, float rw, float rh) 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_)); } @@ -167,6 +171,9 @@ Menu::additem(MenuItemKind kind_, const std::string& text_, int toggle_, Menu* m void Menu::additem(MenuItem* pmenu_item) { + if(pmenu_item->kind == MN_BACK) + has_backitem = true; + item.push_back(*pmenu_item); delete pmenu_item; } @@ -540,6 +547,9 @@ void menu_reset(void) /* 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) @@ -555,6 +565,9 @@ void menu_process_current(void) void Menu::event(SDL_Event& event) { + if(show_menu == false && event.key.keysym.sym != SDLK_ESCAPE) + return; + SDLKey key; switch(event.type) { @@ -613,6 +626,13 @@ Menu::event(SDL_Event& event) 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)) { diff --git a/src/menu.h b/src/menu.h index e8baf7018..969b30d47 100644 --- a/src/menu.h +++ b/src/menu.h @@ -59,6 +59,7 @@ private: // 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(); diff --git a/src/timer.cpp b/src/timer.cpp index 4c3290db0..0fd6c188b 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -32,7 +32,8 @@ void st_pause_ticks_init(void) 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) diff --git a/src/title.cpp b/src/title.cpp index d1e93d7ed..b729bef01 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -285,7 +285,7 @@ bool title(void) /* Check for menu events */ //menu_event(event); - if (key == SDLK_ESCAPE) + if (!show_menu) { /* Escape: Quit: */ done = true; diff --git a/src/worldmap.cpp b/src/worldmap.cpp index f96b1048c..85eb56ec8 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -370,11 +370,11 @@ WorldMap::get_input() 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) { @@ -385,10 +385,6 @@ WorldMap::get_input() 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; @@ -643,8 +639,7 @@ WorldMap::draw_status() void WorldMap::display() { - show_menu = 0; - menu_reset(); + show_menu = false; quit = false; @@ -669,7 +664,11 @@ WorldMap::display() get_input(); update(); - menu_process_current(); + if(show_menu) + { + menu_process_current(); + mouse_cursor->draw(); + } flipscreen(); SDL_Delay(20); -- 2.11.0