]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/vote.qc
take3: format 903 files
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / vote.qc
1 #include "vote.qh"
2
3 #include <client/autocvars.qh>
4 #include <client/defs.qh>
5 #include <client/miscfunctions.qh>
6 #include <common/mapinfo.qh>
7
8 // Vote (#9)
9
10 void HUD_Vote()
11 {
12         if (autocvar_cl_allow_uid2name == -1 && (gametype == MAPINFO_TYPE_CTS || gametype == MAPINFO_TYPE_RACE || (serverflags & SERVERFLAG_PLAYERSTATS))) {
13                 // this dialog gets overriden by the uid2name menu dialog, if it exists
14                 // TODO remove this client side uid2name dialog in the next release
15                 if (!autocvar__menu_alpha) {
16                         uid2name_dialog = 0;
17                 }
18
19                 if (!uid2name_dialog) {
20                         localcmd("menu_cmd directmenu Uid2Name\n");
21                 }
22
23                 vote_active = 1;
24                 if (autocvar__hud_configure) {
25                         vote_yescount = 0;
26                         vote_nocount = 0;
27                         LOG_INFO(_("^1You must answer before entering hud configure mode"));
28                         cvar_set("_hud_configure", "0");
29                 }
30                 if (vote_called_vote) {
31                         strunzone(vote_called_vote);
32                 }
33                 vote_called_vote = strzone(_("^2Name ^7instead of \"^1Anonymous player^7\" in stats"));
34                 uid2name_dialog = 1;
35         }
36
37         if (!autocvar__hud_configure) {
38                 if (!autocvar_hud_panel_vote) { return; }
39                 /*
40                 if(cvar("hud_panel_vote_test")) {
41                     if(vote_called_vote) strunzone(vote_called_vote); vote_called_vote = strzone("^1test the vote panel");
42                     vote_active = true; vote_yescount = 3; vote_nocount = 2; vote_needed = 4;
43                 } else vote_active = false;
44                 */
45         } else {
46                 vote_yescount = 3;
47                 vote_nocount = 2;
48                 vote_needed = 4;
49         }
50
51         string s;
52         float a;
53         if (vote_active != vote_prev) {
54                 vote_change = time;
55                 vote_prev = vote_active;
56         }
57
58         if (vote_active || autocvar__hud_configure) {
59                 vote_alpha = bound(0, (time - vote_change) * 2, 1);
60         } else {
61                 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
62         }
63
64         a = vote_alpha * (vote_highlighted ? autocvar_hud_panel_vote_alreadyvoted_alpha : 1);
65         if (a <= 0) {
66                 return;
67         }
68         // panel_fade_alpha *= a;
69         // nothing can hide this panel, not even the menu
70         float hud_fade_alpha_save = hud_fade_alpha;
71         if (uid2name_dialog && autocvar__menu_alpha) {
72                 hud_fade_alpha = 0;
73         } else {
74                 hud_fade_alpha = a;
75         }
76         HUD_Panel_LoadCvars();
77         hud_fade_alpha = hud_fade_alpha_save;
78
79         if (uid2name_dialog) {
80                 panel_pos = vec2(0.3 * vid_conwidth, 0.1 * vid_conheight);
81                 panel_size = vec2(0.4 * vid_conwidth, 0.3 * vid_conheight);
82         }
83
84         vector pos, mySize;
85         pos = panel_pos;
86         mySize = panel_size;
87
88         if (autocvar_hud_panel_vote_dynamichud) {
89                 HUD_Scale_Enable();
90         } else {
91                 HUD_Scale_Disable();
92         }
93         HUD_Panel_DrawBg();
94
95         if (panel_bg_padding) {
96                 pos += '1 1 0' * panel_bg_padding;
97                 mySize -= '2 2 0' * panel_bg_padding;
98         }
99
100         // always force 3:1 aspect
101         vector newSize = '0 0 0';
102         if (mySize.x / mySize.y > 3) {
103                 newSize.x = 3 * mySize.y;
104                 newSize.y = mySize.y;
105
106                 pos.x = pos.x + (mySize.x - newSize.x) / 2;
107         } else {
108                 newSize.y = 1 / 3 * mySize.x;
109                 newSize.x = mySize.x;
110
111                 pos.y = pos.y + (mySize.y - newSize.y) / 2;
112         }
113         mySize = newSize;
114
115         s = _("A vote has been called for:");
116         if (uid2name_dialog) {
117                 s = _("Allow servers to store and display your name?");
118         }
119         drawstring_aspect(pos, s, vec2(mySize.x, (2 / 8) * mySize.y), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
120         s = textShortenToWidth(ColorTranslateRGB(vote_called_vote), mySize.x, '1 1 0' * mySize.y * (1 / 8), stringwidth_colors);
121         if (autocvar__hud_configure) {
122                 s = _("^1Configure the HUD");
123         }
124         drawcolorcodedstring_aspect(pos + eY * (2 / 8) * mySize.y, s, vec2(mySize.x, (1.75 / 8) * mySize.y), panel_fg_alpha, DRAWFLAG_NORMAL);
125
126         // print the yes/no counts
127         s = sprintf("^2%s ^7(%d)", getcommandkey_forcename(_("Yes"), "vyes"), vote_yescount);
128         drawcolorcodedstring_aspect(pos + eY * (4 / 8) * mySize.y, s, vec2(0.5 * mySize.x, (1.5 / 8) * mySize.y), panel_fg_alpha, DRAWFLAG_NORMAL);
129         s = sprintf("^1%s ^7(%d)", getcommandkey_forcename(_("No"), "vno"), vote_nocount);
130         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);
131
132         pos.y += (5 / 8) * mySize.y;
133         vector tmp_size = vec2(mySize.x, (3 / 8) * mySize.y);
134         // draw the progress bar backgrounds
135         drawpic_skin(pos, "voteprogress_back", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
136
137         // draw the highlights
138         if (vote_highlighted == 1) {
139                 drawsetcliparea(pos.x, pos.y, mySize.x * 0.5, mySize.y);
140                 drawpic_skin(pos, "voteprogress_voted", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
141         } else if (vote_highlighted == -1) {
142                 drawsetcliparea(pos.x + 0.5 * mySize.x, pos.y, mySize.x * 0.5, mySize.y);
143                 drawpic_skin(pos, "voteprogress_voted", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
144         }
145
146         // draw the progress bars
147         if (vote_yescount && vote_needed) {
148                 drawsetcliparea(pos.x, pos.y, mySize.x * 0.5 * (vote_yescount / vote_needed), mySize.y);
149                 drawpic_skin(pos, "voteprogress_prog", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
150         }
151
152         if (vote_nocount && vote_needed) {
153                 drawsetcliparea(pos.x + mySize.x - mySize.x * 0.5 * (vote_nocount / vote_needed), pos.y, mySize.x * 0.5, mySize.y);
154                 drawpic_skin(pos, "voteprogress_prog", tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
155         }
156
157         drawresetcliparea();
158 }