Add easier way to change touch controls type
This commit is contained in:
parent
f89933bb46
commit
8e19e96a9e
@ -14,6 +14,8 @@
|
||||
<buttonbar id="backbtnribbon" proportion="4" width="100%" align="center">
|
||||
<icon-button id="backbtn" width="128" height="128" align="center" icon="gui/icons/back.png"
|
||||
extend_label="200" I18N="Race paused button" text="Back to Race"/>
|
||||
<icon-button id="touch_device" width="128" height="128" align="center" icon="gui/icons/android/gyroscope_icon.png"
|
||||
extend_label="200" I18N="Race paused button" text="Gyroscope"/>
|
||||
</buttonbar>
|
||||
|
||||
<spacer width="20" height="8%" />
|
||||
|
@ -8,6 +8,8 @@
|
||||
<buttonbar id="backbtnribbon" proportion="4" width="100%" align="center">
|
||||
<icon-button id="backbtn" width="128" height="128" align="center" icon="gui/icons/back.png"
|
||||
extend_label="200" I18N="In the in-game dialog" text="Back to Game"/>
|
||||
<icon-button id="touch_device" width="128" height="128" align="center" icon="gui/icons/android/gyroscope_icon.png"
|
||||
extend_label="200" I18N="Race paused button" text="Gyroscope"/>
|
||||
</buttonbar>
|
||||
|
||||
<spacer width="20" height="8%" />
|
||||
|
@ -8,6 +8,8 @@
|
||||
<buttonbar id="backbtnribbon" proportion="4" width="100%" align="center">
|
||||
<icon-button id="backbtn" width="128" height="128" align="center" icon="gui/icons/back.png"
|
||||
extend_label="200" I18N="Race paused button" text="Back to Race"/>
|
||||
<icon-button id="touch_device" width="128" height="128" align="center" icon="gui/icons/android/gyroscope_icon.png"
|
||||
extend_label="200" I18N="Race paused button" text="Gyroscope"/>
|
||||
</buttonbar>
|
||||
|
||||
<spacer width="20" height="8%" />
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "audio/sfx_manager.hpp"
|
||||
#include "challenges/story_mode_timer.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "guiengine/emoji_keyboard.hpp"
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "guiengine/scalable_font.hpp"
|
||||
@ -132,6 +133,18 @@ RacePausedDialog::~RacePausedDialog()
|
||||
{
|
||||
World::getWorld()->scheduleUnpause();
|
||||
}
|
||||
|
||||
if (m_touch_controls != UserConfigParams::m_multitouch_controls)
|
||||
{
|
||||
UserConfigParams::m_multitouch_controls = m_touch_controls;
|
||||
|
||||
if (World::getWorld() && World::getWorld()->getRaceGUI())
|
||||
{
|
||||
World::getWorld()->getRaceGUI()->recreateMultitouchGUI();
|
||||
}
|
||||
|
||||
user_config->saveConfig();
|
||||
}
|
||||
} // ~RacePausedDialog
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -182,6 +195,8 @@ GUIEngine::EventPropagation
|
||||
{
|
||||
GUIEngine::RibbonWidget* choice_ribbon =
|
||||
getWidget<GUIEngine::RibbonWidget>("choiceribbon");
|
||||
GUIEngine::RibbonWidget* backbtn_ribbon =
|
||||
getWidget<GUIEngine::RibbonWidget>("backbtnribbon");
|
||||
|
||||
if (eventSource == "send" && m_text_box)
|
||||
{
|
||||
@ -197,11 +212,52 @@ GUIEngine::EventPropagation
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
else if (eventSource == "backbtnribbon")
|
||||
{
|
||||
const std::string& selection =
|
||||
backbtn_ribbon->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||
|
||||
if (selection == "backbtn")
|
||||
{
|
||||
// unpausing is done in the destructor so nothing more to do here
|
||||
ModalDialog::dismiss();
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
else if (selection == "touch_device")
|
||||
{
|
||||
IrrlichtDevice* irrlicht_device = irr_driver->getDevice();
|
||||
assert(irrlicht_device != NULL);
|
||||
bool accelerometer_available = irrlicht_device->isAccelerometerAvailable();
|
||||
bool gyroscope_available = irrlicht_device->isGyroscopeAvailable() && accelerometer_available;
|
||||
|
||||
if (m_touch_controls == MULTITOUCH_CONTROLS_STEERING_WHEEL)
|
||||
{
|
||||
m_touch_controls = MULTITOUCH_CONTROLS_ACCELEROMETER;
|
||||
}
|
||||
else if (m_touch_controls == MULTITOUCH_CONTROLS_ACCELEROMETER)
|
||||
{
|
||||
m_touch_controls = MULTITOUCH_CONTROLS_GYROSCOPE;
|
||||
}
|
||||
else if (m_touch_controls == MULTITOUCH_CONTROLS_GYROSCOPE)
|
||||
{
|
||||
m_touch_controls = MULTITOUCH_CONTROLS_STEERING_WHEEL;
|
||||
}
|
||||
|
||||
if (m_touch_controls == MULTITOUCH_CONTROLS_ACCELEROMETER &&
|
||||
!accelerometer_available)
|
||||
{
|
||||
m_touch_controls = MULTITOUCH_CONTROLS_STEERING_WHEEL;
|
||||
}
|
||||
else if (m_touch_controls == MULTITOUCH_CONTROLS_GYROSCOPE &&
|
||||
!gyroscope_available)
|
||||
{
|
||||
m_touch_controls = MULTITOUCH_CONTROLS_STEERING_WHEEL;
|
||||
}
|
||||
|
||||
updateTouchDeviceIcon();
|
||||
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
}
|
||||
else if (eventSource == "choiceribbon")
|
||||
{
|
||||
const std::string& selection =
|
||||
@ -331,8 +387,36 @@ void RacePausedDialog::beforeAddingWidgets()
|
||||
m_text_box = getWidget<TextBoxWidget>("chat");
|
||||
else
|
||||
m_text_box = NULL;
|
||||
|
||||
bool has_multitouch_gui = false;
|
||||
|
||||
if (World::getWorld() && World::getWorld()->getRaceGUI() &&
|
||||
World::getWorld()->getRaceGUI()->getMultitouchGUI())
|
||||
{
|
||||
has_multitouch_gui = true;
|
||||
}
|
||||
|
||||
IrrlichtDevice* irrlicht_device = irr_driver->getDevice();
|
||||
assert(irrlicht_device != NULL);
|
||||
bool accelerometer_available = irrlicht_device->isAccelerometerAvailable();
|
||||
|
||||
if (!has_multitouch_gui || !accelerometer_available)
|
||||
{
|
||||
GUIEngine::RibbonWidget* backbtn_ribbon =
|
||||
getWidget<GUIEngine::RibbonWidget>("backbtnribbon");
|
||||
backbtn_ribbon->removeChildNamed("touch_device");
|
||||
}
|
||||
|
||||
} // beforeAddingWidgets
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void RacePausedDialog::init()
|
||||
{
|
||||
m_touch_controls = UserConfigParams::m_multitouch_controls;
|
||||
updateTouchDeviceIcon();
|
||||
|
||||
} // init
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
bool RacePausedDialog::onEnterPressed(const irr::core::stringw& text)
|
||||
{
|
||||
@ -352,3 +436,35 @@ bool RacePausedDialog::onEnterPressed(const irr::core::stringw& text)
|
||||
m_self_destroy = true;
|
||||
return true;
|
||||
} // onEnterPressed
|
||||
|
||||
void RacePausedDialog::updateTouchDeviceIcon()
|
||||
{
|
||||
GUIEngine::RibbonWidget* backbtn_ribbon =
|
||||
getWidget<GUIEngine::RibbonWidget>("backbtnribbon");
|
||||
GUIEngine::IconButtonWidget* widget = (IconButtonWidget*)backbtn_ribbon->
|
||||
findWidgetNamed("touch_device");
|
||||
if (!widget)
|
||||
return;
|
||||
|
||||
switch (m_touch_controls)
|
||||
{
|
||||
case MULTITOUCH_CONTROLS_UNDEFINED:
|
||||
case MULTITOUCH_CONTROLS_STEERING_WHEEL:
|
||||
widget->setLabel(_("Steering wheel"));
|
||||
widget->setImage(irr_driver->getTexture(FileManager::GUI_ICON,
|
||||
"android/steering_wheel.png"));
|
||||
break;
|
||||
case MULTITOUCH_CONTROLS_ACCELEROMETER:
|
||||
widget->setLabel(_("Accelerometer"));
|
||||
widget->setImage(irr_driver->getTexture(FileManager::GUI_ICON,
|
||||
"android/accelerator.png"));
|
||||
break;
|
||||
case MULTITOUCH_CONTROLS_GYROSCOPE:
|
||||
widget->setLabel(_("Gyroscope"));
|
||||
widget->setImage(irr_driver->getTexture(FileManager::GUI_ICON,
|
||||
"android/gyroscope_icon.png"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -38,12 +38,15 @@ class RacePausedDialog : public GUIEngine::ModalDialog,
|
||||
private:
|
||||
bool m_self_destroy;
|
||||
bool m_from_overworld;
|
||||
int m_touch_controls;
|
||||
|
||||
GUIEngine::TextBoxWidget* m_text_box;
|
||||
|
||||
virtual void onTextUpdated() OVERRIDE {}
|
||||
virtual bool onEnterPressed(const irr::core::stringw& text) OVERRIDE;
|
||||
|
||||
void updateTouchDeviceIcon();
|
||||
|
||||
protected:
|
||||
virtual void loadedFromFile() OVERRIDE;
|
||||
|
||||
@ -57,6 +60,7 @@ public:
|
||||
GUIEngine::EventPropagation processEvent(const std::string& eventSource)
|
||||
OVERRIDE;
|
||||
virtual void beforeAddingWidgets() OVERRIDE;
|
||||
virtual void init() OVERRIDE;
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void onUpdate(float dt) OVERRIDE
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user