1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-09-05 18:41:05 +00:00

Initial Gamepad support

Adds initial ingame gamepad support to minetest.

Full Formspec support is not implemented yet and
can be added by a later change.
This commit is contained in:
est31 2016-05-27 08:35:07 +02:00
parent 1e86c89f36
commit 2060fd9cbe
17 changed files with 577 additions and 80 deletions

View file

@ -79,6 +79,7 @@ static unsigned int font_line_height(gui::IGUIFont *font)
}
GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev,
JoystickController *joystick,
gui::IGUIElement* parent, s32 id, IMenuManager *menumgr,
InventoryManager *invmgr, IGameDef *gamedef,
ISimpleTextureSource *tsrc, IFormSource* fsrc, TextDest* tdst,
@ -102,6 +103,7 @@ GUIFormSpecMenu::GUIFormSpecMenu(irr::IrrlichtDevice* dev,
m_text_dst(tdst),
m_formspec_version(0),
m_focused_element(""),
m_joystick(joystick),
m_font(NULL),
m_remap_dbl_click(remap_dbl_click)
#ifdef __ANDROID__
@ -2459,7 +2461,7 @@ void GUIFormSpecMenu::drawMenu()
Draw static text elements
*/
for (u32 i = 0; i < m_static_texts.size(); i++) {
const StaticTextSpec &spec = m_static_texts[i];
const StaticTextSpec &spec = m_static_texts[i];
core::rect<s32> rect = spec.rect;
if (spec.parent_button && spec.parent_button->isPressed()) {
#if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8)
@ -3024,6 +3026,25 @@ bool GUIFormSpecMenu::preprocessEvent(const SEvent& event)
}
#endif
if (event.EventType == irr::EET_JOYSTICK_INPUT_EVENT) {
/* TODO add a check like:
if (event.JoystickEvent != joystick_we_listen_for)
return false;
*/
bool handled = m_joystick->handleEvent(event.JoystickEvent);
if (handled) {
if (m_joystick->wasKeyDown(KeyType::ESC)) {
tryClose();
} else if (m_joystick->wasKeyDown(KeyType::JUMP)) {
if (m_allowclose) {
acceptInput(quit_mode_accept);
quitMenu();
}
}
}
return handled;
}
return false;
}
@ -3085,19 +3106,24 @@ bool GUIFormSpecMenu::DoubleClickDetection(const SEvent event)
return false;
}
void GUIFormSpecMenu::tryClose()
{
if (m_allowclose) {
doPause = false;
acceptInput(quit_mode_cancel);
quitMenu();
} else {
m_text_dst->gotText(L"MenuQuit");
}
}
bool GUIFormSpecMenu::OnEvent(const SEvent& event)
{
if (event.EventType==EET_KEY_INPUT_EVENT) {
KeyPress kp(event.KeyInput);
if (event.KeyInput.PressedDown && ( (kp == EscapeKey) ||
(kp == getKeySetting("keymap_inventory")) || (kp == CancelKey))) {
if (m_allowclose) {
doPause = false;
acceptInput(quit_mode_cancel);
quitMenu();
} else {
m_text_dst->gotText(L"MenuQuit");
}
tryClose();
return true;
} else if (m_client != NULL && event.KeyInput.PressedDown &&
(kp == getKeySetting("keymap_screenshot"))) {