diff options
author | Simon Howard | 2007-06-20 00:37:40 +0000 |
---|---|---|
committer | Simon Howard | 2007-06-20 00:37:40 +0000 |
commit | 856eebe52624ba5d780436feb349ea5ff2ee46b4 (patch) | |
tree | aea6417f30dc26af06650457e1032bbaccdf5d94 | |
parent | d004976261747a47389b14eaf0d695a14fa0f497 (diff) | |
download | chocolate-doom-856eebe52624ba5d780436feb349ea5ff2ee46b4.tar.gz chocolate-doom-856eebe52624ba5d780436feb349ea5ff2ee46b4.tar.bz2 chocolate-doom-856eebe52624ba5d780436feb349ea5ff2ee46b4.zip |
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
-rw-r--r-- | setup/configfile.c | 5 | ||||
-rw-r--r-- | setup/joystick.c | 28 | ||||
-rw-r--r-- | setup/joystick.h | 2 | ||||
-rw-r--r-- | setup/mouse.c | 60 | ||||
-rw-r--r-- | setup/mouse.h | 5 | ||||
-rw-r--r-- | setup/txt_joybinput.c | 4 | ||||
-rw-r--r-- | setup/txt_mouseinput.c | 4 | ||||
-rw-r--r-- | src/g_game.c | 147 | ||||
-rw-r--r-- | src/m_misc.c | 17 |
9 files changed, 188 insertions, 84 deletions
diff --git a/setup/configfile.c b/setup/configfile.c index 0a1e9e5f..d9b17af2 100644 --- a/setup/configfile.c +++ b/setup/configfile.c @@ -272,6 +272,11 @@ static default_t extra_defaults_list[] = {"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 = diff --git a/setup/joystick.c b/setup/joystick.c index d491aadf..eb7f9bfa 100644 --- a/setup/joystick.c +++ b/setup/joystick.c @@ -43,6 +43,8 @@ int joybfire = 0; 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 @@ static void SetJoystickButtonLabel(void) 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 @@ void ConfigJoystick(void) 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,12 +368,14 @@ void ConfigJoystick(void) 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); SetJoystickButtonLabel(); diff --git a/setup/joystick.h b/setup/joystick.h index 30b568ad..39cf0bf4 100644 --- a/setup/joystick.h +++ b/setup/joystick.h @@ -27,6 +27,8 @@ extern int joybfire; extern int joybstrafe; extern int joybuse; extern int joybspeed; +extern int joybstrafeleft; +extern int joybstraferight; extern int joystick_index; extern int joystick_x_axis; diff --git a/setup/mouse.c b/setup/mouse.c index c2d7e155..bafccc87 100644 --- a/setup/mouse.c +++ b/setup/mouse.c @@ -39,9 +39,22 @@ int grabmouse = 1; int mousebfire = 0; int mousebforward = 1; int mousebstrafe = 2; - -static int *all_mouse_buttons[] = {&mousebfire, &mousebstrafe, - &mousebforward}; +int mousebstrafeleft = -1; +int mousebstraferight = -1; +int mousebbackward = -1; +int mousebuse = -1; + +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)) { @@ -73,11 +86,31 @@ static void AddMouseControl(txt_table_t *table, char *label, int *var) 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 @@ void ConfigMouse(void) 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 @@ void ConfigMouse(void) 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); } diff --git a/setup/mouse.h b/setup/mouse.h index 445a50c7..f0a39ade 100644 --- a/setup/mouse.h +++ b/setup/mouse.h @@ -32,6 +32,11 @@ extern int grabmouse; 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); diff --git a/setup/txt_joybinput.c b/setup/txt_joybinput.c index 0f05eaf4..7a94a996 100644 --- a/setup/txt_joybinput.c +++ b/setup/txt_joybinput.c @@ -143,9 +143,9 @@ static void TXT_JoystickInputDrawer(TXT_UNCAST_ARG(joystick_input), int selected char buf[20]; int i; - if (*joystick_input->variable == -1) + if (*joystick_input->variable < 0) { - strcpy(buf, ""); + strcpy(buf, "(none)"); } else { diff --git a/setup/txt_mouseinput.c b/setup/txt_mouseinput.c index 4e8cf2f3..6b70d110 100644 --- a/setup/txt_mouseinput.c +++ b/setup/txt_mouseinput.c @@ -117,9 +117,9 @@ static void TXT_MouseInputDrawer(TXT_UNCAST_ARG(mouse_input), int selected) char buf[20]; int i; - if (*mouse_input->variable == -1) + if (*mouse_input->variable < 0) { - strcpy(buf, ""); + strcpy(buf, "(none)"); } else { diff --git a/src/g_game.c b/src/g_game.c index 8d60a5ce..46337443 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -177,11 +177,23 @@ int key_speed = KEY_RSHIFT; 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 @@ void G_BuildTiccmd (ticcmd_t* cmd) 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 @@ void G_BuildTiccmd (ticcmd_t* cmd) || 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 @@ void G_BuildTiccmd (ticcmd_t* cmd) // 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) diff --git a/src/m_misc.c b/src/m_misc.c index 2d59675e..92510734 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -261,10 +261,19 @@ extern int mousebfire; 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 @@ static default_t extra_defaults_list[] = {"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 = |