From: Mattia Basaglia Date: Thu, 9 Jul 2015 10:03:51 +0000 (+0200) Subject: Send name and description for customized vote options X-Git-Tag: xonotic-v0.8.1~43^2~5 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=b177a78473fa1aba00950e6b71ec9d6a7eec88ed;p=xonotic%2Fxonotic-data.pk3dir.git Send name and description for customized vote options --- diff --git a/qcsrc/client/mapvoting.qc b/qcsrc/client/mapvoting.qc index bcbf1863a..046def4e1 100644 --- a/qcsrc/client/mapvoting.qc +++ b/qcsrc/client/mapvoting.qc @@ -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) diff --git a/qcsrc/common/constants.qh b/qcsrc/common/constants.qh index 79889d50c..9c998f39a 100644 --- a/qcsrc/common/constants.qh +++ b/qcsrc/common/constants.qh @@ -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 diff --git a/qcsrc/server/mapvoting.qc b/qcsrc/server/mapvoting.qc index 8d5fe604b..952ce5bd0 100644 --- a/qcsrc/server/mapvoting.qc +++ b/qcsrc/server/mapvoting.qc @@ -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);