Skip to content

Commit 41a7481

Browse files
committed
Allow steering wheel following touchscreen control with acceleration indicator
1 parent f787832 commit 41a7481

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed
2.42 KB
Loading
2.9 KB
Loading

src/states_screens/race_gui_multitouch.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ using namespace irr;
2424
#include "config/user_config.hpp"
2525
#include "graphics/camera.hpp"
2626
#include "graphics/camera_debug.hpp"
27+
#include "graphics/central_settings.hpp"
2728
#include "graphics/2dutils.hpp"
2829
#include "graphics/irr_driver.hpp"
2930
#include "graphics/material.hpp"
@@ -32,6 +33,7 @@ using namespace irr;
3233
#include "input/multitouch_device.hpp"
3334
#include "items/powerup.hpp"
3435
#include "karts/abstract_kart.hpp"
36+
#include "karts/controller/kart_control.hpp"
3537
#include "modes/world.hpp"
3638
#include "network/protocols/client_lobby.hpp"
3739
#include "states_screens/race_gui_base.hpp"
@@ -47,6 +49,8 @@ RaceGUIMultitouch::RaceGUIMultitouch(RaceGUIBase* race_gui)
4749
m_is_spectator_mode = false;
4850
m_height = 0;
4951
m_steering_wheel_tex = NULL;
52+
m_steering_wheel_tex_mask_up = NULL;
53+
m_steering_wheel_tex_mask_down = NULL;
5054
m_up_down_tex = NULL;
5155
m_pause_tex = NULL;
5256
m_nitro_tex = NULL;
@@ -150,7 +154,15 @@ void RaceGUIMultitouch::init()
150154
m_gui_action_tex = irr_driver->getTexture(FileManager::GUI_ICON,"challenge.png");
151155
m_up_tex = irr_driver->getTexture(FileManager::GUI_ICON, "up.png");
152156
m_down_tex = irr_driver->getTexture(FileManager::GUI_ICON, "down.png");
153-
157+
#ifndef SERVER_ONLY
158+
if (CVS->isGLSL())
159+
{
160+
m_steering_wheel_tex_mask_up = irr_driver->getTexture(FileManager::GUI_ICON,
161+
"android/steering_wheel_mask_up.png");
162+
m_steering_wheel_tex_mask_down = irr_driver->getTexture(FileManager::GUI_ICON,
163+
"android/steering_wheel_mask_down.png");
164+
}
165+
#endif
154166
auto cl = LobbyProtocol::get<ClientLobby>();
155167

156168
if (cl && cl->isSpectator())
@@ -352,8 +364,23 @@ void RaceGUIMultitouch::draw(const AbstractKart* kart,
352364
{
353365
video::ITexture* btn_texture = m_steering_wheel_tex;
354366
core::rect<s32> coords(pos_zero, btn_texture->getSize());
355-
draw2DImage(btn_texture, btn_pos, coords, NULL, NULL, true);
356-
367+
draw2DImage(btn_texture, btn_pos, coords, NULL, NULL, true, false/*draw_translucently*/,
368+
(button->axis_y >= 0 ? -1 : 1) * button->axis_x);
369+
#ifndef SERVER_ONLY
370+
AbstractKart* k = NULL;
371+
Camera* c = Camera::getActiveCamera();
372+
if (c)
373+
k = c->getKart();
374+
if (CVS->isGLSL() && k)
375+
{
376+
float accel = k->getControls().getAccel();
377+
core::rect<s32> mask_coords(pos_zero, m_steering_wheel_tex_mask_up->getSize());
378+
draw2DImageCustomAlpha(m_steering_wheel_tex_mask_up, btn_pos, mask_coords, NULL,
379+
(button->axis_y >= 0 ? -1 : 1) * button->axis_x, accel >= 0.0f ? accel * 0.5f : 0.0f);
380+
draw2DImageCustomAlpha(m_steering_wheel_tex_mask_down, btn_pos, mask_coords, NULL,
381+
(button->axis_y >= 0 ? -1 : 1) * button->axis_x, k->getControls().getBrake() ? 0.5f : 0.0f);
382+
}
383+
#endif
357384
// float x = (float)(button->x) + (float)(button->width) / 2.0f *
358385
// (button->axis_x + 1.0f);
359386
// float y = (float)(button->y) + (float)(button->height) / 2.0f *

src/states_screens/race_gui_multitouch.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class RaceGUIMultitouch
4040
unsigned int m_height;
4141

4242
video::ITexture* m_steering_wheel_tex;
43+
video::ITexture* m_steering_wheel_tex_mask_up;
44+
video::ITexture* m_steering_wheel_tex_mask_down;
4345
video::ITexture* m_up_down_tex;
4446
video::ITexture* m_pause_tex;
4547
video::ITexture* m_nitro_tex;

0 commit comments

Comments
 (0)