/
hu_stuff.cpp
1655 lines (1384 loc) · 46.5 KB
/
hu_stuff.cpp
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
/**
* @file hu_stuff.cpp
* Miscellaneous routines for heads-up displays and UI.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2013 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 1993-1996 by id Software, Inc.
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>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., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/
#include "common.h"
#include "hu_stuff.h"
#include "hu_chat.h"
#include "hu_log.h"
#include "hu_menu.h"
#include "hu_msg.h"
#include "hu_inventory.h"
#include "g_common.h"
#include "gamesession.h"
#include "p_mapsetup.h"
#include "p_tick.h"
#include "am_map.h"
#include "fi_lib.h"
#include "r_common.h"
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <map>
/**
* @defgroup tableColumnFlags Table Column flags
*/
///@{
#define CF_HIDE 0x0001 ///< Column is presently hidden (will be collapsed).
#define CF_STRETCH_WIDTH 0x0002 ///< Column width is not fixed.
///@}
/**
* Defines a column in a table layout.
*/
typedef struct {
const char* label;
int type;
int flags; ///< @ref tableColumnFlags
int alignFlags; ///< @ref alignFlags
/// Auto-initialized:
float x;
float width;
} column_t;
/**
* Player "score" information, kills, suicides, etc...
*/
typedef struct {
int player, pClass, team;
int kills, suicides;
float color[3];
} scoreinfo_t;
/**
* Per-player scoreboard state.
*/
typedef struct {
int hideTics;
float alpha;
} scoreboardstate_t;
typedef struct fogeffectlayer_s {
float texOffset[2];
float texAngle;
float posAngle;
} fogeffectlayer_t;
typedef struct fogeffectdata_s {
DGLuint texture;
float alpha, targetAlpha;
fogeffectlayer_t layers[2];
float joinY;
dd_bool scrollDir;
} fogeffectdata_t;
fontid_t fonts[NUM_GAME_FONTS];
#if __JDOOM__ || __JDOOM64__
/// The end message strings.
const char* endmsg[NUM_QUITMESSAGES + 1];
#endif
dd_bool shiftdown = false;
const char shiftXForm[] = {
0,
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,
' ', '!', '"', '#', '$', '%', '&',
'"', // shift-'
'(', ')', '*', '+',
'<', // shift-,
'_', // shift--
'>', // shift-.
'?', // shift-/
')', // shift-0
'!', // shift-1
'@', // shift-2
'#', // shift-3
'$', // shift-4
'%', // shift-5
'^', // shift-6
'&', // shift-7
'*', // shift-8
'(', // shift-9
':',
':', // shift-;
'<',
'+', // shift-=
'>', '?', '@',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'[', // shift-[
'!', // shift-backslash
']', // shift-]
'"', '_',
'\'', // shift-`
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'{', '|', '}', '~', 127
};
// Misc UI patches:
patchid_t borderPatches[8];
#if __JDOOM__ || __JDOOM64__
patchid_t *pMapNames; // Name graphics for each map.
uint pMapNamesSize;
#endif
#if __JHERETIC__ || __JHEXEN__
patchid_t pInvItemBox;
patchid_t pInvSelectBox;
patchid_t pInvPageLeft[2];
patchid_t pInvPageRight[2];
#endif
static patchid_t m_pause; // Paused graphic.
// Menu and message background fog effect state.
static fogeffectdata_t fogEffectData;
// Scoreboard states for each player.
static scoreboardstate_t scoreStates[MAXPLAYERS];
// Patch => Text Replacement LUT.
typedef std::map<patchid_t, int> PatchReplacementValues;
PatchReplacementValues patchReplacements;
static int patchReplacementValueIndex(patchid_t patchId, bool canCreate = true)
{
// Have we previously encountered this?
PatchReplacementValues::const_iterator found = patchReplacements.find(patchId);
if(found != patchReplacements.end()) return found->second;
// No. Look it up.
int valueIndex = -1;
AutoStr* patchPath = R_ComposePatchPath(patchId);
if(!Str_IsEmpty(patchPath))
{
AutoStr* valueStr = Str_Appendf(AutoStr_New(), "Patch Replacement|%s", Str_Text(patchPath));
valueIndex = Def_Get(DD_DEF_VALUE, Str_Text(valueStr), 0);
}
if(canCreate)
{
patchReplacements.insert(std::pair<patchid_t, int>(patchId, valueIndex));
}
return valueIndex;
}
/**
* Intialize the background fog effect.
*/
static void initFogEffect()
{
fogeffectdata_t *fog = &fogEffectData;
fog->texture = 0;
fog->alpha = fog->targetAlpha = 0;
fog->joinY = 0.5f;
fog->scrollDir = true;
fog->layers[0].texOffset[VX] = fog->layers[0].texOffset[VY] = 0;
fog->layers[0].texAngle = 93;
fog->layers[0].posAngle = 35;
fog->layers[1].texOffset[VX] = fog->layers[1].texOffset[VY] = 0;
fog->layers[1].texAngle = 12;
fog->layers[1].posAngle = 77;
}
static void prepareFogTexture()
{
if(Get(DD_NOVIDEO) || Get(DD_DEDICATED)) return;
// Already prepared?
if(fogEffectData.texture) return;
if(CentralLumpIndex().contains("menufog.lmp"))
{
de::File1 &lump = CentralLumpIndex()[CentralLumpIndex().findLast("menufog.lmp")];
uint8_t const *pixels = lump.cache();
/// @todo fixme: Do not assume dimensions.
fogEffectData.texture = DGL_NewTextureWithParams(DGL_LUMINANCE, 64, 64,
pixels, 0, DGL_NEAREST, DGL_LINEAR, -1 /*best anisotropy*/, DGL_REPEAT, DGL_REPEAT);
lump.unlock();
}
}
static void releaseFogTexture()
{
if(Get(DD_NOVIDEO) || Get(DD_DEDICATED)) return;
// Not prepared?
if(!fogEffectData.texture) return;
DGL_DeleteTextures(1, (DGLuint *) &fogEffectData.texture);
fogEffectData.texture = 0;
}
static void declareGraphicPatches()
{
// View border patches:
for(uint i = 1; i < 9; ++i)
{
borderPatches[i-1] = R_DeclarePatch(borderGraphics[i]);
}
#if __JDOOM__ || __JDOOM64__
m_pause = R_DeclarePatch("M_PAUSE");
#elif __JHERETIC__ || __JHEXEN__
m_pause = R_DeclarePatch("PAUSED");
#endif
// Map name patches:
#if __JDOOM__ || __JDOOM64__
# if !__JDOOM64__
if(gameModeBits & GM_ANY_DOOM2)
# endif
{
pMapNamesSize = 32;
pMapNames = (patchid_t *) Z_Malloc(sizeof(patchid_t) * pMapNamesSize, PU_GAMESTATIC, 0);
Str name; Str_InitStd(&name);
for(uint i = 0; i < pMapNamesSize; ++i)
{
# if __JDOOM64__
Str_Appendf(Str_Clear(&name), "WILV%2.2u", i);
# else // __JDOOM__
Str_Appendf(Str_Clear(&name), "CWILV%2.2u", i);
# endif
pMapNames[i] = R_DeclarePatch(Str_Text(&name));
}
Str_Free(&name);
}
# if !__JDOOM64__
else
{
const uint numEpisodes = (gameMode == doom_shareware? 1 : gameMode == doom_ultimate? 4 : 3);
Str name; Str_InitStd(&name);
// Don't waste space - patches are loaded back to back
// ie no space in the array is left for E1M10
pMapNamesSize = 9 * 4;
pMapNames = (patchid_t *) Z_Malloc(sizeof(patchid_t) * pMapNamesSize, PU_GAMESTATIC, 0);
for(uint i = 0; i < numEpisodes; ++i)
{
for(uint k = 0; k < 9; ++k) // Number of maps per episode.
{
Str_Appendf(Str_Clear(&name), "WILV%2.2u", (i * 10) + k);
pMapNames[(i * 9) + k] = R_DeclarePatch(Str_Text(&name));
}
}
Str_Free(&name);
}
# endif
#endif
#if __JHERETIC__ || __JHEXEN__
pInvItemBox = R_DeclarePatch("ARTIBOX");
pInvSelectBox = R_DeclarePatch("SELECTBO");
pInvPageLeft[0] = R_DeclarePatch("INVGEML1");
pInvPageLeft[1] = R_DeclarePatch("INVGEML2");
pInvPageRight[0] = R_DeclarePatch("INVGEMR1");
pInvPageRight[1] = R_DeclarePatch("INVGEMR2");
#endif
}
/**
* Loads the font patches and inits various strings
* JHEXEN Note: Don't bother with the yellow font, we'll colour the white version
*/
void Hu_LoadData()
{
// Clear the patch replacement value map (definitions have been re-read).
patchReplacements.clear();
initFogEffect();
prepareFogTexture();
declareGraphicPatches();
#if __JDOOM__ || __JHERETIC__ || __JDOOM64__
R_GetGammaMessageStrings();
#endif
#if __JDOOM__ || __JDOOM64__
// Quit messages:
endmsg[0] = GET_TXT(TXT_QUITMSG);
for(uint i = 1; i <= NUM_QUITMESSAGES; ++i)
{
endmsg[i] = GET_TXT(TXT_QUITMESSAGE1 + i - 1);
}
#endif
}
void Hu_UnloadData()
{
#if __JDOOM__ || __JDOOM64__
Z_Free(pMapNames); pMapNames = 0;
#endif
releaseFogTexture();
}
void HU_WakeWidgets(int player)
{
if(player < 0)
{
// Wake the widgets of all players.
for(uint i = 0; i < MAXPLAYERS; ++i)
{
if(!players[i].plr->inGame) continue;
HU_WakeWidgets(i);
}
return;
}
if(player < MAXPLAYERS)
{
if(!players[player].plr->inGame) return;
ST_Start(player);
}
}
#if __JHERETIC__ || __JHEXEN__
static void drawQuad(float x, float y, float w, float h, float s, float t,
float r, float g, float b, float a)
{
DGL_Color4f(r, g, b, a);
DGL_Begin(DGL_QUADS);
DGL_TexCoord2f(0, 0 * s, 0);
DGL_Vertex2f(x, y);
DGL_TexCoord2f(0, 1 * s, 0);
DGL_Vertex2f(x + w, y);
DGL_TexCoord2f(0, 1 * s, t);
DGL_Vertex2f(x + w, y + h);
DGL_TexCoord2f(0, 0 * s, t);
DGL_Vertex2f(x, y + h);
DGL_End();
}
#endif
void HU_DrawText(const char* str, float x, float y, float scale,
float r, float g, float b, float a, int alignFlags, short textFlags)
{
if(!str || !str[0]) return;
const bool applyScale = !FEQUAL(scale, 1.0f);
if(applyScale)
{
DGL_MatrixMode(DGL_MODELVIEW);
DGL_PushMatrix();
DGL_Translatef(x, y, 0);
DGL_Scalef(scale, scale, 1);
DGL_Translatef(-x, -y, 0);
}
FR_SetColorAndAlpha(r, g, b, a);
FR_DrawTextXY3(str, x, y, alignFlags, textFlags);
if(applyScale)
{
DGL_MatrixMode(DGL_MODELVIEW);
DGL_PopMatrix();
}
}
/// Predicate for sorting score infos.
int scoreInfoCompare(void const *a_, void const *b_)
{
scoreinfo_t const *a = (scoreinfo_t *) a_;
scoreinfo_t const *b = (scoreinfo_t *) b_;
if(a->kills > b->kills) return -1;
if(b->kills > a->kills) return 1;
if(COMMON_GAMESESSION->rules().deathmatch)
{
// In deathmatch, suicides affect your place on the scoreboard.
if(a->suicides < b->suicides) return -1;
if(b->suicides < a->suicides) return 1;
}
return 0;
}
static void sortScoreInfo(scoreinfo_t* vec, size_t size)
{
qsort(vec, size, sizeof(scoreinfo_t), scoreInfoCompare);
}
static int populateScoreInfo(scoreinfo_t* scoreBoard, int maxPlayers, int player)
{
DENG_UNUSED(player);
#if __JHEXEN__
static const int plrColors[] = {
AM_PLR1_COLOR,
AM_PLR2_COLOR,
AM_PLR3_COLOR,
AM_PLR4_COLOR,
AM_PLR5_COLOR,
AM_PLR6_COLOR,
AM_PLR7_COLOR,
AM_PLR8_COLOR
};
#else
static const float green[3] = { 0.f, .8f, 0.f };
static const float gray[3] = { .45f, .45f, .45f };
static const float brown[3] = { .7f, .5f, .4f };
static const float red[3] = { 1.f, 0.f, 0.f };
#endif
int n = 0, inCount;
memset(scoreBoard, 0, sizeof(*scoreBoard) * maxPlayers);
inCount = 0;
for(int i = 0; i < maxPlayers; ++i)
{
player_t* plr = &players[i];
scoreinfo_t* info;
if(!plr->plr->inGame) continue;
inCount++;
info = &scoreBoard[n++];
info->player = i;
#if __JHERETIC__
info->pClass = (plr->morphTics > 0? PCLASS_CHICKEN : PCLASS_PLAYER);
#elif __JHEXEN__
if(plr->morphTics > 0)
info->pClass = PCLASS_PIG;
else
info->pClass = plr->class_;
#else
info->pClass = PCLASS_PLAYER;
#endif
info->team = cfg.playerColor[i];
// Pick team color:
#if __JHEXEN__
R_GetColorPaletteRGBf(0, plrColors[info->team], info->color, false);
#else
switch(info->team)
{
case 0: memcpy(info->color, green, sizeof(float)*3); break;
case 1: memcpy(info->color, gray, sizeof(float)*3); break;
case 2: memcpy(info->color, brown, sizeof(float)*3); break;
case 3: memcpy(info->color, red, sizeof(float)*3); break;
}
#endif
if(COMMON_GAMESESSION->rules().deathmatch)
{
for(int j = 0; j < maxPlayers; ++j)
{
if(j != i)
{
info->kills += plr->frags[j];
}
else
{
#if __JHEXEN__
info->suicides += -plr->frags[j];
#else
info->suicides += plr->frags[j];
#endif
}
}
}
else
{
info->kills = plr->killCount;
info->suicides = 0; // We don't care anyway.
}
}
sortScoreInfo(scoreBoard, n);
return inCount;
}
void HU_ScoreBoardUnHide(int player)
{
if(player < 0 || player >= MAXPLAYERS) return;
player_t* plr = &players[player];
if(!plr->plr->inGame) return;
scoreboardstate_t* ss = &scoreStates[player];
ss->alpha = 1;
ss->hideTics = 35;
}
static int countTableColumns(const column_t* columns)
{
int count = 0;
while(columns[count].label){ count++; }
return count;
}
static void applyTableLayout(column_t* columns, int numCols, float x, float width,
int cellPadding = 0)
{
DENG_ASSERT(columns);
column_t* col;
col = columns;
int numStretchCols = 0;
for(int n = 0; n < numCols; ++n, col++)
{
col->x = 0;
col->width = 0;
// Count the total number of non-fixed width ("stretched") columns.
if(!(col->flags & CF_HIDE) && (col->flags & CF_STRETCH_WIDTH))
numStretchCols++;
}
col = columns;
int fixedWidth = 0;
for(int n = 0; n < numCols; ++n, col++)
{
col->width = 0;
if(col->flags & CF_HIDE) continue; // Collapse.
if(!(col->flags & CF_STRETCH_WIDTH))
{
col->width = FR_TextWidth(col->label) + cellPadding * 2;
fixedWidth += col->width;
}
}
col = columns;
for(int n = 0; n < numCols; ++n, col++)
{
if(col->flags & CF_HIDE) continue; // Collapse.
if(col->flags & CF_STRETCH_WIDTH)
{
col->width = (width - fixedWidth) / numStretchCols;
}
}
col = columns;
for(int n = 0; n < numCols; ++n, col++)
{
col->x = x;
if(!(col->flags & CF_HIDE)) // Collapse.
{
x += col->width;
}
}
}
static void drawTable(float x, float ly, float width, float height,
column_t* columns, scoreinfo_t* scoreBoard, int inCount, float alpha,
int player)
{
#define CELL_PADDING 1
if(!columns) return;
if(!(alpha > 0)) return;
int numCols = countTableColumns(columns);
if(!numCols) return;
const int lineHeight = .5f + height / (MAXPLAYERS + 1);
const int fontHeight = FR_CharHeight('A');
float fontScale = float(lineHeight) / (fontHeight + CELL_PADDING * 2);
#ifdef __JHEXEN__
// Quick fix for Hexen's oversized scoreboard fonts.
// Something is broken here, though: the above should calculate a
// suitable font size for all games? -jk
fontScale *= .55f;
#endif
applyTableLayout(columns, numCols, x, width, CELL_PADDING);
/// @todo fixme: all layout/placement should be done in applyTableLayout()
// Draw the table header:
DGL_Enable(DGL_TEXTURE_2D);
const column_t* col = columns;
for(int n = 0; n < numCols; ++n, col++)
{
if(col->flags & CF_HIDE) continue;
int cX = col->x;
if(col->alignFlags & ALIGN_RIGHT) cX += col->width - CELL_PADDING;
else cX += CELL_PADDING;
int cY = ly + lineHeight - CELL_PADDING;
int alignFlags = (col->alignFlags & ~ALIGN_TOP) | ALIGN_BOTTOM;
HU_DrawText(col->label, cX, cY, fontScale, 1.f, 1.f, 1.f, alpha, alignFlags, DTF_ONLY_SHADOW);
}
ly += lineHeight;
DGL_Disable(DGL_TEXTURE_2D);
// Draw the table from left to right, top to bottom:
for(int i = 0; i < inCount; ++i, ly += lineHeight)
{
scoreinfo_t* info = &scoreBoard[i];
const char* name = Net_GetPlayerName(info->player);
char buf[5];
if(info->player == player)
{
// Draw a background to make *me* stand out.
float val = (info->color[0] + info->color[1] + info->color[2]) / 3;
if(val < .5f) val = .2f;
else val = .8f;
DGL_DrawRectf2Color(x, ly, width, lineHeight, val + .2f, val + .2f, val, .5f * alpha);
}
// Now draw the fields:
DGL_Enable(DGL_TEXTURE_2D);
const column_t* col = columns;
for(int n = 0; n < numCols; ++n, col++)
{
if(col->flags & CF_HIDE) continue;
int cX = col->x;
if(col->alignFlags & ALIGN_RIGHT) cX += col->width - CELL_PADDING;
else cX += CELL_PADDING;
int cY = ly + CELL_PADDING;
switch(col->type)
{
case 0: // Class icon.
{
#if __JHERETIC__ || __JHEXEN__
int spr = 0;
# if __JHERETIC__
if(info->pClass == PCLASS_CHICKEN)
spr = SPR_CHKN;
# else
switch(info->pClass)
{
case PCLASS_FIGHTER: spr = SPR_PLAY; break;
case PCLASS_CLERIC: spr = SPR_CLER; break;
case PCLASS_MAGE: spr = SPR_MAGE; break;
case PCLASS_PIG: spr = SPR_PIGY; break;
}
# endif
if(spr)
{
spriteinfo_t sprInfo;
int w, h;
float scale;
R_GetSpriteInfo(spr, 0, &sprInfo);
w = sprInfo.geometry.size.width;
h = sprInfo.geometry.size.height;
if(h > w) scale = float(lineHeight - CELL_PADDING * 2) / h;
else scale = float(col->width - CELL_PADDING * 2) / w;
w *= scale;
h *= scale;
// Align to center on both X+Y axes.
cX += ((col->width - CELL_PADDING * 2) - w) / 2.0f;
cY += ((lineHeight - CELL_PADDING * 2) - h) / 2.0f;
DGL_SetMaterialUI(sprInfo.material, DGL_CLAMP_TO_EDGE, DGL_CLAMP_TO_EDGE);
drawQuad(cX, cY, w, h, sprInfo.texCoord[0], sprInfo.texCoord[1], 1, 1, 1, alpha);
}
#endif
break;
}
case 1: // Name.
HU_DrawText(name, cX, cY, fontScale,
info->color[0], info->color[1], info->color[2],
alpha, col->alignFlags, DTF_ONLY_SHADOW);
break;
case 2: // #Suicides.
sprintf(buf, "%4i", info->suicides);
HU_DrawText(buf, cX, cY, fontScale,
info->color[0], info->color[1], info->color[2],
alpha, col->alignFlags, DTF_ONLY_SHADOW);
break;
case 3: // #Kills.
sprintf(buf, "%4i", info->kills);
HU_DrawText(buf, cX, cY, fontScale,
info->color[0], info->color[1], info->color[2],
alpha, col->alignFlags, DTF_ONLY_SHADOW);
break;
}
}
DGL_Disable(DGL_TEXTURE_2D);
}
#undef CELL_PADDING
}
static void drawMapMetaData(float x, float y, float alpha)
{
#define BORDER 2
de::String title = G_MapTitle(); // current map
if(title.isEmpty()) title = "Unnamed";
char buf[256];
dd_snprintf(buf, 256, "%s - %s", COMMON_GAMESESSION->rules().description().toLatin1().constData(),
title.toLatin1().constData());
FR_SetColorAndAlpha(1, 1, 1, alpha);
FR_DrawTextXY2(buf, x + BORDER, y - BORDER, ALIGN_BOTTOMLEFT);
#undef BORDER
}
/**
* Draws a sorted frags list in the lower right corner of the screen.
*/
void HU_DrawScoreBoard(int player)
{
#define LINE_BORDER 4
static column_t columns[] = {
{ "cl", 0, 0, 0, 0, 0 },
{ "name", 1, CF_STRETCH_WIDTH, ALIGN_TOPLEFT, 0, 0 },
{ "suicides", 2, 0, ALIGN_TOPRIGHT, 0, 0 },
{ "frags", 3, 0, ALIGN_TOPRIGHT, 0, 0 },
{ NULL, 0, 0, 0, 0, 0 }
};
static bool tableInitialized = false;
if(!IS_NETGAME) return;
if(player < 0 || player >= MAXPLAYERS) return;
scoreboardstate_t* ss = &scoreStates[player];
if(!(ss->alpha > 0)) return;
// Are we yet to initialize the table for this game mode?
if(!tableInitialized)
{
// Only display the player class column if more than one class is defined.
if(NUM_PLAYER_CLASSES == 1)
columns[0].flags |= CF_HIDE;
tableInitialized = true;
}
// Set up the fixed 320x200 projection.
DGL_MatrixMode(DGL_PROJECTION);
DGL_PushMatrix();
DGL_LoadIdentity();
DGL_Ortho(0, 0, SCREENWIDTH, SCREENHEIGHT, -1, 1);
// Populate and sort the scoreboard according to game rules, type, etc.
scoreinfo_t scoreBoard[MAXPLAYERS];
int inCount = populateScoreInfo(scoreBoard, MAXPLAYERS, player);
// Determine the dimensions of the scoreboard:
RectRaw geom = RectRaw(0, 0, SCREENWIDTH - 32, SCREENHEIGHT - 32);
DGL_MatrixMode(DGL_MODELVIEW);
DGL_PushMatrix();
DGL_Translatef(16, 16, 0);
// Draw a background around the whole thing.
DGL_DrawRectf2Color(geom.origin.x, geom.origin.y, geom.size.width, geom.size.height,
0, 0, 0, .4f * ss->alpha);
DGL_Enable(DGL_TEXTURE_2D);
FR_SetFont(FID(GF_FONTB));
FR_LoadDefaultAttrib();
FR_SetLeading(0);
FR_SetColorAndAlpha(1, 0, 0, ss->alpha);
FR_DrawTextXY3("ranking", geom.origin.x + geom.size.width / 2, geom.origin.y + LINE_BORDER, ALIGN_TOP, DTF_ONLY_SHADOW);
FR_SetFont(FID(GF_FONTA));
drawMapMetaData(geom.origin.x, geom.origin.y + geom.size.height, ss->alpha);
drawTable(geom.origin.x, geom.origin.y + 20, geom.size.width, geom.size.height - 20,
columns, scoreBoard, inCount, ss->alpha, player);
DGL_Disable(DGL_TEXTURE_2D);
// Restore earlier matrices.
DGL_MatrixMode(DGL_PROJECTION);
DGL_PopMatrix();
DGL_MatrixMode(DGL_MODELVIEW);
DGL_PopMatrix();
}
void Hu_Ticker(void)
{
int i;
for(i = 0; i < MAXPLAYERS; ++i)
{
scoreboardstate_t* ss = &scoreStates[i];
player_t* plr = &players[i];
if(!plr->plr->inGame) continue;
if(ss->hideTics > 0)
{
--ss->hideTics;
}
else
{
if(ss->alpha > 0)
ss->alpha -= .05f;
}
}
}
/**
* Updates on Game Tick.
*/
void Hu_FogEffectTicker(timespan_t ticLength)
{
#define fog (&fogEffectData)
#define FOGALPHA_FADE_STEP (.07f)
static const float MENUFOGSPEED[2] = {.03f, -.085f};
int i;
if(cfg.hudFog == 0)
return;
// Move towards the target alpha
if(fog->alpha != fog->targetAlpha)
{
float diff = fog->targetAlpha - fog->alpha;
if(fabs(diff) > FOGALPHA_FADE_STEP)
{
fog->alpha += FOGALPHA_FADE_STEP * ticLength * TICRATE * (diff > 0? 1 : -1);
}
else
{
fog->alpha = fog->targetAlpha;
}
}
if(!(fog->alpha > 0))
return;
for(i = 0; i < 2; ++i)
{
if(cfg.hudFog == 2)
{
fog->layers[i].texAngle += ((MENUFOGSPEED[i]/4) * ticLength * TICRATE);
fog->layers[i].posAngle -= (MENUFOGSPEED[!i] * ticLength * TICRATE);
fog->layers[i].texOffset[VX] = 160 + 120 * cos(fog->layers[i].posAngle / 180 * DD_PI);
fog->layers[i].texOffset[VY] = 100 + 100 * sin(fog->layers[i].posAngle / 180 * DD_PI);
}
else
{
fog->layers[i].texAngle += ((MENUFOGSPEED[i]/4) * ticLength * TICRATE);
fog->layers[i].posAngle -= ((MENUFOGSPEED[!i]*1.5f) * ticLength * TICRATE);
fog->layers[i].texOffset[VX] = 320 + 320 * cos(fog->layers[i].posAngle / 180 * DD_PI);
fog->layers[i].texOffset[VY] = 240 + 240 * sin(fog->layers[i].posAngle / 180 * DD_PI);
}
}
// Calculate the height of the menuFog 3 Y join
if(cfg.hudFog == 4)
{
if(fog->scrollDir && fog->joinY > 0.46f)
fog->joinY = fog->joinY / 1.002f;
else if(!fog->scrollDir && fog->joinY < 0.54f )
fog->joinY = fog->joinY * 1.002f;
if((fog->joinY < 0.46f || fog->joinY > 0.54f))
fog->scrollDir = !fog->scrollDir;
}
#undef fog
#undef FOGALPHA_FADE_STEP
}
void M_DrawGlowBar(const float a[2], const float b[2], float thickness,
dd_bool left, dd_bool right, dd_bool caps, float red, float green,
float blue, float alpha)
{
float length, delta[2], normal[2], unit[2];
DGLuint tex;
if(!left && !right && !caps)
return;
if(!(alpha > 0))
return;
delta[0] = b[0] - a[0];
delta[1] = b[1] - a[1];
length = sqrt(delta[0] * delta[0] + delta[1] * delta[1]);
if(length <= 0)
return;
unit[0] = delta[0] / length;
unit[1] = delta[1] / length;
normal[0] = unit[1];
normal[1] = -unit[0];
tex = Get(DD_DYNLIGHT_TEXTURE);
if(caps)
{ // Draw a "cap" at the start of the line.
float v1[2], v2[2], v3[2], v4[2];
v1[0] = a[0] - unit[0] * thickness + normal[0] * thickness;
v1[1] = a[1] - unit[1] * thickness + normal[1] * thickness;
v2[0] = a[0] + normal[0] * thickness;
v2[1] = a[1] + normal[1] * thickness;
v3[0] = a[0] - normal[0] * thickness;
v3[1] = a[1] - normal[1] * thickness;
v4[0] = a[0] - unit[0] * thickness - normal[0] * thickness;
v4[1] = a[1] - unit[1] * thickness - normal[1] * thickness;
DGL_Bind(tex);
DGL_Color4f(red, green, blue, alpha);
DGL_Begin(DGL_QUADS);
DGL_TexCoord2f(0, 0, 0);
DGL_Vertex2f(v1[0], v1[1]);
DGL_TexCoord2f(0, .5f, 0);
DGL_Vertex2f(v2[0], v2[1]);
DGL_TexCoord2f(0, .5f, 1);
DGL_Vertex2f(v3[0], v3[1]);
DGL_TexCoord2f(0, 0, 1);
DGL_Vertex2f(v4[0], v4[1]);
DGL_End();
}
// The middle part of the line.
if(left && right)
{
float v1[2], v2[2], v3[2], v4[2];
v1[0] = a[0] + normal[0] * thickness;
v1[1] = a[1] + normal[1] * thickness;
v2[0] = b[0] + normal[0] * thickness;
v2[1] = b[1] + normal[1] * thickness;
v3[0] = b[0] - normal[0] * thickness;
v3[1] = b[1] - normal[1] * thickness;
v4[0] = a[0] - normal[0] * thickness;
v4[1] = a[1] - normal[1] * thickness;