]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/vote.qc
Merge branch 'master' into terencehill/dynamic_hud
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / vote.qc
1 #include "vote.qh"
2
3 #include <common/mapinfo.qh>
4
5 /** Vote window (#9) */
6 void HUD_Vote()
7 {
8         if(autocvar_cl_allow_uid2name == -1 && (gametype == MAPINFO_TYPE_CTS || gametype == MAPINFO_TYPE_RACE || (serverflags & SERVERFLAG_PLAYERSTATS)))
9         {
10                 vote_active = 1;
11                 if (autocvar__hud_configure)
12                 {
13                         vote_yescount = 0;
14                         vote_nocount = 0;
15                         LOG_INFO(_("^1You must answer before entering hud configure mode\n"));
16                         cvar_set("_hud_configure", "0");
17                 }
18                 if(vote_called_vote)
19                         strunzone(vote_called_vote);
20                 vote_called_vote = strzone(_("^2Name ^7instead of \"^1Anonymous player^7\" in stats"));
21                 uid2name_dialog = 1;
22         }
23
24         if(!autocvar__hud_configure)
25         {
26                 if(!autocvar_hud_panel_vote) return;
27
28                 panel_fg_alpha = autocvar_hud_panel_fg_alpha;
29                 panel_bg_alpha_str = autocvar_hud_panel_vote_bg_alpha;
30
31                 if(panel_bg_alpha_str == "") {
32                         panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha);
33                 }
34                 panel_bg_alpha = stof(panel_bg_alpha_str);
35         }
36         else
37         {
38                 vote_yescount = 3;
39                 vote_nocount = 2;
40                 vote_needed = 4;
41         }
42
43         string s;
44         float a;
45         if(vote_active != vote_prev) {
46                 vote_change = time;
47                 vote_prev = vote_active;
48         }
49
50         if(vote_active || autocvar__hud_configure)
51                 vote_alpha = bound(0, (time - vote_change) * 2, 1);
52         else
53                 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
54
55         if(!vote_alpha)
56                 return;
57
58         HUD_Panel_UpdateCvars();
59
60         if(uid2name_dialog)
61         {
62                 panel_pos = eX * 0.3 * vid_conwidth + eY * 0.1 * vid_conheight;
63                 panel_size = eX * 0.4 * vid_conwidth + eY * 0.3 * vid_conheight;
64         }
65
66     // these must be below above block
67         vector pos, mySize;
68         pos = panel_pos;
69         mySize = panel_size;
70
71         a = vote_alpha * (vote_highlighted ? autocvar_hud_panel_vote_alreadyvoted_alpha : 1);
72         HUD_Panel_DrawBg(a);
73         a = panel_fg_alpha * a;
74
75         if(panel_bg_padding)
76         {
77                 pos += '1 1 0' * panel_bg_padding;
78                 mySize -= '2 2 0' * panel_bg_padding;
79         }
80
81         // always force 3:1 aspect
82         vector newSize = '0 0 0';
83         if(mySize.x/mySize.y > 3)
84         {
85                 newSize.x = 3 * mySize.y;
86                 newSize.y = mySize.y;
87
88                 pos.x = pos.x + (mySize.x - newSize.x) / 2;
89         }
90         else
91         {
92                 newSize.y = 1/3 * mySize.x;
93                 newSize.x = mySize.x;
94
95                 pos.y = pos.y + (mySize.y - newSize.y) / 2;
96         }
97         mySize = newSize;
98
99         s = _("A vote has been called for:");
100         if(uid2name_dialog)
101                 s = _("Allow servers to store and display your name?");
102         drawstring_aspect(pos, s, eX * mySize.x + eY * (2/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
103         s = textShortenToWidth(vote_called_vote, mySize.x, '1 1 0' * mySize.y * (1/8), stringwidth_colors);
104         if(autocvar__hud_configure)
105                 s = _("^1Configure the HUD");
106         drawcolorcodedstring_aspect(pos + eY * (2/8) * mySize.y, s, eX * mySize.x + eY * (1.75/8) * mySize.y, a, DRAWFLAG_NORMAL);
107
108         // print the yes/no counts
109     s = sprintf(_("Yes (%s): %d"), getcommandkey("vyes", "vyes"), vote_yescount);
110         drawstring_aspect(pos + eY * (4/8) * mySize.y, s, eX * 0.5 * mySize.x + eY * (1.5/8) * mySize.y, '0 1 0', a, DRAWFLAG_NORMAL);
111     s = sprintf(_("No (%s): %d"), getcommandkey("vno", "vno"), vote_nocount);
112         drawstring_aspect(pos + eX * 0.5 * mySize.x + eY * (4/8) * mySize.y, s, eX * 0.5 * mySize.x + eY * (1.5/8) * mySize.y, '1 0 0', a, DRAWFLAG_NORMAL);
113
114         // draw the progress bar backgrounds
115         drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_back", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
116
117         // draw the highlights
118         if(vote_highlighted == 1) {
119                 drawsetcliparea(pos.x, pos.y, mySize.x * 0.5, mySize.y);
120                 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_voted", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
121         }
122         else if(vote_highlighted == -1) {
123                 drawsetcliparea(pos.x + 0.5 * mySize.x, pos.y, mySize.x * 0.5, mySize.y);
124                 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_voted", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
125         }
126
127         // draw the progress bars
128         if(vote_yescount && vote_needed)
129         {
130                 drawsetcliparea(pos.x, pos.y, mySize.x * 0.5 * (vote_yescount/vote_needed), mySize.y);
131                 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_prog", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
132         }
133
134         if(vote_nocount && vote_needed)
135         {
136                 drawsetcliparea(pos.x + mySize.x - mySize.x * 0.5 * (vote_nocount/vote_needed), pos.y, mySize.x * 0.5, mySize.y);
137                 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_prog", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
138         }
139
140         drawresetcliparea();
141 }