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