Skip to content

Commit 2a245e7

Browse files
committed
Basic remapping for 10 buttons, allow the same action to be bound to multiple buttons
1 parent 2637fca commit 2a245e7

4 files changed

Lines changed: 51 additions & 30 deletions

File tree

id_in.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -233,23 +233,22 @@ int IN_JoyButtons()
233233

234234
SDL_GameControllerUpdate();
235235

236-
// Read triggers in as buttons
237-
int leftTrigger = (SDL_GameControllerGetAxis(GameController, SDL_CONTROLLER_AXIS_TRIGGERLEFT) >> 8) > JOYDEADZONE;
238-
int rightTrigger = (SDL_GameControllerGetAxis(GameController, SDL_CONTROLLER_AXIS_TRIGGERRIGHT) >> 8) > JOYDEADZONE;
239-
240236
// Read in each button in the order we expect to define it
241237
int res = 0;
242-
res |= (SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_A) || rightTrigger) << 0;
243-
res |= (SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_B) || leftTrigger) << 1;
238+
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_A) << 0;
239+
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_B) << 1;
244240
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_X) << 2;
245241
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_Y) << 3;
246242
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_LEFTSHOULDER) << 4;
247243
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) << 5;
248-
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_LEFTSTICK) << 6;
249-
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_RIGHTSTICK) << 7;
250-
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_BACK) << 8;
251-
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_START) << 9;
252-
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_GUIDE) << 10;
244+
// Read triggers in as buttons
245+
res |= ((SDL_GameControllerGetAxis(GameController, SDL_CONTROLLER_AXIS_TRIGGERLEFT) >> 8) > JOYDEADZONE) << 6;
246+
res |= ((SDL_GameControllerGetAxis(GameController, SDL_CONTROLLER_AXIS_TRIGGERRIGHT) >> 8) > JOYDEADZONE) << 7;
247+
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_LEFTSTICK) << 8;
248+
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_RIGHTSTICK) << 9;
249+
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_BACK) << 10;
250+
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_START) << 11;
251+
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_GUIDE) << 12;
253252
return res;
254253
}
255254

@@ -537,11 +536,13 @@ IN_ReadControl(int player,ControlInfo *info)
537536
info->button0 = (buttons & (1 << 0)) != 0;
538537
info->button1 = (buttons & (1 << 1)) != 0;
539538
info->button2 = (buttons & (1 << 2)) != 0;
540-
info->button3 = (buttons & (1 << 3)) != 0;
541-
// info->button0 = (buttons & (1 << 0)) != 0 || SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_A);
542-
// info->button1 = (buttons & (1 << 1)) != 0 || SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_B);
543-
// info->button2 = (buttons & (1 << 2)) != 0 || SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_X);
544-
// info->button3 = (buttons & (1 << 3)) != 0 || SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_Y);
539+
info->button3 = (buttons & (1 << 3)) != 0;
540+
info->button4 = (buttons & (1 << 4)) != 0;
541+
info->button5 = (buttons & (1 << 5)) != 0;
542+
info->button6 = (buttons & (1 << 6)) != 0;
543+
info->button7 = (buttons & (1 << 7)) != 0;
544+
info->button8 = (buttons & (1 << 8)) != 0;
545+
info->button9 = (buttons & (1 << 9)) != 0;
545546
info->dir = DirTable[((my + 1) * 3) + (mx + 1)];
546547
}
547548

