Send name and description for customized vote options
authorMattia Basaglia <mattia.basaglia@gmail.com>
Thu, 9 Jul 2015 10:03:51 +0000 (12:03 +0200)
committerMattia Basaglia <mattia.basaglia@gmail.com>
Thu, 9 Jul 2015 10:03:51 +0000 (12:03 +0200)
qcsrc/client/mapvoting.qc
qcsrc/common/constants.qh
qcsrc/server/mapvoting.qc

index bcbf186..046def4 100644 (file)
@@ -514,11 +514,47 @@ void MapVote_ReadMask()
        }
 }
 
-void MapVote_Init()
+void MapVote_ReadOption(int i)
 {
-       int i, j;
-       string map, pk3, s;
+       string map = strzone(ReadString());
+       string pk3 = strzone(ReadString());
+       int j = bound(0, ReadByte(), n_ssdirs - 1);
+
+       mv_maps[i] = map;
+       mv_pk3[i] = pk3;
+       mv_flags[i] = GTV_AVAILABLE;
+
+       string pic = strzone(strcat(ssdirs[j], "/", map));
+       mv_pics[i] = pic;
+       mv_preview[i] = false;
+       MapVote_CheckPic(pic, pk3, i);
+}
+
+void GameTypeVote_ReadOption(int i)
+{
+       dprint(sprintf("\n\n^3==========\nReading %d\n\n",i));
+       string gt = strzone(ReadString());
+
+       mv_maps[i] = gt;
+       mv_pk3[i] = string_null;
+       mv_flags[i] = ReadByte();
+
+       string mv_picpath = sprintf("gfx/menu/%s/gametype_%s", autocvar_menu_skin, gt);
+       if(precache_pic(mv_picpath) == "")
+               mv_picpath = strcat("gfx/menu/default/gametype_", gt);
+       string pic = strzone(mv_picpath);
+       mv_pics[i] = pic;
+       mv_preview[i] = PreviewExists(pic);
+
+       if ( mv_flags[i] & GTV_CUSTOM )
+       {
+               ReadString(); // name
+               ReadString(); // description
+       }
+}
 
+void MapVote_Init()
+{
        precache_sound ("misc/invshot.wav");
 
        mv_active = 1;
@@ -527,6 +563,7 @@ void MapVote_Init()
        mv_selection = -1;
        mv_selection_keyboard = 0;
 
+       string s;
        for(n_ssdirs = 0; ; ++n_ssdirs)
        {
                s = ReadString();
@@ -577,6 +614,7 @@ void MapVote_Init()
        }
 
        MapVote_ReadMask();
+       int i;
        for(i = 0; i < mv_num_maps; ++i )
                mv_flags_start[i] = mv_flags[i];
 
@@ -587,32 +625,10 @@ void MapVote_Init()
        {
                mv_votes[i] = 0;
 
-               map = strzone(ReadString());
-               pk3 = strzone(ReadString());
-               j = bound(0, ReadByte(), n_ssdirs - 1);
-
-               mv_maps[i] = map;
-               mv_pk3[i] = pk3;
-               mv_flags[i] = ReadByte();
-
-               if(gametypevote)
-               {
-                       //map = strzone(strcat("gfx/menu/default/gametype_", map));
-                       //map = strzone(sprintf("gfx/menu/%s/gametype_%s", autocvar_menu_skin, map));
-                       string mv_picpath = sprintf("gfx/menu/%s/gametype_%s", autocvar_menu_skin, map);
-                       if(precache_pic(mv_picpath) == "")
-                               mv_picpath = strcat("gfx/menu/default/gametype_", map);
-                       map = strzone(mv_picpath);
-                       mv_pics[i] = map;
-                       mv_preview[i] = PreviewExists(map);
-               }
+               if ( gametypevote )
+                       GameTypeVote_ReadOption(i);
                else
-               {
-                       map = strzone(strcat(ssdirs[j], "/", map));
-                       mv_pics[i] = map;
-                       mv_preview[i] = false;
-                       MapVote_CheckPic(map, pk3, i);
-               }
+                       MapVote_ReadOption(i);
        }
 
        for(i = 0; i < n_ssdirs; ++i)
index 79889d5..9c998f3 100644 (file)
@@ -323,4 +323,5 @@ const int URI_GET_URLLIB_END = 191;
 // gametype vote flags
 const int GTV_FORBIDDEN = 0; // Cannot be voted
 const int GTV_AVAILABLE = 1; // Can be voted
+const int GTV_CUSTOM    = 2; // Custom entry
 #endif
index 8d5fe60..952ce5b 100644 (file)
@@ -51,21 +51,30 @@ float GameTypeVote_Type_FromString(string type_name)
        return type;
 }
 
