Skip to content

Commit

Permalink
Allow customizing keys for strafe left/right and prev/next weapon
Browse files Browse the repository at this point in the history
  • Loading branch information
lazd committed Oct 20, 2018
1 parent e54d932 commit 2035f7c
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 45 deletions.
2 changes: 2 additions & 0 deletions foreign.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
#define STR_CNEXTWEP "Wep+"
#define STR_CPAUSE "Pause"
#define STR_CESCAPE "Esc"
#define STR_CSTRAFELEFT "StrfL"
#define STR_CSTRAFERIGHT "StrfR"

#define STR_LEFT "Left"
#define STR_RIGHT "Right"
Expand Down
43 changes: 29 additions & 14 deletions wl_agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,35 +173,50 @@ void ControlMovement (objtype *ob)
oldy = player->y;

int joyx, joyy;
float joyfactor = 1;
bool joystrafe = false;
if (joystickenabled && JoyNumAxes >= 4) {
// Enable strafing with the left stick if we have two sticks
joystrafe = true;
int32_t runspeed = RUNMOVE * MOVESCALE * tics;
int32_t walkspeed = BASEMOVE * MOVESCALE * tics;
bool joystrafeleft = false;
bool joystraferight = false;
if (joystickenabled && JoyNumAxes >= 4)
{
IN_GetJoyDelta (&joyx, &joyy, SDL_CONTROLLER_AXIS_LEFTX, SDL_CONTROLLER_AXIS_RIGHTY);
joyfactor = abs(joyx) / 127.0;
float joyfactor = abs(joyx) / 127.0;

joystrafeleft = joyx < -JOYDEADZONE;
joystraferight = joyx > JOYDEADZONE;

// Only adjust run speed if we're controlling with the joystick
// Otherewise, keyboard strafe won't work at the same time as joystick
if (joystrafeleft || joystraferight)
{
runspeed = runspeed * joyfactor;
walkspeed = walkspeed * joyfactor;
}
}

if(buttonstate[bt_strafeleft] || (joystrafe && joyx < -JOYDEADZONE))
bool strafeleft = buttonstate[bt_strafeleft] || joystrafeleft;
bool straferight = buttonstate[bt_straferight] || joystraferight;

if(strafeleft)
{
angle = ob->angle + ANGLES/4;
if(angle >= ANGLES)
angle -= ANGLES;
if(buttonstate[bt_run])
Thrust(angle, (int32_t) (joyfactor * RUNMOVE * MOVESCALE * tics));
else
Thrust(angle, (int32_t) (joyfactor * BASEMOVE * MOVESCALE * tics));
}

if(buttonstate[bt_straferight] || (joystrafe && joyx > JOYDEADZONE))
if(straferight)
{
angle = ob->angle - ANGLES/4;
if(angle < 0)
angle += ANGLES;
}

if (strafeleft || straferight)
{
if(buttonstate[bt_run])
Thrust(angle, (int32_t) (joyfactor * RUNMOVE * MOVESCALE * tics));
Thrust(angle, runspeed);
else
Thrust(angle, (int32_t) (joyfactor * BASEMOVE * MOVESCALE * tics));
Thrust(angle, walkspeed);
}

//
Expand Down
132 changes: 104 additions & 28 deletions wl_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,12 @@ CP_itemtype CusMenu[] = {
{1, "", 0},
{0, "", 0},
{0, "", 0},
{0, "", 0},
{0, "", 0},
{1, "", 0},
{0, "", 0},
{1, "", 0},
{0, "", 0},
{1, "", 0}
{1, "", 0},
{0, "", 0}
};

CP_itemtype CusJoyMenu[] = {
Expand Down Expand Up @@ -296,6 +296,7 @@ static char SaveGameNames[10][32];
static char SaveName[13] = "savegam?.";

#define MENUSPACING 13
#define MENUWIDTH 310
#define MENUPADDING 5
#define RADIOOFFSET 3

Expand Down Expand Up @@ -2323,6 +2324,7 @@ char joyarray[13][3] = { "A ", "B ", "X ", "Y ", "L1", "R1", "L2", "R2", "LS", "
char mbarray[3][2] = { "L", "R", "M", };
int8_t order[4] = { bt_run, bt_use, bt_attack, bt_strafe };
int8_t order2[4] = { bt_pause, bt_esc, bt_prevweapon, bt_nextweapon };
int8_t order3[4] = { bt_nextweapon, bt_prevweapon, bt_strafeleft, bt_straferight };


int
Expand Down Expand Up @@ -2369,13 +2371,17 @@ CustomControls (int)
DefineMouseBtns ();
DrawCustMouse (1);
break;
case 6:
case 3:
DefineKeyBtns ();
DrawCustKeybd (0);
break;
case 8:
case 5:
DefineKeyMove ();
DrawCustKeys (0);
case 7:
DefineKeyBtns2 ();
DrawCustKeybd2 (0);
break;
}
}
while (which >= 0);
Expand Down Expand Up @@ -2430,7 +2436,19 @@ void
DefineKeyBtns (void)
{
CustomCtrls keyallowed = { 1, 1, 1, 1 };
EnterCtrlData (8, &keyallowed, DrawCustKeybd, PrintCustKeybd, KEYBOARDBTNS);
EnterCtrlData (5, &keyallowed, DrawCustKeybd, PrintCustKeybd, KEYBOARDBTNS);
}


////////////////////////
//
// DEFINE THE KEYBOARD BUTTONS
//
void
DefineKeyBtns2 (void)
{
CustomCtrls keyallowed = { 1, 1, 1, 1 };
EnterCtrlData (9, &keyallowed, DrawCustKeybd2, PrintCustKeybd2, KEYBOARDBTNS2);
}


Expand All @@ -2442,7 +2460,7 @@ void
DefineKeyMove (void)
{
CustomCtrls keyallowed = { 1, 1, 1, 1 };
EnterCtrlData (10, &keyallowed, DrawCustKeys, PrintCustKeys, KEYBOARDMOVE);
EnterCtrlData (7, &keyallowed, DrawCustKeys, PrintCustKeys, KEYBOARDMOVE);
}


Expand Down Expand Up @@ -2484,7 +2502,7 @@ EnterCtrlData (int index, CustomCtrls * cust, void (*DrawRtn) (int), void (*Prin
x = CST_START + CST_SPC * which;

// Clear existing text
DrawWindow (5, PrintY - 1, 310, 13, BKGDCOLOR);
DrawWindow (5, PrintY - 1, MENUWIDTH, MENUSPACING, BKGDCOLOR);

// Redraw the other joystick options that could have been overwritten
if (type == JOYSTICK)
Expand Down Expand Up @@ -2522,14 +2540,14 @@ EnterCtrlData (int index, CustomCtrls * cust, void (*DrawRtn) (int), void (*Prin
//
// CHANGE BUTTON VALUE?
//
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 || ci.button10 || ci.button11 || ci.button12)) ||
((type == KEYBOARDBTNS || type == KEYBOARDMOVE) && LastScan == sc_Enter))
if (((type != KEYBOARDBTNS && type != KEYBOARDBTNS2 && type != KEYBOARDMOVE) && (ci.button0 || ci.button1 || ci.button2 || ci.button3 || ci.button4 || ci.button5 || ci.button6 || ci.button7 || ci.button8 || ci.button9 || ci.button10 || ci.button11 || ci.button12)) ||
((type == KEYBOARDBTNS || type == KEYBOARDBTNS2 || type == KEYBOARDMOVE) && LastScan == sc_Enter))
{
lastFlashTime = GetTimeCount();
tick = picked = 0;
SETFONTCOLOR (0, TEXTCOLOR);

if (type == KEYBOARDBTNS || type == KEYBOARDMOVE)
if (type == KEYBOARDBTNS || type == KEYBOARDBTNS2 || type == KEYBOARDMOVE)
IN_ClearKeysDown ();

while(1)
Expand Down Expand Up @@ -2698,6 +2716,16 @@ EnterCtrlData (int index, CustomCtrls * cust, void (*DrawRtn) (int), void (*Prin
}
break;

case KEYBOARDBTNS2:
if (LastScan && LastScan != sc_Escape)
{
buttonscan[order3[which]] = LastScan;
picked = 1;
ShootSnd ();
IN_ClearKeysDown ();
}
break;

case KEYBOARDMOVE:
if (LastScan && LastScan != sc_Escape)
{
Expand Down Expand Up @@ -2775,7 +2803,7 @@ EnterCtrlData (int index, CustomCtrls * cust, void (*DrawRtn) (int), void (*Prin

SD_PlaySound (ESCPRESSEDSND);
WaitKeyUp ();
DrawWindow (5, PrintY - 1, 310, 13, BKGDCOLOR);
DrawWindow (5, PrintY - 1, MENUWIDTH, MENUSPACING, BKGDCOLOR);
}

static int lastwhich = -1;
Expand Down Expand Up @@ -2893,7 +2921,7 @@ DrawCustomJoyScreen (void)
US_Print (STR_CNEXTWEP "\n");
#endif

DrawWindow (5, PrintY - 1, 310, 13, BKGDCOLOR);
DrawWindow (5, PrintY - 1, MENUWIDTH, MENUSPACING, BKGDCOLOR);
DrawCustJoy2 (0);
US_Print ("\n");

Expand All @@ -2905,7 +2933,7 @@ DrawCustomJoyScreen (void)
SETFONTCOLOR (READCOLOR, BKGDCOLOR);
US_CPrint ("\n");
#else
PrintY += 13;
PrintY += MENUSPACING;
VWB_DrawPic (40, 88, C_JOYSTICKPIC);
#endif

Expand Down Expand Up @@ -2933,7 +2961,7 @@ DrawCustomJoyScreen (void)
PrintX = CST_START + CST_SPC * 3;
US_Print (STR_CSTRAFE "\n");
#endif
DrawWindow (5, PrintY - 1, 310, 13, BKGDCOLOR);
DrawWindow (5, PrintY - 1, MENUWIDTH, MENUSPACING, BKGDCOLOR);
DrawCustJoy (0);
US_Print ("\n");
#endif
Expand Down Expand Up @@ -3025,12 +3053,9 @@ DrawCustomScreen (void)
US_Print (STR_CSTRAFE "\n");
#endif

DrawWindow (5, PrintY - 1, 310, 13, BKGDCOLOR);
DrawWindow (5, PrintY - 1, MENUWIDTH, MENUSPACING, BKGDCOLOR);
DrawCustMouse (0);
US_Print ("\n");
US_Print ("\n");
US_Print ("\n");
PrintY += 13;
PrintY += MENUSPACING;

//
// KEYBOARD
Expand All @@ -3039,7 +3064,7 @@ DrawCustomScreen (void)
SETFONTCOLOR (READCOLOR, BKGDCOLOR);
US_CPrint ("Keyboard\n");
#else
PrintY += 13;
PrintY += MENUSPACING;
#endif
SETFONTCOLOR (TEXTCOLOR, BKGDCOLOR);
#ifdef SPANISH
Expand All @@ -3061,7 +3086,7 @@ DrawCustomScreen (void)
PrintX = CST_START + CST_SPC * 3;
US_Print (STR_CSTRAFE "\n");
#endif
DrawWindow (5, PrintY - 1, 310, 13, BKGDCOLOR);
DrawWindow (5, PrintY - 1, MENUWIDTH, MENUSPACING, BKGDCOLOR);
DrawCustKeybd (0);
US_Print ("\n");

Expand Down Expand Up @@ -3089,8 +3114,36 @@ DrawCustomScreen (void)
PrintX = CST_START + CST_SPC * 3;
US_Print (STR_BKWD "\n");
#endif
DrawWindow (5, PrintY - 1, 310, 13, BKGDCOLOR);
DrawWindow (5, PrintY - 1, MENUWIDTH, MENUSPACING, BKGDCOLOR);
DrawCustKeys (0);
US_Print ("\n");

//
// KEYBOARD EXTRA KEYS
//
SETFONTCOLOR (TEXTCOLOR, BKGDCOLOR);
#ifdef SPANISH
PrintX = 4;
US_Print (STR_CNEXTWEP);
US_Print ("/");
US_Print (STR_CPREVWEP);
US_Print ("/");
US_Print (STR_CSTRAFELEFT);
US_Print ("/");
US_Print (STR_CSTRAFERIGHT "\n");
#else
PrintX = CST_START;
US_Print (STR_CNEXTWEP);
PrintX = CST_START + CST_SPC * 1;
US_Print (STR_CPREVWEP);
PrintX = CST_START + CST_SPC * 2;
US_Print (STR_CSTRAFELEFT);
PrintX = CST_START + CST_SPC * 3;
US_Print (STR_CSTRAFERIGHT "\n");
#endif
DrawWindow (5, PrintY - 1, MENUWIDTH, MENUSPACING, BKGDCOLOR);
DrawCustKeybd2 (0);

#endif
//
// PICK STARTING POINT IN MENU
Expand Down Expand Up @@ -3142,7 +3195,7 @@ DrawCustMouse (int hilight)
else
CusMenu[0].active = 1;

PrintY = CST_Y + 13 * 2;
PrintY = CST_Y + MENUSPACING * 2;
for (i = 0; i < 4; i++)
PrintCustMouse (i);
}
Expand Down Expand Up @@ -3182,7 +3235,7 @@ DrawCustJoy2 (int hilight)
CusJoyMenu[0].active = 1;

// Clear text
VWB_Bar (60, CST_Y + 13 * 2, 250, 12, BKGDCOLOR);
VWB_Bar (60, CST_Y + MENUSPACING * 2, 250, 12, BKGDCOLOR);

PrintY = CST_Y + 13 * 2;
for (i = 0; i < 4; i++)
Expand Down Expand Up @@ -3222,7 +3275,7 @@ DrawCustJoy (int hilight)
CusJoyMenu[3].active = 1;

// Clear text
VWB_Bar (60, CST_Y + 13 * 5, 250, 12, BKGDCOLOR);
VWB_Bar (60, CST_Y + MENUSPACING * 5, 250, 12, BKGDCOLOR);

PrintY = CST_Y + 13 * 5;
for (i = 0; i < 4; i++)
Expand All @@ -3248,11 +3301,34 @@ DrawCustKeybd (int hilight)
color = HIGHLIGHT;
SETFONTCOLOR (color, BKGDCOLOR);

PrintY = CST_Y + 13 * 8;
PrintY = CST_Y + MENUSPACING * 5;
for (i = 0; i < 4; i++)
PrintCustKeybd (i);
}

void
PrintCustKeybd2 (int i)
{
PrintX = CST_START + CST_SPC * i;
US_Print ((const char *) IN_GetScanName (buttonscan[order3[i]]));
}

void
DrawCustKeybd2 (int hilight)
{
int i, color;


color = TEXTCOLOR;
if (hilight)
color = HIGHLIGHT;
SETFONTCOLOR (color, BKGDCOLOR);

PrintY = CST_Y + MENUSPACING * 9;
for (i = 0; i < 4; i++)
PrintCustKeybd2 (i);
}

void
PrintCustKeys (int i)
{
Expand All @@ -3271,7 +3347,7 @@ DrawCustKeys (int hilight)
color = HIGHLIGHT;
SETFONTCOLOR (color, BKGDCOLOR);

PrintY = CST_Y + 13 * 10;
PrintY = CST_Y + MENUSPACING * 7;
for (i = 0; i < 4; i++)
PrintCustKeys (i);
}
Expand Down

0 comments on commit 2035f7c

Please sign in to comment.