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)
This commit is contained in:
parent
5957cd3ca1
commit
b33e6dbcad
@ -215,6 +215,14 @@ public:
|
|||||||
{
|
{
|
||||||
return m_receiver->left_active;
|
return m_receiver->left_active;
|
||||||
}
|
}
|
||||||
|
virtual bool getMiddleState()
|
||||||
|
{
|
||||||
|
return m_receiver->middle_active;
|
||||||
|
}
|
||||||
|
virtual void resetMiddleState()
|
||||||
|
{
|
||||||
|
m_receiver->middle_active = false;
|
||||||
|
}
|
||||||
virtual bool getRightState()
|
virtual bool getRightState()
|
||||||
{
|
{
|
||||||
return m_receiver->right_active;
|
return m_receiver->right_active;
|
||||||
@ -303,6 +311,11 @@ public:
|
|||||||
{
|
{
|
||||||
return leftdown;
|
return leftdown;
|
||||||
}
|
}
|
||||||
|
virtual bool getMiddleState()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
virtual void resetMiddleState() {}
|
||||||
virtual bool getRightState()
|
virtual bool getRightState()
|
||||||
{
|
{
|
||||||
return rightdown;
|
return rightdown;
|
||||||
|
13
src/game.cpp
13
src/game.cpp
@ -3670,6 +3670,8 @@ void Game::processPlayerInteraction(GameRunData *runData,
|
|||||||
|
|
||||||
input->resetLeftReleased();
|
input->resetLeftReleased();
|
||||||
input->resetRightReleased();
|
input->resetRightReleased();
|
||||||
|
|
||||||
|
input->resetMiddleState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -3792,7 +3794,14 @@ void Game::handlePointingAtObject(GameRunData *runData,
|
|||||||
runData->selected_object->debugInfoText()));
|
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 = false;
|
||||||
bool do_punch_damage = false;
|
bool do_punch_damage = false;
|
||||||
|
|
||||||
@ -3802,7 +3811,7 @@ void Game::handlePointingAtObject(GameRunData *runData,
|
|||||||
runData->object_hit_delay_timer = object_hit_delay;
|
runData->object_hit_delay_timer = object_hit_delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input->getLeftClicked())
|
if (input->getLeftClicked() || middle_state)
|
||||||
do_punch = true;
|
do_punch = true;
|
||||||
|
|
||||||
if (do_punch) {
|
if (do_punch) {
|
||||||
|
@ -114,6 +114,8 @@ public:
|
|||||||
virtual void setMousePos(s32 x, s32 y) = 0;
|
virtual void setMousePos(s32 x, s32 y) = 0;
|
||||||
|
|
||||||
virtual bool getLeftState() = 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 getRightState() = 0;
|
||||||
|
|
||||||
virtual bool getLeftClicked() = 0;
|
virtual bool getLeftClicked() = 0;
|
||||||
|
@ -611,6 +611,23 @@ void TouchScreenGUI::translateEvent(const SEvent &event)
|
|||||||
m_move_downtime = getTimeMs();
|
m_move_downtime = getTimeMs();
|
||||||
m_move_downlocation = v2s32(event.TouchInput.X, event.TouchInput.Y);
|
m_move_downlocation = v2s32(event.TouchInput.X, event.TouchInput.Y);
|
||||||
m_move_sent_as_mouse_event = false;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user