ref: 856eebe52624ba5d780436feb349ea5ff2ee46b4
parent: d004976261747a47389b14eaf0d695a14fa0f497
author: Simon Howard <fraggle@gmail.com>
date: Tue Jun 19 20:37:40 EDT 2007
Add new configuration options for the mouse and joystick for controls that are available through the keyboard. Justification: this is already possible through advanced mouse drivers and programs like js2x, so there might as well be a proper interface for it. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 918
--- a/setup/configfile.c
+++ b/setup/configfile.c
@@ -272,6 +272,11 @@
{"joystick_x_invert", &joystick_x_invert, DEFAULT_INT, 0, 0},
{"joystick_y_axis", &joystick_y_axis, DEFAULT_INT, 0, 0},
{"joystick_y_invert", &joystick_y_invert, DEFAULT_INT, 0, 0},
+ {"joyb_strafeleft", &joybstrafeleft, DEFAULT_INT, 0, 0},
+ {"joyb_straferight", &joybstraferight, 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},
};
static default_collection_t extra_defaults =
--- a/setup/joystick.c
+++ b/setup/joystick.c
@@ -43,6 +43,8 @@
int joybstrafe = 1;
int joybuse = 2;
int joybspeed = 3;
+int joybstrafeleft = -1;
+int joybstraferight = -1;
// Joystick to use, as an SDL joystick index:
@@ -325,6 +327,12 @@
TXT_SetButtonLabel(joystick_button, name);
}
+static void AddJoystickControl(txt_table_t *table, char *label, int *var)
+{
+ TXT_AddWidget(table, TXT_NewLabel(label));
+ TXT_AddWidget(table, TXT_NewJoystickInput(var));
+}
+
void ConfigJoystick(void)
{
txt_window_t *window;
@@ -351,14 +359,8 @@
TXT_SetColumnWidths(button_table, 20, 15);
- TXT_AddWidgets(button_table,
- TXT_NewLabel("Fire"),
- TXT_NewJoystickInput(&joybfire),
- TXT_NewLabel("Use"),
- TXT_NewJoystickInput(&joybuse),
- TXT_NewLabel("Strafe"),
- TXT_NewJoystickInput(&joybstrafe),
- NULL);
+ AddJoystickControl(button_table, "Fire", &joybfire);
+ AddJoystickControl(button_table, "Use", &joybuse);
// High values of joybspeed are used to activate the "always run mode"
// trick in Vanilla Doom. If this has been enabled, not only is the
@@ -366,11 +368,13 @@
if (joybspeed < 20)
{
- TXT_AddWidgets(button_table,
- TXT_NewLabel("Speed"),
- TXT_NewJoystickInput(&joybspeed),
- NULL);
+ AddJoystickControl(button_table, "Speed", &joybspeed);
}
+
+ AddJoystickControl(button_table, "Strafe", &joybstrafe);
+
+ AddJoystickControl(button_table, "Strafe Left", &joybstrafeleft);
+ AddJoystickControl(button_table, "Strafe Right", &joybstraferight);
TXT_SignalConnect(joystick_button, "pressed", CalibrateJoystick, NULL);
--- a/setup/joystick.h
+++ b/setup/joystick.h
@@ -27,6 +27,8 @@
extern int joybstrafe;
extern int joybuse;
extern int joybspeed;
+extern int joybstrafeleft;
+extern int joybstraferight;
extern int joystick_index;
extern int joystick_x_axis;
--- a/setup/mouse.c
+++ b/setup/mouse.c
@@ -39,10 +39,23 @@
int mousebfire = 0;
int mousebforward = 1;
int mousebstrafe = 2;
+int mousebstrafeleft = -1;
+int mousebstraferight = -1;
+int mousebbackward = -1;
+int mousebuse = -1;
-static int *all_mouse_buttons[] = {&mousebfire, &mousebstrafe,
- &mousebforward};
+int dclick_use = 1;
+static int *all_mouse_buttons[] = {
+ &mousebfire,
+ &mousebstrafe,
+ &mousebforward,
+ &mousebstrafeleft,
+ &mousebstraferight,
+ &mousebbackward,
+ &mousebuse,
+};
+
static void MouseSetCallback(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(variable))
{
TXT_CAST_ARG(int, variable);
@@ -73,11 +86,31 @@
TXT_SignalConnect(mouse_input, "set", MouseSetCallback, var);
}
+static void ConfigExtraButtons(void)
+{
+ txt_window_t *window;
+ txt_table_t *buttons_table;
+
+ window = TXT_NewWindow("Additional mouse buttons");
+
+ TXT_AddWidgets(window,
+ buttons_table = TXT_NewTable(2),
+ NULL);
+
+ TXT_SetColumnWidths(buttons_table, 29, 5);
+
+ AddMouseControl(buttons_table, "Move backward", &mousebbackward);
+ AddMouseControl(buttons_table, "Use", &mousebuse);
+ AddMouseControl(buttons_table, "Strafe left", &mousebstrafeleft);
+ AddMouseControl(buttons_table, "Strafe right", &mousebstraferight);
+}
+
void ConfigMouse(void)
{
txt_window_t *window;
txt_table_t *motion_table;
- txt_table_t *button_table;
+ txt_table_t *buttons_table;
+ txt_button_t *more_buttons;
window = TXT_NewWindow("Mouse configuration");
@@ -86,14 +119,17 @@
TXT_NewInvertedCheckBox("Allow vertical mouse movement",
&novert),
TXT_NewCheckBox("Grab mouse in windowed mode",
- &grabmouse),
+ &grabmouse),
+ TXT_NewCheckBox("Double click acts as \"use\"",
+ &dclick_use),
TXT_NewSeparator("Mouse motion"),
motion_table = TXT_NewTable(2),
- TXT_NewSeparator("Mouse buttons"),
+ TXT_NewSeparator("Buttons"),
+ buttons_table = TXT_NewTable(2),
+ more_buttons = TXT_NewButton("More buttons..."),
- button_table = TXT_NewTable(2),
NULL);
TXT_SetColumnWidths(motion_table, 27, 5);
@@ -107,12 +143,14 @@
TXT_NewSpinControl(&mouse_threshold, 0, 32),
NULL);
- TXT_SetColumnWidths(button_table, 27, 5);
+ TXT_SetColumnWidths(buttons_table, 27, 5);
- AddMouseControl(button_table, "Fire weapon", &mousebfire);
- AddMouseControl(button_table, "Move forward", &mousebforward);
- AddMouseControl(button_table, "Strafe on", &mousebstrafe);
+ AddMouseControl(buttons_table, "Move forward", &mousebforward);
+ AddMouseControl(buttons_table, "Strafe on", &mousebstrafe);
+ AddMouseControl(buttons_table, "Fire weapon", &mousebfire);
TXT_SetWindowAction(window, TXT_HORIZ_CENTER, TestConfigAction());
+
+ TXT_SignalConnect(more_buttons, "pressed", ConfigExtraButtons, NULL);
}
--- a/setup/mouse.h
+++ b/setup/mouse.h
@@ -32,6 +32,11 @@
extern int mousebfire;
extern int mousebforward;
extern int mousebstrafe;
+extern int mousebstrafeleft;
+extern int mousebstraferight;
+extern int mousebbackward;
+extern int mousebuse;
+extern int dclick_use;
void ConfigMouse(void);
--- a/setup/txt_joybinput.c
+++ b/setup/txt_joybinput.c
@@ -143,9 +143,9 @@
char buf[20];
int i;
- if (*joystick_input->variable == -1)
+ if (*joystick_input->variable < 0)
{
- strcpy(buf, "");
+ strcpy(buf, "(none)");
}
else
{
--- a/setup/txt_mouseinput.c
+++ b/setup/txt_mouseinput.c
@@ -117,9 +117,9 @@
char buf[20];
int i;
- if (*mouse_input->variable == -1)
+ if (*mouse_input->variable < 0)
{
- strcpy(buf, "");
+ strcpy(buf, "(none)");
}
else
{
--- a/src/g_game.c
+++ b/src/g_game.c
@@ -177,11 +177,23 @@
int mousebfire = 0;
int mousebstrafe = 1;
int mousebforward = 2;
+
+int mousebstrafeleft = -1;
+int mousebstraferight = -1;
+int mousebbackward = -1;
+int mousebuse = -1;
+
+// Control whether if a mouse button is double clicked, it acts like
+// "use" has been pressed
+
+int dclick_use = 1;
int joybfire = 0;
int joybstrafe = 1;
int joybuse = 3;
int joybspeed = 2;
+int joybstrafeleft = -1;
+int joybstraferight = -1;
// fraggle: Disallow mouse and joystick movement to cause forward/backward
// motion. Specified with the '-novert' command line parameter.
@@ -465,11 +477,21 @@
if (joyymove > 0)
forward -= forwardmove[speed];
}
- if (gamekeydown[key_straferight])
- side += sidemove[speed];
- if (gamekeydown[key_strafeleft])
- side -= sidemove[speed];
-
+
+ if (gamekeydown[key_strafeleft]
+ || joybuttons[joybstrafeleft]
+ || mousebuttons[mousebstrafeleft])
+ {
+ side -= sidemove[speed];
+ }
+
+ if (gamekeydown[key_straferight]
+ || joybuttons[joybstraferight]
+ || mousebuttons[mousebstraferight])
+ {
+ side += sidemove[speed];
+ }
+
// buttons
cmd->chatchar = HU_dequeueChatChar();
@@ -477,7 +499,9 @@
|| joybuttons[joybfire])
cmd->buttons |= BT_ATTACK;
- if (gamekeydown[key_use] || joybuttons[joybuse] )
+ if (gamekeydown[key_use]
+ || joybuttons[joybuse]
+ || mousebuttons[mousebuse])
{
cmd->buttons |= BT_USE;
// clear double clicks if hit use button
@@ -495,59 +519,68 @@
// mouse
if (mousebuttons[mousebforward])
+ {
forward += forwardmove[speed];
-
- // forward double click
- if (mousebuttons[mousebforward] != dclickstate && dclicktime > 1 )
- {
- dclickstate = mousebuttons[mousebforward];
- if (dclickstate)
- dclicks++;
- if (dclicks == 2)
- {
- cmd->buttons |= BT_USE;
- dclicks = 0;
- }
- else
- dclicktime = 0;
- }
- else
- {
- dclicktime += ticdup;
- if (dclicktime > 20)
- {
- dclicks = 0;
- dclickstate = 0;
- }
}
-
- // strafe double click
- bstrafe =
- mousebuttons[mousebstrafe]
- || joybuttons[joybstrafe];
- if (bstrafe != dclickstate2 && dclicktime2 > 1 )
- {
- dclickstate2 = bstrafe;
- if (dclickstate2)
- dclicks2++;
- if (dclicks2 == 2)
- {
- cmd->buttons |= BT_USE;
- dclicks2 = 0;
- }
- else
- dclicktime2 = 0;
- }
- else
- {
- dclicktime2 += ticdup;
- if (dclicktime2 > 20)
- {
- dclicks2 = 0;
- dclickstate2 = 0;
- }
- }
-
+ if (mousebuttons[mousebbackward])
+ {
+ forward -= forwardmove[speed];
+ }
+
+ if (dclick_use)
+ {
+ // forward double click
+ if (mousebuttons[mousebforward] != dclickstate && dclicktime > 1 )
+ {
+ dclickstate = mousebuttons[mousebforward];
+ if (dclickstate)
+ dclicks++;
+ if (dclicks == 2)
+ {
+ cmd->buttons |= BT_USE;
+ dclicks = 0;
+ }
+ else
+ dclicktime = 0;
+ }
+ else
+ {
+ dclicktime += ticdup;
+ if (dclicktime > 20)
+ {
+ dclicks = 0;
+ dclickstate = 0;
+ }
+ }
+
+ // strafe double click
+ bstrafe =
+ mousebuttons[mousebstrafe]
+ || joybuttons[joybstrafe];
+ if (bstrafe != dclickstate2 && dclicktime2 > 1 )
+ {
+ dclickstate2 = bstrafe;
+ if (dclickstate2)
+ dclicks2++;
+ if (dclicks2 == 2)
+ {
+ cmd->buttons |= BT_USE;
+ dclicks2 = 0;
+ }
+ else
+ dclicktime2 = 0;
+ }
+ else
+ {
+ dclicktime2 += ticdup;
+ if (dclicktime2 > 20)
+ {
+ dclicks2 = 0;
+ dclickstate2 = 0;
+ }
+ }
+ }
+
// fraggle: allow disabling mouse y movement
if (!novert)
--- a/src/m_misc.c
+++ b/src/m_misc.c
@@ -261,10 +261,19 @@
extern int mousebstrafe;
extern int mousebforward;
+extern int mousebstrafeleft;
+extern int mousebstraferight;
+extern int mousebbackward;
+extern int mousebuse;
+
+extern int dclick_use;
+
extern int joybfire;
extern int joybstrafe;
extern int joybuse;
extern int joybspeed;
+extern int joybstrafeleft;
+extern int joybstraferight;
extern int viewwidth;
extern int viewheight;
@@ -422,6 +431,14 @@
{"joystick_x_invert", &joystick_x_invert, DEFAULT_INT, 0, 0},
{"joystick_y_axis", &joystick_y_axis, DEFAULT_INT, 0, 0},
{"joystick_y_invert", &joystick_y_invert, DEFAULT_INT, 0, 0},
+ {"joyb_strafeleft", &joybstrafeleft, DEFAULT_INT, 0, 0},
+ {"joyb_straferight", &joybstraferight, 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},
+
+ {"dclick_use", &dclick_use, DEFAULT_INT, 0, 0},
};
static default_collection_t extra_defaults =