Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
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
bool mv_active
int mv_winner
float xmax
float xmin
float ymax
float ymin

Function Documentation

◆ Cmd_MapVote_MapDownload()

void Cmd_MapVote_MapDownload ( int argc)

Definition at line 645 of file mapvoting.qc.

646{
647 TC(int, argc);
648
649 if (argc != 2 || !mv_pk3list)
650 {
651 LOG_INFO(_("mv_mapdownload: ^3You're not supposed to use this command on your own!"));
652 return;
653 }
654
655 entity pak;
656 const int id = stof(argv(1));
657 for (pak = mv_pk3list; pak; pak = pak.chain)
658 if (pak.sv_entnum == id)
659 break;
660
661 if (!pak || pak.sv_entnum != id)
662 {
663 LOG_INFO(_("^1Error:^7 Couldn't find pak index."));
664 return;
665 }
666
667 if (PreviewExists(pak.message))
668 {
669 mv_preview[id] = true;
670 return;
671 }
672 else
673 {
674 LOG_INFO(_("Requesting preview..."));
675 localcmd("\ncmd mv_getpicture ", ftos(id), "\n");
676 }
677}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
bool PreviewExists(string name)
Definition mapvoting.qc:59
entity mv_pk3list
Definition mapvoting.qc:30
float mv_preview[MAPVOTE_COUNT]
Definition mapvoting.qc:25
#define TC(T, sym)
Definition _all.inc:82
#define LOG_INFO(...)
Definition log.qh:65
void localcmd(string command,...)
float stof(string val,...)
string ftos(float f)
string argv(float n)

References argv(), entity(), ftos(), localcmd(), LOG_INFO, mv_pk3list, mv_preview, PreviewExists(), stof(), and TC.

Referenced by LocalCommand_mv_download(), and MapVote_CheckPK3().

◆ MapVote_Draw()

void MapVote_Draw ( )

Definition at line 425 of file mapvoting.qc.

