foxygit / doom Log in
commit f0b710024a2820cd062163db29fddccc03cdf5a3
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Sat Apr 19 01:35:40 2014 -0400
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Sat Apr 19 01:35:40 2014 -0400

    joystick: Add joystick button to toggle menu.

    When using a joystick or gamepad it's nice to be able to bring up the
    menu without having to reach for the keyboard. This makes modern
    gamepads more useful/usable.
---
 src/doom/m_menu.c     |  5 +++++
 src/heretic/mn_menu.c | 11 +++++++++++
 src/hexen/mn_menu.c   | 11 +++++++++++
 src/m_config.c        |  6 ++++++
 src/m_controls.c      | 50 +++++++++++++++++++++++++++-----------------------
 src/m_controls.h      |  2 ++
 src/setup/joystick.c  |  3 ++-
 src/strife/m_menu.c   |  5 +++++
 8 files changed, 69 insertions(+), 24 deletions(-)

diff --git a/src/doom/m_menu.c b/src/doom/m_menu.c
index a0581579..271a100a 100644
--- a/src/doom/m_menu.c
+++ b/src/doom/m_menu.c
@@ -1524,6 +1524,11 @@ boolean M_Responder (event_t* ev)
 	    key = key_menu_back;
 	    joywait = I_GetTime() + 5;
 	}
+        if (joybmenu >= 0 && (ev->data1 & (1 << joybmenu)) != 0)
+        {
+            key = key_menu_activate;
+	    joywait = I_GetTime() + 5;
+        }
     }
     else
     {
diff --git a/src/heretic/mn_menu.c b/src/heretic/mn_menu.c
index 3057261f..a72f2455 100644
--- a/src/heretic/mn_menu.c
+++ b/src/heretic/mn_menu.c
@@ -1080,6 +1080,17 @@ boolean MN_Responder(event_t * event)
         return true;
     }

+    // Allow the menu to be activated from a joystick button if a button
+    // is bound for joybmenu.
+    if (event->type == ev_joystick)
+    {
+        if (joybmenu >= 0 && (event->data1 & (1 << joybmenu)) != 0)
+        {
+            MN_ActivateMenu();
+            return true;
+        }
+    }
+
     if (event->type != ev_keydown)
     {
         return false;
diff --git a/src/hexen/mn_menu.c b/src/hexen/mn_menu.c
index 75433306..c418ce82 100644
--- a/src/hexen/mn_menu.c
+++ b/src/hexen/mn_menu.c
@@ -1175,6 +1175,17 @@ boolean MN_Responder(event_t * event)
         return true;
     }

+    // Allow the menu to be activated from a joystick button if a button
+    // is bound for joybmenu.
+    if (event->type == ev_joystick)
+    {
+        if (joybmenu >= 0 && (event->data1 & (1 << joybmenu)) != 0)
+        {
+            MN_ActivateMenu();
+            return true;
+        }
+    }
+
     // Only care about keypresses beyond this point.

     if (event->type != ev_keydown)
diff --git a/src/m_config.c b/src/m_config.c
index ac4eb304..898c9368 100644
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -950,6 +950,12 @@ static default_t extra_defaults_list[] =

     CONFIG_VARIABLE_INT(joyb_straferight),

+    //!
+    // Joystick button to activate the game menu.
+    //
+
+    CONFIG_VARIABLE_INT(joyb_menu_activate),
+
     //!
     // Joystick button to cycle to the previous weapon.
     //
diff --git a/src/m_controls.c b/src/m_controls.c
index 73e81b1b..a71209a0 100644
--- a/src/m_controls.c
+++ b/src/m_controls.c
@@ -186,10 +186,10 @@ int key_menu_screenshot = 0;
 // Joystick controls
 //

-int joybfire = 0;
-int joybstrafe = 1;
-int joybuse = 3;
-int joybspeed = 2;
+int joybfire = 0;
+int joybstrafe = 1;
+int joybuse = 3;
+int joybspeed = 2;

 int joybstrafeleft = -1;
 int joybstraferight = -1;
@@ -199,6 +199,8 @@ int joybjump = -1;
 int joybprevweapon = -1;
 int joybnextweapon = -1;

