#include <iostream>
#include "lisp/list_iterator.hpp"
+#include "gui/menu_manager.hpp"
#include "supertux/console.hpp"
#include "supertux/gameconfig.hpp"
#include "supertux/menu/joystick_menu.hpp"
if (Console::instance->hasFocus()) {
// if console is open: send key there
process_console_key_event(event);
- } else if (Menu::current()) {
+ } else if (MenuManager2::current()) {
// if menu mode: send key there
process_menu_key_event(event);
} else if(key_mapping == keymap.end()) {
#include "control/joystickkeyboardcontroller.hpp"
#include "gui/menu_item.hpp"
+#include "gui/menu_manager.hpp"
#include "gui/mousecursor.hpp"
#include "supertux/globals.hpp"
#include "supertux/mainloop.hpp"
extern SDL_Surface* g_screen;
-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);
- }
-}
-
-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;
-}
-
Menu::Menu() :
hit_item(),
pos_x(),
arrow_left(),
arrow_right()
{
- all_menus.push_back(this);
+ MenuManager2::all_menus.push_back(this);
hit_item = -1;
menuaction = MENU_ACTION_NONE;
arrow_right.reset(new Surface("images/engine/menu/arrow-right.png"));
}
+Menu::~Menu()
+{
+ MenuManager2::all_menus.remove(this);
+
+ for(std::vector<MenuItem*>::iterator i = items.begin();
+ i != items.end(); ++i)
+ {
+ delete *i;
+ }
+
+ if (MenuManager2::current_ == this)
+ MenuManager2::current_ = NULL;
+
+ if (MenuManager2::previous == this)
+ MenuManager2::previous = NULL;
+}
+
void
Menu::set_pos(float x, float y, float rw, float rh)
{
effect_progress = 1.0f;
if (close) {
- current_ = 0;
+ MenuManager2::current_ = 0;
close = false;
}
}
switch (items[active_item]->kind) {
case MN_GOTO:
assert(items[active_item]->target_menu != 0);
- Menu::push_current(items[active_item]->target_menu);
+ MenuManager2::push_current(items[active_item]->target_menu);
break;
case MN_TOGGLE:
break;
case MN_BACK:
- Menu::pop_current();
+ MenuManager2::pop_current();
break;
default:
break;
break;
case MENU_ACTION_BACK:
- Menu::pop_current();
+ MenuManager2::pop_current();
break;
case MENU_ACTION_NONE:
{
if (close)
{
- menu_width = (current_->get_width() * (1.0f - effect_progress));
- menu_height = (current_->get_height() * (1.0f - effect_progress));
+ menu_width = (MenuManager2::current_->get_width() * (1.0f - effect_progress));
+ menu_height = (MenuManager2::current_->get_height() * (1.0f - effect_progress));
}
- else if (Menu::previous)
+ else if (MenuManager2::previous)
{
- menu_width = (menu_width * effect_progress) + (Menu::previous->get_width() * (1.0f - effect_progress));
- menu_height = (menu_height * effect_progress) + (Menu::previous->get_height() * (1.0f - effect_progress));
+ menu_width = (menu_width * effect_progress) + (MenuManager2::previous->get_width() * (1.0f - effect_progress));
+ menu_height = (menu_height * effect_progress) + (MenuManager2::previous->get_height() * (1.0f - effect_progress));
//std::cout << effect_progress << " " << this << " " << last_menus.back() << std::endl;
}
else
Menu*
Menu::get_parent() const
{
- if (last_menus.empty())
+ if (MenuManager2::last_menus.empty())
return 0;
else
- return last_menus.back();
+ return MenuManager2::last_menus.back();
}
/* Check for menu event */
static Color label_color;
static Color field_color;
private:
- static std::vector<Menu*> last_menus;
-
- /** Pointers to all currently available menus, used to handle repositioning on window resize */
- static std::list<Menu*> all_menus;
-
- static Menu* previous;
- static Menu* current_;
-
-public:
- /** Set the current menu, if pmenu is NULL, hide the current menu */
- static void set_current(Menu* pmenu);
-
- static void push_current(Menu* pmenu);
- static void pop_current();
-
- static void recalc_pos();
-
- /** Return the current active menu or NULL if none is active */
- static Menu* current()
- {
- return current_;
- }
-
-private:
/* Action done on the menu */
enum MenuAction {
MENU_ACTION_NONE = -1,
char mn_input_char;
float menu_repeat_time;
+public:
bool close;
-public:
std::vector<MenuItem*> items;
-private:
+public:
float effect_progress;
float effect_start_time;
+
+private:
int arrange_left;
int active_item;
class MenuItem
{
public:
+ static MenuItem* create(MenuItemKind kind, const std::string& text,
+ int init_toggle, Menu* target_menu, int id, int key);
+
+public:
MenuItem(MenuItemKind kind, int id = -1);
void set_help(const std::string& help_text);
void change_text (const std::string& text);
void change_input(const std::string& text);
- static MenuItem* create(MenuItemKind kind, const std::string& text,
- int init_toggle, Menu* target_menu, int id, int key);
-
std::string get_input_with_symbol(bool active_item); // returns the text with an input symbol
public:
--- /dev/null
+// SuperTux
+// Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include "gui/menu_manager.hpp"
+
+#include "control/joystickkeyboardcontroller.hpp"
+#include "gui/menu.hpp"
+#include "supertux/globals.hpp"
+#include "supertux/timer.hpp"
+
+std::vector<Menu*> MenuManager2::last_menus;
+std::list<Menu*> MenuManager2::all_menus;
+Menu* MenuManager2::current_ = 0;
+Menu* MenuManager2::previous = 0;
+
+void
+MenuManager2::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
+MenuManager2::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
+MenuManager2::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
+MenuManager2::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);
+ }
+}
+
+/* EOF */
--- /dev/null
+// SuperTux
+// Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_SUPERTUX_GUI_MENU_MANAGER_HPP
+#define HEADER_SUPERTUX_GUI_MENU_MANAGER_HPP
+
+#include <vector>
+#include <list>
+
+class Menu;
+
+class MenuManager2 // FIXME: temporary name
+{
+public:
+ static std::vector<Menu*> last_menus;
+ static Menu* previous;
+ static Menu* current_;
+
+public:
+ /** Pointers to all currently available menus, used to handle repositioning on window resize */
+ static std::list<Menu*> all_menus;
+
+public:
+ /** Set the current menu, if pmenu is NULL, hide the current menu */
+ static void set_current(Menu* pmenu);
+
+ static void push_current(Menu* pmenu);
+ static void pop_current();
+
+ static void recalc_pos();
+
+ /** Return the current active menu or NULL if none is active */
+ static Menu* current()
+ {
+ return current_;
+ }
+
+private:
+ MenuManager2(const MenuManager2&);
+ MenuManager2& operator=(const MenuManager2&);
+};
+
+#endif
+
+/* EOF */
#include "audio/sound_manager.hpp"
#include "control/joystickkeyboardcontroller.hpp"
#include "gui/menu.hpp"
+#include "gui/menu_manager.hpp"
#include "math/random_generator.hpp"
#include "object/camera.hpp"
#include "object/endsequence_fireworks.hpp"
if(!game_pause) {
speed_before_pause = g_main_loop->get_speed();
g_main_loop->set_speed(0);
- Menu::set_current(game_menu.get());
+ MenuManager2::set_current(game_menu.get());
game_menu->set_active_item(MNID_CONTINUE);
game_pause = true;
}
void
GameSession::process_menu()
{
- Menu* menu = Menu::current();
+ Menu* menu = MenuManager2::current();
if(menu) {
if(menu == game_menu.get()) {
switch (game_menu->check()) {
case MNID_CONTINUE:
- Menu::set_current(0);
+ MenuManager2::set_current(0);
toggle_pause();
break;
case MNID_ABORTLEVEL:
- Menu::set_current(0);
+ MenuManager2::set_current(0);
g_main_loop->exit_screen();
break;
}
process_menu();
// Unpause the game if the menu has been closed
- if (game_pause && !Menu::current()) {
+ if (game_pause && !MenuManager2::current()) {
g_main_loop->set_speed(speed_before_pause);
game_pause = false;
}
#include "audio/sound_manager.hpp"
#include "control/joystickkeyboardcontroller.hpp"
#include "gui/menu.hpp"
+#include "gui/menu_manager.hpp"
#include "scripting/squirrel_util.hpp"
#include "scripting/time_scheduler.hpp"
#include "supertux/constants.hpp"
static int frame_count = 0;
current_screen->draw(context);
- if(Menu::current() != NULL)
- Menu::current()->draw(context);
+ if(MenuManager2::current() != NULL)
+ MenuManager2::current()->draw(context);
if(screen_fade.get() != NULL)
screen_fade->draw(context);
Console::instance->draw(context);
Scripting::update_debugger();
Scripting::TimeScheduler::instance->update(game_time);
current_screen->update(elapsed_time);
- if (Menu::current() != NULL)
- Menu::current()->update();
+ if (MenuManager2::current() != NULL)
+ MenuManager2::current()->update();
if(screen_fade.get() != NULL)
screen_fade->update(elapsed_time);
Console::instance->update(elapsed_time);
{
g_main_controller->process_event(event);
- if(Menu::current() != NULL)
- Menu::current()->event(event);
+ if(MenuManager2::current() != NULL)
+ MenuManager2::current()->event(event);
switch(event.type)
{
case SDL_VIDEORESIZE:
Renderer::instance()->resize(event.resize.w, event.resize.h);
- Menu::recalc_pos();
+ MenuManager2::recalc_pos();
break;
case SDL_KEYDOWN:
{
g_config->use_fullscreen = !g_config->use_fullscreen;
init_video();
- Menu::recalc_pos();
+ MenuManager2::recalc_pos();
}
else if (event.key.keysym.sym == SDLK_PRINT ||
event.key.keysym.sym == SDLK_F12)
// SuperTux
-// Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.de>
+// Copyright (C) 2006 Matthias Braun <matze@braunis.de>,
+// 2007 Ingo Ruhnke <grumbel@gmx.de>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
#include "findlocale.h"
}
#include "gui/menu_item.hpp"
+#include "gui/menu_manager.hpp"
#include "supertux/gameconfig.hpp"
enum {
dictionary_manager.set_language(language);
g_config->locale = language.str();
g_config->save();
- Menu::pop_current();
+ MenuManager2::pop_current();
}
else if (item->id == MNID_LANGUAGE_ENGLISH) // english
{
g_config->locale = "en";
dictionary_manager.set_language(tinygettext::Language::from_name(g_config->locale));
g_config->save();
- Menu::pop_current();
+ MenuManager2::pop_current();
}
else
{
g_config->locale = i->str();
dictionary_manager.set_language(*i);
g_config->save();
- Menu::pop_current();
+ MenuManager2::pop_current();
break;
}
}
#include "audio/sound_manager.hpp"
#include "control/joystickkeyboardcontroller.hpp"
#include "gui/menu.hpp"
+#include "gui/menu_manager.hpp"
#include "gui/menu_item.hpp"
#include "supertux/gameconfig.hpp"
#include "supertux/globals.hpp"
g_config->aspect_width = 0; // Magic values
g_config->aspect_height = 0;
Renderer::instance()->apply_config();
- Menu::recalc_pos();
+ MenuManager2::recalc_pos();
}
else if(sscanf(item->list[item->selected].c_str(), "%d:%d", &g_config->aspect_width, &g_config->aspect_height) == 2)
{
Renderer::instance()->apply_config();
- Menu::recalc_pos();
+ MenuManager2::recalc_pos();
}
else
{
g_config->magnification /= 100.0f;
}
Renderer::instance()->apply_config();
- Menu::recalc_pos();
+ MenuManager2::recalc_pos();
break;
case MNID_FULLSCREEN_RESOLUTION:
if(g_config->use_fullscreen != is_toggled(MNID_FULLSCREEN)) {
g_config->use_fullscreen = !g_config->use_fullscreen;
init_video(); // FIXME: Should call apply_config instead
- Menu::recalc_pos();
+ MenuManager2::recalc_pos();
g_config->save();
}
break;
#include <sstream>
#include "gui/menu.hpp"
+#include "gui/menu_manager.hpp"
#include "gui/menu_item.hpp"
#include "supertux/gameconfig.hpp"
#include "util/gettext.hpp"
ProfileMenu::menu_action(MenuItem* item)
{
g_config->profile = item->id;
- Menu::set_current(0);
+ MenuManager2::set_current(0);
}
/*
#include "addon/addon_manager.hpp"
#include "audio/sound_manager.hpp"
#include "gui/menu.hpp"
+#include "gui/menu_manager.hpp"
#include "gui/menu_item.hpp"
#include "lisp/parser.hpp"
#include "object/camera.hpp"
contrib_world_menu->add_hl();
contrib_world_menu->add_back(_("Back"));
- Menu::push_current(contrib_world_menu.get());
+ MenuManager2::push_current(contrib_world_menu.get());
}
}
try {
AddonManager::get_instance().check_online();
generate_addons_menu();
- Menu::set_current(addons_menu.get());
+ MenuManager2::set_current(addons_menu.get());
addons_menu->set_active_item(index);
}
catch (std::runtime_error e) {
sector->activate(sector->player->get_pos());
}
- Menu::set_current(main_menu.get());
+ MenuManager2::set_current(main_menu.get());
}
void
{
Sector* sector = titlesession->get_current_sector();
sector->deactivate();
- Menu::set_current(NULL);
+ MenuManager2::set_current(NULL);
}
void
make_tux_jump();
- Menu* menu = Menu::current();
+ Menu* menu = MenuManager2::current();
if(menu) {
if(menu == main_menu.get()) {
switch (main_menu->check()) {
case MNID_LEVELS_CONTRIB:
// Contrib Menu
generate_contrib_menu();
- Menu::push_current(contrib_menu.get());
+ MenuManager2::push_current(contrib_menu.get());
break;
case MNID_ADDONS:
// Add-ons Menu
generate_addons_menu();
- Menu::push_current(addons_menu.get());
+ MenuManager2::push_current(addons_menu.get());
break;
case MNID_CREDITS:
- Menu::set_current(NULL);
+ MenuManager2::set_current(NULL);
g_main_loop->push_screen(new TextScroller("credits.txt"),
new FadeOut(0.5));
break;
// reopen menu if user closed it (so that the app doesn't close when user
// accidently hit ESC)
- if(Menu::current() == 0 && g_main_loop->has_no_pending_fadeout()) {
+ if(MenuManager2::current() == 0 && g_main_loop->has_no_pending_fadeout()) {
generate_main_menu();
- Menu::set_current(main_menu.get());
+ MenuManager2::set_current(main_menu.get());
}
}
void
TitleScreen::start_game()
{
- Menu::set_current(NULL);
+ MenuManager2::set_current(NULL);
std::string basename = current_world->get_basedir();
basename = basename.substr(0, basename.length()-1);
std::string worlddirname = FileSystem::basename(basename);
#include "audio/sound_manager.hpp"
#include "control/joystickkeyboardcontroller.hpp"
#include "gui/menu.hpp"
+#include "gui/menu_manager.hpp"
#include "gui/mousecursor.hpp"
#include "lisp/lisp.hpp"
#include "lisp/list_iterator.hpp"
WorldMap::on_escape_press()
{
// Show or hide the menu
- if(!Menu::current()) {
- Menu::set_current(worldmap_menu.get());
+ if(!MenuManager2::current()) {
+ MenuManager2::set_current(worldmap_menu.get());
tux->set_direction(D_NONE); // stop tux movement when menu is called
} else {
- Menu::set_current(NULL);
+ MenuManager2::set_current(NULL);
}
}
WorldMap::update(float delta)
{
if(!in_level) {
- Menu* menu = Menu::current();
+ Menu* menu = MenuManager2::current();
if(menu != NULL) {
if(menu == worldmap_menu.get()) {
switch (worldmap_menu->check())
{
case MNID_RETURNWORLDMAP: // Return to game
- Menu::set_current(0);
+ MenuManager2::set_current(0);
break;
case MNID_QUITWORLDMAP: // Quit Worldmap
g_main_loop->exit_screen();
WorldMap::setup()
{
sound_manager->play_music(music);
- Menu::set_current(NULL);
+ MenuManager2::set_current(NULL);
current_ = this;
load_state();