Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
mapvoting.qc File Reference
#include "mapvoting.qh"
#include <client/draw.qh>
#include <client/hud/_mod.qh>
#include <client/hud/panel/scoreboard.qh>
#include <common/mapinfo.qh>
#include <common/util.qh>
Include dependency graph for mapvoting.qc:
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 GameTypeVote_DrawGameTypeItem (vector pos, float maxh, float tsize, string gtype, string pic, int _count, int id, int most_votes)
void GameTypeVote_ReadOption (int i)
void MapVote_CheckPic (string pic, string pk3, int id)
void MapVote_CheckPK3 (string pic, string pk3, int id)
void MapVote_Draw ()
void MapVote_Draw_Export (int fh)
void MapVote_DrawAbstain (vector pos, float tsize, int _count, int id)
void MapVote_DrawMapItem (vector pos, float isize, float tsize, string map, string pic, int _count, int id, int most_votes)
void MapVote_DrawMapPicture (string pic, vector pos, vector img_size, float theAlpha)
void MapVote_DrawSuggester (vector pos)
string MapVote_FormatMapItem (int id, string map, int _count, float maxwidth, vector fontsize, int most_votes)
vector MapVote_GridVec (vector gridspec, int i, int m)
void MapVote_Init ()
float MapVote_InputEvent (int bInputType, float nPrimary, float nSecondary)
int MapVote_MoveDown (int pos)
int MapVote_MoveLeft (int pos)
int MapVote_MoveRight (int pos)
int MapVote_MoveUp (int pos)
void MapVote_ReadMask ()
void MapVote_ReadOption (int i)
vector MapVote_RGB (int id)
float MapVote_Selection (vector topleft, vector cellsize, float rows, float columns)
void MapVote_SendChoice (int index)
void MapVote_UpdateMask ()
void MapVote_UpdateVotes ()
 NET_HANDLE (ENT_CLIENT_MAPVOTE, bool isnew)
 NET_HANDLE (TE_CSQC_PICTURE, bool isNew)
void Net_MapVote_Picture ()
bool PreviewExists (string name)

Variables

bool gametypevote
vector gtv_text_size
vector gtv_text_size_small
string mapvote_chosenmap
bool mv_abstain
int mv_columns
string mv_data [MAPVOTE_COUNT]
string mv_desc [MAPVOTE_COUNT]
int mv_detail
string mv_entries [MAPVOTE_COUNT]
const float MV_FADETIME = 0.2
int mv_flags [MAPVOTE_COUNT]
int mv_flags_start [MAPVOTE_COUNT]
int mv_mouse_selection
int mv_num_maps
int mv_ownvote
string mv_pics [MAPVOTE_COUNT]
entity mv_pk3list
float mv_preview [MAPVOTE_COUNT]
float mv_select_lasttime [MAPVOTE_COUNT]
int mv_selection
bool mv_selection_keyboard
string mv_suggester [MAPVOTE_COUNT]
string mv_suggester_cache
float mv_suggester_cachetime
int mv_tie_winner
float mv_timeout
float mv_top2_alpha
float mv_top2_time
int mv_votes [MAPVOTE_COUNT]
float mv_winner_alpha
float mv_winner_time
int n_ssdirs
const int NUM_SSDIRS = 4
string ssdirs [NUM_SSDIRS]

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().

◆ GameTypeVote_DrawGameTypeItem()

void GameTypeVote_DrawGameTypeItem ( vector pos,
float maxh,
float tsize,
string gtype,
string pic,
int _count,
int id,
int most_votes )

Definition at line 115 of file mapvoting.qc.

