shithub: choc

Download patch

ref: f3d3b03870a6842e104c67ce6fc7edfde89d77ec
parent: f291db8f1456b9d1be47eae0ac34bcf0546ce151
author: Simon Howard <fraggle@gmail.com>
date: Mon Aug 9 13:53:10 EDT 2010

Add weapon cycling bindings for mouse and joystick buttons. Add weapon
cycling bindings to configuration file and setup tool.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 1953

--- a/setup/configfile.c
+++ b/setup/configfile.c
@@ -286,11 +286,15 @@
     {"joystick_y_invert",           &joystick_y_invert, DEFAULT_INT, 0, 0},
     {"joyb_strafeleft",             &joybstrafeleft, DEFAULT_INT, 0, 0},
     {"joyb_straferight",            &joybstraferight, DEFAULT_INT, 0, 0},
+    {"joyb_prevweapon",             &joybprevweapon, DEFAULT_INT, 0, 0},
+    {"joyb_nextweapon",             &joybnextweapon, DEFAULT_INT, 0, 0},
     {"dclick_use",                  &dclick_use, DEFAULT_INT, 0, 0},
     {"mouseb_strafeleft",           &mousebstrafeleft, DEFAULT_INT, 0, 0},
     {"mouseb_straferight",          &mousebstraferight, DEFAULT_INT, 0, 0},
     {"mouseb_use",                  &mousebuse, DEFAULT_INT, 0, 0},
     {"mouseb_backward",             &mousebbackward, DEFAULT_INT, 0, 0},
+    {"mouseb_prevweapon",           &mousebprevweapon, DEFAULT_INT, 0, 0},
+    {"mouseb_nextweapon",           &mousebnextweapon, DEFAULT_INT, 0, 0},
     {"use_libsamplerate",           &use_libsamplerate, DEFAULT_INT, 0, 0},
 
     {"key_pause",                   &key_pause, DEFAULT_KEY, 0, 0},
@@ -338,6 +342,8 @@
     {"key_weapon6",                 &key_weapon6, DEFAULT_KEY, 0, 0},
     {"key_weapon7",                 &key_weapon7, DEFAULT_KEY, 0, 0},
     {"key_weapon8",                 &key_weapon8, DEFAULT_KEY, 0, 0},
+    {"key_prevweapon",              &key_prevweapon, DEFAULT_KEY, 0, 0},
+    {"key_nextweapon",              &key_nextweapon, DEFAULT_KEY, 0, 0},
     {"key_message_refresh",         &key_message_refresh, DEFAULT_KEY, 0, 0},
     {"key_demo_quit",               &key_demo_quit, DEFAULT_KEY, 0, 0},
     {"key_multi_msg",               &key_multi_msg, DEFAULT_KEY, 0, 0},
--- a/setup/joystick.c
+++ b/setup/joystick.c
@@ -50,6 +50,8 @@
 int joybspeed = 3;
 int joybstrafeleft = -1;
 int joybstraferight = -1;
+int joybprevweapon = -1;
+int joybnextweapon = -1;
 
 // Joystick to use, as an SDL joystick index:
 
@@ -430,6 +432,8 @@
 
     AddJoystickControl(button_table, "Strafe Left", &joybstrafeleft);
     AddJoystickControl(button_table, "Strafe Right", &joybstraferight);
+    AddJoystickControl(button_table, "Previous weapon", &joybprevweapon);
+    AddJoystickControl(button_table, "Next weapon", &joybnextweapon);
 
     TXT_SignalConnect(joystick_button, "pressed", CalibrateJoystick, NULL);
     TXT_SignalConnect(window, "closed", JoystickWindowClosed, NULL);
--- a/setup/joystick.h
+++ b/setup/joystick.h
@@ -29,6 +29,8 @@
 extern int joybspeed;
 extern int joybstrafeleft;
 extern int joybstraferight;
+extern int joybprevweapon;
+extern int joybnextweapon;
 
 extern int joystick_index;
 extern int joystick_x_axis;
--- a/setup/keyboard.c
+++ b/setup/keyboard.c
@@ -90,6 +90,8 @@
 int key_weapon6        = '6';
 int key_weapon7        = '7';
 int key_weapon8        = '8';
+int key_prevweapon     = 0;
+int key_nextweapon     = 0;
 
 int key_message_refresh = KEY_ENTER;
 int key_demo_quit      = 'q';
@@ -109,7 +111,8 @@
                            &key_pause,
                            &key_weapon1, &key_weapon2, &key_weapon3,
                            &key_weapon4, &key_weapon5, &key_weapon6,
