From 95e4bc21ff37e93668762ce58d59a4109eb02dc5 Mon Sep 17 00:00:00 2001 From: SinnamonLat Date: Fri, 20 May 2022 20:07:25 +0200 Subject: [PATCH] Allow P1 to retain controller usage when playing alone even if they started charsel with keyboard --- src/k_menu.h | 5 +++++ src/k_menufunc.c | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/k_menu.h b/src/k_menu.h index 1362b56dd..b39d1c872 100644 --- a/src/k_menu.h +++ b/src/k_menu.h @@ -528,6 +528,11 @@ typedef struct setup_player_s UINT8 color; UINT8 mdepth; + // Hack, save player 1's original device even if they init charsel with keyboard. + // If they play ALONE, allow them to retain that original device, otherwise, ignore this. + // We can allow them to retain the device with no consequence as when P1 is alone, they have exclusive keyboard fallback options. + UINT8 ponedevice; + INT32 followern; INT16 followercolor; tic_t follower_tics; diff --git a/src/k_menufunc.c b/src/k_menufunc.c index 5233ba67d..26e854aba 100644 --- a/src/k_menufunc.c +++ b/src/k_menufunc.c @@ -2287,6 +2287,13 @@ static boolean M_HandlePressStart(setup_player_t *p, UINT8 num) if (M_DeviceAvailable(i, setup_numplayers) == true) { // Available!! Let's use this one!! + + // if P1 is setting up using keyboard (device 0), save their last used device. + // this is to allow them to retain controller usage when they play alone. + // Because let's face it, when you test mods, you're often lazy to grab your controller for menuing :) + if (!i && !num) + setup_player[num].ponedevice = cv_usejoystick[num].value; + CV_SetValue(&cv_usejoystick[num], i); //CONS_Printf("Device for %d set to %d\n", num, i); //CONS_Printf("========\n"); @@ -2903,6 +2910,14 @@ void M_CharacterSelectTick(void) } CV_StealthSetValue(&cv_splitplayers, setup_numplayers); + + // P1 is alone, set their old device just in case. + if (setup_numplayers < 2) + { + CONS_Printf("Reseting controller device for P1...\n"); + CV_StealthSetValue(&cv_usejoystick[0], setup_player[0].ponedevice); + } + M_SetupNextMenu(&PLAY_MainDef, false); } }