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