-                           &key_weapon7, &key_weapon8, NULL };
+                           &key_weapon7, &key_weapon8,
+                           &key_prevweapon, &key_nextweapon, NULL };
 
 static int *menu_nav[] = { &key_menu_activate, &key_menu_up, &key_menu_down,
                            &key_menu_left, &key_menu_right, &key_menu_back,
@@ -240,6 +243,8 @@
     AddKeyControl(table, "Weapon 6",              &key_weapon6);
     AddKeyControl(table, "Weapon 7",              &key_weapon7);
     AddKeyControl(table, "Weapon 8",              &key_weapon8);
+    AddKeyControl(table, "Previous weapon",       &key_prevweapon);
+    AddKeyControl(table, "Next weapon",           &key_nextweapon);
 
     TXT_AddWidgets(table, TXT_NewStrut(0, 1),
                           TXT_NewStrut(0, 1),
--- a/setup/keyboard.h
+++ b/setup/keyboard.h
@@ -95,6 +95,8 @@
 extern int key_weapon6;
 extern int key_weapon7;
 extern int key_weapon8;
+extern int key_prevweapon;
+extern int key_nextweapon;
 
 extern int key_message_refresh;
 extern int key_demo_quit;
--- a/setup/mouse.c
+++ b/setup/mouse.c
@@ -44,6 +44,8 @@
 int mousebstraferight = -1;
 int mousebbackward = -1;
 int mousebuse = -1;
+int mousebprevweapon = -1;
+int mousebnextweapon = -1;
 
 int dclick_use = 1;
 
@@ -55,6 +57,8 @@
     &mousebstraferight,
     &mousebbackward,
     &mousebuse,
+    &mousebprevweapon,
+    &mousebnextweapon
 };
 
 static void MouseSetCallback(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(variable))
@@ -104,6 +108,8 @@
     AddMouseControl(buttons_table, "Use", &mousebuse);
     AddMouseControl(buttons_table, "Strafe left", &mousebstrafeleft);
     AddMouseControl(buttons_table, "Strafe right", &mousebstraferight);
+    AddMouseControl(buttons_table, "Previous weapon", &mousebprevweapon);
+    AddMouseControl(buttons_table, "Next weapon", &mousebnextweapon);
 }
 
 void ConfigMouse(void)
--- a/setup/mouse.h
+++ b/setup/mouse.h
@@ -37,6 +37,8 @@
 extern int mousebbackward;
 extern int mousebuse;
 extern int dclick_use;
+extern int mousebprevweapon;
+extern int mousebnextweapon;
 
 void ConfigMouse(void);
 
--- a/setup/txt_keyinput.c
+++ b/setup/txt_keyinput.c
@@ -111,7 +111,7 @@
 
     if (*key_input->variable == 0)
     {
-        strcpy(buf, "");
+        strcpy(buf, "(none)");
     }
     else
     {
--- a/src/g_game.c
+++ b/src/g_game.c
@@ -198,6 +198,9 @@
 int             mousebbackward = -1;
 int             mousebuse = -1;
 
+int             mousebprevweapon = -1;
+int             mousebnextweapon = -1;
+
 // Control whether if a mouse button is double clicked, it acts like 
 // "use" has been pressed
 
@@ -210,6 +213,9 @@
 int             joybstrafeleft = -1;
 int             joybstraferight = -1;
 
+int             joybprevweapon = -1;
+int             joybnextweapon = -1;
+
 // fraggle: Disallow mouse and joystick movement to cause forward/backward
 // motion.  Specified with the '-novert' command line parameter.
 // This is an int to allow saving to config file
@@ -262,11 +268,13 @@
 #define SLOWTURNTICS	6 
  
 #define NUMKEYS		256 
+#define MAX_JOY_BUTTONS 20
+#define MAX_MOUSE_BUTTONS 3
 
 static boolean  gamekeydown[NUMKEYS]; 
 static int      turnheld;		// for accelerative turning 
  
-static boolean  mousearray[4]; 
+static boolean  mousearray[MAX_MOUSE_BUTTONS + 1];
 static boolean *mousebuttons = &mousearray[1];  // allow [-1]
 
 // mouse values are used once 
@@ -280,8 +288,6 @@
 static boolean  dclickstate2;
 static int      dclicks2;
 
-#define MAX_JOY_BUTTONS 20
-
 // joystick values are repeated 
 static int      joyxmove;
 static int      joyymove;
@@ -815,7 +821,6 @@
         players[consoleplayer].message = "Press escape to quit.";
     }
 } 
