3 string mv_maps[MAPVOTE_COUNT];
4 string mv_pics[MAPVOTE_COUNT];
5 string mv_pk3[MAPVOTE_COUNT];
6 float mv_preview[MAPVOTE_COUNT];
7 float mv_votes[MAPVOTE_COUNT];
8 float mv_avail[MAPVOTE_COUNT];
9 float mv_avail_start[MAPVOTE_COUNT];
21 float mv_mouse_selection;
22 float mv_selection_keyboard;
25 string mapvote_chosenmap;
27 vector gtv_text_size_small;
29 string MapVote_FormatMapItem(float id, string map, float count, float maxwidth, vector fontsize)
32 pre = sprintf("%d. ", id+1);
36 post = _(" (1 vote)");
37 else if(count >= 0 && mv_avail[id] == GTV_AVAILABLE)
38 post = sprintf(_(" (%d votes)"), count);
44 maxwidth -= stringwidth(pre, FALSE, fontsize) + stringwidth(post, FALSE, fontsize);
45 map = textShortenToWidth(map, maxwidth, fontsize, stringwidth_nocolors);
46 return strcat(pre, map, post);
49 string GameTypeVote_DescriptionByID(float id)
51 return MapInfo_Type_Description(MapInfo_Type_FromString(mv_maps[id]));
54 vector MapVote_RGB(float id)
56 if(mv_avail[id] != GTV_AVAILABLE)
60 else if (id == mv_selection)
66 void GameTypeVote_DrawGameTypeItem(vector pos, float maxh, float tsize, string gtype, string pic, float count, float id)
69 float desc_padding = gtv_text_size_x * 3;
70 float rect_margin = hud_fontsize_y / 2;
71 vector rect_pos = pos - '0.5 0.5 0' * rect_margin;
72 vector rect_size = '1 1 0';
73 rect_size_x = tsize + rect_margin;
74 rect_size_y = maxh + rect_margin;
75 vector rgb = MapVote_RGB(id);
79 if(mv_avail_start[id] != GTV_AVAILABLE)
81 else if ( mv_avail[id] != GTV_AVAILABLE && mv_top2_alpha)
82 alpha = mv_top2_alpha;
86 if(id == mv_selection && mv_avail[id] == GTV_AVAILABLE)
88 drawfill(rect_pos, rect_size, '1 1 1', 0.1, DRAWFLAG_NORMAL);
92 drawfill(rect_pos, rect_size, rgb, 0.1*alpha, DRAWFLAG_NORMAL);
93 drawborderlines(autocvar_scoreboard_border_thickness, rect_pos, rect_size, rgb, alpha, DRAWFLAG_NORMAL);
98 title.message = MapVote_FormatMapItem(id, MapInfo_Type_ToText(MapInfo_Type_FromString(gtype)),
99 count, tsize, gtv_text_size);
100 title.origin = pos-offset;
102 pos_y += gtv_text_size_small_y;
103 pos_y += gtv_text_size_y/2;
105 maxh -= gtv_text_size_y;
107 entity picent = spawn();
108 picent.origin = pos-offset;
109 picent.maxs = '1 1 0 ' * min(maxh, desc_padding) * 0.8;
111 pos_x += desc_padding;
112 tsize -= desc_padding;
114 string thelabel = GameTypeVote_DescriptionByID(id), ts;
119 float i,n = tokenizebyseparator(thelabel, "\n");
120 for(i = 0; i < n && maxh > (nlines+1)*gtv_text_size_small_y; ++i)
122 getWrappedLine_remaining = argv(i);
123 while(getWrappedLine_remaining && maxh > (nlines+1)*gtv_text_size_small_y)
125 ts = getWrappedLine(tsize, gtv_text_size_small, stringwidth_colors);
130 next.origin = pos-offset;
133 pos_y += gtv_text_size_small_y;
140 maxh -= max(nlines*gtv_text_size_small_y,picent.maxs_y);
143 drawstring(title.origin+offset, title.message, gtv_text_size, rgb, alpha, DRAWFLAG_NORMAL);
146 drawpic(picent.origin+offset, pic, picent.maxs, '1 1 1', alpha, DRAWFLAG_NORMAL);
148 for ( last = title.chain; last ; )
150 drawstring(last.origin+offset, last.message, gtv_text_size_small, '1 1 1', alpha, DRAWFLAG_NORMAL);
160 void MapVote_DrawMapItem(vector pos, float isize, float tsize, string map, string pic, float count, float id)
162 vector img_size = '0 0 0';
167 isize -= hud_fontsize_y; // respect the text when calculating the image size
169 rgb = MapVote_RGB(id);
172 img_size_x = isize / 0.75; // 4:3 x can be stretched easily, height is defined in isize
174 pos_y = pos_y + img_size_y;
176 label = MapVote_FormatMapItem(id, map, count, tsize, hud_fontsize);
178 text_size = stringwidth(label, false, hud_fontsize);
181 if (mv_avail[id] != GTV_AVAILABLE && mv_top2_alpha)
182 theAlpha = mv_top2_alpha;
186 pos_x -= text_size*0.5;
187 drawstring(pos, label, hud_fontsize, rgb, theAlpha, DRAWFLAG_NORMAL);
189 pos_x = pos_x + text_size*0.5 - img_size_x*0.5;
190 pos_y = pos_y - img_size_y;
192 pos += autocvar_scoreboard_border_thickness * '1 1 0';
193 img_size -= (autocvar_scoreboard_border_thickness * 2) * '1 1 0';
196 drawfill(pos, img_size, '.5 .5 .5', .7 * theAlpha, DRAWFLAG_NORMAL);
200 if(drawgetimagesize(pic) == '0 0 0')
201 drawpic(pos, draw_UseSkinFor("nopreview_map"), img_size, '1 1 1', theAlpha, DRAWFLAG_NORMAL);
203 drawpic(pos, pic, img_size, '1 1 1', theAlpha, DRAWFLAG_NORMAL);
207 drawborderlines(autocvar_scoreboard_border_thickness, pos, img_size, rgb, theAlpha, DRAWFLAG_NORMAL);
209 drawborderlines(autocvar_scoreboard_border_thickness, pos, img_size, '0 0 0', theAlpha, DRAWFLAG_NORMAL);
211 if(id == mv_selection && mv_avail[id] == GTV_AVAILABLE)
212 drawfill(pos, img_size, '1 1 1', 0.1, DRAWFLAG_NORMAL);
215 void MapVote_DrawAbstain(vector pos, float isize, float tsize, float count, float id)
221 rgb = MapVote_RGB(id);
223 pos_y = pos_y + hud_fontsize_y;
225 label = MapVote_FormatMapItem(id, _("Don't care"), count, tsize, hud_fontsize);
227 text_size = stringwidth(label, false, hud_fontsize);
229 pos_x -= text_size*0.5;
230 drawstring(pos, label, hud_fontsize, rgb, 1, DRAWFLAG_NORMAL);
233 vector MapVote_GridVec(vector gridspec, float i, float m)
238 '1 0 0' * (gridspec_x * r)
240 '0 1 0' * (gridspec_y * (i - r) / m);
243 float MapVote_Selection(vector topleft, vector cellsize, float rows, float columns)
248 mv_mouse_selection = -1;
250 for (r = 0; r < rows; ++r)
251 for (c = 0; c < columns; ++c)
253 if (mv_mousepos_x >= topleft_x + cellsize_x * c &&
254 mv_mousepos_x <= topleft_x + cellsize_x * (c + 1) &&
255 mv_mousepos_y >= topleft_y + cellsize_y * r &&
256 mv_mousepos_y <= topleft_y + cellsize_y * (r + 1))
258 mv_mouse_selection = r * columns + c;
263 if (mv_mouse_selection >= mv_num_maps)
264 mv_mouse_selection = -1;
266 if (mv_abstain && mv_mouse_selection < 0)
267 mv_mouse_selection = mv_num_maps;
269 if ( mv_selection_keyboard )
272 return mv_mouse_selection;
284 vector dist = '0 0 0';
289 if (!autocvar_hud_cursormode)
291 vector mpos = mv_mousepos + getmousepos();
292 mpos_x = bound(0, mpos_x, vid_conwidth);
293 mpos_y = bound(0, mpos_y, vid_conheight);
295 if ( mpos_x != mv_mousepos_x || mpos_y != mv_mousepos_y )
296 mv_selection_keyboard = 0;
301 center = (vid_conwidth - 1)/2;
302 xmin = vid_conwidth*0.05; // 5% border must suffice
303 xmax = vid_conwidth - xmin;
305 i = autocvar_con_chatpos; //*autocvar_con_chatsize;
307 ymax = vid_conheight + (i - autocvar_con_chat) * autocvar_con_chatsize;
308 if(i >= 0 || ymax < (vid_conheight*0.5))
309 ymax = vid_conheight - ymin;
311 hud_fontsize = HUD_GetFontsize("hud_fontsize");
316 draw_beginBoldFont();
317 map = ((gametypevote) ? _("Decide the gametype") : _("Vote for a map"));
318 pos_x = center - stringwidth(map, false, '12 0 0');
319 drawstring(pos, map, '24 24 0', '1 1 1', 1, DRAWFLAG_NORMAL);
322 if( mapvote_chosenmap != "" )
324 pos_x = center - stringwidth(mapvote_chosenmap, false, hud_fontsize*1.5/2);
325 drawstring(pos, mapvote_chosenmap, hud_fontsize*1.5, '1 1 1', 1, DRAWFLAG_NORMAL);
326 pos_y += hud_fontsize_y*2;
329 i = ceil(max(0, mv_timeout - time));
330 map = sprintf(_("%d seconds left"), i);
331 pos_x = center - stringwidth(map, false, '8 0 0');
332 drawstring(pos, map, '16 16 0', '0 1 0', 1, DRAWFLAG_NORMAL);
337 // base for multi-column stuff...
342 rows = ceil(mv_num_maps / mv_columns);
344 dist_x = (xmax - xmin) / mv_columns;
345 dist_y = (ymax - pos_y) / rows;
349 tsize = dist_x - hud_fontsize_y;
351 float maxheight = (ymax - pos_y) / 3;
352 if ( isize > maxheight )
354 pos_x += (isize - maxheight)/2;
358 dist_y += hud_fontsize_y;
359 pos_x = ( vid_conwidth - dist_x * mv_columns ) / 2;
364 isize = min(dist_y - 10, 0.75 * tsize);
367 mv_selection = MapVote_Selection(pos, dist, rows, mv_columns);
371 pos_y += (dist_y - isize) / 2;
375 mv_top2_alpha = max(0.2, 1 - (time - mv_top2_time)*(time - mv_top2_time));
377 void (vector, float, float, string, string, float, float) DrawItem;
380 DrawItem = GameTypeVote_DrawGameTypeItem;
382 DrawItem = MapVote_DrawMapItem;
384 for(i = 0; i < mv_num_maps; ++i)
386 tmp = mv_votes[i]; // FTEQCC bug: too many array accesses in the function call screw it up
389 DrawItem(pos + MapVote_GridVec(dist, i, mv_columns), isize, tsize, map, mv_pics[i], tmp, i);
391 DrawItem(pos + MapVote_GridVec(dist, i, mv_columns), isize, tsize, map, "", tmp, i);
397 if(mv_abstain && i < mv_num_maps) {
399 pos_y = ymax + isize - hud_fontsize_y;
400 pos_x = (xmax+xmin)*0.5;
401 MapVote_DrawAbstain(pos, isize, xmax - xmin, tmp, i);
404 drawpic(mv_mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), '32 32 0', '1 1 1', 1 - autocvar__menu_alpha, DRAWFLAG_NORMAL);
407 void Cmd_MapVote_MapDownload(float argc)
412 if(argc != 2 || !mv_pk3list)
414 print(_("mv_mapdownload: ^3You're not supposed to use this command on your own!\n"));
419 for(pak = mv_pk3list; pak; pak = pak.chain)
420 if(pak.sv_entnum == id)
423 if(!pak || pak.sv_entnum != id) {
424 print(_("^1Error:^7 Couldn't find pak index.\n"));
428 if(PreviewExists(pak.message))
430 mv_preview[id] = true;
433 print(_("Requesting preview...\n"));
434 localcmd(strcat("\ncmd mv_getpicture ", ftos(id), "\n"));
438 void MapVote_CheckPK3(string pic, string pk3, float id)
446 pak.chain = mv_pk3list;
451 localcmd(strcat("\ncurl --pak ", pk3, "; wait; cl_cmd mv_download ", ftos(id), "\n"));
455 Cmd_MapVote_MapDownload(tokenize_console(strcat("mv_download ", ftos(id))));
459 void MapVote_CheckPic(string pic, string pk3, float id)
461 // never try to retrieve a pic for the "don't care" 'map'
462 if(mv_abstain && id == mv_num_maps - 1)
465 if(PreviewExists(pic))
467 mv_preview[id] = true;
470 MapVote_CheckPK3(pic, pk3, id);
473 void MapVote_ReadMask()
476 if ( mv_num_maps < 24 )
481 else if(mv_num_maps < 16)
486 for(i = 0, power = 1; i < mv_num_maps; ++i, power *= 2)
487 mv_avail[i] = (mask & power) ? GTV_AVAILABLE : GTV_FORBIDDEN;
491 for(i = 0; i < mv_num_maps; ++i )
492 mv_avail[i] = ReadByte();
497 string ssdirs[NUM_SSDIRS];
504 precache_sound ("misc/invshot.wav");
507 if(autocvar_hud_cursormode) { setcursormode(1); }
508 else { mv_mousepos = '0.5 0 0' * vid_conwidth + '0 0.5 0' * vid_conheight; }
510 mv_selection_keyboard = 0;
512 for(n_ssdirs = 0; ; ++n_ssdirs)
517 if(n_ssdirs < NUM_SSDIRS)
518 ssdirs[n_ssdirs] = s;
520 n_ssdirs = min(n_ssdirs, NUM_SSDIRS);
522 mv_num_maps = min(MAPVOTE_COUNT, ReadByte());
523 mv_abstain = ReadByte();
525 mv_abstain = 1; // must be 1 for bool-true, makes stuff easier
526 mv_detail = ReadByte();
529 mv_timeout = ReadCoord();
531 gametypevote = ReadByte();
533 float mv_real_num_maps = mv_num_maps - mv_abstain;
537 mapvote_chosenmap = strzone(ReadString());
538 if ( gametypevote == 2 )
541 gtv_text_size = hud_fontsize*1.4;
542 gtv_text_size_small = hud_fontsize*1.1;
544 if (mv_real_num_maps > 8 )
547 mv_columns = min(2, mv_real_num_maps);
551 if (mv_real_num_maps > 16)
553 else if (mv_real_num_maps > 9)
555 else if(mv_real_num_maps > 3)
558 mv_columns = mv_real_num_maps;
562 for(i = 0; i < mv_num_maps; ++i )
563 mv_avail_start[i] = mv_avail[i];
565 // Assume mv_pk3list is world, there should only be 1 mapvote per round
566 mv_pk3list = world; // I'm still paranoid!
568 for(i = 0; i < mv_num_maps; ++i)
572 map = strzone(ReadString());
573 pk3 = strzone(ReadString());
574 j = bound(0, ReadByte(), n_ssdirs - 1);
578 mv_avail[i] = ReadByte();
582 //map = strzone(strcat("gfx/menu/default/gametype_", map));
583 //map = strzone(sprintf("gfx/menu/%s/gametype_%s", autocvar_menu_skin, map));
584 string mv_picpath = sprintf("gfx/menu/%s/gametype_%s", autocvar_menu_skin, map);
585 if(precache_pic(mv_picpath) == "")
586 mv_picpath = strcat("gfx/menu/default/gametype_", map);
587 map = strzone(mv_picpath);
589 mv_preview[i] = PreviewExists(map);
593 map = strzone(strcat(ssdirs[j], "/", map));
595 mv_preview[i] = false;
596 MapVote_CheckPic(map, pk3, i);
600 for(i = 0; i < n_ssdirs; ++i)
601 ssdirs[n_ssdirs] = string_null;
605 void MapVote_SendChoice(float index)
607 localcmd(strcat("\nimpulse ", ftos(index+1), "\n"));
610 float MapVote_MoveLeft(float pos)
614 imp = mv_num_maps - 1;
616 imp = pos < 1 ? mv_num_maps - 1 : pos - 1;
617 if ( mv_avail[imp] != GTV_AVAILABLE && imp != mv_ownvote )
618 imp = MapVote_MoveLeft(imp);
621 float MapVote_MoveRight(float pos)
627 imp = pos >= mv_num_maps - 1 ? 0 : pos + 1;
628 if ( mv_avail[imp] != GTV_AVAILABLE && imp != mv_ownvote )
629 imp = MapVote_MoveRight(imp);
632 float MapVote_MoveUp(float pos)
636 imp = mv_num_maps - 1;
639 imp = pos - mv_columns;
642 imp = floor(mv_num_maps/mv_columns)*mv_columns + pos % mv_columns;
643 if ( imp >= mv_num_maps )
647 if ( mv_avail[imp] != GTV_AVAILABLE && imp != mv_ownvote )
648 imp = MapVote_MoveUp(imp);
651 float MapVote_MoveDown(float pos)
658 imp = pos + mv_columns;
659 if ( imp >= mv_num_maps )
660 imp = imp % mv_columns;
662 if ( mv_avail[imp] != GTV_AVAILABLE && imp != mv_ownvote )
663 imp = MapVote_MoveDown(imp);
667 float MapVote_InputEvent(float bInputType, float nPrimary, float nSecondary)
676 mv_mousepos_x = nPrimary;
677 mv_mousepos_y = nSecondary;
678 mv_selection_keyboard = 0;
685 if ('0' <= nPrimary && nPrimary <= '9')
687 imp = nPrimary - '0';
688 if (imp == 0) imp = 10;
689 localcmd(strcat("\nimpulse ", ftos(imp), "\n"));
694 case K_KP_1: localcmd("\nimpulse 1\n"); return true;
695 case K_KP_2: localcmd("\nimpulse 2\n"); return true;
696 case K_KP_3: localcmd("\nimpulse 3\n"); return true;
697 case K_KP_4: localcmd("\nimpulse 4\n"); return true;
698 case K_KP_5: localcmd("\nimpulse 5\n"); return true;
699 case K_KP_6: localcmd("\nimpulse 6\n"); return true;
700 case K_KP_7: localcmd("\nimpulse 7\n"); return true;
701 case K_KP_8: localcmd("\nimpulse 8\n"); return true;
702 case K_KP_9: localcmd("\nimpulse 9\n"); return true;
703 case K_KP_0: localcmd("\nimpulse 10\n"); return true;
706 mv_selection_keyboard = 1;
707 mv_selection = MapVote_MoveRight(mv_selection);
710 mv_selection_keyboard = 1;
711 mv_selection = MapVote_MoveLeft(mv_selection);
714 mv_selection_keyboard = 1;
715 mv_selection = MapVote_MoveDown(mv_selection);
718 mv_selection_keyboard = 1;
719 mv_selection = MapVote_MoveUp(mv_selection);
724 if ( mv_selection_keyboard )
725 MapVote_SendChoice(mv_selection);
729 if (nPrimary == K_MOUSE1)
731 mv_selection_keyboard = 0;
732 mv_selection = mv_mouse_selection;
733 if (mv_selection >= 0)
735 imp = min(mv_selection + 1, mv_num_maps);
736 localcmd(strcat("\nimpulse ", ftos(imp), "\n"));
744 void MapVote_UpdateMask()
750 void MapVote_UpdateVotes()
753 for(i = 0; i < mv_num_maps; ++i)
755 if(mv_avail[i] == GTV_AVAILABLE)
758 mv_votes[i] = ReadByte();
766 mv_ownvote = ReadByte()-1;
779 MapVote_UpdateMask();
782 MapVote_UpdateVotes();
785 void Net_MapVote_Picture()
789 mv_preview[type] = true;
790 mv_pics[type] = strzone(ReadPicture());