Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/buymenu.cc15
-rw-r--r--src/client/buymenu.h2
-rw-r--r--src/client/entitymenu.cc36
-rw-r--r--src/client/entitymenu.h15
-rw-r--r--src/client/playerview.cc17
-rw-r--r--src/client/playerview.h3
-rw-r--r--src/ui/menu.cc18
-rw-r--r--src/ui/menu.h3
8 files changed, 95 insertions, 14 deletions
diff --git a/src/client/buymenu.cc b/src/client/buymenu.cc
index 4a4107b..79b5444 100644
--- a/src/client/buymenu.cc
+++ b/src/client/buymenu.cc
@@ -140,5 +140,20 @@ void BuyMenu::draw()
set_item(menu_itemtype, menu_itemname);
}
+bool BuyMenu::on_keypress(const int key, const unsigned int modifier)
+{
+ switch( key ) {
+
+ case SDLK_ESCAPE:
+ this->hide();
+ return true;
+ break;
+ default:
+ break;
+ }
+
+ return Window::on_keypress(key, modifier);
+}
+
}
diff --git a/src/client/buymenu.h b/src/client/buymenu.h
index 44517cf..6a1a651 100644
--- a/src/client/buymenu.h
+++ b/src/client/buymenu.h
@@ -35,6 +35,8 @@ protected:
/// draw event
virtual void draw();
+ /// keypress event handler
+ virtual bool on_keypress(const int key, const unsigned int modifier);
private:
ui::Window *menu_modelpane;
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);
+}
+
}
diff --git a/src/client/entitymenu.h b/src/client/entitymenu.h
index adc31a9..db69867 100644
--- a/src/client/entitymenu.h
+++ b/src/client/entitymenu.h
@@ -22,6 +22,16 @@ public:
/// create a new menu
EntityMenu(ui::Widget *parent, const char * label = 0);
~EntityMenu();
+
+ /* ---- inspectors ----------------------------------------- */
+
+ /// entity the current menu was generated for
+ inline core::Entity *generated_entity() { return menu_generated_entity; }
+
+ /// the current generated menu
+ inline const std::string & generated_menu() const { return menu_generated_menu; }
+
+ /* ---- mutators ------------------------------------------- */
/// generate a menu from menu descriptions
void generate(core::Entity *entity, const char *menulabel);
@@ -33,8 +43,13 @@ protected:
/// resize event
virtual void resize();
+ /// keypress event handler
+ virtual bool on_keypress(const int key, const unsigned int modifier);
+
private:
ui::Container *menu_container;
+ core::Entity *menu_generated_entity;
+ std::string menu_generated_menu;
};
}
diff --git a/src/client/playerview.cc b/src/client/playerview.cc
index e75cd47..889e4d4 100644
--- a/src/client/playerview.cc
+++ b/src/client/playerview.cc
@@ -19,8 +19,6 @@ PlayerView::PlayerView(ui::Widget *parent) : ui::Widget(parent)
set_border(false);
set_background(false);
- view_lastentity = 0;
-
view_notify = new Notifications(this);
view_hud = new HUD(this);
@@ -52,8 +50,6 @@ void PlayerView::clear()
view_chat->hide();
view_map->hide();
view_entitymenu->hide();
-
- view_lastentity = 0;
}
void PlayerView::event_text(const std::string & text)
@@ -198,19 +194,18 @@ void PlayerView::draw()
label_viewname->show();
- if (view_lastentity != core::localplayer()->view()) {
+ if (view_entitymenu->generated_entity() != core::localplayer()->view()) {
// initially show the menu
show_menu("main");
map()->hide();
chat()->hide();
audio::play("ui/menu");
- view_lastentity = core::localplayer()->view();
} else if (!view_entitymenu->visible() && !view_buymenu->visible() &&
!map()->visible() && (!chat()->visible() || chat()->small_view()) ) {
// show the menu if there's no other window open
- menu()->show();
+ view_entitymenu->show();
audio::play("ui/menu");
}
@@ -219,8 +214,6 @@ void PlayerView::draw()
} else {
// entity without menus, plain view
- view_lastentity = 0;
-
this->hide();
return;
}
@@ -231,6 +224,11 @@ void PlayerView::draw()
if (view_entitymenu->visible()) {
view_entitymenu->hide();
}
+
+ if (view_entitymenu->generated_entity()) {
+ view_entitymenu->generate(0,0);
+ }
+
if (view_buymenu->visible()) {
view_buymenu->hide();
}
@@ -247,7 +245,6 @@ void PlayerView::draw()
}
view_hud->show();
- view_lastentity = 0;
}
// reposition chat widget
diff --git a/src/client/playerview.h b/src/client/playerview.h
index 855e671..d72b78b 100644
--- a/src/client/playerview.h
+++ b/src/client/playerview.h
@@ -62,9 +62,6 @@ private:
BuyMenu *view_buymenu;
TradeMenu *view_trademenu;
- core::Entity *view_lastentity;
-
- //ui::Label *label_zonename;
ui::Label *label_viewname;
};
diff --git a/src/ui/menu.cc b/src/ui/menu.cc
index f1364ac..716f5b4 100644
--- a/src/ui/menu.cc
+++ b/src/ui/menu.cc
@@ -61,4 +61,22 @@ void Menu::resize()
menu_container->set_location(ui::UI::elementsize.height(), (height() - menu_container->height()) / 2.0f);
}
+bool Menu::on_keypress(const int key, const unsigned int modifier)
+{
+ switch( key ) {
+
+ case SDLK_ESCAPE:
+ if (visible()) {
+ this->hide();
+ return true;
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ return Window::on_keypress(key, modifier);
+}
+
}
diff --git a/src/ui/menu.h b/src/ui/menu.h
index bbcea5a..c907d76 100644
--- a/src/ui/menu.h
+++ b/src/ui/menu.h
@@ -40,6 +40,9 @@ public:
protected:
/// resize event
virtual void resize();
+
+ /// keypress event
+ virtual bool on_keypress(const int key, const unsigned int modifier);
private:
Bitmap *menu_background;