4 string mv_maps[MAPVOTE_COUNT];
\r
5 string mv_pics[MAPVOTE_COUNT];
\r
6 string mv_pk3[MAPVOTE_COUNT];
\r
7 float mv_preview[MAPVOTE_COUNT];
\r
8 float mv_votes[MAPVOTE_COUNT];
\r
19 string MapVote_FormatMapItem(float id, string map, float count, float maxwidth, vector fontsize)
\r
22 pre = strcat(ftos(id+1), ". ");
\r
26 post = strcat(" (1 vote)");
\r
28 post = strcat(" (", ftos(count), " votes)");
\r
32 maxwidth -= stringwidth(pre, FALSE, fontsize) + stringwidth(post, FALSE, fontsize);
\r
33 map = textShortenToWidth(map, maxwidth, fontsize, stringwidth_nocolors);
\r
34 return strcat(pre, map, post);
\r
37 vector MapVote_RGB(float id)
\r
39 if(id == mv_ownvote)
\r
41 else if (id == mv_selection)
\r
47 void MapVote_DrawMapItem(vector pos, float isize, float tsize, string map, string pic, float count, float id)
\r
54 isize -= sbar_fontsize_y; // respect the text when calculating the image size
\r
56 rgb = MapVote_RGB(id);
\r
59 img_size_x = isize / 0.75; // 4:3 x can be stretched easily, height is defined in isize
\r
61 drawfont = sbar_font;
\r
62 pos_y = pos_y + img_size_y;
\r
64 label = MapVote_FormatMapItem(id, map, count, tsize, sbar_fontsize);
\r
66 text_size = stringwidth(label, false, sbar_fontsize);
\r
68 pos_x -= text_size*0.5;
\r
69 drawstring(pos, label, sbar_fontsize, rgb, 1, DRAWFLAG_NORMAL);
\r
71 pos_x = pos_x + text_size*0.5 - img_size_x*0.5;
\r
72 pos_y = pos_y - img_size_y;
\r
74 pos += sbar_border_thickness * '1 1 0';
\r
75 img_size -= (sbar_border_thickness * 2) * '1 1 0';
\r
78 if(drawgetimagesize(pic) == '0 0 0')
\r
79 drawpic(pos, draw_UseSkinFor("nopreview_map"), img_size, '1 1 1', 0.7, DRAWFLAG_NORMAL);
\r
81 drawpic(pos, pic, img_size, '1 1 1', 0.7, DRAWFLAG_NORMAL);
\r
85 drawpic(pos, pic, img_size, '1 1 1', 1, DRAWFLAG_NORMAL);
\r
88 drawstring(pos + '2 0 0', ftos(id+1), (img_size_y / 5) * '1 1 0', '1 1 1', 0.6, DRAWFLAG_NORMAL);
\r
90 if(id == mv_ownvote || pic == "")
\r
92 drawborderlines(sbar_border_thickness, pos, img_size, rgb, 1, DRAWFLAG_NORMAL);
\r
93 drawstring(pos + '2 0 0', ftos(id+1), (img_size_y / 5) * '1 1 0', rgb, 0.6, DRAWFLAG_NORMAL);
\r
97 drawborderlines(sbar_border_thickness, pos, img_size, '0 0 0', 1, DRAWFLAG_NORMAL);
\r
98 drawstring(pos + '2 0 0', ftos(id+1), (img_size_y / 5) * '1 1 0', '1 1 1', 0.6, DRAWFLAG_NORMAL);
\r
102 void MapVote_DrawAbstain(vector pos, float isize, float tsize, float count, float id)
\r
108 rgb = MapVote_RGB(id);
\r
110 drawfont = sbar_font;
\r
111 pos_y = pos_y + sbar_fontsize_y;
\r
113 label = MapVote_FormatMapItem(id, "Don't care", count, tsize, sbar_fontsize);
\r
115 text_size = stringwidth(label, false, sbar_fontsize);
\r
117 pos_x -= text_size*0.5;
\r
118 drawstring(pos, label, sbar_fontsize, rgb, 1, DRAWFLAG_NORMAL);
\r
121 vector MapVote_GridVec(vector gridspec, float i, float m)
\r
126 '1 0 0' * (gridspec_x * r)
\r
128 '0 1 0' * (gridspec_y * (i - r) / m);
\r
131 float MapVote_Selection(vector topleft, vector cellsize, float rows, float columns)
\r
138 for (r = 0; r < rows; ++r)
\r
139 for (c = 0; c < columns; ++c)
\r
141 if (mv_mousepos_x >= topleft_x + cellsize_x * c &&
\r
142 mv_mousepos_x <= topleft_x + cellsize_x * (c + 1) &&
\r
143 mv_mousepos_y >= topleft_y + cellsize_y * r &&
\r
144 mv_mousepos_y <= topleft_y + cellsize_y * (r + 1))
\r
146 cell = r * columns + c;
\r
151 if (cell >= mv_num_maps)
\r
154 if (mv_abstain && cell < 0)
\r
155 return mv_num_maps;
\r
160 void MapVote_Draw()
\r
167 float columns, rows;
\r
174 mv_mousepos = mv_mousepos + getmousepos();
\r
176 mv_mousepos_x = bound(0, mv_mousepos_x, vid_conwidth);
\r
177 mv_mousepos_y = bound(0, mv_mousepos_y, vid_conheight);
\r
179 center = (vid_conwidth - 1)/2;
\r
180 xmin = vid_conwidth*0.05; // 5% border must suffice
\r
181 xmax = vid_conwidth - xmin;
\r
183 i = cvar("con_chatpos"); //*cvar("con_chatsize");
\r
185 ymax = vid_conheight + (i - cvar("con_chat")) * cvar("con_chatsize");
\r
186 if(i >= 0 || ymax < (vid_conheight*0.5))
\r
187 ymax = vid_conheight - ymin;
\r
189 drawfont = sbar_bigfont;
\r
190 sbar_fontsize = Sbar_GetFontsize("sbar_fontsize");
\r
194 //pos_x = center - stringwidth("Vote for a map", false) * 0.5 * 24;
\r
195 pos_x = center - stringwidth("Vote for a map", false, '12 0 0');
\r
196 drawstring(pos, "Vote for a map", '24 24 0', '1 1 1', 1, DRAWFLAG_NORMAL);
\r
199 i = ceil(max(0, mv_timeout - time));
\r
200 map = strcat(ftos(i), " seconds left");
\r
201 //pos_x = center - stringwidth(map, false) * 0.5 * 16;
\r
202 pos_x = center - stringwidth(map, false, '8 0 0');
\r
203 drawstring(pos, map, '16 16 0', '0 1 0', 1, DRAWFLAG_NORMAL);
\r
207 drawfont = sbar_font;
\r
209 // base for multi-column stuff...
\r
214 if(mv_num_maps > 3)
\r
218 columns = mv_num_maps;
\r
220 rows = ceil(mv_num_maps / columns);
\r
222 dist_x = (xmax - xmin) / columns;
\r
223 dist_y = (ymax - pos_y) / rows;
\r
224 tsize = dist_x - 10;
\r
225 isize = min(dist_y - 10, 0.75 * tsize);
\r
227 mv_selection = MapVote_Selection(pos, dist, rows, columns);
\r
229 pos_x += (xmax - xmin) / (2 * columns);
\r
230 pos_y += (dist_y - isize) / 2;
\r
233 for(i = 0; i < mv_num_maps; ++i)
\r
235 tmp = mv_votes[i]; // FTEQCC bug: too many array accesses in the function call screw it up
\r
240 MapVote_DrawMapItem(pos + MapVote_GridVec(dist, i, columns), isize, tsize, map, mv_pics[i], tmp, i);
\r
242 MapVote_DrawMapItem(pos + MapVote_GridVec(dist, i, columns), isize, tsize, map, "", tmp, i);
\r
248 if(mv_abstain && i < mv_num_maps) {
\r
250 pos_y = ymax + isize - sbar_fontsize_y;
\r
251 pos_x = (xmax+xmin)*0.5;
\r
252 MapVote_DrawAbstain(pos, isize, xmax - xmin, tmp, i);
\r
255 drawpic(mv_mousepos, strcat("gfx/menu/", cvar_string("menu_skin"), "/cursor.tga"), '32 32 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL);
\r
258 void Cmd_MapVote_MapDownload(float argc)
\r
263 if(argc != 2 || !mv_pk3list)
\r
265 print("mv_mapdownload: ^3You're not supposed to use this command on your own!\n");
\r
269 id = stof(argv(1));
\r
270 for(pak = mv_pk3list; pak; pak = pak.chain)
\r
271 if(pak.sv_entnum == id)
\r
274 if(!pak || pak.sv_entnum != id) {
\r
275 print("^1Error:^7 Couldn't find pak index.\n");
\r
279 //print(strcat("^3Adding: ", ftos(id), " - ", pak.message, " - "));
\r
281 if(PreviewExists(pak.message))
\r
283 mv_preview[id] = true;
\r
284 //print("^2Found...\n");
\r
287 print("Requesting preview...\n");
\r
288 localcmd(strcat("\ncmd mv_getpic ", ftos(id), "\n"));
\r
292 void MapVote_CheckPK3(string pic, string pk3, float id)
\r
298 pak.sv_entnum = id;
\r
300 pak.chain = mv_pk3list;
\r
305 localcmd(strcat("\ncurl --pak ", pk3, "; wait; cl_cmd mv_download ", ftos(id), "\n"));
\r
309 Cmd_MapVote_MapDownload(tokenize_console(strcat("mv_download ", ftos(id))));
\r
313 void MapVote_CheckPic(string pic, string pk3, float id)
\r
315 // never try to retrieve a pic for the "don't care" 'map'
\r
316 if(mv_abstain && id == mv_num_maps - 1)
\r
319 if(PreviewExists(pic))
\r
321 mv_preview[id] = true;
\r
324 MapVote_CheckPK3(pic, pk3, id);
\r
327 #define NUM_SSDIRS 4
\r
328 string ssdirs[NUM_SSDIRS];
\r
330 void MapVote_Init()
\r
333 string map, pk3, s;
\r
335 precache_sound ("misc/invshot.wav");
\r
337 registercmd("+showscores");
\r
338 registercmd("-showscores");
\r
342 mv_mousepos = '0.5 0 0' * vid_conwidth + '0 0.5 0' * vid_conheight;
\r
345 for(n_ssdirs = 0; ; ++n_ssdirs)
\r
350 if(n_ssdirs < NUM_SSDIRS)
\r
351 ssdirs[n_ssdirs] = s;
\r
353 n_ssdirs = min(n_ssdirs, NUM_SSDIRS);
\r
355 mv_num_maps = min(MAPVOTE_COUNT, ReadByte());
\r
356 mv_abstain = ReadByte();
\r
358 mv_abstain = 1; // must be 1 for bool-true, makes stuff easier
\r
359 mv_detail = ReadByte();
\r
362 mv_timeout = ReadCoord();
\r
364 if(mv_num_maps <= 8)
\r
365 mv_maps_mask = ReadByte();
\r
367 mv_maps_mask = ReadShort();
\r
369 // Assume mv_pk3list is NULL, there should only be 1 mapvote per round
\r
370 mv_pk3list = NULL; // I'm still paranoid!
\r
372 for(i = 0, power = 1; i < mv_num_maps; ++i, power *= 2)
\r
376 if(mv_maps_mask & power)
\r
378 map = strzone(ReadString());
\r
379 pk3 = strzone(ReadString());
\r
380 j = bound(0, ReadByte(), n_ssdirs - 1);
\r
384 map = strzone(strcat(ssdirs[j], "/", map));
\r
387 mv_preview[i] = false;
\r
389 //print(strcat("RECV: ", map, " in ", pk3, "\n"));
\r
390 MapVote_CheckPic(map, pk3, i);
\r
394 mv_maps[i] = strzone("if-you-see-this-the-code-is-broken");
\r
395 mv_pk3[i] = strzone("if-you-see-this-the-code-is-broken");
\r
396 mv_pics[i] = strzone("if-you-see-this-the-code-is-broken");
\r
397 mv_preview[i] = false;
\r
401 for(i = 0; i < n_ssdirs; ++i)
\r
402 ssdirs[n_ssdirs] = string_null;
\r
406 float MapVote_InputEvent(float bInputType, float nPrimary, float nSecondary)
\r
413 if (bInputType != 0)
\r
416 if ('0' <= nPrimary && nPrimary <= '9')
\r
418 imp = nPrimary - '0';
\r
419 if (imp == 0) imp = 10;
\r
420 localcmd(strcat("\nimpulse ", ftos(imp), "\n"));
\r
424 if (nPrimary == K_MOUSE1)
\r
425 if (mv_selection >= 0)
\r
427 imp = min(mv_selection + 1, mv_num_maps);
\r
428 localcmd(strcat("\nimpulse ", ftos(imp), "\n"));
\r
435 void MapVote_UpdateMask()
\r
440 oldmask = mv_maps_mask;
\r
441 if(mv_num_maps <= 8)
\r
442 mv_maps_mask = ReadByte();
\r
444 mv_maps_mask = ReadShort();
\r
446 if(oldmask & mv_maps_mask != oldmask)
\r
447 if(oldmask & mv_maps_mask == mv_maps_mask)
\r
448 sound(world, CHAN_AUTO, "misc_invshot.wav", VOL_BASE, ATTN_NONE);
\r
450 // remove votes that no longer apply
\r
451 for(i = 0, power = 1; i < mv_num_maps; ++i, power *= 2)
\r
452 if not(mv_maps_mask & power)
\r
456 void MapVote_UpdateVotes()
\r
459 for(i = 0, power = 1; i < mv_num_maps; ++i, power *= 2)
\r
461 if(mv_maps_mask & power)
\r
464 mv_votes[i] = ReadByte();
\r
472 mv_ownvote = ReadByte()-1;
\r
485 MapVote_UpdateMask();
\r
488 MapVote_UpdateVotes();
\r
491 void Net_MapVote_Picture()
\r
495 mv_preview[type] = true;
\r
496 mv_pics[type] = strzone(ReadPicture());
\r