Gyroscope option in config dialogs

This commit is contained in:
Sergii Pylypenko 2018-10-01 23:13:50 +03:00
parent 964d7bf8de
commit 9f923fdfaa
6 changed files with 83 additions and 3 deletions

@ -10,6 +10,8 @@
<ribbon id="control_type" proportion="1" width="100%" align="center">
<icon-button id="accelerometer" width="fit" height="fit" icon="gui/icons/difficulty_medium.png"
I18N="Control type" text="Accelerometer"/>
<icon-button id="gyroscope" width="fit" height="fit" icon="gui/icons/difficulty_best.png"
I18N="Control type" text="Gyroscope"/>
<icon-button id="steering_wheel" width="fit" height="fit" icon="gui/icons/difficulty_hard.png"
I18N="Control type" text="Steering wheel"/>
</ribbon>

@ -39,6 +39,14 @@
</div>
</div>
<div width="75%" layout="horizontal-row" proportion="1">
<label proportion="1" align="center" text_align="right" I18N="In the multitouch settings screen" text="Gyroscope"/>
<div proportion="1" align="center" height="fit" layout="horizontal-row" >
<spacer width="40" height="10" />
<checkbox id="gyroscope"/>
</div>
</div>
<label width="100%" I18N="In the multitouch settings screen" text="Advanced"/>
<div width="75%" layout="horizontal-row" proportion="1">

@ -168,6 +168,13 @@ msgstr ""
msgid "Accelerometer"
msgstr ""
#. I18N: ./data/gui/dialogs/android/init_android.stkgui
#. I18N: Control type
#. I18N: ./data/gui/dialogs/android/multitouch_settings.stkgui
#. I18N: In the multitouch settings screen
msgid "Gyroscope"
msgstr ""
#. I18N: ./data/gui/dialogs/android/init_android.stkgui
#. I18N: Control type
msgid "Steering wheel"

@ -488,7 +488,7 @@ namespace UserConfigParams
PARAM_PREFIX IntUserConfigParam m_multitouch_controls
PARAM_DEFAULT( IntUserConfigParam(0, "multitouch_controls",
&m_multitouch_group,
"Multitouch mode: 0 = undefined, 1 = steering wheel, 2 = accelerometer"));
"Multitouch mode: 0 = undefined, 1 = steering wheel, 2 = accelerometer, 3 = gyroscope"));
PARAM_PREFIX FloatUserConfigParam m_multitouch_deadzone_center
PARAM_DEFAULT( FloatUserConfigParam(0.1f, "multitouch_deadzone_center",

@ -64,12 +64,14 @@ void InitAndroidDialog::load()
void InitAndroidDialog::beforeAddingWidgets()
{
bool accelerometer_available = false;
bool gyroscope_available = false;
#ifdef ANDROID
CIrrDeviceAndroid* android_device = dynamic_cast<CIrrDeviceAndroid*>(
irr_driver->getDevice());
assert(android_device != NULL);
accelerometer_available = android_device->isAccelerometerAvailable();
gyroscope_available = android_device->isGyroscopeAvailable() && accelerometer_available;
#endif
if (!accelerometer_available)
@ -87,6 +89,21 @@ void InitAndroidDialog::beforeAddingWidgets()
}
}
if (!gyroscope_available)
{
RibbonWidget* control_type = getWidget<RibbonWidget>("control_type");
assert(control_type != NULL);
int index = control_type->findItemNamed("gyroscope");
Widget* gyroscope = &control_type->getChildren()[index];
gyroscope->setActive(false);
if (UserConfigParams::m_multitouch_controls == 3)
{
UserConfigParams::m_multitouch_controls = 1;
}
}
updateValues();
}
@ -116,6 +133,10 @@ GUIEngine::EventPropagation InitAndroidDialog::processEvent(
{
UserConfigParams::m_multitouch_controls = 2;
}
else if (selected == "gyroscope")
{
UserConfigParams::m_multitouch_controls = 3;
}
user_config->saveConfig();
@ -138,6 +159,11 @@ void InitAndroidDialog::updateValues()
int id = control_type->findItemNamed("accelerometer");
control_type->setSelection(id, PLAYER_ID_GAME_MASTER);
}
else if (UserConfigParams::m_multitouch_controls == 3)
{
int id = control_type->findItemNamed("gyroscope");
control_type->setSelection(id, PLAYER_ID_GAME_MASTER);
}
else
{
int id = control_type->findItemNamed("steering_wheel");

@ -57,12 +57,14 @@ MultitouchSettingsDialog::~MultitouchSettingsDialog()
void MultitouchSettingsDialog::beforeAddingWidgets()
{
bool accelerometer_available = false;
bool gyroscope_available = false;
#ifdef ANDROID
CIrrDeviceAndroid* android_device = dynamic_cast<CIrrDeviceAndroid*>(
irr_driver->getDevice());
assert(android_device != NULL);
accelerometer_available = android_device->isAccelerometerAvailable();
gyroscope_available = android_device->isGyroscopeAvailable() && accelerometer_available;
#endif
if (!accelerometer_available)
@ -72,6 +74,13 @@ void MultitouchSettingsDialog::beforeAddingWidgets()
accelerometer->setActive(false);
}
if (!gyroscope_available)
{
CheckBoxWidget* gyroscope = getWidget<CheckBoxWidget>("gyroscope");
assert(gyroscope != NULL);
gyroscope->setActive(false);
}
updateValues();
}
@ -107,8 +116,20 @@ GUIEngine::EventPropagation MultitouchSettingsDialog::processEvent(
CheckBoxWidget* accelerometer = getWidget<CheckBoxWidget>("accelerometer");
assert(accelerometer != NULL);
UserConfigParams::m_multitouch_controls = accelerometer->
getState() ? 2 : 1;
CheckBoxWidget* gyroscope = getWidget<CheckBoxWidget>("gyroscope");
assert(gyroscope != NULL);
UserConfigParams::m_multitouch_controls = 1;
if (accelerometer->getState())
{
UserConfigParams::m_multitouch_controls = 2;
}
if (gyroscope->getState())
{
UserConfigParams::m_multitouch_controls = 3;
}
MultitouchDevice* touch_device = input_manager->getDeviceManager()->
getMultitouchDevice();
@ -159,6 +180,18 @@ GUIEngine::EventPropagation MultitouchSettingsDialog::processEvent(
return GUIEngine::EVENT_BLOCK;
}
else if (eventSource == "accelerometer")
{
CheckBoxWidget* gyroscope = getWidget<CheckBoxWidget>("gyroscope");
assert(gyroscope != NULL);
gyroscope->setState(false);
}
else if (eventSource == "gyroscope")
{
CheckBoxWidget* accelerometer = getWidget<CheckBoxWidget>("accelerometer");
assert(accelerometer != NULL);
accelerometer->setState(false);
}
return GUIEngine::EVENT_LET;
} // processEvent
@ -192,6 +225,10 @@ void MultitouchSettingsDialog::updateValues()
CheckBoxWidget* accelerometer = getWidget<CheckBoxWidget>("accelerometer");
assert(accelerometer != NULL);
accelerometer->setState(UserConfigParams::m_multitouch_controls == 2);
CheckBoxWidget* gyroscope = getWidget<CheckBoxWidget>("gyroscope");
assert(gyroscope != NULL);
gyroscope->setState(UserConfigParams::m_multitouch_controls == 3);
}
// -----------------------------------------------------------------------------