Repository navigation
Expand file tree
/
Copy pathmenu.c
More file actions
4519 lines (3853 loc) · 132 KB
/
Copy pathmenu.c
File metadata and controls
4519 lines (3853 loc) · 132 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 1997-2001 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <ctype.h>
#ifdef _WIN32
#include <io.h> // For filelength()
#endif // _WIN32
#include "client.h"
#include "client/qmenu.h"
#include "ps2/debug/debug_menu.h" // [PS2_QUAKE]
void M_Menu_Main_f(void);
void M_Menu_Game_f(void);
void M_Menu_LoadGame_f(void);
void M_Menu_SaveGame_f(void);
void M_Menu_PlayerConfig_f(void);
void M_Menu_DownloadOptions_f(void);
void M_Menu_Credits_f(void);
void M_Menu_Multiplayer_f(void);
void M_Menu_JoinServer_f(void);
void M_Menu_AddressBook_f(void);
void M_Menu_StartServer_f(void);
void M_Menu_DMOptions_f(void);
void M_Menu_Video_f(void);
void M_Menu_Options_f(void);
void M_Menu_Keys_f(void);
void M_Menu_Quit_f(void);
void M_Menu_Credits(void);
//=============================================================================
/* Locals */
enum
{
MAX_MENU_DEPTH = 20,
NUM_CURSOR_FRAMES = 15
};
static const char * menu_in_sound = "misc/menu1.wav";
static const char * menu_move_sound = "misc/menu2.wav";
static const char * menu_out_sound = "misc/menu3.wav";
static void (*m_drawfunc)(void);
static const char * (*m_keyfunc)(int key);
typedef struct
{
void (*draw)(void);
const char * (*key)(int k);
} menulayer_t;
static menulayer_t m_layers[MAX_MENU_DEPTH];
static int m_menudepth;
static int m_main_cursor;
// [PS2_QUAKE]: config.cfg as it stood when the menu opened, or was last written from it, to tell
// on leaving a page whether the visit changed a bind or an archived cvar (see M_WriteChangedConfig).
static char * m_config_at_open;
static size_t m_config_at_open_len;
char * CL_ConfigurationText(size_t * length); // cl_main.c
// [PS2_QUAKE]: the controls menu waiting for a button to bind (declared with the keys menu in id's
// code). Moved up so M_ForceMenuOff can end it: SELECT's console toggle closes the menu from keys.c
// without the keys menu seeing the key, and a grab left set has the backend send game keys to
// every later menu and the console, which then ignore every button (see M_IsGrabbingKey).
static int bind_grab;
// play after drawing a frame, so caching won't disrupt the sound.
static qboolean m_entersound;
//=============================================================================
/* Support Routines */
static void M_Banner(char * name)
{
int w, h;
re.DrawGetPicSize(&w, &h, name);
re.DrawPic(viddef.width / 2 - w / 2, viddef.height / 2 - 110, name);
}
// [PS2_QUAKE]: Writes config.cfg if it differs from the copy taken as the menu opened, and keeps
// the new text as the copy. Called on leaving every page and on closing the menu: a console is
// usually switched off rather than quit, when the engine writes it otherwise, so a changed setting
// or bind would be lost. The backend writes nothing for a text the save device holds already, and
// an unchanged one never gets that far, so a visit that changed nothing costs a few KB of text.
static void M_WriteChangedConfig(void)
{
size_t length = 0;
char * text;
if (!m_config_at_open)
return;
text = CL_ConfigurationText(&length);
if (!text)
return;
if (length != m_config_at_open_len || memcmp(text, m_config_at_open, length) != 0)
{
Sys_SaveStoreConfig(text, (int)length);
free(m_config_at_open);
m_config_at_open = text;
m_config_at_open_len = length;
return;
}
free(text);
}
void M_PushMenu(void (*draw)(void), const char * (*key)(int k))
{
int i;
if (Cvar_VariableValue("maxclients") == 1 && Com_ServerState())
{
Cvar_Set("paused", "1");
}
// [PS2_QUAKE]: the config as the menu opens, for M_WriteChangedConfig.
if (m_menudepth == 0 && !m_config_at_open)
{
m_config_at_open = CL_ConfigurationText(&m_config_at_open_len);
}
// if this menu is already present, drop back to that level
// to avoid stacking menus by hotkeys
for (i = 0; i < m_menudepth; i++)
{
if (m_layers[i].draw == draw &&
m_layers[i].key == key)
{
m_menudepth = i;
}
}
if (i == m_menudepth)
{
if (m_menudepth >= MAX_MENU_DEPTH)
{
Com_Error(ERR_FATAL, "M_PushMenu: MAX_MENU_DEPTH exceeded!");
}
m_layers[m_menudepth].draw = m_drawfunc;
m_layers[m_menudepth].key = m_keyfunc;
m_menudepth++;
}
m_drawfunc = draw;
m_keyfunc = key;
m_entersound = true;
cls.key_dest = key_menu;
}
void M_ForceMenuOff(void)
{
M_WriteChangedConfig(); // [PS2_QUAKE]
free(m_config_at_open);
m_config_at_open = NULL;
m_drawfunc = 0;
m_keyfunc = 0;
cls.key_dest = key_game;
m_menudepth = 0;
bind_grab = false; // [PS2_QUAKE]: see its declaration
Key_ClearStates();
Cvar_Set("paused", "0");
}
void M_PopMenu(void)
{
S_StartLocalSound(menu_out_sound);
if (m_menudepth < 1)
Com_Error(ERR_FATAL, "M_PopMenu: depth < 1");
M_WriteChangedConfig(); // [PS2_QUAKE]: on leaving each page, not only the last
m_menudepth--;
m_drawfunc = m_layers[m_menudepth].draw;
m_keyfunc = m_layers[m_menudepth].key;
if (!m_menudepth)
M_ForceMenuOff();
}
const char * Default_MenuKey(menuframework_s * m, int key)
{
const char * sound = NULL;
menucommon_s * item;
if (m)
{
if ((item = Menu_ItemAtCursor(m)) != 0)
{
if (item->type == MTYPE_FIELD)
{
if (Field_Key((menufield_s *)item, key))
return NULL;
}
}
}
switch (key)
{
case K_ESCAPE:
M_PopMenu();
return menu_out_sound;
case K_KP_UPARROW:
case K_UPARROW:
if (m)
{
m->cursor--;
Menu_AdjustCursor(m, -1);
sound = menu_move_sound;
}
break;
case K_TAB:
if (m)
{
m->cursor++;
Menu_AdjustCursor(m, 1);
sound = menu_move_sound;
}
break;
case K_KP_DOWNARROW:
case K_DOWNARROW:
if (m)
{
m->cursor++;
Menu_AdjustCursor(m, 1);
sound = menu_move_sound;
}
break;
case K_KP_LEFTARROW:
case K_LEFTARROW:
if (m)
{
Menu_SlideItem(m, -1);
sound = menu_move_sound;
}
break;
case K_KP_RIGHTARROW:
case K_RIGHTARROW:
if (m)
{
Menu_SlideItem(m, 1);
sound = menu_move_sound;
}
break;
case K_MOUSE1:
case K_MOUSE2:
case K_MOUSE3:
case K_JOY1:
case K_JOY2:
case K_JOY3:
case K_JOY4:
case K_AUX1:
case K_AUX2:
case K_AUX3:
case K_AUX4:
case K_AUX5:
case K_AUX6:
case K_AUX7:
case K_AUX8:
case K_AUX9:
case K_AUX10:
case K_AUX11:
case K_AUX12:
case K_AUX13:
case K_AUX14:
case K_AUX15:
case K_AUX16:
case K_AUX17:
case K_AUX18:
case K_AUX19:
case K_AUX20:
case K_AUX21:
case K_AUX22:
case K_AUX23:
case K_AUX24:
case K_AUX25:
case K_AUX26:
case K_AUX27:
case K_AUX28:
case K_AUX29:
case K_AUX30:
case K_AUX31:
case K_AUX32:
case K_KP_ENTER:
case K_ENTER:
if (m)
Menu_SelectItem(m);
sound = menu_move_sound;
break;
}
return sound;
}
//=============================================================================
/*
================
M_DrawCharacter
Draws one solid graphics character
cx and cy are in 320*240 coordinates, and will be centered on
higher res screens.
================
*/
void M_DrawCharacter(int cx, int cy, int num)
{
re.DrawChar(cx + ((viddef.width - 320) >> 1), cy + ((viddef.height - 240) >> 1), num);
}
void M_Print(int cx, int cy, char * str)
{
while (*str)
{
M_DrawCharacter(cx, cy, (*str) + 128);
str++;
cx += 8;
}
}
void M_PrintWhite(int cx, int cy, char * str)
{
while (*str)
{
M_DrawCharacter(cx, cy, *str);
str++;
cx += 8;
}
}
void M_DrawPic(int x, int y, char * pic)
{
re.DrawPic(x + ((viddef.width - 320) >> 1), y + ((viddef.height - 240) >> 1), pic);
}
/*
=============
M_DrawCursor
Draws an animating cursor with the point at
x,y. The pic will extend to the left of x,
and both above and below y.
=============
*/
void M_DrawCursor(int x, int y, int f)
{
char cursorname[80];
static qboolean cached;
if (!cached)
{
int i;
for (i = 0; i < NUM_CURSOR_FRAMES; i++)
{
Com_sprintf(cursorname, sizeof(cursorname), "m_cursor%d", i);
re.RegisterPic(cursorname);
}
cached = true;
}
Com_sprintf(cursorname, sizeof(cursorname), "m_cursor%d", f);
re.DrawPic(x, y, cursorname);
}
void M_DrawTextBox(int x, int y, int width, int lines)
{
int cx, cy;
int n;
// draw left side
cx = x;
cy = y;
M_DrawCharacter(cx, cy, 1);
for (n = 0; n < lines; n++)
{
cy += 8;
M_DrawCharacter(cx, cy, 4);
}
M_DrawCharacter(cx, cy + 8, 7);
// draw middle
cx += 8;
while (width > 0)
{
cy = y;
M_DrawCharacter(cx, cy, 2);
for (n = 0; n < lines; n++)
{
cy += 8;
M_DrawCharacter(cx, cy, 5);
}
M_DrawCharacter(cx, cy + 8, 8);
width -= 1;
cx += 8;
}
// draw right side
cy = y;
M_DrawCharacter(cx, cy, 3);
for (n = 0; n < lines; n++)
{
cy += 8;
M_DrawCharacter(cx, cy, 6);
}
M_DrawCharacter(cx, cy + 8, 9);
}
/*
=======================================================================
[PS2_QUAKE]: POPUP MESSAGE BOX
A message drawn over everything - the game, other menus, the full-screen
console after an error drop - until any button is pressed. It is how the
player learns why saving or loading failed: the console can't be read or
typed into from a gamepad. Laid out like the video menu's notice
(ps2/renderer/vid.cpp).
=======================================================================
*/
enum
{
POPUP_CHARS = 38, // inner width of the box, which its border takes to all the menus' 320 columns
POPUP_MAX_LINES = 12 // message lines
};
static char m_popup_title[POPUP_CHARS + 1];
static char m_popup_lines[POPUP_MAX_LINES][POPUP_CHARS + 1];
static int m_popup_numlines;
// Breaks the text into lines at spaces, and at every '\n' ("\n\n" for a blank line).
static void M_Popup_Wrap(const char * text)
{
m_popup_numlines = 0;
while (*text && m_popup_numlines < POPUP_MAX_LINES)
{
int len = 0;
int lastSpace = -1;
while (text[len] && text[len] != '\n' && len < POPUP_CHARS)
{
if (text[len] == ' ')
lastSpace = len;
len++;
}
// the line is full and the word goes on: break at its start instead
if (text[len] && text[len] != '\n' && text[len] != ' ' && lastSpace > 0)
len = lastSpace;
memcpy(m_popup_lines[m_popup_numlines], text, len);
m_popup_lines[m_popup_numlines][len] = 0;
m_popup_numlines++;
text += len;
if (*text == '\n' || *text == ' ')
text++;
}
}
static void M_Popup_Draw(void)
{
static const char * prompt = "press any button";
// title, blank, the message, blank, prompt
const int lines = m_popup_numlines + 4;
const int boxX = (320 - (POPUP_CHARS + 2) * 8) / 2;
const int boxY = (240 - (lines + 2) * 8) / 2;
const int textX = ((viddef.width - 320) / 2) + boxX + 8;
const int textY = ((viddef.height - 240) / 2) + boxY + 8;
int i;
M_DrawTextBox(boxX, boxY, POPUP_CHARS, lines);
Menu_DrawStringDark(textX + (POPUP_CHARS - (int)strlen(m_popup_title)) * 4, textY, m_popup_title);
for (i = 0; i < m_popup_numlines; i++)
Menu_DrawString(textX, textY + (i + 2) * 8, m_popup_lines[i]);
Menu_DrawStringDark(textX + (POPUP_CHARS - (int)strlen(prompt)) * 4, textY + (lines - 1) * 8, prompt);
}
static const char * M_Popup_Key(int key)
{
M_PopMenu();
return NULL; // M_PopMenu played the sound
}
void M_Popup(const char * title, const char * text)
{
Com_sprintf(m_popup_title, sizeof(m_popup_title), "%s", title);
M_Popup_Wrap(text);
M_PushMenu(M_Popup_Draw, M_Popup_Key);
}
/*
=======================================================================
MAIN MENU
=======================================================================
*/
enum
{
MAIN_ITEMS = 4 // [PS2_QUAKE]: was 5, no Multiplayer (see M_Main_Draw)
};
void M_Main_Draw(void)
{
int i;
int w, h;
int ystart;
int xoffset;
int widest = -1;
int totalheight = 0;
char litname[80];
char * names[] =
{
"m_main_game",
//"m_main_multiplayer", // [PS2_QUAKE]: the PS2 has no network play, so no Multiplayer item
"m_main_options",
"m_main_video",
"m_main_quit",
0
};
for (i = 0; names[i] != 0; i++)
{
re.DrawGetPicSize(&w, &h, names[i]);
if (w > widest)
widest = w;
totalheight += (h + 12);
}
ystart = (viddef.height / 2 - 110);
xoffset = (viddef.width - widest + 70) / 2;
for (i = 0; names[i] != 0; i++)
{
if (i != m_main_cursor)
re.DrawPic(xoffset, ystart + i * 40 + 13, names[i]);
}
strcpy(litname, names[m_main_cursor]);
strcat(litname, "_sel");
re.DrawPic(xoffset, ystart + m_main_cursor * 40 + 13, litname);
M_DrawCursor(xoffset - 25, ystart + m_main_cursor * 40 + 11, (int)(cls.realtime / 100) % NUM_CURSOR_FRAMES);
re.DrawGetPicSize(&w, &h, "m_main_plaque");
re.DrawPic(xoffset - 30 - w, ystart, "m_main_plaque");
re.DrawPic(xoffset - 30 - w, ystart + h + 5, "m_main_logo");
}
const char * M_Main_Key(int key)
{
const char * sound = menu_move_sound;
switch (key)
{
case K_ESCAPE:
M_PopMenu();
break;
case K_KP_DOWNARROW:
case K_DOWNARROW:
if (++m_main_cursor >= MAIN_ITEMS)
m_main_cursor = 0;
return sound;
case K_KP_UPARROW:
case K_UPARROW:
if (--m_main_cursor < 0)
m_main_cursor = MAIN_ITEMS - 1;
return sound;
case K_KP_ENTER:
case K_ENTER:
m_entersound = true;
// [PS2_QUAKE]: no Multiplayer (see M_Main_Draw), so the items after it moved up one.
switch (m_main_cursor)
{
case 0:
M_Menu_Game_f();
break;
//case 1:
// M_Menu_Multiplayer_f();
// break;
case 1:
M_Menu_Options_f();
break;
case 2:
M_Menu_Video_f();
break;
case 3:
M_Menu_Quit_f();
break;
}
}
return NULL;
}
void M_Menu_Main_f(void)
{
M_PushMenu(M_Main_Draw, M_Main_Key);
}
/*
=======================================================================
MULTIPLAYER MENU
=======================================================================
*/
static menuframework_s s_multiplayer_menu;
static menuaction_s s_join_network_server_action;
static menuaction_s s_start_network_server_action;
static menuaction_s s_player_setup_action;
static void Multiplayer_MenuDraw(void)
{
M_Banner("m_banner_multiplayer");
Menu_AdjustCursor(&s_multiplayer_menu, 1);
Menu_Draw(&s_multiplayer_menu);
}
static void PlayerSetupFunc(void * unused)
{
M_Menu_PlayerConfig_f();
}
static void JoinNetworkServerFunc(void * unused)
{
M_Menu_JoinServer_f();
}
static void StartNetworkServerFunc(void * unused)
{
M_Menu_StartServer_f();
}
void Multiplayer_MenuInit(void)
{
s_multiplayer_menu.x = viddef.width * 0.50 - 64;
s_multiplayer_menu.nitems = 0;
s_join_network_server_action.generic.type = MTYPE_ACTION;
s_join_network_server_action.generic.flags = QMF_LEFT_JUSTIFY;
s_join_network_server_action.generic.x = 0;
s_join_network_server_action.generic.y = 0;
s_join_network_server_action.generic.name = " join network server";
s_join_network_server_action.generic.callback = JoinNetworkServerFunc;
s_start_network_server_action.generic.type = MTYPE_ACTION;
s_start_network_server_action.generic.flags = QMF_LEFT_JUSTIFY;
s_start_network_server_action.generic.x = 0;
s_start_network_server_action.generic.y = 10;
s_start_network_server_action.generic.name = " start network server";
s_start_network_server_action.generic.callback = StartNetworkServerFunc;
s_player_setup_action.generic.type = MTYPE_ACTION;
s_player_setup_action.generic.flags = QMF_LEFT_JUSTIFY;
s_player_setup_action.generic.x = 0;
s_player_setup_action.generic.y = 20;
s_player_setup_action.generic.name = " player setup";
s_player_setup_action.generic.callback = PlayerSetupFunc;
Menu_AddItem(&s_multiplayer_menu, (void *)&s_join_network_server_action);
Menu_AddItem(&s_multiplayer_menu, (void *)&s_start_network_server_action);
Menu_AddItem(&s_multiplayer_menu, (void *)&s_player_setup_action);
Menu_SetStatusBar(&s_multiplayer_menu, NULL);
Menu_Center(&s_multiplayer_menu);
}
const char * Multiplayer_MenuKey(int key)
{
return Default_MenuKey(&s_multiplayer_menu, key);
}
void M_Menu_Multiplayer_f(void)
{
Multiplayer_MenuInit();
M_PushMenu(Multiplayer_MenuDraw, Multiplayer_MenuKey);
}
/*
=======================================================================
KEYS MENU
=======================================================================
*/
char * bindnames[][2] =
{
{ "+attack", "attack" },
{ "weapnext", "next weapon" },
{ "+forward", "walk forward" },
{ "+back", "backpedal" },
{ "+left", "turn left" },
{ "+right", "turn right" },
{ "+speed", "run" },
{ "+moveleft", "step left" },
{ "+moveright", "step right" },
{ "+strafe", "sidestep" },
{ "+lookup", "look up" },
{ "+lookdown", "look down" },
{ "centerview", "center view" },
#if 0 // [PS2_QUAKE]: mouse look and keyboard look do nothing here: the sticks always look.
{ "+mlook", "mouse look" },
{ "+klook", "keyboard look" },
#endif
{ "+moveup", "up / jump" },
{ "+movedown", "down / crouch" },
{ "inven", "inventory" },
{ "invuse", "use item" },
{ "invdrop", "drop item" },
{ "invprev", "prev item" },
{ "invnext", "next item" },
{ "cmd help", "help computer" },
{ 0, 0 }
};
int keys_cursor;
// [PS2_QUAKE]: bind_grab moved up, next to the menu stack, for M_ForceMenuOff.
// [PS2_QUAKE]: read by the input backend, which then sends each gamepad button's game key
// rather than its menu key, so the bind lands on the key the button sends in play.
qboolean M_IsGrabbingKey(void)
{
return bind_grab != 0;
}
// [PS2_QUAKE]: the controls menu is about the gamepad. It lists, names and clears the keys
// its buttons send in play; a keyboard's binds (default.cfg's) are left as they are.
static const char * M_GamepadKeyName(int keynum)
{
const char * name = IN_GamepadKeyName(keynum);
return name ? name : Key_KeynumToString(keynum);
}
static menuframework_s s_keys_menu;
static menuaction_s s_keys_attack_action;
static menuaction_s s_keys_change_weapon_action;
static menuaction_s s_keys_walk_forward_action;
static menuaction_s s_keys_backpedal_action;
static menuaction_s s_keys_turn_left_action;
static menuaction_s s_keys_turn_right_action;
static menuaction_s s_keys_run_action;
static menuaction_s s_keys_step_left_action;
static menuaction_s s_keys_step_right_action;
static menuaction_s s_keys_sidestep_action;
static menuaction_s s_keys_look_up_action;
static menuaction_s s_keys_look_down_action;
static menuaction_s s_keys_center_view_action;
#if 0 // [PS2_QUAKE]: see bindnames.
static menuaction_s s_keys_mouse_look_action;
static menuaction_s s_keys_keyboard_look_action;
#endif
static menuaction_s s_keys_move_up_action;
static menuaction_s s_keys_move_down_action;
static menuaction_s s_keys_inventory_action;
static menuaction_s s_keys_inv_use_action;
static menuaction_s s_keys_inv_drop_action;
static menuaction_s s_keys_inv_prev_action;
static menuaction_s s_keys_inv_next_action;
static menuaction_s s_keys_help_computer_action;
static void M_UnbindCommand(char * command)
{
int j;
int l;
char * b;
l = strlen(command);
for (j = 0; j < 256; j++)
{
b = keybindings[j];
if (!b)
continue;
if (!IN_GamepadKeyName(j)) // [PS2_QUAKE]: gamepad buttons only
continue;
if (!strncmp(b, command, l))
Key_SetBinding(j, "");
}
}
static void M_FindKeysForCommand(char * command, int * twokeys)
{
int count;
int j;
int l;
char * b;
twokeys[0] = twokeys[1] = -1;
l = strlen(command);
count = 0;
for (j = 0; j < 256; j++)
{
b = keybindings[j];
if (!b)
continue;
if (!IN_GamepadKeyName(j)) // [PS2_QUAKE]: gamepad buttons only
continue;
if (!strncmp(b, command, l))
{
twokeys[count] = j;
count++;
if (count == 2)
break;
}
}
}
static void KeyCursorDrawFunc(menuframework_s * menu)
{
if (bind_grab)
re.DrawChar(menu->x, menu->y + menu->cursor * 9, '=');
else
re.DrawChar(menu->x, menu->y + menu->cursor * 9, 12 + ((int)(Sys_Milliseconds() / 250) & 1));
}
static void DrawKeyBindingFunc(void * self)
{
int keys[2];
menuaction_s * a = (menuaction_s *)self;
M_FindKeysForCommand(bindnames[a->generic.localdata[0]][0], keys);
if (keys[0] == -1)
{
Menu_DrawString(a->generic.x + a->generic.parent->x + 16, a->generic.y + a->generic.parent->y, "???");
}
else
{
int x;
const char * name;
name = M_GamepadKeyName(keys[0]); // [PS2_QUAKE]: the button's name, not JOY1/AUX1
Menu_DrawString(a->generic.x + a->generic.parent->x + 16, a->generic.y + a->generic.parent->y, name);
x = strlen(name) * 8;
if (keys[1] != -1)
{
Menu_DrawString(a->generic.x + a->generic.parent->x + 24 + x, a->generic.y + a->generic.parent->y, "or");
Menu_DrawString(a->generic.x + a->generic.parent->x + 48 + x, a->generic.y + a->generic.parent->y, M_GamepadKeyName(keys[1]));
}
}
}
static void KeyBindingFunc(void * self)
{
menuaction_s * a = (menuaction_s *)self;
int keys[2];
M_FindKeysForCommand(bindnames[a->generic.localdata[0]][0], keys);
if (keys[1] != -1)
M_UnbindCommand(bindnames[a->generic.localdata[0]][0]);
bind_grab = true;
Menu_SetStatusBar(&s_keys_menu, "press a button for this action"); // [PS2_QUAKE]
}
static void Keys_MenuInit(void)
{
int y = 0;
int i = 0;
s_keys_menu.x = viddef.width * 0.50;
s_keys_menu.nitems = 0;
s_keys_menu.cursordraw = KeyCursorDrawFunc;
s_keys_attack_action.generic.type = MTYPE_ACTION;
s_keys_attack_action.generic.flags = QMF_GRAYED;
s_keys_attack_action.generic.x = 0;
s_keys_attack_action.generic.y = y;
s_keys_attack_action.generic.ownerdraw = DrawKeyBindingFunc;
s_keys_attack_action.generic.localdata[0] = i;
s_keys_attack_action.generic.name = bindnames[s_keys_attack_action.generic.localdata[0]][1];
s_keys_change_weapon_action.generic.type = MTYPE_ACTION;
s_keys_change_weapon_action.generic.flags = QMF_GRAYED;
s_keys_change_weapon_action.generic.x = 0;
s_keys_change_weapon_action.generic.y = y += 9;
s_keys_change_weapon_action.generic.ownerdraw = DrawKeyBindingFunc;
s_keys_change_weapon_action.generic.localdata[0] = ++i;
s_keys_change_weapon_action.generic.name = bindnames[s_keys_change_weapon_action.generic.localdata[0]][1];
s_keys_walk_forward_action.generic.type = MTYPE_ACTION;
s_keys_walk_forward_action.generic.flags = QMF_GRAYED;
s_keys_walk_forward_action.generic.x = 0;
s_keys_walk_forward_action.generic.y = y += 9;
s_keys_walk_forward_action.generic.ownerdraw = DrawKeyBindingFunc;
s_keys_walk_forward_action.generic.localdata[0] = ++i;
s_keys_walk_forward_action.generic.name = bindnames[s_keys_walk_forward_action.generic.localdata[0]][1];
s_keys_backpedal_action.generic.type = MTYPE_ACTION;
s_keys_backpedal_action.generic.flags = QMF_GRAYED;
s_keys_backpedal_action.generic.x = 0;
s_keys_backpedal_action.generic.y = y += 9;
s_keys_backpedal_action.generic.ownerdraw = DrawKeyBindingFunc;
s_keys_backpedal_action.generic.localdata[0] = ++i;
s_keys_backpedal_action.generic.name = bindnames[s_keys_backpedal_action.generic.localdata[0]][1];
s_keys_turn_left_action.generic.type = MTYPE_ACTION;
s_keys_turn_left_action.generic.flags = QMF_GRAYED;
s_keys_turn_left_action.generic.x = 0;
s_keys_turn_left_action.generic.y = y += 9;
s_keys_turn_left_action.generic.ownerdraw = DrawKeyBindingFunc;
s_keys_turn_left_action.generic.localdata[0] = ++i;
s_keys_turn_left_action.generic.name = bindnames[s_keys_turn_left_action.generic.localdata[0]][1];
s_keys_turn_right_action.generic.type = MTYPE_ACTION;
s_keys_turn_right_action.generic.flags = QMF_GRAYED;
s_keys_turn_right_action.generic.x = 0;
s_keys_turn_right_action.generic.y = y += 9;
s_keys_turn_right_action.generic.ownerdraw = DrawKeyBindingFunc;
s_keys_turn_right_action.generic.localdata[0] = ++i;
s_keys_turn_right_action.generic.name = bindnames[s_keys_turn_right_action.generic.localdata[0]][1];
s_keys_run_action.generic.type = MTYPE_ACTION;
s_keys_run_action.generic.flags = QMF_GRAYED;
s_keys_run_action.generic.x = 0;
s_keys_run_action.generic.y = y += 9;
s_keys_run_action.generic.ownerdraw = DrawKeyBindingFunc;
s_keys_run_action.generic.localdata[0] = ++i;
s_keys_run_action.generic.name = bindnames[s_keys_run_action.generic.localdata[0]][1];
s_keys_step_left_action.generic.type = MTYPE_ACTION;
s_keys_step_left_action.generic.flags = QMF_GRAYED;
s_keys_step_left_action.generic.x = 0;
s_keys_step_left_action.generic.y = y += 9;
s_keys_step_left_action.generic.ownerdraw = DrawKeyBindingFunc;
s_keys_step_left_action.generic.localdata[0] = ++i;
s_keys_step_left_action.generic.name = bindnames[s_keys_step_left_action.generic.localdata[0]][1];
s_keys_step_right_action.generic.type = MTYPE_ACTION;
s_keys_step_right_action.generic.flags = QMF_GRAYED;
s_keys_step_right_action.generic.x = 0;
s_keys_step_right_action.generic.y = y += 9;
s_keys_step_right_action.generic.ownerdraw = DrawKeyBindingFunc;
s_keys_step_right_action.generic.localdata[0] = ++i;
s_keys_step_right_action.generic.name = bindnames[s_keys_step_right_action.generic.localdata[0]][1];
s_keys_sidestep_action.generic.type = MTYPE_ACTION;
s_keys_sidestep_action.generic.flags = QMF_GRAYED;
s_keys_sidestep_action.generic.x = 0;
s_keys_sidestep_action.generic.y = y += 9;
s_keys_sidestep_action.generic.ownerdraw = DrawKeyBindingFunc;
s_keys_sidestep_action.generic.localdata[0] = ++i;
s_keys_sidestep_action.generic.name = bindnames[s_keys_sidestep_action.generic.localdata[0]][1];
s_keys_look_up_action.generic.type = MTYPE_ACTION;