From: MirceaKitsune Date: Fri, 25 Nov 2011 16:32:56 +0000 (+0200) Subject: Port a code I made in Xonotic, which displays "no preview" images if a map or player... X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=4dcf9dbdb16be58eeb7fc81b634a416d66023a5c;p=voretournament%2Fvoretournament.git Port a code I made in Xonotic, which displays "no preview" images if a map or player model does not have a preview picture (instead of the checker texture). Will not work until I add some preview images too, at a later time --- diff --git a/data/qcsrc/client/Main.qc b/data/qcsrc/client/Main.qc index 43ce8601..d84f6ce5 100644 --- a/data/qcsrc/client/Main.qc +++ b/data/qcsrc/client/Main.qc @@ -182,6 +182,8 @@ void CSQC_Init(void) minimapname = strzone(minimapname); WarpZone_Init(); + + draw_currentSkin = strzone(strcat("gfx/menu/", cvar_string("menu_skin"))); } // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc) diff --git a/data/qcsrc/client/mapvoting.qc b/data/qcsrc/client/mapvoting.qc index bf60a868..655163da 100644 --- a/data/qcsrc/client/mapvoting.qc +++ b/data/qcsrc/client/mapvoting.qc @@ -75,7 +75,10 @@ void MapVote_DrawMapItem(vector pos, float isize, float tsize, string map, strin img_size -= (sbar_border_thickness * 2) * '1 1 0'; if(pic == "") { - drawfill(pos, img_size, '.5 .5 .5', .7, DRAWFLAG_NORMAL); + if(precache_pic(pic) == "") + drawpic(pos, draw_UseSkinFor("nopreview_player"), img_size, '1 1 1', 0.7, DRAWFLAG_NORMAL); + else + drawpic(pos, pic, img_size, '1 1 1', 0.7, DRAWFLAG_NORMAL); } else { diff --git a/data/qcsrc/common/util.qc b/data/qcsrc/common/util.qc index 990e3c4d..bcd8465e 100644 --- a/data/qcsrc/common/util.qc +++ b/data/qcsrc/common/util.qc @@ -79,6 +79,16 @@ void wordwrap_sprint(string s, float l) #endif #endif +#ifndef SVQC +string draw_UseSkinFor(string pic) +{ + if(substring(pic, 0, 1) == "/") + return substring(pic, 1, strlen(pic)-1); + else + return strcat(draw_currentSkin, "/", pic); +} +#endif + string unescape(string in) { local float i, len; diff --git a/data/qcsrc/common/util.qh b/data/qcsrc/common/util.qh index fd4193e7..ec704494 100644 --- a/data/qcsrc/common/util.qh +++ b/data/qcsrc/common/util.qh @@ -17,6 +17,11 @@ void wordwrap_sprint(string s, float l); #endif void wordwrap_cb(string s, float l, void(string) callback) +#ifndef SVQC +string draw_currentSkin; +string draw_UseSkinFor(string pic); +#endif + float GameCommand_Generic(string cmd); // returns TRUE if handled, FALSE otherwise // uses tokenize on its argument! diff --git a/data/qcsrc/menu/draw.qc b/data/qcsrc/menu/draw.qc index 7ab53e2e..ca6f0a29 100644 --- a/data/qcsrc/menu/draw.qc +++ b/data/qcsrc/menu/draw.qc @@ -2,14 +2,6 @@ string draw_mousepointer; vector draw_mousepointer_offset; vector draw_mousepointer_size; -string draw_UseSkinFor(string pic) -{ - if(substring(pic, 0, 1) == "/") - return substring(pic, 1, strlen(pic)-1); - else - return strcat(draw_currentSkin, "/", pic); -} - void draw_setMousePointer(string pic, vector theSize, vector theOffset) { draw_mousepointer = strzone(draw_UseSkinFor(pic)); @@ -61,10 +53,10 @@ vector boxToGlobalSize(vector v, vector theScale) return v; } -void draw_PreloadPicture(string pic) +string draw_PreloadPicture(string pic) { pic = draw_UseSkinFor(pic); - precache_pic(pic); + return precache_pic(pic); } void draw_Picture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha) diff --git a/data/qcsrc/menu/draw.qh b/data/qcsrc/menu/draw.qh index 28fffe73..bea80561 100644 --- a/data/qcsrc/menu/draw.qh +++ b/data/qcsrc/menu/draw.qh @@ -14,7 +14,7 @@ void draw_reset(float cw, float ch, float ox, float oy); void draw_setMousePointer(string pic, vector theSize, vector theOffset); void draw_drawMousePointer(vector where); -void draw_PreloadPicture(string pic); +string draw_PreloadPicture(string pic); void draw_ButtonPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha); void draw_VertButtonPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha); void draw_BorderPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha, vector theBorderSize); @@ -38,7 +38,5 @@ vector globalToBoxSize(vector v, vector scale); float draw_NeedResizeNotify; -string draw_currentSkin; - float draw_TextWidth_WithColors(string s, vector size); float draw_TextWidth_WithoutColors(string s, vector size); diff --git a/data/qcsrc/menu/voret/campaign.c b/data/qcsrc/menu/voret/campaign.c index e3a4315b..ba65cd2c 100644 --- a/data/qcsrc/menu/voret/campaign.c +++ b/data/qcsrc/menu/voret/campaign.c @@ -275,10 +275,13 @@ void drawListBoxItemVoretCampaignList(entity me, float i, vector absSize, float draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); s = ftos(p); - if(i <= me.campaignIndex) - draw_Picture(me.columnPreviewOrigin * eX, strcat("/maps/", campaign_mapname[i]), me.columnPreviewSize * eX + eY, '1 1 1', theAlpha); - else + if(i > me.campaignIndex) draw_Picture(me.columnPreviewOrigin * eX, "/gfx/campaign_hidden", me.columnPreviewSize * eX + eY, '1 1 1', theAlpha); + else if(draw_PreloadPicture(strcat("/maps/", campaign_mapname[i])) == "") + draw_Picture(me.columnPreviewOrigin * eX, "nopreview_map", me.columnPreviewSize * eX + eY, '1 1 1', theAlpha); + else + draw_Picture(me.columnPreviewOrigin * eX, strcat("/maps/", campaign_mapname[i]), me.columnPreviewSize * eX + eY, '1 1 1', theAlpha); + if(i < me.campaignIndex) draw_Picture(me.checkMarkOrigin, "checkmark", me.checkMarkSize, '1 1 1', 1); if(i <= me.campaignIndex) diff --git a/data/qcsrc/menu/voret/dialog_multiplayer_create_mapinfo.c b/data/qcsrc/menu/voret/dialog_multiplayer_create_mapinfo.c index b640ee86..7925b80e 100644 --- a/data/qcsrc/menu/voret/dialog_multiplayer_create_mapinfo.c +++ b/data/qcsrc/menu/voret/dialog_multiplayer_create_mapinfo.c @@ -66,7 +66,10 @@ void loadMapInfoVoretMapInfoDialog(entity me, float i, entity mlb) me.authorLabel.setText(me.authorLabel, me.currentMapAuthor); me.descriptionLabel.setText(me.descriptionLabel, me.currentMapDescription); me.featuresLabel.setText(me.featuresLabel, me.currentMapFeaturesText); - me.previewImage.src = me.currentMapPreviewImage; + if(draw_PreloadPicture(me.currentMapPreviewImage) == "") + me.previewImage.src = "nopreview_map"; + else + me.previewImage.src = me.currentMapPreviewImage; me.typeDeathmatchLabel.disabled = !(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_DEATHMATCH); me.typeTDMLabel.disabled = !(MapInfo_Map_supportedGametypes & MAPINFO_TYPE_TEAM_DEATHMATCH); diff --git a/data/qcsrc/menu/voret/maplist.c b/data/qcsrc/menu/voret/maplist.c index 413b0b46..d4b77c39 100644 --- a/data/qcsrc/menu/voret/maplist.c +++ b/data/qcsrc/menu/voret/maplist.c @@ -186,7 +186,11 @@ void drawListBoxItemVoretMapList(entity me, float i, vector absSize, float isSel draw_Fill('0 0 0', '1 1 0', SKINCOLOR_MAPLIST_INCLUDEDBG, SKINALPHA_MAPLIST_INCLUDEDBG); s = ftos(p); - draw_Picture(me.columnPreviewOrigin * eX, strcat("/maps/", MapInfo_Map_bspname), me.columnPreviewSize * eX + eY, '1 1 1', theAlpha); + if(draw_PreloadPicture(strcat("/maps/", MapInfo_Map_bspname)) == "") + draw_Picture(me.columnPreviewOrigin * eX, "nopreview_map", me.columnPreviewSize * eX + eY, '1 1 1', theAlpha); + else + draw_Picture(me.columnPreviewOrigin * eX, strcat("/maps/", MapInfo_Map_bspname), me.columnPreviewSize * eX + eY, '1 1 1', theAlpha); + if(included) draw_Picture(me.checkMarkOrigin, "checkmark", me.checkMarkSize, '1 1 1', 1); s = draw_TextShortenToWidth(strcat(MapInfo_Map_bspname, ": ", MapInfo_Map_title), me.columnNameSize, 0, me.realFontSize); diff --git a/data/qcsrc/menu/voret/playermodel.c b/data/qcsrc/menu/voret/playermodel.c index fb48f1a2..639f625d 100644 --- a/data/qcsrc/menu/voret/playermodel.c +++ b/data/qcsrc/menu/voret/playermodel.c @@ -176,7 +176,10 @@ void drawVoretPlayerModelSelector(entity me) float i, n; vector o; - me.src = me.currentModelName; + if(draw_PreloadPicture(me.currentModelName) == "") + me.src = "nopreview_player"; + else + me.src = me.currentModelName; drawImage(me); me.src = string_null;