Xonotic
cl_domination.qc
Go to the documentation of this file.
1 #include "cl_domination.qh"
2 
3 #include <client/draw.qh>
5 
6 void HUD_Mod_Dom_Export(int fh)
7 {
8  HUD_Write_Cvar("hud_panel_modicons_dom_layout");
9 }
10 
12 
13 void DrawDomItem(vector myPos, vector mySize, float aspect_ratio, int layout, int i)
14 {
15  TC(int, layout); TC(int, i);
16  float stat = -1;
17  string pic = "";
18  vector color = '0 0 0';
19  switch(i)
20  {
21  case 0: stat = STAT(DOM_PPS_RED); pic = "dom_icon_red"; color = '1 0 0'; break;
22  case 1: stat = STAT(DOM_PPS_BLUE); pic = "dom_icon_blue"; color = '0 0 1'; break;
23  case 2: stat = STAT(DOM_PPS_YELLOW); pic = "dom_icon_yellow"; color = '1 1 0'; break;
24  default:
25  case 3: stat = STAT(DOM_PPS_PINK); pic = "dom_icon_pink"; color = '1 0 1'; break;
26  }
27  float pps_ratio = 0;
28  if(STAT(DOM_TOTAL_PPS))
29  pps_ratio = stat / STAT(DOM_TOTAL_PPS);
30 
31  if(mySize.x/mySize.y > aspect_ratio)
32  {
33  i = aspect_ratio * mySize.y;
34  myPos.x = myPos.x + (mySize.x - i) / 2;
35  mySize.x = i;
36  }
37  else
38  {
39  i = 1/aspect_ratio * mySize.x;
40  myPos.y = myPos.y + (mySize.y - i) / 2;
41  mySize.y = i;
42  }
43 
44  if (layout) // show text too
45  {
46  //draw the text
47  color *= 0.5 + pps_ratio * (1 - 0.5); // half saturated color at min, full saturated at max
48  if (layout == 2) // average pps
49  drawstring_aspect(myPos + eX * mySize.y, ftos_decimals(stat, 2), vec2((2/3) * mySize.x, mySize.y), color, panel_fg_alpha, DRAWFLAG_NORMAL);
50  else // percentage of average pps
51  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);
52  }
53 
54  //draw the icon
55  drawpic_aspect_skin(myPos, pic, '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
56  if (stat > 0)
57  {
58  drawsetcliparea(myPos.x, myPos.y + mySize.y * (1 - pps_ratio), mySize.y, mySize.y * pps_ratio);
59  drawpic_aspect_skin(myPos, strcat(pic, "-highlighted"), '1 1 0' * mySize.y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
61  }
62 }
63 
64 void HUD_Mod_Dom(vector myPos, vector mySize)
65 {
66  mod_active = 1; // required in each mod function that always shows something
67 
69  int rows, columns;
70  float aspect_ratio;
71  aspect_ratio = (layout) ? 3 : 1;
72  rows = HUD_GetRowCount(team_count, mySize, aspect_ratio);
73  columns = ceil(team_count/rows);
74 
75  int i;
76  float row = 0, column = 0;
77  vector pos, itemSize;
78  itemSize = vec2(mySize.x / columns, mySize.y / rows);
79  for(i=0; i<team_count; ++i)
80  {
81  pos = myPos + vec2(column * itemSize.x, row * itemSize.y);
82 
83  DrawDomItem(pos, itemSize, aspect_ratio, layout, i);
84 
85  ++row;
86  if(row >= rows)
87  {
88  row = 0;
89  ++column;
90  }
91  }
92 }
vector color
float panel_fg_alpha
Definition: hud.qh:166
ERASEABLE string ftos_decimals(float number, int decimals)
converts a number to a string with the indicated number of decimals
Definition: string.qh:450
void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag)
Definition: draw.qc:102
float HUD_GetRowCount(int item_count, vector size, float item_aspect)
Definition: hud.qc:165
bool mod_active
Definition: modicons.qh:7
void HUD_Mod_Dom(vector myPos, vector mySize)
void HUD_Mod_Dom_Export(int fh)
Definition: cl_domination.qc:6
#define drawpic_aspect_skin(pos, pic, sz, color, theAlpha, drawflag)
Definition: draw.qh:78
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
int autocvar_hud_panel_modicons_dom_layout
const float DRAWFLAG_NORMAL
Definition: csprogsdefs.qc:317
#define TC(T, sym)
Definition: _all.inc:82
vector(float skel, float bonenum) _skel_get_boneabs_hidden
const vector eX
Definition: vector.qh:44
float team_count
Definition: main.qh:45
#define vec2(...)
Definition: vector.qh:90
void DrawDomItem(vector myPos, vector mySize, float aspect_ratio, int layout, int i)
#define HUD_Write_Cvar(cvar)
Definition: hud_config.qh:38