116{
117 TC(int, id);
118 // gtype is unused
119
120 // Find the correct alpha
121 float alpha;
122 if (!(mv_flags_start[id] & GTV_AVAILABLE))
123 alpha = 0.2; // The gametype isn't supported by the map
124 else if (!(mv_flags[id] & GTV_AVAILABLE) && mv_top2_alpha)
125 alpha = mv_top2_alpha; // Fade away if not one of the top 2 choice
126 else
127 alpha = 1; // Normal, full alpha
129
130 // Bounding box details
131 const float rect_margin = hud_fontsize.y * 0.5;
132
133 pos.x += rect_margin + autocvar_hud_panel_mapvote_highlight_border;
134 pos.y += rect_margin + autocvar_hud_panel_mapvote_highlight_border;
135 maxh -= 2 * (rect_margin + autocvar_hud_panel_mapvote_highlight_border);
136 tsize -= 2 * (rect_margin + autocvar_hud_panel_mapvote_highlight_border);
137
138 vector rect_pos = pos - '0.5 0.5 0' * rect_margin;
139 vector rect_size = '1 1 0';
140 rect_size.x = tsize + rect_margin;
141 rect_size.y = maxh + rect_margin;
142
143 const vector rgb = MapVote_RGB(id);
144 float time_frac;
145 if (id == mv_ownvote)
146 {
147 // Highlight current vote
148 time_frac = 0;
149 mv_select_lasttime[id] = time; // pretend it's selected, to also enlarge icon
150 drawfill(rect_pos, rect_size, rgb, 0.1 * alpha, DRAWFLAG_NORMAL);
152 }
153 else if (mv_flags[id] & GTV_AVAILABLE)
154 {
155 // Highlight selected item
156 if (id == mv_selection)
157 time_frac = 0;
158 else
159 time_frac = (time - mv_select_lasttime[id]) / MV_FADETIME;
160 if (time_frac < 1)
161 drawfill(rect_pos, rect_size, '1 1 1', 0.1 * (1 - sqrt(time_frac)) * panel_fg_alpha, DRAWFLAG_NORMAL);
162 }
163 else
164 time_frac = 1;
165
166 vector offset = pos;
167
168 const float title_gap = gtv_text_size.y * 1.4; // distance between the title and the description
169 pos.y += title_gap;
170 maxh -= title_gap;
171
172 // Evaluate the image size
173 vector image_size = '3 3 0' * gtv_text_size.x;
174 if (maxh < image_size.y)
175 image_size = '1 1 0' * maxh;
176 image_size *= 0.8;
177 const float desc_padding = gtv_text_size.x * 0.6;
178 pos.x += image_size.x + desc_padding;
179
180 // Split the description into lines
181 entity title = spawn();
182 title.message = strcat(rgb_to_hexcolor(rgb), MapVote_FormatMapItem(id, mv_data[id], _count, tsize, gtv_text_size, most_votes));
183 tsize -= image_size.x + desc_padding;
184
185 string thelabel = mv_desc[id], ts;
186 entity last = title;
187 entity next = NULL;
188 int nlines = 0;
189 if (thelabel != "")
190 {
191 const int n = tokenizebyseparator(thelabel, "\n");
192 for (int i = 0; i < n && maxh > (nlines + 1) * gtv_text_size_small.y; ++i)
193 {
195 while (getWrappedLine_remaining && maxh > (nlines + 1) * gtv_text_size_small.y)
196 {
198 if (ts != "")
199 {
200 next = spawn();
201 next.message = ts;
202 next.origin = pos - offset;
203 last.chain = next;
204 last = next;
205 pos.y += gtv_text_size_small.y;
206 ++nlines;
207 }
208 }
209 }
210 }
211
212 // Center the contents in the bounding box
213 maxh -= max(nlines * gtv_text_size_small.y, image_size.y);
214 if (maxh > 0)
215 offset.y += maxh * 0.5;
216
217 // Draw the title
219
220 // Draw the icon
221 if (pic != "")
222 {
223 vector offset_padding;
224 if (time_frac >= 0 && time_frac < 1)
225 {
226 const float extra_padding = min(desc_padding, title_gap);
227 const float transition_progress = (1 - sqrt(time_frac));
228 image_size *= transition_progress * (extra_padding / image_size.x) + 1;
229 offset_padding = transition_progress * extra_padding * '-0.5 -0.5 0';
230 }
231 else
232 offset_padding = '0 0 0';
233 drawpic(eY * title_gap + eX * 0.5 * desc_padding + offset + offset_padding, pic, image_size, '1 1 1', alpha, DRAWFLAG_NORMAL);
234 }
235
236 // Draw the description
237 last = title.chain;
238 while (last)
239 {
240 drawstring(last.origin + offset, last.message, gtv_text_size_small, '1 1 1', alpha, DRAWFLAG_NORMAL);
241 next = last;
242 last = last.chain;
243 delete(next);
244 }
245
246 // Cleanup
247 delete(title);
248}
void drawborderlines(float thickness, vector pos, vector dim, vector color, float theAlpha, float drawflag)
Definition draw.qc:5
#define drawcolorcodedstring(position, text, scale, alpha, flag)
Definition draw.qh:30
#define drawstring(position, text, scale, rgb, alpha, flag)
Definition draw.qh:27
#define drawpic(position, pic, size, rgb, alpha, flag)
Definition draw.qh:21
#define drawfill(position, size, rgb, alpha, flag)
Definition draw.qh:36
float alpha
Definition items.qc:13
vector hud_fontsize
Definition main.qh:77
int mv_selection
Definition mapvoting.qc:43
float mv_select_lasttime[MAPVOTE_COUNT]
Definition mapvoting.qc:29
vector gtv_text_size_small
Definition mapvoting.qc:51
int mv_flags[MAPVOTE_COUNT]
Definition mapvoting.qc:27
int mv_flags_start[MAPVOTE_COUNT]
Definition mapvoting.qc:28
string mv_desc[MAPVOTE_COUNT]
Definition mapvoting.qc:24
float mv_top2_alpha
Definition mapvoting.qc:37
vector gtv_text_size
Definition mapvoting.qc:50
int mv_ownvote
Definition mapvoting.qc:33
string mv_data[MAPVOTE_COUNT]
Definition mapvoting.qc:22
vector MapVote_RGB(int id)
Definition mapvoting.qc:96
string MapVote_FormatMapItem(int id, string map, int _count, float maxwidth, vector fontsize, int most_votes)
Definition mapvoting.qc:72
const float MV_FADETIME
Definition mapvoting.qc:53
float autocvar_hud_panel_mapvote_highlight_border
Definition mapvoting.qh:6
ERASEABLE string rgb_to_hexcolor(vector rgb)
Definition color.qh:183
string getWrappedLine(float maxWidth, vector theFontSize, textLengthUpToWidth_widthFunction_t tw)
Definition util.qc:995
string getWrappedLine_remaining
Definition util.qh:147
const int GTV_AVAILABLE
Definition constants.qh:64
const float DRAWFLAG_NORMAL
float time
#define spawn
#define tokenizebyseparator
float panel_fg_alpha
Definition hud.qh:169
next
Definition all.qh:93
float sqrt(float f)
float min(float f,...)
float max(float f,...)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define NULL
Definition post.qh:14
vector
Definition self.qh:92
float stringwidth_colors(string s, vector theSize)
Definition string.qh:30
const vector eY
Definition vector.qh:45
const vector eX
Definition vector.qh:44

References alpha, argv(), autocvar_hud_panel_mapvote_highlight_border, drawborderlines(), drawcolorcodedstring, drawfill, DRAWFLAG_NORMAL, drawpic, drawstring, entity(), eX, eY, getWrappedLine(), getWrappedLine_remaining, GTV_AVAILABLE, gtv_text_size, gtv_text_size_small, hud_fontsize, MapVote_FormatMapItem(), MapVote_RGB(), max(), min(), mv_data, mv_desc, MV_FADETIME, mv_flags, mv_flags_start, mv_ownvote, mv_select_lasttime, mv_selection, mv_top2_alpha, next, NULL, panel_fg_alpha, rgb_to_hexcolor(), spawn, sqrt(), strcat(), stringwidth_colors(), TC, time, tokenizebyseparator, and vector.

Referenced by MapVote_Draw().

◆ GameTypeVote_ReadOption()

void GameTypeVote_ReadOption ( int i)

Definition at line 754 of file mapvoting.qc.

