Xonotic
vote.qc File Reference
#include "vote.qh"
#include <client/draw.qh>
+ Include dependency graph for vote.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void HUD_Vote ()
 
void HUD_Vote_Export (int fh)
 

Function Documentation

◆ HUD_Vote()

void HUD_Vote ( )

Definition at line 13 of file vote.qc.

References autocvar__hud_configure, autocvar__menu_alpha, autocvar_cl_allow_uid2name, localcmd, LOG_INFO, MUTATOR_CALLHOOK, SERVERFLAG_PLAYERSTATS, serverflags, uid2name_dialog, vote_active, vote_nocount, and vote_yescount.

14 {
16  {
17  // this dialog gets overriden by the uid2name menu dialog, if it exists
18  // TODO remove this client side uid2name dialog in the next release
20  uid2name_dialog = 0;
21 
22  if (!uid2name_dialog)
23  localcmd("menu_cmd directmenu Uid2Name\n");
24 
25  vote_active = 1;
27  {
28  vote_yescount = 0;
29  vote_nocount = 0;
30  LOG_INFO(_("^1You must answer before entering hud configure mode"));
31  cvar_set("_hud_configure", "0");
32  }
33  strcpy(vote_called_vote, _("^2Name ^7instead of \"^1Anonymous player^7\" in stats"));
34  uid2name_dialog = 1;
35  }
36 
38  {
39  if(!autocvar_hud_panel_vote) return;
40  /*
41  if(cvar("hud_panel_vote_test")) {
42  if(vote_called_vote) strunzone(vote_called_vote); vote_called_vote = strzone("^1test the vote panel");
43  vote_active = true; vote_yescount = 3; vote_nocount = 2; vote_needed = 4;
44  } else vote_active = false;
45  */
46  }
47  else
48  {
49  vote_yescount = 3;
50  vote_nocount = 2;
51  vote_needed = 4;
52  }
53 
54  string s;
55  float a;
56  if(vote_active != vote_prev) {
57  vote_change = time;
59  }
60 
62  vote_alpha = bound(0, (time - vote_change) * 2, 1);
63  else
64  vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
65 
67  if(a <= 0)
68  return;
69  //panel_fade_alpha *= a;
70  // nothing can hide this panel, not even the menu
71  float hud_fade_alpha_save = hud_fade_alpha;
73  hud_fade_alpha = 0;
74  else
75  hud_fade_alpha = a;
77  hud_fade_alpha = hud_fade_alpha_save;
78 
79  if(uid2name_dialog)
80  {
81  panel_pos = vec2(0.3 * vid_conwidth, 0.1 * vid_conheight);
82  panel_size = vec2(0.4 * vid_conwidth, 0.3 * vid_conheight);
83  }
84 
85  vector pos, mySize;
86  pos = panel_pos;
87  mySize = panel_size;
88 
91  else
94 
96  {
97  pos += '1 1 0' * panel_bg_padding;
98  mySize -= '2 2 0' * panel_bg_padding;
99  }
100 
101  // always force 3:1 aspect
102  vector newSize = '0 0 0';
103  if(mySize.x/mySize.y > 3)
104  {
105  newSize.x = 3 * mySize.y;
106  newSize.y = mySize.y;
107 
108  pos.x = pos.x + (mySize.x - newSize.x) / 2;
109  }
110  else
111  {
112  newSize.y = 1/3 * mySize.x;
113  newSize.x = mySize.x;
114 
115  pos.y = pos.y + (mySize.y - newSize.y) / 2;
116  }
117  mySize = newSize;
118 
119  s = _("A vote has been called for:");
120  if(uid2name_dialog)
121  s = _("Allow servers to store and display your name?");
122  drawstring_aspect(pos, s, vec2(mySize.x, (2/8) * mySize.y), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
123  s = textShortenToWidth(ColorTranslateRGB(vote_called_vote), mySize.x, '1 1 0' * mySize.y * (1/8), stringwidth_colors);
125  s = _("^1Configure the HUD");
126  drawcolorcodedstring_aspect(pos + eY * (2/8) * mySize.y, s, vec2(mySize.x, (1.75/8) * mySize.y), panel_fg_alpha, DRAWFLAG_NORMAL);
127 
128  // print the yes/no counts
129  s = sprintf("^2%s ^7(%d)", getcommandkey_forcename(_("Yes"), "vyes"), vote_yescount);
130  drawcolorcodedstring_aspect(pos + eY * (4/8) * mySize.y, s, vec2(0.5 * mySize.x, (1.5/8) * mySize.y), panel_fg_alpha, DRAWFLAG_NORMAL);
131  s = sprintf("^1%s ^7(%d)", getcommandkey_forcename(_("No"), "vno"), vote_nocount);
132  drawcolorcodedstring_aspect(pos + vec2(0.5 * mySize.x, (4/8) * mySize.y), s, vec2(0.5 * mySize.x, (1.5/8) * mySize.y), panel_fg_alpha, DRAWFLAG_NORMAL);
133 
134  pos.y += (5/8) * mySize.y;
135  vector tmp_size = vec2(mySize.x, (3/8) * mySize.y);
136  // draw the progress bar backgrounds
137  drawpic_skin(pos, "voteprogress_back", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
138 
139  // draw the highlights
140  if(vote_highlighted == 1) {
141  drawsetcliparea(pos.x, pos.y, mySize.x * 0.5, mySize.y);
142  drawpic_skin(pos, "voteprogress_voted", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
143  }
144  else if(vote_highlighted == -1) {
145  drawsetcliparea(pos.x + 0.5 * mySize.x, pos.y, mySize.x * 0.5, mySize.y);
146  drawpic_skin(pos, "voteprogress_voted", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
147  }
148 
149  // draw the progress bars
151  {
152  drawsetcliparea(pos.x, pos.y, mySize.x * 0.5 * (vote_yescount/vote_needed), mySize.y);
153  drawpic_skin(pos, "voteprogress_prog", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
154  }
155 
157  {
158  drawsetcliparea(pos.x + mySize.x - mySize.x * 0.5 * (vote_nocount/vote_needed), pos.y, mySize.x * 0.5, mySize.y);
159  drawpic_skin(pos, "voteprogress_prog", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
160  }
161 
163 }
bool autocvar_hud_panel_vote
Definition: vote.qh:4
float vid_conheight
int serverflags
Definition: main.qh:184
#define getcommandkey_forcename(cmd_name, command)
Definition: main.qh:109
float panel_fg_alpha
Definition: hud.qh:166
float uid2name_dialog
Definition: vote.qh:10
int vote_yescount
Definition: hud.qh:92
void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag)
Definition: draw.qc:102
const vector eY
Definition: vector.qh:45
int vote_highlighted
Definition: hud.qh:95
bool autocvar__hud_configure
Definition: hud_config.qh:3
vector panel_size
Definition: hud.qh:160
void HUD_Scale_Disable()
Definition: hud.qc:83
string textShortenToWidth(string theText, float maxWidth, vector theFontSize, textLengthUpToWidth_widthFunction_t tw)
Definition: util.qc:956
float vote_change
Definition: hud.qh:100
float vid_conwidth
int vote_prev
Definition: hud.qh:98
int vote_active
Definition: hud.qh:97
const int SERVERFLAG_PLAYERSTATS
Definition: constants.qh:17
int vote_needed
Definition: hud.qh:94
#define strcpy(this, s)
Definition: string.qh:49
bool autocvar_hud_panel_vote_dynamichud
Definition: vote.qh:6
float autocvar__menu_alpha
Definition: hud.qh:184
#define HUD_Panel_DrawBg()
Definition: hud.qh:54
string vote_called_vote
Definition: main.qh:111
int autocvar_cl_allow_uid2name
Definition: vote.qh:8
void HUD_Scale_Enable()
Definition: hud.qc:90
void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag)
Definition: draw.qc:108
ERASEABLE string ColorTranslateRGB(string s)
Definition: string.qh:177
float autocvar_hud_panel_vote_alreadyvoted_alpha
Definition: vote.qh:5
#define drawpic_skin(pos, pic, sz, color, theAlpha, drawflag)
Definition: draw.qh:89
#define LOG_INFO(...)
Definition: log.qh:70
const float DRAWFLAG_NORMAL
Definition: csprogsdefs.qc:317
vector panel_pos
Definition: hud.qh:159
vector(float skel, float bonenum) _skel_get_boneabs_hidden
float vote_alpha
Definition: hud.qh:99
#define MUTATOR_CALLHOOK(id,...)
Definition: base.qh:140
#define vec2(...)
Definition: vector.qh:90
float hud_fade_alpha
Definition: hud.qh:131
int vote_nocount
Definition: hud.qh:93
float time
Definition: csprogsdefs.qc:16
void HUD_Panel_LoadCvars()
Definition: hud.qc:216
float panel_bg_padding
Definition: hud.qh:171

◆ HUD_Vote_Export()

void HUD_Vote_Export ( int  fh)

Definition at line 7 of file vote.qc.

References HUD_Write_Cvar.

8 {
9  // allow saving cvars that aesthetically change the panel into hud skin files
10  HUD_Write_Cvar("hud_panel_vote_alreadyvoted_alpha");
11 }
#define HUD_Write_Cvar(cvar)
Definition: hud_config.qh:38