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];
9 float mv_avail[MAPVOTE_COUNT];
10 float mv_avail_start[MAPVOTE_COUNT];
24 string mapvote_choosenmap;
26 vector gtv_text_size_small;
28 string MapVote_FormatMapItem(float id, string map, float count, float maxwidth, vector fontsize)
31 pre = sprintf("%d. ", id+1);
35 post = _(" (1 vote)");
36 else if(count >= 0 && mv_avail[id] == GTV_AVAILABLE)
37 post = sprintf(_(" (%d votes)"), count);
43 maxwidth -= stringwidth(pre, FALSE, fontsize) + stringwidth(post, FALSE, fontsize);
44 map = textShortenToWidth(map, maxwidth, fontsize, stringwidth_nocolors);
45 return strcat(pre, map, post);
48 string GameTypeVote_DescriptionByID(float id)
50 return MapInfo_Type_Description(MapInfo_Type_FromString(mv_maps[id]));
53 vector MapVote_RGB(float id)
55 if(mv_avail[id] != GTV_AVAILABLE)
59 else if (id == mv_selection)
65 void GameTypeVote_DrawGameTypeItem(vector pos, float maxh, float tsize, string gtype, string pic, float count, float id)
68 float desc_padding = gtv_text_size_x * 3;
69 float rect_margin = hud_fontsize_y / 2;
70 vector rect_pos = pos - '0.5 0.5 0' * rect_margin;
71 vector rect_size = '1 1 0';
72 rect_size_x = tsize + rect_margin;
73 rect_size_y = maxh + rect_margin;
74 vector rgb = MapVote_RGB(id);
78 if(mv_avail_start[id] != GTV_AVAILABLE)
80 else if ( mv_avail[id] != GTV_AVAILABLE && mv_top2_alpha)
81 alpha = mv_top2_alpha;
85 if(id == mv_selection && mv_avail[id] == GTV_AVAILABLE)
87 drawfill(rect_pos, rect_size, '1 1 1', 0.1, DRAWFLAG_NORMAL);
91 drawfill(rect_pos, rect_size, rgb, 0.1*alpha, DRAWFLAG_NORMAL);
92 drawborderlines(autocvar_scoreboard_border_thickness, rect_pos, rect_size, rgb, alpha, DRAWFLAG_NORMAL);
97 title.message = MapVote_FormatMapItem(id, MapInfo_Type_ToText(MapInfo_Type_FromString(gtype)),
98 count, tsize, gtv_text_size);
99 title.origin = pos-offset;
101 pos_y += gtv_text_size_small_y;
102 pos_y += gtv_text_size_y/2;
104 maxh -= gtv_text_size_y;
106 entity picent = spawn();
107 picent.origin = pos-offset;
108 picent.maxs = '1 1 0 ' * min(maxh, desc_padding) * 0.8;
110 pos_x += desc_padding;
111 tsize -= desc_padding;
113 string thelabel = GameTypeVote_DescriptionByID(id), ts;
118 float i,n = tokenizebyseparator(thelabel, "\n");
119 for(i = 0; i < n && maxh > (nlines+1)*gtv_text_size_small_y; ++i)
121 getWrappedLine_remaining = argv(i);
122 while(getWrappedLine_remaining && maxh > (nlines+1)*gtv_text_size_small_y)
124 ts = getWrappedLine(tsize, gtv_text_size_small, stringwidth_colors);
129 next.origin = pos-offset;
132 pos_y += gtv_text_size_small_y;
139 maxh -= max(nlines*gtv_text_size_small_y,picent.maxs_y);
142 drawstring(title.origin+offset, title.message, gtv_text_size, rgb, alpha, DRAWFLAG_NORMAL);
145 drawpic(picent.origin+offset, pic, picent.maxs, '1 1 1', alpha, DRAWFLAG_NORMAL);
147 for ( last = title.chain; last ; )
149 drawstring(last.origin+offset, last.message, gtv_text_size_small, '1 1 1', alpha, DRAWFLAG_NORMAL);
159 void MapVote_DrawMapItem(vector pos, float isize, float tsize, string map, string pic, float count, float id)
161 vector img_size = '0 0 0';
166 isize -= hud_fontsize_y; // respect the text when calculating the image size
168 rgb = MapVote_RGB(id);
171 img_size_x = isize / 0.75; // 4:3 x can be stretched easily, height is defined in isize
173 pos_y = pos_y + img_size_y;
175 label = MapVote_FormatMapItem(id, map, count, tsize, hud_fontsize);
177 text_size = stringwidth(label, false, hud_fontsize);
180 if (mv_avail[id] != GTV_AVAILABLE && mv_top2_alpha)
181 theAlpha = mv_top2_alpha;
185 pos_x -= text_size*0.5;
186 drawstring(pos, label, hud_fontsize, rgb, theAlpha, DRAWFLAG_NORMAL);
188 pos_x = pos_x + text_size*0.5 - img_size_x*0.5;
189 pos_y = pos_y - img_size_y;
191 pos += autocvar_scoreboard_border_thickness * '1 1 0';
192 img_size -= (autocvar_scoreboard_border_thickness * 2) * '1 1 0';
195 drawfill(pos, img_size, '.5 .5 .5', .7 * theAlpha, DRAWFLAG_NORMAL);
199 if(drawgetimagesize(pic) == '0 0 0')
200 drawpic(pos, draw_UseSkinFor("nopreview_map"), img_size, '1 1 1', theAlpha, DRAWFLAG_NORMAL);
202 drawpic(pos, pic, img_size, '1 1 1', theAlpha, DRAWFLAG_NORMAL);
206 drawborderlines(autocvar_scoreboard_border_thickness, pos, img_size, rgb, theAlpha, DRAWFLAG_NORMAL);
208 drawborderlines(autocvar_scoreboard_border_thickness, pos, img_size, '0 0 0', theAlpha, DRAWFLAG_NORMAL);
210 if(id == mv_selection && mv_avail[id] == GTV_AVAILABLE)
211 drawfill(pos, img_size, '1 1 1', 0.1, DRAWFLAG_NORMAL);
214 void MapVote_DrawAbstain(vector pos, float isize, float tsize, float count, float id)
220 rgb = MapVote_RGB(id);
222 pos_y = pos_y + hud_fontsize_y;
224 label = MapVote_FormatMapItem(id, _("Don't care"), count, tsize, hud_fontsize);
226 text_size = stringwidth(label, false, hud_fontsize);
228 pos_x -= text_size*0.5;
229 drawstring(pos, label, hud_fontsize, rgb, 1, DRAWFLAG_NORMAL);
232 vector MapVote_GridVec(vector gridspec, float i, float m)
237 '1 0 0' * (gridspec_x * r)
239 '0 1 0' * (gridspec_y * (i - r) / m);
242 float MapVote_Selection(vector topleft, vector cellsize, float rows, float columns)
249 for (r = 0; r < rows; ++r)
250 for (c = 0; c < columns; ++c)
252 if (mv_mousepos_x >= topleft_x + cellsize_x * c &&
253 mv_mousepos_x <= topleft_x + cellsize_x * (c + 1) &&
254 mv_mousepos_y >= topleft_y + cellsize_y * r &&
255 mv_mousepos_y <= topleft_y + cellsize_y * (r + 1))
257 cell = r * columns + c;
262 if (cell >= mv_num_maps)
265 if (mv_abstain && cell < 0)
280 vector dist = '0 0 0';
285 if (!autocvar_hud_cursormode)
287 mv_mousepos = mv_mousepos + getmousepos();
289 mv_mousepos_x = bound(0, mv_mousepos_x, vid_conwidth);
290 mv_mousepos_y = bound(0, mv_mousepos_y, vid_conheight);
293 center = (vid_conwidth - 1)/2;
294 xmin = vid_conwidth*0.05; // 5% border must suffice
295 xmax = vid_conwidth - xmin;
297 i = autocvar_con_chatpos; //*autocvar_con_chatsize;
299 ymax = vid_conheight + (i - autocvar_con_chat) * autocvar_con_chatsize;
300 if(i >= 0 || ymax < (vid_conheight*0.5))
301 ymax = vid_conheight - ymin;
303 hud_fontsize = HUD_GetFontsize("hud_fontsize");
308 draw_beginBoldFont();
309 map = ((gametypevote) ? _("Decide the gametype") : _("Vote for a map"));
310 pos_x = center - stringwidth(map, false, '12 0 0');
311 drawstring(pos, map, '24 24 0', '1 1 1', 1, DRAWFLAG_NORMAL);
314 if(gametypevote && mapvote_choosenmap != "" )
316 pos_x = center - stringwidth(mapvote_choosenmap, false, hud_fontsize);
317 drawstring(pos, mapvote_choosenmap, hud_fontsize*2, '1 1 1', 1, DRAWFLAG_NORMAL);
318 pos_y += hud_fontsize_y*2;
321 i = ceil(max(0, mv_timeout - time));
322 map = sprintf(_("%d seconds left"), i);
323 pos_x = center - stringwidth(map, false, '8 0 0');
324 drawstring(pos, map, '16 16 0', '0 1 0', 1, DRAWFLAG_NORMAL);
329 // base for multi-column stuff...
334 rows = ceil(mv_num_maps / mv_columns);
336 dist_x = (xmax - xmin) / mv_columns;
337 dist_y = (ymax - pos_y) / rows;
341 tsize = dist_x - hud_fontsize_y;
343 float maxheight = (ymax - pos_y) / 3;
344 if ( isize > maxheight )
346 pos_x += (isize - maxheight)/2;
350 dist_y += hud_fontsize_y;
351 pos_x = ( vid_conwidth - dist_x * mv_columns ) / 2;
356 isize = min(dist_y - 10, 0.75 * tsize);
359 mv_selection = MapVote_Selection(pos, dist, rows, mv_columns);
363 pos_y += (dist_y - isize) / 2;
367 mv_top2_alpha = max(0.2, 1 - (time - mv_top2_time)*(time - mv_top2_time));
369 void (vector, float, float, string, string, float, float) DrawItem;
372 DrawItem = GameTypeVote_DrawGameTypeItem;
374 DrawItem = MapVote_DrawMapItem;
376 for(i = 0; i < mv_num_maps; ++i)
378 tmp = mv_votes[i]; // FTEQCC bug: too many array accesses in the function call screw it up
381 DrawItem(pos + MapVote_GridVec(dist, i, mv_columns), isize, tsize, map, mv_pics[i], tmp, i);
383 DrawItem(pos + MapVote_GridVec(dist, i, mv_columns), isize, tsize, map, "", tmp, i);
389 if(mv_abstain && i < mv_num_maps) {
391 pos_y = ymax + isize - hud_fontsize_y;
392 pos_x = (xmax+xmin)*0.5;
393 MapVote_DrawAbstain(pos, isize, xmax - xmin, tmp, i);
396 drawpic(mv_mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), '32 32 0', '1 1 1', 1 - autocvar__menu_alpha, DRAWFLAG_NORMAL);
399 void Cmd_MapVote_MapDownload(float argc)
404 if(argc != 2 || !mv_pk3list)
406 print(_("mv_mapdownload: ^3You're not supposed to use this command on your own!\n"));
411 for(pak = mv_pk3list; pak; pak = pak.chain)
412 if(pak.sv_entnum == id)
415 if(!pak || pak.sv_entnum != id) {
416 print(_("^1Error:^7 Couldn't find pak index.\n"));
420 if(PreviewExists(pak.message))
422 mv_preview[id] = true;
425 print(_("Requesting preview...\n"));
426 localcmd(strcat("\ncmd mv_getpicture ", ftos(id), "\n"));
430 void MapVote_CheckPK3(string pic, string pk3, float id)
438 pak.chain = mv_pk3list;
443 localcmd(strcat("\ncurl --pak ", pk3, "; wait; cl_cmd mv_download ", ftos(id), "\n"));
447 Cmd_MapVote_MapDownload(tokenize_console(strcat("mv_download ", ftos(id))));
451 void MapVote_CheckPic(string pic, string pk3, float id)
453 // never try to retrieve a pic for the "don't care" 'map'
454 if(mv_abstain && id == mv_num_maps - 1)
457 if(PreviewExists(pic))
459 mv_preview[id] = true;
462 MapVote_CheckPK3(pic, pk3, id);
465 void MapVote_ReadMask()
468 if ( mv_num_maps < 24 )
473 else if(mv_num_maps < 16)
478 for(i = 0, power = 1; i < mv_num_maps; ++i, power *= 2)
479 mv_avail[i] = (mask & power) ? GTV_AVAILABLE : GTV_FORBIDDEN;
483 for(i = 0; i < mv_num_maps; ++i )
484 mv_avail[i] = ReadByte();
489 string ssdirs[NUM_SSDIRS];
496 precache_sound ("misc/invshot.wav");
499 if(autocvar_hud_cursormode) { setcursormode(1); }
500 else { mv_mousepos = '0.5 0 0' * vid_conwidth + '0 0.5 0' * vid_conheight; }
503 for(n_ssdirs = 0; ; ++n_ssdirs)
508 if(n_ssdirs < NUM_SSDIRS)
509 ssdirs[n_ssdirs] = s;
511 n_ssdirs = min(n_ssdirs, NUM_SSDIRS);
513 mv_num_maps = min(MAPVOTE_COUNT, ReadByte());
514 mv_abstain = ReadByte();
516 mv_abstain = 1; // must be 1 for bool-true, makes stuff easier
517 mv_detail = ReadByte();
520 mv_timeout = ReadCoord();
522 gametypevote = ReadByte();
524 float mv_real_num_maps = mv_num_maps - mv_abstain;
528 // read map name in case we have nextmap set
529 mapvote_choosenmap = strzone(ReadString());
531 gtv_text_size = hud_fontsize*1.4;
532 gtv_text_size_small = hud_fontsize*1.1;
534 if (mv_real_num_maps > 8 )
537 mv_columns = min(2, mv_real_num_maps);
541 if (mv_real_num_maps > 16)
543 else if (mv_real_num_maps > 9)
545 else if(mv_real_num_maps > 3)
548 mv_columns = mv_real_num_maps;
552 for(i = 0; i < mv_num_maps; ++i )
553 mv_avail_start[i] = mv_avail[i];
555 // Assume mv_pk3list is world, there should only be 1 mapvote per round
556 mv_pk3list = world; // I'm still paranoid!
558 for(i = 0; i < mv_num_maps; ++i)
562 map = strzone(ReadString());
563 pk3 = strzone(ReadString());
564 j = bound(0, ReadByte(), n_ssdirs - 1);
568 mv_avail[i] = ReadByte();
572 //map = strzone(strcat("gfx/menu/default/gametype_", map));
573 //map = strzone(sprintf("gfx/menu/%s/gametype_%s", autocvar_menu_skin, map));
574 string mv_picpath = sprintf("gfx/menu/%s/gametype_%s", autocvar_menu_skin, map);
575 if(precache_pic(mv_picpath) == "")
576 mv_picpath = strcat("gfx/menu/default/gametype_", map);
577 map = strzone(mv_picpath);
579 mv_preview[i] = PreviewExists(map);
583 map = strzone(strcat(ssdirs[j], "/", map));
585 mv_preview[i] = false;
586 MapVote_CheckPic(map, pk3, i);
590 for(i = 0; i < n_ssdirs; ++i)
591 ssdirs[n_ssdirs] = string_null;
595 void MapVote_SendChoice(float index)
597 localcmd(strcat("\nimpulse ", ftos(index+1), "\n"));
600 float MapVote_MoveLeft(float pos)
604 imp = mv_num_maps - 1;
606 imp = pos < 1 ? mv_num_maps - 1 : pos - 1;
607 if ( mv_avail[imp] != GTV_AVAILABLE && imp != mv_ownvote )
608 imp = MapVote_MoveLeft(imp);
611 float MapVote_MoveRight(float pos)
617 imp = pos >= mv_num_maps - 1 ? 0 : pos + 1;
618 if ( mv_avail[imp] != GTV_AVAILABLE && imp != mv_ownvote )
619 imp = MapVote_MoveRight(imp);
622 float MapVote_MoveUp(float pos)
626 imp = mv_num_maps - 1;
629 imp = pos - mv_columns;
632 imp = floor(mv_num_maps/mv_columns)*mv_columns + pos % mv_columns;
633 if ( imp >= mv_num_maps )
637 if ( mv_avail[imp] != GTV_AVAILABLE && imp != mv_ownvote )
638 imp = MapVote_MoveUp(imp);
641 float MapVote_MoveDown(float pos)
648 imp = pos + mv_columns;
649 if ( imp >= mv_num_maps )
650 imp = imp % mv_columns;
652 if ( mv_avail[imp] != GTV_AVAILABLE && imp != mv_ownvote )
653 imp = MapVote_MoveDown(imp);
657 float MapVote_InputEvent(float bInputType, float nPrimary, float nSecondary)
666 mv_mousepos_x = nPrimary;
667 mv_mousepos_y = nSecondary;
674 if ('0' <= nPrimary && nPrimary <= '9')
676 imp = nPrimary - '0';
677 if (imp == 0) imp = 10;
678 localcmd(strcat("\nimpulse ", ftos(imp), "\n"));
683 case K_KP_1: localcmd("\nimpulse 1\n"); return true;
684 case K_KP_2: localcmd("\nimpulse 2\n"); return true;
685 case K_KP_3: localcmd("\nimpulse 3\n"); return true;
686 case K_KP_4: localcmd("\nimpulse 4\n"); return true;
687 case K_KP_5: localcmd("\nimpulse 5\n"); return true;
688 case K_KP_6: localcmd("\nimpulse 6\n"); return true;
689 case K_KP_7: localcmd("\nimpulse 7\n"); return true;
690 case K_KP_8: localcmd("\nimpulse 8\n"); return true;
691 case K_KP_9: localcmd("\nimpulse 9\n"); return true;
692 case K_KP_0: localcmd("\nimpulse 10\n"); return true;
695 MapVote_SendChoice(MapVote_MoveRight(mv_ownvote));
698 MapVote_SendChoice(MapVote_MoveLeft(mv_ownvote));
701 MapVote_SendChoice(MapVote_MoveDown(mv_ownvote));
704 MapVote_SendChoice(MapVote_MoveUp(mv_ownvote));
708 if (nPrimary == K_MOUSE1)
709 if (mv_selection >= 0)
711 imp = min(mv_selection + 1, mv_num_maps);
712 localcmd(strcat("\nimpulse ", ftos(imp), "\n"));
719 void MapVote_UpdateMask()
725 void MapVote_UpdateVotes()
728 for(i = 0; i < mv_num_maps; ++i)
730 if(mv_avail[i] == GTV_AVAILABLE)
733 mv_votes[i] = ReadByte();
741 mv_ownvote = ReadByte()-1;
754 MapVote_UpdateMask();
757 MapVote_UpdateVotes();
760 void Net_MapVote_Picture()
764 mv_preview[type] = true;
765 mv_pics[type] = strzone(ReadPicture());