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