Skip to content

Commit 2035f7c

Browse files
committed
Allow customizing keys for strafe left/right and prev/next weapon
1 parent e54d932 commit 2035f7c

5 files changed

Lines changed: 141 additions & 45 deletions

File tree

foreign.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
#define STR_CNEXTWEP "Wep+"
7272
#define STR_CPAUSE "Pause"
7373
#define STR_CESCAPE "Esc"
74+
#define STR_CSTRAFELEFT "StrfL"
75+
#define STR_CSTRAFERIGHT "StrfR"
7476

7577
#define STR_LEFT "Left"
7678
#define STR_RIGHT "Right"

wl_agent.cpp

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -173,35 +173,50 @@ void ControlMovement (objtype *ob)
173173
oldy = player->y;
174174

175175
int joyx, joyy;
176-
float joyfactor = 1;
177-
bool joystrafe = false;
178-
if (joystickenabled && JoyNumAxes >= 4) {
179-
// Enable strafing with the left stick if we have two sticks
180-
joystrafe = true;
176+
int32_t runspeed = RUNMOVE * MOVESCALE * tics;
177+
int32_t walkspeed = BASEMOVE * MOVESCALE * tics;
178+
bool joystrafeleft = false;
179+
bool joystraferight = false;
180+
if (joystickenabled && JoyNumAxes >= 4)
181+
{
181182
IN_GetJoyDelta (&joyx, &joyy, SDL_CONTROLLER_AXIS_LEFTX, SDL_CONTROLLER_AXIS_RIGHTY);
182-
joyfactor = abs(joyx) / 127.0;
183+
float joyfactor = abs(joyx) / 127.0;
184+
185+
joystrafeleft = joyx < -JOYDEADZONE;
186+
joystraferight = joyx > JOYDEADZONE;
187+
188+
// Only adjust run speed if we're controlling with the joystick
189+
// Otherewise, keyboard strafe won't work at the same time as joystick
190+
if (joystrafeleft || joystraferight)
191+
{
192+
runspeed = runspeed * joyfactor;
193+
walkspeed = walkspeed * joyfactor;
194+
}
183195
}
184196

185-
if(buttonstate[bt_strafeleft] || (joystrafe && joyx < -JOYDEADZONE))
197+
bool strafeleft = buttonstate[bt_strafeleft] || joystrafeleft;
198+
bool straferight = buttonstate[bt_straferight] || joystraferight;
199+
200+
if(strafeleft)
186201
{
187202
angle = ob->angle + ANGLES/4;
188203
if(angle >= ANGLES)
189204
angle -= ANGLES;
190-
if(buttonstate[bt_run])
191-
Thrust(angle, (int32_t) (joyfactor * RUNMOVE * MOVESCALE * tics));
192-
else
193-
Thrust(angle, (int32_t) (joyfactor * BASEMOVE * MOVESCALE * tics));
194205
}
195206

196-
if(buttonstate[bt_straferight] || (joystrafe && joyx > JOYDEADZONE))
207+
if(straferight)
197208
{
198209
angle = ob->angle - ANGLES/4;
199210
if(angle < 0)
200211
angle += ANGLES;
212+
}
213+
214+
if (strafeleft || straferight)
215+
{
201216
if(buttonstate[bt_run])
202-
Thrust(angle, (int32_t) (joyfactor * RUNMOVE * MOVESCALE * tics));
217+
Thrust(angle, runspeed);
203218
else
204-
Thrust(angle, (int32_t) (joyfactor * BASEMOVE * MOVESCALE * tics));
219+
Thrust(angle, walkspeed);
205220
}
206221

207222
//

wl_menu.cpp

Lines changed: 104 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,12 @@ CP_itemtype CusMenu[] = {
239239
{1, "", 0},
240240
{0, "", 0},
241241
{0, "", 0},
242-
{0, "", 0},
243-
{0, "", 0},
242+
{1, "", 0},
244243
{0, "", 0},
245244
{1, "", 0},
246245
{0, "", 0},
247-
{1, "", 0}
246+
{1, "", 0},
247+
{0, "", 0}
248248
};
249249

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

298298
#define MENUSPACING 13
299+
#define MENUWIDTH 310
299300
#define MENUPADDING 5
300301
#define RADIOOFFSET 3
301302

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

23272329

23282330
int
@@ -2369,13 +2371,17 @@ CustomControls (int)
23692371
DefineMouseBtns ();
23702372
DrawCustMouse (1);
23712373
break;
2372-
case 6:
2374+
case 3:
23732375
DefineKeyBtns ();
23742376
DrawCustKeybd (0);
23752377
break;
2376-
case 8:
2378+
case 5:
23772379
DefineKeyMove ();
23782380
DrawCustKeys (0);
2381+
case 7:
2382+
DefineKeyBtns2 ();
2383+
DrawCustKeybd2 (0);
2384+
break;
23792385
}
23802386
}
23812387
while (which >= 0);
@@ -2430,7 +2436,19 @@ void
24302436
DefineKeyBtns (void)
24312437
{
24322438
CustomCtrls keyallowed = { 1, 1, 1, 1 };
2433-
EnterCtrlData (8, &keyallowed, DrawCustKeybd, PrintCustKeybd, KEYBOARDBTNS);
2439+
EnterCtrlData (5, &keyallowed, DrawCustKeybd, PrintCustKeybd, KEYBOARDBTNS);
2440+
}
2441+
2442+
2443+
////////////////////////
2444+
//
2445+
// DEFINE THE KEYBOARD BUTTONS
2446+
//
2447+
void
2448+
DefineKeyBtns2 (void)
2449+
{
2450+
CustomCtrls keyallowed = { 1, 1, 1, 1 };
2451+
EnterCtrlData (9, &keyallowed, DrawCustKeybd2, PrintCustKeybd2, KEYBOARDBTNS2);
24342452
}
24352453

