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