Reset multitouch buttons state when game is restarted

This commit is contained in:
Deve 2017-08-29 21:44:27 +02:00
parent 65363a2fa0
commit 184ecce836
5 changed files with 42 additions and 8 deletions

View File

@ -43,14 +43,7 @@ MultitouchDevice::MultitouchDevice()
assert(m_android_device != NULL);
#endif
for (MultitouchEvent& event : m_events)
{
event.id = 0;
event.touched = false;
event.x = 0;
event.y = 0;
}
reset();
updateConfigParams();
} // MultitouchDevice
@ -183,6 +176,28 @@ void MultitouchDevice::clearButtons()
m_buttons.clear();
} // clearButtons
// ----------------------------------------------------------------------------
/** Sets all buttons and events to default state
*/
void MultitouchDevice::reset()
{
for (MultitouchButton* button : m_buttons)
{
button->pressed = false;
button->event_id = 0;
button->axis_x = 0.0f;
button->axis_y = 0.0f;
}
for (MultitouchEvent& event : m_events)
{
event.id = 0;
event.touched = false;
event.x = 0;
event.y = 0;
}
} // reset
// ----------------------------------------------------------------------------
/** The function that is executed when touch event occurs. It updates the
* buttons state when it's needed.

View File

@ -111,6 +111,7 @@ public:
void addButton(MultitouchButtonType type, int x, int y, int width,
int height);
void clearButtons();
void reset();
/** Returns the number of created buttons */
unsigned int getButtonsCount() {return m_buttons.size();}

View File

@ -154,6 +154,11 @@ void RaceGUIBase::reset()
m_plunger_speed = core::vector2df(0,0);
m_plunger_state = PLUNGER_STATE_INIT;
clearAllMessages();
if (m_multitouch_gui != NULL)
{
m_multitouch_gui->reset();
}
} // reset
//-----------------------------------------------------------------------------

View File

@ -76,6 +76,18 @@ RaceGUIMultitouch::~RaceGUIMultitouch()
} // ~RaceGUIMultitouch
//-----------------------------------------------------------------------------
/** Sets the multitouch race gui to its initial state
*/
void RaceGUIMultitouch::reset()
{
if (m_device != NULL)
{
m_device->reset();
}
} // reset
//-----------------------------------------------------------------------------
/** Clears all previously created buttons in the multitouch device
*/

View File

@ -62,6 +62,7 @@ public:
unsigned int getMinimapBottom() {return m_minimap_bottom;}
void setGuiAction(bool enabled = true) {m_gui_action = enabled;}
void reset();
}; // RaceGUIMultitouch