From cb67dc78c81fe79e704952b6cd056353af24bb68 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Wed, 24 Aug 2011 10:23:50 +0200 Subject: [PATCH] Hide the map bsp file name if it is equal to the title other than for trivial changes Should make the menu look better --- qcsrc/common/mapinfo.qc | 37 +++++++++++++++++++++++++++++++++++- qcsrc/common/mapinfo.qh | 1 + qcsrc/menu/xonotic/maplist.c | 2 +- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/qcsrc/common/mapinfo.qc b/qcsrc/common/mapinfo.qc index cca716a33..366538de7 100644 --- a/qcsrc/common/mapinfo.qc +++ b/qcsrc/common/mapinfo.qc @@ -49,6 +49,7 @@ void MapInfo_Cache_Store() // now store all the stuff bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, i, MapInfo_Map_bspname); bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, ++i, MapInfo_Map_title); + bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, ++i, MapInfo_Map_titlestring); bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, ++i, MapInfo_Map_description); bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, ++i, MapInfo_Map_author); bufstr_set(_MapInfo_Cache_Buf_IndexToMapData, ++i, ftos(MapInfo_Map_supportedGametypes)); @@ -71,6 +72,7 @@ float MapInfo_Cache_Retrieve(string map) // now retrieve all the stuff MapInfo_Map_bspname = bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, i); MapInfo_Map_title = bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, ++i); + MapInfo_Map_titlestring = bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, ++i); MapInfo_Map_description = bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, ++i); MapInfo_Map_author = bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, ++i); MapInfo_Map_supportedGametypes = stof(bufstr_get(_MapInfo_Cache_Buf_IndexToMapData, ++i)); @@ -379,6 +381,7 @@ float _MapInfo_Generate(string pFilename) // 0: failure, 1: ok ent, 2: ok bsp void _MapInfo_Map_Reset() { MapInfo_Map_title = ""; + MapInfo_Map_titlestring = "<TITLE>"; MapInfo_Map_description = "<DESCRIPTION>"; MapInfo_Map_author = "<AUTHOR>"; MapInfo_Map_supportedGametypes = 0; @@ -797,6 +800,30 @@ void _MapInfo_Parse_Settemp(string pFilename, string acl, float type, string s, } } +float MapInfo_isRedundant(string fn, string t) +{ + // normalize file name + fn = strreplace("_", "-", fn); + + // normalize visible title + t = strreplace(": ", "-", t); + t = strreplace(":", "-", t); + t = strreplace(" ", "-", t); + t = strreplace("_", "-", t); + + if(!strcasecmp(fn, t)) + return TRUE; + + // we allow the visible title to have punctuation the file name does + // not, but not vice versa + t = strreplace("-", "", t); + + if(!strcasecmp(fn, t)) + return TRUE; + + return FALSE; +} + // load info about a map by name into the MapInfo_Map_* globals float MapInfo_Get_ByName(string pFilename, float pAllowGenerate, float pGametypeToSet) { @@ -1056,7 +1083,14 @@ float MapInfo_Get_ByName(string pFilename, float pAllowGenerate, float pGametype } } - MapInfo_Cache_Store(); + if(MapInfo_Map_titlestring == "<TITLE>") + MapInfo_Map_titlestring = MapInfo_Map_bspname; + else if(MapInfo_isRedundant(MapInfo_Map_bspname, MapInfo_Map_title)) + MapInfo_Map_titlestring = MapInfo_Map_title; + else + MapInfo_Map_titlestring = sprintf(_("%s: %s"), MapInfo_Map_bspname, MapInfo_Map_title); + + MapInfo_cache_Store(); if(MapInfo_Map_supportedGametypes != 0) return r; dprint("Map ", pFilename, " supports no game types, ignored\n"); @@ -1313,6 +1347,7 @@ void MapInfo_ClearTemps() { MapInfo_Map_bspname = string_null; MapInfo_Map_title = string_null; + MapInfo_Map_titlestring = string_null; MapInfo_Map_description = string_null; MapInfo_Map_author = string_null; MapInfo_Map_clientstuff = string_null; diff --git a/qcsrc/common/mapinfo.qh b/qcsrc/common/mapinfo.qh index 2ce5d60c9..3eb16d854 100644 --- a/qcsrc/common/mapinfo.qh +++ b/qcsrc/common/mapinfo.qh @@ -27,6 +27,7 @@ float MapInfo_count; // info about a map that MapInfo loads string MapInfo_Map_bspname; string MapInfo_Map_title; +string MapInfo_Map_titlestring; // either bspname: title or just title, depending on whether bspname is redundant string MapInfo_Map_description; string MapInfo_Map_author; string MapInfo_Map_clientstuff; // not in cache, only for map load diff --git a/qcsrc/menu/xonotic/maplist.c b/qcsrc/menu/xonotic/maplist.c index 699166776..9ce298082 100644 --- a/qcsrc/menu/xonotic/maplist.c +++ b/qcsrc/menu/xonotic/maplist.c @@ -189,7 +189,7 @@ void XonoticMapList_drawListBoxItem(entity me, float i, vector absSize, float is 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); + s = draw_TextShortenToWidth(MapInfo_Map_titlestring, me.columnNameSize, 0, me.realFontSize); draw_Text(me.realUpperMargin1 * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, SKINCOLOR_MAPLIST_TITLE, theAlpha, 0); s = draw_TextShortenToWidth(MapInfo_Map_author, me.columnNameSize, 0, me.realFontSize); draw_Text(me.realUpperMargin2 * eY + (me.columnNameOrigin + 1.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, SKINCOLOR_MAPLIST_AUTHOR, theAlpha, 0); -- 2.39.2