Skip to content

Commit

Permalink
Merge branch 'master' of https://code.google.com/p/supertux
Browse files Browse the repository at this point in the history
  • Loading branch information
giby committed Aug 16, 2014
2 parents df83da5 + 8093970 commit a0e9a6c
Show file tree
Hide file tree
Showing 37 changed files with 457 additions and 109 deletions.
1 change: 1 addition & 0 deletions src/control/controller.cpp
Expand Up @@ -26,6 +26,7 @@ const char* Controller::controlNames[] = {
"pause-menu",
"menu-select",
"menu-back",
"cheat-menu",
"console",
"peek-left",
"peek-right",
Expand Down
1 change: 1 addition & 0 deletions src/control/controller.hpp
Expand Up @@ -35,6 +35,7 @@ class Controller
MENU_SELECT,
MENU_BACK,

CHEAT_MENU,
CONSOLE,

PEEK_LEFT,
Expand Down
3 changes: 2 additions & 1 deletion src/control/game_controller_manager.cpp
Expand Up @@ -67,10 +67,11 @@ GameControllerManager::process_button_event(const SDL_ControllerButtonEvent& ev)
break;

case SDL_CONTROLLER_BUTTON_BACK:
set_control(Controller::CONSOLE, ev.state);
break;

case SDL_CONTROLLER_BUTTON_GUIDE:
set_control(Controller::CONSOLE, ev.state);
set_control(Controller::CHEAT_MENU, ev.state);
break;

case SDL_CONTROLLER_BUTTON_START:
Expand Down
1 change: 1 addition & 0 deletions src/control/keyboard_manager.cpp
Expand Up @@ -51,6 +51,7 @@ KeyboardManager::KeyboardManager(InputManager* parent) :
keymap[SDLK_PAGEDOWN] = Controller::PEEK_RIGHT;
keymap[SDLK_HOME] = Controller::PEEK_UP;
keymap[SDLK_END] = Controller::PEEK_DOWN;
keymap[SDLK_TAB] = Controller::CHEAT_MENU;
}

KeyboardManager::~KeyboardManager()
Expand Down
41 changes: 11 additions & 30 deletions src/gui/menu.cpp
Expand Up @@ -36,18 +36,14 @@ static const float MENU_REPEAT_INITIAL = 0.4f;
static const float MENU_REPEAT_RATE = 0.1f;

Menu::Menu() :
hit_item(),
pos(),
menuaction(),
delete_character(),
mn_input_char(),
menu_repeat_time(),
items(),
arrange_left(),
active_item()
{
hit_item = -1;
menuaction = MENU_ACTION_NONE;
delete_character = 0;
mn_input_char = '\0';

Expand Down Expand Up @@ -172,7 +168,6 @@ Menu::clear()
active_item = -1;
}

/* Process actions done on the menu */
void
Menu::process_input()
{
Expand All @@ -183,6 +178,7 @@ Menu::process_input()
pos.y = SCREEN_HEIGHT/2 - scroll_offset * ((float(active_item) / (items.size()-1)) - 0.5f) * 2.0f;
}

MenuAction menuaction = MENU_ACTION_NONE;
Controller* controller = g_input_manager->get_controller();
/** check main input controller... */
if(controller->pressed(Controller::UP)) {
Expand Down Expand Up @@ -234,10 +230,18 @@ Menu::process_input()
menuaction = MENU_ACTION_BACK;
}

hit_item = -1;
if(items.size() == 0)
return;

// The menu_action() call can pop() the menu from the stack and thus
// delete it, so it's important that no further member variables are
// accessed after this call
process_action(menuaction);
}

