]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/vote.qc
Merge branch 'master' into Mirio/balance
[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         if (autocvar_hud_panel_vote_dynamichud)
73                 HUD_Scale_Enable();
74         else
75                 HUD_Scale_Disable();
76         HUD_Panel_DrawBg(a);
77         a = panel_fg_alpha * a;
78
79         if(panel_bg_padding)
80         {
81                 pos += '1 1 0' * panel_bg_padding;
82                 mySize -= '2 2 0' * panel_bg_padding;
83         }
84
85         // always force 3:1 aspect
86         vector newSize = '0 0 0';
87         if(mySize.x/mySize.y > 3)
88         {
89                 newSize.x = 3 * mySize.y;
90                 newSize.y = mySize.y;
91
92                 pos.x = pos.x + (mySize.x - newSize.x) / 2;
93         }
94         else
95         {
96                 newSize.y = 1/3 * mySize.x;
97                 newSize.x = mySize.x;
98
99                 pos.y = pos.y + (mySize.y - newSize.y) / 2;
100         }
101         mySize = newSize;
102
103         s = _("A vote has been called for:");
104         if(uid2name_dialog)
105                 s = _("Allow servers to store and display your name?");
106         drawstring_aspect(pos, s, eX * mySize.x + eY * (2/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
107         s = textShortenToWidth(vote_called_vote, mySize.x, '1 1 0' * mySize.y * (1/8), stringwidth_colors);
108         if(autocvar__hud_configure)
109                 s = _("^1Configure the HUD");
110         drawcolorcodedstring_aspect(pos + eY * (2/8) * mySize.y, s, eX * mySize.x + eY * (1.75/8) * mySize.y, a, DRAWFLAG_NORMAL);
111
112         // print the yes/no counts
113     s = sprintf(_("Yes (%s): %d"), getcommandkey("vyes", "vyes"), vote_yescount);
114         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);
115     s = sprintf(_("No (%s): %d"), getcommandkey("vno", "vno"), vote_nocount);
116         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);
117
118         // draw the progress bar backgrounds
119         drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_back", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
120
121         // draw the highlights
122         if(vote_highlighted == 1) {
123                 drawsetcliparea(pos.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         else if(vote_highlighted == -1) {
127                 drawsetcliparea(pos.x + 0.5 * mySize.x, pos.y, mySize.x * 0.5, mySize.y);
128                 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_voted", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
129         }
130
131         // draw the progress bars
132         if(vote_yescount && vote_needed)
133         {
134                 drawsetcliparea(pos.x, pos.y, mySize.x * 0.5 * (vote_yescount/vote_needed), mySize.y);
135                 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_prog", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
136         }
137
138         if(vote_nocount && vote_needed)
139         {
140                 drawsetcliparea(pos.x + mySize.x - mySize.x * 0.5 * (vote_nocount/vote_needed), pos.y, mySize.x * 0.5, mySize.y);
141                 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_prog", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
142         }
143
144         drawresetcliparea();
145 }