diff options
author | Muhammad Rifqi Priyo Susanto <muhammadrifqipriyosusanto@gmail.com> | 2018-07-11 05:33:40 +0700 |
---|---|---|
committer | Paramat <paramat@users.noreply.github.com> | 2018-07-10 23:33:40 +0100 |
commit | 7ebc229b0d2d59e367b8ba64a41535d79fdd4204 (patch) | |
tree | 04a7636198dfc8c36348e81c3f0962d03d18bc6d /src | |
parent | f7a8e757655034abf661c0fcb5129b9ddd798a0b (diff) | |
download | minetest-7ebc229b0d2d59e367b8ba64a41535d79fdd4204.tar.gz minetest-7ebc229b0d2d59e367b8ba64a41535d79fdd4204.tar.bz2 minetest-7ebc229b0d2d59e367b8ba64a41535d79fdd4204.zip |
Android: Add 'aux' button (#7477)
Add 'aux' button.
Use joystick to trigger 'aux' button when forward and out of main circle, by enabling
'virtual_joystick_triggers_aux' setting.
Diffstat (limited to 'src')
-rw-r--r-- | src/defaultsettings.cpp | 1 | ||||
-rw-r--r-- | src/gui/touchscreengui.cpp | 30 | ||||
-rw-r--r-- | src/gui/touchscreengui.h | 16 |
3 files changed, 37 insertions, 10 deletions
diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 8bcded9cd..277f56d2d 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -409,6 +409,7 @@ void set_default_settings(Settings *settings) settings->setDefault("TMPFolder","/sdcard/" PROJECT_NAME_C "/tmp/"); settings->setDefault("touchscreen_threshold","20"); settings->setDefault("fixed_virtual_joystick", "false"); + settings->setDefault("virtual_joystick_triggers_aux", "false"); settings->setDefault("smooth_lighting", "false"); settings->setDefault("max_simultaneous_block_sends_per_client", "3"); settings->setDefault("emergequeue_limit_diskonly", "8"); diff --git a/src/gui/touchscreengui.cpp b/src/gui/touchscreengui.cpp index 13a6a0799..6d07a4742 100644 --- a/src/gui/touchscreengui.cpp +++ b/src/gui/touchscreengui.cpp @@ -42,7 +42,8 @@ using namespace irr::core; const char **touchgui_button_imagenames = (const char *[]) { "jump_btn.png", "down.png", - "zoom.png" + "zoom.png", + "aux_btn.png" }; const char **touchgui_joystick_imagenames = (const char *[]) { @@ -82,6 +83,9 @@ static irr::EKEY_CODE id2keycode(touch_gui_button_id id) case zoom_id: key = "zoom"; break; + case special1_id: + key = "special1"; + break; case fly_id: key = "freemove"; break; @@ -454,6 +458,7 @@ TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, IEventReceiver *receiver) m_touchscreen_threshold = g_settings->getU16("touchscreen_threshold"); m_fixed_joystick = g_settings->getBool("fixed_virtual_joystick"); + m_joystick_triggers_special1 = g_settings->getBool("virtual_joystick_triggers_aux"); m_screensize = m_device->getVideoDriver()->getScreenSize(); } @@ -555,11 +560,20 @@ void TouchScreenGUI::init(ISimpleTextureSource *tsrc) // init zoom button initButton(zoom_id, rect<s32>(m_screensize.X - (1.25 * button_size), - m_screensize.Y - (3 * button_size), + m_screensize.Y - (4 * button_size), m_screensize.X - (0.25 * button_size), - m_screensize.Y - (2 * button_size)), + m_screensize.Y - (3 * button_size)), L"z", false); + // init special1 button + if (!m_joystick_triggers_special1) + initButton(special1_id, + rect<s32>(m_screensize.X - (1.25 * button_size), + m_screensize.Y - (2.5 * button_size), + m_screensize.X - (0.25 * button_size), + m_screensize.Y - (1.5 * button_size)), + L"spc1", false); + m_settingsbar.init(m_texturesource, "gear_icon.png", settings_starter_id, v2s32(m_screensize.X - (button_size / 2), m_screensize.Y - ((SETTINGS_BAR_Y_OFFSET + 1) * button_size) @@ -973,7 +987,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event) angle = fmod(angle + 180 + 22.5, 360); // reset state before applying - for (unsigned int i = 0; i < 4; i ++) + for (unsigned int i = 0; i < 5; i ++) m_joystick_status[i] = false; if (distance <= m_touchscreen_threshold) { @@ -1000,8 +1014,9 @@ void TouchScreenGUI::translateEvent(const SEvent &event) m_joystick_status[j_left] = true; } - // move joystick "button" if (distance > button_size) { + m_joystick_status[j_special1] = true; + // move joystick "button" s32 ndx = (s32) button_size * dx / distance - (s32) button_size / 2; s32 ndy = (s32) button_size * dy / distance - (s32) button_size / 2; if (m_fixed_joystick) { @@ -1125,7 +1140,10 @@ bool TouchScreenGUI::doubleTapDetection() void TouchScreenGUI::applyJoystickStatus() { - for (unsigned int i = 0; i < 4; i ++) { + for (unsigned int i = 0; i < 5; i ++) { + if (i == 4 && !m_joystick_triggers_special1) + continue; + SEvent translated{}; translated.EventType = irr::EET_KEY_INPUT_EVENT; translated.KeyInput.Key = id2keycode(m_joystick_names[i]); diff --git a/src/gui/touchscreengui.h b/src/gui/touchscreengui.h index d3ce84929..5102f188b 100644 --- a/src/gui/touchscreengui.h +++ b/src/gui/touchscreengui.h @@ -37,6 +37,7 @@ typedef enum { jump_id = 0, crunch_id, zoom_id, + special1_id, after_last_element_id, settings_starter_id, rare_controls_starter_id, @@ -60,7 +61,13 @@ typedef enum { joystick_center_id } touch_gui_button_id; -typedef enum { j_forward = 0, j_backward, j_left, j_right } touch_gui_joystick_move_id; +typedef enum { + j_forward = 0, + j_backward, + j_left, + j_right, + j_special1 +} touch_gui_joystick_move_id; typedef enum { AHBB_Dir_Top_Bottom, @@ -206,9 +213,9 @@ private: double m_camera_pitch = 0.0; // forward, backward, left, right - touch_gui_button_id m_joystick_names[4] = { - forward_id, backward_id, left_id, right_id}; - bool m_joystick_status[4] = {false, false, false, false}; + touch_gui_button_id m_joystick_names[5] = { + forward_id, backward_id, left_id, right_id, special1_id}; + bool m_joystick_status[5] = {false, false, false, false, false}; /*! * A line starting at the camera and pointing towards the @@ -227,6 +234,7 @@ private: int m_joystick_id = -1; bool m_joystick_has_really_moved = false; bool m_fixed_joystick = false; + bool m_joystick_triggers_special1 = false; button_info *m_joystick_btn_off = nullptr; button_info *m_joystick_btn_bg = nullptr; button_info *m_joystick_btn_center = nullptr; |