-
Notifications
You must be signed in to change notification settings - Fork 606
/
ui_main.c
10634 lines (9381 loc) · 292 KB
/
ui_main.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
/*
===========================================================================
Copyright (C) 1999 - 2005, Id Software, Inc.
Copyright (C) 2000 - 2013, Raven Software, Inc.
Copyright (C) 2001 - 2013, Activision, Inc.
Copyright (C) 2005 - 2015, ioquake3 contributors
Copyright (C) 2013 - 2015, OpenJK contributors
This file is part of the OpenJK source code.
OpenJK is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
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, see <http://www.gnu.org/licenses/>.
===========================================================================
*/
/*
=======================================================================
USER INTERFACE MAIN
=======================================================================
*/
// use this to get a demo build without an explicit demo build, i.e. to get the demo ui files to build
//#define PRE_RELEASE_TADEMO
#include <stdlib.h>
#include "ghoul2/G2.h"
#include "ui_local.h"
#include "qcommon/qfiles.h"
#include "qcommon/game_version.h"
#include "ui_force.h"
#include "cgame/animtable.h" //we want this to be compiled into the module because we access it in the shared module.
#include "game/bg_saga.h"
#include "ui_shared.h"
NORETURN_PTR void (*Com_Error)( int level, const char *error, ... );
void (*Com_Printf)( const char *msg, ... );
extern void UI_SaberAttachToChar( itemDef_t *item );
const char *forcepowerDesc[NUM_FORCE_POWERS] =
{
"@MENUS_OF_EFFECT_JEDI_ONLY_NEFFECT",
"@MENUS_DURATION_IMMEDIATE_NAREA",
"@MENUS_DURATION_5_SECONDS_NAREA",
"@MENUS_DURATION_INSTANTANEOUS",
"@MENUS_INSTANTANEOUS_EFFECT_NAREA",
"@MENUS_DURATION_VARIABLE_20",
"@MENUS_DURATION_INSTANTANEOUS_NAREA",
"@MENUS_OF_EFFECT_LIVING_PERSONS",
"@MENUS_DURATION_VARIABLE_10",
"@MENUS_DURATION_VARIABLE_NAREA",
"@MENUS_DURATION_CONTINUOUS_NAREA",
"@MENUS_OF_EFFECT_JEDI_ALLIES_NEFFECT",
"@MENUS_EFFECT_JEDI_ALLIES_NEFFECT",
"@MENUS_VARIABLE_NAREA_OF_EFFECT",
"@MENUS_EFFECT_NAREA_OF_EFFECT",
"@SP_INGAME_FORCE_SABER_OFFENSE_DESC",
"@SP_INGAME_FORCE_SABER_DEFENSE_DESC",
"@SP_INGAME_FORCE_SABER_THROW_DESC"
};
// Movedata Sounds
enum
{
MDS_NONE = 0,
MDS_FORCE_JUMP,
MDS_ROLL,
MDS_SABER,
MDS_MOVE_SOUNDS_MAX
};
enum
{
MD_ACROBATICS = 0,
MD_SINGLE_FAST,
MD_SINGLE_MEDIUM,
MD_SINGLE_STRONG,
MD_DUAL_SABERS,
MD_SABER_STAFF,
MD_MOVE_TITLE_MAX
};
// Some hard coded badness
// At some point maybe this should be externalized to a .dat file
const char *datapadMoveTitleData[MD_MOVE_TITLE_MAX] =
{
"@MENUS_ACROBATICS",
"@MENUS_SINGLE_FAST",
"@MENUS_SINGLE_MEDIUM",
"@MENUS_SINGLE_STRONG",
"@MENUS_DUAL_SABERS",
"@MENUS_SABER_STAFF",
};
const char *datapadMoveTitleBaseAnims[MD_MOVE_TITLE_MAX] =
{
"BOTH_RUN1",
"BOTH_SABERFAST_STANCE",
"BOTH_STAND2",
"BOTH_SABERSLOW_STANCE",
"BOTH_SABERDUAL_STANCE",
"BOTH_SABERSTAFF_STANCE",
};
#define MAX_MOVES 16
typedef struct datpadmovedata_s
{
const char *title;
const char *desc;
const char *anim;
short sound;
} datpadmovedata_t;
static datpadmovedata_t datapadMoveData[MD_MOVE_TITLE_MAX][MAX_MOVES] = {
{// Acrobatics
{ "@MENUS_FORCE_JUMP1", "@MENUS_FORCE_JUMP1_DESC", "BOTH_FORCEJUMP1", MDS_FORCE_JUMP },
{ "@MENUS_FORCE_FLIP", "@MENUS_FORCE_FLIP_DESC", "BOTH_FLIP_F", MDS_FORCE_JUMP },
{ "@MENUS_ROLL", "@MENUS_ROLL_DESC", "BOTH_ROLL_F", MDS_ROLL },
{ "@MENUS_BACKFLIP_OFF_WALL", "@MENUS_BACKFLIP_OFF_WALL_DESC", "BOTH_WALL_FLIP_BACK1", MDS_FORCE_JUMP },
{ "@MENUS_SIDEFLIP_OFF_WALL", "@MENUS_SIDEFLIP_OFF_WALL_DESC", "BOTH_WALL_FLIP_RIGHT", MDS_FORCE_JUMP },
{ "@MENUS_WALL_RUN", "@MENUS_WALL_RUN_DESC", "BOTH_WALL_RUN_RIGHT", MDS_FORCE_JUMP },
{ "@MENUS_WALL_GRAB_JUMP", "@MENUS_WALL_GRAB_JUMP_DESC", "BOTH_FORCEWALLREBOUND_FORWARD",MDS_FORCE_JUMP },
{ "@MENUS_RUN_UP_WALL_BACKFLIP", "@MENUS_RUN_UP_WALL_BACKFLIP_DESC", "BOTH_FORCEWALLRUNFLIP_START", MDS_FORCE_JUMP },
{ "@MENUS_JUMPUP_FROM_KNOCKDOWN", "@MENUS_JUMPUP_FROM_KNOCKDOWN_DESC", "BOTH_KNOCKDOWN3", MDS_NONE },
{ "@MENUS_JUMPKICK_FROM_KNOCKDOWN", "@MENUS_JUMPKICK_FROM_KNOCKDOWN_DESC", "BOTH_KNOCKDOWN2", MDS_NONE },
{ "@MENUS_ROLL_FROM_KNOCKDOWN", "@MENUS_ROLL_FROM_KNOCKDOWN_DESC", "BOTH_KNOCKDOWN1", MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
},
{//Single Saber, Fast Style
{ "@MENUS_STAB_BACK", "@MENUS_STAB_BACK_DESC", "BOTH_A2_STABBACK1", MDS_SABER },
{ "@MENUS_LUNGE_ATTACK", "@MENUS_LUNGE_ATTACK_DESC", "BOTH_LUNGE2_B__T_", MDS_SABER },
{ "@MENUS_FAST_ATTACK_KATA", "@MENUS_FAST_ATTACK_KATA_DESC", "BOTH_A1_SPECIAL", MDS_SABER },
{ "@MENUS_ATTACK_ENEMYONGROUND", "@MENUS_ATTACK_ENEMYONGROUND_DESC", "BOTH_STABDOWN", MDS_FORCE_JUMP },
{ "@MENUS_CARTWHEEL", "@MENUS_CARTWHEEL_DESC", "BOTH_ARIAL_RIGHT", MDS_FORCE_JUMP },
{ "@MENUS_BOTH_ROLL_STAB", "@MENUS_BOTH_ROLL_STAB2_DESC", "BOTH_ROLL_STAB", MDS_SABER },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
},
{//Single Saber, Medium Style
{ "@MENUS_SLASH_BACK", "@MENUS_SLASH_BACK_DESC", "BOTH_ATTACK_BACK", MDS_SABER },
{ "@MENUS_FLIP_ATTACK", "@MENUS_FLIP_ATTACK_DESC", "BOTH_JUMPFLIPSLASHDOWN1", MDS_FORCE_JUMP },
{ "@MENUS_MEDIUM_ATTACK_KATA", "@MENUS_MEDIUM_ATTACK_KATA_DESC", "BOTH_A2_SPECIAL", MDS_SABER },
{ "@MENUS_ATTACK_ENEMYONGROUND", "@MENUS_ATTACK_ENEMYONGROUND_DESC", "BOTH_STABDOWN", MDS_FORCE_JUMP },
{ "@MENUS_CARTWHEEL", "@MENUS_CARTWHEEL_DESC", "BOTH_ARIAL_RIGHT", MDS_FORCE_JUMP },
{ "@MENUS_BOTH_ROLL_STAB", "@MENUS_BOTH_ROLL_STAB2_DESC", "BOTH_ROLL_STAB", MDS_SABER },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
},
{//Single Saber, Strong Style
{ "@MENUS_SLASH_BACK", "@MENUS_SLASH_BACK_DESC", "BOTH_ATTACK_BACK", MDS_SABER },
{ "@MENUS_JUMP_ATTACK", "@MENUS_JUMP_ATTACK_DESC", "BOTH_FORCELEAP2_T__B_", MDS_FORCE_JUMP },
{ "@MENUS_STRONG_ATTACK_KATA", "@MENUS_STRONG_ATTACK_KATA_DESC", "BOTH_A3_SPECIAL", MDS_SABER },
{ "@MENUS_ATTACK_ENEMYONGROUND", "@MENUS_ATTACK_ENEMYONGROUND_DESC", "BOTH_STABDOWN", MDS_FORCE_JUMP },
{ "@MENUS_CARTWHEEL", "@MENUS_CARTWHEEL_DESC", "BOTH_ARIAL_RIGHT", MDS_FORCE_JUMP },
{ "@MENUS_BOTH_ROLL_STAB", "@MENUS_BOTH_ROLL_STAB2_DESC", "BOTH_ROLL_STAB", MDS_SABER },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
},
{//Dual Sabers
{ "@MENUS_SLASH_BACK", "@MENUS_SLASH_BACK_DESC", "BOTH_ATTACK_BACK", MDS_SABER },
{ "@MENUS_FLIP_FORWARD_ATTACK", "@MENUS_FLIP_FORWARD_ATTACK_DESC", "BOTH_JUMPATTACK6", MDS_FORCE_JUMP },
{ "@MENUS_DUAL_SABERS_TWIRL", "@MENUS_DUAL_SABERS_TWIRL_DESC", "BOTH_SPINATTACK6", MDS_SABER },
{ "@MENUS_ATTACK_ENEMYONGROUND", "@MENUS_ATTACK_ENEMYONGROUND_DESC", "BOTH_STABDOWN_DUAL", MDS_FORCE_JUMP },
{ "@MENUS_DUAL_SABER_BARRIER", "@MENUS_DUAL_SABER_BARRIER_DESC", "BOTH_A6_SABERPROTECT", MDS_SABER },
{ "@MENUS_DUAL_STAB_FRONT_BACK", "@MENUS_DUAL_STAB_FRONT_BACK_DESC", "BOTH_A6_FB", MDS_SABER },
{ "@MENUS_DUAL_STAB_LEFT_RIGHT", "@MENUS_DUAL_STAB_LEFT_RIGHT_DESC", "BOTH_A6_LR", MDS_SABER },
{ "@MENUS_CARTWHEEL", "@MENUS_CARTWHEEL_DESC", "BOTH_ARIAL_RIGHT", MDS_FORCE_JUMP },
{ "@MENUS_BOTH_ROLL_STAB", "@MENUS_BOTH_ROLL_STAB_DESC", "BOTH_ROLL_STAB", MDS_SABER },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
},
{// Saber Staff
{ "@MENUS_STAB_BACK", "@MENUS_STAB_BACK_DESC", "BOTH_A2_STABBACK1", MDS_SABER },
{ "@MENUS_BACK_FLIP_ATTACK", "@MENUS_BACK_FLIP_ATTACK_DESC", "BOTH_JUMPATTACK7", MDS_FORCE_JUMP },
{ "@MENUS_SABER_STAFF_TWIRL", "@MENUS_SABER_STAFF_TWIRL_DESC", "BOTH_SPINATTACK7", MDS_SABER },
{ "@MENUS_ATTACK_ENEMYONGROUND", "@MENUS_ATTACK_ENEMYONGROUND_DESC", "BOTH_STABDOWN_STAFF", MDS_FORCE_JUMP },
{ "@MENUS_SPINNING_KATA", "@MENUS_SPINNING_KATA_DESC", "BOTH_A7_SOULCAL", MDS_SABER },
{ "@MENUS_KICK1", "@MENUS_KICK1_DESC", "BOTH_A7_KICK_F", MDS_FORCE_JUMP },
{ "@MENUS_JUMP_KICK", "@MENUS_JUMP_KICK_DESC", "BOTH_A7_KICK_F_AIR", MDS_FORCE_JUMP },
{ "@MENUS_BUTTERFLY_ATTACK", "@MENUS_BUTTERFLY_ATTACK_DESC", "BOTH_BUTTERFLY_FR1", MDS_SABER },
{ "@MENUS_BOTH_ROLL_STAB", "@MENUS_BOTH_ROLL_STAB2_DESC", "BOTH_ROLL_STAB", MDS_SABER },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE },
{ NULL, NULL, NULL, MDS_NONE }
}
};
static siegeClassDesc_t g_UIClassDescriptions[MAX_SIEGE_CLASSES];
static siegeTeam_t *siegeTeam1 = NULL, *siegeTeam2 = NULL;
static int g_UIGloballySelectedSiegeClass = -1;
//Cut down version of the stuff used in the game code
//This is just the bare essentials of what we need to load animations properly for ui ghoul2 models.
//This function doesn't need to be sync'd with the BG_ version in bg_panimate.c unless some sort of fundamental change
//is made. Just make sure the variables/functions accessed in ui_shared.c exist in both modules.
qboolean UIPAFtextLoaded = qfalse;
animation_t uiHumanoidAnimations[MAX_TOTALANIMATIONS]; //humanoid animations are the only ones that are statically allocated.
bgLoadedAnim_t bgAllAnims[MAX_ANIM_FILES];
int uiNumAllAnims = 1; //start off at 0, because 0 will always be assigned to humanoid.
animation_t *UI_AnimsetAlloc(void)
{
assert (uiNumAllAnims < MAX_ANIM_FILES);
bgAllAnims[uiNumAllAnims].anims = (animation_t *) BG_Alloc(sizeof(animation_t)*MAX_TOTALANIMATIONS);
return bgAllAnims[uiNumAllAnims].anims;
}
/*
======================
UI_ParseAnimationFile
Read a configuration file containing animation counts and rates
models/players/visor/animation.cfg, etc
======================
*/
static char UIPAFtext[60000];
int UI_ParseAnimationFile(const char *filename, animation_t *animset, qboolean isHumanoid)
{
char *text_p;
int len;
int i;
char *token;
float fps;
int usedIndex = -1;
int nextIndex = uiNumAllAnims;
fileHandle_t f;
int animNum;
if (!isHumanoid)
{
i = 1;
while (i < uiNumAllAnims)
{ //see if it's been loaded already
if (!Q_stricmp(bgAllAnims[i].filename, filename))
{
animset = bgAllAnims[i].anims;
return i; //alright, we already have it.
}
i++;
}
//Looks like it has not yet been loaded. Allocate space for the anim set if we need to, and continue along.
if (!animset)
{
if (strstr(filename, "players/_humanoid/"))
{ //then use the static humanoid set.
animset = uiHumanoidAnimations;
isHumanoid = qtrue;
nextIndex = 0;
}
else
{
animset = UI_AnimsetAlloc();
if (!animset)
{
assert(!"Anim set alloc failed!");
return -1;
}
}
}
}
#ifdef _DEBUG
else
{
assert(animset);
}
#endif
// load the file
if (!UIPAFtextLoaded || !isHumanoid)
{ //rww - We are always using the same animation config now. So only load it once.
len = trap->FS_Open( filename, &f, FS_READ );
if ( !f ) {
return -1;
}
if ( len >= sizeof( UIPAFtext ) - 1 ) {
trap->FS_Close( f );
Com_Error(ERR_DROP, "%s exceeds the allowed ui-side animation buffer!", filename);
}
trap->FS_Read( UIPAFtext, len, f );
UIPAFtext[len] = 0;
trap->FS_Close( f );
}
else
{
return 0; //humanoid index
}
// parse the text
text_p = UIPAFtext;
//FIXME: have some way of playing anims backwards... negative numFrames?
//initialize anim array so that from 0 to MAX_ANIMATIONS, set default values of 0 1 0 100
for(i = 0; i < MAX_ANIMATIONS; i++)
{
animset[i].firstFrame = 0;
animset[i].numFrames = 0;
animset[i].loopFrames = -1;
animset[i].frameLerp = 100;
// animset[i].initialLerp = 100;
}
COM_BeginParseSession ("UI_ParseAnimationFile");
// read information for each frame
while(1)
{
token = COM_Parse( (const char **)(&text_p) );
if ( !token || !token[0])
{
break;
}
animNum = GetIDForString(animTable, token);
if(animNum == -1)
{
//#ifndef FINAL_BUILD
#ifdef _DEBUG
//Com_Printf(S_COLOR_RED"WARNING: Unknown token %s in %s\n", token, filename);
#endif
continue;
}
token = COM_Parse( (const char **)(&text_p) );
if ( !token )
{
break;
}
animset[animNum].firstFrame = atoi( token );
token = COM_Parse( (const char **)(&text_p) );
if ( !token )
{
break;
}
animset[animNum].numFrames = atoi( token );
token = COM_Parse( (const char **)(&text_p) );
if ( !token )
{
break;
}
animset[animNum].loopFrames = atoi( token );
token = COM_Parse( (const char **)(&text_p) );
if ( !token )
{
break;
}
fps = atof( token );
if ( fps == 0 )
{
fps = 1;//Don't allow divide by zero error
}
if ( fps < 0 )
{//backwards
animset[animNum].frameLerp = floor(1000.0f / fps);
}
else
{
animset[animNum].frameLerp = ceil(1000.0f / fps);
}
// animset[animNum].initialLerp = ceil(1000.0f / fabs(fps));
}
#ifdef _DEBUG
//Check the array, and print the ones that have nothing in them.
/*
for(i = 0; i < MAX_ANIMATIONS; i++)
{
if (animTable[i].name != NULL) // This animation reference exists.
{
if (animset[i].firstFrame <= 0 && animset[i].numFrames <=0)
{ // This is an empty animation reference.
Com_Printf("***ANIMTABLE reference #%d (%s) is empty!\n", i, animTable[i].name);
}
}
}
*/
#endif // _DEBUG
if (isHumanoid)
{
bgAllAnims[0].anims = animset;
Q_strncpyz(bgAllAnims[0].filename, filename, sizeof(bgAllAnims[0].filename));
UIPAFtextLoaded = qtrue;
usedIndex = 0;
}
else
{
bgAllAnims[nextIndex].anims = animset;
Q_strncpyz(bgAllAnims[nextIndex].filename, filename, sizeof(bgAllAnims[nextIndex].filename));
usedIndex = nextIndex;
if (nextIndex)
{ //don't bother increasing the number if this ended up as a humanoid load.
uiNumAllAnims++;
}
else
{
UIPAFtextLoaded = qtrue;
usedIndex = 0;
}
}
return usedIndex;
}
//menuDef_t *Menus_FindByName(const char *p);
void Menu_ShowItemByName(menuDef_t *menu, const char *p, qboolean bShow);
void UpdateForceUsed();
char holdSPString[MAX_STRING_CHARS]={0};
uiInfo_t uiInfo;
static void UI_StartServerRefresh(qboolean full);
static void UI_StopServerRefresh( void );
static void UI_DoServerRefresh( void );
static void UI_BuildServerDisplayList(int force);
static void UI_BuildServerStatus(qboolean force);
static void UI_BuildFindPlayerList(qboolean force);
static int QDECL UI_ServersQsortCompare( const void *arg1, const void *arg2 );
static int UI_MapCountByGameType(qboolean singlePlayer);
static int UI_HeadCountByColor( void );
static void UI_ParseGameInfo(const char *teamFile);
static const char *UI_SelectedMap(int index, int *actual);
static int UI_GetIndexFromSelection(int actual);
static void UI_SiegeClassCnt( const int team );
int uiSkinColor=TEAM_FREE;
int uiHoldSkinColor=TEAM_FREE; // Stores the skin color so that in non-team games, the player screen remembers the team you chose, in case you're coming back from the force powers screen.
static const char *skillLevels[] = {
"SKILL1", // "Initiate"
"SKILL2", // "Padawan"
"SKILL3", // "Jedi"
"SKILL4", // "Jedi Knight"
"SKILL5" // "Jedi Master"
};
static const size_t numSkillLevels = ARRAY_LEN( skillLevels );
static const char *gameTypes[GT_MAX_GAME_TYPE] = {
"FFA",
"Holocron",
"JediMaster",
"Duel",
"PowerDuel",
"SP",
"Team FFA",
"Siege",
"CTF",
"CTY",
};
static const int numGameTypes = ARRAY_LEN( gameTypes );
static char* netNames[] = {
"???",
"UDP",
NULL
};
static const int numNetNames = ARRAY_LEN( netNames ) - 1;
const char *UI_GetStringEdString(const char *refSection, const char *refName);
const char *UI_TeamName(int team) {
if (team==TEAM_RED)
return "RED";
else if (team==TEAM_BLUE)
return "BLUE";
else if (team==TEAM_SPECTATOR)
return "SPECTATOR";
return "FREE";
}
// returns either string or NULL for OOR...
//
static const char *GetCRDelineatedString( const char *psStripFileRef, const char *psStripStringRef, int iIndex)
{
static char sTemp[256];
const char *psList = UI_GetStringEdString(psStripFileRef, psStripStringRef);
char *p;
while (iIndex--)
{
psList = strchr(psList,'\n');
if (!psList){
return NULL; // OOR
}
psList++;
}
Q_strncpyz(sTemp,psList, sizeof(sTemp));
p = strchr(sTemp,'\n');
if (p) {
*p = '\0';
}
return sTemp;
}
static const char *GetMonthAbbrevString( int iMonth )
{
const char *p = GetCRDelineatedString("MP_INGAME","MONTHS", iMonth);
return p ? p : "Jan"; // sanity
}
#define UIAS_LOCAL 0
#define UIAS_GLOBAL1 1
#define UIAS_GLOBAL2 2
#define UIAS_GLOBAL3 3
#define UIAS_GLOBAL4 4
#define UIAS_GLOBAL5 5
#define UIAS_FAVORITES 6
#define UI_MAX_MASTER_SERVERS 5
// Convert ui's net source to AS_* used by trap calls.
int UI_SourceForLAN( void ) {
switch ( ui_netSource.integer ) {
default:
case UIAS_LOCAL:
return AS_LOCAL;
case UIAS_GLOBAL1:
case UIAS_GLOBAL2:
case UIAS_GLOBAL3:
case UIAS_GLOBAL4:
case UIAS_GLOBAL5:
return AS_GLOBAL;
case UIAS_FAVORITES:
return AS_FAVORITES;
}
}
/*
static const char *netSources[] = {
"Local",
"Internet",
"Favorites"
// "Mplayer"
};
static const int numNetSources = ARRAY_LEN(netSources);
*/
static const int numNetSources = 7; // now hard-entered in StringEd file
static const char *GetNetSourceString(int iSource)
{
static char result[256] = {0};
Q_strncpyz( result, GetCRDelineatedString( "MP_INGAME", "NET_SOURCES", UI_SourceForLAN() ), sizeof(result) );
if ( iSource >= UIAS_GLOBAL1 && iSource <= UIAS_GLOBAL5 ) {
Q_strcat( result, sizeof(result), va( " %d", iSource ) );
}
return result;
}
void AssetCache(void) {
int n;
//if (Assets.textFont == NULL) {
//}
//Com_Printf("Menu Size: %i bytes\n", sizeof(Menus));
uiInfo.uiDC.Assets.gradientBar = trap->R_RegisterShaderNoMip( ASSET_GRADIENTBAR );
uiInfo.uiDC.Assets.fxBasePic = trap->R_RegisterShaderNoMip( ART_FX_BASE );
uiInfo.uiDC.Assets.fxPic[0] = trap->R_RegisterShaderNoMip( ART_FX_RED );
uiInfo.uiDC.Assets.fxPic[1] = trap->R_RegisterShaderNoMip( ART_FX_ORANGE );//trap->R_RegisterShaderNoMip( ART_FX_YELLOW );
uiInfo.uiDC.Assets.fxPic[2] = trap->R_RegisterShaderNoMip( ART_FX_YELLOW );//trap->R_RegisterShaderNoMip( ART_FX_GREEN );
uiInfo.uiDC.Assets.fxPic[3] = trap->R_RegisterShaderNoMip( ART_FX_GREEN );//trap->R_RegisterShaderNoMip( ART_FX_TEAL );
uiInfo.uiDC.Assets.fxPic[4] = trap->R_RegisterShaderNoMip( ART_FX_BLUE );
uiInfo.uiDC.Assets.fxPic[5] = trap->R_RegisterShaderNoMip( ART_FX_PURPLE );//trap->R_RegisterShaderNoMip( ART_FX_CYAN );
uiInfo.uiDC.Assets.fxPic[6] = trap->R_RegisterShaderNoMip( ART_FX_WHITE );
uiInfo.uiDC.Assets.scrollBar = trap->R_RegisterShaderNoMip( ASSET_SCROLLBAR );
uiInfo.uiDC.Assets.scrollBarArrowDown = trap->R_RegisterShaderNoMip( ASSET_SCROLLBAR_ARROWDOWN );
uiInfo.uiDC.Assets.scrollBarArrowUp = trap->R_RegisterShaderNoMip( ASSET_SCROLLBAR_ARROWUP );
uiInfo.uiDC.Assets.scrollBarArrowLeft = trap->R_RegisterShaderNoMip( ASSET_SCROLLBAR_ARROWLEFT );
uiInfo.uiDC.Assets.scrollBarArrowRight = trap->R_RegisterShaderNoMip( ASSET_SCROLLBAR_ARROWRIGHT );
uiInfo.uiDC.Assets.scrollBarThumb = trap->R_RegisterShaderNoMip( ASSET_SCROLL_THUMB );
uiInfo.uiDC.Assets.sliderBar = trap->R_RegisterShaderNoMip( ASSET_SLIDER_BAR );
uiInfo.uiDC.Assets.sliderThumb = trap->R_RegisterShaderNoMip( ASSET_SLIDER_THUMB );
// Icons for various server settings.
uiInfo.uiDC.Assets.needPass = trap->R_RegisterShaderNoMip( "gfx/menus/needpass" );
uiInfo.uiDC.Assets.noForce = trap->R_RegisterShaderNoMip( "gfx/menus/noforce" );
uiInfo.uiDC.Assets.forceRestrict = trap->R_RegisterShaderNoMip( "gfx/menus/forcerestrict" );
uiInfo.uiDC.Assets.saberOnly = trap->R_RegisterShaderNoMip( "gfx/menus/saberonly" );
uiInfo.uiDC.Assets.trueJedi = trap->R_RegisterShaderNoMip( "gfx/menus/truejedi" );
for( n = 0; n < NUM_CROSSHAIRS; n++ ) {
uiInfo.uiDC.Assets.crosshairShader[n] = trap->R_RegisterShaderNoMip( va("gfx/2d/crosshair%c", 'a' + n ) );
}
}
void _UI_DrawSides(float x, float y, float w, float h, float size) {
size *= uiInfo.uiDC.xscale;
trap->R_DrawStretchPic( x, y, size, h, 0, 0, 0, 0, uiInfo.uiDC.whiteShader );
trap->R_DrawStretchPic( x + w - size, y, size, h, 0, 0, 0, 0, uiInfo.uiDC.whiteShader );
}
void _UI_DrawTopBottom(float x, float y, float w, float h, float size) {
size *= uiInfo.uiDC.yscale;
trap->R_DrawStretchPic( x, y, w, size, 0, 0, 0, 0, uiInfo.uiDC.whiteShader );
trap->R_DrawStretchPic( x, y + h - size, w, size, 0, 0, 0, 0, uiInfo.uiDC.whiteShader );
}
/*
================
UI_DrawRect
Coordinates are 640*480 virtual values
=================
*/
void _UI_DrawRect( float x, float y, float width, float height, float size, const float *color ) {
trap->R_SetColor( color );
_UI_DrawTopBottom(x, y, width, height, size);
_UI_DrawSides(x, y, width, height, size);
trap->R_SetColor( NULL );
}
int MenuFontToHandle(int iMenuFont)
{
switch (iMenuFont)
{
case 1: return uiInfo.uiDC.Assets.qhSmallFont;
case 2: return uiInfo.uiDC.Assets.qhMediumFont;
case 3: return uiInfo.uiDC.Assets.qhBigFont;
case 4: return uiInfo.uiDC.Assets.qhSmall2Font;
}
return uiInfo.uiDC.Assets.qhMediumFont; // 0;
}
int Text_Width(const char *text, float scale, int iMenuFont)
{
int iFontIndex = MenuFontToHandle(iMenuFont);
return trap->R_Font_StrLenPixels(text, iFontIndex, scale);
}
int Text_Height(const char *text, float scale, int iMenuFont)
{
int iFontIndex = MenuFontToHandle(iMenuFont);
return trap->R_Font_HeightPixels(iFontIndex, scale);
}
void Text_Paint(float x, float y, float scale, vec4_t color, const char *text, float adjust, int limit, int style, int iMenuFont)
{
int iStyleOR = 0;
int iFontIndex = MenuFontToHandle(iMenuFont);
//
// kludge.. convert JK2 menu styles to SOF2 printstring ctrl codes...
//
switch (style)
{
case ITEM_TEXTSTYLE_NORMAL: iStyleOR = 0;break; // JK2 normal text
case ITEM_TEXTSTYLE_BLINK: iStyleOR = (int)STYLE_BLINK;break; // JK2 fast blinking
case ITEM_TEXTSTYLE_PULSE: iStyleOR = (int)STYLE_BLINK;break; // JK2 slow pulsing
case ITEM_TEXTSTYLE_SHADOWED: iStyleOR = (int)STYLE_DROPSHADOW;break; // JK2 drop shadow
case ITEM_TEXTSTYLE_OUTLINED: iStyleOR = (int)STYLE_DROPSHADOW;break; // JK2 drop shadow
case ITEM_TEXTSTYLE_OUTLINESHADOWED: iStyleOR = (int)STYLE_DROPSHADOW;break; // JK2 drop shadow
case ITEM_TEXTSTYLE_SHADOWEDMORE: iStyleOR = (int)STYLE_DROPSHADOW;break; // JK2 drop shadow
}
trap->R_Font_DrawString( x, // int ox
y, // int oy
text, // const char *text
color, // paletteRGBA_c c
iStyleOR | iFontIndex, // const int iFontHandle
!limit?-1:limit, // iCharLimit (-1 = none)
scale // const float scale = 1.0f
);
}
void Text_PaintWithCursor(float x, float y, float scale, vec4_t color, const char *text, int cursorPos, char cursor, int limit, int style, int iMenuFont)
{
Text_Paint(x, y, scale, color, text, 0, limit, style, iMenuFont);
// now print the cursor as well... (excuse the braces, it's for porting C++ to C)
//
{
char sTemp[1024];
int iCopyCount = limit > 0 ? Q_min( (int)strlen( text ), limit ) : (int)strlen( text );
iCopyCount = Q_min( iCopyCount, cursorPos );
iCopyCount = Q_min( iCopyCount, (int)sizeof( sTemp )-1 );
// copy text into temp buffer for pixel measure...
//
strncpy(sTemp,text,iCopyCount);
sTemp[iCopyCount] = '\0';
{
int iFontIndex = MenuFontToHandle( iMenuFont );
int iNextXpos = trap->R_Font_StrLenPixels(sTemp, iFontIndex, scale );
Text_Paint(x+iNextXpos, y, scale, color, va("%c",cursor), 0, limit, style|ITEM_TEXTSTYLE_BLINK, iMenuFont);
}
}
}
// maxX param is initially an X limit, but is also used as feedback. 0 = text was clipped to fit within, else maxX = next pos
//
static void Text_Paint_Limit(float *maxX, float x, float y, float scale, vec4_t color, const char* text, float adjust, int limit, int iMenuFont)
{
// this is kinda dirty, but...
//
int iFontIndex = MenuFontToHandle(iMenuFont);
//float fMax = *maxX;
int iPixelLen = trap->R_Font_StrLenPixels(text, iFontIndex, scale);
if (x + iPixelLen > *maxX)
{
// whole text won't fit, so we need to print just the amount that does...
// Ok, this is slow and tacky, but only called occasionally, and it works...
//
char sTemp[4096]={0}; // lazy assumption
const char *psText = text;
char *psOut = &sTemp[0];
char *psOutLastGood = psOut;
unsigned int uiLetter;
while (*psText && (x + trap->R_Font_StrLenPixels(sTemp, iFontIndex, scale)<=*maxX)
&& psOut < &sTemp[sizeof(sTemp)-1] // sanity
)
{
int iAdvanceCount;
psOutLastGood = psOut;
uiLetter = trap->R_AnyLanguage_ReadCharFromString(psText, &iAdvanceCount, NULL);
psText += iAdvanceCount;
if (uiLetter > 255)
{
*psOut++ = uiLetter>>8;
*psOut++ = uiLetter&0xFF;
}
else
{
*psOut++ = uiLetter&0xFF;
}
}
*psOutLastGood = '\0';
*maxX = 0; // feedback
Text_Paint(x, y, scale, color, sTemp, adjust, limit, ITEM_TEXTSTYLE_NORMAL, iMenuFont);
}
else
{
// whole text fits fine, so print it all...
//
*maxX = x + iPixelLen; // feedback the next position, as the caller expects
Text_Paint(x, y, scale, color, text, adjust, limit, ITEM_TEXTSTYLE_NORMAL, iMenuFont);
}
}
void UI_LoadNonIngame() {
const char *menuSet = UI_Cvar_VariableString("ui_menuFilesMP");
if (menuSet == NULL || menuSet[0] == '\0') {
menuSet = "ui/jampmenus.txt";
}
UI_LoadMenus(menuSet, qfalse);
uiInfo.inGameLoad = qfalse;
}
/*
===============
UI_BuildPlayerList
===============
*/
static void UI_BuildPlayerList() {
uiClientState_t cs;
int n, count, team, team2, playerTeamNumber;
char info[MAX_INFO_STRING];
trap->GetClientState( &cs );
trap->GetConfigString( CS_PLAYERS + cs.clientNum, info, MAX_INFO_STRING );
uiInfo.playerNumber = cs.clientNum;
uiInfo.teamLeader = atoi(Info_ValueForKey(info, "tl"));
team = atoi(Info_ValueForKey(info, "t"));
trap->GetConfigString( CS_SERVERINFO, info, sizeof(info) );
count = atoi( Info_ValueForKey( info, "sv_maxclients" ) );
uiInfo.playerCount = 0;
uiInfo.myTeamCount = 0;
playerTeamNumber = 0;
for( n = 0; n < count; n++ ) {
trap->GetConfigString( CS_PLAYERS + n, info, MAX_INFO_STRING );
if (info[0]) {
Q_strncpyz( uiInfo.playerNames[uiInfo.playerCount], Info_ValueForKey( info, "n" ), MAX_NETNAME );
Q_StripColor( uiInfo.playerNames[uiInfo.playerCount] );
uiInfo.playerIndexes[uiInfo.playerCount] = n;
uiInfo.playerCount++;
team2 = atoi(Info_ValueForKey(info, "t"));
if (team2 == team && n != uiInfo.playerNumber) {
Q_strncpyz( uiInfo.teamNames[uiInfo.myTeamCount], Info_ValueForKey( info, "n" ), MAX_NETNAME );
Q_StripColor( uiInfo.teamNames[uiInfo.myTeamCount] );
uiInfo.teamClientNums[uiInfo.myTeamCount] = n;
if (uiInfo.playerNumber == n) {
playerTeamNumber = uiInfo.myTeamCount;
}
uiInfo.myTeamCount++;
}
}
}
if (!uiInfo.teamLeader) {
trap->Cvar_Set("cg_selectedPlayer", va("%d", playerTeamNumber));
}
n = trap->Cvar_VariableValue("cg_selectedPlayer");
if (n < 0 || n > uiInfo.myTeamCount) {
n = 0;
}
if (n < uiInfo.myTeamCount) {
trap->Cvar_Set("cg_selectedPlayerName", uiInfo.teamNames[n]);
}
else
{
trap->Cvar_Set("cg_selectedPlayerName", "Everyone");
}
if (!team || team == TEAM_SPECTATOR || !uiInfo.teamLeader)
{
n = uiInfo.myTeamCount;
trap->Cvar_Set("cg_selectedPlayer", va("%d", n));
trap->Cvar_Set("cg_selectedPlayerName", "N/A");
}
}
void UI_SetActiveMenu( uiMenuCommand_t menu ) {
char buf[256];
// this should be the ONLY way the menu system is brought up
// enusure minumum menu data is cached
if (Menu_Count() > 0) {
vec3_t v;
v[0] = v[1] = v[2] = 0;
switch ( menu ) {
case UIMENU_NONE:
trap->Key_SetCatcher( trap->Key_GetCatcher() & ~KEYCATCH_UI );
trap->Key_ClearStates();
trap->Cvar_Set( "cl_paused", "0" );
Menus_CloseAll();
return;
case UIMENU_MAIN:
{
// trap->Cvar_Set( "sv_killserver", "1" );
trap->Key_SetCatcher( KEYCATCH_UI );
// trap->S_StartLocalSound( trap_S_RegisterSound("sound/misc/menu_background.wav", qfalse) , CHAN_LOCAL_SOUND );
// trap->S_StartBackgroundTrack("sound/misc/menu_background.wav", NULL);
if (uiInfo.inGameLoad)
UI_LoadNonIngame();
Menus_CloseAll();
Menus_ActivateByName("main");
trap->Cvar_VariableStringBuffer("com_errorMessage", buf, sizeof(buf));
if (buf[0])
{
if (!ui_singlePlayerActive.integer)
{
Menus_ActivateByName("error_popmenu");
}
else
{
trap->Cvar_Set("com_errorMessage", "");
}
}
return;
}
case UIMENU_TEAM:
trap->Key_SetCatcher( KEYCATCH_UI );
Menus_ActivateByName("team");
return;
case UIMENU_POSTGAME:
//trap->Cvar_Set( "sv_killserver", "1" );
trap->Key_SetCatcher( KEYCATCH_UI );
if (uiInfo.inGameLoad)
UI_LoadNonIngame();
Menus_CloseAll();
Menus_ActivateByName("endofgame");
return;
case UIMENU_INGAME:
trap->Cvar_Set( "cl_paused", "1" );
trap->Key_SetCatcher( KEYCATCH_UI );
UI_BuildPlayerList();
Menus_CloseAll();
Menus_ActivateByName("ingame");
return;
case UIMENU_PLAYERCONFIG:
// trap->Cvar_Set( "cl_paused", "1" );
trap->Key_SetCatcher( KEYCATCH_UI );
UI_BuildPlayerList();
Menus_CloseAll();
Menus_ActivateByName("ingame_player");
UpdateForceUsed();
return;
case UIMENU_PLAYERFORCE:
// trap->Cvar_Set( "cl_paused", "1" );
trap->Key_SetCatcher( KEYCATCH_UI );
UI_BuildPlayerList();
Menus_CloseAll();
Menus_ActivateByName("ingame_playerforce");
UpdateForceUsed();
return;
case UIMENU_SIEGEMESSAGE:
// trap->Cvar_Set( "cl_paused", "1" );
trap->Key_SetCatcher( KEYCATCH_UI );
Menus_CloseAll();
Menus_ActivateByName("siege_popmenu");
return;
case UIMENU_SIEGEOBJECTIVES:
// trap->Cvar_Set( "cl_paused", "1" );
trap->Key_SetCatcher( KEYCATCH_UI );
Menus_CloseAll();
Menus_ActivateByName("ingame_siegeobjectives");
return;
case UIMENU_VOICECHAT:
// trap->Cvar_Set( "cl_paused", "1" );
// No chatin non-siege games.
if (trap->Cvar_VariableValue( "g_gametype" ) < GT_TEAM)
{
return;
}
trap->Key_SetCatcher( KEYCATCH_UI );
Menus_CloseAll();