]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/gamemodes/gamemode/domination/cl_domination.qc
Move gametype registers into their own files, fallback now selects a supported gamety...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / gamemodes / gamemode / domination / cl_domination.qc
1 #include "cl_domination.qh"
2
3 #include <client/hud/panel/modicons.qh>
4
5 void HUD_Mod_Dom_Export(int fh)
6 {
7         HUD_Write_Cvar("hud_panel_modicons_dom_layout");
8 }
9
10 int autocvar_hud_panel_modicons_dom_layout;
11
12 void DrawDomItem(vector myPos, vector mySize, float aspect_ratio, int layout, int i)
13 {
14         TC(int, layout); TC(int, i);
15         float stat = -1;
16         string pic = "";
17         vector color = '0 0 0';
18         switch(i)
19         {
20                 case 0: stat = STAT(DOM_PPS_RED); pic = "dom_icon_red"; color = '1 0 0'; break;
21                 case 1: stat = STAT(DOM_PPS_BLUE); pic = "dom_icon_blue"; color = '0 0 1'; break;
22                 case 2: stat = STAT(DOM_PPS_YELLOW); pic = "dom_icon_yellow"; color = '1 1 0'; break;
23                 default:
24                 case 3: stat = STAT(DOM_PPS_PINK); pic = "dom_icon_pink"; color = '1 0 1'; break;
25         }
26         float pps_ratio = 0;
27         if(STAT(DOM_TOTAL_PPS))
28                 pps_ratio = stat / STAT(DOM_TOTAL_PPS);
29
30         if(mySize.x/mySize.y > aspect_ratio)
31         {
32                 i = aspect_ratio * mySize.y;
33                 myPos.x = myPos.x + (mySize.x - i) / 2;
34                 mySize.x = i;
35         }
36         else
37         {
38                 i = 1/aspect_ratio * mySize.x;
39                 myPos.y = myPos.y + (mySize.y - i) / 2;
40                 mySize.y = i;
41         }
42
43         if (layout) // show text too
44         {
45                 //draw the text
46                 color *= 0.5 + pps_ratio * (1 - 0.5); // half saturated color at min, full saturated at max
47                 if (layout == 2) // average pps
48                         drawstring_aspect(myPos + eX * mySize.y, ftos_decimals(stat, 2), vec2((2/3) * mySize.x, mySize.y), color, panel_fg_alpha, DRAWFLAG_NORMAL);
49                 else // percentage of average pps
50                         drawstring_aspect(myPos + eX * mySize.y, strcat( ftos(floor(pps_ratio*100 + 0.5)), "%" ), vec2((2/3) * mySize.x, mySize.y), color, panel_fg_alpha, DRAWFLAG_NORMAL);
51         }
52
53         //draw the icon
54         drawpic_aspect_skin(myPos, pic, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
55         if (stat > 0)
56         {
57                 drawsetcliparea(myPos.x, myPos.y + mySize.y * (1 - pps_ratio), mySize.y, mySize.y * pps_ratio);
58                 drawpic_aspect_skin(myPos, strcat(pic, "-highlighted"), '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
59                 drawresetcliparea();
60         }
61 }
62
63 void HUD_Mod_Dom(vector myPos, vector mySize)
64 {
65         mod_active = 1; // required in each mod function that always shows something
66
67         int layout = autocvar_hud_panel_modicons_dom_layout;
68         int rows, columns;
69         float aspect_ratio;
70         aspect_ratio = (layout) ? 3 : 1;
71         rows = HUD_GetRowCount(team_count, mySize, aspect_ratio);
72         columns = ceil(team_count/rows);
73
74         int i;
75         float row = 0, column = 0;
76         vector pos, itemSize;
77         itemSize = vec2(mySize.x / columns, mySize.y / rows);
78         for(i=0; i<team_count; ++i)
79         {
80                 pos = myPos + vec2(column * itemSize.x, row * itemSize.y);
81
82                 DrawDomItem(pos, itemSize, aspect_ratio, layout, i);
83
84                 ++row;
85                 if(row >= rows)
86                 {
87                         row = 0;
88                         ++column;
89                 }
90         }
91 }