755{
756 TC(int, i);
757
759 mv_flags[i] = ReadByte();
760 mv_suggester[i] = "";
761
762 string basetype = "";
763
764 if (mv_flags[i] & GTV_CUSTOM)
765 {
766 string name = ReadString();
767 if (strlen(name) < 1)
768 name = mv_entries[i];
769 mv_data[i] = strzone(name);
770 mv_desc[i] = strzone(ReadString());
771 basetype = strzone(ReadString());
772 }
773 else
774 {
775 const Gametype type = MapInfo_Type_FromString(mv_entries[i], false, false);
778 }
779
780 string mv_picpath = sprintf("gfx/menu/%s/gametype_%s", autocvar_menu_skin, mv_entries[i]);
781 if (precache_pic(mv_picpath) == "")
782 {
783 mv_picpath = strcat("gfx/menu/wickedx/gametype_", mv_entries[i]);
784 if (precache_pic(mv_picpath) == "")
785 {
786 mv_picpath = sprintf("gfx/menu/%s/gametype_%s", autocvar_menu_skin, basetype);
787 if (precache_pic(mv_picpath) == "")
788 mv_picpath = strcat("gfx/menu/wickedx/gametype_", basetype);
789 }
790 }
791 mv_pics[i] = strzone(mv_picpath);
793}
#define ReadString
string mv_entries[MAPVOTE_COUNT]
Definition mapvoting.qc:20
string mv_suggester[MAPVOTE_COUNT]
Definition mapvoting.qc:23
string mv_pics[MAPVOTE_COUNT]
Definition mapvoting.qc:21
string autocvar_menu_skin
Definition mapvoting.qh:7
const int GTV_CUSTOM
Definition constants.qh:65
#define strlen
int ReadByte()
string MapInfo_Type_Description(Gametype t)
Definition mapinfo.qc:651
string MapInfo_Type_ToText(Gametype t)
Definition mapinfo.qc:661
Gametype MapInfo_Type_FromString(string gtype, bool dowarn, bool is_q3compat)
Definition mapinfo.qc:621
string name
Definition menu.qh:30
string precache_pic(string name,...)
string strzone(string s)

References autocvar_menu_skin, GTV_CUSTOM, MapInfo_Type_Description(), MapInfo_Type_FromString(), MapInfo_Type_ToText(), mv_data, mv_desc, mv_entries, mv_flags, mv_pics, mv_preview, mv_suggester, name, precache_pic(), PreviewExists(), ReadByte(), ReadString, strcat(), strlen, strzone(), and TC.

Referenced by MapVote_Init().

◆ MapVote_CheckPic()

void MapVote_CheckPic ( string pic,
string pk3,
int id )

Definition at line 696 of file mapvoting.qc.

697{
698 TC(int, id);
699 // never try to retrieve a pic for the "don't care" 'map'
700 if (mv_abstain && id == mv_num_maps - 1)
701 return;
702
703 if (PreviewExists(pic))
704 {
705 mv_preview[id] = true;
706 return;
707 }
708 MapVote_CheckPK3(pic, pk3, id);
709}
bool mv_abstain
Definition mapvoting.qc:31
void MapVote_CheckPK3(string pic, string pk3, int id)
Definition mapvoting.qc:679
int mv_num_maps
Definition mapvoting.qc:17

References MapVote_CheckPK3(), mv_abstain, mv_num_maps, mv_preview, PreviewExists(), and TC.

Referenced by MapVote_ReadOption().

◆ MapVote_CheckPK3()

void MapVote_CheckPK3 ( string pic,
string pk3,
int id )

Definition at line 679 of file mapvoting.qc.

680{
681 TC(int, id);
682 entity pak = spawn();
683 pak.message = pic;
684 pak.netname = pk3;
685 pak.sv_entnum = id;
686
687 pak.chain = mv_pk3list;
688 mv_pk3list = pak;
689
690 if (pk3 != "")
691 localcmd("\ncurl --pak ", pk3, "; wait; cl_cmd mv_download ", itos(id), "\n");
692 else
694}
void Cmd_MapVote_MapDownload(int argc)
Definition mapvoting.qc:645
#define tokenize_console
#define itos(i)
Definition int.qh:6

References Cmd_MapVote_MapDownload(), entity(), itos, localcmd(), mv_pk3list, spawn, strcat(), TC, and tokenize_console.

Referenced by MapVote_CheckPic().

◆ 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 draw_beginBoldFont()
Definition draw.qh:4
#define draw_endBoldFont()
Definition draw.qh:5
int mv_columns
Definition mapvoting.qc:44
string mapvote_chosenmap
Definition mapvoting.qc:49
int mv_tie_winner
Definition mapvoting.qc:34
void GameTypeVote_DrawGameTypeItem(vector pos, float maxh, float tsize, string gtype, string pic, int _count, int id, int most_votes)
Definition mapvoting.qc:115
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
void MapVote_DrawMapPicture(string pic, vector pos, vector img_size, float theAlpha)
Definition mapvoting.qc:250
float mv_winner_time
Definition mapvoting.qc:38
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
float MapVote_Selection(vector topleft, vector cellsize, float rows, float columns)
Definition mapvoting.qc:396
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
#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_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)
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_Draw_Export()

void MapVote_Draw_Export ( int fh)

Definition at line 11 of file mapvoting.qc.

12{
13 // allow saving cvars that aesthetically change the panel into hud skin files
14 HUD_Write_Cvar("hud_panel_mapvote_highlight_border");
15}
#define HUD_Write_Cvar(cvar)
Definition hud_config.qh:40

References HUD_Write_Cvar.

◆ MapVote_DrawAbstain()

void MapVote_DrawAbstain ( vector pos,
float tsize,
int _count,
int id )

Definition at line 338 of file mapvoting.qc.

339{
340 const string label = MapVote_FormatMapItem(id, _("Don't care"), _count, tsize, hud_fontsize, -1);
341
342 float theAlpha = (mv_winner && mv_winner_alpha)
344 : 1;
345 theAlpha *= panel_fg_alpha;
346 pos.x -= 0.5 * stringwidth(label, false, hud_fontsize);
347 drawstring(pos, label, hud_fontsize, MapVote_RGB(id), theAlpha, DRAWFLAG_NORMAL);
348}

References DRAWFLAG_NORMAL, drawstring, hud_fontsize, MapVote_FormatMapItem(), MapVote_RGB(), mv_winner, mv_winner_alpha, panel_fg_alpha, stringwidth, and vector.

Referenced by MapVote_Draw().

◆ MapVote_DrawMapItem()

void MapVote_DrawMapItem ( vector pos,
float isize,
float tsize,
string map,
string pic,
int _count,
int id,
int most_votes )

Definition at line 263 of file mapvoting.qc.

