]> git.lizzy.rs Git - minetest.git/commitdiff
Android: Add 'aux' button (#7477)
authorMuhammad Rifqi Priyo Susanto <muhammadrifqipriyosusanto@gmail.com>
Tue, 10 Jul 2018 22:33:40 +0000 (05:33 +0700)
committerParamat <paramat@users.noreply.github.com>
Tue, 10 Jul 2018 22:33:40 +0000 (23:33 +0100)
Add 'aux' button.
Use joystick to trigger 'aux' button when forward and out of main circle, by enabling
'virtual_joystick_triggers_aux' setting.

builtin/settingtypes.txt
src/defaultsettings.cpp
src/gui/touchscreengui.cpp
src/gui/touchscreengui.h
textures/base/pack/aux_btn.png [new file with mode: 0755]

index 0b0ec4a4c01b404e9296f6e2befa6e28de76f1c3..125a962c0b3e2e594594e46eb3bc3bced001e8fd 100644 (file)
@@ -126,6 +126,10 @@ touchscreen_threshold (Touch screen threshold) int 20 0 100
 #    If disabled, virtual joystick will center to first-touch's position.
 fixed_virtual_joystick (Fixed virtual joystick) bool false
 
+#    (Android) Use virtual joystick to trigger "aux" button.
+#    If enabled, virtual joystick will also tap "aux" button when out of main circle.
+virtual_joystick_triggers_aux (Virtual joystick triggers aux button) bool false
+
 #    Enable joysticks
 enable_joysticks (Enable joysticks) bool false
 
index 8bcded9cd94d1dea37b20320a5faf1222b353ff8..277f56d2d1c4b2d9140bcc7762b46370971a7ce4 100644 (file)
@@ -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");
index 13a6a079909dce8e605d24fca35555f46d85e7cf..6d07a4742dc6b2b90879d845f49f3146c2ea83ef 100644 (file)
@@ -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]);
index d3ce8492949860663f9a7217e7429922958bdf1c..5102f188bf913578599d838018e2ac71c05d7ff3 100644 (file)
@@ -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 @@ class TouchScreenGUI
        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 @@ class TouchScreenGUI
        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;
diff --git a/textures/base/pack/aux_btn.png b/textures/base/pack/aux_btn.png
new file mode 100755 (executable)
index 0000000..0377e7a
Binary files /dev/null and b/textures/base/pack/aux_btn.png differ