/
ui_shared.c
1852 lines (1636 loc) · 36.3 KB
/
ui_shared.c
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
/*
* Wolfenstein: Enemy Territory GPL Source Code
* Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
*
* ET: Legacy
* Copyright (C) 2012-2017 ET:Legacy team <mail@etlegacy.com>
*
* This file is part of ET: Legacy - http://www.etlegacy.com
*
* ET: Legacy 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 3 of the License, or
* (at your option) any later version.
*
* ET: Legacy 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 ET: Legacy. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, Wolfenstein: Enemy Territory GPL Source Code is also
* subject to certain additional terms. You should have received a copy
* of these additional terms immediately following the terms and conditions
* of the GNU General Public License which accompanied the source code.
* If not, please request a copy in writing from id Software at the address below.
*
* id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
*/
/**
* @file ui_shared.c
* @brief String allocation/managment
*/
#include "ui_shared.h"
#include "ui_local.h" // For CS settings/retrieval
scrollInfo_t scrollInfo;
void (*captureFunc)(void *p) = NULL;
void *captureData = NULL;
itemDef_t *itemCapture = NULL; // item that has the mouse captured ( if any )
displayContextDef_t *DC = NULL;
qboolean g_waitingForKey = qfalse;
qboolean g_editingField = qfalse;
itemDef_t *g_bindItem = NULL;
itemDef_t *g_editItem = NULL;
menuDef_t Menus[MAX_MENUS]; // defined menus
int menuCount = 0; // how many
// a stack for modal menus only, stores the menus to come back to
// (an item can be NULL, goes back to main menu / no action required)
menuDef_t *modalMenuStack[MAX_MODAL_MENUS];
int modalMenuCount = 0;
qboolean debugMode = qfalse;
int lastListBoxClickTime = 0;
#ifdef CGAME
#define MEM_POOL_SIZE 128 * 1024
#else
#define MEM_POOL_SIZE 2048 * 1024 // was 1536, 1024
#endif
static char memoryPool[MEM_POOL_SIZE];
static int allocPoint;
static qboolean outOfMemory;
/**
* @brief Convert rectangle-coordinates for use with the current aspectratio.
* @param[out] rect
*/
void Cui_WideRect(rectDef_t *rect)
{
rect->x *= DC->xscale;
rect->y *= DC->yscale;
rect->w *= DC->xscale;
rect->h *= DC->yscale;
if (DC->glconfig.windowAspect > RATIO43 && DC->getCVarValue("r_mode") != 11.f)
{
rect->x *= RATIO43 / DC->glconfig.windowAspect;
rect->w *= RATIO43 / DC->glconfig.windowAspect;
}
}
/**
* @brief Convert an x-coordinate for use with the current aspectratio.
* (if the current aspectratio is 4:3, then leave the x-coordinate unchanged)
* @param[in] x
* @return
*/
float Cui_WideX(float x)
{
return (DC->glconfig.windowAspect <= RATIO43) ? x : x * (DC->glconfig.windowAspect * RPRATIO43); // aspectratio / (4/3)
}
/**
* @brief The horizontal center of screen pixel-difference of a 4:3 ratio vs. the current aspectratio
*/
float Cui_WideXoffset(void)
{
return (DC->glconfig.windowAspect <= RATIO43) ? 0.0f : ((640.0f * (DC->glconfig.windowAspect * RPRATIO43)) - 640.0f) * 0.5f;
}
/**
* @brief UI_Alloc
* @param[in] size
* @return
*/
void *UI_Alloc(int size)
{
char *p;
if (allocPoint + size > MEM_POOL_SIZE)
{
outOfMemory = qtrue;
if (DC->Print)
{
DC->Print(S_COLOR_RED "UI_Alloc: Failure. UI out of memory!\n");
}
return NULL;
}
p = &memoryPool[allocPoint];
allocPoint += (size + 15) & ~15;
return p;
}
/**
* @brief UI_InitMemory
*/
void UI_InitMemory(void)
{
allocPoint = 0;
outOfMemory = qfalse;
}
/**
* @brief UI_OutOfMemory
* @return
*/
qboolean UI_OutOfMemory(void)
{
return outOfMemory;
}
#define HASH_TABLE_SIZE 2048
/**
* @brief Return a hash value for the string
* @param[in] str
* @return
*/
static long hashForString(const char *str)
{
int i = 0;
long hash = 0;
char letter;
while (str[i] != '\0')
{
letter = (char)tolower(str[i]);
hash += (long)(letter) * (i + 119);
i++;
}
hash &= (HASH_TABLE_SIZE - 1);
return hash;
}
typedef struct stringDef_s
{
struct stringDef_s *next;
const char *str;
} stringDef_t;
static int strPoolIndex = 0;
static char strPool[STRING_POOL_SIZE];
static int strHandleCount = 0;
static stringDef_t *strHandle[HASH_TABLE_SIZE];
/**
* @brief String_Alloc
* @param[in] p
* @return
*/
const char *String_Alloc(const char *p)
{
int len;
long hash;
stringDef_t *str, *last;
static const char *staticNULL = "";
if (p == NULL)
{
return NULL;
}
if (*p == 0)
{
return staticNULL;
}
hash = hashForString(p);
str = strHandle[hash];
while (str)
{
if (strcmp(p, str->str) == 0)
{
return str->str;
}
str = str->next;
}
len = strlen(p);
if (len + strPoolIndex + 1 < STRING_POOL_SIZE)
{
int ph = strPoolIndex;
strcpy(&strPool[strPoolIndex], p);
strPoolIndex += len + 1;
str = strHandle[hash];
last = str;
while (str && str->next)
{
str = str->next;
last = str;
}
str = UI_Alloc(sizeof(stringDef_t));
str->next = NULL;
str->str = &strPool[ph];
if (last)
{
last->next = str;
}
else
{
strHandle[hash] = str;
}
return &strPool[ph];
}
return NULL;
}
/**
* @brief String_Report
*/
void String_Report(void)
{
float f;
Com_Printf("Memory/String Pool Info\n");
Com_Printf("----------------\n");
f = strPoolIndex;
f /= STRING_POOL_SIZE;
f *= 100;
Com_Printf("String Pool is %.1f%% full, %i bytes out of %i used.\n", (double)f, strPoolIndex, STRING_POOL_SIZE);
f = allocPoint;
f /= MEM_POOL_SIZE;
f *= 100;
Com_Printf("Memory Pool is %.1f%% full, %i bytes out of %i used.\n", (double)f, allocPoint, MEM_POOL_SIZE);
}
/**
* @brief String_Init
*/
void String_Init(void)
{
int i;
for (i = 0; i < HASH_TABLE_SIZE; i++)
{
strHandle[i] = 0;
}
strHandleCount = 0;
strPoolIndex = 0;
menuCount = 0;
modalMenuCount = 0;
UI_InitMemory();
Item_SetupKeywordHash();
Menu_SetupKeywordHash();
if (DC && DC->getBindingBuf)
{
Controls_GetConfig();
}
}
/**
* @brief Lerp and clamp each component of @p a and @p b into @p c by the fraction @p t
* @param[in] a
* @param[in] b
* @param[in] c
* @param[in] t
*/
void LerpColor(vec4_t a, vec4_t b, vec4_t c, float t)
{
int i;
for (i = 0; i < 4; i++)
{
c[i] = a[i] + t * (b[i] - a[i]);
if (c[i] < 0)
{
c[i] = 0;
}
else if (c[i] > 1.0f)
{
c[i] = 1.0;
}
}
}
// display, window, menu, item code
/**
* @brief Initializes the display with a structure to all the drawing routines
* @param[in] dc
*/
void Init_Display(displayContextDef_t *dc)
{
DC = dc;
}
// type and style painting
/**
* @brief GradientBar_Paint
* @param[in] rect
* @param[in] color
*/
void GradientBar_Paint(rectDef_t *rect, vec4_t color)
{
// gradient bar takes two paints
DC->setColor(color);
DC->drawHandlePic(rect->x, rect->y, rect->w, rect->h, DC->Assets.gradientBar);
DC->setColor(NULL);
}
/**
* @brief Initializes a window structure ( windowDef_t ) with defaults
* @param[in,out] w
*/
void Window_Init(Window *w)
{
memset(w, 0, sizeof(windowDef_t));
w->borderSize = 1;
w->foreColor[0] = w->foreColor[1] = w->foreColor[2] = w->foreColor[3] = 1.0;
w->cinematic = -1;
}
/**
* @brief Fade
* @param[in,out] flags
* @param[in,out] f
* @param[in] clamp
* @param[in,out] nextTime
* @param[in] offsetTime
* @param[in] bFlags
* @param[in] fadeAmount
*/
void Fade(int *flags, float *f, float clamp, int *nextTime, int offsetTime, qboolean bFlags, float fadeAmount)
{
if (*flags & (WINDOW_FADINGOUT | WINDOW_FADINGIN))
{
if (DC->realTime > *nextTime)
{
*nextTime = DC->realTime + offsetTime;
if (*flags & WINDOW_FADINGOUT)
{
*f -= fadeAmount;
if (bFlags && *f <= 0.0f)
{
*flags &= ~(WINDOW_FADINGOUT | WINDOW_VISIBLE);
}
}
else
{
*f += fadeAmount;
if (*f >= clamp)
{
*f = clamp;
if (bFlags)
{
*flags &= ~WINDOW_FADINGIN;
}
}
}
}
}
}
/**
* @brief Window_Paint
* @param[in,out] w
* @param[in] fadeAmount
* @param[in] fadeClamp
* @param[in] fadeCycle
*/
void Window_Paint(Window *w, float fadeAmount, float fadeClamp, float fadeCycle)
{
vec4_t color = { 0.0, 0.0, 0.0, 0.0 };
rectDef_t fillRect;
if (w == NULL)
{
return;
}
if (debugMode)
{
color[0] = color[1] = color[2] = color[3] = 1;
DC->drawRect(w->rect.x, w->rect.y, w->rect.w, w->rect.h, 1, color);
}
if (w->style == 0 && w->border == 0)
{
return;
}
fillRect = w->rect;
// FIXME: do right thing for right border type
if (w->border != 0)
{
fillRect.x += w->borderSize;
fillRect.y += w->borderSize;
fillRect.w -= 2 * w->borderSize;
fillRect.h -= 2 * w->borderSize;
}
if (w->style == WINDOW_STYLE_FILLED)
{
// box, but possible a shader that needs filled
if (w->background)
{
Fade(&w->flags, &w->backColor[3], fadeClamp, &w->nextTime, fadeCycle, qtrue, fadeAmount);
DC->setColor(w->backColor);
DC->drawHandlePic(fillRect.x, fillRect.y, fillRect.w, fillRect.h, w->background);
DC->setColor(NULL);
}
else
{
DC->fillRect(fillRect.x, fillRect.y, fillRect.w, fillRect.h, w->backColor);
}
}
else if (w->style == WINDOW_STYLE_GRADIENT)
{
GradientBar_Paint(&fillRect, w->backColor);
// gradient bar
}
else if (w->style == WINDOW_STYLE_SHADER)
{
if (w->flags & WINDOW_FORECOLORSET)
{
DC->setColor(w->foreColor);
}
DC->drawHandlePic(fillRect.x, fillRect.y, fillRect.w, fillRect.h, w->background);
DC->setColor(NULL);
}
else if (w->style == WINDOW_STYLE_TEAMCOLOR)
{
if (DC->getTeamColor)
{
DC->getTeamColor(&color);
DC->fillRect(fillRect.x, fillRect.y, fillRect.w, fillRect.h, color);
}
}
else if (w->style == WINDOW_STYLE_CINEMATIC)
{
if (w->cinematic == -1)
{
w->cinematic = DC->playCinematic(w->cinematicName, fillRect.x, fillRect.y, fillRect.w, fillRect.h);
if (w->cinematic == -1)
{
w->cinematic = -2;
}
}
if (w->cinematic >= 0)
{
DC->runCinematicFrame(w->cinematic);
DC->drawCinematic(w->cinematic, fillRect.x, fillRect.y, fillRect.w, fillRect.h);
}
}
if (w->border == WINDOW_BORDER_FULL)
{
// WARNING: full HACK HACK HACK
if (w->style == WINDOW_STYLE_TEAMCOLOR)
{
if (color[0] > 0)
{
// red
color[0] = 1;
color[1] = color[2] = .5;
}
else
{
color[2] = 1;
color[0] = color[1] = .5;
}
color[3] = 1;
DC->drawRect(w->rect.x, w->rect.y, w->rect.w, w->rect.h, w->borderSize, color);
}
else
{
DC->drawRect(w->rect.x, w->rect.y, w->rect.w, w->rect.h, w->borderSize, w->borderColor);
}
}
else if (w->border == WINDOW_BORDER_HORZ)
{
// top/bottom
DC->setColor(w->borderColor);
DC->drawTopBottom(w->rect.x, w->rect.y, w->rect.w, w->rect.h, w->borderSize);
DC->setColor(NULL);
}
else if (w->border == WINDOW_BORDER_VERT)
{
// left right
DC->setColor(w->borderColor);
DC->drawSides(w->rect.x, w->rect.y, w->rect.w, w->rect.h, w->borderSize);
DC->setColor(NULL);
}
else if (w->border == WINDOW_BORDER_KCGRADIENT)
{
// this is just two gradient bars along each horz edge
rectDef_t r = w->rect;
r.h = w->borderSize;
GradientBar_Paint(&r, w->borderColor);
r.y = w->rect.y + w->rect.h - 1;
GradientBar_Paint(&r, w->borderColor);
}
}
/**
* @brief IsVisible
* @param[in] flags
* @return
*/
qboolean IsVisible(int flags)
{
return ((flags & WINDOW_VISIBLE) && !(flags & WINDOW_FADINGOUT));
}
/**
* @brief FileExists
* @param filename
* @return
*/
qboolean FileExists(const char *filename)
{
fileHandle_t f;
if (trap_FS_FOpenFile(filename, &f, FS_READ) < 0)
{
trap_FS_FCloseFile(f);
return qfalse;
}
else
{
trap_FS_FCloseFile(f);
return qtrue;
}
}
/**
* @brief AdjustFrom640
* @param[out] x
* @param[out] y
* @param[out] w
* @param[out] h
*/
void AdjustFrom640(float *x, float *y, float *w, float *h)
{
*x *= DC->xscale;
*y *= DC->yscale;
*w *= DC->xscale;
*h *= DC->yscale;
// adjust screen
if (DC->glconfig.windowAspect > RATIO43)
{
*x *= RATIO43 / DC->glconfig.windowAspect;
*w *= RATIO43 / DC->glconfig.windowAspect;
}
}
/**
* @brief Rect_ContainsPoint
* @param[in] rect
* @param[in] x
* @param[in] y
* @return
*/
qboolean Rect_ContainsPoint(rectDef_t *rect, float x, float y)
{
if (rect)
{
// correction for widescreen cursor coordinates..
x = Cui_WideX(x);
if (x > Cui_WideX(rect->x) && x < Cui_WideX(rect->x + rect->w) && y > rect->y && y < rect->y + rect->h)
{
return qtrue;
}
}
return qfalse;
}
/**
* @brief Rect_ContainsPointN
* @param[in] rect
* @param[in] x
* @param[in] y
* @return
*/
qboolean Rect_ContainsPointN(rectDef_t *rect, float x, float y)
{
if (rect)
{
if (x > rect->x && x < rect->x + rect->w + 200 && y > rect->y && y < rect->y + rect->h)
{
return qtrue;
}
}
return qfalse;
}
/**
* @brief Window_CloseCinematic
* @param[in,out] window
*/
void Window_CloseCinematic(windowDef_t *window)
{
if (window->style == WINDOW_STYLE_CINEMATIC && window->cinematic >= 0)
{
DC->stopCinematic(window->cinematic);
window->cinematic = -1;
}
}
/**
* @brief Display_CloseCinematics
*/
void Display_CloseCinematics(void)
{
int i;
for (i = 0; i < menuCount; i++)
{
Menu_CloseCinematics(&Menus[i]);
}
}
/**
* @brief Display_VisibleMenuCount
* @return
*/
int Display_VisibleMenuCount(void)
{
int i, count = 0;
for (i = 0; i < menuCount; i++)
{
if (Menus[i].window.flags & (WINDOW_FORCED | WINDOW_VISIBLE))
{
count++;
}
}
return count;
}
/**
* @brief ToWindowCoords
* @param[out] x
* @param[out] y
* @param[in] window
*/
void ToWindowCoords(float *x, float *y, windowDef_t *window)
{
*x += window->rect.x;
*y += window->rect.y;
}
/*
* @brief Rect_ToWindowCoords
* @param rect
* @param window
*
* @note Unused
void Rect_ToWindowCoords(rectDef_t *rect, windowDef_t *window)
{
ToWindowCoords(&rect->x, &rect->y, window);
}
*/
typedef struct
{
char *command;
int id; // unused
int defaultbind1_right;
int defaultbind2_right;
int defaultbind1_left;
int defaultbind2_left;
int bind1;
int bind2;
} bind_t;
/**
* @var g_bindings
* @brief
* @note These MUST be all lowercase now
*/
static bind_t g_bindings[] =
{
{ "+forward", 'w', -1, K_UPARROW, -1, -1, -1, -1 },
{ "+back", 's', -1, K_DOWNARROW, -1, -1, -1, -1 },
{ "+moveleft", 'a', -1, K_LEFTARROW, -1, -1, -1, -1 },
{ "+moveright", 'd', -1, K_RIGHTARROW, -1, -1, -1, -1 },
{ "+moveup", K_SPACE, -1, K_KP_INS, -1, -1, -1, -1 },
{ "+movedown", 'c', -1, K_CTRL, -1, -1, -1, -1 },
{ "+leanright", 'e', -1, K_PGDN, -1, -1, -1, -1 },
{ "+leanleft", 'q', -1, K_DEL, -1, -1, -1, -1 },
{ "+prone", 'x', -1, K_SHIFT, -1, -1, -1, -1 },
{ "+attack", K_MOUSE1, -1, K_MOUSE1, -1, -1, -1, -1 },
{ "weapalt", K_MOUSE2, -1, K_MOUSE2, -1, -1, -1, -1 },
{ "weapprev", K_MWHEELDOWN, -1, K_MWHEELDOWN, -1, -1, -1, -1 },
{ "weapnext", K_MWHEELUP, -1, K_MWHEELUP, -1, -1, -1, -1 },
{ "weaponbank 10", '0', -1, '0', -1, -1, -1, -1 },
{ "weaponbank 1", '1', -1, '1', -1, -1, -1, -1 },
{ "weaponbank 2", '2', -1, '2', -1, -1, -1, -1 },
{ "weaponbank 3", '3', -1, '3', -1, -1, -1, -1 },
{ "weaponbank 4", '4', -1, '4', -1, -1, -1, -1 },
{ "weaponbank 5", '5', -1, '5', -1, -1, -1, -1 },
{ "weaponbank 6", '6', -1, '6', -1, -1, -1, -1 },
{ "weaponbank 7", '7', -1, '7', -1, -1, -1, -1 },
{ "weaponbank 8", '8', -1, '8', -1, -1, -1, -1 },
{ "weaponbank 9", '9', -1, '9', -1, -1, -1, -1 },
{ "+sprint", K_SHIFT, -1, K_MOUSE3, -1, -1, -1, -1 },
{ "+speed", K_CAPSLOCK, -1, K_CAPSLOCK, -1, -1, -1, -1 },
{ "+activate", 'f', -1, K_ENTER, -1, -1, -1, -1 },
{ "+zoom", 'b', -1, 'b', -1, -1, -1, -1 },
{ "+mapexpand", 'g', -1, '#', -1, -1, -1, -1 },
{ "+reload", 'r', -1, K_END, -1, -1, -1, -1 },
{ "kill", 'k', -1, 'k', -1, -1, -1, -1 },
{ "+scores", K_TAB, -1, K_TAB, -1, -1, -1, -1 },
{ "+stats", K_ALT, -1, K_F9, -1, -1, -1, -1 },
{ "+topshots", K_CTRL, -1, K_F10, -1, -1, -1, -1 },
{ "+objectives", 'o', -1, 'o', -1, -1, -1, -1 },
{ "toggleconsole", '`', '~', '`', '~', -1, -1, -1 },
{ "togglemenu", K_ESCAPE, -1, K_ESCAPE, -1, -1, -1, -1 },
{ "openlimbomenu", 'l', -1, 'l', -1, -1, -1, -1 },
#ifdef FEATURE_MULTIVIEW
{ "mvactivate", 'm', -1, 'm', -1, -1, -1, -1 },
{ "spechelp", K_BACKSPACE, -1, K_BACKSPACE, -1, -1, -1, -1 },
#endif
{ "mapzoomout", ',', -1, '[', -1, -1, -1, -1 },
{ "mapzoomin", '.', -1, ']', -1, -1, -1, -1 },
{ "zoomin", '=', -1, '-', -1, -1, -1, -1 },
{ "zoomout", '-', -1, '=', -1, -1, -1, -1 },
{ "messagemode", 't', -1, 't', -1, -1, -1, -1 },
{ "messagemode2", 'y', -1, 'y', -1, -1, -1, -1 },
{ "messagemode3", 'u', -1, 'u', -1, -1, -1, -1 },
{ "mp_quickmessage", 'v', -1, 'v', -1, -1, -1, -1 },
{ "mp_fireteammsg", 'z', -1, 'c', -1, -1, -1, -1 },
{ "vote yes", K_F1, -1, K_F1, -1, -1, -1, -1 },
{ "vote no", K_F2, -1, K_F2, -1, -1, -1, -1 },
{ "ready", K_F3, -1, K_F3, -1, -1, -1, -1 },
{ "notready", K_F4, -1, K_F4, -1, -1, -1, -1 },
{ "autoscreenshot", K_F11, -1, K_F11, -1, -1, -1, -1 },
{ "autoRecord", K_F12, -1, K_F12, -1, -1, -1, -1 },
{ "mp_fireteamadmin", K_KP_ENTER, -1, K_KP_ENTER, -1, -1, -1, -1 },
{ "selectbuddy -1", K_KP_PLUS, -1, K_KP_PLUS, -1, -1, -1, -1 },
{ "selectbuddy 0", K_KP_END, -1, K_KP_END, -1, -1, -1, -1 },
{ "selectbuddy 1", K_KP_DOWNARROW, -1, K_KP_DOWNARROW, -1, -1, -1, -1 },
{ "selectbuddy 2", K_KP_PGDN, -1, K_KP_PGDN, -1, -1, -1, -1 },
{ "selectbuddy 3", K_KP_LEFTARROW, -1, K_KP_LEFTARROW, -1, -1, -1, -1 },
{ "selectbuddy 4", K_KP_5, -1, K_KP_5, -1, -1, -1, -1 },
{ "selectbuddy 5", K_KP_RIGHTARROW, -1, K_KP_RIGHTARROW, -1, -1, -1, -1 },
{ "selectbuddy 6", K_KP_HOME, -1, K_KP_HOME, -1, -1, -1, -1 },
{ "selectbuddy 7", K_KP_UPARROW, -1, K_KP_UPARROW, -1, -1, -1, -1 },
{ "selectbuddy -2", K_KP_MINUS, -1, K_KP_MINUS, -1, -1, -1, -1 },
};
static const int g_bindCount = sizeof(g_bindings) / sizeof(bind_t);
/**
* @brief Controls_GetConfig
*/
void Controls_GetConfig(void)
{
int i;
// iterate each command, get its numeric binding
for (i = 0; i < g_bindCount; i++)
{
DC->getKeysForBinding(g_bindings[i].command, &g_bindings[i].bind1, &g_bindings[i].bind2);
}
}
/**
* @brief Controls_SetConfig
* @param[in] restart
*/
void Controls_SetConfig(qboolean restart)
{
int i;
// iterate each command, get its numeric binding
for (i = 0; i < g_bindCount; i++)
{
if (g_bindings[i].bind1 != -1)
{
DC->setBinding(g_bindings[i].bind1, g_bindings[i].command);
if (g_bindings[i].bind2 != -1)
{
DC->setBinding(g_bindings[i].bind2, g_bindings[i].command);
}
}
}
if (restart)
{
DC->executeText(EXEC_APPEND, "in_restart\n");
}
}
/**
* @brief Controls_SetDefaults
* @param[in] lefthanded
*/
void Controls_SetDefaults(qboolean lefthanded)
{
int i;
// iterate each command, set its default binding
for (i = 0; i < g_bindCount; i++)
{
g_bindings[i].bind1 = lefthanded ? g_bindings[i].defaultbind1_left : g_bindings[i].defaultbind1_right;
g_bindings[i].bind2 = lefthanded ? g_bindings[i].defaultbind2_left : g_bindings[i].defaultbind2_right;
}
}
/**
* @brief Binding_IDFromName
* @param[in] name
* @return
*/
int Binding_IDFromName(const char *name)
{
int i;
for (i = 0; i < g_bindCount; i++)
{
if (!Q_stricmp(name, g_bindings[i].command))
{
return i;
}
}
return -1;
}
/**
* @brief Binding_Set
* @param[in] id
* @param[in] b1
* @param[in] b2
*/
void Binding_Set(int id, int b1, int b2)
{
if (id != -1)
{
if (b1 != -2)
{
int key1;
int key2;
// Set the current value of bind1 to bind2
DC->getKeysForBinding(g_bindings[id].command, &key1, &key2);
Binding_Set(id, -2, key1);
Binding_Unset(id, 1);
g_bindings[id].bind1 = b1;
}
if (b2 != -2)
{
Binding_Unset(id, 2);
g_bindings[id].bind2 = b2;
}
}
}
/**
* @brief Binding_Unset
* @param[in] id
* @param[in] index
*/
void Binding_Unset(int id, int index)
{
int key1;
int key2;
// Find the keys binded to action
DC->getKeysForBinding(g_bindings[id].command, &key1, &key2);
// Unbind the key1 or key2 according to index
switch (index)
{
case 1:
DC->setBinding(key1, "");
break;
case 2:
DC->setBinding(key2, "");
break;
default:
break;
}
}
/**
* @brief Binding_Check
* @param[in] id
* @param[in] b1
* @param[in] key
* @return
*/
qboolean Binding_Check(int id, qboolean b1, int key)
{
if (id != -1)
{
if (b1)
{
if (g_bindings[id].bind1 == key)
{
return qtrue;
}
}
else
{
if (g_bindings[id].bind2 == key)
{
return qtrue;
}
}
}
return qfalse;
}
/**
* @brief Binding_Get
* @param[in] id
* @param[in] b1
* @return
*/
int Binding_Get(int id, qboolean b1)
{
if (id != -1)
{
if (b1)
{
return g_bindings[id].bind1;
}
else
{
return g_bindings[id].bind2;
}
}
return -1;
}
/**
* @brief Binding_Count
* @return