Add a popup on first run on android, so that user can choose if accelerometer should be enabled

This commit is contained in:
Deve 2018-03-04 00:08:24 +01:00
parent 975fc8f84a
commit 8f78d4e891
8 changed files with 257 additions and 9 deletions

View 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>

View File

@ -468,10 +468,10 @@ namespace UserConfigParams
&m_multitouch_group,
"Draw steering wheel on right side.") );
PARAM_PREFIX IntUserConfigParam m_multitouch_accelerometer
PARAM_DEFAULT( IntUserConfigParam(0, "multitouch_accelerometer",
PARAM_PREFIX IntUserConfigParam m_multitouch_controls
PARAM_DEFAULT( IntUserConfigParam(0, "multitouch_controls",
&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_DEFAULT( FloatUserConfigParam(0.1f, "multitouch_deadzone_center",

View File

@ -140,7 +140,7 @@ void MultitouchDevice::addButton(MultitouchButtonType type, int x, int y,
#ifdef ANDROID
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->activateAccelerometer(1.0f / 30);

View File

@ -228,6 +228,7 @@
#include "states_screens/register_screen.hpp"
#include "states_screens/state_manager.hpp"
#include "states_screens/user_screen.hpp"
#include "states_screens/dialogs/init_android_dialog.hpp"
#include "states_screens/dialogs/message_dialog.hpp"
#include "tracks/arena_graph.hpp"
#include "tracks/track.hpp"
@ -1669,6 +1670,21 @@ int main(int argc, char *argv[] )
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(
GraphicsRestrictions::GR_DRIVER_RECENT_ENOUGH))
{

View 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
// -----------------------------------------------------------------------------

View 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

View File

@ -107,8 +107,8 @@ GUIEngine::EventPropagation MultitouchSettingsDialog::processEvent(
CheckBoxWidget* accelerometer = getWidget<CheckBoxWidget>("accelerometer");
assert(accelerometer != NULL);
UserConfigParams::m_multitouch_accelerometer = accelerometer->
getState() ? 1 : 0;
UserConfigParams::m_multitouch_controls = accelerometer->
getState() ? 2 : 1;
MultitouchDevice* touch_device = input_manager->getDeviceManager()->
getMultitouchDevice();
@ -129,7 +129,7 @@ GUIEngine::EventPropagation MultitouchSettingsDialog::processEvent(
UserConfigParams::m_multitouch_deadzone_edge.revertToDefaults();
UserConfigParams::m_multitouch_deadzone_center.revertToDefaults();
UserConfigParams::m_multitouch_mode.revertToDefaults();
UserConfigParams::m_multitouch_accelerometer.revertToDefaults();
UserConfigParams::m_multitouch_controls.revertToDefaults();
updateValues();
@ -167,7 +167,7 @@ void MultitouchSettingsDialog::updateValues()
CheckBoxWidget* accelerometer = getWidget<CheckBoxWidget>("accelerometer");
assert(accelerometer != NULL);
accelerometer->setState(UserConfigParams::m_multitouch_accelerometer != 0);
accelerometer->setState(UserConfigParams::m_multitouch_controls == 2);
}
// -----------------------------------------------------------------------------