Switch to fly mode if spacebar is doubleclicked
authorPilzAdam <PilzAdam@gmx.de>
Thu, 3 Jan 2013 18:51:52 +0000 (19:51 +0100)
committerPilzAdam <PilzAdam@gmx.de>
Fri, 4 Jan 2013 17:51:38 +0000 (18:51 +0100)
Can be turned off in the key change GUI or in minetest.conf via doubletab_space

minetest.conf.example
src/defaultsettings.cpp
src/game.cpp
src/guiKeyChangeMenu.cpp

index 5fb4244b2d30091de983f66df288eeae35f90b6b..a4448ab61d9403f36024ed968f626124aaae2058 100644 (file)
@@ -51,6 +51,8 @@
 #keymap_screenshot = KEY_F12
 # If true, keymap_special1 instead of keymap_sneak is used for climbing down and descending
 #aux1_descends = false
+# Doubletabing the jump key toogles fly mode
+#doubletab_jump = false
 # Some (temporary) keys for debugging
 #keymap_print_debug_stacks = KEY_KEY_P
 #keymap_quicktune_prev = KEY_HOME
index cac3e568a155569e467fe0a36f380470c8f514ae..82783db0d27cec472814ea42d134628a81c2d168 100644 (file)
@@ -56,6 +56,7 @@ void set_default_settings(Settings *settings)
        settings->setDefault("anaglyph", "false");
        settings->setDefault("anaglyph_strength", "0.1");
        settings->setDefault("aux1_descends", "false");
+       settings->setDefault("doubletab_jump", "false");
 
        // Some (temporary) keys for debugging
        settings->setDefault("keymap_print_debug_stacks", "KEY_KEY_P");
index fdb083ff1b490542ee701007b68c68a7b5a9005b..ab480c3db7e459e648e7f45ffd1d67e017e34c4a 100644 (file)
@@ -1310,6 +1310,9 @@ void the_game(
        float damage_flash = 0;
        s16 farmesh_range = 20*MAP_BLOCKSIZE;
 
+       float jump_timer = 0;
+       bool reset_jump_timer = false;
+
        const float object_hit_delay = 0.2;
        float object_hit_delay_timer = 0.0;
        float time_from_last_punch = 10;
@@ -1592,6 +1595,10 @@ void the_game(
                // Input handler step() (used by the random input generator)
                input->step(dtime);
 
+               // Increase timer for doubleclick of "jump"
+               if(g_settings->getBool("doubletab_jump") && jump_timer <= 0.2)
+                       jump_timer += dtime;
+
                /*
                        Launch menus and trigger stuff according to keys
                */
@@ -1681,6 +1688,27 @@ void the_game(
                                        statustext += L" (note: no 'fly' privilege)";
                        }
                }
+               else if(input->wasKeyDown(getKeySetting("keymap_jump")))
+               {
+                       if(g_settings->getBool("doubletab_jump") && jump_timer < 0.2)
+                       {
+                               if(g_settings->getBool("free_move"))
+                               {
+                                       g_settings->set("free_move","false");
+                                       statustext = L"free_move disabled";
+                                       statustext_time = 0;
+                               }
+                               else
+                               {
+                                       g_settings->set("free_move","true");
+                                       statustext = L"free_move enabled";
+                                       statustext_time = 0;
+                                       if(!client.checkPrivilege("fly"))
+                                               statustext += L" (note: no 'fly' privilege)";
+                               }
+                       }
+                       reset_jump_timer = true;
+               }
                else if(input->wasKeyDown(getKeySetting("keymap_fastmove")))
                {
                        if(g_settings->getBool("fast_move"))
@@ -1843,6 +1871,13 @@ void the_game(
                        statustext_time = 0;
                }
                
+               // Reset jump_timer
+               if(!input->isKeyDown(getKeySetting("keymap_jump")) && reset_jump_timer)
+               {
+                       reset_jump_timer = false;
+                       jump_timer = 0.0;
+               }
+
                // Handle QuicktuneShortcutter
                if(input->wasKeyDown(getKeySetting("keymap_quicktune_next")))
                        quicktune.next();
index 8f7c7245c1dc0fc437b54b965f527d2a0ba9bac9..336b13e0727aeda4d54a84cbd275a8dfe1cbabcd 100644 (file)
@@ -57,6 +57,7 @@ enum
        GUI_ID_KEY_RANGE_BUTTON,
        // other
        GUI_ID_CB_AUX1_DESCENDS,
+       GUI_ID_CB_DOUBLETAB_JUMP,
 };
 
 GUIKeyChangeMenu::GUIKeyChangeMenu(gui::IGUIEnvironment* env,
@@ -149,6 +150,20 @@ void GUIKeyChangeMenu::regenerateGui(v2u32 screensize)
                        Environment->addCheckBox(g_settings->getBool("aux1_descends"), rect, this,
                                        GUI_ID_CB_AUX1_DESCENDS, wgettext("\"Use\" = climb down"));
                }
+               offset += v2s32(0, 25);
+       }
+
+       {
+               s32 option_x = offset.X + 10;
+               s32 option_y = offset.Y;
+               u32 option_w = 220;
+               {
+                       core::rect<s32> rect(0, 0, option_w, 30);
+                       rect += topleft + v2s32(option_x, option_y);
+                       Environment->addCheckBox(g_settings->getBool("doubletab_jump"), rect, this,
+                                       GUI_ID_CB_DOUBLETAB_JUMP, wgettext("Doubltab \"jump\" to toogle fly"));
+               }
+               offset += v2s32(0, 25);
        }
 
        {
@@ -197,6 +212,11 @@ bool GUIKeyChangeMenu::acceptInput()
                if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
                        g_settings->setBool("aux1_descends", ((gui::IGUICheckBox*)e)->isChecked());
        }
+       {
+               gui::IGUIElement *e = getElementFromId(GUI_ID_CB_DOUBLETAB_JUMP);
+               if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
+                       g_settings->setBool("doubletab_jump", ((gui::IGUICheckBox*)e)->isChecked());
+       }
        clearKeyCache();
        return true;
 }