264{
265 TC(int, id);
266
267 const float rect_margin = hud_fontsize.y * 0.5;
268 pos.x += rect_margin + autocvar_hud_panel_mapvote_highlight_border;
269 pos.y += rect_margin + autocvar_hud_panel_mapvote_highlight_border;
270 isize -= 2 * (rect_margin + autocvar_hud_panel_mapvote_highlight_border);
271 tsize -= 2 * (rect_margin + autocvar_hud_panel_mapvote_highlight_border);
272
273 vector rect_pos = pos - '0.5 0.5 0' * rect_margin;
274 vector rect_size = '1 1 0';
275 rect_size.x = tsize + rect_margin;
276 rect_size.y = isize + rect_margin;
277
278 const float img_ar = 4/3;
279 vector img_size = '0 0 0';
280 img_size.x = min(tsize, isize * img_ar);
281 img_size.y = img_size.x / img_ar;
282 img_size.y -= hud_fontsize.y;
283 img_size.x = img_size.y * img_ar;
284
285 pos.y += (isize - img_size.y - hud_fontsize.y) * 0.5;
286
287 const vector rgb = MapVote_RGB(id);
288 const string label = strcat(rgb_to_hexcolor(rgb), MapVote_FormatMapItem(id, map, _count, tsize, hud_fontsize, most_votes));
289
290 const float text_size = stringwidth(label, true, hud_fontsize);
291
292 const float save_rect_sizex = rect_size.x;
293 rect_size.x = max(img_size.x, text_size) + rect_margin;
294 rect_pos.x += (save_rect_sizex - rect_size.x) * 0.5;
295
296 vector text_pos;
297 text_pos.x = pos.x + (tsize - text_size) * 0.5;
298 text_pos.y = pos.y + img_size.y;
299 text_pos.z = 0;
300
301 pos.x += (tsize - img_size.x) * 0.5;
302
303 float theAlpha;
304 if (!(mv_flags[id] & GTV_AVAILABLE) && mv_top2_alpha)
305 theAlpha = mv_top2_alpha;
306 else if (mv_winner && mv_winner_alpha)
307 theAlpha = mv_winner_alpha;
308 else
309 theAlpha = 1;
310 theAlpha *= panel_fg_alpha;
311
312 if (!mv_winner)
313 {
314 if (id == mv_ownvote)
315 {
316 // Highlight current vote
317 drawfill(rect_pos, rect_size, rgb, 0.1 * theAlpha, DRAWFLAG_NORMAL);
319 }
320 else if (mv_flags[id] & GTV_AVAILABLE)
321 {
322 // Highlight selected item
323 float time_frac;
324 if (id == mv_selection)
325 time_frac = 0;
326 else
327 time_frac = (time - mv_select_lasttime[id]) / MV_FADETIME;
328 if (time_frac < 1)
329 drawfill(rect_pos, rect_size, '1 1 1', 0.1 * (1 - sqrt(time_frac)) * panel_fg_alpha, DRAWFLAG_NORMAL);
330 }
331 }
332
333 drawcolorcodedstring(text_pos, label, hud_fontsize, theAlpha, DRAWFLAG_NORMAL);
334
335 MapVote_DrawMapPicture(pic, pos, img_size, theAlpha);
336}

References autocvar_hud_panel_mapvote_highlight_border, drawborderlines(), drawcolorcodedstring, drawfill, DRAWFLAG_NORMAL, GTV_AVAILABLE, hud_fontsize, MapVote_DrawMapPicture(), MapVote_FormatMapItem(), MapVote_RGB(), max(), min(), MV_FADETIME, mv_flags, mv_ownvote, mv_select_lasttime, mv_selection, mv_top2_alpha, mv_winner, mv_winner_alpha, panel_fg_alpha, rgb_to_hexcolor(), sqrt(), strcat(), stringwidth, TC, time, and vector.

Referenced by MapVote_Draw().

◆ MapVote_DrawMapPicture()

void MapVote_DrawMapPicture ( string pic,
vector pos,
vector img_size,
float theAlpha )

Definition at line 250 of file mapvoting.qc.

251{
252 if (pic == "")
253 drawfill(pos, img_size, '0.5 0.5 0.5', 0.7 * theAlpha, DRAWFLAG_NORMAL);
254 else
255 {
256 if (drawgetimagesize(pic) == '0 0 0')
257 drawpic(pos, draw_UseSkinFor("nopreview_map"), img_size, '1 1 1', theAlpha, DRAWFLAG_NORMAL);
258 else
259 drawpic(pos, pic, img_size, '1 1 1', theAlpha, DRAWFLAG_NORMAL);
260 }
261}
vector drawgetimagesize(string pic)

References drawfill, DRAWFLAG_NORMAL, drawgetimagesize(), drawpic, and vector.

Referenced by MapVote_Draw(), and MapVote_DrawMapItem().

◆ MapVote_DrawSuggester()

void MapVote_DrawSuggester ( vector pos)

Definition at line 350 of file mapvoting.qc.

351{
352 const int id = mv_winner ? mv_winner - 1 : mv_selection;
353
354 float theAlpha = 0;
355 if (id != -1 && (mv_flags[id] & GTV_AVAILABLE)) // if the map is valid, update cache and time
356 {
357 if (mv_suggester_cache == "" && mv_suggester[id] == "")
358 return;
359 if (mv_suggester[id] != "") // update cache to current, set time
360 {
363 theAlpha = 1;
364 }
365 }
366 if (mv_suggester_cache != "" && theAlpha != 1) // figure out alpha for cache if it's partly-faded
367 {
368 const float time_frac = (time - mv_suggester_cachetime) / MV_FADETIME;
369 if (time_frac >= 1) // finished fading out, delete cache
370 {
372 return;
373 }
374 theAlpha = (1 - sqrt(time_frac));
375 }
376 if (!theAlpha)
377 return;
378
379 const string label = sprintf(_("Suggested by: %s"), ColorTranslateRGB(mv_suggester_cache));
380
381 theAlpha *= panel_fg_alpha;
382 pos.x -= 0.5 * stringwidth(label, true, hud_fontsize);
383 drawcolorcodedstring(pos, label, hud_fontsize, theAlpha, DRAWFLAG_NORMAL);
384}
float mv_suggester_cachetime
Definition mapvoting.qc:41
string mv_suggester_cache
Definition mapvoting.qc:40
ERASEABLE string ColorTranslateRGB(string s)
Definition string.qh:196

References ColorTranslateRGB(), drawcolorcodedstring, DRAWFLAG_NORMAL, GTV_AVAILABLE, hud_fontsize, MV_FADETIME, mv_flags, mv_selection, mv_suggester, mv_suggester_cache, mv_suggester_cachetime, mv_winner, panel_fg_alpha, sqrt(), stringwidth, time, and vector.

Referenced by MapVote_Draw().

◆ MapVote_FormatMapItem()

string MapVote_FormatMapItem ( int id,
string map,
int _count,
float maxwidth,
vector fontsize,
int most_votes )

Definition at line 72 of file mapvoting.qc.

