]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/vote.qc
Merge branch 'TimePath/remove_remove'
[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                 // this dialog gets overriden by the uid2name menu dialog, if it exists
11                 // TODO remove this client side uid2name dialog in the next release
12                 if(autocvar__menu_alpha)
13                         hud_fade_alpha = 0;
14                 else
15                         uid2name_dialog = 0;
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                 panel_fg_alpha = autocvar_hud_panel_fg_alpha;
38                 panel_bg_alpha_str = autocvar_hud_panel_vote_bg_alpha;
39
40                 if(panel_bg_alpha_str == "") {
41                         panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha);
42                 }
43                 panel_bg_alpha = stof(panel_bg_alpha_str);
44         }
45         else
46         {
47                 vote_yescount = 3;
48                 vote_nocount = 2;
49                 vote_needed = 4;
50         }
51
52         string s;
53         float a;
54         if(vote_active != vote_prev) {
55                 vote_change = time;
56                 vote_prev = vote_active;
57         }
58
59         if(vote_active || autocvar__hud_configure)
60                 vote_alpha = bound(0, (time - vote_change) * 2, 1);
61         else
62                 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
63
64         if(!vote_alpha)
65                 return;
66
67         HUD_Panel_UpdateCvars();
68
69         if(uid2name_dialog)
70         {
71                 panel_pos = eX * 0.3 * vid_conwidth + eY * 0.1 * vid_conheight;
72                 panel_size = eX * 0.4 * vid_conwidth + eY * 0.3 * vid_conheight;
73         }
74
75         vector pos, mySize;
76         pos = panel_pos;
77         mySize = panel_size;
78
79         a = vote_alpha * (vote_highlighted ? autocvar_hud_panel_vote_alreadyvoted_alpha : 1);
80         if (autocvar_hud_panel_vote_dynamichud)
81                 HUD_Scale_Enable();
82         else
83                 HUD_Scale_Disable();
84         HUD_Panel_DrawBg(a);
85         a = panel_fg_alpha * a;
86
87         if(panel_bg_padding)
88         {
89                 pos += '1 1 0' * panel_bg_padding;
90                 mySize -= '2 2 0' * panel_bg_padding;
91         }
92
93         // always force 3:1 aspect
94         vector newSize = '0 0 0';
95         if(mySize.x/mySize.y > 3)
96         {
97                 newSize.x = 3 * mySize.y;
98                 newSize.y = mySize.y;
99
100                 pos.x = pos.x + (mySize.x - newSize.x) / 2;
101         }
102         else
103         {
104                 newSize.y = 1/3 * mySize.x;
105                 newSize.x = mySize.x;
106
107                 pos.y = pos.y + (mySize.y - newSize.y) / 2;
108         }
109         mySize = newSize;
110
111         s = _("A vote has been called for:");
112         if(uid2name_dialog)
113                 s = _("Allow servers to store and display your name?");
114         drawstring_aspect(pos, s, eX * mySize.x + eY * (2/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
115         s = textShortenToWidth(vote_called_vote, mySize.x, '1 1 0' * mySize.y * (1/8), stringwidth_colors);
116         if(autocvar__hud_configure)
117                 s = _("^1Configure the HUD");
118         drawcolorcodedstring_aspect(pos + eY * (2/8) * mySize.y, s, eX * mySize.x + eY * (1.75/8) * mySize.y, a, DRAWFLAG_NORMAL);
119
120         // print the yes/no counts
121         s = sprintf("^2%s ^7(%d)", getcommandkey_forcename(_("Yes"), "vyes"), vote_yescount);
122         drawcolorcodedstring_aspect(pos + eY * (4/8) * mySize.y, s, eX * 0.5 * mySize.x + eY * (1.5/8) * mySize.y, a, DRAWFLAG_NORMAL);
123         s = sprintf("^1%s ^7(%d)", getcommandkey_forcename(_("No"), "vno"), vote_nocount);
124         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, a, DRAWFLAG_NORMAL);
125
126         // draw the progress bar backgrounds
127         drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_back", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
128
129         // draw the highlights
130         if(vote_highlighted == 1) {
131                 drawsetcliparea(pos.x, pos.y, mySize.x * 0.5, mySize.y);
132                 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_voted", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
133         }
134         else if(vote_highlighted == -1) {
135                 drawsetcliparea(pos.x + 0.5 * mySize.x, pos.y, mySize.x * 0.5, mySize.y);
136                 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_voted", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
137         }
138
139         // draw the progress bars
140         if(vote_yescount && vote_needed)
141         {
142                 drawsetcliparea(pos.x, pos.y, mySize.x * 0.5 * (vote_yescount/vote_needed), mySize.y);
143                 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_prog", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
144         }
145
146         if(vote_nocount && vote_needed)
147         {
148                 drawsetcliparea(pos.x + mySize.x - mySize.x * 0.5 * (vote_nocount/vote_needed), pos.y, mySize.x * 0.5, mySize.y);
149                 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_prog", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
150         }
151
152         drawresetcliparea();
153 }