From b33e6dbcad3d15daf9f48ce1edb648be2ba91707 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 17 Oct 2016 22:32:52 +0200 Subject: [PATCH] Allow picking up items with a single touch (#29) * Allow handling middle click events * Send middle click events when touch starts (Android) * Punch objects when middle clicking (Touch only, combination with previous change) --- src/client/inputhandler.h | 13 +++++++++++++ src/game.cpp | 13 +++++++++++-- src/game.h | 2 ++ src/touchscreengui.cpp | 17 +++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/client/inputhandler.h b/src/client/inputhandler.h index 378730190..0e64e44f5 100644 --- a/src/client/inputhandler.h +++ b/src/client/inputhandler.h @@ -215,6 +215,14 @@ public: { return m_receiver->left_active; } + virtual bool getMiddleState() + { + return m_receiver->middle_active; + } + virtual void resetMiddleState() + { + m_receiver->middle_active = false; + } virtual bool getRightState() { return m_receiver->right_active; @@ -303,6 +311,11 @@ public: { return leftdown; } + virtual bool getMiddleState() + { + return false; + } + virtual void resetMiddleState() {} virtual bool getRightState() { return rightdown; diff --git a/src/game.cpp b/src/game.cpp index ab99f7dfb..5e6a0a890 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -3670,6 +3670,8 @@ void Game::processPlayerInteraction(GameRunData *runData, input->resetLeftReleased(); input->resetRightReleased(); + + input->resetMiddleState(); } @@ -3792,7 +3794,14 @@ void Game::handlePointingAtObject(GameRunData *runData, runData->selected_object->debugInfoText())); } - if (input->getLeftState()) { +#ifdef HAVE_TOUCHSCREENGUI + // Interact with object on single touch (touchscreengui.cpp send this event) + bool middle_state = input->getMiddleState(); +#else + const bool middle_state = false; +#endif + + if (input->getLeftState() || middle_state) { bool do_punch = false; bool do_punch_damage = false; @@ -3802,7 +3811,7 @@ void Game::handlePointingAtObject(GameRunData *runData, runData->object_hit_delay_timer = object_hit_delay; } - if (input->getLeftClicked()) + if (input->getLeftClicked() || middle_state) do_punch = true; if (do_punch) { diff --git a/src/game.h b/src/game.h index 6f1fea3af..78104cb1a 100644 --- a/src/game.h +++ b/src/game.h @@ -114,6 +114,8 @@ public: virtual void setMousePos(s32 x, s32 y) = 0; virtual bool getLeftState() = 0; + virtual bool getMiddleState() = 0; + virtual void resetMiddleState() = 0; // TODO: handle middle button like all others virtual bool getRightState() = 0; virtual bool getLeftClicked() = 0; diff --git a/src/touchscreengui.cpp b/src/touchscreengui.cpp index 996fcf4fa..c96a43eeb 100644 --- a/src/touchscreengui.cpp +++ b/src/touchscreengui.cpp @@ -611,6 +611,23 @@ void TouchScreenGUI::translateEvent(const SEvent &event) m_move_downtime = getTimeMs(); m_move_downlocation = v2s32(event.TouchInput.X, event.TouchInput.Y); m_move_sent_as_mouse_event = false; + + // update shootline (in case the game handles the event we send below) + m_shootline = m_device + ->getSceneManager() + ->getSceneCollisionManager() + ->getRayFromScreenCoordinates(m_move_downlocation); + + // send a middle click event so the game can handle single touches + SEvent *translated = new SEvent; + memset(translated, 0, sizeof(SEvent)); + translated->EventType = EET_MOUSE_INPUT_EVENT; + translated->MouseInput.X = m_move_downlocation.X; + translated->MouseInput.Y = m_move_downlocation.Y; + translated->MouseInput.ButtonStates = EMBSM_MIDDLE; // << important! + translated->MouseInput.Event = EMIE_MMOUSE_LEFT_UP; + m_receiver->OnEvent(*translated); + delete translated; } }