Keep acceleration sensitivity for up/down button when accelerometer is enabled

This commit is contained in:
Deve 2018-04-10 21:08:10 +02:00
parent a4159a9b1a
commit 1ee5f3aa8a
5 changed files with 39 additions and 31 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

View File

@ -251,23 +251,39 @@ void MultitouchDevice::updateDeviceState(unsigned int event_id)
if (button->type == MultitouchButtonType::BUTTON_STEERING) if (button->type == MultitouchButtonType::BUTTON_STEERING)
{ {
float prev_axis_x = button->axis_x; float prev_axis_x = button->axis_x;
float prev_axis_y = button->axis_y;
if (button->pressed == true) if (button->pressed == true)
{ {
button->axis_x = button->axis_x =
(float)(event.x - button->x) / (button->width/2) - 1; (float)(event.x - button->x) / (button->width/2) - 1;
}
else
{
button->axis_x = 0.0f;
}
if (prev_axis_x != button->axis_x)
{
update_controls = true;
}
}
if (button->type == MultitouchButtonType::BUTTON_STEERING ||
button->type == MultitouchButtonType::BUTTON_UP_DOWN)
{
float prev_axis_y = button->axis_y;
if (button->pressed == true)
{
button->axis_y = button->axis_y =
(float)(event.y - button->y) / (button->height/2) - 1; (float)(event.y - button->y) / (button->height/2) - 1;
} }
else else
{ {
button->axis_x = 0.0f;
button->axis_y = 0.0f; button->axis_y = 0.0f;
} }
if (prev_axis_x != button->axis_x || if (prev_axis_y != button->axis_y)
prev_axis_y != button->axis_y)
{ {
update_controls = true; update_controls = true;
} }
@ -375,13 +391,11 @@ void MultitouchDevice::handleControls(MultitouchButton* button)
if (button->type == MultitouchButtonType::BUTTON_STEERING) if (button->type == MultitouchButtonType::BUTTON_STEERING)
{ {
#ifdef ANDROID updateAxisX(button->axis_x);
if (!m_android_device->isAccelerometerActive()) updateAxisY(button->axis_y);
#endif }
{ else if (button->type == MultitouchButtonType::BUTTON_UP_DOWN)
updateAxisX(button->axis_x); {
}
updateAxisY(button->axis_y); updateAxisY(button->axis_y);
} }
else else

View File

@ -34,6 +34,7 @@
enum MultitouchButtonType enum MultitouchButtonType
{ {
BUTTON_STEERING, BUTTON_STEERING,
BUTTON_UP_DOWN,
BUTTON_FIRE, BUTTON_FIRE,
BUTTON_NITRO, BUTTON_NITRO,
BUTTON_SKIDDING, BUTTON_SKIDDING,

View File

@ -43,6 +43,7 @@ RaceGUIMultitouch::RaceGUIMultitouch(RaceGUIBase* race_gui)
m_minimap_bottom = 0; m_minimap_bottom = 0;
m_gui_action = false; m_gui_action = false;
m_steering_wheel_tex = NULL; m_steering_wheel_tex = NULL;
m_up_down_tex = NULL;
m_pause_tex = NULL; m_pause_tex = NULL;
m_nitro_tex = NULL; m_nitro_tex = NULL;
m_nitro_empty_tex = NULL; m_nitro_empty_tex = NULL;
@ -52,8 +53,6 @@ RaceGUIMultitouch::RaceGUIMultitouch(RaceGUIBase* race_gui)
m_bg_button_tex = NULL; m_bg_button_tex = NULL;
m_bg_button_focus_tex = NULL; m_bg_button_focus_tex = NULL;
m_gui_action_tex = NULL; m_gui_action_tex = NULL;
m_up_tex = NULL;
m_down_tex = NULL;
m_device = input_manager->getDeviceManager()->getMultitouchDevice(); m_device = input_manager->getDeviceManager()->getMultitouchDevice();
@ -139,7 +138,6 @@ void RaceGUIMultitouch::init()
float first_column_x = w - 2 * col_size; float first_column_x = w - 2 * col_size;
float second_column_x = w - 1 * col_size; float second_column_x = w - 1 * col_size;
float left_column_x = margin + col_size / 2;
float steering_btn_margin = 0.6f * margin; float steering_btn_margin = 0.6f * margin;
float steering_btn_x = steering_btn_margin; float steering_btn_x = steering_btn_margin;
float steering_btn_y = h - steering_btn_margin - btn2_size; float steering_btn_y = h - steering_btn_margin - btn2_size;
@ -148,7 +146,6 @@ void RaceGUIMultitouch::init()
{ {
first_column_x = margin + 1 * col_size; first_column_x = margin + 1 * col_size;
second_column_x = margin; second_column_x = margin;
left_column_x = w - 1.5f * col_size;
steering_btn_x = w - btn2_size - steering_btn_margin; steering_btn_x = w - btn2_size - steering_btn_margin;
} }
@ -156,12 +153,9 @@ void RaceGUIMultitouch::init()
if (m_device->isAccelerometerActive()) if (m_device->isAccelerometerActive())
{ {
m_device->addButton(BUTTON_UP, m_device->addButton(BUTTON_UP_DOWN,
int(left_column_x), int(h - 2 * col_size), int(steering_btn_x + btn2_size / 4), int(steering_btn_y),
int(btn_size), int(btn_size)); int(btn2_size / 2), int(btn2_size));
m_device->addButton(BUTTON_DOWN,
int(left_column_x), int(h - 1 * col_size),
int(btn_size), int(btn_size));
} }
else else
{ {
@ -191,6 +185,8 @@ void RaceGUIMultitouch::init()
m_steering_wheel_tex = irr_driver->getTexture(FileManager::GUI, m_steering_wheel_tex = irr_driver->getTexture(FileManager::GUI,
"android/steering_wheel.png"); "android/steering_wheel.png");
m_up_down_tex = irr_driver->getTexture(FileManager::GUI,
"android/up_down.png");
m_pause_tex = irr_driver->getTexture(FileManager::GUI, "android/pause.png"); m_pause_tex = irr_driver->getTexture(FileManager::GUI, "android/pause.png");
m_nitro_tex = irr_driver->getTexture(FileManager::GUI, "android/nitro.png"); m_nitro_tex = irr_driver->getTexture(FileManager::GUI, "android/nitro.png");
m_nitro_empty_tex = irr_driver->getTexture(FileManager::GUI, m_nitro_empty_tex = irr_driver->getTexture(FileManager::GUI,
@ -205,8 +201,6 @@ void RaceGUIMultitouch::init()
m_bg_button_focus_tex = irr_driver->getTexture(FileManager::GUI, m_bg_button_focus_tex = irr_driver->getTexture(FileManager::GUI,
"android/blur_bg_button_focus.png"); "android/blur_bg_button_focus.png");
m_gui_action_tex = irr_driver->getTexture(FileManager::GUI,"challenge.png"); m_gui_action_tex = irr_driver->getTexture(FileManager::GUI,"challenge.png");
m_up_tex = irr_driver->getTexture(FileManager::GUI, "up.png");
m_down_tex = irr_driver->getTexture(FileManager::GUI, "down.png");
} // init } // init
@ -256,6 +250,12 @@ void RaceGUIMultitouch::draw(const AbstractKart* kart,
// draw2DImage(btn_texture, pos2, coords, NULL, NULL, true); // draw2DImage(btn_texture, pos2, coords, NULL, NULL, true);
} }
if (button->type == MultitouchButtonType::BUTTON_UP_DOWN)
{
video::ITexture* btn_texture = m_up_down_tex;
core::rect<s32> coords(pos_zero, btn_texture->getSize());
draw2DImage(btn_texture, btn_pos, coords, NULL, NULL, true);
}
else else
{ {
bool can_be_pressed = true; bool can_be_pressed = true;
@ -307,12 +307,6 @@ void RaceGUIMultitouch::draw(const AbstractKart* kart,
case MultitouchButtonType::BUTTON_SKIDDING: case MultitouchButtonType::BUTTON_SKIDDING:
btn_texture = m_drift_tex; btn_texture = m_drift_tex;
break; break;
case MultitouchButtonType::BUTTON_UP:
btn_texture = m_up_tex;
break;
case MultitouchButtonType::BUTTON_DOWN:
btn_texture = m_down_tex;
break;
default: default:
break; break;
} }

View File

@ -39,6 +39,7 @@ private:
unsigned int m_minimap_bottom; unsigned int m_minimap_bottom;
video::ITexture* m_steering_wheel_tex; video::ITexture* m_steering_wheel_tex;
video::ITexture* m_up_down_tex;
video::ITexture* m_pause_tex; video::ITexture* m_pause_tex;
video::ITexture* m_nitro_tex; video::ITexture* m_nitro_tex;
video::ITexture* m_nitro_empty_tex; video::ITexture* m_nitro_empty_tex;
@ -48,8 +49,6 @@ private:
video::ITexture* m_bg_button_tex; video::ITexture* m_bg_button_tex;
video::ITexture* m_bg_button_focus_tex; video::ITexture* m_bg_button_focus_tex;
video::ITexture* m_gui_action_tex; video::ITexture* m_gui_action_tex;
video::ITexture* m_up_tex;
video::ITexture* m_down_tex;
void init(); void init();
void close(); void close();