shithub: choc

Download patch

ref: 7579f29afb9f48e01a7f21a0726b109f66b5f2b5
parent: c1cfa2e0914fe451d5fd147beadfcec922878684
author: Simon Howard <[email protected]>
date: Fri Jun 22 15:14:49 EDT 2007

Don't allow two actions bound to the same button in setup.

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

--- a/setup/joystick.c
+++ b/setup/joystick.c
@@ -21,6 +21,7 @@
 
 #include <stdlib.h>
 
+#include "doomtype.h"
 #include "textscreen.h"
 #include "txt_joybinput.h"
 
@@ -64,6 +65,11 @@
 
 static txt_button_t *joystick_button;
 
+static int *all_joystick_buttons[] = {
+        &joybstraferight, &joybstrafeleft, &joybfire, &joybspeed,
+        &joybuse, &joybstrafe,
+};
+
 //
 // Calibration 
 //
@@ -308,7 +314,26 @@
     SetCalibrationLabel();
 }
 
+void JoyButtonSetCallback(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(variable))
+{
+    TXT_CAST_ARG(int, variable);
+    int i;
 
+    // Only allow a button to be bound to one action at a time.  If 
+    // we assign a key that another action is using, set that other action
+    // to -1.
+
+    for (i=0; i<arrlen(all_joystick_buttons); ++i)
+    {
+        if (variable != all_joystick_buttons[i]
+         && *variable == *all_joystick_buttons[i])
+        {
+            *all_joystick_buttons[i] = -1;
+        }
+    }
+}
+
+
 // 
 // GUI
 //
@@ -329,8 +354,14 @@
 
 static void AddJoystickControl(txt_table_t *table, char *label, int *var)
 {
+    txt_joystick_input_t *joy_input;
+
+    joy_input = TXT_NewJoystickInput(var);
+
     TXT_AddWidget(table, TXT_NewLabel(label));
-    TXT_AddWidget(table, TXT_NewJoystickInput(var));
+    TXT_AddWidget(table, joy_input);
+
+    TXT_SignalConnect(joy_input, "set", JoyButtonSetCallback, var);
 }
 
 void ConfigJoystick(void)
--- a/setup/txt_joybinput.c
+++ b/setup/txt_joybinput.c
@@ -48,6 +48,7 @@
     if (event->type == SDL_JOYBUTTONDOWN)
     {
         *joystick_input->variable = event->jbutton.button;
+        TXT_EmitSignal(joystick_input, "set");
         TXT_CloseWindow(joystick_input->prompt_window);
         return 1;
     }