void
Menu::process_action(MenuAction menuaction)
{
int last_active_item = active_item;
switch(menuaction) {
case MENU_ACTION_UP:
Expand Down Expand Up @@ -289,7 +293,6 @@ Menu::process_input()
break;

case MENU_ACTION_HIT: {
hit_item = active_item;
switch (items[active_item]->kind) {
case MN_GOTO:
assert(items[active_item]->target_menu != 0);
Expand Down Expand Up @@ -367,29 +370,8 @@ Menu::process_input()
case MENU_ACTION_NONE:
break;
}
menuaction = MENU_ACTION_NONE;

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* )
{}

void
Menu::draw_item(DrawingContext& context, int index)
{
Expand Down Expand Up @@ -674,7 +656,6 @@ Menu::set_toggled(int id, bool toggled)
get_item_by_id(id).toggled = toggled;
}

/* Check for menu event */
void
Menu::event(const SDL_Event& event)
{
Expand All @@ -691,7 +672,7 @@ Menu::event(const SDL_Event& event)
y > pos.y - get_height()/2 &&
y < pos.y + get_height()/2)
{
menuaction = MENU_ACTION_HIT;
process_action(MENU_ACTION_HIT);
}
}
break;
Expand Down
18 changes: 2 additions & 16 deletions src/gui/menu.hpp
Expand Up @@ -28,8 +28,6 @@
class DrawingContext;
class MenuItem;

bool confirm_dialog(Surface* background, std::string text);

class Menu
{
static Color default_color;
Expand Down Expand Up @@ -67,7 +65,7 @@ class Menu
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();

Expand All @@ -77,8 +75,6 @@ class Menu
/** Remove all entries from the menu */
void clear();

virtual void check_menu() =0;

MenuItem& get_item(int index)
{
return *(items[index]);
Expand All @@ -105,27 +101,17 @@ class Menu
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 process_action(MenuAction menuaction);
void check_controlfield_change_event(const SDL_Event& event);
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;

/** input event for the menu (up, down, left, right, etc.) */
MenuAction menuaction;

/* input implementation variables */
int delete_character;
char mn_input_char;
Expand Down
15 changes: 1 addition & 14 deletions src/gui/menu_manager.cpp
Expand Up @@ -201,20 +201,6 @@ MenuManager::draw(DrawingContext& context)
}
}

bool
MenuManager::check_menu()
{
if (current())
{
current()->check_menu();
return true;
}
else
{
return false;
}
}

void
MenuManager::push_menu(int id)
{
Expand Down Expand Up @@ -261,6 +247,7 @@ MenuManager::set_menu(std::unique_ptr<Menu> menu)
{
transition(m_menu_stack.empty() ? nullptr : m_menu_stack.back().get(),
menu.get());
m_menu_stack.clear();
m_menu_stack.push_back(std::move(menu));
}
else
Expand Down
1 change: 0 additions & 1 deletion src/gui/menu_manager.hpp
Expand Up @@ -49,7 +49,6 @@ class MenuManager
void refresh();

void draw(DrawingContext& context);
bool check_menu();

void set_menu(int id);
void set_menu(std::unique_ptr<Menu> menu);
Expand Down
15 changes: 13 additions & 2 deletions src/supertux/game_session.cpp
Expand Up @@ -242,7 +242,8 @@ void
GameSession::toggle_pause()
{
// pause
if(!game_pause) {
if (!game_pause && !MenuManager::instance().is_active())
{
speed_before_pause = g_screen_manager->get_speed();
g_screen_manager->set_speed(0);
MenuManager::instance().set_menu(MenuStorage::GAME_MENU);
Expand Down Expand Up @@ -417,10 +418,20 @@ GameSession::update(float elapsed_time)
{
// handle controller
if(g_input_manager->get_controller()->pressed(Controller::PAUSE_MENU))
{
on_escape_press();
}

if(g_input_manager->get_controller()->pressed(Controller::CHEAT_MENU))
{
if (!MenuManager::instance().is_active())
{
game_pause = true;
MenuManager::instance().set_menu(MenuStorage::CHEAT_MENU);
}
}

process_events();
MenuManager::instance().check_menu();

// Unpause the game if the menu has been closed
if (game_pause && !MenuManager::instance().is_active()) {
Expand Down
6 changes: 4 additions & 2 deletions src/supertux/menu/addon_menu.cpp
Expand Up @@ -22,6 +22,8 @@

#include "addon/addon.hpp"
#include "addon/addon_manager.hpp"
#include "gui/menu.hpp"
#include "gui/menu_item.hpp"
#include "util/gettext.hpp"

namespace {
Expand Down Expand Up @@ -120,9 +122,9 @@ AddonMenu::refresh()
}

void
AddonMenu::check_menu()
AddonMenu::menu_action(MenuItem* item)
{
int index = check();
int index = item->id;

if (index == -1)
{
Expand Down
2 changes: 1 addition & 1 deletion src/supertux/menu/addon_menu.hpp
Expand Up @@ -34,7 +34,7 @@ class AddonMenu : public Menu
AddonMenu();

void refresh();
void check_menu();
void menu_action(MenuItem* item) override;

private:
AddonMenu(const AddonMenu&);
Expand Down

0 comments on commit a0e9a6c

Please sign in to comment.