]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud/panel/vote.qc
Implement the uid2name dialog in the menu, but keep the existing one implemented...
[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 (!uid2name_dialog)
13                         localcmd("menu_cmd directmenu Uid2Name\n");
14                 if(autocvar__menu_alpha)
15                         hud_fade_alpha = 0;
16
17                 vote_active = 1;
18                 if (autocvar__hud_configure)
19                 {
20                         vote_yescount = 0;
21                         vote_nocount = 0;
22                         LOG_INFO(_("^1You must answer before entering hud configure mode\n"));
23                         cvar_set("_hud_configure", "0");
24                 }
25                 if(vote_called_vote)
26                         strunzone(vote_called_vote);
27                 vote_called_vote = strzone(_("^2Name ^7instead of \"^1Anonymous player^7\" in stats"));
28                 uid2name_dialog = 1;
29         }
30
31         if(!autocvar__hud_configure)
32         {
33                 if(!autocvar_hud_panel_vote) return;
34
35                 panel_fg_alpha = autocvar_hud_panel_fg_alpha;
36                 panel_bg_alpha_str = autocvar_hud_panel_vote_bg_alpha;
37
38                 if(panel_bg_alpha_str == "") {
39                         panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha);
40                 }
41                 panel_bg_alpha = stof(panel_bg_alpha_str);
42         }
43         else
44         {
45                 vote_yescount = 3;
46                 vote_nocount = 2;
47                 vote_needed = 4;
48         }
49
50         string s;
51         float a;
52         if(vote_active != vote_prev) {
53                 vote_change = time;
54                 vote_prev = vote_active;
55         }
56
57         if(vote_active || autocvar__hud_configure)
58                 vote_alpha = bound(0, (time - vote_change) * 2, 1);
59         else
60                 vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
61
62         if(!vote_alpha)
63                 return;
64
65         HUD_Panel_UpdateCvars();
66
67         if(uid2name_dialog)
68         {
69                 panel_pos = eX * 0.3 * vid_conwidth + eY * 0.1 * vid_conheight;
70                 panel_size = eX * 0.4 * vid_conwidth + eY * 0.3 * vid_conheight;
71         }
72
73     // these must be below above block
74         vector pos, mySize;
75         pos = panel_pos;
76         mySize = panel_size;
77
78         a = vote_alpha * (vote_highlighted ? autocvar_hud_panel_vote_alreadyvoted_alpha : 1);
79         if (autocvar_hud_panel_vote_dynamichud)
80                 HUD_Scale_Enable();
81         else
82                 HUD_Scale_Disable();
83         HUD_Panel_DrawBg(a);
84         a = panel_fg_alpha * a;
85
86         if(panel_bg_padding)
87         {
88                 pos += '1 1 0' * panel_bg_padding;
89                 mySize -= '2 2 0' * panel_bg_padding;
90         }
91
92         // always force 3:1 aspect
93         vector newSize = '0 0 0';
94         if(mySize.x/mySize.y > 3)
95         {
96                 newSize.x = 3 * mySize.y;
97                 newSize.y = mySize.y;
98
99                 pos.x = pos.x + (mySize.x - newSize.x) / 2;
100         }
101         else
102         {
103                 newSize.y = 1/3 * mySize.x;
104                 newSize.x = mySize.x;
105
106                 pos.y = pos.y + (mySize.y - newSize.y) / 2;
107         }
108         mySize = newSize;
109
110         s = _("A vote has been called for:");
111         if(uid2name_dialog)
112                 s = _("Allow servers to store and display your name?");
113         drawstring_aspect(pos, s, eX * mySize.x + eY * (2/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
114         s = textShortenToWidth(vote_called_vote, mySize.x, '1 1 0' * mySize.y * (1/8), stringwidth_colors);
115         if(autocvar__hud_configure)
116                 s = _("^1Configure the HUD");
117         drawcolorcodedstring_aspect(pos + eY * (2/8) * mySize.y, s, eX * mySize.x + eY * (1.75/8) * mySize.y, a, DRAWFLAG_NORMAL);
118
119         // print the yes/no counts
120     s = sprintf(_("Yes (%s): %d"), getcommandkey("vyes", "vyes"), vote_yescount);
121         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);
122     s = sprintf(_("No (%s): %d"), getcommandkey("vno", "vno"), vote_nocount);
123         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);
124
125         // draw the progress bar backgrounds
126         drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_back", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
127
128         // draw the highlights
129         if(vote_highlighted == 1) {
130                 drawsetcliparea(pos.x, pos.y, mySize.x * 0.5, mySize.y);
131                 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_voted", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
132         }
133         else if(vote_highlighted == -1) {
134                 drawsetcliparea(pos.x + 0.5 * mySize.x, pos.y, mySize.x * 0.5, mySize.y);
135                 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_voted", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
136         }
137
138         // draw the progress bars
139         if(vote_yescount && vote_needed)
140         {
141                 drawsetcliparea(pos.x, pos.y, mySize.x * 0.5 * (vote_yescount/vote_needed), mySize.y);
142                 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_prog", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
143         }
144
145         if(vote_nocount && vote_needed)
146         {
147                 drawsetcliparea(pos.x + mySize.x - mySize.x * 0.5 * (vote_nocount/vote_needed), pos.y, mySize.x * 0.5, mySize.y);
148                 drawpic_skin(pos + eY * (5/8) * mySize.y, "voteprogress_prog", eX * mySize.x + eY * (3/8) * mySize.y, '1 1 1', a, DRAWFLAG_NORMAL);
149         }
150
151         drawresetcliparea();
152 }