73{
74 TC(int, id);
75 string post;
76 string pre = sprintf("%d. ", id + 1);
77 if (mv_detail)
78 {
79 if (_count == 1)
80 post = _(" (1 vote)");
81 else if (_count >= 0 && (mv_flags[id] & GTV_AVAILABLE))
82 post = sprintf(_(" (%d votes)"), _count);
83 else
84 post = "";
85 if (post != "" && (mv_flags[id] & GTV_AVAILABLE))
86 if (mv_tie_winner == id || (mv_tie_winner == -2 && _count == most_votes))
87 post = strcat("^5", post);
88 }
89 else
90 post = "";
91 maxwidth -= stringwidth(pre, false, fontsize) + stringwidth(post, true, fontsize);
92 map = textShortenToWidth(map, maxwidth, fontsize, stringwidth_nocolors);
93 return strcat(pre, map, post);
94}
int mv_detail
Definition mapvoting.qc:32
string textShortenToWidth(string theText, float maxWidth, vector theFontSize, textLengthUpToWidth_widthFunction_t tw)
Definition util.qc:1071
float stringwidth_nocolors(string s, vector theSize)
Definition string.qh:35

References GTV_AVAILABLE, mv_detail, mv_flags, mv_tie_winner, strcat(), stringwidth, stringwidth_nocolors(), TC, textShortenToWidth(), and vector.

Referenced by GameTypeVote_DrawGameTypeItem(), MapVote_DrawAbstain(), and MapVote_DrawMapItem().

◆ MapVote_GridVec()

vector MapVote_GridVec ( vector gridspec,
int i,
int m )

Definition at line 386 of file mapvoting.qc.

387{
388 TC(int, i); TC(int, m);
389 const int r = i % m;
390 return
391 eX * (gridspec.x * r)
392 +
393 eY * (gridspec.y * (i - r) / m);
394}

References eX, eY, TC, and vector.

Referenced by MapVote_Draw().

◆ MapVote_Init()

void MapVote_Init ( )

Definition at line 795 of file mapvoting.qc.

796{
797 mv_active = true;
799 mousepos = (eX * vid_conwidth + eY * vid_conheight) * 0.5;
800 mv_selection = -1;
801 mv_selection_keyboard = false;
802
803 string s;
804 for (n_ssdirs = 0; ; ++n_ssdirs)
805 {
806 s = ReadString();
807 if (s == "")
808 break;
809 if (n_ssdirs < NUM_SSDIRS)
810 ssdirs[n_ssdirs] = s;
811 }
813
817
820
821 mv_ownvote = -1;
822 mv_timeout = ReadCoord();
823
824 const int gametypevote_flags = ReadByte();
825 gametypevote = boolean(gametypevote_flags & BIT(0));
826 if (gametypevote_flags)
828
830 int i;
831 for (i = 0; i < mv_num_maps; ++i)
832 mv_flags_start[i] = mv_flags[i];
833
834 // Assume mv_pk3list is NULL, there should only be 1 mapvote per round
835 mv_pk3list = NULL; // I'm still paranoid!
836
837 for (i = 0; i < mv_num_maps; ++i)
838 {
839 mv_votes[i] = 0;
840 mv_select_lasttime[i] = 0;
841
842 if (gametypevote)
844 else
846 }
847
848 for (i = 0; i < n_ssdirs; ++i)
850 n_ssdirs = 0;
851}
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition bits.qh:8
#define boolean(value)
Definition bool.qh:9
bool mv_selection_keyboard
Definition mapvoting.qc:46
int n_ssdirs
Definition mapvoting.qc:57
void GameTypeVote_ReadOption(int i)
Definition mapvoting.qc:754
string ssdirs[NUM_SSDIRS]
Definition mapvoting.qc:56
void MapVote_ReadOption(int i)
Definition mapvoting.qc:739
const int NUM_SSDIRS
Definition mapvoting.qc:55
void MapVote_ReadMask()
Definition mapvoting.qc:711
const int MAPVOTE_COUNT
Definition constants.qh:52
bool autocvar_hud_cursormode
Definition hud.qh:191
vector mousepos
Definition hud.qh:103
string string_null
Definition nil.qh:9

References autocvar_hud_cursormode, BIT, boolean, eX, eY, gametypevote, GameTypeVote_ReadOption(), mapvote_chosenmap, MAPVOTE_COUNT, MapVote_ReadMask(), MapVote_ReadOption(), min(), mousepos, mv_abstain, mv_active, mv_detail, mv_flags, mv_flags_start, mv_num_maps, mv_ownvote, mv_pk3list, mv_select_lasttime, mv_selection, mv_selection_keyboard, mv_suggester_cache, mv_suggester_cachetime, mv_timeout, mv_votes, n_ssdirs, NULL, NUM_SSDIRS, ReadByte(), ReadString, ssdirs, string_null, strzone(), vid_conheight, and vid_conwidth.

Referenced by MapVote_Finished(), MapVote_Think(), and NET_HANDLE().

◆ MapVote_InputEvent()

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

Definition at line 928 of file mapvoting.qc.

