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
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
21
22 if (!uid2name_dialog)
23 localcmd("menu_cmd directmenu Uid2Name\n");
24
25 vote_active = true;
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"));
35 }
36
38 {
40 return;
41 /*
42 if (cvar("hud_panel_vote_test"))
43 {
44 if (vote_called_vote)
45 strunzone(vote_called_vote);
46 vote_called_vote = strzone("^1test the vote panel");
47 vote_active = true; vote_yescount = 3; vote_nocount = 2; vote_needed = 4;
48 }
49 else
50 vote_active = false;
51 */
52 }
53 else
54 {
55 vote_yescount = 3;
56 vote_nocount = 2;
57 vote_needed = 4;
58 }
59
61 {
64 }
65
67 vote_alpha = bound(0, (time - vote_change) * 2, 1);
68 else
69 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
70
72 if (a <= 0)
73 return;
74
75 // menu can't hide this panel, unless:
76 // 1) the uid2name menu dialog is open (replaces this panel)
77 // 2) the settings menu of another panel is open (hud_config mode)
78 float hud_fade_alpha_save = hud_fade_alpha;
81 else if (!(hud_configure_menu_open == 2 && highlightedPanel != panel))
84 hud_fade_alpha = hud_fade_alpha_save;
85
87 {
90 }
91
92 vector pos = panel_pos;
93 vector mySize = panel_size;
94
97 else
100
102 {
103 pos += '1 1 0' * panel_bg_padding;
104 mySize -= '2 2 0' * panel_bg_padding;
105 }
106
107 // always force 3:1 aspect
108 vector newSize = '0 0 0';
109 if (mySize.x / mySize.y > 3)
110 {
111 newSize.x = 3 * mySize.y;
112 newSize.y = mySize.y;
113
114 pos.x += (mySize.x - newSize.x) * 0.5;
115 }
116 else
117 {
118 newSize.y = 1/3 * mySize.x;
119 newSize.x = mySize.x;
120
121 pos.y += (mySize.y - newSize.y) * 0.5;
122 }
123 mySize = newSize;
124
125 string s = uid2name_dialog
126 ? _("Allow servers to store and display your name?")
127 : _("A vote has been called for:");
128 drawstring_aspect(pos, s, vec2(mySize.x, (2/8) * mySize.y), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
130 s = _("^1Configure the HUD");
131 else
132 s = textShortenToWidth(ColorTranslateRGB(vote_called_vote), mySize.x, '1 1 0' * mySize.y * (1/8), stringwidth_colors);
133 drawcolorcodedstring_aspect(pos + eY * (2/8) * mySize.y, s, vec2(mySize.x, (1.75/8) * mySize.y), panel_fg_alpha, DRAWFLAG_NORMAL);
134
135 // print the yes/no counts
136 s = sprintf("^2%s ^7(%d)", getcommandkey_forcename(_("Yes"), "vyes"), vote_yescount);
137 drawcolorcodedstring_aspect(pos + eY * (4/8) * mySize.y, s, vec2(0.5 * mySize.x, (1.5/8) * mySize.y), panel_fg_alpha, DRAWFLAG_NORMAL);
138 s = sprintf("^1%s ^7(%d)", getcommandkey_forcename(_("No"), "vno"), vote_nocount);
139 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);
140
141 pos.y += (5/8) * mySize.y;
142 vector tmp_size = vec2(mySize.x, (3/8) * mySize.y);
143 // draw the progress bar backgrounds
144 drawpic_skin(pos, "voteprogress_back", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
145
146 // draw the highlights
147 if (vote_highlighted == 1)
148 {
149 drawsetcliparea(pos.x, pos.y, mySize.x * 0.5, mySize.y);
150 drawpic_skin(pos, "voteprogress_voted", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
151 }
152 else if (vote_highlighted == -1)
153 {
154 drawsetcliparea(pos.x + 0.5 * mySize.x, pos.y, mySize.x * 0.5, mySize.y);
155 drawpic_skin(pos, "voteprogress_voted", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
156 }
157
158 // draw the progress bars
160 {
161 drawsetcliparea(pos.x, pos.y, mySize.x * 0.5 * (vote_yescount / vote_needed), mySize.y);
162 drawpic_skin(pos, "voteprogress_prog", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
163 }
165 {
166 drawsetcliparea(pos.x + mySize.x - mySize.x * 0.5 * (vote_nocount / vote_needed), pos.y, mySize.x * 0.5, mySize.y);
167 drawpic_skin(pos, "voteprogress_prog", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
168 }
169
171}
#define MUTATOR_CALLHOOK(id,...)
Definition base.qh:143
void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag)
Definition draw.qc:110
void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag)
Definition draw.qc:116
#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()
Definition vote.qc:13
void HUD_Vote_Export(int fh)
Definition vote.qc:7
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:1071
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
#define vec2(...)
Definition vector.qh:90