]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/xonotic/maplist.qc
micro-optimization chore: in for-loops change all post-{in,de}crements to pre-{in...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / maplist.qc
index 111744e9668da9e0b3909f7c97e15c8f01062e72..89748e85c3647dda4ac36afc3c06e08e83f3a166 100644 (file)
@@ -79,7 +79,8 @@ void XonoticMapList_g_maplistCacheToggle(entity me, float i)
 void XonoticMapList_draw(entity me)
 {
        if(me.startButton)
-               me.startButton.disabled = ((me.selectedItem < 0) || (me.selectedItem >= me.nItems));
+               me.startButton.disabled = ((me.selectedItem < 0) || (me.selectedItem >= me.nItems)
+                       || ((gamestatus & (GAME_ISSERVER | GAME_CONNECTED)) && cvar("g_campaign")));
        SUPER(XonoticMapList).draw(me);
 }
 
@@ -88,8 +89,10 @@ void XonoticMapList_resizeNotify(entity me, vector relOrigin, vector relSize, ve
        me.itemAbsSize = '0 0 0';
        SUPER(XonoticMapList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
 
-       me.realFontSize_y = me.fontSize / (me.itemAbsSize_y = (absSize.y * me.itemHeight));
-       me.realFontSize_x = me.fontSize / (me.itemAbsSize_x = (absSize.x * (1 - me.controlWidth)));
+       me.itemAbsSize.y = absSize.y * me.itemHeight;
+       me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
+       me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
+       me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
        me.realUpperMargin1 = 0.5 * (1 - 2.5 * me.realFontSize.y);
        me.realUpperMargin2 = me.realUpperMargin1 + 1.5 * me.realFontSize.y;
 
@@ -154,7 +157,12 @@ void XonoticMapList_drawListBoxItem(entity me, int i, vector absSize, bool isSel
        }
 
        if(draw_PictureSize(strcat("/maps/", MapInfo_Map_bspname)) == '0 0 0')
-               draw_Picture(me.columnPreviewOrigin * eX, "nopreview_map", me.columnPreviewSize * eX + eY, '1 1 1', theAlpha);
+       {
+               if(!draw_PictureExists(strcat("/levelshots/", 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("/levelshots/", MapInfo_Map_bspname), 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);
 
@@ -181,8 +189,6 @@ void XonoticMapList_refilter(entity me)
 
        for(i = 0; i < MapInfo_count; ++i)
                draw_PreloadPicture(strcat("/maps/", MapInfo_BSPName_ByID(i)));
-       if(me.g_maplistCache)
-               strunzone(me.g_maplistCache);
        s = "0";
        for(i = 1; i < MapInfo_count; i *= 2)
                s = strcat(s, s);
@@ -201,7 +207,7 @@ void XonoticMapList_refilter(entity me)
                                );
                }
        }
-       me.g_maplistCache = strzone(s);
+       strcpy(me.g_maplistCache, s);
        if(gt != me.lastGametype || f != me.lastFeatures)
        {
                me.lastGametype = gt;
@@ -217,12 +223,9 @@ void XonoticMapList_refilterCallback(entity me, entity cb)
 
 void MapList_StringFilterBox_Change(entity box, entity me)
 {
-       if(me.stringFilter)
-               strunzone(me.stringFilter);
+       strfree(me.stringFilter);
        if(box.text != "")
                me.stringFilter = strzone(box.text);
-       else
-               me.stringFilter = string_null;
 
        me.refilter(me);
 }
@@ -231,7 +234,7 @@ void MapList_Add_Shown(entity btn, entity me)
 {
        float i, n;
        n = strlen(me.g_maplistCache);
-       for (i = 0 ; i < n; i++)
+       for (i = 0 ; i < n; ++i)
        {
                if (!me.g_maplistCacheQuery(me, i))
                        me.g_maplistCacheToggle(me, i);
@@ -243,7 +246,7 @@ void MapList_Remove_Shown(entity btn, entity me)
 {
        float i, n;
        n = strlen(me.g_maplistCache);
-       for (i = 0 ; i < n; i++)
+       for (i = 0 ; i < n; ++i)
        {
                if (me.g_maplistCacheQuery(me, i))
                        me.g_maplistCacheToggle(me, i);
@@ -345,9 +348,7 @@ float XonoticMapList_keyDown(entity me, float scan, float ascii, float shift)
                if(time < me.typeToSearchTime)
                {
                        save = substring(me.typeToSearchString, 0, strlen(me.typeToSearchString) - 1);
-                       if(me.typeToSearchString)
-                               strunzone(me.typeToSearchString);
-                       me.typeToSearchString = strzone(save);
+                       strcpy(me.typeToSearchString, save);
                        me.typeToSearchTime = time + 0.5;
                        if(strlen(me.typeToSearchString))
                        {
@@ -364,19 +365,17 @@ float XonoticMapList_keyDown(entity me, float scan, float ascii, float shift)
                        save = ch;
                else
                        save = strcat(me.typeToSearchString, ch);
-               if(me.typeToSearchString)
-                       strunzone(me.typeToSearchString);
-               me.typeToSearchString = strzone(save);
+               strcpy(me.typeToSearchString, save);
                me.typeToSearchTime = time + 0.5;
                MapInfo_FindName(me.typeToSearchString);
                if(MapInfo_FindName_firstResult >= 0)
                        me.setSelected(me, MapInfo_FindName_firstResult);
        }
-       else if(shift & S_CTRL && scan == 'f') // ctrl-f (as in "F"ind)
+       else if((shift & S_CTRL) && scan == 'f') // ctrl-f (as in "F"ind)
        {
                me.parent.setFocus(me.parent, me.stringFilterBox);
        }
-       else if(shift & S_CTRL && scan == 'u') // ctrl-u (remove stringFilter line
+       else if((shift & S_CTRL) && scan == 'u') // ctrl-u (remove stringFilter line
        {
                me.stringFilterBox.setText(me.stringFilterBox, "");
                MapList_StringFilterBox_Change(me.stringFilterBox, me);