Skip to content

Commit

Permalink
Basic remapping for 10 buttons, allow the same action to be bound to …
Browse files Browse the repository at this point in the history
…multiple buttons
  • Loading branch information
lazd committed Oct 17, 2018
1 parent 2637fca commit 2a245e7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 30 deletions.
33 changes: 17 additions & 16 deletions id_in.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,23 +233,22 @@ int IN_JoyButtons()

SDL_GameControllerUpdate();

// Read triggers in as buttons
int leftTrigger = (SDL_GameControllerGetAxis(GameController, SDL_CONTROLLER_AXIS_TRIGGERLEFT) >> 8) > JOYDEADZONE;
int rightTrigger = (SDL_GameControllerGetAxis(GameController, SDL_CONTROLLER_AXIS_TRIGGERRIGHT) >> 8) > JOYDEADZONE;

// Read in each button in the order we expect to define it
int res = 0;
res |= (SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_A) || rightTrigger) << 0;
res |= (SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_B) || leftTrigger) << 1;
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_A) << 0;
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_B) << 1;
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_X) << 2;
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_Y) << 3;
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_LEFTSHOULDER) << 4;
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) << 5;
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_LEFTSTICK) << 6;
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_RIGHTSTICK) << 7;
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_BACK) << 8;
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_START) << 9;
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_GUIDE) << 10;
// Read triggers in as buttons
res |= ((SDL_GameControllerGetAxis(GameController, SDL_CONTROLLER_AXIS_TRIGGERLEFT) >> 8) > JOYDEADZONE) << 6;
res |= ((SDL_GameControllerGetAxis(GameController, SDL_CONTROLLER_AXIS_TRIGGERRIGHT) >> 8) > JOYDEADZONE) << 7;
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_LEFTSTICK) << 8;
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_RIGHTSTICK) << 9;
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_BACK) << 10;
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_START) << 11;
res |= SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_GUIDE) << 12;
return res;
}

Expand Down Expand Up @@ -537,11 +536,13 @@ IN_ReadControl(int player,ControlInfo *info)
info->button0 = (buttons & (1 << 0)) != 0;
info->button1 = (buttons & (1 << 1)) != 0;
info->button2 = (buttons & (1 << 2)) != 0;
info->button3 = (buttons & (1 << 3)) != 0;
// info->button0 = (buttons & (1 << 0)) != 0 || SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_A);
// info->button1 = (buttons & (1 << 1)) != 0 || SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_B);
// info->button2 = (buttons & (1 << 2)) != 0 || SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_X);
// info->button3 = (buttons & (1 << 3)) != 0 || SDL_GameControllerGetButton(GameController, SDL_CONTROLLER_BUTTON_Y);
info->button3 = (buttons & (1 << 3)) != 0;
info->button4 = (buttons & (1 << 4)) != 0;
info->button5 = (buttons & (1 << 5)) != 0;
info->button6 = (buttons & (1 << 6)) != 0;
info->button7 = (buttons & (1 << 7)) != 0;
info->button8 = (buttons & (1 << 8)) != 0;
info->button9 = (buttons & (1 << 9)) != 0;
info->dir = DirTable[((my + 1) * 3) + (mx + 1)];
}

