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