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 (bool should_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 647 of file mapvoting.qc.

648{
649 TC(int, argc);
650
651 if (argc != 2 || !mv_pk3list)
652 {
653 LOG_INFO(_("mv_mapdownload: ^3You're not supposed to use this command on your own!"));
654 return;
655 }
656
657 entity pak;
658 const int id = stof(argv(1));
659 for (pak = mv_pk3list; pak; pak = pak.chain)
660 if (pak.sv_entnum == id)
661 break;
662
663 if (!pak || pak.sv_entnum != id)
664 {
665 LOG_INFO(_("^1Error:^7 Couldn't find pak index."));
666 return;
667 }
668
669 if (PreviewExists(pak.message))
670 {
671 mv_preview[id] = true;
672 return;
673 }
674 else
675 {
676 LOG_INFO(_("Requesting preview..."));
677 localcmd("\ncmd mv_getpicture ", ftos(id), "\n");
678 }
679}
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:1131
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:95
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 756 of file mapvoting.qc.

757{
758 TC(int, i);
759
761 mv_flags[i] = ReadByte();
762 mv_suggester[i] = "";
763
764 string basetype = "";
765
766 if (mv_flags[i] & GTV_CUSTOM)
767 {
768 string name = ReadString();
769 if (strlen(name) < 1)
770 name = mv_entries[i];
771 mv_data[i] = strzone(name);
772 mv_desc[i] = strzone(ReadString());
773 basetype = strzone(ReadString());
774 }
775 else
776 {
777 const Gametype type = MapInfo_Type_FromString(mv_entries[i], false, false);
780 }
781
782 string mv_picpath = sprintf("gfx/menu/%s/gametype_%s", autocvar_menu_skin, mv_entries[i]);
783 if (precache_pic(mv_picpath) == "")
784 {
785 mv_picpath = strcat("gfx/menu/wickedx/gametype_", mv_entries[i]);
786 if (precache_pic(mv_picpath) == "")
787 {
788 mv_picpath = sprintf("gfx/menu/%s/gametype_%s", autocvar_menu_skin, basetype);
789 if (precache_pic(mv_picpath) == "")
790 mv_picpath = strcat("gfx/menu/wickedx/gametype_", basetype);
791 }
792 }
793 mv_pics[i] = strzone(mv_picpath);
795}
#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:650
string MapInfo_Type_ToText(Gametype t)
Definition mapinfo.qc:660
Gametype MapInfo_Type_FromString(string gtype, bool dowarn, bool is_q3compat)
Definition mapinfo.qc:620
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 698 of file mapvoting.qc.

699{
700 TC(int, id);
701 // never try to retrieve a pic for the "don't care" 'map'
702 if (mv_abstain && id == mv_num_maps - 1)
703 return;
704
705 if (PreviewExists(pic))
706 {
707 mv_preview[id] = true;
708 return;
709 }
710 MapVote_CheckPK3(pic, pk3, id);
711}
bool mv_abstain
Definition mapvoting.qc:31
void MapVote_CheckPK3(string pic, string pk3, int id)
Definition mapvoting.qc:681
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 681 of file mapvoting.qc.

682{
683 TC(int, id);
684 entity pak = spawn();
685 pak.message = pic;
686 pak.netname = pk3;
687 pak.sv_entnum = id;
688
689 pak.chain = mv_pk3list;
690 mv_pk3list = pak;
691
692 if (pk3 != "")
693 localcmd("\ncurl --pak ", pk3, "; wait; cl_cmd mv_download ", itos(id), "\n");
694 else
696}
void Cmd_MapVote_MapDownload(int argc)
Definition mapvoting.qc:647
#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 ( bool should_draw)

Definition at line 425 of file mapvoting.qc.

426{
427 if (!should_draw)
428 return;
429 //if (intermission != 2) return;
430 if (!mv_active)
431 return;
432
434
435 const float center = (vid_conwidth - 1) * 0.5;
436 xmin = vid_conwidth * (gametypevote ? 0.08 : 0.1);
438 ymin = 20;
440
441 if (chat_posy + chat_sizey * 0.5 < vid_conheight * 0.5)
442 ymin += chat_sizey;
443 else
444 ymax -= chat_sizey;
445
446 hud_fontsize = HUD_GetFontsize("hud_fontsize");
447 if (gametypevote)
448 {
451 }
452
453 vector pos;
454 pos.y = ymin;
455 pos.z = 0;
456
459
460 string map = (gametypevote) ? _("Decide the gametype") : _("Vote for a map");
461 if (!mv_winner)
462 {
463 pos.x = center - stringwidth(map, false, hud_fontsize * 2) * 0.5;
464 drawstring(pos, map, hud_fontsize * 2, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
465 }
466 pos.y += hud_fontsize.y * 2;
467
468 if (mapvote_chosenmap != "")
469 {
470 pos.y += hud_fontsize.y * 0.25;
471 pos.x = center - stringwidth(mapvote_chosenmap, false, hud_fontsize * 1.5) * 0.5;
473 pos.y += hud_fontsize.y * 1.5;
474 }
475 pos.y += hud_fontsize.y * 0.5;
476
478
479 int i;
480 if (mv_winner)
481 map = mv_entries[mv_winner - 1];
482 else
483 {
484 i = ceil(max(1, mv_timeout - time)); // make sure 0 seconds left never shows up, not even for a frame
485 map = count_seconds(i);
486 }
487 pos.x = center - stringwidth(map, false, hud_fontsize * 1.5) * 0.5;
488 drawstring(pos, map, hud_fontsize * 1.5, '0 1 0', panel_fg_alpha, DRAWFLAG_NORMAL);
489 pos.y += hud_fontsize.y * 1.5;
490 pos.y += hud_fontsize.y * 0.5;
491
492 // base for multi-column stuff...
493 pos.y += hud_fontsize.y;
494 pos.x = xmin;
495 ymin = pos.y;
496 const float abstain_spacing = panel_bg_border + hud_fontsize.y;
497 const float suggester_spacing = hud_fontsize.y * 1.5;
498 if (mv_abstain)
499 {
500 --mv_num_maps;
501 ymax -= abstain_spacing;
502 }
503 const bool were_suggesters = (mv_suggester[0] != ""); // suggestions are placed at the start
504 if (were_suggesters)
505 ymax -= suggester_spacing;
506
507 // higher than the image itself ratio for mapvote items to reserve space for long map names
508 const float item_aspect = (gametypevote) ? 3/1 : 5/3;
509 const vector table_size = HUD_GetTableSize_BestItemAR(mv_num_maps, vec2(xmax - xmin, ymax - ymin), item_aspect);
510 mv_columns = table_size.x;
511 const float rows = table_size.y;
512
513 vector dist;
514 dist.x = (xmax - xmin) / mv_columns;
515 dist.y = (ymax - pos.y) / rows;
516 dist.z = 0;
517
518 // reduce size of too wide items
519 float tmp = vid_conwidth / 3; // max width
520 if (dist.x > tmp)
521 {
522 dist.x = tmp;
523 dist.y = min(dist.y, dist.x / item_aspect);
524 }
525 tmp = vid_conheight / 3; // max height
526 if (dist.y > tmp)
527 {
528 dist.y = tmp;
529 dist.x = min(dist.x, dist.y * item_aspect);
530 }
531
532 // reduce size to fix aspect ratio
533 if (dist.x / dist.y > item_aspect)
534 dist.x = dist.y * item_aspect;
535 else
536 dist.y = dist.x / item_aspect;
537
538 // adjust table pos and size according to the new size
539 float offset = ((xmax - pos.x) - dist.x * mv_columns) * 0.5;
540 xmin = pos.x += offset;
541 xmax -= offset;
542 offset = ((ymax - pos.y) - dist.y * rows) * 0.5;
543 ymax -= 2 * offset;
544
545 // override panel_pos and panel_size
546 panel_pos.x = pos.x;
547 panel_pos.y = pos.y;
548 panel_size.x = xmax - xmin;
549 panel_size.y = ymax - ymin;
551
553 {
554 // FIXME item AR gets slightly changed here...
555 // it's rather hard to avoid it at this point
556 dist.x -= 2 * panel_bg_padding / mv_columns;
557 dist.y -= 2 * panel_bg_padding / rows;
558 xmin = pos.x += panel_bg_padding;
559 ymin = pos.y += panel_bg_padding;
560 xmax -= 2 * panel_bg_padding;
561 ymax -= 2 * panel_bg_padding;
562 }
563
564 mv_selection = MapVote_Selection(pos, dist, rows, mv_columns);
565 if (mv_selection != -1)
567
568 if (mv_top2_time)
569 mv_top2_alpha = max(0.2, 1 - (time - mv_top2_time) ** 2);
570
571 if (mv_winner_time)
572 mv_winner_alpha = max(0.2, 1 - sqrt(max(0, time - mv_winner_time)));
573
574 int most_votes = -1;
575 if (mv_tie_winner == -2)
576 for (i = 0; i < mv_num_maps; ++i)
577 if (mv_votes[i] > most_votes)
578 most_votes = mv_votes[i];
579
580 void(vector, float, float, string, string, float, int, int) DrawItem;
581 if (gametypevote)
583 else
584 DrawItem = MapVote_DrawMapItem;
585
586 for (i = 0; i < mv_num_maps; ++i)
587 {
588 tmp = mv_votes[i]; // FTEQCC bug: too many array accesses in the function call screw it up
589 map = mv_entries[i];
590 const string pic = mv_preview[i] ? mv_pics[i] : "";
591 DrawItem(pos + MapVote_GridVec(dist, i, mv_columns), dist.y, dist.x, map, pic, tmp, i, most_votes);
592 }
593
594 if (mv_abstain)
595 ++mv_num_maps;
596
597 pos.y = ymax + abstain_spacing;
598 if (mv_abstain && i < mv_num_maps)
599 {
600 tmp = mv_votes[i];
601 pos.x = center;
602 MapVote_DrawAbstain(pos, xmax - xmin, tmp, i);
603 pos.y += suggester_spacing;
604 }
605
606 if (mv_winner)
607 {
608 // expand winner map image
609 vector startsize;
610 startsize.z = 0;
611 startsize.y = vid_conheight * 0.1;
612 startsize.x = startsize.y * 4/3;
613 const vector startpos = panel_pos + (panel_size - startsize) * 0.5;
614
615 vector endsize;
616 endsize.z = 0;
617 endsize.y = vid_conheight * 0.5;
618 endsize.x = endsize.y * 4/3;
619 vector endpos;
620 endpos.z = 0;
621 endpos.y = panel_pos.y;
622 endpos.x = (vid_conwidth - endsize.x) * 0.5;
623
624 float f = bound(0, sqrt((time - mv_winner_time) * 2), 1);
625 const float theAlpha = f;
626 f = min(0.1 + f, 1);
627 vector img_size = endsize * f + startsize * (1 - f);
628 vector img_pos = endpos * f + startpos * (1 - f);
629
630 MapVote_DrawMapPicture(mv_pics[mv_winner - 1], img_pos, img_size, theAlpha);
631
632 if (were_suggesters)
633 {
634 const float suggester_startposy = pos.y;
635 const float suggester_endposy = panel_pos.y + endsize.y + hud_fontsize.y;
636 pos.y = suggester_endposy * f + suggester_startposy * (1 - f);
637 }
638 }
639
640 if (were_suggesters)
641 {
642 pos.x = center;
644 }
645}
#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:19
float ymin
Definition mapvoting.qh:19
bool mv_active
Definition mapvoting.qh:17
float xmax
Definition mapvoting.qh:19
int mv_winner
Definition mapvoting.qh:18
float ymax
Definition mapvoting.qh:19
#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:1171
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 797 of file mapvoting.qc.

798{
799 mv_active = true;
801 mousepos = (eX * vid_conwidth + eY * vid_conheight) * 0.5;
802 mv_selection = -1;
803 mv_selection_keyboard = false;
804
805 string s;
806 for (n_ssdirs = 0; ; ++n_ssdirs)
807 {
808 s = ReadString();
809 if (s == "")
810 break;
811 if (n_ssdirs < NUM_SSDIRS)
812 ssdirs[n_ssdirs] = s;
813 }
815
819
822
823 mv_ownvote = -1;
824 mv_timeout = ReadCoord();
825
826 const int gametypevote_flags = ReadByte();
827 gametypevote = boolean(gametypevote_flags & BIT(0));
828 if (gametypevote_flags)
830
832 int i;
833 for (i = 0; i < mv_num_maps; ++i)
834 mv_flags_start[i] = mv_flags[i];
835
836 // Assume mv_pk3list is NULL, there should only be 1 mapvote per round
837 mv_pk3list = NULL; // I'm still paranoid!
838
839 for (i = 0; i < mv_num_maps; ++i)
840 {
841 mv_votes[i] = 0;
842 mv_select_lasttime[i] = 0;
843
844 if (gametypevote)
846 else
848 }
849
850 for (i = 0; i < n_ssdirs; ++i)
852 n_ssdirs = 0;
853}
#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:756
string ssdirs[NUM_SSDIRS]
Definition mapvoting.qc:56
void MapVote_ReadOption(int i)
Definition mapvoting.qc:741
const int NUM_SSDIRS
Definition mapvoting.qc:55
void MapVote_ReadMask()
Definition mapvoting.qc:713
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 930 of file mapvoting.qc.

931{
932 TC(int, bInputType);
933
934 static int first_digit = 0;
935 if (!mv_active || isdemo())
936 return false;
937
938 if (bInputType == 3)
939 {
940 mousepos.x = nPrimary;
941 mousepos.y = nSecondary;
942 mv_selection_keyboard = false;
943 return true;
944 }
945
946 if (bInputType == 2)
947 {
948 mv_selection_keyboard = false;
949 return false;
950 }
951
952 // at this point bInputType can only be 0 or 1 (key pressed or released)
953 const bool key_pressed = (bInputType == 0);
954
955 if (key_pressed)
956 {
957 if (nPrimary == K_ALT) hudShiftState |= S_ALT;
958 if (nPrimary == K_CTRL) hudShiftState |= S_CTRL;
959 if (nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
960 }
961 else
962 {
963 if (nPrimary == K_ALT) hudShiftState &= ~S_ALT;
964 if (nPrimary == K_CTRL) hudShiftState &= ~S_CTRL;
965 if (nPrimary == K_SHIFT) hudShiftState &= ~S_SHIFT;
966
967 if (nPrimary == K_CTRL)
968 first_digit = 0;
969 }
970
971 // Key release events must be handled by the engine otherwise the on-press command such as +jump
972 // executed by pressing SPACE before entering the map voting screen won't be followed by the
973 // on-release command (-jump) on key release once entered the map voting screen, causing +jump
974 // to stay active even on the next map and automatically forcing the player to join
975 if (!key_pressed) return false;
976
977 int imp = 0;
978 switch (nPrimary)
979 {
980 case K_RIGHTARROW:
981 if (mv_winner)
982 return true;
985 return true;
986 case K_LEFTARROW:
987 if (mv_winner)
988 return true;
991 return true;
992 case K_DOWNARROW:
993 if (mv_winner)
994 return true;
997 return true;
998 case K_UPARROW:
999 if (mv_winner)
1000 return true;
1001 mv_selection_keyboard = true;
1003 return true;
1004 case K_KP_ENTER:
1005 case K_ENTER:
1006 case K_SPACE:
1007 if (mv_winner)
1008 return true;
1011 return true;
1012 case '1': case K_KP_1: imp = 1; break;
1013 case '2': case K_KP_2: imp = 2; break;
1014 case '3': case K_KP_3: imp = 3; break;
1015 case '4': case K_KP_4: imp = 4; break;
1016 case '5': case K_KP_5: imp = 5; break;
1017 case '6': case K_KP_6: imp = 6; break;
1018 case '7': case K_KP_7: imp = 7; break;
1019 case '8': case K_KP_8: imp = 8; break;
1020 case '9': case K_KP_9: imp = 9; break;
1021 case '0': case K_KP_0: imp = 10; break;
1022 }
1023
1024 if (imp && hudShiftState & S_CTRL)
1025 {
1026 if (!first_digit)
1027 {
1028 first_digit = imp % 10;
1029 return true;
1030 }
1031 else
1032 imp = first_digit * 10 + (imp % 10);
1033 }
1034
1035 if (nPrimary == K_MOUSE1)
1036 {
1037 mv_selection_keyboard = false;
1039 if (mv_selection >= 0)
1041 }
1042
1043 if (nPrimary == K_MOUSE2)
1044 return true; // do nothing
1045
1046 if (imp)
1047 {
1048 if (!mv_winner && imp <= mv_num_maps)
1049 localcmd("\nimpulse ", ftos(imp), "\n");
1050 return true;
1051 }
1052
1053 return false;
1054}
int MapVote_MoveRight(int pos)
Definition mapvoting.qc:873
int mv_mouse_selection
Definition mapvoting.qc:45
void MapVote_SendChoice(int index)
Definition mapvoting.qc:855
int MapVote_MoveLeft(int pos)
Definition mapvoting.qc:861
int MapVote_MoveUp(int pos)
Definition mapvoting.qc:885
int MapVote_MoveDown(int pos)
Definition mapvoting.qc:907
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 907 of file mapvoting.qc.

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

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 861 of file mapvoting.qc.

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

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 873 of file mapvoting.qc.

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

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 885 of file mapvoting.qc.

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

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 713 of file mapvoting.qc.

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

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 741 of file mapvoting.qc.

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

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 855 of file mapvoting.qc.

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

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

Referenced by MapVote_InputEvent().

◆ MapVote_UpdateMask()

void MapVote_UpdateMask ( )

Definition at line 1056 of file mapvoting.qc.

1057{
1060}

References MapVote_ReadMask(), mv_top2_time, and time.

Referenced by NET_HANDLE().

◆ MapVote_UpdateVotes()

void MapVote_UpdateVotes ( )

Definition at line 1062 of file mapvoting.qc.

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

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 1082 of file mapvoting.qc.

1083{
1084 make_pure(this);
1085 const int sf = ReadByte();
1086 return = true;
1087
1088 if (sf & BIT(0))
1089 MapVote_Init();
1090
1091 if (sf & BIT(1))
1093
1094 if (sf & BIT(2))
1096
1097 if (sf & BIT(3))
1098 {
1099 mv_winner = ReadByte();
1101 }
1102}
void MapVote_UpdateMask()
void MapVote_UpdateVotes()
void MapVote_Init()
Definition mapvoting.qc:797
#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 1104 of file mapvoting.qc.

1105{
1107 return true;
1108}
void Net_MapVote_Picture()

References Net_MapVote_Picture().

◆ Net_MapVote_Picture()

void Net_MapVote_Picture ( )

Definition at line 1110 of file mapvoting.qc.

1111{
1112 const int type = ReadByte();
1113 mv_preview[type] = true;
1114 mv_pics[type] = strzone(ReadPicture());
1115}

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