+int joybmenu = -1;
+
 // Control whether if a mouse button is double clicked, it acts like
 // "use" has been pressed

@@ -210,25 +212,27 @@ int dclick_use = 1;

 void M_BindBaseControls(void)
 {
-    M_BindVariable("key_right",          &key_right),
-    M_BindVariable("key_left",           &key_left),
-    M_BindVariable("key_up",             &key_up),
-    M_BindVariable("key_down",           &key_down),
-    M_BindVariable("key_strafeleft",     &key_strafeleft),
-    M_BindVariable("key_straferight",    &key_straferight),
-    M_BindVariable("key_fire",           &key_fire),
-    M_BindVariable("key_use",            &key_use),
-    M_BindVariable("key_strafe",         &key_strafe),
-    M_BindVariable("key_speed",          &key_speed),
-
-    M_BindVariable("mouseb_fire",        &mousebfire),
-    M_BindVariable("mouseb_strafe",      &mousebstrafe),
-    M_BindVariable("mouseb_forward",     &mousebforward),
-
-    M_BindVariable("joyb_fire",          &joybfire),
-    M_BindVariable("joyb_strafe",        &joybstrafe),
-    M_BindVariable("joyb_use",           &joybuse),
-    M_BindVariable("joyb_speed",         &joybspeed),
+    M_BindVariable("key_right",          &key_right);
+    M_BindVariable("key_left",           &key_left);
+    M_BindVariable("key_up",             &key_up);
+    M_BindVariable("key_down",           &key_down);
+    M_BindVariable("key_strafeleft",     &key_strafeleft);
+    M_BindVariable("key_straferight",    &key_straferight);
+    M_BindVariable("key_fire",           &key_fire);
+    M_BindVariable("key_use",            &key_use);
+    M_BindVariable("key_strafe",         &key_strafe);
+    M_BindVariable("key_speed",          &key_speed);
+
+    M_BindVariable("mouseb_fire",        &mousebfire);
+    M_BindVariable("mouseb_strafe",      &mousebstrafe);
+    M_BindVariable("mouseb_forward",     &mousebforward);
+
+    M_BindVariable("joyb_fire",          &joybfire);
+    M_BindVariable("joyb_strafe",        &joybstrafe);
+    M_BindVariable("joyb_use",           &joybuse);
+    M_BindVariable("joyb_speed",         &joybspeed);
+
+    M_BindVariable("joyb_menu_activate", &joybmenu);

     // Extra controls that are not in the Vanilla versions:

diff --git a/src/m_controls.h b/src/m_controls.h
index ff3f7774..5b2f34d6 100644
--- a/src/m_controls.h
+++ b/src/m_controls.h
@@ -157,6 +157,8 @@ extern int joybstraferight;
 extern int joybprevweapon;
 extern int joybnextweapon;

+extern int joybmenu;
+
 extern int dclick_use;

 void M_BindBaseControls(void);
diff --git a/src/setup/joystick.c b/src/setup/joystick.c
index 9e04ba0b..23cbaa4a 100644
--- a/src/setup/joystick.c
+++ b/src/setup/joystick.c
@@ -72,7 +72,8 @@ static txt_button_t *joystick_button;

 static int *all_joystick_buttons[] = {
     &joybstraferight, &joybstrafeleft, &joybfire, &joybspeed,
-    &joybuse, &joybstrafe, &joybprevweapon, &joybnextweapon, &joybjump
+    &joybuse, &joybstrafe, &joybprevweapon, &joybnextweapon, &joybjump,
+    &joybmenu,
 };

 //
diff --git a/src/strife/m_menu.c b/src/strife/m_menu.c
index 7f4f18fc..bc365453 100644
--- a/src/strife/m_menu.c
+++ b/src/strife/m_menu.c
@@ -1778,6 +1778,11 @@ boolean M_Responder (event_t* ev)
             key = key_menu_back;
             joywait = I_GetTime() + 5;
         }
+        if (joybmenu >= 0 && (ev->data1 & (1 << joybmenu)) != 0)
+        {
+            key = key_menu_activate;
+            joywait = I_GetTime() + 5;
+        }
     }
     else
     {