Implement auto acceleration for steering wheel from mobile control

This commit is contained in:
Benau 2020-12-08 08:51:30 +08:00
parent 7f9f4dc182
commit 0e1732c45d
6 changed files with 62 additions and 7 deletions

View File

@ -2,7 +2,7 @@
<stkgui>
<div x="2%" y="2%" width="96%" height="96%" layout="vertical-row" >
<box width="100%" height="80%" padding="10" layout="vertical-row">
<box width="100%" height="75%" padding="10" layout="vertical-row">
<bright width="100%" text="Select a type of control that you prefer" align="center" text_align="left" word_wrap="true"/>
<spacer height="7%" width="10"/>
@ -16,12 +16,19 @@
icon="gui/icons/android/steering_wheel.png" I18N="Control type" text="Steering wheel"/>
</ribbon>
<spacer height="12%" width="10"/>
<spacer height="6%" width="10"/>
<div width="100%" height="16%" align="center" layout="horizontal-row">
<label align="center" text_align="left" text="Auto acceleration"/>
<spacer width="10"/>
<checkbox width="7%" height="100%" id="auto_acceleration"/>
</div>
<label width="100%" text="You can change it later in touch device settings." text_align="left" word_wrap="true"/>
</box>
<spacer height="7%" width="10"/>
<spacer height="6%" width="10"/>
<button id="close" text="Apply" align="center"/>

View File

@ -31,6 +31,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="Auto acceleration"/>
<div proportion="1" align="center" height="fit" layout="horizontal-row" >
<spacer width="40" height="10" />
<checkbox id="auto_acceleration"/>
</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="Accelerometer"/>
<div proportion="1" align="center" height="fit" layout="horizontal-row" >

View File

@ -533,6 +533,11 @@ namespace UserConfigParams
&m_multitouch_group,
"Draw steering wheel on right side.") );
PARAM_PREFIX BoolUserConfigParam m_multitouch_auto_acceleration
PARAM_DEFAULT( BoolUserConfigParam(false, "multitouch_auto_acceleration",
&m_multitouch_group,
"Auto acceleration for multitouch controls.") );
PARAM_PREFIX IntUserConfigParam m_multitouch_controls
PARAM_DEFAULT( IntUserConfigParam(0, "multitouch_controls",
&m_multitouch_group,

View File

@ -494,7 +494,9 @@ void MultitouchDevice::updateAxisY(float value)
else
{
m_controller->action(PA_BRAKE, 0);
m_controller->action(PA_ACCEL, 0);
m_controller->action(PA_ACCEL,
UserConfigParams::m_multitouch_controls == 1 &&
UserConfigParams::m_multitouch_auto_acceleration ? Input::MAX_VALUE : 0);
}
}

View File

@ -105,7 +105,24 @@ void InitAndroidDialog::beforeAddingWidgets()
GUIEngine::EventPropagation InitAndroidDialog::processEvent(
const std::string& eventSource)
{
if (eventSource == "close")
if (eventSource == "control_type")
{
RibbonWidget* control_type = getWidget<RibbonWidget>("control_type");
assert(control_type != NULL);
const std::string& selected = control_type->getSelectionIDString(
PLAYER_ID_GAME_MASTER);
if (selected == "steering_wheel")
{
getWidget<CheckBoxWidget>("auto_acceleration")->setActive(true);
}
else
{
getWidget<CheckBoxWidget>("auto_acceleration")->setState(false);
getWidget<CheckBoxWidget>("auto_acceleration")->setActive(false);
}
}
else if (eventSource == "close")
{
RibbonWidget* control_type = getWidget<RibbonWidget>("control_type");
assert(control_type != NULL);
@ -121,14 +138,17 @@ GUIEngine::EventPropagation InitAndroidDialog::processEvent(
if (selected == "steering_wheel")
{
UserConfigParams::m_multitouch_controls = MULTITOUCH_CONTROLS_STEERING_WHEEL;
UserConfigParams::m_multitouch_auto_acceleration = getWidget<CheckBoxWidget>("auto_acceleration")->getState();
}
else if (selected == "accelerometer")
{
UserConfigParams::m_multitouch_controls = MULTITOUCH_CONTROLS_ACCELEROMETER;
UserConfigParams::m_multitouch_auto_acceleration = false;
}
else if (selected == "gyroscope")
{
UserConfigParams::m_multitouch_controls = MULTITOUCH_CONTROLS_GYROSCOPE;
UserConfigParams::m_multitouch_auto_acceleration = false;
}
user_config->saveConfig();
@ -151,17 +171,20 @@ void InitAndroidDialog::updateValues()
{
int id = control_type->findItemNamed("accelerometer");
control_type->setSelection(id, PLAYER_ID_GAME_MASTER);
getWidget<CheckBoxWidget>("auto_acceleration")->setActive(false);
}
else if (UserConfigParams::m_multitouch_controls == MULTITOUCH_CONTROLS_GYROSCOPE)
{
int id = control_type->findItemNamed("gyroscope");
control_type->setSelection(id, PLAYER_ID_GAME_MASTER);
getWidget<CheckBoxWidget>("auto_acceleration")->setActive(false);
}
else
{
int id = control_type->findItemNamed("steering_wheel");
control_type->setSelection(id, PLAYER_ID_GAME_MASTER);
}
getWidget<CheckBoxWidget>("auto_acceleration")->setState(false);
}
// -----------------------------------------------------------------------------

View File

@ -138,6 +138,9 @@ GUIEngine::EventPropagation MultitouchSettingsDialog::processEvent(
UserConfigParams::m_multitouch_controls = MULTITOUCH_CONTROLS_GYROSCOPE;
}
if (UserConfigParams::m_multitouch_controls == MULTITOUCH_CONTROLS_STEERING_WHEEL)
UserConfigParams::m_multitouch_auto_acceleration = getWidget<CheckBoxWidget>("auto_acceleration")->getState();
MultitouchDevice* touch_device = input_manager->getDeviceManager()->
getMultitouchDevice();
@ -183,12 +186,14 @@ GUIEngine::EventPropagation MultitouchSettingsDialog::processEvent(
CheckBoxWidget* gyroscope = getWidget<CheckBoxWidget>("gyroscope");
assert(gyroscope != NULL);
gyroscope->setState(false);
getWidget<CheckBoxWidget>("auto_acceleration")->setState(false);
}
else if (eventSource == "gyroscope")
{
CheckBoxWidget* accelerometer = getWidget<CheckBoxWidget>("accelerometer");
assert(accelerometer != NULL);
accelerometer->setState(false);
getWidget<CheckBoxWidget>("auto_acceleration")->setState(false);
}
return GUIEngine::EVENT_LET;
@ -232,6 +237,11 @@ void MultitouchSettingsDialog::updateValues()
CheckBoxWidget* gyroscope = getWidget<CheckBoxWidget>("gyroscope");
assert(gyroscope != NULL);
gyroscope->setState(UserConfigParams::m_multitouch_controls == MULTITOUCH_CONTROLS_GYROSCOPE);
if (UserConfigParams::m_multitouch_controls == MULTITOUCH_CONTROLS_STEERING_WHEEL)
getWidget<CheckBoxWidget>("auto_acceleration")->setState(UserConfigParams::m_multitouch_auto_acceleration);
else
getWidget<CheckBoxWidget>("auto_acceleration")->setState(false);
}
// -----------------------------------------------------------------------------