id_in.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ typedef enum {
115115
dir_None
116116
} Direction;
117117
typedef struct {
118-
boolean button0,button1,button2,button3;
118+
boolean button0,button1,button2,button3,button4,button5,button6,button7,button8,button9;
119119
short x,y;
120120
Motion xaxis,yaxis;
121121
Direction dir;

wl_menu.cpp

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,7 +2205,7 @@ DrawCtlScreen (void)
22052205
////////////////////////////////////////////////////////////////////
22062206
enum
22072207
{ FIRE, STRAFE, RUN, OPEN };
2208-
char mbarray[4][3] = { "b0", "b1", "b2", "b3" };
2208+
char mbarray[10][3] = { "A ", "B ", "X ", "Y ", "L1", "R1", "L2", "R2", "LS", "RS" };
22092209
int8_t order[4] = { RUN, OPEN, FIRE, STRAFE };
22102210

22112211

@@ -2352,11 +2352,10 @@ EnterCtrlData (int index, CustomCtrls * cust, void (*DrawRtn) (int), void (*Prin
23522352
IN_ClearKeysDown ();
23532353
ci.button0 = ci.button1 = false;
23542354
}
2355-
23562355
//
23572356
// CHANGE BUTTON VALUE?
23582357
//
2359-
if (((type != KEYBOARDBTNS && type != KEYBOARDMOVE) && (ci.button0 | ci.button1 | ci.button2 | ci.button3)) ||
2358+
if (((type != KEYBOARDBTNS && type != KEYBOARDMOVE) && (ci.button0 || ci.button1 || ci.button2 || ci.button3 || ci.button4 || ci.button5 || ci.button6 || ci.button7 || ci.button8 || ci.button9)) ||
23602359
((type == KEYBOARDBTNS || type == KEYBOARDMOVE) && LastScan == sc_Enter))
23612360
{
23622361
lastFlashTime = GetTimeCount();
@@ -2435,17 +2434,32 @@ EnterCtrlData (int index, CustomCtrls * cust, void (*DrawRtn) (int), void (*Prin
24352434
result = 3;
24362435
else if (ci.button3)
24372436
result = 4;
2437+
else if (ci.button4)
2438+
result = 5;
2439+
else if (ci.button5)
2440+
result = 6;
2441+
else if (ci.button6)
2442+
result = 7;
2443+
else if (ci.button7)
2444+
result = 8;
2445+
else if (ci.button8)
2446+
result = 9;
2447+
else if (ci.button9)
2448+
result = 10;
24382449

24392450
if (result)
24402451
{
2441-
for (int z = 0; z < 4; z++)
2452+
/*
2453+
// Allow the same action to be bound to multiple buttons
2454+
for (int z = 0; z < 10; z++)
24422455
{
24432456
if (order[which] == buttonjoy[z])
24442457
{
24452458
buttonjoy[z] = bt_nobutton;
24462459
break;
24472460
}
24482461
}
2462+
*/
24492463

24502464
buttonjoy[result - 1] = order[which];
24512465
picked = 1;
@@ -2851,7 +2865,7 @@ DrawCustMouse (int hilight)
28512865
void
28522866
PrintCustJoy (int i)
28532867
{
2854-
for (int j = 0; j < 4; j++)
2868+
for (int j = 0; j < 10; j++)
28552869
{
28562870
if (order[i] == buttonjoy[j])
28572871
{
@@ -3718,8 +3732,8 @@ WaitKeyUp (void)
37183732
{
37193733
ControlInfo ci;
37203734
while (ReadAnyControl (&ci), ci.button0 |
3721-
ci.button1 |
3722-
ci.button2 | ci.button3 | Keyboard[sc_Space] | Keyboard[sc_Enter] | Keyboard[sc_Escape])
3735+
ci.button1 | ci.button2 | ci.button3 | ci.button4 | ci.button5 | ci.button6 | ci.button7 | ci.button8 | ci.button9 |
3736+
Keyboard[sc_Space] | Keyboard[sc_Enter] | Keyboard[sc_Escape])
37233737
{
37243738
IN_WaitAndProcessEvents();
37253739
}
@@ -3801,10 +3815,16 @@ ReadAnyControl (ControlInfo * ci)
38013815
jb = IN_JoyButtons ();
38023816
if (jb)
38033817
{
3804-
ci->button0 = jb & 1;
3805-
ci->button1 = jb & 2;
3806-
ci->button2 = jb & 4;
3807-
ci->button3 = jb & 8;
3818+
ci->button0 = (jb & (1 << 0)) > 0;
3819+
ci->button1 = (jb & (1 << 1)) > 0;
3820+
ci->button2 = (jb & (1 << 2)) > 0;
3821+
ci->button3 = (jb & (1 << 3)) > 0;
3822+
ci->button4 = (jb & (1 << 4)) > 0;
3823+
ci->button5 = (jb & (1 << 5)) > 0;
3824+
ci->button6 = (jb & (1 << 6)) > 0;
3825+
ci->button7 = (jb & (1 << 7)) > 0;
3826+
ci->button8 = (jb & (1 << 8)) > 0;
3827+
ci->button9 = (jb & (1 << 9)) > 0;
38083828
}
38093829
}
38103830
}

wl_play.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ int buttonjoy[32] = {
5959
bt_attack, bt_strafe, bt_use, bt_run, bt_esc, bt_prevweapon, bt_nobutton, bt_nextweapon,
6060
bt_pause, bt_strafeleft, bt_straferight, bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton,
6161
#else
62-
bt_attack, bt_use, bt_strafe, bt_run, bt_prevweapon, bt_nextweapon, bt_run, bt_run,
63-
bt_pause, bt_esc, bt_esc, bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton,
62+
bt_attack, bt_use, bt_strafe, bt_run, bt_prevweapon, bt_nextweapon, bt_use, bt_attack,
63+
bt_run, bt_run, bt_pause, bt_esc, bt_esc, bt_nobutton, bt_nobutton, bt_nobutton,
6464
#endif
6565
bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton,
6666
bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton

0 commit comments

Comments
 (0)