Menu* Menu::current_ = 0;
void
-Menu::set_current(Menu* menu)
+Menu::push_current(Menu* pmenu)
{
- if (menu)
- {
- if (last_menus.empty() || menu != last_menus.top())
- last_menus.push(current_);
+ if (current_)
+ last_menus.push(current_);
+
+ set_current(pmenu);
+}
- menu->effect.start(500);
+void
+Menu::pop_current()
+{
+ if (!last_menus.empty())
+ {
+ set_current(last_menus.top());
+ last_menus.pop();
+ }
+ else
+ {
+ set_current(0);
}
+}
+
+void
+Menu::set_current(Menu* menu)
+{
+ if (menu)
+ menu->effect.start(500);
current_ = menu;
}
{
case MN_GOTO:
if (item[active_item].target_menu != NULL)
- Menu::set_current(item[active_item].target_menu);
+ Menu::push_current(item[active_item].target_menu);
else
puts("NULLL");
break;
break;
case MN_BACK:
- if (!last_menus.empty())
- {
- Menu::set_current(last_menus.top());
- last_menus.pop();
- }
+ Menu::pop_current();
break;
default:
break;
delete_character++;
break;
case SDLK_ESCAPE:
- if(Menu::current())
- {
- if (has_backitem == true && !last_menus.empty())
- {
- Menu::set_current(last_menus.top());
- last_menus.pop();
- }
- else
- Menu::set_current(0);
- }
+ Menu::pop_current();
+ break;
default:
if( (key >= SDLK_0 && key <= SDLK_9) || (key >= SDLK_a && key <= SDLK_z) || (key >= SDLK_SPACE && key <= SDLK_SLASH))
{
private:
static std::stack<Menu*> last_menus;
static Menu* current_;
+
+ static void push_current(Menu* pmenu);
+ static void pop_current();
public:
/** Set the current menu, if pmenu is NULL, hide the current menu */
static void set_current(Menu* pmenu);