#include "mapvoting.qh"
+#include "_all.qh"
+
+#include "hud.qh"
#include "scoreboard.qh"
+#include "../common/mapinfo.qh"
+#include "../common/util.qh"
+
+#include "../dpdefs/keycodes.qh"
+
+
+int mv_num_maps;
+
+float mv_active;
+string mv_maps[MAPVOTE_COUNT];
+string mv_pics[MAPVOTE_COUNT];
+string mv_pk3[MAPVOTE_COUNT];
+float mv_preview[MAPVOTE_COUNT];
+float mv_votes[MAPVOTE_COUNT];
+float mv_flags[MAPVOTE_COUNT];
+float mv_flags_start[MAPVOTE_COUNT];
+entity mv_pk3list;
+float mv_abstain;
+float mv_ownvote;
+float mv_detail;
+float mv_timeout;
+float mv_top2_time;
+float mv_top2_alpha;
+
+vector mv_mousepos;
+int mv_selection;
+int mv_columns;
+int mv_mouse_selection;
+int mv_selection_keyboard;
+
+float gametypevote;
+string mapvote_chosenmap;
+vector gtv_text_size;
+vector gtv_text_size_small;
+
+const int NUM_SSDIRS = 4;
+string ssdirs[NUM_SSDIRS];
+int n_ssdirs;
+
string MapVote_FormatMapItem(int id, string map, float _count, float maxwidth, vector fontsize)
{
string pre, post;
{
if(_count == 1)
post = _(" (1 vote)");
- else if(_count >= 0 && mv_avail[id] == GTV_AVAILABLE)
+ else if(_count >= 0 && (mv_flags[id] & GTV_AVAILABLE))
post = sprintf(_(" (%d votes)"), _count);
else
post = "";
vector MapVote_RGB(int id)
{
- if(mv_avail[id] != GTV_AVAILABLE)
+ if(!(mv_flags[id] & GTV_AVAILABLE))
return '1 1 1';
if(id == mv_ownvote)
return '0 1 0';
vector rgb = MapVote_RGB(id);
vector offset = pos;
float nlines = 0;
-
- if(mv_avail_start[id] != GTV_AVAILABLE)
+
+ if(!(mv_flags_start[id] & GTV_AVAILABLE))
alpha = 0.2;
- else if ( mv_avail[id] != GTV_AVAILABLE && mv_top2_alpha)
+ else if ( !(mv_flags[id] & GTV_AVAILABLE) && mv_top2_alpha)
alpha = mv_top2_alpha;
else
alpha = 1;
-
- if(id == mv_selection && mv_avail[id] == GTV_AVAILABLE)
+
+ if(id == mv_selection && (mv_flags[id] & GTV_AVAILABLE))
{
drawfill(rect_pos, rect_size, '1 1 1', 0.1, DRAWFLAG_NORMAL);
}
drawfill(rect_pos, rect_size, rgb, 0.1*alpha, DRAWFLAG_NORMAL);
drawborderlines(autocvar_scoreboard_border_thickness, rect_pos, rect_size, rgb, alpha, DRAWFLAG_NORMAL);
}
-
+
entity title;
title = spawn();
- title.message = MapVote_FormatMapItem(id, MapInfo_Type_ToText(MapInfo_Type_FromString(gtype)),
+ title.message = MapVote_FormatMapItem(id, MapInfo_Type_ToText(MapInfo_Type_FromString(gtype)),
_count, tsize, gtv_text_size);
title.origin = pos-offset;
-
+
pos.y += gtv_text_size_small.y;
pos.y += gtv_text_size.y/2;
-
+
maxh -= gtv_text_size.y;
-
+
entity picent = spawn();
picent.origin = pos-offset;
picent.maxs = '1 1 0 ' * min(maxh, desc_padding) * 0.8;
-
+
pos.x += desc_padding;
tsize -= desc_padding;
-
+
string thelabel = GameTypeVote_DescriptionByID(id), ts;
entity last = title;
entity next = world;
- if( thelabel != "")
+ if( thelabel != "")
{
float i,n = tokenizebyseparator(thelabel, "\n");
for(i = 0; i < n && maxh > (nlines+1)*gtv_text_size_small.y; ++i)
}
}
}
-
+
maxh -= max(nlines*gtv_text_size_small.y,picent.maxs.y);
if ( maxh > 0 )
offset.y += maxh/2;
- drawstring(title.origin+offset, title.message, gtv_text_size, rgb, alpha, DRAWFLAG_NORMAL);
-
+ drawstring(title.origin+offset, title.message, gtv_text_size, rgb, alpha, DRAWFLAG_NORMAL);
+
if(pic != "")
drawpic(picent.origin+offset, pic, picent.maxs, '1 1 1', alpha, DRAWFLAG_NORMAL);
-
+
for ( last = title.chain; last ; )
{
drawstring(last.origin+offset, last.message, gtv_text_size_small, '1 1 1', alpha, DRAWFLAG_NORMAL);
last = last.chain;
remove(next);
}
-
+
remove(picent);
remove(title);
}
text_size = stringwidth(label, false, hud_fontsize);
float theAlpha;
- if (mv_avail[id] != GTV_AVAILABLE && mv_top2_alpha)
+ if (!(mv_flags[id] & GTV_AVAILABLE) && mv_top2_alpha)
theAlpha = mv_top2_alpha;
else
theAlpha = 1;
else
drawborderlines(autocvar_scoreboard_border_thickness, pos, img_size, '0 0 0', theAlpha, DRAWFLAG_NORMAL);
- if(id == mv_selection && mv_avail[id] == GTV_AVAILABLE)
+ if(id == mv_selection && (mv_flags[id] & GTV_AVAILABLE))
drawfill(pos, img_size, '1 1 1', 0.1, DRAWFLAG_NORMAL);
}
if ( mv_selection_keyboard )
return mv_selection;
-
+
return mv_mouse_selection;
}
vector mpos = mv_mousepos + getmousepos();
mpos.x = bound(0, mpos.x, vid_conwidth);
mpos.y = bound(0, mpos.y, vid_conheight);
-
+
if ( mpos.x != mv_mousepos.x || mpos.y != mv_mousepos.y )
mv_selection_keyboard = 0;
mv_mousepos = mpos;
mask = ReadShort();
else
mask = ReadLong();
-
+
for(i = 0, power = 1; i < mv_num_maps; ++i, power *= 2)
- mv_avail[i] = (mask & power) ? GTV_AVAILABLE : GTV_FORBIDDEN;
+ {
+ if ( mask & power )
+ mv_flags[i] |= GTV_AVAILABLE;
+ else
+ mv_flags[i] &= ~GTV_AVAILABLE;
+ }
}
else
{
for(i = 0; i < mv_num_maps; ++i )
- mv_avail[i] = ReadByte();
+ mv_flags[i] = ReadByte();
}
}
mv_timeout = ReadCoord();
gametypevote = ReadByte();
-
+
float mv_real_num_maps = mv_num_maps - mv_abstain;
if(gametypevote)
gtv_text_size = hud_fontsize*1.4;
gtv_text_size_small = hud_fontsize*1.1;
-
+
if (mv_real_num_maps > 8 )
mv_columns = 3;
else
MapVote_ReadMask();
for(i = 0; i < mv_num_maps; ++i )
- mv_avail_start[i] = mv_avail[i];
+ mv_flags_start[i] = mv_flags[i];
// Assume mv_pk3list is world, there should only be 1 mapvote per round
mv_pk3list = world; // I'm still paranoid!
mv_maps[i] = map;
mv_pk3[i] = pk3;
- mv_avail[i] = ReadByte();
+ mv_flags[i] = ReadByte();
if(gametypevote)
{
int MapVote_MoveLeft(int pos)
{
int imp;
- if ( pos < 0 )
+ if ( pos < 0 )
imp = mv_num_maps - 1;
else
imp = pos < 1 ? mv_num_maps - 1 : pos - 1;
- if ( mv_avail[imp] != GTV_AVAILABLE && imp != mv_ownvote )
+ if ( !(mv_flags[imp] & GTV_AVAILABLE) && imp != mv_ownvote )
imp = MapVote_MoveLeft(imp);
return imp;
}
int MapVote_MoveRight(int pos)
{
int imp;
- if ( pos < 0 )
+ if ( pos < 0 )
imp = 0;
else
imp = pos >= mv_num_maps - 1 ? 0 : pos + 1;
- if ( mv_avail[imp] != GTV_AVAILABLE && imp != mv_ownvote )
+ if ( !(mv_flags[imp] & GTV_AVAILABLE) && imp != mv_ownvote )
imp = MapVote_MoveRight(imp);
return imp;
}
int MapVote_MoveUp(int pos)
{
int imp;
- if ( pos < 0 )
+ if ( pos < 0 )
imp = mv_num_maps - 1;
else
{
imp -= mv_columns;
}
}
- if ( mv_avail[imp] != GTV_AVAILABLE && imp != mv_ownvote )
+ if ( !(mv_flags[imp] & GTV_AVAILABLE) && imp != mv_ownvote )
imp = MapVote_MoveUp(imp);
return imp;
}
int MapVote_MoveDown(int pos)
{
int imp;
- if ( pos < 0 )
+ if ( pos < 0 )
imp = 0;
else
{
if ( imp >= mv_num_maps )
imp = imp % mv_columns;
}
- if ( mv_avail[imp] != GTV_AVAILABLE && imp != mv_ownvote )
+ if ( !(mv_flags[imp] & GTV_AVAILABLE) && imp != mv_ownvote )
imp = MapVote_MoveDown(imp);
return imp;
}
int i;
for(i = 0; i < mv_num_maps; ++i)
{
- if(mv_avail[i] == GTV_AVAILABLE)
+ if(mv_flags[i] & GTV_AVAILABLE)
{
if(mv_detail)
mv_votes[i] = ReadByte();