426{
427 //if (intermission != 2) return;
428 if (!mv_active)
429 return;
430
432
433 const float center = (vid_conwidth - 1) * 0.5;
434 xmin = vid_conwidth * (gametypevote ? 0.08 : 0.1);
436 ymin = 20;
438
439 if (chat_posy + chat_sizey * 0.5 < vid_conheight * 0.5)
440 ymin += chat_sizey;
441 else
442 ymax -= chat_sizey;
443
444 hud_fontsize = HUD_GetFontsize("hud_fontsize");
445 if (gametypevote)
446 {
449 }
450
451 vector pos;
452 pos.y = ymin;
453 pos.z = 0;
454
457
458 string map = (gametypevote) ? _("Decide the gametype") : _("Vote for a map");
459 if (!mv_winner)
460 {
461 pos.x = center - stringwidth(map, false, hud_fontsize * 2) * 0.5;
462 drawstring(pos, map, hud_fontsize * 2, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
463 }
464 pos.y += hud_fontsize.y * 2;
465
466 if (mapvote_chosenmap != "")
467 {
468 pos.y += hud_fontsize.y * 0.25;
469 pos.x = center - stringwidth(mapvote_chosenmap, false, hud_fontsize * 1.5) * 0.5;
471 pos.y += hud_fontsize.y * 1.5;
472 }
473 pos.y += hud_fontsize.y * 0.5;
474
476
477 int i;
478 if (mv_winner)
479 map = mv_entries[mv_winner - 1];
480 else
481 {
482 i = ceil(max(1, mv_timeout - time)); // make sure 0 seconds left never shows up, not even for a frame
483 map = count_seconds(i);
484 }
485 pos.x = center - stringwidth(map, false, hud_fontsize * 1.5) * 0.5;
486 drawstring(pos, map, hud_fontsize * 1.5, '0 1 0', panel_fg_alpha, DRAWFLAG_NORMAL);
487 pos.y += hud_fontsize.y * 1.5;
488 pos.y += hud_fontsize.y * 0.5;
489
490 // base for multi-column stuff...
491 pos.y += hud_fontsize.y;
492 pos.x = xmin;
493 ymin = pos.y;
494 const float abstain_spacing = panel_bg_border + hud_fontsize.y;
495 const float suggester_spacing = hud_fontsize.y * 1.5;
496 if (mv_abstain)
497 {
498 --mv_num_maps;
499 ymax -= abstain_spacing;
500 }
501 const bool were_suggesters = (mv_suggester[0] != ""); // suggestions are placed at the start
502 if (were_suggesters)
503 ymax -= suggester_spacing;
504
505 // higher than the image itself ratio for mapvote items to reserve space for long map names
506 const float item_aspect = (gametypevote) ? 3/1 : 5/3;
507 const vector table_size = HUD_GetTableSize_BestItemAR(mv_num_maps, vec2(xmax - xmin, ymax - ymin), item_aspect);
508 mv_columns = table_size.x;
509 const float rows = table_size.y;
510
511 vector dist;
512 dist.x = (xmax - xmin) / mv_columns;
513 dist.y = (ymax - pos.y) / rows;
514 dist.z = 0;
515
516 // reduce size of too wide items
517 float tmp = vid_conwidth / 3; // max width
518 if (dist.x > tmp)
519 {
520 dist.x = tmp;
521 dist.y = min(dist.y, dist.x / item_aspect);
522 }
523 tmp = vid_conheight / 3; // max height
524 if (dist.y > tmp)
525 {
526 dist.y = tmp;
527 dist.x = min(dist.x, dist.y * item_aspect);
528 }
529
530 // reduce size to fix aspect ratio
531 if (dist.x / dist.y > item_aspect)
532 dist.x = dist.y * item_aspect;
533 else
534 dist.y = dist.x / item_aspect;
535
536 // adjust table pos and size according to the new size
537 float offset = ((xmax - pos.x) - dist.x * mv_columns) * 0.5;
538 xmin = pos.x += offset;
539 xmax -= offset;
540 offset = ((ymax - pos.y) - dist.y * rows) * 0.5;
541 ymax -= 2 * offset;
542
543 // override panel_pos and panel_size
544 panel_pos.x = pos.x;
545 panel_pos.y = pos.y;
546 panel_size.x = xmax - xmin;
547 panel_size.y = ymax - ymin;
549
551 {
552 // FIXME item AR gets slightly changed here...
553 // it's rather hard to avoid it at this point
554 dist.x -= 2 * panel_bg_padding / mv_columns;
555 dist.y -= 2 * panel_bg_padding / rows;
556 xmin = pos.x += panel_bg_padding;
557 ymin = pos.y += panel_bg_padding;
558 xmax -= 2 * panel_bg_padding;
559 ymax -= 2 * panel_bg_padding;
560 }
561
562 mv_selection = MapVote_Selection(pos, dist, rows, mv_columns);
563 if (mv_selection != -1)
565
566 if (mv_top2_time)
567 mv_top2_alpha = max(0.2, 1 - (time - mv_top2_time) ** 2);
568
569 if (mv_winner_time)
570 mv_winner_alpha = max(0.2, 1 - sqrt(max(0, time - mv_winner_time)));
571
572 int most_votes = -1;
573 if (mv_tie_winner == -2)
574 for (i = 0; i < mv_num_maps; ++i)
575 if (mv_votes[i] > most_votes)
576 most_votes = mv_votes[i];
577
578 void(vector, float, float, string, string, float, int, int) DrawItem;
579 if (gametypevote)
581 else
582 DrawItem = MapVote_DrawMapItem;
583
584 for (i = 0; i < mv_num_maps; ++i)
585 {
586 tmp = mv_votes[i]; // FTEQCC bug: too many array accesses in the function call screw it up
587 map = mv_entries[i];
588 const string pic = mv_preview[i] ? mv_pics[i] : "";
589 DrawItem(pos + MapVote_GridVec(dist, i, mv_columns), dist.y, dist.x, map, pic, tmp, i, most_votes);
590 }
591
592 if (mv_abstain)
593 ++mv_num_maps;
594
595 pos.y = ymax + abstain_spacing;
596 if (mv_abstain && i < mv_num_maps)
597 {
598 tmp = mv_votes[i];
599 pos.x = center;
600 MapVote_DrawAbstain(pos, xmax - xmin, tmp, i);
601 pos.y += suggester_spacing;
602 }
603
604 if (mv_winner)
605 {
606 // expand winner map image
607 vector startsize;
608 startsize.z = 0;
609 startsize.y = vid_conheight * 0.1;
610 startsize.x = startsize.y * 4/3;
611 const vector startpos = panel_pos + (panel_size - startsize) * 0.5;
612
613 vector endsize;
614 endsize.z = 0;
615 endsize.y = vid_conheight * 0.5;
616 endsize.x = endsize.y * 4/3;
617 vector endpos;
618 endpos.z = 0;
619 endpos.y = panel_pos.y;
620 endpos.x = (vid_conwidth - endsize.x) * 0.5;
621
622 float f = bound(0, sqrt((time - mv_winner_time) * 2), 1);
623 const float theAlpha = f;
624 f = min(0.1 + f, 1);
625 vector img_size = endsize * f + startsize * (1 - f);
626 vector img_pos = endpos * f + startpos * (1 - f);
627
628 MapVote_DrawMapPicture(mv_pics[mv_winner - 1], img_pos, img_size, theAlpha);
629
630 if (were_suggesters)
631 {
632 const float suggester_startposy = pos.y;
633 const float suggester_endposy = panel_pos.y + endsize.y + hud_fontsize.y;
634 pos.y = suggester_endposy * f + suggester_startposy * (1 - f);
635 }
636 }
637
638 if (were_suggesters)
639 {
640 pos.x = center;
642 }
643}
#define drawstring(position, text, scale, rgb, alpha, flag)
Definition draw.qh:27
#define draw_beginBoldFont()
Definition draw.qh:4
#define draw_endBoldFont()
Definition draw.qh:5
vector hud_fontsize
Definition main.qh:77
int mv_columns
Definition mapvoting.qc:44
bool mv_abstain
Definition mapvoting.qc:31
string mapvote_chosenmap
Definition mapvoting.qc:49
int mv_tie_winner
Definition mapvoting.qc:34
int mv_selection
Definition mapvoting.qc:43
void GameTypeVote_DrawGameTypeItem(vector pos, float maxh, float tsize, string gtype, string pic, int _count, int id, int most_votes)
Definition mapvoting.qc:115
float mv_select_lasttime[MAPVOTE_COUNT]
Definition mapvoting.qc:29
vector gtv_text_size_small
Definition mapvoting.qc:51
void MapVote_DrawMapItem(vector pos, float isize, float tsize, string map, string pic, int _count, int id, int most_votes)
Definition mapvoting.qc:263
float mv_top2_time
Definition mapvoting.qc:36
vector MapVote_GridVec(vector gridspec, int i, int m)
Definition mapvoting.qc:386
string mv_entries[MAPVOTE_COUNT]
Definition mapvoting.qc:20
void MapVote_DrawMapPicture(string pic, vector pos, vector img_size, float theAlpha)
Definition mapvoting.qc:250
float mv_winner_time
Definition mapvoting.qc:38
float mv_top2_alpha
Definition mapvoting.qc:37
vector gtv_text_size
Definition mapvoting.qc:50
bool gametypevote
Definition mapvoting.qc:48
void MapVote_DrawSuggester(vector pos)
Definition mapvoting.qc:350
int mv_votes[MAPVOTE_COUNT]
Definition mapvoting.qc:26
void MapVote_DrawAbstain(vector pos, float tsize, int _count, int id)
Definition mapvoting.qc:338
float mv_winner_alpha
Definition mapvoting.qc:39
string mv_suggester[MAPVOTE_COUNT]
Definition mapvoting.qc:23
float MapVote_Selection(vector topleft, vector cellsize, float rows, float columns)
Definition mapvoting.qc:396
string mv_pics[MAPVOTE_COUNT]
Definition mapvoting.qc:21
int mv_num_maps
Definition mapvoting.qc:17
float mv_timeout
Definition mapvoting.qc:35
float xmin
Definition mapvoting.qh:21
float ymin
Definition mapvoting.qh:21
bool mv_active
Definition mapvoting.qh:19
float xmax
Definition mapvoting.qh:21
int mv_winner
Definition mapvoting.qh:20
float ymax
Definition mapvoting.qh:21
#define count_seconds(time)
Definition counting.qh:56
const float DRAWFLAG_NORMAL
float time
#define stringwidth
void HUD_Panel_LoadCvars()
Definition hud.qc:215
vector HUD_GetFontsize(string cvarname)
Definition hud.qc:112
vector HUD_GetTableSize_BestItemAR(int item_count, vector psize, float item_aspect)
Definition hud.qc:172
void HUD_Scale_Disable()
Definition hud.qc:84
vector panel_size
Definition hud.qh:163
float panel_fg_alpha
Definition hud.qh:169
float panel_bg_padding
Definition hud.qh:174
float panel_bg_border
Definition hud.qh:172
float chat_sizey
Definition hud.qh:183
#define HUD_Panel_DrawBg()
Definition hud.qh:55
vector panel_pos
Definition hud.qh:162
float chat_posy
Definition hud.qh:182
noref float vid_conwidth
Definition draw.qh:8
noref float vid_conheight
Definition draw.qh:9
float ceil(float f)
float bound(float min, float value, float max)
float sqrt(float f)
float min(float f,...)
float max(float f,...)
vector
Definition self.qh:92
void
Definition self.qh:72
#define vec2(...)
Definition vector.qh:90

References bound(), ceil(), chat_posy, chat_sizey, count_seconds, draw_beginBoldFont, draw_endBoldFont, DRAWFLAG_NORMAL, drawstring, gametypevote, GameTypeVote_DrawGameTypeItem(), gtv_text_size, gtv_text_size_small, hud_fontsize, HUD_GetFontsize(), HUD_GetTableSize_BestItemAR(), HUD_Panel_DrawBg, HUD_Panel_LoadCvars(), HUD_Scale_Disable(), mapvote_chosenmap, MapVote_DrawAbstain(), MapVote_DrawMapItem(), MapVote_DrawMapPicture(), MapVote_DrawSuggester(), MapVote_GridVec(), MapVote_Selection(), max(), min(), mv_abstain, mv_active, mv_columns, mv_entries, mv_num_maps, mv_pics, mv_preview, mv_select_lasttime, mv_selection, mv_suggester, mv_tie_winner, mv_timeout, mv_top2_alpha, mv_top2_time, mv_votes, mv_winner, mv_winner_alpha, mv_winner_time, panel_bg_border, panel_bg_padding, panel_fg_alpha, panel_pos, panel_size, sqrt(), stringwidth, time, vec2, vector, vid_conheight, vid_conwidth, void, xmax, xmin, ymax, and ymin.

◆ MapVote_InputEvent()

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

◆ Net_MapVote_Picture()

void Net_MapVote_Picture ( )

Definition at line 1108 of file mapvoting.qc.

1109{
1110 const int type = ReadByte();
1111 mv_preview[type] = true;
1112 mv_pics[type] = strzone(ReadPicture());
1113}
int ReadByte()
string strzone(string s)

References mv_pics, mv_preview, ReadByte(), and strzone().

Referenced by NET_HANDLE().

◆ PreviewExists()

bool PreviewExists ( string name)

Definition at line 59 of file mapvoting.qc.

60{
62 return false;
63
64 if (fexists(strcat(name, ".tga"))) return true;
65 if (fexists(strcat(name, ".png"))) return true;
66 if (fexists(strcat(name, ".jpg"))) return true;
67 if (fexists(strcat(name, ".pcx"))) return true;
68
69 return false;
70}
bool autocvar_cl_readpicture_force
Definition mapvoting.qh:5
ERASEABLE bool fexists(string f)
Definition file.qh:4
string name
Definition menu.qh:30
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))

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

Referenced by Cmd_MapVote_MapDownload(), GameTypeVote_ReadOption(), and MapVote_CheckPic().

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

◆ mv_winner

◆ xmax

float xmax

Definition at line 21 of file mapvoting.qh.

Referenced by MapVote_Draw().

◆ xmin

float xmin

Definition at line 21 of file mapvoting.qh.

Referenced by MapVote_Draw().

◆ ymax

float ymax

Definition at line 21 of file mapvoting.qh.

Referenced by MapVote_Draw().

◆ ymin

float ymin

Definition at line 21 of file mapvoting.qh.

Referenced by MapVote_Draw().