From 36cce4e79c214c097cdda30f262aa8343bc6a07f Mon Sep 17 00:00:00 2001 From: Lendemor Date: Thu, 16 Feb 2017 16:58:42 +0100 Subject: [PATCH] compatibility with new version of input --- src/defaultkeysmap.cpp | 6 --- src/defaultkeysmap.h | 69 ++++++++++++++++++++----------- src/engine.cpp | 12 +++--- src/scene/gui/buttonnode.cpp | 2 +- src/scene/gui/textinputnode.cpp | 4 +- src/scene/playercharacternode.cpp | 14 +++---- src/scene/trackballcameranode.cpp | 6 +-- src/test/potator.cpp | 8 ++-- 8 files changed, 69 insertions(+), 52 deletions(-) delete mode 100644 src/defaultkeysmap.cpp diff --git a/src/defaultkeysmap.cpp b/src/defaultkeysmap.cpp deleted file mode 100644 index 64dc37f..0000000 --- a/src/defaultkeysmap.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "defaultkeysmap.h" - -//DefaultKeysMap::DefaultKeysMap() -//{ - -//} diff --git a/src/defaultkeysmap.h b/src/defaultkeysmap.h index 53df63f..b22dc1f 100644 --- a/src/defaultkeysmap.h +++ b/src/defaultkeysmap.h @@ -12,37 +12,60 @@ public: EXIT_GAME,LAST_DEFAULT_ACTION}; DefaultKeysMap(){ - keys.push_back( {MAIN_ACTION, sf::Keyboard::KeyCount + sf::Mouse::Left, IKeysMap::PRESSED} ); - keys.push_back( {SECONDARY_ACTION, sf::Keyboard::KeyCount + sf::Mouse::Right, IKeysMap::PRESSED} ); - keys.push_back( {TERTIARY_ACTION, sf::Keyboard::KeyCount + sf::Mouse::Middle, IKeysMap::PRESSED} ); - keys.push_back( {MOVE_FORWARD, sf::Keyboard::Z, IKeysMap::HOLD} ); - keys.push_back( {MOVE_BACKWARD, sf::Keyboard::S, IKeysMap::HOLD} ); - keys.push_back( {STRAFE_LEFT, sf::Keyboard::Q, IKeysMap::HOLD} ); - keys.push_back( {STRAFE_RIGHT, sf::Keyboard::D, IKeysMap::HOLD} ); - keys.push_back( {JUMP, sf::Keyboard::Space, IKeysMap::PRESSED} ); - keys.push_back( {TOGGLE_NOCLIP, sf::Keyboard::G, IKeysMap::PRESSED} ); - keys.push_back( {TOGGLE_PHYSICS_DEBUG, sf::Keyboard::P, IKeysMap::PRESSED} ); - keys.push_back( {TOGGLE_CONSOLE, sf::Keyboard::F3, IKeysMap::PRESSED} ); - keys.push_back( {MOVE_CURSOR_LEFT, sf::Keyboard::Left, IKeysMap::PRESSED} ); - keys.push_back( {MOVE_CURSOR_RIGHT, sf::Keyboard::Right, IKeysMap::PRESSED} ); - keys.push_back( {PLOP_TEST, sf::Keyboard::F7, IKeysMap::PRESSED} ); - keys.push_back( {CLEAR_CONSOLE, sf::Keyboard::F2, IKeysMap::PRESSED} ); - keys.push_back( {EXIT_GAME, sf::Keyboard::Escape, IKeysMap::PRESSED} ); - keys.push_back( {LEFT_CLICK, sf::Keyboard::KeyCount + sf::Mouse::Left, IKeysMap::PRESSED} ); + keys.push_back( {{MAIN_ACTION,input::MOUSE}, sf::Mouse::Left, IKeysMap::PRESSED} ); + keys.push_back( {{SECONDARY_ACTION,input::MOUSE}, sf::Mouse::Right, IKeysMap::PRESSED} ); + keys.push_back( {{TERTIARY_ACTION,input::MOUSE}, sf::Mouse::Middle, IKeysMap::PRESSED} ); + keys.push_back( {{MOVE_FORWARD,input::KEYBOARD}, sf::Keyboard::Z, IKeysMap::HOLD} ); + keys.push_back( {{MOVE_BACKWARD,input::KEYBOARD}, sf::Keyboard::S, IKeysMap::HOLD} ); + keys.push_back( {{STRAFE_LEFT,input::KEYBOARD}, sf::Keyboard::Q, IKeysMap::HOLD} ); + keys.push_back( {{STRAFE_RIGHT,input::KEYBOARD}, sf::Keyboard::D, IKeysMap::HOLD} ); + keys.push_back( {{JUMP,input::KEYBOARD}, sf::Keyboard::Space, IKeysMap::PRESSED} ); + keys.push_back( {{TOGGLE_NOCLIP,input::KEYBOARD}, sf::Keyboard::G, IKeysMap::PRESSED} ); + keys.push_back( {{TOGGLE_PHYSICS_DEBUG,input::KEYBOARD},sf::Keyboard::P, IKeysMap::PRESSED} ); + keys.push_back( {{TOGGLE_CONSOLE,input::KEYBOARD}, sf::Keyboard::F3, IKeysMap::PRESSED} ); + keys.push_back( {{MOVE_CURSOR_LEFT,input::KEYBOARD}, sf::Keyboard::Left, IKeysMap::PRESSED} ); + keys.push_back( {{MOVE_CURSOR_RIGHT,input::KEYBOARD}, sf::Keyboard::Right, IKeysMap::PRESSED} ); + keys.push_back( {{PLOP_TEST,input::KEYBOARD}, sf::Keyboard::F7, IKeysMap::PRESSED} ); + keys.push_back( {{CLEAR_CONSOLE,input::KEYBOARD}, sf::Keyboard::F2, IKeysMap::PRESSED} ); + keys.push_back( {{EXIT_GAME,input::KEYBOARD}, sf::Keyboard::Escape,IKeysMap::PRESSED} ); + keys.push_back( {{LEFT_CLICK,input::MOUSE}, sf::Mouse::Left, IKeysMap::PRESSED} ); } - static std::vector getDefaultContext() + static std::vector getDefaultContext() { - return {MAIN_ACTION, SECONDARY_ACTION, TERTIARY_ACTION, MOVE_FORWARD, MOVE_BACKWARD, STRAFE_LEFT, STRAFE_RIGHT, JUMP, TOGGLE_NOCLIP, TOGGLE_PHYSICS_DEBUG, TOGGLE_CONSOLE, EXIT_GAME}; + return { + {MAIN_ACTION,input::MOUSE}, + {SECONDARY_ACTION,input::MOUSE}, + {TERTIARY_ACTION,input::MOUSE}, + {MOVE_FORWARD,input::KEYBOARD}, + {MOVE_BACKWARD,input::KEYBOARD}, + {STRAFE_LEFT,input::KEYBOARD}, + {STRAFE_RIGHT,input::KEYBOARD}, + {JUMP,input::KEYBOARD}, + {TOGGLE_NOCLIP,input::KEYBOARD}, + {TOGGLE_PHYSICS_DEBUG,input::KEYBOARD}, + {TOGGLE_CONSOLE,input::KEYBOARD}, + {EXIT_GAME,input::KEYBOARD} + }; } - static std::vector getShellContext() + static std::vector getShellContext() { - return {TOGGLE_CONSOLE,MOVE_CURSOR_LEFT,MOVE_CURSOR_RIGHT,PLOP_TEST,CLEAR_CONSOLE}; + return { + {TOGGLE_CONSOLE,input::KEYBOARD}, + {MOVE_CURSOR_LEFT,input::KEYBOARD}, + {MOVE_CURSOR_RIGHT,input::KEYBOARD}, + {PLOP_TEST,input::KEYBOARD}, + {CLEAR_CONSOLE,input::KEYBOARD} + }; } - static std::vector getMenuContext(){ - return {LEFT_CLICK,EXIT_GAME,TOGGLE_CONSOLE}; + static std::vector getMenuContext(){ + return { + {LEFT_CLICK,input::MOUSE}, + {EXIT_GAME,input::KEYBOARD}, + {TOGGLE_CONSOLE,input::KEYBOARD} + }; } }; diff --git a/src/engine.cpp b/src/engine.cpp index 50c6698..2d57bfd 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -202,23 +202,23 @@ void Engine::setShowMouseAction(int action) void Engine::checkSpecialInputs() { - for(int action : m_input->getActions()) + for(Action action : m_input->getActions()) { - if(action == -1) + if(action.action == NO_ACTION) continue; - if(action == m_togglePhysicsDebugAction) + if(action.action == m_togglePhysicsDebugAction) { if(m_physicsDebugNode == nullptr) enablePhysicsDebug(); else disablePhysicsDebug(); } - else if(action == m_toggleShellAction) + else if(action.action == m_toggleShellAction) m_sparrowshell->toggleShell(); - else if(action == m_exitGameAction) + else if(action.action == m_exitGameAction) m_running = false; - else if(action == m_showMouseAction) + else if(action.action == m_showMouseAction) toggleMouseVisibility(); } } diff --git a/src/scene/gui/buttonnode.cpp b/src/scene/gui/buttonnode.cpp index 4fd2e10..a7641d1 100644 --- a/src/scene/gui/buttonnode.cpp +++ b/src/scene/gui/buttonnode.cpp @@ -49,7 +49,7 @@ void ButtonNode::update() for (auto action : input->getActions()) { - if (action == m_action){ + if (action.action == m_action){ if (m_shape->hover(this->getPosition(),input->getPosition())) m_callback->exec(); } diff --git a/src/scene/gui/textinputnode.cpp b/src/scene/gui/textinputnode.cpp index 3613573..c839b36 100644 --- a/src/scene/gui/textinputnode.cpp +++ b/src/scene/gui/textinputnode.cpp @@ -36,13 +36,13 @@ void TextInputNode::update() auto input = getEngine().getInput(); for(auto action : input->getActions()){ - if (action == m_move_cursor_left){ + if (action.action == m_move_cursor_left){ if (m_cursor_pos > 0){ m_cursor_pos--; cursor_pos_updated=true; } } - else if(action == m_move_cursor_right){ + else if(action.action == m_move_cursor_right){ if(m_cursor_pos < m_text.length()){ m_cursor_pos++; cursor_pos_updated=true; diff --git a/src/scene/playercharacternode.cpp b/src/scene/playercharacternode.cpp index a36e94f..14d8c9c 100644 --- a/src/scene/playercharacternode.cpp +++ b/src/scene/playercharacternode.cpp @@ -118,19 +118,19 @@ void PlayerCharacterNode::update() int walk = 0; int strafe = 0; bool jump = false; - for(int action : input->getActions()) + for(Action action : input->getActions()) { - if(action == m_inputActions[FORWARD]) + if(action.action == m_inputActions[FORWARD]) ++walk; - else if(action == m_inputActions[BACKWARD]) + else if(action.action == m_inputActions[BACKWARD]) --walk; - else if(action == m_inputActions[STRAFE_LEFT]) + else if(action.action == m_inputActions[STRAFE_LEFT]) --strafe; - else if(action == m_inputActions[STRAFE_RIGHT]) + else if(action.action == m_inputActions[STRAFE_RIGHT]) ++strafe; - else if(action == m_inputActions[JUMP]) + else if(action.action == m_inputActions[JUMP]) jump = true; - else if(action == m_inputActions[TOGGLE_NOCLIP]) + else if(action.action == m_inputActions[TOGGLE_NOCLIP]) toggleNoClip(); } diff --git a/src/scene/trackballcameranode.cpp b/src/scene/trackballcameranode.cpp index 11500a9..3d4cc2b 100644 --- a/src/scene/trackballcameranode.cpp +++ b/src/scene/trackballcameranode.cpp @@ -9,11 +9,11 @@ TrackBallCameraNode::TrackBallCameraNode(Input *input) : void TrackBallCameraNode::update() { glm::vec2 diff = m_input->getDeltaPosition(); - for(int action : m_input->getActions()) + for(Action action : m_input->getActions()) { - if(action == m_action_move) + if(action.action == m_action_move) moveCamera(diff.x, diff.y); - else if(action == m_action_rotate) + else if(action.action == m_action_rotate) rotateCamera(diff.x, diff.y); } zoom(m_input->getDeltaVerticalScroll()*120.f); diff --git a/src/test/potator.cpp b/src/test/potator.cpp index 6c52d28..0963e47 100644 --- a/src/test/potator.cpp +++ b/src/test/potator.cpp @@ -167,13 +167,13 @@ void Potator::update() { GibGeneratorNode::update(); Input *input = getEngine().getInput(); - for(int action : input->getActions()) + for(Action action : input->getActions()) { - if(action == m_throwCubeAction) + if(action.action == m_throwCubeAction) throwCube(); - else if(action == m_throwSphereAction) + else if(action.action == m_throwSphereAction) throwSphere(); - else if(action == m_throwObjectAction) + else if(action.action == m_throwObjectAction) throwSword(); } }