From: Ingo Ruhnke Date: Wed, 6 Aug 2014 07:34:49 +0000 (+0200) Subject: Moved keyboard code into KeyboardManager class X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=b26a4e8ac7eedb0def71d2a0d9b0b4b2c2d42cc9;p=supertux.git Moved keyboard code into KeyboardManager class --- diff --git a/src/control/game_controller_manager.cpp b/src/control/game_controller_manager.cpp index b76d41fe7..a9478ce30 100644 --- a/src/control/game_controller_manager.cpp +++ b/src/control/game_controller_manager.cpp @@ -40,7 +40,7 @@ void GameControllerManager::process_button_event(const SDL_ControllerButtonEvent& ev) { //log_info << "button event: " << static_cast(ev.button) << " " << static_cast(ev.state) << std::endl; - auto controller = m_parent->get_main_controller(); + auto controller = m_parent->get_controller(); switch(ev.button) { case SDL_CONTROLLER_BUTTON_A: @@ -112,7 +112,7 @@ GameControllerManager::process_axis_event(const SDL_ControllerAxisEvent& ev) // to OR the values together //log_info << "axis event: " << static_cast(ev.axis) << " " << ev.value << std::endl; - auto controller = m_parent->get_main_controller(); + auto controller = m_parent->get_controller(); auto axis2button = [this, &controller](int value, Controller::Control control_left, Controller::Control control_right) { diff --git a/src/control/joystick_manager.cpp b/src/control/joystick_manager.cpp index 4d2ba4130..a9230b47e 100644 --- a/src/control/joystick_manager.cpp +++ b/src/control/joystick_manager.cpp @@ -452,10 +452,10 @@ JoystickManager::set_joy_controls(Controller::Control id, bool value) { if (jump_with_up_joy && id == Controller::UP) { - parent->get_main_controller()->set_control(Controller::JUMP, value); + parent->get_controller()->set_control(Controller::JUMP, value); } - parent->get_main_controller()->set_control(id, value); + parent->get_controller()->set_control(id, value); } /* EOF */ diff --git a/src/control/joystick_manager.hpp b/src/control/joystick_manager.hpp index f899ffce5..e30fdc46f 100644 --- a/src/control/joystick_manager.hpp +++ b/src/control/joystick_manager.hpp @@ -29,7 +29,7 @@ class JoystickKeyboardController; -class JoystickManager +class JoystickManager final { private: typedef Uint8 JoyId; diff --git a/src/control/joystickkeyboardcontroller.cpp b/src/control/joystickkeyboardcontroller.cpp index 50de73969..ea2d9ea2c 100644 --- a/src/control/joystickkeyboardcontroller.cpp +++ b/src/control/joystickkeyboardcontroller.cpp @@ -19,47 +19,22 @@ #include +#include "control/keyboard_manager.hpp" #include "control/joystick_manager.hpp" #include "control/game_controller_manager.hpp" #include "gui/menu_manager.hpp" #include "lisp/list_iterator.hpp" -#include "supertux/console.hpp" #include "supertux/gameconfig.hpp" -#include "supertux/menu/joystick_menu.hpp" -#include "supertux/menu/keyboard_menu.hpp" -#include "supertux/menu/menu_storage.hpp" #include "util/gettext.hpp" #include "util/writer.hpp" JoystickKeyboardController::JoystickKeyboardController() : controller(new Controller), m_use_game_controller(true), + keyboard_manager(new KeyboardManager(this)), joystick_manager(new JoystickManager(this)), - game_controller_manager(new GameControllerManager(this)), - keymap(), - jump_with_up_kbd(), - wait_for_key(-1) + game_controller_manager(new GameControllerManager(this)) { - // initialize default keyboard map - keymap[SDLK_LEFT] = Controller::LEFT; - keymap[SDLK_RIGHT] = Controller::RIGHT; - keymap[SDLK_UP] = Controller::UP; - keymap[SDLK_DOWN] = Controller::DOWN; - keymap[SDLK_SPACE] = Controller::JUMP; - keymap[SDLK_LCTRL] = Controller::ACTION; - keymap[SDLK_LALT] = Controller::ACTION; - keymap[SDLK_ESCAPE] = Controller::PAUSE_MENU; - keymap[SDLK_p] = Controller::PAUSE_MENU; - keymap[SDLK_PAUSE] = Controller::PAUSE_MENU; - keymap[SDLK_RETURN] = Controller::MENU_SELECT; - keymap[SDLK_KP_ENTER] = Controller::MENU_SELECT; - keymap[SDLK_CARET] = Controller::CONSOLE; - keymap[SDLK_DELETE] = Controller::PEEK_LEFT; - keymap[SDLK_PAGEDOWN] = Controller::PEEK_RIGHT; - keymap[SDLK_HOME] = Controller::PEEK_UP; - keymap[SDLK_END] = Controller::PEEK_DOWN; - - jump_with_up_kbd = false; } JoystickKeyboardController::~JoystickKeyboardController() @@ -67,7 +42,7 @@ JoystickKeyboardController::~JoystickKeyboardController() } Controller* -JoystickKeyboardController::get_main_controller() +JoystickKeyboardController::get_controller() { return controller.get(); } @@ -76,30 +51,9 @@ void JoystickKeyboardController::read(const Reader& lisp) { const lisp::Lisp* keymap_lisp = lisp.get_lisp("keymap"); - if (keymap_lisp) { - keymap.clear(); - keymap_lisp->get("jump-with-up", jump_with_up_kbd); - lisp::ListIterator iter(keymap_lisp); - while(iter.next()) { - if (iter.item() == "map") { - int key = -1; - std::string control; - const lisp::Lisp* map = iter.lisp(); - map->get("key", key); - map->get("control", control); - - int i = 0; - for(i = 0; Controller::controlNames[i] != 0; ++i) { - if (control == Controller::controlNames[i]) - break; - } - if (Controller::controlNames[i] == 0) { - log_info << "Invalid control '" << control << "' in keymap" << std::endl; - continue; - } - keymap[SDL_Keycode(key)] = Control(i); - } - } + if (keymap_lisp) + { + keyboard_manager->read(keymap_lisp); } const lisp::Lisp* joystick_lisp = lisp.get_lisp(_("joystick")); @@ -113,13 +67,7 @@ void JoystickKeyboardController::write(Writer& writer) { writer.start_list("keymap"); - writer.write("jump-with-up", jump_with_up_kbd); - for(KeyMap::iterator i = keymap.begin(); i != keymap.end(); ++i) { - writer.start_list("map"); - writer.write("key", (int) i->first); - writer.write("control", Controller::controlNames[i->second]); - writer.end_list("map"); - } + keyboard_manager->write(writer); writer.end_list("keymap"); writer.start_list("joystick"); @@ -144,12 +92,12 @@ JoystickKeyboardController::process_event(const SDL_Event& event) { switch(event.type) { case SDL_TEXTINPUT: - process_text_input_event(event.text); + keyboard_manager->process_text_input_event(event.text); break; case SDL_KEYUP: case SDL_KEYDOWN: - process_key_event(event.key); + keyboard_manager->process_key_event(event.key); break; case SDL_JOYAXISMOTION: @@ -204,183 +152,4 @@ JoystickKeyboardController::process_event(const SDL_Event& event) } } -void -JoystickKeyboardController::process_text_input_event(const SDL_TextInputEvent& event) -{ - if (Console::instance->hasFocus()) { - for(int i = 0; event.text[i] != '\0'; ++i) - { - Console::instance->input(event.text[i]); - } - } -} - -void -JoystickKeyboardController::process_key_event(const SDL_KeyboardEvent& event) -{ - KeyMap::iterator key_mapping = keymap.find(event.keysym.sym); - - // if console key was pressed: toggle console - if ((key_mapping != keymap.end()) && (key_mapping->second == Controller::CONSOLE)) { - if (event.type == SDL_KEYDOWN) - Console::instance->toggle(); - } else { - if (Console::instance->hasFocus()) { - // if console is open: send key there - process_console_key_event(event); - } else if (MenuManager::current()) { - // if menu mode: send key there - process_menu_key_event(event); - } else if (key_mapping == keymap.end()) { - // default action: update controls - //log_debug << "Key " << event.key.SDL_Keycode.sym << " is unbound" << std::endl; - } else { - Control control = key_mapping->second; - bool value = (event.type == SDL_KEYDOWN); - controller->set_control(control, value); - if (jump_with_up_kbd && control == Controller::UP){ - controller->set_control(Controller::JUMP, value); - } - } - } -} - -void -JoystickKeyboardController::process_console_key_event(const SDL_KeyboardEvent& event) -{ - if (event.type != SDL_KEYDOWN) return; - - switch (event.keysym.sym) { - case SDLK_RETURN: - Console::instance->enter(); - break; - case SDLK_BACKSPACE: - Console::instance->backspace(); - break; - case SDLK_TAB: - Console::instance->autocomplete(); - break; - case SDLK_PAGEUP: - Console::instance->scroll(-1); - break; - case SDLK_PAGEDOWN: - Console::instance->scroll(+1); - break; - case SDLK_HOME: - Console::instance->move_cursor(-65535); - break; - case SDLK_END: - Console::instance->move_cursor(+65535); - break; - case SDLK_UP: - Console::instance->show_history(-1); - break; - case SDLK_DOWN: - Console::instance->show_history(+1); - break; - case SDLK_LEFT: - Console::instance->move_cursor(-1); - break; - case SDLK_RIGHT: - Console::instance->move_cursor(+1); - break; - default: - break; - } -} - -void -JoystickKeyboardController::process_menu_key_event(const SDL_KeyboardEvent& event) -{ - // wait for key mode? - if (wait_for_key >= 0) { - if (event.type == SDL_KEYUP) - return; - - if (event.keysym.sym != SDLK_ESCAPE - && event.keysym.sym != SDLK_PAUSE) { - bind_key(event.keysym.sym, Control(wait_for_key)); - } - reset(); - MenuStorage::get_key_options_menu()->update(); - wait_for_key = -1; - return; - } - if (joystick_manager->wait_for_joystick >= 0) { - if (event.keysym.sym == SDLK_ESCAPE) { - reset(); - MenuStorage::get_joystick_options_menu()->update(); - joystick_manager->wait_for_joystick = -1; - } - return; - } - - Control control; - /* we use default keys when the menu is open (to avoid problems when - * redefining keys to invalid settings - */ - switch(event.keysym.sym) { - case SDLK_UP: - control = Controller::UP; - break; - case SDLK_DOWN: - control = Controller::DOWN; - break; - case SDLK_LEFT: - control = Controller::LEFT; - break; - case SDLK_RIGHT: - control = Controller::RIGHT; - break; - case SDLK_SPACE: - case SDLK_RETURN: - case SDLK_KP_ENTER: - control = Controller::MENU_SELECT; - break; - case SDLK_ESCAPE: - case SDLK_PAUSE: - control = Controller::PAUSE_MENU; - break; - default: - return; - break; - } - - controller->set_control(control, (event.type == SDL_KEYDOWN)); -} - -void -JoystickKeyboardController::bind_key(SDL_Keycode key, Control control) -{ - // remove all previous mappings for that control and for that key - for(KeyMap::iterator i = keymap.begin(); - i != keymap.end(); /* no ++i */) { - if (i->second == control) { - KeyMap::iterator e = i; - ++i; - keymap.erase(e); - } else { - ++i; - } - } - - KeyMap::iterator i = keymap.find(key); - if (i != keymap.end()) - keymap.erase(i); - - // add new mapping - keymap[key] = control; -} - -SDL_Keycode -JoystickKeyboardController::reversemap_key(Control c) -{ - for(KeyMap::iterator i = keymap.begin(); i != keymap.end(); ++i) { - if (i->second == c) - return i->first; - } - - return SDLK_UNKNOWN; -} - /* EOF */ diff --git a/src/control/joystickkeyboardcontroller.hpp b/src/control/joystickkeyboardcontroller.hpp index 411000bbb..24adfc427 100644 --- a/src/control/joystickkeyboardcontroller.hpp +++ b/src/control/joystickkeyboardcontroller.hpp @@ -32,10 +32,11 @@ class Controller; class GameControllerManager; class JoystickManager; class JoystickMenu; +class KeyboardManager; class KeyboardMenu; class Menu; -class JoystickKeyboardController +class JoystickKeyboardController final { private: friend class KeyboardMenu; @@ -43,14 +44,10 @@ private: typedef Controller::Control Control; - typedef std::map KeyMap; - public: JoystickKeyboardController(); virtual ~JoystickKeyboardController(); - /** Process an SDL Event and return true if the event has been used - */ void process_event(const SDL_Event& event); void write(Writer& writer); @@ -58,34 +55,18 @@ public: void update(); void reset(); - void updateAvailableJoysticks(); - - Controller *get_main_controller(); - -private: - void process_text_input_event(const SDL_TextInputEvent& event); - void process_key_event(const SDL_KeyboardEvent& event); - void process_console_key_event(const SDL_KeyboardEvent& event); - void process_menu_key_event(const SDL_KeyboardEvent& event); - - SDL_Keycode reversemap_key(Control c); - void bind_key(SDL_Keycode key, Control c); + Controller* get_controller(); private: std::unique_ptr controller; + public: bool m_use_game_controller; - std::unique_ptr joystick_manager; + std::unique_ptr keyboard_manager; + std::unique_ptr joystick_manager; std::unique_ptr game_controller_manager; private: - KeyMap keymap; - - bool jump_with_up_kbd; // Keyboard up jumps - - int wait_for_key; - -private: JoystickKeyboardController(const JoystickKeyboardController&); JoystickKeyboardController& operator=(const JoystickKeyboardController&); }; diff --git a/src/control/keyboard_manager.cpp b/src/control/keyboard_manager.cpp new file mode 100644 index 000000000..929e10617 --- /dev/null +++ b/src/control/keyboard_manager.cpp @@ -0,0 +1,298 @@ +// SuperTux +// Copyright (C) 2006 Matthias Braun , +// 2007-2014 Ingo Ruhnke +// +// 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 . + +#include "control/keyboard_manager.hpp" + +#include "control/controller.hpp" +#include "control/joystick_manager.hpp" +#include "gui/menu_manager.hpp" +#include "lisp/list_iterator.hpp" +#include "supertux/console.hpp" +#include "supertux/menu/joystick_menu.hpp" +#include "supertux/menu/keyboard_menu.hpp" +#include "supertux/menu/menu_storage.hpp" +#include "util/writer.hpp" + +KeyboardManager::KeyboardManager(JoystickKeyboardController* parent) : + m_parent(parent), + keymap(), + jump_with_up_kbd(false), + wait_for_key(-1) +{ + // initialize default keyboard map + keymap[SDLK_LEFT] = Controller::LEFT; + keymap[SDLK_RIGHT] = Controller::RIGHT; + keymap[SDLK_UP] = Controller::UP; + keymap[SDLK_DOWN] = Controller::DOWN; + keymap[SDLK_SPACE] = Controller::JUMP; + keymap[SDLK_LCTRL] = Controller::ACTION; + keymap[SDLK_LALT] = Controller::ACTION; + keymap[SDLK_ESCAPE] = Controller::PAUSE_MENU; + keymap[SDLK_p] = Controller::PAUSE_MENU; + keymap[SDLK_PAUSE] = Controller::PAUSE_MENU; + keymap[SDLK_RETURN] = Controller::MENU_SELECT; + keymap[SDLK_KP_ENTER] = Controller::MENU_SELECT; + keymap[SDLK_CARET] = Controller::CONSOLE; + keymap[SDLK_DELETE] = Controller::PEEK_LEFT; + keymap[SDLK_PAGEDOWN] = Controller::PEEK_RIGHT; + keymap[SDLK_HOME] = Controller::PEEK_UP; + keymap[SDLK_END] = Controller::PEEK_DOWN; +} + +KeyboardManager::~KeyboardManager() +{ +} + +void +KeyboardManager::process_key_event(const SDL_KeyboardEvent& event) +{ + KeyMap::iterator key_mapping = keymap.find(event.keysym.sym); + + // if console key was pressed: toggle console + if (key_mapping != keymap.end() && + key_mapping->second == Controller::CONSOLE) + { + if (event.type == SDL_KEYDOWN) + { + Console::instance->toggle(); + } + } + else if (Console::instance->hasFocus()) + { + // if console is open: send key there + process_console_key_event(event); + } + else if (MenuManager::current()) + { + // if menu mode: send key there + process_menu_key_event(event); + } + else if (key_mapping == keymap.end()) + { + // default action: update controls + //log_debug << "Key " << event.key.SDL_Keycode.sym << " is unbound" << std::endl; + } + else + { + auto control = key_mapping->second; + bool value = (event.type == SDL_KEYDOWN); + m_parent->get_controller()->set_control(control, value); + if (jump_with_up_kbd && control == Controller::UP) + { + m_parent->get_controller()->set_control(Controller::JUMP, value); + } + } +} + +void +KeyboardManager::process_text_input_event(const SDL_TextInputEvent& event) +{ + if (Console::instance->hasFocus()) { + for(int i = 0; event.text[i] != '\0'; ++i) + { + Console::instance->input(event.text[i]); + } + } +} + +void +KeyboardManager::process_console_key_event(const SDL_KeyboardEvent& event) +{ + if (event.type != SDL_KEYDOWN) return; + + switch (event.keysym.sym) { + case SDLK_RETURN: + Console::instance->enter(); + break; + case SDLK_BACKSPACE: + Console::instance->backspace(); + break; + case SDLK_TAB: + Console::instance->autocomplete(); + break; + case SDLK_PAGEUP: + Console::instance->scroll(-1); + break; + case SDLK_PAGEDOWN: + Console::instance->scroll(+1); + break; + case SDLK_HOME: + Console::instance->move_cursor(-65535); + break; + case SDLK_END: + Console::instance->move_cursor(+65535); + break; + case SDLK_UP: + Console::instance->show_history(-1); + break; + case SDLK_DOWN: + Console::instance->show_history(+1); + break; + case SDLK_LEFT: + Console::instance->move_cursor(-1); + break; + case SDLK_RIGHT: + Console::instance->move_cursor(+1); + break; + default: + break; + } +} + +void +KeyboardManager::process_menu_key_event(const SDL_KeyboardEvent& event) +{ + // wait for key mode? + if (wait_for_key >= 0) + { + if (event.type == SDL_KEYUP) + return; + + if (event.keysym.sym != SDLK_ESCAPE && + event.keysym.sym != SDLK_PAUSE) + { + bind_key(event.keysym.sym, static_cast(wait_for_key)); + } + m_parent->reset(); + MenuStorage::get_key_options_menu()->update(); + wait_for_key = -1; + return; + } + + if (m_parent->joystick_manager->wait_for_joystick >= 0) + { + if (event.keysym.sym == SDLK_ESCAPE) + { + m_parent->reset(); + MenuStorage::get_joystick_options_menu()->update(); + m_parent->joystick_manager->wait_for_joystick = -1; + } + return; + } + + Controller::Control control; + /* we use default keys when the menu is open (to avoid problems when + * redefining keys to invalid settings + */ + switch(event.keysym.sym) { + case SDLK_UP: + control = Controller::UP; + break; + case SDLK_DOWN: + control = Controller::DOWN; + break; + case SDLK_LEFT: + control = Controller::LEFT; + break; + case SDLK_RIGHT: + control = Controller::RIGHT; + break; + case SDLK_SPACE: + case SDLK_RETURN: + case SDLK_KP_ENTER: + control = Controller::MENU_SELECT; + break; + case SDLK_ESCAPE: + case SDLK_PAUSE: + control = Controller::PAUSE_MENU; + break; + default: + return; + break; + } + + m_parent->get_controller()->set_control(control, (event.type == SDL_KEYDOWN)); +} + +void +KeyboardManager::bind_key(SDL_Keycode key, Controller::Control control) +{ + // remove all previous mappings for that control and for that key + for(KeyMap::iterator i = keymap.begin(); + i != keymap.end(); /* no ++i */) { + if (i->second == control) { + KeyMap::iterator e = i; + ++i; + keymap.erase(e); + } else { + ++i; + } + } + + KeyMap::iterator i = keymap.find(key); + if (i != keymap.end()) + keymap.erase(i); + + // add new mapping + keymap[key] = control; +} + +SDL_Keycode +KeyboardManager::reversemap_key(Controller::Control c) +{ + for(KeyMap::iterator i = keymap.begin(); i != keymap.end(); ++i) + { + if (i->second == c) + { + return i->first; + } + } + + return SDLK_UNKNOWN; +} + +void +KeyboardManager::read(const lisp::Lisp* keymap_lisp) +{ + keymap.clear(); + keymap_lisp->get("jump-with-up", jump_with_up_kbd); + lisp::ListIterator iter(keymap_lisp); + while(iter.next()) { + if (iter.item() == "map") { + int key = -1; + std::string control; + const lisp::Lisp* map = iter.lisp(); + map->get("key", key); + map->get("control", control); + + int i = 0; + for(i = 0; Controller::controlNames[i] != 0; ++i) { + if (control == Controller::controlNames[i]) + break; + } + if (Controller::controlNames[i] == 0) { + log_info << "Invalid control '" << control << "' in keymap" << std::endl; + continue; + } + keymap[static_cast(key)] = static_cast(i); + } + } +} + +void +KeyboardManager::write(Writer& writer) +{ + writer.write("jump-with-up", jump_with_up_kbd); + for(KeyMap::iterator i = keymap.begin(); i != keymap.end(); ++i) { + writer.start_list("map"); + writer.write("key", (int) i->first); + writer.write("control", Controller::controlNames[i->second]); + writer.end_list("map"); + } +} + +/* EOF */ diff --git a/src/control/keyboard_manager.hpp b/src/control/keyboard_manager.hpp new file mode 100644 index 000000000..15d804352 --- /dev/null +++ b/src/control/keyboard_manager.hpp @@ -0,0 +1,65 @@ +// SuperTux +// Copyright (C) 2006 Matthias Braun , +// 2007-2014 Ingo Ruhnke +// +// 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 . + +#ifndef HEADER_SUPERTUX_CONTROL_KEYBOARD_MANAGER_HPP +#define HEADER_SUPERTUX_CONTROL_KEYBOARD_MANAGER_HPP + +#include + +#include "SDL.h" + +#include "control/controller.hpp" +#include "util/reader_fwd.hpp" +#include "util/writer_fwd.hpp" + +class JoystickKeyboardController; + +class KeyboardManager final +{ +private: + friend class KeyboardMenu; + typedef std::map KeyMap; + +public: + KeyboardManager(JoystickKeyboardController* parent); + ~KeyboardManager(); + + void process_key_event(const SDL_KeyboardEvent& event); + void process_text_input_event(const SDL_TextInputEvent& event); + void process_console_key_event(const SDL_KeyboardEvent& event); + void process_menu_key_event(const SDL_KeyboardEvent& event); + + SDL_Keycode reversemap_key(Controller::Control c); + void bind_key(SDL_Keycode key, Controller::Control c); + + void read(const lisp::Lisp* keymap_lisp); + void write(Writer& writer); + +private: + JoystickKeyboardController* m_parent; + KeyMap keymap; + bool jump_with_up_kbd; + int wait_for_key; + +private: + KeyboardManager(const KeyboardManager&) = delete; + KeyboardManager& operator=(const KeyboardManager&) = delete; +}; + +#endif + +/* EOF */ diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp index c2917e7c6..55415ee4b 100644 --- a/src/gui/menu.cpp +++ b/src/gui/menu.cpp @@ -227,7 +227,7 @@ Menu::update() effect_progress = 0.0f; } - Controller *controller = g_jk_controller->get_main_controller(); + Controller* controller = g_jk_controller->get_controller(); /** check main input controller... */ if(controller->pressed(Controller::UP)) { menuaction = MENU_ACTION_UP; diff --git a/src/object/player.cpp b/src/object/player.cpp index 46c4423ff..ab6c51939 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -159,7 +159,7 @@ Player::Player(PlayerStatus* _player_status, const std::string& name) : climbing(0) { this->name = name; - controller = g_jk_controller->get_main_controller(); + controller = g_jk_controller->get_controller(); scripting_controller.reset(new CodeController()); // if/when we have complete penny gfx, we can // load those instead of Tux's sprite in the diff --git a/src/supertux/game_session.cpp b/src/supertux/game_session.cpp index 393d6e734..2e76fa4e6 100644 --- a/src/supertux/game_session.cpp +++ b/src/supertux/game_session.cpp @@ -349,7 +349,7 @@ GameSession::process_events() // save input for demo? if(capture_demo_stream != 0) { - Controller *controller = g_jk_controller->get_main_controller(); + Controller *controller = g_jk_controller->get_controller(); capture_demo_stream ->put(controller->hold(Controller::LEFT)); capture_demo_stream ->put(controller->hold(Controller::RIGHT)); capture_demo_stream ->put(controller->hold(Controller::UP)); @@ -436,7 +436,7 @@ void GameSession::update(float elapsed_time) { // handle controller - if(g_jk_controller->get_main_controller()->pressed(Controller::PAUSE_MENU)) + if(g_jk_controller->get_controller()->pressed(Controller::PAUSE_MENU)) on_escape_press(); process_events(); diff --git a/src/supertux/levelintro.cpp b/src/supertux/levelintro.cpp index f81d6539c..8b3d3ed95 100644 --- a/src/supertux/levelintro.cpp +++ b/src/supertux/levelintro.cpp @@ -53,7 +53,7 @@ LevelIntro::setup() void LevelIntro::update(float elapsed_time) { - Controller *controller = g_jk_controller->get_main_controller(); + Controller *controller = g_jk_controller->get_controller(); // Check if it's time to exit the screen if(controller->pressed(Controller::JUMP) diff --git a/src/supertux/menu/keyboard_menu.cpp b/src/supertux/menu/keyboard_menu.cpp index bbdd1cfc9..e75b59d90 100644 --- a/src/supertux/menu/keyboard_menu.cpp +++ b/src/supertux/menu/keyboard_menu.cpp @@ -17,9 +17,10 @@ #include "supertux/menu/keyboard_menu.hpp" -#include "util/gettext.hpp" +#include "control/keyboard_manager.hpp" #include "supertux/gameconfig.hpp" #include "supertux/globals.hpp" +#include "util/gettext.hpp" KeyboardMenu::KeyboardMenu(JoystickKeyboardController* _controller) : controller(_controller) @@ -39,7 +40,7 @@ KeyboardMenu::KeyboardMenu(JoystickKeyboardController* _controller) : if (g_config->console_enabled) { add_controlfield(Controller::CONSOLE, _("Console")); } - add_toggle(Controller::CONTROLCOUNT, _("Jump with Up"), controller->jump_with_up_kbd); + add_toggle(Controller::CONTROLCOUNT, _("Jump with Up"), controller->keyboard_manager->jump_with_up_kbd); add_hl(); add_back(_("Back")); update(); @@ -88,9 +89,9 @@ KeyboardMenu::menu_action(MenuItem* item) { if(item->id >= 0 && item->id < Controller::CONTROLCOUNT){ item->change_input(_("Press Key")); - controller->wait_for_key = item->id; + controller->keyboard_manager->wait_for_key = item->id; } else if( item->id == Controller::CONTROLCOUNT) { - controller->jump_with_up_kbd = item->toggled; + controller->keyboard_manager->jump_with_up_kbd = item->toggled; } } @@ -98,31 +99,34 @@ void KeyboardMenu::update() { // update menu + + auto& kbd_mgr = controller->keyboard_manager; + get_item_by_id((int) Controller::UP).change_input(get_key_name( - controller->reversemap_key(Controller::UP))); + kbd_mgr->reversemap_key(Controller::UP))); get_item_by_id((int) Controller::DOWN).change_input(get_key_name( - controller->reversemap_key(Controller::DOWN))); + kbd_mgr->reversemap_key(Controller::DOWN))); get_item_by_id((int) Controller::LEFT).change_input(get_key_name( - controller->reversemap_key(Controller::LEFT))); + kbd_mgr->reversemap_key(Controller::LEFT))); get_item_by_id((int) Controller::RIGHT).change_input(get_key_name( - controller->reversemap_key(Controller::RIGHT))); + kbd_mgr->reversemap_key(Controller::RIGHT))); get_item_by_id((int) Controller::JUMP).change_input(get_key_name( - controller->reversemap_key(Controller::JUMP))); + kbd_mgr->reversemap_key(Controller::JUMP))); get_item_by_id((int) Controller::ACTION).change_input(get_key_name( - controller->reversemap_key(Controller::ACTION))); + kbd_mgr->reversemap_key(Controller::ACTION))); get_item_by_id((int) Controller::PEEK_LEFT).change_input(get_key_name( - controller->reversemap_key(Controller::PEEK_LEFT))); + kbd_mgr->reversemap_key(Controller::PEEK_LEFT))); get_item_by_id((int) Controller::PEEK_RIGHT).change_input(get_key_name( - controller->reversemap_key(Controller::PEEK_RIGHT))); + kbd_mgr->reversemap_key(Controller::PEEK_RIGHT))); get_item_by_id((int) Controller::PEEK_UP).change_input(get_key_name( - controller->reversemap_key(Controller::PEEK_UP))); + kbd_mgr->reversemap_key(Controller::PEEK_UP))); get_item_by_id((int) Controller::PEEK_DOWN).change_input(get_key_name( - controller->reversemap_key(Controller::PEEK_DOWN))); + kbd_mgr->reversemap_key(Controller::PEEK_DOWN))); if (g_config->console_enabled) { get_item_by_id((int) Controller::CONSOLE).change_input(get_key_name( - controller->reversemap_key(Controller::CONSOLE))); + kbd_mgr->reversemap_key(Controller::CONSOLE))); } - get_item_by_id(Controller::CONTROLCOUNT).toggled = controller->jump_with_up_kbd; + get_item_by_id(Controller::CONTROLCOUNT).toggled = kbd_mgr->jump_with_up_kbd; } /* EOF */ diff --git a/src/supertux/textscroller.cpp b/src/supertux/textscroller.cpp index be8fca532..2a023fb22 100644 --- a/src/supertux/textscroller.cpp +++ b/src/supertux/textscroller.cpp @@ -93,7 +93,7 @@ TextScroller::setup() void TextScroller::update(float elapsed_time) { - Controller *controller = g_jk_controller->get_main_controller(); + Controller *controller = g_jk_controller->get_controller(); if(controller->hold(Controller::UP)) { speed = -defaultspeed*5; } else if(controller->hold(Controller::DOWN)) { diff --git a/src/worldmap/tux.cpp b/src/worldmap/tux.cpp index 1e6ba7b20..85c4e784a 100644 --- a/src/worldmap/tux.cpp +++ b/src/worldmap/tux.cpp @@ -290,7 +290,7 @@ Tux::tryContinueWalking(float elapsed_time) void Tux::updateInputDirection() { - Controller *controller = g_jk_controller->get_main_controller(); + Controller* controller = g_jk_controller->get_controller(); if(controller->hold(Controller::UP)) input_direction = D_NORTH; else if(controller->hold(Controller::DOWN)) diff --git a/src/worldmap/worldmap.cpp b/src/worldmap/worldmap.cpp index dc2203b06..f30241bbc 100644 --- a/src/worldmap/worldmap.cpp +++ b/src/worldmap/worldmap.cpp @@ -648,7 +648,7 @@ WorldMap::update(float delta) } // handle input - Controller *controller = g_jk_controller->get_main_controller(); + Controller *controller = g_jk_controller->get_controller(); bool enter_level = false; if(controller->pressed(Controller::ACTION) || controller->pressed(Controller::JUMP)