24362454

@@ -2442,7 +2460,7 @@ void
24422460
DefineKeyMove (void)
24432461
{
24442462
CustomCtrls keyallowed = { 1, 1, 1, 1 };
2445-
EnterCtrlData (10, &keyallowed, DrawCustKeys, PrintCustKeys, KEYBOARDMOVE);
2463+
EnterCtrlData (7, &keyallowed, DrawCustKeys, PrintCustKeys, KEYBOARDMOVE);
24462464
}
24472465

24482466

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

24862504
// Clear existing text
2487-
DrawWindow (5, PrintY - 1, 310, 13, BKGDCOLOR);
2505+
DrawWindow (5, PrintY - 1, MENUWIDTH, MENUSPACING, BKGDCOLOR);
24882506

24892507
// Redraw the other joystick options that could have been overwritten
24902508
if (type == JOYSTICK)
@@ -2522,14 +2540,14 @@ EnterCtrlData (int index, CustomCtrls * cust, void (*DrawRtn) (int), void (*Prin
25222540
//
25232541
// CHANGE BUTTON VALUE?
25242542
//
2525-
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)) ||
2526-
((type == KEYBOARDBTNS || type == KEYBOARDMOVE) && LastScan == sc_Enter))
2543+
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)) ||
2544+
((type == KEYBOARDBTNS || type == KEYBOARDBTNS2 || type == KEYBOARDMOVE) && LastScan == sc_Enter))
25272545
{
25282546
lastFlashTime = GetTimeCount();
25292547
tick = picked = 0;
25302548
SETFONTCOLOR (0, TEXTCOLOR);
25312549

2532-
if (type == KEYBOARDBTNS || type == KEYBOARDMOVE)
2550+
if (type == KEYBOARDBTNS || type == KEYBOARDBTNS2 || type == KEYBOARDMOVE)
25332551
IN_ClearKeysDown ();
25342552

25352553
while(1)
@@ -2698,6 +2716,16 @@ EnterCtrlData (int index, CustomCtrls * cust, void (*DrawRtn) (int), void (*Prin
26982716
}
26992717
break;
27002718

2719+
case KEYBOARDBTNS2:
2720+
if (LastScan && LastScan != sc_Escape)
2721+
{
2722+
buttonscan[order3[which]] = LastScan;
2723+
picked = 1;
2724+
ShootSnd ();
2725+
IN_ClearKeysDown ();
2726+
}
2727+
break;
2728+
27012729
case KEYBOARDMOVE:
27022730
if (LastScan && LastScan != sc_Escape)
27032731
{
@@ -2775,7 +2803,7 @@ EnterCtrlData (int index, CustomCtrls * cust, void (*DrawRtn) (int), void (*Prin
27752803

27762804
SD_PlaySound (ESCPRESSEDSND);
27772805
WaitKeyUp ();
2778-
DrawWindow (5, PrintY - 1, 310, 13, BKGDCOLOR);
2806+
DrawWindow (5, PrintY - 1, MENUWIDTH, MENUSPACING, BKGDCOLOR);
27792807
}
27802808

27812809
static int lastwhich = -1;
@@ -2893,7 +2921,7 @@ DrawCustomJoyScreen (void)
28932921
US_Print (STR_CNEXTWEP "\n");
28942922
#endif
28952923

2896-
DrawWindow (5, PrintY - 1, 310, 13, BKGDCOLOR);
2924+
DrawWindow (5, PrintY - 1, MENUWIDTH, MENUSPACING, BKGDCOLOR);
28972925
DrawCustJoy2 (0);
28982926
US_Print ("\n");
28992927

@@ -2905,7 +2933,7 @@ DrawCustomJoyScreen (void)
29052933
SETFONTCOLOR (READCOLOR, BKGDCOLOR);
29062934
US_CPrint ("\n");
29072935
#else
2908-
PrintY += 13;
2936+
PrintY += MENUSPACING;
29092937
VWB_DrawPic (40, 88, C_JOYSTICKPIC);
29102938
#endif
29112939

@@ -2933,7 +2961,7 @@ DrawCustomJoyScreen (void)
29332961
PrintX = CST_START + CST_SPC * 3;
29342962
US_Print (STR_CSTRAFE "\n");
29352963
#endif
2936-
DrawWindow (5, PrintY - 1, 310, 13, BKGDCOLOR);
2964+
DrawWindow (5, PrintY - 1, MENUWIDTH, MENUSPACING, BKGDCOLOR);
29372965
DrawCustJoy (0);
29382966
US_Print ("\n");
29392967
#endif
@@ -3025,12 +3053,9 @@ DrawCustomScreen (void)
30253053
US_Print (STR_CSTRAFE "\n");
30263054
#endif
30273055

3028-
DrawWindow (5, PrintY - 1, 310, 13, BKGDCOLOR);
3056+
DrawWindow (5, PrintY - 1, MENUWIDTH, MENUSPACING, BKGDCOLOR);
30293057
DrawCustMouse (0);
3030-
US_Print ("\n");
3031-
US_Print ("\n");
3032-
US_Print ("\n");
3033-
PrintY += 13;
3058+
PrintY += MENUSPACING;
30343059

30353060
//
30363061
// KEYBOARD
@@ -3039,7 +3064,7 @@ DrawCustomScreen (void)
30393064
SETFONTCOLOR (READCOLOR, BKGDCOLOR);
30403065
US_CPrint ("Keyboard\n");
30413066
#else
3042-
PrintY += 13;
3067+
PrintY += MENUSPACING;
30433068
#endif
30443069
SETFONTCOLOR (TEXTCOLOR, BKGDCOLOR);
30453070
#ifdef SPANISH
@@ -3061,7 +3086,7 @@ DrawCustomScreen (void)
30613086
PrintX = CST_START + CST_SPC * 3;
30623087
US_Print (STR_CSTRAFE "\n");
30633088
#endif
3064-
DrawWindow (5, PrintY - 1, 310, 13, BKGDCOLOR);
3089+
DrawWindow (5, PrintY - 1, MENUWIDTH, MENUSPACING, BKGDCOLOR);
30653090
DrawCustKeybd (0);
30663091
US_Print ("\n");
30673092

@@ -3089,8 +3114,36 @@ DrawCustomScreen (void)
30893114
PrintX = CST_START + CST_SPC * 3;
30903115
US_Print (STR_BKWD "\n");
30913116
#endif
3092-
DrawWindow (5, PrintY - 1, 310, 13, BKGDCOLOR);
3117+
DrawWindow (5, PrintY - 1, MENUWIDTH, MENUSPACING, BKGDCOLOR);
30933118
DrawCustKeys (0);
3119+
US_Print ("\n");
3120+
3121+
//
3122+
// KEYBOARD EXTRA KEYS
3123+
//
3124+
SETFONTCOLOR (TEXTCOLOR, BKGDCOLOR);
3125+
#ifdef SPANISH
3126+
PrintX = 4;
3127+
US_Print (STR_CNEXTWEP);
3128+
US_Print ("/");
3129+
US_Print (STR_CPREVWEP);
3130+
US_Print ("/");
3131+
US_Print (STR_CSTRAFELEFT);
3132+
US_Print ("/");
3133+
US_Print (STR_CSTRAFERIGHT "\n");
3134+
#else
3135+
PrintX = CST_START;
3136+
US_Print (STR_CNEXTWEP);
3137+
PrintX = CST_START + CST_SPC * 1;
3138+
US_Print (STR_CPREVWEP);
3139+
PrintX = CST_START + CST_SPC * 2;
3140+
US_Print (STR_CSTRAFELEFT);
3141+
PrintX = CST_START + CST_SPC * 3;
3142+
US_Print (STR_CSTRAFERIGHT "\n");
3143+
#endif
3144+
DrawWindow (5, PrintY - 1, MENUWIDTH, MENUSPACING, BKGDCOLOR);
3145+
DrawCustKeybd2 (0);
3146+
30943147
#endif
30953148
//
30963149
// PICK STARTING POINT IN MENU
@@ -3142,7 +3195,7 @@ DrawCustMouse (int hilight)
31423195
else
31433196
CusMenu[0].active = 1;
31443197

3145-
PrintY = CST_Y + 13 * 2;
3198+
PrintY = CST_Y + MENUSPACING * 2;
31463199
for (i = 0; i < 4; i++)
31473200
PrintCustMouse (i);
31483201
}
@@ -3182,7 +3235,7 @@ DrawCustJoy2 (int hilight)
31823235
CusJoyMenu[0].active = 1;
31833236

31843237
// Clear text
3185-
VWB_Bar (60, CST_Y + 13 * 2, 250, 12, BKGDCOLOR);
3238+
VWB_Bar (60, CST_Y + MENUSPACING * 2, 250, 12, BKGDCOLOR);
31863239

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

32243277
// Clear text
3225-
VWB_Bar (60, CST_Y + 13 * 5, 250, 12, BKGDCOLOR);
3278+
VWB_Bar (60, CST_Y + MENUSPACING * 5, 250, 12, BKGDCOLOR);
32263279

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

3251-
PrintY = CST_Y + 13 * 8;
3304+
PrintY = CST_Y + MENUSPACING * 5;
32523305
for (i = 0; i < 4; i++)
32533306
PrintCustKeybd (i);
32543307
}
32553308

3309+
void
3310+
PrintCustKeybd2 (int i)
3311+
{
3312+
PrintX = CST_START + CST_SPC * i;
3313+
US_Print ((const char *) IN_GetScanName (buttonscan[order3[i]]));
3314+
}
3315+
3316+
void
3317+
DrawCustKeybd2 (int hilight)
3318+
{
3319+
int i, color;
3320+
3321+
3322+
color = TEXTCOLOR;
3323+
if (hilight)
3324+
color = HIGHLIGHT;
3325+
SETFONTCOLOR (color, BKGDCOLOR);
3326+
3327+
PrintY = CST_Y + MENUSPACING * 9;
3328+
for (i = 0; i < 4; i++)
3329+
PrintCustKeybd2 (i);
3330+
}
3331+
32563332
void
32573333
PrintCustKeys (int i)
32583334
{
@@ -3271,7 +3347,7 @@ DrawCustKeys (int hilight)
32713347
color = HIGHLIGHT;
32723348
SETFONTCOLOR (color, BKGDCOLOR);
32733349

3274-
PrintY = CST_Y + 13 * 10;
3350+
PrintY = CST_Y + MENUSPACING * 7;
32753351
for (i = 0; i < 4; i++)
32763352
PrintCustKeys (i);
32773353
}

0 commit comments

Comments
 (0)