- 
 
 static void SetJoyButtons(unsigned int buttons_mask)
 {
@@ -823,10 +828,54 @@
 
     for (i=0; i<MAX_JOY_BUTTONS; ++i)
     {
-        joybuttons[i] = (buttons_mask & (1 << i)) != 0;
+        int button_on = (buttons_mask & (1 << i)) != 0;
+
+        // Detect button press:
+
+        if (!joybuttons[i] && button_on)
+        {
+            // Weapon cycling:
+
+            if (i == joybprevweapon)
+            {
+                next_weapon = -1;
+            }
+            else if (i == joybnextweapon)
+            {
+                next_weapon = 1;
+            }
+        }
+
+        joybuttons[i] = button_on;
     }
 }
- 
+
+static void SetMouseButtons(unsigned int buttons_mask)
+{
+    int i;
+
+    for (i=0; i<MAX_MOUSE_BUTTONS; ++i)
+    {
+        unsigned int button_on = (buttons_mask & (1 << i)) != 0;
+
+        // Detect button press:
+
+        if (!mousebuttons[i] && button_on)
+        {
+            if (i == mousebprevweapon)
+            {
+                next_weapon = -1;
+            }
+            else if (i == mousebnextweapon)
+            {
+                next_weapon = 1;
+            }
+        }
+
+	mousebuttons[i] = button_on;
+    }
+}
+
 //
 // G_Responder  
 // Get info needed to make ticcmd_ts for the players.
@@ -927,9 +976,7 @@
 	return false;   // always let key up events filter down 
 		 
       case ev_mouse: 
-	mousebuttons[0] = ev->data1 & 1; 
-	mousebuttons[1] = ev->data1 & 2; 
-	mousebuttons[2] = ev->data1 & 4; 
+        SetMouseButtons(ev->data1);
 	mousex = ev->data2*(mouseSensitivity+5)/10; 
 	mousey = ev->data3*(mouseSensitivity+5)/10; 
 	return true;    // eat events 
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -148,6 +148,8 @@
 extern int key_weapon6;
 extern int key_weapon7;
 extern int key_weapon8;
+extern int key_prevweapon;
+extern int key_nextweapon;
 
 extern int key_message_refresh;
 extern int key_demo_quit;
@@ -164,6 +166,9 @@
 extern int      mousebbackward;
 extern int      mousebuse;
 
+extern int      mousebprevweapon;
+extern int      mousebnextweapon;
+
 extern int      dclick_use;
 
 extern int	joybfire;
@@ -173,6 +178,9 @@
 extern int      joybstrafeleft;
 extern int      joybstraferight;
 
+extern int      joybprevweapon;
+extern int      joybnextweapon;
+
 extern int	viewwidth;
 extern int	viewheight;
 
@@ -748,6 +756,18 @@
     CONFIG_VARIABLE_INT(joyb_straferight,          joybstraferight),
 
     //!
+    // Joystick button to cycle to the previous weapon.
+    //
+
+    CONFIG_VARIABLE_INT(joyb_prevweapon,           joybprevweapon),
+
+    //!
+    // Joystick button to cycle to the next weapon.
+    //
+
+    CONFIG_VARIABLE_INT(joyb_nextweapon,          joybnextweapon),
+
+    //!
     // Mouse button to strafe left.
     //
 
@@ -772,6 +792,18 @@
     CONFIG_VARIABLE_INT(mouseb_backward,           mousebbackward),
 
     //!
+    // Mouse button to cycle to the previous weapon.
+    //
+
+    CONFIG_VARIABLE_INT(mouseb_prevweapon,         mousebprevweapon),
+
+    //!
+    // Mouse button to cycle to the next weapon.
+    //
+
+    CONFIG_VARIABLE_INT(mouseb_nextweapon,         mousebnextweapon),
+
+    //!
     // If non-zero, double-clicking a mouse button acts like pressing
     // the "use" key to use an object in-game, eg. a door or switch.
     //
@@ -1060,6 +1092,18 @@
     //
 
     CONFIG_VARIABLE_KEY(key_weapon8,               key_weapon8),
+
+    //!
+    // Key to cycle to the previous weapon.
+    //
+
+    CONFIG_VARIABLE_KEY(key_prevweapon,            key_prevweapon),
+
+    //!
+    // Key to cycle to the next weapon.
+    //
+
+    CONFIG_VARIABLE_KEY(key_nextweapon,            key_nextweapon),
 
     //!
     // Key to re-display last message.