foxygit / doom Log in
commit 28109d47dc23c68e6ac9fa439d68933d4bdcf30a
Author:     Michael Day <contact@michaelcday.com>
AuthorDate: Mon Feb 5 16:16:14 2024 -0500
Commit:     Michael Day <contact@michaelcday.com>
CommitDate: Tue Feb 6 09:49:25 2024 -0500

    raven: Add artifact joystick binds
---
 src/heretic/g_game.c      | 25 ++++++++++++++++++++++++-
 src/hexen/g_game.c        | 26 +++++++++++++++++++++++++-
 src/i_joystick.c          |  2 +-
 src/i_joystick.h          |  2 +-
 src/m_config.c            | 42 ++++++++++++++++++++++++++++++++++++++++++
 src/m_controls.c          |  8 ++++++++
 src/m_controls.h          |  4 ++++
 src/setup/joystick.c      | 21 +++++++++++++++++++--
 src/setup/txt_joybinput.c |  3 +++
 9 files changed, 127 insertions(+), 6 deletions(-)

diff --git a/src/heretic/g_game.c b/src/heretic/g_game.c
index 95830ccb..b77bf65d 100644
--- a/src/heretic/g_game.c
+++ b/src/heretic/g_game.c
@@ -57,6 +57,9 @@ void G_DoSaveGame(void);
 void D_PageTicker(void);
 void D_AdvanceDemo(void);

+static boolean InventoryMoveLeft();
+static boolean InventoryMoveRight();
+
 struct
 {
     int type;   // mobjtype_t
@@ -488,7 +491,8 @@ void G_BuildTiccmd(ticcmd_t *cmd, int maketic)
     }

     // Use artifact key