929{
930 TC(int, bInputType);
931
932 static int first_digit = 0;
933 if (!mv_active || isdemo())
934 return false;
935
936 if (bInputType == 3)
937 {
938 mousepos.x = nPrimary;
939 mousepos.y = nSecondary;
940 mv_selection_keyboard = false;
941 return true;
942 }
943
944 if (bInputType == 2)
945 {
946 mv_selection_keyboard = false;
947 return false;
948 }
949
950 // at this point bInputType can only be 0 or 1 (key pressed or released)
951 const bool key_pressed = (bInputType == 0);
952
953 if (key_pressed)
954 {
955 if (nPrimary == K_ALT) hudShiftState |= S_ALT;
956 if (nPrimary == K_CTRL) hudShiftState |= S_CTRL;
957 if (nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
958 }
959 else
960 {
961 if (nPrimary == K_ALT) hudShiftState &= ~S_ALT;
962 if (nPrimary == K_CTRL) hudShiftState &= ~S_CTRL;
963 if (nPrimary == K_SHIFT) hudShiftState &= ~S_SHIFT;
964
965 if (nPrimary == K_CTRL)
966 first_digit = 0;
967 }
968
969 // Key release events must be handled by the engine otherwise the on-press command such as +jump
970 // executed by pressing SPACE before entering the map voting screen won't be followed by the
971 // on-release command (-jump) on key release once entered the map voting screen, causing +jump
972 // to stay active even on the next map and automatically forcing the player to join
973 if (!key_pressed) return false;
974
975 int imp = 0;
976 switch (nPrimary)
977 {
978 case K_RIGHTARROW:
979 if (mv_winner)
980 return true;
983 return true;
984 case K_LEFTARROW:
985 if (mv_winner)
986 return true;
989 return true;
990 case K_DOWNARROW:
991 if (mv_winner)
992 return true;
995 return true;
996 case K_UPARROW:
997 if (mv_winner)
998 return true;
1001 return true;
1002 case K_KP_ENTER:
1003 case K_ENTER:
1004 case K_SPACE:
1005 if (mv_winner)
1006 return true;
1009 return true;
1010 case '1': case K_KP_1: imp = 1; break;
1011 case '2': case K_KP_2: imp = 2; break;
1012 case '3': case K_KP_3: imp = 3; break;
1013 case '4': case K_KP_4: imp = 4; break;
1014 case '5': case K_KP_5: imp = 5; break;
1015 case '6': case K_KP_6: imp = 6; break;
1016 case '7': case K_KP_7: imp = 7; break;
1017 case '8': case K_KP_8: imp = 8; break;
1018 case '9': case K_KP_9: imp = 9; break;
1019 case '0': case K_KP_0: imp = 10; break;
1020 }
1021
1022 if (imp && hudShiftState & S_CTRL)
1023 {
1024 if (!first_digit)
1025 {
1026 first_digit = imp % 10;
1027 return true;
1028 }
1029 else
1030 imp = first_digit * 10 + (imp % 10);
1031 }
1032
1033 if (nPrimary == K_MOUSE1)
1034 {
1035 mv_selection_keyboard = false;
1037 if (mv_selection >= 0)
1039 }
1040
1041 if (nPrimary == K_MOUSE2)
1042 return true; // do nothing
1043
1044 if (imp)
1045 {
1046 if (!mv_winner && imp <= mv_num_maps)
1047 localcmd("\nimpulse ", ftos(imp), "\n");
1048 return true;
1049 }
1050
1051 return false;
1052}
int MapVote_MoveRight(int pos)
Definition mapvoting.qc:871
int mv_mouse_selection
Definition mapvoting.qc:45
void MapVote_SendChoice(int index)
Definition mapvoting.qc:853
int MapVote_MoveLeft(int pos)
Definition mapvoting.qc:859
int MapVote_MoveUp(int pos)
Definition mapvoting.qc:883
int MapVote_MoveDown(int pos)
Definition mapvoting.qc:905
const int S_SHIFT
Definition hud.qh:129
int hudShiftState
Definition hud.qh:128
const int S_ALT
Definition hud.qh:131
const int S_CTRL
Definition hud.qh:130
float K_KP_9
Definition keycodes.qc:65
float K_SHIFT
Definition keycodes.qc:22
float K_KP_8
Definition keycodes.qc:63
float K_UPARROW
Definition keycodes.qc:15
float K_KP_3
Definition keycodes.qc:54
float K_KP_0
Definition keycodes.qc:48
float K_DOWNARROW
Definition keycodes.qc:16
float K_KP_7
Definition keycodes.qc:61
float K_MOUSE1
Definition keycodes.qc:129
float K_KP_4
Definition keycodes.qc:56
float K_CTRL
Definition keycodes.qc:21
float K_RIGHTARROW
Definition keycodes.qc:18
float K_SPACE
Definition keycodes.qc:10
float K_ALT
Definition keycodes.qc:20
float K_ENTER
Definition keycodes.qc:8
float K_KP_5
Definition keycodes.qc:58
float K_KP_2
Definition keycodes.qc:52
float K_LEFTARROW
Definition keycodes.qc:17
float K_MOUSE2
Definition keycodes.qc:130
float K_KP_ENTER
Definition keycodes.qc:74
float K_KP_1
Definition keycodes.qc:50
float K_KP_6
Definition keycodes.qc:59
float isdemo()
int int int imp
Definition impulse.qc:90

References ftos(), hudShiftState, imp, isdemo(), K_ALT, K_CTRL, K_DOWNARROW, K_ENTER, K_KP_0, K_KP_1, K_KP_2, K_KP_3, K_KP_4, K_KP_5, K_KP_6, K_KP_7, K_KP_8, K_KP_9, K_KP_ENTER, K_LEFTARROW, K_MOUSE1, K_MOUSE2, K_RIGHTARROW, K_SHIFT, K_SPACE, K_UPARROW, localcmd(), MapVote_MoveDown(), MapVote_MoveLeft(), MapVote_MoveRight(), MapVote_MoveUp(), MapVote_SendChoice(), min(), mousepos, mv_active, mv_mouse_selection, mv_num_maps, mv_selection, mv_selection_keyboard, mv_winner, S_ALT, S_CTRL, S_SHIFT, and TC.

Referenced by CSQC_InputEvent().

◆ MapVote_MoveDown()

int MapVote_MoveDown ( int pos)

Definition at line 905 of file mapvoting.qc.

906{
907 TC(int, pos);
908 int imp;
909 if (pos < 0)
910 imp = 0;
911 else
912 {
913 imp = pos + mv_columns;
914 if (imp >= mv_num_maps)
915 {
916 const int col = imp % mv_columns;
917 if (col == mv_columns - 1)
918 imp = 0;
919 else
920 imp = col + 1;
921 }
922 }
923 if (!(mv_flags[imp] & GTV_AVAILABLE) && imp != mv_ownvote)
925 return imp;
926}

References GTV_AVAILABLE, imp, MapVote_MoveDown(), mv_columns, mv_flags, mv_num_maps, mv_ownvote, and TC.

Referenced by MapVote_InputEvent(), and MapVote_MoveDown().

◆ MapVote_MoveLeft()

int MapVote_MoveLeft ( int pos)

Definition at line 859 of file mapvoting.qc.

860{
861 TC(int, pos);
862 int imp;
863 if (pos < 0)
864 imp = mv_num_maps - 1;
865 else
866 imp = pos < 1 ? mv_num_maps - 1 : pos - 1;
867 if (!(mv_flags[imp] & GTV_AVAILABLE) && imp != mv_ownvote)
869 return imp;
870}

References GTV_AVAILABLE, imp, MapVote_MoveLeft(), mv_flags, mv_num_maps, mv_ownvote, and TC.

Referenced by MapVote_InputEvent(), and MapVote_MoveLeft().

◆ MapVote_MoveRight()

int MapVote_MoveRight ( int pos)

Definition at line 871 of file mapvoting.qc.

872{
873 TC(int, pos);
874 int imp;
875 if (pos < 0)
876 imp = 0;
877 else
878 imp = pos >= mv_num_maps - 1 ? 0 : pos + 1;
879 if (!(mv_flags[imp] & GTV_AVAILABLE) && imp != mv_ownvote)
881 return imp;
882}

References GTV_AVAILABLE, imp, MapVote_MoveRight(), mv_flags, mv_num_maps, mv_ownvote, and TC.

Referenced by MapVote_InputEvent(), and MapVote_MoveRight().

◆ MapVote_MoveUp()

int MapVote_MoveUp ( int pos)

Definition at line 883 of file mapvoting.qc.

884{
885 TC(int, pos);
886 int imp;
887 if (pos < 0)
888 imp = mv_num_maps - 1;
889 else
890 {
891 imp = pos - mv_columns;
892 if (imp < 0)
893 {
894 const int mv_rows = ceil(mv_num_maps / mv_columns);
895 if (imp == -mv_columns) // pos == 0
896 imp = mv_columns * mv_rows - 1;
897 else
898 imp = imp + mv_columns * mv_rows - 1;
899 }
900 }
901 if (!(mv_flags[imp] & GTV_AVAILABLE) && imp != mv_ownvote)
903 return imp;
904}

References ceil(), GTV_AVAILABLE, imp, MapVote_MoveUp(), mv_columns, mv_flags, mv_num_maps, mv_ownvote, and TC.

Referenced by MapVote_InputEvent(), and MapVote_MoveUp().

◆ MapVote_ReadMask()

void MapVote_ReadMask ( )

Definition at line 711 of file mapvoting.qc.

712{
713 int i;
714 if (mv_num_maps < 24)
715 {
716 int mask;
717 if (mv_num_maps < 8)
718 mask = ReadByte();
719 else if (mv_num_maps < 16)
720 mask = ReadShort();
721 else
722 mask = ReadLong();
723
724 for (i = 0; i < mv_num_maps; ++i)
725 {
726 if (mask & BIT(i))
728 else
730 }
731 }
732 else
733 {
734 for (i = 0; i < mv_num_maps; ++i)
735 mv_flags[i] = ReadByte();
736 }
737}

References BIT, GTV_AVAILABLE, mv_flags, mv_num_maps, and ReadByte().

Referenced by MapVote_Init(), and MapVote_UpdateMask().

◆ MapVote_ReadOption()

void MapVote_ReadOption ( int i)

Definition at line 739 of file mapvoting.qc.

740{
741 TC(int, i);
742
744 mv_data[i] = strzone(ReadString());
747 const int j = bound(0, ReadByte(), n_ssdirs - 1);
748
749 mv_pics[i] = strzone(strcat(ssdirs[j], "/", mv_entries[i]));
750 mv_preview[i] = false;
752}
void MapVote_CheckPic(string pic, string pk3, int id)
Definition mapvoting.qc:696

References bound(), GTV_AVAILABLE, MapVote_CheckPic(), mv_data, mv_entries, mv_flags, mv_pics, mv_preview, mv_suggester, n_ssdirs, ReadByte(), ReadString, ssdirs, strcat(), strzone(), and TC.

Referenced by MapVote_Init().

◆ MapVote_RGB()

vector MapVote_RGB ( int id)

Definition at line 96 of file mapvoting.qc.

97{
98 TC(int, id);
99
100 vector rgb;
101 if (!(mv_flags[id] & GTV_AVAILABLE))
102 rgb = '1 1 1';
103 else if (id == mv_ownvote)
104 rgb = '0 1 0';
105 else if (id == mv_selection)
106 rgb = '1 1 0';
107 else
108 {
109 const float time_frac = (time - mv_select_lasttime[id]) / MV_FADETIME;
110 rgb = '1 1 0' + eZ * (time_frac >= 1 ? 1 : sqrt(time_frac));
111 }
112 return rgb;
113}
const vector eZ
Definition vector.qh:46

References eZ, GTV_AVAILABLE, MV_FADETIME, mv_flags, mv_ownvote, mv_select_lasttime, mv_selection, sqrt(), TC, time, and vector.

Referenced by GameTypeVote_DrawGameTypeItem(), MapVote_DrawAbstain(), and MapVote_DrawMapItem().

◆ MapVote_Selection()

float MapVote_Selection ( vector topleft,
vector cellsize,
float rows,
float columns )

Definition at line 396 of file mapvoting.qc.

397{
398 if (mv_winner)
399 return -1;
400
402
403 for (float c, r = 0; r < rows; ++r)
404 for (c = 0; c < columns; ++c)
405 if (mousepos.x >= topleft.x + cellsize.x * c
406 && mousepos.x <= topleft.x + cellsize.x * (c + 1)
407 && mousepos.y >= topleft.y + cellsize.y * r
408 && mousepos.y <= topleft.y + cellsize.y * (r + 1))
409 {
410 mv_mouse_selection = r * columns + c;
411 break;
412 }
413
418
420 return mv_selection;
421 return mv_mouse_selection;
422}

References mousepos, mv_abstain, mv_mouse_selection, mv_num_maps, mv_selection, mv_selection_keyboard, mv_winner, and vector.

Referenced by MapVote_Draw().

◆ MapVote_SendChoice()

void MapVote_SendChoice ( int index)

Definition at line 853 of file mapvoting.qc.

854{
855 TC(int, index);
856 localcmd("\nimpulse ", ftos(index + 1), "\n");
857}

References ftos(), localcmd(), and TC.

Referenced by MapVote_InputEvent().

◆ MapVote_UpdateMask()

void MapVote_UpdateMask ( )

Definition at line 1054 of file mapvoting.qc.

1055{
1058}

References MapVote_ReadMask(), mv_top2_time, and time.

Referenced by NET_HANDLE().

◆ MapVote_UpdateVotes()

void MapVote_UpdateVotes ( )

Definition at line 1060 of file mapvoting.qc.

1061{
1062 for (int i = 0; i < mv_num_maps; ++i)
1063 {
1064 if (mv_flags[i] & GTV_AVAILABLE)
1065 {
1066 if (mv_detail)
1067 mv_votes[i] = ReadByte();
1068 else
1069 mv_votes[i] = 0;
1070 }
1071 else
1072 mv_votes[i] = -1;
1073 }
1074 if (mv_detail)
1075 mv_tie_winner = ReadChar();
1076
1077 mv_ownvote = ReadByte() - 1;
1078}

References GTV_AVAILABLE, mv_detail, mv_flags, mv_num_maps, mv_ownvote, mv_tie_winner, mv_votes, and ReadByte().

Referenced by NET_HANDLE().

◆ NET_HANDLE() [1/2]

NET_HANDLE ( ENT_CLIENT_MAPVOTE ,
bool isnew )

Definition at line 1080 of file mapvoting.qc.

1081{
1082 make_pure(this);
1083 const int sf = ReadByte();
1084 return = true;
1085
1086 if (sf & BIT(0))
1087 MapVote_Init();
1088
1089 if (sf & BIT(1))
1091
1092 if (sf & BIT(2))
1094
1095 if (sf & BIT(3))
1096 {
1097 mv_winner = ReadByte();
1099 }
1100}
void MapVote_UpdateMask()
void MapVote_UpdateVotes()
void MapVote_Init()
Definition mapvoting.qc:795
#define make_pure(e)
direct use is
Definition oo.qh:13

References BIT, make_pure, MapVote_Init(), MapVote_UpdateMask(), MapVote_UpdateVotes(), mv_winner, mv_winner_time, ReadByte(), and time.

◆ NET_HANDLE() [2/2]

NET_HANDLE ( TE_CSQC_PICTURE ,
bool isNew )

Definition at line 1102 of file mapvoting.qc.

1103{
1105 return true;
1106}
void Net_MapVote_Picture()

References Net_MapVote_Picture().

◆ 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}

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

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

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

