From 94c18f535a2b30d478340e8be651959b69bb0191 Mon Sep 17 00:00:00 2001 From: SinnamonLat Date: Sun, 20 Feb 2022 09:36:17 +0100 Subject: [PATCH] Map 4 keys per button. Detect device when mapping --- src/k_menudraw.c | 33 ++++++++++++++-------- src/k_menufunc.c | 72 ++++++++++++++++++++++++++++-------------------- 2 files changed, 63 insertions(+), 42 deletions(-) diff --git a/src/k_menudraw.c b/src/k_menudraw.c index 278265af7..6c01c5be2 100644 --- a/src/k_menudraw.c +++ b/src/k_menudraw.c @@ -2332,7 +2332,7 @@ void M_DrawProfileControls(void) const UINT8 spacing = 34; INT32 y = 16 - (optionsmenu.controlscroll*spacing); INT32 x = 8; - INT32 i, j; + INT32 i, j, k; M_DrawOptionsCogs(); @@ -2353,7 +2353,7 @@ void M_DrawProfileControls(void) for (i = 0; i < currentMenu->numitems; i++) { char buf[256]; - INT32 keys[2]; + INT32 keys[MAXINPUTMAPPING]; // cursor if (i == itemOn) @@ -2372,34 +2372,43 @@ void M_DrawProfileControls(void) case IT_STRING2: + boolean drawnpatch = false; + if (currentMenu->menuitems[i].patch) + { V_DrawScaledPatch(x+12, y+12, 0, W_CachePatchName(currentMenu->menuitems[i].patch, PU_CACHE)); + drawnpatch = true; + } else V_DrawString(x, y+1, (i == itemOn ? highlightflags : 0), currentMenu->menuitems[i].text); if (currentMenu->menuitems[i].status & IT_CONTROL) { // Draw what the controls are mapped to - keys[0] = optionsmenu.profile->controls[currentMenu->menuitems[i].mvar1][0]; - keys[1] = optionsmenu.profile->controls[currentMenu->menuitems[i].mvar1][1]; + for (k = 0; k < MAXINPUTMAPPING; k++) + keys[k] = optionsmenu.profile->controls[currentMenu->menuitems[i].mvar1][k]; buf[0] = '\0'; - if (keys[0] == KEY_NULL && keys[1] == KEY_NULL) + if (keys[0] == KEY_NULL) // If the first key's null, so should every other. strcpy(buf, "\x85NOT BOUND"); else { - if (keys[0] != KEY_NULL) - strcat (buf, G_KeynumToString (keys[0])); + for (k=0; k < MAXINPUTMAPPING && keys[k] != KEY_NULL; k++) + { + if (k > 0) + strcat(buf," / "); - if (keys[0] != KEY_NULL && keys[1] != KEY_NULL) - strcat(buf," / "); + if (k == 2 && drawnpatch) // hacky... + strcat(buf, "\n"); - if (keys[1] != KEY_NULL) - strcat (buf, G_KeynumToString (keys[1])); + strcat(buf, G_KeynumToString (keys[k])); + + } } - V_DrawThinString(x+32, y+12, V_6WIDTHSPACE, buf); + // don't shift the text if we didn't draw a patch. + V_DrawThinString(x+ (drawnpatch ? 32 : 0), y+ (drawnpatch? 2 : 12), V_6WIDTHSPACE, buf); // controller dest coords: if (itemOn == i && currentMenu->menuitems[i].mvar1 && currentMenu->menuitems[i].mvar1 <= gc_start) diff --git a/src/k_menufunc.c b/src/k_menufunc.c index cbf06a6d4..45f762a31 100644 --- a/src/k_menufunc.c +++ b/src/k_menufunc.c @@ -3870,10 +3870,10 @@ void M_HandleVideoModes(INT32 ch) } } -static void M_ProfileDeviceSelectResponse(INT32 key) +// sets whatever device has had its key pressed to the active device. +static void SetDeviceOnPress(void) { UINT8 i; - (void) key; for (i=0; i < MAXDEVICES; i++) { @@ -3900,7 +3900,8 @@ void M_ProfileDeviceSelect(INT32 choice) optionsmenu.contx = optionsmenu.tcontx = controlleroffsets[gc_a][0]; optionsmenu.conty = optionsmenu.tconty = controlleroffsets[gc_a][1]; - M_StartMessage(M_GetText("Press any key on the device\nyou would like to use"), M_ProfileDeviceSelectResponse, MM_EVENTHANDLER); + //M_StartMessage(M_GetText("Press any key on the device\nyou would like to use"), M_ProfileDeviceSelectResponse, MM_EVENTHANDLER); + M_SetupNextMenu(&OPTIONS_ProfileControlsDef, false); // Don't set device here anymore. } void M_HandleProfileControls(void) @@ -3930,11 +3931,7 @@ void M_HandleProfileControls(void) optionsmenu.bindtimer--; if (!optionsmenu.bindtimer) { - optionsmenu.bindcontrol++; - if (optionsmenu.bindcontrol > 2) - optionsmenu.bindcontrol = 0; // we've gone past the max, just stop. - else - optionsmenu.bindtimer = TICRATE*5; // skip control + optionsmenu.bindcontrol = 0; // we've gone past the max, just stop. } } @@ -3955,8 +3952,11 @@ boolean M_ProfileControlsInputs(INT32 ch) if (currentMenu->menuitems[itemOn].mvar1) { // clear controls for that key - optionsmenu.profile->controls[currentMenu->menuitems[itemOn].mvar1][0] = KEY_NULL; - optionsmenu.profile->controls[currentMenu->menuitems[itemOn].mvar1][1] = KEY_NULL; + INT32 i; + + for (i = 0; i < MAXINPUTMAPPING; i++) + optionsmenu.profile->controls[currentMenu->menuitems[itemOn].mvar1][i] = KEY_NULL; + S_StartSound(NULL, sfx_s3k66); } M_SetMenuDelay(pid); @@ -3967,9 +3967,24 @@ boolean M_ProfileControlsInputs(INT32 ch) void M_ProfileSetControl(INT32 ch) { + INT32 controln = currentMenu->menuitems[itemOn].mvar1; + UINT8 i; (void) ch; - optionsmenu.bindcontrol = 1; + optionsmenu.bindcontrol = 1; // Default to control #1 + + for (i = 0; i < MAXINPUTMAPPING; i++) + { + if (optionsmenu.profile->controls[controln][i] == KEY_NULL) + { + optionsmenu.bindcontrol = i+1; + break; + } + } + + // If we could find a null key to map into, map there. + // Otherwise, this will stay at 1 which means we'll overwrite the first bound control. + optionsmenu.bindtimer = TICRATE*5; } @@ -3977,9 +3992,12 @@ void M_ProfileSetControl(INT32 ch) void M_MapProfileControl(event_t *ev) { INT32 c = ev->data1; - UINT8 n = optionsmenu.bindcontrol-1; // # of input to bind + UINT8 n = optionsmenu.bindcontrol-1; // # of input to bind INT32 controln = currentMenu->menuitems[itemOn].mvar1; // gc_ UINT8 where = n; // By default, we'll save the bind where we're supposed to map. + INT32 i; + + SetDeviceOnPress(); // Update cv_usejoystick // Only consider keydown and joystick events to make sure we ignore ev_mouse and other events if (ev->type != ev_keydown && ev->type != ev_joystick) @@ -3988,28 +4006,22 @@ void M_MapProfileControl(event_t *ev) // Set menu delay regardless of what we're doing to avoid stupid stuff. M_SetMenuDelay(0); - // Check if this control is already assigned, it'd look silly to assign the same key twice on the same thing. - if (n == 0 && optionsmenu.profile->controls[controln][1] == c) + // Check if this particular key (c) is already bound in any slot. + // If that's the case, simply do nothing. + for (i = 0; i < MAXINPUTMAPPING; i++) { - optionsmenu.profile->controls[controln][1] = KEY_NULL; // unbind - where = 0; // save control in slot 0 - } - else if (n == 1 && optionsmenu.profile->controls[controln][0] == c) - { - // Do nothing and exit this menu. - optionsmenu.bindcontrol = 0; - return; + if (optionsmenu.profile->controls[controln][i] == c) + { + optionsmenu.bindcontrol = 0; + return; + } } + // With the way we do things, there cannot be instances of 'gaps' within the controls, so we don't need to pretend like we need to handle that. + // Unless of course you tamper with the cfg file, but then it's *your* fault, not mine. + optionsmenu.profile->controls[controln][where] = c; - - optionsmenu.bindcontrol++; - optionsmenu.bindtimer = TICRATE*5; - if (optionsmenu.bindcontrol > 2) - { - optionsmenu.bindtimer = 0; - optionsmenu.bindcontrol = 0; - } + optionsmenu.bindcontrol = 0; // not binding anymore } void M_HandleItemToggles(INT32 choice)