diff options
author | Stijn Buys <ingar@osirion.org> | 2009-08-13 16:41:39 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2009-08-13 16:41:39 +0000 |
commit | 9f8804390d9ad183a05dc5f4d8f99627e71a791e (patch) | |
tree | 41940079081663b86018ebf56d7f91b6f39fd567 /src/client/entitymenu.cc | |
parent | a320e55dc1a17cef3923643277f1112f74251d70 (diff) |
improved menu ESC handling
Diffstat (limited to 'src/client/entitymenu.cc')
-rw-r--r-- | src/client/entitymenu.cc | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/client/entitymenu.cc b/src/client/entitymenu.cc index f1529e1..59c922c 100644 --- a/src/client/entitymenu.cc +++ b/src/client/entitymenu.cc @@ -22,6 +22,7 @@ EntityMenu::EntityMenu(ui::Widget *parent, const char * label) : ui::Window(pare set_label("entitymenu"); menu_container = new ui::Container(this); + menu_generated_entity = 0; hide(); } @@ -44,7 +45,18 @@ void EntityMenu::generate(core::Entity *entity, const char *menulabel) { using namespace ui; - if (!menulabel) + menu_generated_menu.clear(); + menu_generated_entity = entity; + + if (!entity) + return; + + if (!menulabel) { + return; + } + + menu_generated_menu.assign(menulabel); + if (!menu_generated_menu.size()) return; //con_debug << "generating menu " << entity->label() << " " << menulabel << std::endl; @@ -160,4 +172,26 @@ void EntityMenu::generate(core::Entity *entity, const char *menulabel) resize(); } +bool EntityMenu::on_keypress(const int key, const unsigned int modifier) +{ + switch( key ) { + + case SDLK_ESCAPE: + if (visible()) { + if (menu_generated_menu.compare("main") != 0) { + generate(menu_generated_entity, "main"); + } else { + this->hide(); + ui::root()->show_menu("game"); + } + return true; + } + break; + default: + break; + } + + return Window::on_keypress(key, modifier); +} + } |