Variable Documentation

◆ gametypevote

◆ gtv_text_size

vector gtv_text_size

Definition at line 50 of file mapvoting.qc.

Referenced by GameTypeVote_DrawGameTypeItem(), and MapVote_Draw().

◆ gtv_text_size_small

vector gtv_text_size_small

Definition at line 51 of file mapvoting.qc.

Referenced by GameTypeVote_DrawGameTypeItem(), and MapVote_Draw().

◆ mapvote_chosenmap

string mapvote_chosenmap

Definition at line 49 of file mapvoting.qc.

Referenced by MapVote_Draw(), and MapVote_Init().

◆ mv_abstain

bool mv_abstain

Definition at line 31 of file mapvoting.qc.

Referenced by MapVote_CheckPic(), MapVote_Draw(), MapVote_Init(), and MapVote_Selection().

◆ mv_columns

int mv_columns

Definition at line 44 of file mapvoting.qc.

Referenced by MapVote_Draw(), MapVote_MoveDown(), and MapVote_MoveUp().

◆ mv_data

◆ mv_desc

Definition at line 24 of file mapvoting.qc.

Referenced by GameTypeVote_DrawGameTypeItem(), and GameTypeVote_ReadOption().

◆ mv_detail

int mv_detail

Definition at line 32 of file mapvoting.qc.

