]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Hide the map bsp file name if it is equal to the title other than for trivial changes
authorRudolf Polzer <divVerent@xonotic.org>
Wed, 24 Aug 2011 08:23:50 +0000 (10:23 +0200)
committerRudolf Polzer <divVerent@xonotic.org>
Wed, 24 Aug 2011 08:23:50 +0000 (10:23 +0200)
Should make the menu look better

qcsrc/common/mapinfo.qc
qcsrc/common/mapinfo.qh
qcsrc/menu/xonotic/maplist.c

index cca716a339abb4bc3cd78bbc2af6b7af2fd224a5..366538de71b0346b013d36b32fd7a3315fa0e1ad 100644 (file)
@@ -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 = "<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;
index 2ce5d60c9032eb4136652baf42be37ad5fbb98e1..3eb16d8544b11835f4f272811aef53bbd66a3a5a 100644 (file)
@@ -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
index 6991667763c82225b98aeae199b05dcd7a3e3f96..9ce298082c2fca2f236ba1ea987ebe001005a1f4 100644 (file)
@@ -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);