From 8e19e96a9ebb0095bb352e987b071614b70a02ed Mon Sep 17 00:00:00 2001 From: Deve Date: Sun, 29 Dec 2019 00:04:45 +0100 Subject: [PATCH] Add easier way to change touch controls type --- .../online/network_ingame_dialog.stkgui | 2 + data/gui/dialogs/overworld_dialog.stkgui | 2 + data/gui/dialogs/race_paused_dialog.stkgui | 2 + .../dialogs/race_paused_dialog.cpp | 122 +++++++++++++++++- .../dialogs/race_paused_dialog.hpp | 4 + 5 files changed, 129 insertions(+), 3 deletions(-) diff --git a/data/gui/dialogs/online/network_ingame_dialog.stkgui b/data/gui/dialogs/online/network_ingame_dialog.stkgui index 2e7093ea4..793a6b0b1 100644 --- a/data/gui/dialogs/online/network_ingame_dialog.stkgui +++ b/data/gui/dialogs/online/network_ingame_dialog.stkgui @@ -14,6 +14,8 @@ + diff --git a/data/gui/dialogs/overworld_dialog.stkgui b/data/gui/dialogs/overworld_dialog.stkgui index 5b5d775b3..224ab2673 100644 --- a/data/gui/dialogs/overworld_dialog.stkgui +++ b/data/gui/dialogs/overworld_dialog.stkgui @@ -8,6 +8,8 @@ + diff --git a/data/gui/dialogs/race_paused_dialog.stkgui b/data/gui/dialogs/race_paused_dialog.stkgui index 6a9d46578..451d7102c 100644 --- a/data/gui/dialogs/race_paused_dialog.stkgui +++ b/data/gui/dialogs/race_paused_dialog.stkgui @@ -8,6 +8,8 @@ + diff --git a/src/states_screens/dialogs/race_paused_dialog.cpp b/src/states_screens/dialogs/race_paused_dialog.cpp index 97709b991..abecddfab 100644 --- a/src/states_screens/dialogs/race_paused_dialog.cpp +++ b/src/states_screens/dialogs/race_paused_dialog.cpp @@ -23,6 +23,7 @@ #include "audio/sfx_manager.hpp" #include "challenges/story_mode_timer.hpp" #include "config/user_config.hpp" +#include "graphics/irr_driver.hpp" #include "guiengine/emoji_keyboard.hpp" #include "guiengine/engine.hpp" #include "guiengine/scalable_font.hpp" @@ -132,6 +133,18 @@ RacePausedDialog::~RacePausedDialog() { World::getWorld()->scheduleUnpause(); } + + if (m_touch_controls != UserConfigParams::m_multitouch_controls) + { + UserConfigParams::m_multitouch_controls = m_touch_controls; + + if (World::getWorld() && World::getWorld()->getRaceGUI()) + { + World::getWorld()->getRaceGUI()->recreateMultitouchGUI(); + } + + user_config->saveConfig(); + } } // ~RacePausedDialog // ---------------------------------------------------------------------------- @@ -182,6 +195,8 @@ GUIEngine::EventPropagation { GUIEngine::RibbonWidget* choice_ribbon = getWidget("choiceribbon"); + GUIEngine::RibbonWidget* backbtn_ribbon = + getWidget("backbtnribbon"); if (eventSource == "send" && m_text_box) { @@ -198,9 +213,50 @@ GUIEngine::EventPropagation } else if (eventSource == "backbtnribbon") { - // unpausing is done in the destructor so nothing more to do here - ModalDialog::dismiss(); - return GUIEngine::EVENT_BLOCK; + const std::string& selection = + backbtn_ribbon->getSelectionIDString(PLAYER_ID_GAME_MASTER); + + if (selection == "backbtn") + { + // unpausing is done in the destructor so nothing more to do here + ModalDialog::dismiss(); + return GUIEngine::EVENT_BLOCK; + } + else if (selection == "touch_device") + { + IrrlichtDevice* irrlicht_device = irr_driver->getDevice(); + assert(irrlicht_device != NULL); + bool accelerometer_available = irrlicht_device->isAccelerometerAvailable(); + bool gyroscope_available = irrlicht_device->isGyroscopeAvailable() && accelerometer_available; + + if (m_touch_controls == MULTITOUCH_CONTROLS_STEERING_WHEEL) + { + m_touch_controls = MULTITOUCH_CONTROLS_ACCELEROMETER; + } + else if (m_touch_controls == MULTITOUCH_CONTROLS_ACCELEROMETER) + { + m_touch_controls = MULTITOUCH_CONTROLS_GYROSCOPE; + } + else if (m_touch_controls == MULTITOUCH_CONTROLS_GYROSCOPE) + { + m_touch_controls = MULTITOUCH_CONTROLS_STEERING_WHEEL; + } + + if (m_touch_controls == MULTITOUCH_CONTROLS_ACCELEROMETER && + !accelerometer_available) + { + m_touch_controls = MULTITOUCH_CONTROLS_STEERING_WHEEL; + } + else if (m_touch_controls == MULTITOUCH_CONTROLS_GYROSCOPE && + !gyroscope_available) + { + m_touch_controls = MULTITOUCH_CONTROLS_STEERING_WHEEL; + } + + updateTouchDeviceIcon(); + + return GUIEngine::EVENT_BLOCK; + } } else if (eventSource == "choiceribbon") { @@ -331,8 +387,36 @@ void RacePausedDialog::beforeAddingWidgets() m_text_box = getWidget("chat"); else m_text_box = NULL; + + bool has_multitouch_gui = false; + + if (World::getWorld() && World::getWorld()->getRaceGUI() && + World::getWorld()->getRaceGUI()->getMultitouchGUI()) + { + has_multitouch_gui = true; + } + + IrrlichtDevice* irrlicht_device = irr_driver->getDevice(); + assert(irrlicht_device != NULL); + bool accelerometer_available = irrlicht_device->isAccelerometerAvailable(); + + if (!has_multitouch_gui || !accelerometer_available) + { + GUIEngine::RibbonWidget* backbtn_ribbon = + getWidget("backbtnribbon"); + backbtn_ribbon->removeChildNamed("touch_device"); + } + } // beforeAddingWidgets +// ---------------------------------------------------------------------------- +void RacePausedDialog::init() +{ + m_touch_controls = UserConfigParams::m_multitouch_controls; + updateTouchDeviceIcon(); + +} // init + // ---------------------------------------------------------------------------- bool RacePausedDialog::onEnterPressed(const irr::core::stringw& text) { @@ -352,3 +436,35 @@ bool RacePausedDialog::onEnterPressed(const irr::core::stringw& text) m_self_destroy = true; return true; } // onEnterPressed + +void RacePausedDialog::updateTouchDeviceIcon() +{ + GUIEngine::RibbonWidget* backbtn_ribbon = + getWidget("backbtnribbon"); + GUIEngine::IconButtonWidget* widget = (IconButtonWidget*)backbtn_ribbon-> + findWidgetNamed("touch_device"); + if (!widget) + return; + + switch (m_touch_controls) + { + case MULTITOUCH_CONTROLS_UNDEFINED: + case MULTITOUCH_CONTROLS_STEERING_WHEEL: + widget->setLabel(_("Steering wheel")); + widget->setImage(irr_driver->getTexture(FileManager::GUI_ICON, + "android/steering_wheel.png")); + break; + case MULTITOUCH_CONTROLS_ACCELEROMETER: + widget->setLabel(_("Accelerometer")); + widget->setImage(irr_driver->getTexture(FileManager::GUI_ICON, + "android/accelerator.png")); + break; + case MULTITOUCH_CONTROLS_GYROSCOPE: + widget->setLabel(_("Gyroscope")); + widget->setImage(irr_driver->getTexture(FileManager::GUI_ICON, + "android/gyroscope_icon.png")); + break; + default: + break; + } +} diff --git a/src/states_screens/dialogs/race_paused_dialog.hpp b/src/states_screens/dialogs/race_paused_dialog.hpp index 81cfd22a3..8b5e0547f 100644 --- a/src/states_screens/dialogs/race_paused_dialog.hpp +++ b/src/states_screens/dialogs/race_paused_dialog.hpp @@ -38,11 +38,14 @@ class RacePausedDialog : public GUIEngine::ModalDialog, private: bool m_self_destroy; bool m_from_overworld; + int m_touch_controls; GUIEngine::TextBoxWidget* m_text_box; virtual void onTextUpdated() OVERRIDE {} virtual bool onEnterPressed(const irr::core::stringw& text) OVERRIDE; + + void updateTouchDeviceIcon(); protected: virtual void loadedFromFile() OVERRIDE; @@ -57,6 +60,7 @@ public: GUIEngine::EventPropagation processEvent(const std::string& eventSource) OVERRIDE; virtual void beforeAddingWidgets() OVERRIDE; + virtual void init() OVERRIDE; // ------------------------------------------------------------------------ virtual void onUpdate(float dt) OVERRIDE {