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];
19 string MapVote_FormatMapItem(float id, string map, float count, float maxwidth, vector fontsize)
22 pre = strcat(ftos(id+1), ". ");
26 post = strcat(" (1 vote)");
28 post = strcat(" (", ftos(count), " votes)");
32 maxwidth -= stringwidth(pre, FALSE, fontsize) + stringwidth(post, FALSE, fontsize);
33 map = textShortenToWidth(map, maxwidth, fontsize, stringwidth_nocolors);
34 return strcat(pre, map, post);
37 vector MapVote_RGB(float id)
41 else if (id == mv_selection)
47 void MapVote_DrawMapItem(vector pos, float isize, float tsize, string map, string pic, float count, float id)
54 isize -= hud_fontsize_y; // respect the text when calculating the image size
56 rgb = MapVote_RGB(id);
59 img_size_x = isize / 0.75; // 4:3 x can be stretched easily, height is defined in isize
62 pos_y = pos_y + img_size_y;
64 label = MapVote_FormatMapItem(id, map, count, tsize, hud_fontsize);
66 text_size = stringwidth(label, false, hud_fontsize);
68 pos_x -= text_size*0.5;
69 drawstring(pos, label, hud_fontsize, rgb, 1, DRAWFLAG_NORMAL);
71 pos_x = pos_x + text_size*0.5 - img_size_x*0.5;
72 pos_y = pos_y - img_size_y;
74 pos += autocvar_scoreboard_border_thickness * '1 1 0';
75 img_size -= (autocvar_scoreboard_border_thickness * 2) * '1 1 0';
78 drawfill(pos, img_size, '.5 .5 .5', .7, DRAWFLAG_NORMAL);
82 drawpic(pos, pic, img_size, '1 1 1', 1, DRAWFLAG_NORMAL);
86 drawborderlines(autocvar_scoreboard_border_thickness, pos, img_size, rgb, 1, DRAWFLAG_NORMAL);
88 drawborderlines(autocvar_scoreboard_border_thickness, pos, img_size, '0 0 0', 1, DRAWFLAG_NORMAL);
90 if(id == mv_selection)
91 drawfill(pos, img_size, '1 1 1', 0.1, DRAWFLAG_NORMAL);
94 void MapVote_DrawAbstain(vector pos, float isize, float tsize, float count, float id)
100 rgb = MapVote_RGB(id);
103 pos_y = pos_y + hud_fontsize_y;
105 label = MapVote_FormatMapItem(id, "Don't care", count, tsize, hud_fontsize);
107 text_size = stringwidth(label, false, hud_fontsize);
109 pos_x -= text_size*0.5;
110 drawstring(pos, label, hud_fontsize, rgb, 1, DRAWFLAG_NORMAL);
113 vector MapVote_GridVec(vector gridspec, float i, float m)
118 '1 0 0' * (gridspec_x * r)
120 '0 1 0' * (gridspec_y * (i - r) / m);
123 float MapVote_Selection(vector topleft, vector cellsize, float rows, float columns)
130 for (r = 0; r < rows; ++r)
131 for (c = 0; c < columns; ++c)
133 if (mv_mousepos_x >= topleft_x + cellsize_x * c &&
134 mv_mousepos_x <= topleft_x + cellsize_x * (c + 1) &&
135 mv_mousepos_y >= topleft_y + cellsize_y * r &&
136 mv_mousepos_y <= topleft_y + cellsize_y * (r + 1))
138 cell = r * columns + c;
143 if (cell >= mv_num_maps)
146 if (mv_abstain && cell < 0)
166 mv_mousepos = mv_mousepos + getmousepos();
168 mv_mousepos_x = bound(0, mv_mousepos_x, vid_conwidth);
169 mv_mousepos_y = bound(0, mv_mousepos_y, vid_conheight);
171 center = (vid_conwidth - 1)/2;
172 xmin = vid_conwidth*0.05; // 5% border must suffice
173 xmax = vid_conwidth - xmin;
175 i = cvar("con_chatpos"); //*cvar("con_chatsize");
177 ymax = vid_conheight + (i - cvar("con_chat")) * cvar("con_chatsize");
178 if(i >= 0 || ymax < (vid_conheight*0.5))
179 ymax = vid_conheight - ymin;
181 drawfont = hud_bigfont;
182 hud_fontsize = HUD_GetFontsize("hud_fontsize");
186 //pos_x = center - stringwidth("Vote for a map", false) * 0.5 * 24;
187 pos_x = center - stringwidth("Vote for a map", false, '12 0 0');
188 drawstring(pos, "Vote for a map", '24 24 0', '1 1 1', 1, DRAWFLAG_NORMAL);
191 i = ceil(max(0, mv_timeout - time));
192 map = strcat(ftos(i), " seconds left");
193 //pos_x = center - stringwidth(map, false) * 0.5 * 16;
194 pos_x = center - stringwidth(map, false, '8 0 0');
195 drawstring(pos, map, '16 16 0', '0 1 0', 1, DRAWFLAG_NORMAL);
201 // base for multi-column stuff...
210 columns = mv_num_maps;
212 rows = ceil(mv_num_maps / columns);
214 dist_x = (xmax - xmin) / columns;
215 dist_y = (ymax - pos_y) / rows;
217 isize = min(dist_y - 10, 0.75 * tsize);
219 mv_selection = MapVote_Selection(pos, dist, rows, columns);
221 pos_x += (xmax - xmin) / (2 * columns);
222 pos_y += (dist_y - isize) / 2;
225 for(i = 0; i < mv_num_maps; ++i)
227 tmp = mv_votes[i]; // FTEQCC bug: too many array accesses in the function call screw it up
232 MapVote_DrawMapItem(pos + MapVote_GridVec(dist, i, columns), isize, tsize, map, mv_pics[i], tmp, i);
234 MapVote_DrawMapItem(pos + MapVote_GridVec(dist, i, columns), isize, tsize, map, "", tmp, i);
240 if(mv_abstain && i < mv_num_maps) {
242 pos_y = ymax + isize - hud_fontsize_y;
243 pos_x = (xmax+xmin)*0.5;
244 MapVote_DrawAbstain(pos, isize, xmax - xmin, tmp, i);
247 drawpic(mv_mousepos, strcat("gfx/menu/", cvar_string("menu_skin"), "/cursor.tga"), '32 32 0', '1 1 1', autocvar_hud_panel_fg_alpha, DRAWFLAG_NORMAL);
250 void Cmd_MapVote_MapDownload(float argc)
255 if(argc != 2 || !mv_pk3list)
257 print("mv_mapdownload: ^3You're not supposed to use this command on your own!\n");
262 for(pak = mv_pk3list; pak; pak = pak.chain)
263 if(pak.sv_entnum == id)
266 if(!pak || pak.sv_entnum != id) {
267 print("^1Error:^7 Couldn't find pak index.\n");
271 //print(strcat("^3Adding: ", ftos(id), " - ", pak.message, " - "));
273 if(PreviewExists(pak.message))
275 mv_preview[id] = true;
276 //print("^2Found...\n");
279 print("Requesting preview...\n");
280 localcmd(strcat("\ncmd mv_getpic ", ftos(id), "\n"));
284 void MapVote_CheckPK3(string pic, string pk3, float id)
292 pak.chain = mv_pk3list;
297 localcmd(strcat("\ncurl --pak ", pk3, "; wait; cl_cmd mv_download ", ftos(id), "\n"));
301 Cmd_MapVote_MapDownload(tokenize_console(strcat("mv_download ", ftos(id))));
305 void MapVote_CheckPic(string pic, string pk3, float id)
307 // never try to retrieve a pic for the "don't care" 'map'
308 if(mv_abstain && id == mv_num_maps - 1)
311 if(PreviewExists(pic))
313 mv_preview[id] = true;
316 MapVote_CheckPK3(pic, pk3, id);
320 string ssdirs[NUM_SSDIRS];
327 precache_sound ("misc/invshot.wav");
331 mv_mousepos = '0.5 0 0' * vid_conwidth + '0 0.5 0' * vid_conheight;
334 for(n_ssdirs = 0; ; ++n_ssdirs)
339 if(n_ssdirs < NUM_SSDIRS)
340 ssdirs[n_ssdirs] = s;
342 n_ssdirs = min(n_ssdirs, NUM_SSDIRS);
344 mv_num_maps = min(MAPVOTE_COUNT, ReadByte());
345 mv_abstain = ReadByte();
347 mv_abstain = 1; // must be 1 for bool-true, makes stuff easier
348 mv_detail = ReadByte();
351 mv_timeout = ReadCoord();
354 mv_maps_mask = ReadByte();
356 mv_maps_mask = ReadShort();
358 // Assume mv_pk3list is NULL, there should only be 1 mapvote per round
359 mv_pk3list = NULL; // I'm still paranoid!
361 for(i = 0, power = 1; i < mv_num_maps; ++i, power *= 2)
365 if(mv_maps_mask & power)
367 map = strzone(ReadString());
368 pk3 = strzone(ReadString());
369 j = bound(0, ReadByte(), n_ssdirs - 1);
373 map = strzone(strcat(ssdirs[j], "/", map));
376 mv_preview[i] = false;
378 //print(strcat("RECV: ", map, " in ", pk3, "\n"));
379 MapVote_CheckPic(map, pk3, i);
383 mv_maps[i] = strzone("if-you-see-this-the-code-is-broken");
384 mv_pk3[i] = strzone("if-you-see-this-the-code-is-broken");
385 mv_pics[i] = strzone("if-you-see-this-the-code-is-broken");
386 mv_preview[i] = false;
390 for(i = 0; i < n_ssdirs; ++i)
391 ssdirs[n_ssdirs] = string_null;
395 float MapVote_InputEvent(float bInputType, float nPrimary, float nSecondary)
405 if ('0' <= nPrimary && nPrimary <= '9')
407 imp = nPrimary - '0';
408 if (imp == 0) imp = 10;
409 localcmd(strcat("\nimpulse ", ftos(imp), "\n"));
413 if (nPrimary == K_MOUSE1)
414 if (mv_selection >= 0)
416 imp = min(mv_selection + 1, mv_num_maps);
417 localcmd(strcat("\nimpulse ", ftos(imp), "\n"));
424 void MapVote_UpdateMask()
429 oldmask = mv_maps_mask;
431 mv_maps_mask = ReadByte();
433 mv_maps_mask = ReadShort();
435 if(oldmask & mv_maps_mask != oldmask)
436 if(oldmask & mv_maps_mask == mv_maps_mask)
437 sound(world, CHAN_AUTO, "misc_invshot.wav", VOL_BASE, ATTN_NONE);
439 // remove votes that no longer apply
440 for(i = 0, power = 1; i < mv_num_maps; ++i, power *= 2)
441 if not(mv_maps_mask & power)
445 void MapVote_UpdateVotes()
448 for(i = 0, power = 1; i < mv_num_maps; ++i, power *= 2)
450 if(mv_maps_mask & power)
453 mv_votes[i] = ReadByte();
461 mv_ownvote = ReadByte()-1;
474 MapVote_UpdateMask();
477 MapVote_UpdateVotes();
480 void Net_MapVote_Picture()
484 mv_preview[type] = true;
485 mv_pics[type] = strzone(ReadPicture());