From 89d37a74eebd73e2388ff0a90052552e162371e2 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Mon, 9 Aug 2010 17:53:10 +0000 Subject: [PATCH] Add weapon cycling bindings for mouse and joystick buttons. Add weapon cycling bindings to configuration file and setup tool. git-svn-id: https://chocolate-doom.svn.sourceforge.net/svnroot/chocolate-doom/trunk/chocolate-doom@1953 ee5ca603-980d-0410-972c-a23fc50d79fe --- setup/configfile.c | 6 +++++ setup/joystick.c | 4 ++++ setup/joystick.h | 2 ++ setup/keyboard.c | 7 +++++- setup/keyboard.h | 2 ++ setup/mouse.c | 6 +++++ setup/mouse.h | 2 ++ setup/txt_keyinput.c | 2 +- src/g_game.c | 65 ++++++++++++++++++++++++++++++++++++++++++++-------- src/m_config.c | 44 +++++++++++++++++++++++++++++++++++ 10 files changed, 129 insertions(+), 11 deletions(-) diff --git a/setup/configfile.c b/setup/configfile.c index 5fe1d95..2a3cb84 100644 --- a/setup/configfile.c +++ b/setup/configfile.c @@ -286,11 +286,15 @@ static default_t extra_defaults_list[] = {"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 @@ static default_t extra_defaults_list[] = {"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}, diff --git a/setup/joystick.c b/setup/joystick.c index 867fa5c..825cd8b 100644 --- a/setup/joystick.c +++ b/setup/joystick.c @@ -50,6 +50,8 @@ int joybuse = 2; 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 @@ void ConfigJoystick(void) 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); diff --git a/setup/joystick.h b/setup/joystick.h index 39cf0bf..5d3973c 100644 --- a/setup/joystick.h +++ b/setup/joystick.h @@ -29,6 +29,8 @@ extern int joybuse; extern int joybspeed; extern int joybstrafeleft; extern int joybstraferight; +extern int joybprevweapon; +extern int joybnextweapon; extern int joystick_index; extern int joystick_x_axis; diff --git a/setup/keyboard.c b/setup/keyboard.c index bcf5ec7..81976f8 100644 --- a/setup/keyboard.c +++ b/setup/keyboard.c @@ -90,6 +90,8 @@ int key_weapon5 = '5'; 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 @@ static int *controls[] = { &key_left, &key_right, &key_up, &key_down, &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 @@ static void OtherKeysDialog(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(unused)) 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), diff --git a/setup/keyboard.h b/setup/keyboard.h index f934116..7351086 100644 --- a/setup/keyboard.h +++ b/setup/keyboard.h @@ -95,6 +95,8 @@ extern int key_weapon5; 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; diff --git a/setup/mouse.c b/setup/mouse.c index 49266d4..559231b 100644 --- a/setup/mouse.c +++ b/setup/mouse.c @@ -44,6 +44,8 @@ int mousebstrafeleft = -1; int mousebstraferight = -1; int mousebbackward = -1; int mousebuse = -1; +int mousebprevweapon = -1; +int mousebnextweapon = -1; int dclick_use = 1; @@ -55,6 +57,8 @@ static int *all_mouse_buttons[] = { &mousebstraferight, &mousebbackward, &mousebuse, + &mousebprevweapon, + &mousebnextweapon }; static void MouseSetCallback(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(variable)) @@ -104,6 +108,8 @@ static void ConfigExtraButtons(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(unused)) 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) diff --git a/setup/mouse.h b/setup/mouse.h index f0a39ad..48270ca 100644 --- a/setup/mouse.h +++ b/setup/mouse.h @@ -37,6 +37,8 @@ extern int mousebstraferight; extern int mousebbackward; extern int mousebuse; extern int dclick_use; +extern int mousebprevweapon; +extern int mousebnextweapon; void ConfigMouse(void); diff --git a/setup/txt_keyinput.c b/setup/txt_keyinput.c index e385cc5..483c325 100644 --- a/setup/txt_keyinput.c +++ b/setup/txt_keyinput.c @@ -111,7 +111,7 @@ static void TXT_KeyInputDrawer(TXT_UNCAST_ARG(key_input), int selected) if (*key_input->variable == 0) { - strcpy(buf, ""); + strcpy(buf, "(none)"); } else { diff --git a/src/g_game.c b/src/g_game.c index 1e16371..bf9560d 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -198,6 +198,9 @@ int mousebstraferight = -1; 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 joybspeed = 2; 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 @@ static const struct #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 int dclicktime2; 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 @@ void G_DoLoadLevel (void) players[consoleplayer].message = "Press escape to quit."; } } - static void SetJoyButtons(unsigned int buttons_mask) { @@ -823,10 +828,54 @@ static void SetJoyButtons(unsigned int buttons_mask) for (i=0; idata1 & 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 diff --git a/src/m_config.c b/src/m_config.c index b2e52e7..2065700 100644 --- a/src/m_config.c +++ b/src/m_config.c @@ -148,6 +148,8 @@ extern int key_weapon5; 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 mousebstraferight; 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 joybspeed; extern int joybstrafeleft; extern int joybstraferight; +extern int joybprevweapon; +extern int joybnextweapon; + extern int viewwidth; extern int viewheight; @@ -748,6 +756,18 @@ static default_t extra_defaults_list[] = 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 @@ static default_t extra_defaults_list[] = 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. // @@ -1062,6 +1094,18 @@ static default_t extra_defaults_list[] = 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. // -- 2.11.4.GIT