Xonotic
mapvoting.qh File Reference
+ Include dependency graph for mapvoting.qh:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void Cmd_MapVote_MapDownload (int argc)
 
void MapVote_Draw ()
 
float MapVote_InputEvent (float bInputType, float nPrimary, float nSecondary)
 
void Net_MapVote_Picture ()
 
bool PreviewExists (string name)
 

Variables

bool autocvar_cl_readpicture_force
 
float autocvar_hud_panel_mapvote_highlight_border = 1
 
string autocvar_menu_skin
 
float mv_active
 
float xmax
 
float xmin
 
float ymax
 
float ymin
 

Function Documentation

◆ Cmd_MapVote_MapDownload()

void Cmd_MapVote_MapDownload ( int  argc)

Definition at line 506 of file mapvoting.qc.

References entity(), LOG_INFO, mv_pk3list, and TC.

Referenced by LocalCommand_mv_download(), and MapVote_CheckPK3().

507 {
508  TC(int, argc);
509  entity pak;
510 
511  if(argc != 2 || !mv_pk3list)
512  {
513  LOG_INFO(_("mv_mapdownload: ^3You're not supposed to use this command on your own!"));
514  return;
515  }
516 
517  int id = stof(argv(1));
518  for(pak = mv_pk3list; pak; pak = pak.chain)
519  if(pak.sv_entnum == id)
520  break;
521 
522  if(!pak || pak.sv_entnum != id) {
523  LOG_INFO(_("^1Error:^7 Couldn't find pak index."));
524  return;
525  }
526 
527  if(PreviewExists(pak.message))
528  {
529  mv_preview[id] = true;
530  return;
531  } else {
532  LOG_INFO(_("Requesting preview..."));
533  localcmd(strcat("\ncmd mv_getpicture ", ftos(id), "\n"));
534  }
535 }
entity mv_pk3list
Definition: mapvoting.qc:27
entity() spawn
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
float mv_preview[MAPVOTE_COUNT]
Definition: mapvoting.qc:23
#define LOG_INFO(...)
Definition: log.qh:70
#define TC(T, sym)
Definition: _all.inc:82
bool PreviewExists(string name)
Definition: mapvoting.qc:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MapVote_Draw()

void MapVote_Draw ( )

Definition at line 343 of file mapvoting.qc.

References chat_posy, chat_sizey, draw_beginBoldFont, gametypevote, gtv_text_size, gtv_text_size_small, hud_fontsize, HUD_GetFontsize(), HUD_Panel_LoadCvars(), HUD_Scale_Disable(), mv_active, vector(), vid_conheight, vid_conwidth, xmax, xmin, ymax, and ymin.