Referenced by MapVote_FormatMapItem(), MapVote_Init(), and MapVote_UpdateVotes().

◆ mv_entries

string mv_entries[MAPVOTE_COUNT]

Definition at line 20 of file mapvoting.qc.

Referenced by GameTypeVote_ReadOption(), MapVote_Draw(), and MapVote_ReadOption().

◆ MV_FADETIME

const float MV_FADETIME = 0.2

◆ mv_flags

◆ mv_flags_start

int mv_flags_start[MAPVOTE_COUNT]

Definition at line 28 of file mapvoting.qc.

Referenced by GameTypeVote_DrawGameTypeItem(), and MapVote_Init().

◆ mv_mouse_selection

int mv_mouse_selection

Definition at line 45 of file mapvoting.qc.

Referenced by MapVote_InputEvent(), and MapVote_Selection().

◆ mv_num_maps

◆ mv_ownvote

◆ mv_pics

◆ mv_pk3list

entity mv_pk3list

Definition at line 30 of file mapvoting.qc.

Referenced by Cmd_MapVote_MapDownload(), MapVote_CheckPK3(), and MapVote_Init().

◆ mv_preview

◆ mv_select_lasttime

◆ mv_selection

◆ mv_selection_keyboard

bool mv_selection_keyboard

Definition at line 46 of file mapvoting.qc.

Referenced by MapVote_Init(), MapVote_InputEvent(), and MapVote_Selection().

◆ mv_suggester

◆ mv_suggester_cache

string mv_suggester_cache

Definition at line 40 of file mapvoting.qc.

Referenced by MapVote_DrawSuggester(), and MapVote_Init().

◆ mv_suggester_cachetime

float mv_suggester_cachetime

Definition at line 41 of file mapvoting.qc.

Referenced by MapVote_DrawSuggester(), and MapVote_Init().

◆ mv_tie_winner

int mv_tie_winner

Definition at line 34 of file mapvoting.qc.

Referenced by MapVote_Draw(), MapVote_FormatMapItem(), and MapVote_UpdateVotes().

◆ mv_timeout

float mv_timeout

Definition at line 35 of file mapvoting.qc.

Referenced by MapVote_Draw(), and MapVote_Init().

◆ mv_top2_alpha

float mv_top2_alpha

Definition at line 37 of file mapvoting.qc.

Referenced by GameTypeVote_DrawGameTypeItem(), MapVote_Draw(), and MapVote_DrawMapItem().

◆ mv_top2_time

float mv_top2_time

Definition at line 36 of file mapvoting.qc.

Referenced by MapVote_Draw(), and MapVote_UpdateMask().

◆ mv_votes

int mv_votes[MAPVOTE_COUNT]

Definition at line 26 of file mapvoting.qc.

Referenced by MapVote_Draw(), MapVote_Init(), and MapVote_UpdateVotes().

◆ mv_winner_alpha

float mv_winner_alpha

Definition at line 39 of file mapvoting.qc.

Referenced by MapVote_Draw(), MapVote_DrawAbstain(), and MapVote_DrawMapItem().

◆ mv_winner_time

float mv_winner_time

Definition at line 38 of file mapvoting.qc.

Referenced by MapVote_Draw(), and NET_HANDLE().

◆ n_ssdirs

int n_ssdirs

Definition at line 57 of file mapvoting.qc.

Referenced by MapVote_Init(), and MapVote_ReadOption().

◆ NUM_SSDIRS

const int NUM_SSDIRS = 4

Definition at line 55 of file mapvoting.qc.

Referenced by MapVote_Init().

◆ ssdirs

string ssdirs[NUM_SSDIRS]

Definition at line 56 of file mapvoting.qc.

Referenced by MapVote_Init(), and MapVote_ReadOption().