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