-int GameTypeVote_AvailabilityStatus(string gtname)
+int GameTypeVote_AvailabilityStatus(string type_name)
 {
-       float type = GameTypeVote_Type_FromString(gtname);
+       int flag = GTV_FORBIDDEN;
+
+       float type = MapInfo_Type_FromString(type_name);
+       if ( type == 0 )
+       {
+               type = MapInfo_Type_FromString(cvar_string(
+                       strcat("sv_vote_gametype_",type_name,"_type")));
+               flag |= GTV_CUSTOM;
+       }
+
        if( type == 0 )
-               return GTV_FORBIDDEN;
+               return flag;
 
        if ( autocvar_nextmap != "" )
        {
                if ( !MapInfo_Get_ByName(autocvar_nextmap, false, 0) )
-                       return GTV_FORBIDDEN;
+                       return flag;
                if (!(MapInfo_Map_supportedGametypes & type))
-                       return GTV_FORBIDDEN;
+                       return flag;
        }
 
-       return GTV_AVAILABLE;
+       return flag | GTV_AVAILABLE;
 }
 
 float GameTypeVote_GetMask()
@@ -288,6 +297,52 @@ void MapVote_WriteMask()
        }
 }
 
+/*
+ * Sends a single map vote option to the client
+ */
+void MapVote_SendOption(int i)
+{
+       // abstain
+       if(mapvote_abstain && i == mapvote_count - 1)
+       {
+               WriteString(MSG_ENTITY, ""); // abstain needs no text
+               WriteString(MSG_ENTITY, ""); // abstain needs no pack
+               WriteByte(MSG_ENTITY, 0); // abstain needs no screenshot dir
+       }
+       else
+       {
+               WriteString(MSG_ENTITY, mapvote_maps[i]);
+               WriteString(MSG_ENTITY, mapvote_maps_pakfile[i]);
+               WriteByte(MSG_ENTITY, mapvote_maps_screenshot_dir[i]);
+       }
+}
+
+/*
+ * Sends a single gametype vote option to the client
+ */
+void GameTypeVote_SendOption(int i)
+{
+       // abstain
+       if(mapvote_abstain && i == mapvote_count - 1)
+       {
+               WriteString(MSG_ENTITY, ""); // abstain needs no text
+               WriteByte(MSG_ENTITY, GTV_AVAILABLE);
+       }
+       else
+       {
+               string type_name = mapvote_maps[i];
+               WriteString(MSG_ENTITY, type_name);
+               WriteByte(MSG_ENTITY, mapvote_maps_flags[i]);
+               if ( mapvote_maps_flags[i] & GTV_CUSTOM )
+               {
+                       WriteString(MSG_ENTITY, cvar_string(
+                               strcat("sv_vote_gametype_",type_name,"_name")));
+                       WriteString(MSG_ENTITY, cvar_string(
+                               strcat("sv_vote_gametype_",type_name,"_description")));
+               }
+       }
+}
+
 float MapVote_SendEntity(entity to, int sf)
 {
        float i;
@@ -317,7 +372,7 @@ float MapVote_SendEntity(entity to, int sf)
                }
                else if ( autocvar_sv_vote_gametype )
                {
-                        // map vote but gametype has been chosen via voting screen
+                       // map vote but gametype has been chosen via voting screen
                        WriteByte(MSG_ENTITY, 2);
                        WriteString(MSG_ENTITY, MapInfo_Type_ToText(MapInfo_CurrentGametype()));
                }
@@ -329,20 +384,10 @@ float MapVote_SendEntity(entity to, int sf)
                // Send data for the vote options
                for(i = 0; i < mapvote_count; ++i)
                {
-                       if(mapvote_abstain && i == mapvote_count - 1)
-                       {
-                               WriteString(MSG_ENTITY, ""); // abstain needs no text
-                               WriteString(MSG_ENTITY, ""); // abstain needs no pack
-                               WriteByte(MSG_ENTITY, 0); // abstain needs no screenshot dir
-                               WriteByte(MSG_ENTITY, GTV_AVAILABLE);
-                       }
+                       if(gametypevote)
+                               GameTypeVote_SendOption(i);
                        else
-                       {
-                               WriteString(MSG_ENTITY, mapvote_maps[i]);
-                               WriteString(MSG_ENTITY, mapvote_maps_pakfile[i]);
-                               WriteByte(MSG_ENTITY, mapvote_maps_screenshot_dir[i]);
-                               WriteByte(MSG_ENTITY, mapvote_maps_flags[i]);
-                       }
+                               MapVote_SendOption(i);
                }
        }
 
@@ -356,7 +401,7 @@ float MapVote_SendEntity(entity to, int sf)
        {
                if(mapvote_detail)
                        for(i = 0; i < mapvote_count; ++i)
-                               if ( mapvote_maps_flags[i] == GTV_AVAILABLE )
+                               if ( mapvote_maps_flags[i] & GTV_AVAILABLE )
                                        WriteByte(MSG_ENTITY, mapvote_selections[i]);
 
                WriteByte(MSG_ENTITY, to.mapvote);