Add a possibility to change touch device settings in GUI
This commit is contained in:
parent
da795b69ed
commit
082661db65
52
data/gui/multitouch_settings.stkgui
Normal file
52
data/gui/multitouch_settings.stkgui
Normal file
@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<stkgui>
|
||||
<div x="2%" y="1%" width="96%" height="98%" layout="vertical-row" >
|
||||
<header id="title" width="100%" height="fit" text_align="center" word_wrap="true" text="Touch Device Settings" />
|
||||
|
||||
<spacer height="30" width="10" />
|
||||
|
||||
<label width="100%" I18N="In the multitouch settings screen" text="General"/>
|
||||
|
||||
<spacer height="15" width="10"/>
|
||||
|
||||
<div width="75%" height="fit" layout="horizontal-row" >
|
||||
<label proportion="1" height="100%" text_align="right" I18N="In the multitouch settings screen" text="Buttons scale"/>
|
||||
<div proportion="1" height="fit" layout="horizontal-row" >
|
||||
<spacer width="40" height="100%" />
|
||||
<gauge id="scale" proportion="1" min_value="50" max_value="150"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<spacer height="45" width="10"/>
|
||||
|
||||
<label width="100%" I18N="In the multitouch settings screen" text="Advanced"/>
|
||||
|
||||
<spacer height="15" width="10"/>
|
||||
|
||||
<div width="75%" height="fit" layout="horizontal-row" >
|
||||
<label proportion="1" height="100%" text_align="right" I18N="In the multitouch settings screen" text="Deadzone center"/>
|
||||
<div proportion="1" height="fit" layout="horizontal-row" >
|
||||
<spacer width="40" height="100%" />
|
||||
<gauge id="deadzone_center" proportion="1" min_value="0" max_value="50"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<spacer height="15" width="10"/>
|
||||
|
||||
<div width="75%" height="fit" layout="horizontal-row" >
|
||||
<label proportion="1" height="100%" text_align="right" I18N="In the multitouch settings screen" text="Deadzone edge"/>
|
||||
<div proportion="1" height="fit" layout="horizontal-row" >
|
||||
<spacer width="40" height="100%" />
|
||||
<gauge id="deadzone_edge" proportion="1" min_value="0" max_value="50"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<spacer height="45" width="10"/>
|
||||
|
||||
<button id="restore" text="Restore defaults" align="center"/>
|
||||
|
||||
<spacer height="15" width="10"/>
|
||||
|
||||
<button id="close" text="Apply" align="center"/>
|
||||
</div>
|
||||
</stkgui>
|
112
src/states_screens/dialogs/multitouch_settings_dialog.cpp
Normal file
112
src/states_screens/dialogs/multitouch_settings_dialog.cpp
Normal file
@ -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 <IGUIEnvironment.h>
|
||||
|
||||
|
||||
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<SpinnerWidget>("scale");
|
||||
assert(scale != NULL);
|
||||
UserConfigParams::m_multitouch_scale = scale->getValue() / 100.0f;
|
||||
|
||||
SpinnerWidget* deadzone_edge = getWidget<SpinnerWidget>("deadzone_edge");
|
||||
assert(deadzone_edge != NULL);
|
||||
UserConfigParams::m_multitouch_deadzone_edge =
|
||||
deadzone_edge->getValue() / 100.0f;
|
||||
|
||||
SpinnerWidget* deadzone_center = getWidget<SpinnerWidget>("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<SpinnerWidget>("scale");
|
||||
assert(scale != NULL);
|
||||
scale->setValue((int)(UserConfigParams::m_multitouch_scale * 100.0f));
|
||||
|
||||
SpinnerWidget* deadzone_edge = getWidget<SpinnerWidget>("deadzone_edge");
|
||||
assert(deadzone_edge != NULL);
|
||||
deadzone_edge->setValue(
|
||||
(int)(UserConfigParams::m_multitouch_deadzone_edge * 100.0f));
|
||||
|
||||
SpinnerWidget* deadzone_center = getWidget<SpinnerWidget>("deadzone_center");
|
||||
assert(deadzone_center != NULL);
|
||||
deadzone_center->setValue(
|
||||
(int)(UserConfigParams::m_multitouch_deadzone_center * 100.0f));
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
46
src/states_screens/dialogs/multitouch_settings_dialog.hpp
Normal file
46
src/states_screens/dialogs/multitouch_settings_dialog.hpp
Normal file
@ -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
|
@ -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; i<keyboard_config_count; i++)
|
||||
{
|
||||
@ -97,11 +100,11 @@ void OptionsScreenInput::buildDeviceList()
|
||||
devices->addItem(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 i<gpad_config_count
|
||||
|
||||
MultitouchDevice* touch_device = device_manager->getMultitouchDevice();
|
||||
|
||||
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());
|
||||
|
Loading…
Reference in New Issue
Block a user