-    if (gamekeydown[key_useartifact] || mousebuttons[mousebuseartifact])
+    if (gamekeydown[key_useartifact] || mousebuttons[mousebuseartifact]
+        || joybuttons[joybuseartifact])
     {
         if (gamekeydown[key_speed] && !noartiskip)
         {
@@ -820,6 +824,9 @@ void G_DoLoadLevel(void)
 static void SetJoyButtons(unsigned int buttons_mask)
 {
     int i;
+    player_t* plr;
+
+    plr = &players[consoleplayer];

     for (i=0; i<MAX_JOY_BUTTONS; ++i)
     {
@@ -839,6 +846,22 @@ static void SetJoyButtons(unsigned int buttons_mask)
             {
                 next_weapon = 1;
             }
+            else if (i == joybinvleft)
+            {
+                InventoryMoveLeft();
+            }
+            else if (i == joybinvright)
+            {
+                InventoryMoveRight();
+            }
+            else if (i == joybuseartifact)
+            {
+                if (!inventory)
+                {
+                    plr->readyArtifact = plr->inventory[inv_ptr].type;
+                }
+                usearti = true;
+            }
         }

         joybuttons[i] = button_on;
diff --git a/src/hexen/g_game.c b/src/hexen/g_game.c
index e0b30d15..ba007f78 100644
--- a/src/hexen/g_game.c
+++ b/src/hexen/g_game.c
@@ -57,6 +57,9 @@ void G_DoSingleReborn(void);
 void H2_PageTicker(void);
 void H2_AdvanceDemo(void);

+static boolean InventoryMoveLeft();
+static boolean InventoryMoveRight();
+

 gameaction_t gameaction;
 gamestate_t gamestate;
@@ -419,7 +422,8 @@ void G_BuildTiccmd(ticcmd_t *cmd, int maketic)
         look = TOCENTER;
     }
     // Use artifact key
-    if (gamekeydown[key_useartifact] || mousebuttons[mousebuseartifact])
+    if (gamekeydown[key_useartifact] || mousebuttons[mousebuseartifact]
+        || joybuttons[joybuseartifact])
     {
         if (gamekeydown[key_speed] && artiskip)
         {
@@ -427,6 +431,7 @@ void G_BuildTiccmd(ticcmd_t *cmd, int maketic)
             {                   // Skip an artifact
                 gamekeydown[key_useartifact] = false;
                 mousebuttons[mousebuseartifact] = false;
+                joybuttons[joybuseartifact] = false;
                 P_PlayerNextArtifact(&players[consoleplayer]);
             }
         }
@@ -778,6 +783,9 @@ void G_DoLoadLevel(void)
 static void SetJoyButtons(unsigned int buttons_mask)
 {
     int i;
+    player_t *plr;
+
+    plr = &players[consoleplayer];

     for (i=0; i<MAX_JOY_BUTTONS; ++i)
     {
@@ -797,6 +805,22 @@ static void SetJoyButtons(unsigned int buttons_mask)
             {
                 next_weapon = 1;
             }
+            else if (i == joybinvleft)
+            {
+                InventoryMoveLeft();
+            }
+            else if (i == joybinvright)
+            {
+                InventoryMoveRight();
+            }
+            else if (i == joybuseartifact)
+            {
+                if (!inventory)
+                {
+                    plr->readyArtifact = plr->inventory[inv_ptr].type;
+                }
+                usearti = true;
+            }
         }

         joybuttons[i] = button_on;
diff --git a/src/i_joystick.c b/src/i_joystick.c
index 5ebaca7e..330a4b81 100644
--- a/src/i_joystick.c
+++ b/src/i_joystick.c
@@ -90,7 +90,7 @@ int joystick_look_sensitivity = 10;
 // Virtual to physical button joystick button mapping. By default this
 // is a straight mapping.
 static int joystick_physical_buttons[NUM_VIRTUAL_BUTTONS] = {
-    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
+    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
 };

 void I_ShutdownGamepad(void)
diff --git a/src/i_joystick.h b/src/i_joystick.h
index a50c5309..6f73c8d7 100644
--- a/src/i_joystick.h
+++ b/src/i_joystick.h
@@ -24,7 +24,7 @@
 // Number of "virtual" joystick buttons defined in configuration files.
 // This needs to be at least as large as the number of different key
 // bindings supported by the higher-level game code (joyb* variables).
-#define NUM_VIRTUAL_BUTTONS 11
+#define NUM_VIRTUAL_BUTTONS 14

 // Max allowed number of virtual mappings. Chosen to be less than joybspeed
 // autorun value.
diff --git a/src/m_config.c b/src/m_config.c
index 935a877e..a45c38c6 100644
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -1400,6 +1400,27 @@ static default_t extra_defaults_list[] =

     CONFIG_VARIABLE_INT(joystick_physical_button10),

+    //!
+    // The physical joystick button that corresponds to joystick
+    // virtual button #11.
+    //
+
+    CONFIG_VARIABLE_INT(joystick_physical_button11),
+
+    //!
+    // The physical joystick button that corresponds to joystick
+    // virtual button #12.
+    //
+
+    CONFIG_VARIABLE_INT(joystick_physical_button12),
+
+    //!
+    // The physical joystick button that corresponds to joystick
+    // virtual button #13.
+    //
+
+    CONFIG_VARIABLE_INT(joystick_physical_button13),
+
     //!
     // If non-zero, use the SDL_GameController interface instead of the
     // SDL_Joystick interface.
@@ -1477,6 +1498,27 @@ static default_t extra_defaults_list[] =

     CONFIG_VARIABLE_INT(joyb_nextweapon),

+    //!
+    // @game heretic hexen
+    // Joystick virtual button to activate artifact.
+    //
+
+    CONFIG_VARIABLE_INT(joyb_useartifact),
+
+    //!
+    // @game heretic hexen
+    // Joystick virtual button to move left in the inventory.
+    //
+
+    CONFIG_VARIABLE_INT(joyb_invleft),
+
+    //!
+    // @game heretic hexen
+    // Joystick virtual button to move right in the inventory.
+    //
+
+    CONFIG_VARIABLE_INT(joyb_invright),
+
     //!
     // Key to pause or unpause the game.
     //
diff --git a/src/m_controls.c b/src/m_controls.c
index 990298b2..752ca043 100644
--- a/src/m_controls.c
+++ b/src/m_controls.c
@@ -210,6 +210,10 @@ int joybnextweapon = -1;
 int joybmenu = -1;
 int joybautomap = -1;

+int joybuseartifact = -1;
+int joybinvleft = -1;
+int joybinvright = -1;
+
 // Control whether if a mouse button is double clicked, it acts like
 // "use" has been pressed

@@ -278,6 +282,10 @@ void M_BindHereticControls(void)
     M_BindIntVariable("mouseb_invright", &mousebinvright);
     M_BindIntVariable("mouseb_useartifact", &mousebuseartifact);

+    M_BindIntVariable("joyb_invleft", &joybinvleft);
+    M_BindIntVariable("joyb_invright", &joybinvright);
+    M_BindIntVariable("joyb_useartifact", &joybuseartifact);
+
     M_BindIntVariable("key_arti_quartz",        &key_arti_quartz);
     M_BindIntVariable("key_arti_urn",           &key_arti_urn);
     M_BindIntVariable("key_arti_bomb",          &key_arti_bomb);
diff --git a/src/m_controls.h b/src/m_controls.h
index c5cf5ca8..350653e8 100644
--- a/src/m_controls.h
+++ b/src/m_controls.h
@@ -169,6 +169,10 @@ extern int joybnextweapon;
 extern int joybmenu;
 extern int joybautomap;

+extern int joybuseartifact;
+extern int joybinvleft;
+extern int joybinvright;
+
 extern int dclick_use;

 void M_BindBaseControls(void);
diff --git a/src/setup/joystick.c b/src/setup/joystick.c
index e0cf9e88..833eeaa4 100644
--- a/src/setup/joystick.c
+++ b/src/setup/joystick.c
@@ -100,7 +100,7 @@ int joystick_look_sensitivity = 10;

 // Virtual to physical mapping.
 int joystick_physical_buttons[NUM_VIRTUAL_BUTTONS] = {
-    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
+    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
 };

 static txt_button_t *joystick_button;
@@ -164,6 +164,9 @@ static const joystick_config_t empty_defaults[] =
     {"joyb_jump",                  -1},
     {"joyb_menu_activate",         -1},
     {"joyb_toggle_automap",        -1},
+    {"joyb_useartifact",           -1},
+    {"joyb_invleft",               -1},
+    {"joyb_invright",              -1},
     {"joystick_physical_button0",  0},
     {"joystick_physical_button1",  1},
     {"joystick_physical_button2",  2},
@@ -174,6 +177,10 @@ static const joystick_config_t empty_defaults[] =
     {"joystick_physical_button7",  7},
     {"joystick_physical_button8",  8},
     {"joystick_physical_button9",  9},
+    {"joystick_physical_button10",  10},
+    {"joystick_physical_button11",  11},
+    {"joystick_physical_button12",  12},
+    {"joystick_physical_button13",  13},
     {NULL, 0},
 };

@@ -630,6 +637,9 @@ static const joystick_config_t modern_gamepad[] =
     {"joyb_nextweapon", SDL_CONTROLLER_BUTTON_RIGHTSHOULDER},
     {"joyb_menu_activate", SDL_CONTROLLER_BUTTON_START},
     {"joyb_toggle_automap", SDL_CONTROLLER_BUTTON_Y},
+    {"joyb_useartifact", SDL_CONTROLLER_BUTTON_X},
+    {"joyb_invleft", SDL_CONTROLLER_BUTTON_DPAD_LEFT},
+    {"joyb_invright", SDL_CONTROLLER_BUTTON_DPAD_RIGHT},
     {NULL, 0},
 };

@@ -1173,7 +1183,7 @@ void ConfigJoystick(TXT_UNCAST_ARG(widget), void *user_data)

     window = TXT_NewWindow("Gamepad/Joystick configuration");
     TXT_SetTableColumns(window, 6);
-    TXT_SetColumnWidths(window, 18, 10, 1, 15, 10, 0);
+    TXT_SetColumnWidths(window, 18, 10, 1, 18, 10, 0);
     TXT_SetWindowHelpURL(window, WINDOW_HELP_URL);

     TXT_AddWidgets(window,
@@ -1269,6 +1279,13 @@ void ConfigJoystick(TXT_UNCAST_ARG(widget), void *user_data)

     AddJoystickControl(window, "Toggle Automap", &joybautomap);

+    if (gamemission == heretic || gamemission == hexen)
+    {
+        AddJoystickControl(window, "Use artifact", &joybuseartifact);
+        AddJoystickControl(window, "Inventory left", &joybinvleft);
+        AddJoystickControl(window, "Inventory right", &joybinvright);
+    }
+
     TXT_SignalConnect(joystick_button, "pressed", CalibrateJoystick, window);
     TXT_SetWindowAction(window, TXT_HORIZ_CENTER, TestConfigAction());

diff --git a/src/setup/txt_joybinput.c b/src/setup/txt_joybinput.c
index 0cb651ac..067f63d8 100644
--- a/src/setup/txt_joybinput.c
+++ b/src/setup/txt_joybinput.c
@@ -58,6 +58,9 @@ static int *all_joystick_buttons[NUM_VIRTUAL_BUTTONS] =
     &joybjump,
     &joybmenu,
     &joybautomap,
+    &joybuseartifact,
+    &joybinvleft,
+    &joybinvright,
 };

 // For indirection so that we're not dependent on item ordering in the