From 2c79b02088a099e1112ef847622fff13df66c0e1 Mon Sep 17 00:00:00 2001 From: Deve Date: Wed, 19 Sep 2018 22:06:24 +0200 Subject: [PATCH] Make pause button working when watching ghost replay --- src/input/multitouch_device.cpp | 43 +++++++++++++++++++-------------- src/input/multitouch_device.hpp | 1 + 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/input/multitouch_device.cpp b/src/input/multitouch_device.cpp index c62c52265..decef111a 100644 --- a/src/input/multitouch_device.cpp +++ b/src/input/multitouch_device.cpp @@ -388,25 +388,26 @@ void MultitouchDevice::updateAxisY(float value) */ void MultitouchDevice::handleControls(MultitouchButton* button) { - if (m_controller == NULL) + if (!isGameRunning()) return; - - if (button->type == MultitouchButtonType::BUTTON_STEERING) - { - updateAxisX(button->axis_x); - updateAxisY(button->axis_y); - } - else if (button->type == MultitouchButtonType::BUTTON_UP_DOWN) - { - updateAxisY(button->axis_y); - } - else if (button->type == MultitouchButtonType::BUTTON_ESCAPE) + + if (button->type == MultitouchButtonType::BUTTON_ESCAPE) { StateManager::get()->escapePressed(); } - else + + if (m_controller != NULL && !race_manager->isWatchingReplay()) { - if (button->action != PA_BEFORE_FIRST) + if (button->type == MultitouchButtonType::BUTTON_STEERING) + { + updateAxisX(button->axis_x); + updateAxisY(button->axis_y); + } + else if (button->type == MultitouchButtonType::BUTTON_UP_DOWN) + { + updateAxisY(button->axis_y); + } + else if (button->action != PA_BEFORE_FIRST) { int value = button->pressed ? Input::MAX_VALUE : 0; m_controller->action(button->action, value); @@ -416,6 +417,15 @@ void MultitouchDevice::handleControls(MultitouchButton* button) // ---------------------------------------------------------------------------- +bool MultitouchDevice::isGameRunning() +{ + return StateManager::get()->getGameState() == GUIEngine::GAME && + !GUIEngine::ModalDialog::isADialogActive() && + !GUIEngine::ScreenKeyboard::isActive(); +} + +// ---------------------------------------------------------------------------- + void MultitouchDevice::updateController() { if (m_player == NULL) @@ -427,10 +437,7 @@ void MultitouchDevice::updateController() // Handle multitouch events only when race is running. It avoids to process // it when pause dialog is active during the race. And there is no reason // to use it for GUI navigation. - if (StateManager::get()->getGameState() != GUIEngine::GAME || - GUIEngine::ModalDialog::isADialogActive() || - GUIEngine::ScreenKeyboard::isActive() || - race_manager->isWatchingReplay()) + if (!isGameRunning()) { m_controller = NULL; return; diff --git a/src/input/multitouch_device.hpp b/src/input/multitouch_device.hpp index a7abf779e..fee62e714 100644 --- a/src/input/multitouch_device.hpp +++ b/src/input/multitouch_device.hpp @@ -94,6 +94,7 @@ private: float getSteeringFactor(float value); void handleControls(MultitouchButton* button); + bool isGameRunning(); public: /** The array that contains data for all multitouch input events */