Expand Down
2 changes: 1 addition & 1 deletion id_in.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ typedef enum {
dir_None
} Direction;
typedef struct {
boolean button0,button1,button2,button3;
boolean button0,button1,button2,button3,button4,button5,button6,button7,button8,button9;
short x,y;
Motion xaxis,yaxis;
Direction dir;
Expand Down
42 changes: 31 additions & 11 deletions wl_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2205,7 +2205,7 @@ DrawCtlScreen (void)
////////////////////////////////////////////////////////////////////
enum
{ FIRE, STRAFE, RUN, OPEN };
char mbarray[4][3] = { "b0", "b1", "b2", "b3" };
char mbarray[10][3] = { "A ", "B ", "X ", "Y ", "L1", "R1", "L2", "R2", "LS", "RS" };
int8_t order[4] = { RUN, OPEN, FIRE, STRAFE };


Expand Down Expand Up @@ -2352,11 +2352,10 @@ EnterCtrlData (int index, CustomCtrls * cust, void (*DrawRtn) (int), void (*Prin
IN_ClearKeysDown ();
ci.button0 = ci.button1 = false;
}

//
// CHANGE BUTTON VALUE?
//
if (((type != KEYBOARDBTNS && type != KEYBOARDMOVE) && (ci.button0 | ci.button1 | ci.button2 | ci.button3)) ||
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)) ||
((type == KEYBOARDBTNS || type == KEYBOARDMOVE) && LastScan == sc_Enter))
{
lastFlashTime = GetTimeCount();
Expand Down Expand Up @@ -2435,17 +2434,32 @@ EnterCtrlData (int index, CustomCtrls * cust, void (*DrawRtn) (int), void (*Prin
result = 3;
else if (ci.button3)
result = 4;
else if (ci.button4)
result = 5;
else if (ci.button5)
result = 6;
else if (ci.button6)
result = 7;
else if (ci.button7)
result = 8;
else if (ci.button8)
result = 9;
else if (ci.button9)
result = 10;

if (result)
{
for (int z = 0; z < 4; z++)
/*
// Allow the same action to be bound to multiple buttons
for (int z = 0; z < 10; z++)
{
if (order[which] == buttonjoy[z])
{
buttonjoy[z] = bt_nobutton;
break;
}
}
*/

buttonjoy[result - 1] = order[which];
picked = 1;
Expand Down Expand Up @@ -2851,7 +2865,7 @@ DrawCustMouse (int hilight)
void
PrintCustJoy (int i)
{
for (int j = 0; j < 4; j++)
for (int j = 0; j < 10; j++)
{
if (order[i] == buttonjoy[j])
{
Expand Down Expand Up @@ -3718,8 +3732,8 @@ WaitKeyUp (void)
{
ControlInfo ci;
while (ReadAnyControl (&ci), ci.button0 |
ci.button1 |
ci.button2 | ci.button3 | Keyboard[sc_Space] | Keyboard[sc_Enter] | Keyboard[sc_Escape])
ci.button1 | ci.button2 | ci.button3 | ci.button4 | ci.button5 | ci.button6 | ci.button7 | ci.button8 | ci.button9 |
Keyboard[sc_Space] | Keyboard[sc_Enter] | Keyboard[sc_Escape])
{
IN_WaitAndProcessEvents();
}
Expand Down Expand Up @@ -3801,10 +3815,16 @@ ReadAnyControl (ControlInfo * ci)
jb = IN_JoyButtons ();
if (jb)
{
ci->button0 = jb & 1;
ci->button1 = jb & 2;
ci->button2 = jb & 4;
ci->button3 = jb & 8;
ci->button0 = (jb & (1 << 0)) > 0;
ci->button1 = (jb & (1 << 1)) > 0;
ci->button2 = (jb & (1 << 2)) > 0;
ci->button3 = (jb & (1 << 3)) > 0;
ci->button4 = (jb & (1 << 4)) > 0;
ci->button5 = (jb & (1 << 5)) > 0;
ci->button6 = (jb & (1 << 6)) > 0;
ci->button7 = (jb & (1 << 7)) > 0;
ci->button8 = (jb & (1 << 8)) > 0;
ci->button9 = (jb & (1 << 9)) > 0;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions wl_play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ int buttonjoy[32] = {
bt_attack, bt_strafe, bt_use, bt_run, bt_esc, bt_prevweapon, bt_nobutton, bt_nextweapon,
bt_pause, bt_strafeleft, bt_straferight, bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton,
#else
bt_attack, bt_use, bt_strafe, bt_run, bt_prevweapon, bt_nextweapon, bt_run, bt_run,
bt_pause, bt_esc, bt_esc, bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton,
bt_attack, bt_use, bt_strafe, bt_run, bt_prevweapon, bt_nextweapon, bt_use, bt_attack,
bt_run, bt_run, bt_pause, bt_esc, bt_esc, bt_nobutton, bt_nobutton, bt_nobutton,
#endif
bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton,
bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton, bt_nobutton
Expand Down

0 comments on commit 2a245e7

Please sign in to comment.