4 string mv_maps[MAPVOTE_COUNT];
5 string mv_pics[MAPVOTE_COUNT];
6 string mv_pk3[MAPVOTE_COUNT];
7 float mv_preview[MAPVOTE_COUNT];
8 float mv_votes[MAPVOTE_COUNT];
21 string MapVote_FormatMapItem(float id, string map, float count, float maxwidth, vector fontsize)
24 pre = sprintf("%d. ", id+1);
28 post = _(" (1 vote)");
30 post = sprintf(_(" (%d votes)"), count);
34 maxwidth -= stringwidth(pre, FALSE, fontsize) + stringwidth(post, FALSE, fontsize);
35 map = textShortenToWidth(map, maxwidth, fontsize, stringwidth_nocolors);
36 return strcat(pre, map, post);
39 vector MapVote_RGB(float id, float count)
45 else if (id == mv_selection)
51 void MapVote_DrawMapItem(vector pos, float isize, float tsize, string map, string pic, float count, float id)
58 isize -= hud_fontsize_y; // respect the text when calculating the image size
60 rgb = MapVote_RGB(id, count);
63 img_size_x = isize / 0.75; // 4:3 x can be stretched easily, height is defined in isize
65 pos_y = pos_y + img_size_y;
67 label = MapVote_FormatMapItem(id, map, count, tsize, hud_fontsize);
69 text_size = stringwidth(label, false, hud_fontsize);
72 if (count < 0 && mv_top2_alpha)
73 theAlpha = mv_top2_alpha;
77 pos_x -= text_size*0.5;
78 drawstring(pos, label, hud_fontsize, rgb, theAlpha, DRAWFLAG_NORMAL);
80 pos_x = pos_x + text_size*0.5 - img_size_x*0.5;
81 pos_y = pos_y - img_size_y;
83 pos += autocvar_scoreboard_border_thickness * '1 1 0';
84 img_size -= (autocvar_scoreboard_border_thickness * 2) * '1 1 0';
87 drawfill(pos, img_size, '.5 .5 .5', .7 * theAlpha, DRAWFLAG_NORMAL);
91 if(drawgetimagesize(pic) == '0 0 0')
92 drawpic(pos, draw_UseSkinFor("nopreview_map"), img_size, '1 1 1', theAlpha, DRAWFLAG_NORMAL);
94 drawpic(pos, pic, img_size, '1 1 1', theAlpha, DRAWFLAG_NORMAL);
98 drawborderlines(autocvar_scoreboard_border_thickness, pos, img_size, rgb, theAlpha, DRAWFLAG_NORMAL);
100 drawborderlines(autocvar_scoreboard_border_thickness, pos, img_size, '0 0 0', theAlpha, DRAWFLAG_NORMAL);
102 if(id == mv_selection && count >= 0)
103 drawfill(pos, img_size, '1 1 1', 0.1, DRAWFLAG_NORMAL);
106 void MapVote_DrawAbstain(vector pos, float isize, float tsize, float count, float id)
112 rgb = MapVote_RGB(id, count);
114 pos_y = pos_y + hud_fontsize_y;
116 label = MapVote_FormatMapItem(id, _("Don't care"), count, tsize, hud_fontsize);
118 text_size = stringwidth(label, false, hud_fontsize);
120 pos_x -= text_size*0.5;
121 drawstring(pos, label, hud_fontsize, rgb, 1, DRAWFLAG_NORMAL);
124 vector MapVote_GridVec(vector gridspec, float i, float m)
129 '1 0 0' * (gridspec_x * r)
131 '0 1 0' * (gridspec_y * (i - r) / m);
134 float MapVote_Selection(vector topleft, vector cellsize, float rows, float columns)
141 for (r = 0; r < rows; ++r)
142 for (c = 0; c < columns; ++c)
144 if (mv_mousepos_x >= topleft_x + cellsize_x * c &&
145 mv_mousepos_x <= topleft_x + cellsize_x * (c + 1) &&
146 mv_mousepos_y >= topleft_y + cellsize_y * r &&
147 mv_mousepos_y <= topleft_y + cellsize_y * (r + 1))
149 cell = r * columns + c;
154 if (cell >= mv_num_maps)
157 if (mv_abstain && cell < 0)
177 center = (vid_conwidth - 1)/2;
178 xmin = vid_conwidth*0.05; // 5% border must suffice
179 xmax = vid_conwidth - xmin;
181 i = autocvar_con_chatpos; //*autocvar_con_chatsize;
183 ymax = vid_conheight + (i - autocvar_con_chat) * autocvar_con_chatsize;
184 if(i >= 0 || ymax < (vid_conheight*0.5))
185 ymax = vid_conheight - ymin;
187 hud_fontsize = HUD_GetFontsize("hud_fontsize");
192 draw_beginBoldFont();
193 map = _("Vote for a map");
194 pos_x = center - stringwidth(map, false, '12 0 0');
195 drawstring(pos, map, '24 24 0', '1 1 1', 1, DRAWFLAG_NORMAL);
198 i = ceil(max(0, mv_timeout - time));
199 map = sprintf(_("%d seconds left"), i);
200 pos_x = center - stringwidth(map, false, '8 0 0');
201 drawstring(pos, map, '16 16 0', '0 1 0', 1, DRAWFLAG_NORMAL);
206 // base for multi-column stuff...
215 columns = mv_num_maps;
217 rows = ceil(mv_num_maps / columns);
219 dist_x = (xmax - xmin) / columns;
220 dist_y = (ymax - pos_y) / rows;
222 isize = min(dist_y - 10, 0.75 * tsize);
224 mv_selection = MapVote_Selection(pos, dist, rows, columns);
226 pos_x += (xmax - xmin) / (2 * columns);
227 pos_y += (dist_y - isize) / 2;
231 mv_top2_alpha = max(0.2, 1 - (time - mv_top2_time)*(time - mv_top2_time));
233 for(i = 0; i < mv_num_maps; ++i)
235 tmp = mv_votes[i]; // FTEQCC bug: too many array accesses in the function call screw it up
238 MapVote_DrawMapItem(pos + MapVote_GridVec(dist, i, columns), isize, tsize, map, mv_pics[i], tmp, i);
240 MapVote_DrawMapItem(pos + MapVote_GridVec(dist, i, columns), isize, tsize, map, "", tmp, i);
246 if(mv_abstain && i < mv_num_maps) {
248 pos_y = ymax + isize - hud_fontsize_y;
249 pos_x = (xmax+xmin)*0.5;
250 MapVote_DrawAbstain(pos, isize, xmax - xmin, tmp, i);
253 drawpic(mv_mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), '32 32 0', '1 1 1', autocvar_hud_panel_fg_alpha, DRAWFLAG_NORMAL);
256 void Cmd_MapVote_MapDownload(float argc)
261 if(argc != 2 || !mv_pk3list)
263 print(_("mv_mapdownload: ^3You're not supposed to use this command on your own!\n"));
268 for(pak = mv_pk3list; pak; pak = pak.chain)
269 if(pak.sv_entnum == id)
272 if(!pak || pak.sv_entnum != id) {
273 print(_("^1Error:^7 Couldn't find pak index.\n"));
277 if(PreviewExists(pak.message))
279 mv_preview[id] = true;
282 print(_("Requesting preview...\n"));
283 localcmd(strcat("\ncmd mv_getpicture ", ftos(id), "\n"));
287 void MapVote_CheckPK3(string pic, string pk3, float id)
295 pak.chain = mv_pk3list;
300 localcmd(strcat("\ncurl --pak ", pk3, "; wait; cl_cmd mv_download ", ftos(id), "\n"));
304 Cmd_MapVote_MapDownload(tokenize_console(strcat("mv_download ", ftos(id))));
308 void MapVote_CheckPic(string pic, string pk3, float id)
310 // never try to retrieve a pic for the "don't care" 'map'
311 if(mv_abstain && id == mv_num_maps - 1)
314 if(PreviewExists(pic))
316 mv_preview[id] = true;
319 MapVote_CheckPK3(pic, pk3, id);
323 string ssdirs[NUM_SSDIRS];
330 precache_sound ("misc/invshot.wav");
336 for(n_ssdirs = 0; ; ++n_ssdirs)
341 if(n_ssdirs < NUM_SSDIRS)
342 ssdirs[n_ssdirs] = s;
344 n_ssdirs = min(n_ssdirs, NUM_SSDIRS);
346 mv_num_maps = min(MAPVOTE_COUNT, ReadByte());
347 mv_abstain = ReadByte();
349 mv_abstain = 1; // must be 1 for bool-true, makes stuff easier
350 mv_detail = ReadByte();
353 mv_timeout = ReadCoord();
356 mv_maps_mask = ReadByte();
358 mv_maps_mask = ReadShort();
360 // Assume mv_pk3list is world, there should only be 1 mapvote per round
361 mv_pk3list = world; // I'm still paranoid!
363 for(i = 0, power = 1; i < mv_num_maps; ++i, power *= 2)
367 if(mv_maps_mask & power)
369 map = strzone(ReadString());
370 pk3 = strzone(ReadString());
371 j = bound(0, ReadByte(), n_ssdirs - 1);
375 map = strzone(strcat(ssdirs[j], "/", map));
378 mv_preview[i] = false;
380 MapVote_CheckPic(map, pk3, i);
384 mv_maps[i] = strzone("if-you-see-this-the-code-is-broken");
385 mv_pk3[i] = strzone("if-you-see-this-the-code-is-broken");
386 mv_pics[i] = strzone("if-you-see-this-the-code-is-broken");
387 mv_preview[i] = false;
391 for(i = 0; i < n_ssdirs; ++i)
392 ssdirs[n_ssdirs] = string_null;
396 float MapVote_InputEvent(float bInputType, float nPrimary, float nSecondary)
405 mv_mousepos_x = nPrimary;
406 mv_mousepos_y = nSecondary;
413 if ('0' <= nPrimary && nPrimary <= '9')
415 imp = nPrimary - '0';
416 if (imp == 0) imp = 10;
417 localcmd(strcat("\nimpulse ", ftos(imp), "\n"));
422 case K_KP_1: localcmd("\nimpulse 1\n"); return true;
423 case K_KP_2: localcmd("\nimpulse 2\n"); return true;
424 case K_KP_3: localcmd("\nimpulse 3\n"); return true;
425 case K_KP_4: localcmd("\nimpulse 4\n"); return true;
426 case K_KP_5: localcmd("\nimpulse 5\n"); return true;
427 case K_KP_6: localcmd("\nimpulse 6\n"); return true;
428 case K_KP_7: localcmd("\nimpulse 7\n"); return true;
429 case K_KP_8: localcmd("\nimpulse 8\n"); return true;
430 case K_KP_9: localcmd("\nimpulse 9\n"); return true;
431 case K_KP_0: localcmd("\nimpulse 10\n"); return true;
434 if (nPrimary == K_MOUSE1)
435 if (mv_selection >= 0)
437 imp = min(mv_selection + 1, mv_num_maps);
438 localcmd(strcat("\nimpulse ", ftos(imp), "\n"));
445 void MapVote_UpdateMask()
450 oldmask = mv_maps_mask;
452 mv_maps_mask = ReadByte();
454 mv_maps_mask = ReadShort();
456 if(oldmask & mv_maps_mask != oldmask)
457 if(oldmask & mv_maps_mask == mv_maps_mask)
458 sound(world, CH_INFO, "misc_invshot.wav", VOL_BASE, ATTN_NONE);
460 // remove votes that no longer apply
461 for(i = 0, power = 1; i < mv_num_maps; ++i, power *= 2)
462 if not(mv_maps_mask & power)
468 void MapVote_UpdateVotes()
471 for(i = 0, power = 1; i < mv_num_maps; ++i, power *= 2)
473 if(mv_maps_mask & power)
476 mv_votes[i] = ReadByte();
484 mv_ownvote = ReadByte()-1;
497 MapVote_UpdateMask();
500 MapVote_UpdateVotes();
503 void Net_MapVote_Picture()
507 mv_preview[type] = true;
508 mv_pics[type] = strzone(ReadPicture());