-std::vector<Menu*> Menu::last_menus;
-std::list<Menu*> Menu::all_menus;
-Menu* Menu::current_ = 0;
-Menu* Menu::previous = 0;
-
-/* just displays a Yes/No text that can be used to confirm stuff */
-bool confirm_dialog(Surface *background, std::string text)
-{
- //Surface* cap_screen = Surface::CaptureScreen();
- Menu* dialog = new Menu;
- dialog->add_inactive(-1, text);
- dialog->add_hl();
- dialog->add_entry(true, _("Yes"));
- dialog->add_entry(false, _("No"));
- dialog->add_hl();
-
- Menu::set_current(dialog);
-
- DrawingContext context;
-
- // TODO make this a screen and not another mainloop...
- while(true)
- {
- SDL_Event event;
- while (SDL_PollEvent(&event)) {
- if(event.type == SDL_QUIT)
- g_main_loop->quit();
- g_main_controller->process_event(event);
- dialog->event(event);
- }
-
- if(background == NULL)
- context.draw_gradient(Color(0.8f, 0.95f, 0.85f), Color(0.8f, 0.8f, 0.8f),
- LAYER_BACKGROUND0);
- else
- context.draw_surface(background, Vector(0,0), LAYER_BACKGROUND0);
-
- dialog->draw(context);
- dialog->update();
-
- switch (dialog->check())
- {
- case true:
- //delete cap_screen;
- Menu::set_current(0);
- delete dialog;
- return true;
- break;
- case false:
- //delete cap_screen;
- Menu::set_current(0);
- delete dialog;
- return false;
- break;
- default:
- break;
- }
-
- mouse_cursor->draw(context);
- context.do_drawing();
- SDL_Delay(25);
- }
-
- return false;
-}
-
-void
-Menu::push_current(Menu* pmenu)
-{
- previous = current_;
-
- if (current_)
- last_menus.push_back(current_);
-
- current_ = pmenu;
- current_->effect_start_time = real_time;
- current_->effect_progress = 0.0f;
-}
-
-void
-Menu::pop_current()
-{
- previous = current_;
-
- if (last_menus.size() >= 1) {
- current_ = last_menus.back();
- current_->effect_start_time = real_time;
- current_->effect_progress = 0.0f;
- last_menus.pop_back();
- } else {
- set_current(NULL);
- }
-}
-
-void
-Menu::set_current(Menu* menu)
-{
- if (current_ && current_->close == true)
- return;
-
- previous = current_;
-
- if (menu) {
- menu->effect_start_time = real_time;
- menu->effect_progress = 0.0f;
- current_ = menu;
- }
- else if (current_) {
- last_menus.clear(); //NULL new menu pointer => close all menus
- current_->effect_start_time = real_time;
- current_->effect_progress = 0.0f;
- current_->close = true;
- }
-
- // just to be sure...
- g_main_controller->reset();
-}
-
-void
-Menu::recalc_pos()
-{
- if (current_)
- current_->set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
-
- for(std::list<Menu*>::iterator i = all_menus.begin(); i != all_menus.end(); ++i)
- {
- // FIXME: This is of course not quite right, since it ignores any previous set_pos() calls
- (*i)->set_pos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
- }
-}
-
-MenuItem::MenuItem(MenuItemKind _kind, int _id) :
- kind(_kind),
- id(_id),
- toggled(),
- text(),
- input(),
- help(),
- list(),
- selected(),
- target_menu()
-{
- toggled = false;
- selected = false;
- target_menu = 0;
-}
-
-void
-MenuItem::change_text(const std::string& text_)
-{
- text = text_;
-}
-
-void
-MenuItem::change_input(const std::string& text_)
-{
- input = text_;
-}
-
-void
-MenuItem::set_help(const std::string& help_text)
-{
- std::string overflow;
- help = normal_font->wrap_to_width(help_text, 600, &overflow);
- while (!overflow.empty())
- {
- help += "\n";
- help += normal_font->wrap_to_width(overflow, 600, &overflow);
- }
-}
-
-std::string MenuItem::get_input_with_symbol(bool active_item)
-{
- if(!active_item) {
- input_flickering = true;
- } else {
- input_flickering = ((int) (real_time / FLICK_CURSOR_TIME)) % 2;
- }
-
- char str[1024];
- if(input_flickering)
- snprintf(str, sizeof(str), "%s ",input.c_str());
- else
- snprintf(str, sizeof(str), "%s_",input.c_str());
-
- std::string string = str;
-
- return string;
-}
-
-Menu::~Menu()
-{
- all_menus.remove(this);
-
- for(std::vector<MenuItem*>::iterator i = items.begin();
- i != items.end(); ++i)
- delete *i;
-
- if(current_ == this)
- current_ = NULL;
-
- if (previous == this)
- previous = NULL;
-}
-