Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
vote.qc
Go to the documentation of this file.
1#include "vote.qh"
2
3#include <client/draw.qh>
4
5// Vote (#9)
6
7void HUD_Vote_Export(int fh)
8{
9 // allow saving cvars that aesthetically change the panel into hud skin files
10 HUD_Write_Cvar("hud_panel_vote_alreadyvoted_alpha");
11}
12
13void HUD_Vote(bool should_draw)
14{
15 if (!should_draw)
16 return;
18 {
19 // this dialog gets overriden by the uid2name menu dialog, if it exists
20 // TODO remove this client side uid2name dialog in the next release
23
24 if (!uid2name_dialog)
25 localcmd("menu_cmd directmenu Uid2Name\n");
26
27 vote_active = true;
29 {
30 vote_yescount = 0;
31 vote_nocount = 0;
32 LOG_INFO(_("^1You must answer before entering HUD configure mode"));
33 cvar_set("_hud_configure", "0");
34 }
35 strcpy(vote_called_vote, _("^2Name ^7instead of \"^1Anonymous player^7\" in stats"));
37 }
38
40 {
42 return;
43 /*
44 if (cvar("hud_panel_vote_test"))
45 {
46 if (vote_called_vote)
47 strunzone(vote_called_vote);
48 vote_called_vote = strzone("^1test the vote panel");
49 vote_active = true; vote_yescount = 3; vote_nocount = 2; vote_needed = 4;
50 }
51 else
52 vote_active = false;
53 */
54 }
55 else
56 {
57 vote_yescount = 3;
58 vote_nocount = 2;
59 vote_needed = 4;
60 }
61
63 {
66 }
67
69 vote_alpha = bound(0, (time - vote_change) * 2, 1);
70 else
71 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
72
74 if (a <= 0)
75 return;
76
77 // menu can't hide this panel, unless:
78 // 1) the uid2name menu dialog is open (replaces this panel)
79 // 2) the settings menu of another panel is open (hud_config mode)
80 float hud_fade_alpha_save = hud_fade_alpha;
83 else if (!(hud_configure_menu_open == 2 && highlightedPanel != panel))
86 hud_fade_alpha = hud_fade_alpha_save;
87
89 {
92 }
93
94 vector pos = panel_pos;
95 vector mySize = panel_size;
96
99 else
102
104 {
105 pos += '1 1 0' * panel_bg_padding;
106 mySize -= '2 2 0' * panel_bg_padding;
107 }
108
109 // force 3:1 aspect, but if the panel is thin force 3:2 and draw yes on top of no
110 vector newSize = '0 0 0';
111 bool yes_on_top;
112 if (mySize.x / mySize.y > 3)
113 {
114 newSize.x = 3 * mySize.y;
115 newSize.y = mySize.y;
116
117 pos.x += (mySize.x - newSize.x) * 0.5;
118 yes_on_top = false;
119 }
120 else if (mySize.x / mySize.y > 3/2)
121 {
122 newSize.y = (1/3) * mySize.x;
123 newSize.x = mySize.x;
124
125 pos.y += (mySize.y - newSize.y) * 0.5;
126 yes_on_top = false;
127 }
128 else
129 {
130 newSize.y = (2/3) * mySize.x;
131 newSize.x = mySize.x;
132
133 pos.y += (mySize.y - newSize.y) * 0.5;
134 yes_on_top = true;
135 }
136 mySize = newSize;
137
138 string s = uid2name_dialog
139 ? _("Allow servers to store and display your name?")
140 : _("A vote has been called for:");
141 drawstring_aspect(pos, s, vec2(mySize.x, (2/8) * mySize.y), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
142 // has no padding afterwards
144 s = _("^1Configure the HUD");
145 else
146 s = textShortenToWidth(ColorTranslateRGB(vote_called_vote), mySize.x, '1 1 0' * mySize.y * (1/8), stringwidth_colors);
147 drawcolorcodedstring_aspect(pos + eY * (2/8) * mySize.y, s, vec2(mySize.x, (1.75/8) * mySize.y), panel_fg_alpha, DRAWFLAG_NORMAL);
148 // has 0.25/8 padding afterwards
149
150 // print the yes/no counts
151 float height = (yes_on_top ? 1.3/8 : 1.5/8);
152 s = sprintf("^2%s ^7(%d)", getcommandkey_forcename(_("Yes"), "vyes"), vote_yescount);
153 drawcolorcodedstring_aspect(pos + eY * (4/8) * mySize.y, s, vec2(0.5 * mySize.x, height * mySize.y), panel_fg_alpha, DRAWFLAG_NORMAL);
154 s = sprintf("^1%s ^7(%d)", getcommandkey_forcename(_("No"), "vno"), vote_nocount);
155 drawcolorcodedstring_aspect(pos + vec2(0.5 * mySize.x, (4/8) * mySize.y), s, vec2(0.5 * mySize.x, height * mySize.y), panel_fg_alpha, DRAWFLAG_NORMAL);
156 // overlap with the bars by up to 0.1/8 if yes_on_top or otherwise 0.3/8
157 // this overlap looks fine only since the bar images have padding
158
159 pos.y += 5.2/8 * mySize.y;
160 vector tmp_size, pos_no, pos_yes = pos;
161 if (yes_on_top)
162 {
163 tmp_size = vec2(mySize.x * 2, ((8 - 5.2) * 0.5 + 0.1) / 8 * mySize.y);
164 // bar images have padding, so let them overlap a bit (by 0.1/8)
165 pos_no = pos + eY * ((8 - 5.2) * 0.5 - 0.1) / 8 * mySize.y - eX * mySize.x;
166 // yes is drawn taking the full width,
167 // ... then no is drawn directly underneath also taking the full width,
168 // ... so drawpic position has to be shifted left by the full width
169 }
170 else
171 {
172 tmp_size = vec2(mySize.x, (8 - 5.2) / 8 * mySize.y);
173 pos_no = pos;
174 mySize.x *= 0.5;
175 }
176
177 // draw the progress bar backgrounds
178 if (yes_on_top)
179 {
180 drawsetcliparea(pos_yes.x, pos_yes.y, mySize.x, mySize.y);
181 drawpic_skin(pos_yes, "voteprogress_back", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); // yes
182 drawsetcliparea(pos_no.x + mySize.x, pos_no.y, mySize.x, mySize.y);
183 drawpic_skin(pos_no, "voteprogress_back", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); // no
184 }
185 else
186 drawpic_skin(pos, "voteprogress_back", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); // both, in a line
187
188 // draw the highlights
189 if (vote_highlighted == 1) // yes
190 {
191 drawsetcliparea(pos_yes.x, pos_yes.y, mySize.x, mySize.y);
192 drawpic_skin(pos_yes, "voteprogress_voted", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
193 }
194 else if (vote_highlighted == -1) // no
195 {
196 drawsetcliparea(pos_no.x + mySize.x, pos_no.y, mySize.x, mySize.y);
197 drawpic_skin(pos_no, "voteprogress_voted", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
198 }
199
200 // draw the progress bars
201 if (vote_yescount && vote_needed) // yes
202 {
203 drawsetcliparea(pos_yes.x, pos_yes.y, mySize.x * (vote_yescount / vote_needed), mySize.y);
204 drawpic_skin(pos_yes, "voteprogress_prog", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
205 }
206 if (vote_nocount && vote_needed) // no
207 {
208 drawsetcliparea(pos_no.x + mySize.x * 2 - mySize.x * (vote_nocount / vote_needed), pos_no.y, mySize.x, mySize.y);
209 drawpic_skin(pos_no, "voteprogress_prog", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
210 }
211
213}
#define MUTATOR_CALLHOOK(id,...)
Definition base.qh:143
float height
Definition bobbing.qc:3
void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag)
Definition draw.qc:109
void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag)
Definition draw.qc:115
#define drawsetcliparea(xposition, yposition, w, h)
Definition draw.qh:39
#define drawpic_skin(pos, pic, sz, color, theAlpha, drawflag)
Definition draw.qh:88
void HUD_Vote_Export(int fh)
Definition vote.qc:7
void HUD_Vote(bool should_draw)
Definition vote.qc:13
bool autocvar_hud_panel_vote
Definition vote.qh:4
bool autocvar_hud_panel_vote_dynamichud
Definition vote.qh:6
float autocvar_hud_panel_vote_alreadyvoted_alpha
Definition vote.qh:5
int autocvar_cl_allow_uid2name
Definition vote.qh:8
float uid2name_dialog
Definition vote.qh:10
#define getcommandkey_forcename(cmd_name, command)
Definition main.qh:138
int serverflags
Definition main.qh:211
string vote_called_vote
Definition main.qh:142
string textShortenToWidth(string theText, float maxWidth, vector theFontSize, textLengthUpToWidth_widthFunction_t tw)
Definition util.qc:1171
const int SERVERFLAG_PLAYERSTATS
Definition constants.qh:18
const float DRAWFLAG_NORMAL
float time
void HUD_Panel_LoadCvars()
Definition hud.qc:215
void HUD_Scale_Enable()
Definition hud.qc:91
void HUD_Scale_Disable()
Definition hud.qc:84
entity highlightedPanel
Definition hud.qh:107
int vote_highlighted
Definition hud.qh:96
int vote_nocount
Definition hud.qh:94
vector panel_size
Definition hud.qh:163
int vote_needed
Definition hud.qh:95
float panel_fg_alpha
Definition hud.qh:169
int vote_active
Definition hud.qh:98
float autocvar__menu_alpha
Definition hud.qh:187
float panel_bg_padding
Definition hud.qh:174
int vote_yescount
Definition hud.qh:93
float vote_change
Definition hud.qh:101
float vote_alpha
Definition hud.qh:100
int vote_prev
Definition hud.qh:99
float hud_fade_alpha
Definition hud.qh:134
#define HUD_Panel_DrawBg()
Definition hud.qh:55
vector panel_pos
Definition hud.qh:162
entity panel
Definition hud.qh:147
#define HUD_Write_Cvar(cvar)
Definition hud_config.qh:40
bool autocvar__hud_configure
Definition hud_config.qh:3
float hud_configure_menu_open
Definition hud_config.qh:22
noref float vid_conwidth
Definition draw.qh:8
noref float vid_conheight
Definition draw.qh:9
#define LOG_INFO(...)
Definition log.qh:65
void localcmd(string command,...)
void cvar_set(string name, string value)
void drawresetcliparea(void)
float bound(float min, float value, float max)
vector
Definition self.qh:92
ERASEABLE string ColorTranslateRGB(string s)
Definition string.qh:196
#define strcpy(this, s)
Definition string.qh:52
float stringwidth_colors(string s, vector theSize)
Definition string.qh:30
const vector eY
Definition vector.qh:45
const vector eX
Definition vector.qh:44
#define vec2(...)
Definition vector.qh:90