From 082661db651e55164d87e769adf397e7fc655e6d Mon Sep 17 00:00:00 2001 From: Deve Date: Tue, 20 Dec 2016 22:44:36 +0100 Subject: [PATCH] Add a possibility to change touch device settings in GUI --- data/gui/multitouch_settings.stkgui | 52 ++++++++ .../dialogs/multitouch_settings_dialog.cpp | 112 ++++++++++++++++++ .../dialogs/multitouch_settings_dialog.hpp | 46 +++++++ src/states_screens/options_screen_input.cpp | 25 +++- 4 files changed, 232 insertions(+), 3 deletions(-) create mode 100644 data/gui/multitouch_settings.stkgui create mode 100644 src/states_screens/dialogs/multitouch_settings_dialog.cpp create mode 100644 src/states_screens/dialogs/multitouch_settings_dialog.hpp diff --git a/data/gui/multitouch_settings.stkgui b/data/gui/multitouch_settings.stkgui new file mode 100644 index 000000000..77e05cd40 --- /dev/null +++ b/data/gui/multitouch_settings.stkgui @@ -0,0 +1,52 @@ + + +
+
+ + + +
+
diff --git a/src/states_screens/dialogs/multitouch_settings_dialog.cpp b/src/states_screens/dialogs/multitouch_settings_dialog.cpp new file mode 100644 index 000000000..f163b5614 --- /dev/null +++ b/src/states_screens/dialogs/multitouch_settings_dialog.cpp @@ -0,0 +1,112 @@ +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2014-2015 SuperTuxKart-Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include "states_screens/dialogs/multitouch_settings_dialog.hpp" + +#include "config/user_config.hpp" +#include "guiengine/widgets/spinner_widget.hpp" +#include "utils/translation.hpp" + +#include + + +using namespace GUIEngine; +using namespace irr; +using namespace irr::core; +using namespace irr::gui; + +// ----------------------------------------------------------------------------- + +MultitouchSettingsDialog::MultitouchSettingsDialog(const float w, const float h) + : ModalDialog(w, h) +{ + loadFromFile("multitouch_settings.stkgui"); +} + +// ----------------------------------------------------------------------------- + +MultitouchSettingsDialog::~MultitouchSettingsDialog() +{ +} + +// ----------------------------------------------------------------------------- + +void MultitouchSettingsDialog::beforeAddingWidgets() +{ + updateValues(); +} + +// ----------------------------------------------------------------------------- + +GUIEngine::EventPropagation MultitouchSettingsDialog::processEvent( + const std::string& eventSource) +{ + if (eventSource == "close") + { + SpinnerWidget* scale = getWidget("scale"); + assert(scale != NULL); + UserConfigParams::m_multitouch_scale = scale->getValue() / 100.0f; + + SpinnerWidget* deadzone_edge = getWidget("deadzone_edge"); + assert(deadzone_edge != NULL); + UserConfigParams::m_multitouch_deadzone_edge = + deadzone_edge->getValue() / 100.0f; + + SpinnerWidget* deadzone_center = getWidget("deadzone_center"); + assert(deadzone_center != NULL); + UserConfigParams::m_multitouch_deadzone_center = + deadzone_center->getValue() / 100.0f; + + user_config->saveConfig(); + + ModalDialog::dismiss(); + return GUIEngine::EVENT_BLOCK; + } + else if (eventSource == "restore") + { + UserConfigParams::m_multitouch_scale.revertToDefaults(); + UserConfigParams::m_multitouch_deadzone_edge.revertToDefaults(); + UserConfigParams::m_multitouch_deadzone_center.revertToDefaults(); + + updateValues(); + + return GUIEngine::EVENT_BLOCK; + } + + return GUIEngine::EVENT_LET; +} // processEvent + +// ----------------------------------------------------------------------------- + +void MultitouchSettingsDialog::updateValues() +{ + SpinnerWidget* scale = getWidget("scale"); + assert(scale != NULL); + scale->setValue((int)(UserConfigParams::m_multitouch_scale * 100.0f)); + + SpinnerWidget* deadzone_edge = getWidget("deadzone_edge"); + assert(deadzone_edge != NULL); + deadzone_edge->setValue( + (int)(UserConfigParams::m_multitouch_deadzone_edge * 100.0f)); + + SpinnerWidget* deadzone_center = getWidget("deadzone_center"); + assert(deadzone_center != NULL); + deadzone_center->setValue( + (int)(UserConfigParams::m_multitouch_deadzone_center * 100.0f)); +} + +// ----------------------------------------------------------------------------- diff --git a/src/states_screens/dialogs/multitouch_settings_dialog.hpp b/src/states_screens/dialogs/multitouch_settings_dialog.hpp new file mode 100644 index 000000000..0bc4c485a --- /dev/null +++ b/src/states_screens/dialogs/multitouch_settings_dialog.hpp @@ -0,0 +1,46 @@ +// SuperTuxKart - a fun racing game with go-kart +// Copyright (C) 2014-2015 SuperTuxKart-Team +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 3 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifndef HEADER_MULTITOUCH_SETTINGS_DIALOG_HPP +#define HEADER_MULTITOUCH_SETTINGS_DIALOG_HPP + +#include "guiengine/modaldialog.hpp" + +/** + * \brief Dialog that allows the player to adjust multitouch steering settings + * \ingroup states_screens + */ +class MultitouchSettingsDialog : public GUIEngine::ModalDialog +{ +private: + void updateValues(); + +public: + /** + * Creates a modal dialog with given percentage of screen width and height + */ + MultitouchSettingsDialog(const float percentWidth, const float percentHeight); + ~MultitouchSettingsDialog(); + + virtual void beforeAddingWidgets(); + + GUIEngine::EventPropagation processEvent(const std::string& eventSource); + +}; + +#endif diff --git a/src/states_screens/options_screen_input.cpp b/src/states_screens/options_screen_input.cpp index 17bbde76e..e8728fdd7 100644 --- a/src/states_screens/options_screen_input.cpp +++ b/src/states_screens/options_screen_input.cpp @@ -33,6 +33,7 @@ #include "states_screens/options_screen_video.hpp" #include "states_screens/options_screen_ui.hpp" #include "states_screens/dialogs/add_device_dialog.hpp" +#include "states_screens/dialogs/multitouch_settings_dialog.hpp" #include "states_screens/state_manager.hpp" #include "states_screens/user_screen.hpp" #include "utils/string_utils.hpp" @@ -81,8 +82,10 @@ void OptionsScreenInput::buildDeviceList() assert( m_icon_bank != NULL ); devices->setIcons(m_icon_bank); + + DeviceManager* device_manager = input_manager->getDeviceManager(); - const int keyboard_config_count = input_manager->getDeviceManager()->getKeyboardConfigAmount(); + const int keyboard_config_count = device_manager->getKeyboardConfigAmount(); for (int i=0; iaddItem(internal_name, (core::stringw(" ") + _("Keyboard %i", i)).c_str(), 0 /* icon */); } - const int gpad_config_count = input_manager->getDeviceManager()->getGamePadConfigAmount(); + const int gpad_config_count = device_manager->getGamePadConfigAmount(); for (int i = 0; i < gpad_config_count; i++) { - GamepadConfig *config = input_manager->getDeviceManager()->getGamepadConfig(i); + GamepadConfig *config = device_manager->getGamepadConfig(i); // Don't display the configuration if a matching device is not available if (config->isPlugged()) @@ -126,6 +129,13 @@ void OptionsScreenInput::buildDeviceList() devices->addItem(internal_name, name, icon); } // if config->isPlugged } // for igetMultitouchDevice(); + + if (touch_device != NULL) + { + devices->addItem("touch_device", " Touch device", 1); + } } // buildDeviceList // ----------------------------------------------------------------------------- @@ -252,6 +262,15 @@ void OptionsScreenInput::eventCallback(Widget* widget, const std::string& name, selection.c_str()); } } + else if (selection.find("touch_device") != std::string::npos) + { + // Don't edit multitouch settings during a race, because it needs + // to re-create all buttons to take an effect + if (StateManager::get()->getGameState() != GUIEngine::INGAME_MENU) + { + new MultitouchSettingsDialog(0.8f, 0.9f); + } + } else { Log::error("OptionsScreenInput", "Cannot read internal input device ID: %s", selection.c_str());