Add a popup on first run on android, so that user can choose if accelerometer should be enabled
This commit is contained in:
parent
975fc8f84a
commit
8f78d4e891
26
data/gui/init_android.stkgui
Normal file
26
data/gui/init_android.stkgui
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<stkgui>
|
||||||
|
<div x="2%" y="2%" width="96%" height="96%" layout="vertical-row" >
|
||||||
|
|
||||||
|
<spacer height="2%" width="25"/>
|
||||||
|
<box width="100%" height="fit" padding="10" layout="vertical-row">
|
||||||
|
<bright width="100%" text="Select a type of control that you prefer" align="center" text_align="left" />
|
||||||
|
|
||||||
|
<spacer height="15%" width="10"/>
|
||||||
|
|
||||||
|
<ribbon id="control_type" height="135" width="100%" align="center">
|
||||||
|
<icon-button id="accelerometer" width="128" height="128" icon="gui/difficulty_medium.png"
|
||||||
|
I18N="Control type" text="Accelerometer"/>
|
||||||
|
<icon-button id="steering_wheel" width="128" height="128" icon="gui/difficulty_hard.png"
|
||||||
|
I18N="Control type" text="Steering wheel"/>
|
||||||
|
</ribbon>
|
||||||
|
</box>
|
||||||
|
|
||||||
|
<spacer height="7%" width="10"/>
|
||||||
|
|
||||||
|
<div width="25%" height="10%" layout="horizontal-row" align="center">
|
||||||
|
<button id="close" text="Apply" width="100%" height="100%" align="center"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</stkgui>
|
@ -1,4 +1,4 @@
|
|||||||
# Modify this file to change the last-modified date when you add/remove a file.
|
# Modify this file to change the last-modified date when you add/remove a file.
|
||||||
# This will then trigger a new cmake run automatically.
|
# This will then trigger a new cmake run automatically.
|
||||||
file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp")
|
file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp")
|
||||||
file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp")
|
file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp")
|
||||||
|
@ -468,10 +468,10 @@ namespace UserConfigParams
|
|||||||
&m_multitouch_group,
|
&m_multitouch_group,
|
||||||
"Draw steering wheel on right side.") );
|
"Draw steering wheel on right side.") );
|
||||||
|
|
||||||
PARAM_PREFIX IntUserConfigParam m_multitouch_accelerometer
|
PARAM_PREFIX IntUserConfigParam m_multitouch_controls
|
||||||
PARAM_DEFAULT( IntUserConfigParam(0, "multitouch_accelerometer",
|
PARAM_DEFAULT( IntUserConfigParam(0, "multitouch_controls",
|
||||||
&m_multitouch_group,
|
&m_multitouch_group,
|
||||||
"Accelerometer mode: 0 = off, 1 = tablet, 2 = phone"));
|
"Multitouch mode: 0 = undefined, 1 = steering wheel, 2 = accelerometer"));
|
||||||
|
|
||||||
PARAM_PREFIX FloatUserConfigParam m_multitouch_deadzone_center
|
PARAM_PREFIX FloatUserConfigParam m_multitouch_deadzone_center
|
||||||
PARAM_DEFAULT( FloatUserConfigParam(0.1f, "multitouch_deadzone_center",
|
PARAM_DEFAULT( FloatUserConfigParam(0.1f, "multitouch_deadzone_center",
|
||||||
|
@ -140,7 +140,7 @@ void MultitouchDevice::addButton(MultitouchButtonType type, int x, int y,
|
|||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
if (button->type == MultitouchButtonType::BUTTON_STEERING)
|
if (button->type == MultitouchButtonType::BUTTON_STEERING)
|
||||||
{
|
{
|
||||||
if (UserConfigParams::m_multitouch_accelerometer > 0 &&
|
if (UserConfigParams::m_multitouch_controls == 2 &&
|
||||||
!m_android_device->isAccelerometerActive())
|
!m_android_device->isAccelerometerActive())
|
||||||
{
|
{
|
||||||
m_android_device->activateAccelerometer(1.0f / 30);
|
m_android_device->activateAccelerometer(1.0f / 30);
|
||||||
|
16
src/main.cpp
16
src/main.cpp
@ -228,6 +228,7 @@
|
|||||||
#include "states_screens/register_screen.hpp"
|
#include "states_screens/register_screen.hpp"
|
||||||
#include "states_screens/state_manager.hpp"
|
#include "states_screens/state_manager.hpp"
|
||||||
#include "states_screens/user_screen.hpp"
|
#include "states_screens/user_screen.hpp"
|
||||||
|
#include "states_screens/dialogs/init_android_dialog.hpp"
|
||||||
#include "states_screens/dialogs/message_dialog.hpp"
|
#include "states_screens/dialogs/message_dialog.hpp"
|
||||||
#include "tracks/arena_graph.hpp"
|
#include "tracks/arena_graph.hpp"
|
||||||
#include "tracks/track.hpp"
|
#include "tracks/track.hpp"
|
||||||
@ -1668,6 +1669,21 @@ int main(int argc, char *argv[] )
|
|||||||
}
|
}
|
||||||
Log::warn("main", "Screen size is too small!");
|
Log::warn("main", "Screen size is too small!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ANDROID
|
||||||
|
if (UserConfigParams::m_multitouch_controls == 0)
|
||||||
|
{
|
||||||
|
int32_t touch = AConfiguration_getTouchscreen(
|
||||||
|
global_android_app->config);
|
||||||
|
|
||||||
|
if (touch != ACONFIGURATION_TOUCHSCREEN_NOTOUCH)
|
||||||
|
{
|
||||||
|
InitAndroidDialog* init_android = new InitAndroidDialog(
|
||||||
|
0.6f, 0.6f);
|
||||||
|
GUIEngine::DialogQueue::get()->pushDialog(init_android);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (GraphicsRestrictions::isDisabled(
|
if (GraphicsRestrictions::isDisabled(
|
||||||
GraphicsRestrictions::GR_DRIVER_RECENT_ENOUGH))
|
GraphicsRestrictions::GR_DRIVER_RECENT_ENOUGH))
|
||||||
|
158
src/states_screens/dialogs/init_android_dialog.cpp
Normal file
158
src/states_screens/dialogs/init_android_dialog.cpp
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
// 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/init_android_dialog.hpp"
|
||||||
|
|
||||||
|
#include "config/user_config.hpp"
|
||||||
|
#include "graphics/irr_driver.hpp"
|
||||||
|
#include "guiengine/widgets/check_box_widget.hpp"
|
||||||
|
#include "guiengine/widgets/spinner_widget.hpp"
|
||||||
|
#include "guiengine/widgets/ribbon_widget.hpp"
|
||||||
|
#include "input/device_manager.hpp"
|
||||||
|
#include "input/input_manager.hpp"
|
||||||
|
#include "input/multitouch_device.hpp"
|
||||||
|
#include "utils/translation.hpp"
|
||||||
|
|
||||||
|
#ifdef ANDROID
|
||||||
|
#include "../../../lib/irrlicht/source/Irrlicht/CIrrDeviceAndroid.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <IGUIEnvironment.h>
|
||||||
|
|
||||||
|
|
||||||
|
using namespace GUIEngine;
|
||||||
|
using namespace irr;
|
||||||
|
using namespace irr::core;
|
||||||
|
using namespace irr::gui;
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
InitAndroidDialog::InitAndroidDialog(const float w, const float h)
|
||||||
|
: ModalDialog(w, h)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
InitAndroidDialog::~InitAndroidDialog()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void InitAndroidDialog::load()
|
||||||
|
{
|
||||||
|
loadFromFile("init_android.stkgui");
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void InitAndroidDialog::beforeAddingWidgets()
|
||||||
|
{
|
||||||
|
bool accelerometer_available = false;
|
||||||
|
|
||||||
|
#ifdef ANDROID
|
||||||
|
CIrrDeviceAndroid* android_device = dynamic_cast<CIrrDeviceAndroid*>(
|
||||||
|
irr_driver->getDevice());
|
||||||
|
assert(android_device != NULL);
|
||||||
|
accelerometer_available = android_device->isAccelerometerAvailable();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!accelerometer_available)
|
||||||
|
{
|
||||||
|
RibbonWidget* control_type = getWidget<RibbonWidget>("control_type");
|
||||||
|
assert(control_type != NULL);
|
||||||
|
|
||||||
|
int index = control_type->findItemNamed("accelerometer");
|
||||||
|
Widget* accelerometer = &control_type->getChildren()[index];
|
||||||
|
accelerometer->setActive(false);
|
||||||
|
|
||||||
|
if (UserConfigParams::m_multitouch_controls = 2)
|
||||||
|
{
|
||||||
|
UserConfigParams::m_multitouch_controls = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
GUIEngine::EventPropagation InitAndroidDialog::processEvent(
|
||||||
|
const std::string& eventSource)
|
||||||
|
{
|
||||||
|
if (eventSource == "close")
|
||||||
|
{
|
||||||
|
RibbonWidget* control_type = getWidget<RibbonWidget>("control_type");
|
||||||
|
assert(control_type != NULL);
|
||||||
|
|
||||||
|
const std::string& selected = control_type->getSelectionIDString(
|
||||||
|
PLAYER_ID_GAME_MASTER);
|
||||||
|
int index = control_type->getSelection(PLAYER_ID_GAME_MASTER);
|
||||||
|
Widget* selected_widget = &control_type->getChildren()[index];
|
||||||
|
|
||||||
|
if (!selected_widget->isActivated())
|
||||||
|
return GUIEngine::EVENT_BLOCK;
|
||||||
|
|
||||||
|
if (selected == "steering_wheel")
|
||||||
|
{
|
||||||
|
UserConfigParams::m_multitouch_controls = 1;
|
||||||
|
}
|
||||||
|
else if (selected == "accelerometer")
|
||||||
|
{
|
||||||
|
UserConfigParams::m_multitouch_controls = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
user_config->saveConfig();
|
||||||
|
|
||||||
|
ModalDialog::dismiss();
|
||||||
|
return GUIEngine::EVENT_BLOCK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return GUIEngine::EVENT_LET;
|
||||||
|
} // processEvent
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void InitAndroidDialog::updateValues()
|
||||||
|
{
|
||||||
|
RibbonWidget* control_type = getWidget<RibbonWidget>("control_type");
|
||||||
|
assert(control_type != NULL);
|
||||||
|
|
||||||
|
if (UserConfigParams::m_multitouch_controls == 2)
|
||||||
|
{
|
||||||
|
int id = control_type->findItemNamed("accelerometer");
|
||||||
|
control_type->setSelection(id, PLAYER_ID_GAME_MASTER);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int id = control_type->findItemNamed("steering_wheel");
|
||||||
|
control_type->setSelection(id, PLAYER_ID_GAME_MASTER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool InitAndroidDialog::onEscapePressed()
|
||||||
|
{
|
||||||
|
UserConfigParams::m_multitouch_controls = 1;
|
||||||
|
user_config->saveConfig();
|
||||||
|
ModalDialog::dismiss();
|
||||||
|
return true;
|
||||||
|
} // onEscapePressed
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
48
src/states_screens/dialogs/init_android_dialog.hpp
Normal file
48
src/states_screens/dialogs/init_android_dialog.hpp
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
// 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_INIT_ANDROID_DIALOG_HPP
|
||||||
|
#define HEADER_INIT_ANDROID_DIALOG_HPP
|
||||||
|
|
||||||
|
#include "guiengine/modaldialog.hpp"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Dialog that allows the player to adjust multitouch steering settings
|
||||||
|
* \ingroup states_screens
|
||||||
|
*/
|
||||||
|
class InitAndroidDialog : public GUIEngine::ModalDialog
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
void updateValues();
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Creates a modal dialog with given percentage of screen width and height
|
||||||
|
*/
|
||||||
|
InitAndroidDialog(const float percentWidth, const float percentHeight);
|
||||||
|
~InitAndroidDialog();
|
||||||
|
|
||||||
|
virtual void beforeAddingWidgets();
|
||||||
|
virtual void load();
|
||||||
|
virtual bool onEscapePressed();
|
||||||
|
|
||||||
|
GUIEngine::EventPropagation processEvent(const std::string& eventSource);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -107,8 +107,8 @@ GUIEngine::EventPropagation MultitouchSettingsDialog::processEvent(
|
|||||||
CheckBoxWidget* accelerometer = getWidget<CheckBoxWidget>("accelerometer");
|
CheckBoxWidget* accelerometer = getWidget<CheckBoxWidget>("accelerometer");
|
||||||
assert(accelerometer != NULL);
|
assert(accelerometer != NULL);
|
||||||
|
|
||||||
UserConfigParams::m_multitouch_accelerometer = accelerometer->
|
UserConfigParams::m_multitouch_controls = accelerometer->
|
||||||
getState() ? 1 : 0;
|
getState() ? 2 : 1;
|
||||||
|
|
||||||
MultitouchDevice* touch_device = input_manager->getDeviceManager()->
|
MultitouchDevice* touch_device = input_manager->getDeviceManager()->
|
||||||
getMultitouchDevice();
|
getMultitouchDevice();
|
||||||
@ -129,7 +129,7 @@ GUIEngine::EventPropagation MultitouchSettingsDialog::processEvent(
|
|||||||
UserConfigParams::m_multitouch_deadzone_edge.revertToDefaults();
|
UserConfigParams::m_multitouch_deadzone_edge.revertToDefaults();
|
||||||
UserConfigParams::m_multitouch_deadzone_center.revertToDefaults();
|
UserConfigParams::m_multitouch_deadzone_center.revertToDefaults();
|
||||||
UserConfigParams::m_multitouch_mode.revertToDefaults();
|
UserConfigParams::m_multitouch_mode.revertToDefaults();
|
||||||
UserConfigParams::m_multitouch_accelerometer.revertToDefaults();
|
UserConfigParams::m_multitouch_controls.revertToDefaults();
|
||||||
|
|
||||||
updateValues();
|
updateValues();
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ void MultitouchSettingsDialog::updateValues()
|
|||||||
|
|
||||||
CheckBoxWidget* accelerometer = getWidget<CheckBoxWidget>("accelerometer");
|
CheckBoxWidget* accelerometer = getWidget<CheckBoxWidget>("accelerometer");
|
||||||
assert(accelerometer != NULL);
|
assert(accelerometer != NULL);
|
||||||
accelerometer->setState(UserConfigParams::m_multitouch_accelerometer != 0);
|
accelerometer->setState(UserConfigParams::m_multitouch_controls == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user