344 {
345  string map;
346  int i;
347  float tmp;
348  vector pos;
349  float center;
350  float rows;
351  vector dist = '0 0 0';
352 
353  //if(intermission != 2) return;
354  if(!mv_active)
355  return;
356 
358 
359  center = (vid_conwidth - 1)/2;
360  xmin = vid_conwidth * 0.08;
361  xmax = vid_conwidth - xmin;
362  ymin = 20;
363  ymax = vid_conheight - ymin;
364 
365  if(chat_posy + chat_sizey / 2 < vid_conheight / 2)
366  ymin += chat_sizey;
367  else
368  ymax -= chat_sizey;
369 
370  hud_fontsize = HUD_GetFontsize("hud_fontsize");
371  if (gametypevote)
372  {
373  gtv_text_size = hud_fontsize * 1.4;
375  }
376 
377  pos.y = ymin;
378  pos.z = 0;
379 
382 
383  map = ((gametypevote) ? _("Decide the gametype") : _("Vote for a map"));
384  pos.x = center - stringwidth(map, false, hud_fontsize * 2) * 0.5;
385  drawstring(pos, map, hud_fontsize * 2, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
386  pos.y += hud_fontsize.y * 2;
387 
388  if( mapvote_chosenmap != "" )
389  {
390  pos.y += hud_fontsize.y * 0.25;
391  pos.x = center - stringwidth(mapvote_chosenmap, false, hud_fontsize * 1.5) * 0.5;
393  pos.y += hud_fontsize.y * 1.5;
394  }
395  pos.y += hud_fontsize.y * 0.5;
396 
398 
399  i = ceil(max(0, mv_timeout - time));
400  map = sprintf(_("%d seconds left"), i);
401  pos.x = center - stringwidth(map, false, hud_fontsize * 1.5) * 0.5;
402  drawstring(pos, map, hud_fontsize * 1.5, '0 1 0', panel_fg_alpha, DRAWFLAG_NORMAL);
403  pos.y += hud_fontsize.y * 1.5;
404  pos.y += hud_fontsize.y * 0.5;
405 
406  // base for multi-column stuff...
407  pos.y += hud_fontsize.y;
408  pos.x = xmin;
409  ymin = pos.y;
410  float abstain_spacing = panel_bg_border + hud_fontsize.y;
411  if(mv_abstain)
412  {
413  mv_num_maps -= 1;
414  ymax -= abstain_spacing;
415  }
416 
417  // higher than the image itself ratio for mapvote items to reserve space for long map names
418  int item_aspect = (gametypevote) ? 3/1 : 5/3;
419  vector table_size = HUD_GetTableSize_BestItemAR(mv_num_maps, vec2(xmax - xmin, ymax - ymin), item_aspect);
420  mv_columns = table_size.x;
421  rows = table_size.y;
422 
423  dist.x = (xmax - xmin) / mv_columns;
424  dist.y = (ymax - pos.y) / rows;
425 
426  // reduce size of too wide items
427  tmp = vid_conwidth / 3; // max width
428  if(dist.x > tmp)
429  {
430  dist.x = tmp;
431  dist.y = min(dist.y, dist.x / item_aspect);
432  }
433  tmp = vid_conheight / 3; // max height
434  if(dist.y > tmp)
435  {
436  dist.y = tmp;
437  dist.x = min(dist.x, dist.y * item_aspect);
438  }
439 
440  // reduce size to fix aspect ratio
441  if(dist.x / dist.y > item_aspect)
442  dist.x = dist.y * item_aspect;
443  else
444  dist.y = dist.x / item_aspect;
445 
446  // adjust table pos and size according to the new size
447  float offset;
448  offset = ((xmax - pos.x) - dist.x * mv_columns) / 2;
449  xmin = pos.x += offset;
450  xmax -= offset;
451  offset = ((ymax - pos.y) - dist.y * rows) / 2;
452  ymax -= 2 * offset;
453 
454  // override panel_pos and panel_size
455  panel_pos.x = pos.x;
456  panel_pos.y = pos.y;
457  panel_size.x = xmax - xmin;
458  panel_size.y = ymax - ymin;
460 
461  if(panel_bg_padding)
462  {
463  // FIXME item AR gets slightly changed here...
464  // it's rather hard to avoid it at this point
465  dist.x -= 2 * panel_bg_padding / mv_columns;
466  dist.y -= 2 * panel_bg_padding / rows;
467  xmin = pos.x += panel_bg_padding;
468  ymin = pos.y += panel_bg_padding;
469  xmax -= 2 * panel_bg_padding;
470  ymax -= 2 * panel_bg_padding;
471  }
472 
473  mv_selection = MapVote_Selection(pos, dist, rows, mv_columns);
474 
475  if (mv_top2_time)
476  mv_top2_alpha = max(0.2, 1 - (time - mv_top2_time) ** 2);
477 
478  void (vector, float, float, string, string, float, float) DrawItem;
479 
480  if(gametypevote)
482  else
483  DrawItem = MapVote_DrawMapItem;
484 
485  for(i = 0; i < mv_num_maps; ++i)
486  {
487  tmp = mv_votes[i]; // FTEQCC bug: too many array accesses in the function call screw it up
488  map = mv_maps[i];
489  if(mv_preview[i])
490  DrawItem(pos + MapVote_GridVec(dist, i, mv_columns), dist.y, dist.x, map, mv_pics[i], tmp, i);
491  else
492  DrawItem(pos + MapVote_GridVec(dist, i, mv_columns), dist.y, dist.x, map, "", tmp, i);
493  }
494 
495  if(mv_abstain)
496  ++mv_num_maps;
497 
498  if(mv_abstain && i < mv_num_maps) {
499  tmp = mv_votes[i];
500  pos.y = ymax + abstain_spacing;
501  pos.x = (xmax+xmin)*0.5;
502  MapVote_DrawAbstain(pos, dist.x, xmax - xmin, tmp, i);
503  }
504 }
int mv_num_maps
Definition: mapvoting.qc:17
string mv_maps[MAPVOTE_COUNT]
Definition: mapvoting.qc:19
float vid_conheight
float panel_bg_border
Definition: hud.qh:169
#define draw_endBoldFont()
Definition: draw.qh:5
float panel_fg_alpha
Definition: hud.qh:166
string mapvote_chosenmap
Definition: mapvoting.qc:41
#define stringwidth
Definition: csprogsdefs.qh:29
#define draw_beginBoldFont()
Definition: draw.qh:4
vector panel_size
Definition: hud.qh:160
float xmin
Definition: mapvoting.qh:20
float chat_sizey
Definition: hud.qh:180
vector HUD_GetTableSize_BestItemAR(int item_count, vector psize, float item_aspect)
Definition: hud.qc:172
void HUD_Scale_Disable()
Definition: hud.qc:83
int mv_selection
Definition: mapvoting.qc:35
float vid_conwidth
float mv_active
Definition: mapvoting.qh:19
vector gtv_text_size
Definition: mapvoting.qc:42
vector MapVote_GridVec(vector gridspec, int i, int m)
Definition: mapvoting.qc:300
float mv_top2_time
Definition: mapvoting.qc:32
#define HUD_Panel_DrawBg()
Definition: hud.qh:54
vector gtv_text_size_small
Definition: mapvoting.qc:43
float chat_posy
Definition: hud.qh:179
void MapVote_DrawAbstain(vector pos, float isize, float tsize, float _count, int id)
Definition: mapvoting.qc:283
vector HUD_GetFontsize(string cvarname)
Definition: hud.qc:111
float mv_preview[MAPVOTE_COUNT]
Definition: mapvoting.qc:23
const float DRAWFLAG_NORMAL
Definition: csprogsdefs.qc:317
float mv_abstain
Definition: mapvoting.qc:28
string mv_pics[MAPVOTE_COUNT]
Definition: mapvoting.qc:20
vector panel_pos
Definition: hud.qh:159
float ymax
Definition: mapvoting.qh:20
float mv_votes[MAPVOTE_COUNT]
Definition: mapvoting.qc:24
float MapVote_Selection(vector topleft, vector cellsize, float rows, float columns)
Definition: mapvoting.qc:310
vector(float skel, float bonenum) _skel_get_boneabs_hidden
float gametypevote
Definition: mapvoting.qc:40
float mv_timeout
Definition: mapvoting.qc:31
int mv_columns
Definition: mapvoting.qc:36
#define vec2(...)
Definition: vector.qh:90
vector hud_fontsize
Definition: main.qh:63
void GameTypeVote_DrawGameTypeItem(vector pos, float maxh, float tsize, string gtype, string pic, float _count, int id)
Definition: mapvoting.qc:96
float ymin
Definition: mapvoting.qh:20
void
Definition: self.qh:83
float time
Definition: csprogsdefs.qc:16
float mv_top2_alpha
Definition: mapvoting.qc:33
void HUD_Panel_LoadCvars()
Definition: hud.qc:216
float panel_bg_padding
Definition: hud.qh:171
void MapVote_DrawMapItem(vector pos, float isize, float tsize, string map, string pic, float _count, int id)
Definition: mapvoting.qc:208
float xmax
Definition: mapvoting.qh:20
+ Here is the call graph for this function:

◆ MapVote_InputEvent()

float MapVote_InputEvent ( float  bInputType,
float  nPrimary,
float  nSecondary 
)

◆ Net_MapVote_Picture()

void Net_MapVote_Picture ( )

Definition at line 964 of file mapvoting.qc.

References mv_pics, mv_preview, and strzone().

Referenced by NET_HANDLE().

965 {
966  int type = ReadByte();
967  mv_preview[type] = true;
968  mv_pics[type] = strzone(ReadPicture());
969 }
float mv_preview[MAPVOTE_COUNT]
Definition: mapvoting.qc:23
string mv_pics[MAPVOTE_COUNT]
Definition: mapvoting.qc:20
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PreviewExists()

bool PreviewExists ( string  name)

Definition at line 49 of file mapvoting.qc.

References autocvar_cl_readpicture_force, fexists(), and strcat().

Referenced by GameTypeVote_ReadOption(), and MapVote_CheckPic().

50 {
52  return false;
53 
54  if (fexists(strcat(name, ".tga"))) return true;
55  if (fexists(strcat(name, ".png"))) return true;
56  if (fexists(strcat(name, ".jpg"))) return true;
57  if (fexists(strcat(name, ".pcx"))) return true;
58 
59  return false;
60 }
bool autocvar_cl_readpicture_force
Definition: mapvoting.qh:5
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
ERASEABLE bool fexists(string f)
Definition: file.qh:4
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ autocvar_cl_readpicture_force

bool autocvar_cl_readpicture_force

Definition at line 5 of file mapvoting.qh.

Referenced by PreviewExists().

◆ autocvar_hud_panel_mapvote_highlight_border

float autocvar_hud_panel_mapvote_highlight_border = 1

Definition at line 6 of file mapvoting.qh.

Referenced by GameTypeVote_DrawGameTypeItem(), and MapVote_DrawMapItem().

◆ autocvar_menu_skin

string autocvar_menu_skin

Definition at line 7 of file mapvoting.qh.

Referenced by GameTypeVote_ReadOption(), and minigame_texture().

◆ mv_active

◆ xmax

float xmax

Definition at line 20 of file mapvoting.qh.

Referenced by MapVote_Draw().

◆ xmin

float xmin

Definition at line 20 of file mapvoting.qh.

Referenced by MapVote_Draw().

◆ ymax

float ymax

Definition at line 20 of file mapvoting.qh.

Referenced by MapVote_Draw().

◆ ymin

float ymin

Definition at line 20 of file mapvoting.qh.

Referenced by MapVote_Draw().