static const float MENU_REPEAT_RATE = 0.1f;
Menu::Menu() :
- hit_item(),
pos(),
menuaction(),
delete_character(),
arrange_left(),
active_item()
{
- hit_item = -1;
menuaction = MENU_ACTION_NONE;
delete_character = 0;
mn_input_char = '\0';
menuaction = MENU_ACTION_BACK;
}
- hit_item = -1;
if(items.size() == 0)
return;
break;
case MENU_ACTION_HIT: {
- hit_item = active_item;
switch (items[active_item]->kind) {
case MN_GOTO:
assert(items[active_item]->target_menu != 0);
assert(active_item < int(items.size()));
}
-int
-Menu::check()
-{
- if (hit_item != -1)
- {
- int id = items[hit_item]->id;
- // Clear event when checked out.. (we would end up in a loop when we try to leave "fake" submenu like Addons or Contrib)
- hit_item = -1;
- return id;
- }
- else
- return -1;
-}
-
void
Menu::menu_action(MenuItem* )
{}
const std::string& mapping = "");
MenuItem* add_string_select(int id, const std::string& text);
- virtual void menu_action(MenuItem* item);
+ virtual void menu_action(MenuItem* item) = 0;
void process_input();
/** Remove all entries from the menu */
void clear();
- virtual void check_menu() =0;
-
MenuItem& get_item(int index)
{
return *(items[index]);
virtual void on_window_resize();
protected:
- /** Return the index of the menu item that was 'hit' (ie. the user
- clicked on it) in the last event() call */
- int check ();
-
MenuItem* add_item(std::unique_ptr<MenuItem> menu_item);
private:
void draw_item(DrawingContext& context, int index);
private:
- /** Number of the item that got 'hit' (ie. pressed) in the last
- event()/update() call, -1 if none */
- int hit_item;
-
// position of the menu (ie. center of the menu, not top/left)
Vector pos;
}
}
-bool
-MenuManager::check_menu()
-{
- if (current())
- {
- current()->check_menu();
- return true;
- }
- else
- {
- return false;
- }
-}
-
void
MenuManager::push_menu(int id)
{
void refresh();
void draw(DrawingContext& context);
- bool check_menu();
void set_menu(int id);
void set_menu(std::unique_ptr<Menu> menu);
}
process_events();
- MenuManager::instance().check_menu();
// Unpause the game if the menu has been closed
if (game_pause && !MenuManager::instance().is_active()) {
#include "addon/addon.hpp"
#include "addon/addon_manager.hpp"
+#include "gui/menu.hpp"
+#include "gui/menu_item.hpp"
#include "util/gettext.hpp"
namespace {
}
void
-AddonMenu::check_menu()
+AddonMenu::menu_action(MenuItem* item)
{
- int index = check();
+ int index = item->id;
if (index == -1)
{
AddonMenu();
void refresh();
- void check_menu();
+ void menu_action(MenuItem* item) override;
private:
AddonMenu(const AddonMenu&);
CheatMenu();
void menu_action(MenuItem* item) override;
- void check_menu() override {}
private:
CheatMenu(const CheatMenu&) = delete;
}
void
-ContribLevelsetMenu::check_menu()
+ContribLevelsetMenu::menu_action(MenuItem* item)
{
- int index = check();
- if (index != -1)
+ if (item->kind == MN_ACTION)
{
- if (get_item_by_id(index).kind == MN_ACTION)
- {
- sound_manager->stop_music();
+ sound_manager->stop_music();
- // reload the World so that we have something that we can safely
- // std::move() around without wreaking the ContribMenu
- std::unique_ptr<World> world = World::load(m_world->get_basedir());
- GameManager::current()->start_level(std::move(world), m_levelset->get_level_filename(index));
- }
+ // reload the World so that we have something that we can safely
+ // std::move() around without wreaking the ContribMenu
+ std::unique_ptr<World> world = World::load(m_world->get_basedir());
+ GameManager::current()->start_level(std::move(world), m_levelset->get_level_filename(item->id));
}
}
public:
ContribLevelsetMenu(std::unique_ptr<World> current_world);
- void check_menu();
+ void menu_action(MenuItem* item) override;
private:
ContribLevelsetMenu(const ContribLevelsetMenu&);
#include <physfs.h>
#include <sstream>
+#include "gui/menu_item.hpp"
#include "gui/menu_manager.hpp"
#include "supertux/game_manager.hpp"
#include "supertux/gameconfig.hpp"
}
void
-ContribMenu::check_menu()
+ContribMenu::menu_action(MenuItem* item)
{
- int index = check();
+ int index = item->id;
if (index != -1)
{
// reload the World so that we have something that we can safely
ContribMenu();
~ContribMenu();
- void check_menu();
+ void menu_action(MenuItem* item) override;
private:
ContribMenu(const ContribMenu&);
#include "supertux/menu/game_menu.hpp"
+#include "gui/menu.hpp"
+#include "gui/menu_item.hpp"
#include "gui/menu_manager.hpp"
#include "supertux/game_session.hpp"
-#include "supertux/screen_manager.hpp"
#include "supertux/level.hpp"
#include "supertux/menu/menu_storage.hpp"
#include "supertux/menu/options_menu.hpp"
+#include "supertux/screen_manager.hpp"
#include "util/gettext.hpp"
GameMenu::GameMenu()
}
void
-GameMenu::check_menu()
+GameMenu::menu_action(MenuItem* item)
{
- switch (check())
+ switch (item->id)
{
case MNID_CONTINUE:
MenuManager::instance().clear_menu_stack();
public:
GameMenu();
- void check_menu() override;
+ void menu_action(MenuItem* item) override;
private:
GameMenu(const GameMenu&);
void refresh_menu_item(Controller::Control id);
std::string get_button_name(int button);
- virtual void menu_action(MenuItem* item);
- void check_menu() {}
+ void menu_action(MenuItem* item) override;
private:
void recreate_menu();
void refresh();
std::string get_key_name(SDL_Keycode key);
- virtual void menu_action(MenuItem* item);
+ void menu_action(MenuItem* item) override;
InputManager* controller;
- void check_menu() {}
+
private:
KeyboardMenu(const KeyboardMenu&);
KeyboardMenu& operator=(const KeyboardMenu&);
public:
LanguageMenu();
- void menu_action(MenuItem* item);
- void check_menu() {}
+ void menu_action(MenuItem* item) override;
};
#endif
#include "supertux/menu/main_menu.hpp"
#include "audio/sound_manager.hpp"
+#include "gui/menu_item.hpp"
#include "gui/menu_manager.hpp"
#include "supertux/fadeout.hpp"
#include "supertux/game_manager.hpp"
}
void
-MainMenu::check_menu()
+MainMenu::menu_action(MenuItem* item)
{
- switch (check())
+ switch (item->id)
{
case MNID_STARTGAME:
{
MainMenu();
void on_window_resize() override;
- void check_menu();
+ void menu_action(MenuItem* item) override;
private:
MainMenu(const MainMenu&);
OptionsMenu(bool complete);
virtual ~OptionsMenu();
- void menu_action(MenuItem* item);
+ void menu_action(MenuItem* item) override;
void check_menu();
};
public:
ProfileMenu();
- void menu_action(MenuItem* item);
+ void menu_action(MenuItem* item) override;
void check_menu() {}
};
#include "supertux/menu/worldmap_menu.hpp"
+#include "gui/menu_item.hpp"
#include "gui/menu_manager.hpp"
#include "supertux/menu/menu_storage.hpp"
#include "supertux/menu/options_menu.hpp"
}
void
-WorldmapMenu::check_menu()
+WorldmapMenu::menu_action(MenuItem* item)
{
- switch (check())
+ switch (item->id)
{
case MNID_RETURNWORLDMAP:
MenuManager::instance().clear_menu_stack();
public:
WorldmapMenu();
- void check_menu() override;
+ void menu_action(MenuItem* item) override;
private:
WorldmapMenu(const WorldmapMenu&);
make_tux_jump();
- MenuManager::instance().check_menu();
-
// reopen menu if user closed it (so that the app doesn't close when user
// accidently hit ESC)
if(!MenuManager::instance().is_active() && !g_screen_manager->has_pending_fadeout())
void
WorldMap::update(float delta)
{
- if(!in_level) {
- if (MenuManager::instance().check_menu())
- {
- return;
- }
-
+ if (!in_level && !MenuManager::instance().is_active())
+ {
// update GameObjects
for(size_t i = 0; i < game_objects.size(); ++i) {
GameObject* object = game_objects[i];