]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/xonotic/serverlist.c
Merge remote-tracking branch 'origin/master' into samual/serverlist
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / serverlist.c
index 9e49626023375b96651e5fa13bc4c2e50d0f6c54..0a3fd91db6914cae0801f1d9ac8fc7828570055d 100644 (file)
@@ -57,6 +57,7 @@ CLASS(XonoticServerList) EXTENDS(XonoticListBox)
        ATTRIB(XonoticServerList, seenIPv6, float, 0)
 ENDCLASS(XonoticServerList)
 entity makeXonoticServerList();
+
 void ServerList_Connect_Click(entity btn, entity me);
 void ServerList_ShowEmpty_Click(entity box, entity me);
 void ServerList_ShowFull_Click(entity box, entity me);
@@ -65,6 +66,7 @@ void ServerList_Favorite_Click(entity btn, entity me);
 void ServerList_Info_Click(entity btn, entity me);
 void ServerList_Update_favoriteButton(entity btn, entity me);
 
+#ifndef IMPLEMENTATION
 float SLIST_FIELD_CNAME;
 float SLIST_FIELD_PING;
 float SLIST_FIELD_GAME;
@@ -82,6 +84,8 @@ float SLIST_FIELD_QCSTATUS;
 float SLIST_FIELD_ISFAVORITE;
 #endif
 
+#endif
+
 #ifdef IMPLEMENTATION
 void ServerList_UpdateFieldIDs()
 {
@@ -214,8 +218,8 @@ void XonoticServerList_setSelected(entity me, float i)
        */
        if(me.nItems == 0)
                return;
-       if(gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT) != me.nItems)
-               return; // sorry, it would be wrong
+       //if(gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT) != me.nItems)
+       //      return; // sorry, it would be wrong
 
        if(me.selectedServer)
                strunzone(me.selectedServer);
@@ -319,6 +323,7 @@ void XonoticServerList_focusEnter(entity me)
        me.nextRefreshTime = time + 10;
        me.refreshServerList(me, 1);
 }
+float category_drawn;
 void XonoticServerList_draw(entity me)
 {
        float i, found, owned;
@@ -347,7 +352,7 @@ void XonoticServerList_draw(entity me)
 
        owned = ((me.selectedServer == me.ipAddressBox.text) && (me.ipAddressBox.text != ""));
 
-       me.nItems = gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT);
+       me.nItems = gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT) + 1;
 
        me.connectButton.disabled = ((me.nItems == 0) && (me.ipAddressBox.text == ""));
        me.infoButton.disabled = ((me.nItems == 0) || !owned);
@@ -395,6 +400,7 @@ void XonoticServerList_draw(entity me)
                me.ipAddressBoxFocused = me.ipAddressBox.focused;
        }
 
+       category_drawn = 0;
        SUPER(XonoticServerList).draw(me);
 }
 void ServerList_PingSort_Click(entity btn, entity me)
@@ -593,6 +599,7 @@ void XonoticServerList_clickListBoxItem(entity me, float i, vector where)
        me.lastClickedServer = i;
        me.lastClickedTime = time;
 }
+float category_drawn;
 void XonoticServerList_drawListBoxItem(entity me, float i, vector absSize, float isSelected)
 {
        // layout: Ping, Server name, Map name, NP, TP, MP
@@ -603,10 +610,24 @@ void XonoticServerList_drawListBoxItem(entity me, float i, vector absSize, float
        float m, pure, freeslots, j, sflags;
        string s, typestr, versionstr, k, v, modname;
 
+       float cache = i;
+
+       if(category_drawn)
+       {
+               cache -= 1;
+               print(sprintf("time: %f, category_drawn: %d, i: %d, cache: %d, nitems: %d\n", time, category_drawn, i, cache, me.nItems));
+       }
+       else
+       {
+               draw_Text(me.realUpperMargin * eY + (me.columnNameOrigin + (me.columnNameSize - draw_TextWidth("category", 0, me.realFontSize)) * 0.5) * eX, "category", me.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
+               print(sprintf("time: %f, category_drawn: %d, i: %d, cache: %d, nitems: %d\n", time, category_drawn, i, cache, me.nItems));
+               category_drawn = TRUE;
+               return;
+       }
        if(isSelected)
                draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
 
-       s = gethostcachestring(SLIST_FIELD_QCSTATUS, i);
+       s = gethostcachestring(SLIST_FIELD_QCSTATUS, cache);
        m = tokenizebyseparator(s, ":");
        typestr = "";
        if(m >= 2)
@@ -641,7 +662,7 @@ void XonoticServerList_drawListBoxItem(entity me, float i, vector absSize, float
 
        /*
        SLIST_FIELD_MOD = gethostcacheindexforkey("mod");
-       s = gethostcachestring(SLIST_FIELD_MOD, i);
+       s = gethostcachestring(SLIST_FIELD_MOD, cache);
        if(s != "data")
                if(modname == "Xonotic")
                        modname = s;
@@ -655,16 +676,16 @@ void XonoticServerList_drawListBoxItem(entity me, float i, vector absSize, float
        if(modname != "NewToys")
                pure = 0;
 
-       if(gethostcachenumber(SLIST_FIELD_FREESLOTS, i) <= 0)
+       if(gethostcachenumber(SLIST_FIELD_FREESLOTS, cache) <= 0)
                theAlpha = SKINALPHA_SERVERLIST_FULL;
        else if(freeslots == 0)
                theAlpha = SKINALPHA_SERVERLIST_FULL; // g_maxplayers support
-       else if not(gethostcachenumber(SLIST_FIELD_NUMHUMANS, i))
+       else if not(gethostcachenumber(SLIST_FIELD_NUMHUMANS, cache))
                theAlpha = SKINALPHA_SERVERLIST_EMPTY;
        else
                theAlpha = 1;
 
-       p = gethostcachenumber(SLIST_FIELD_PING, i);
+       p = gethostcachenumber(SLIST_FIELD_PING, cache);
 #define PING_LOW 75
 #define PING_MED 200
 #define PING_HIGH 500
@@ -683,13 +704,13 @@ void XonoticServerList_drawListBoxItem(entity me, float i, vector absSize, float
                theAlpha *= SKINALPHA_SERVERLIST_HIGHPING;
        }
 
-       if(gethostcachenumber(SLIST_FIELD_ISFAVORITE, i))
+       if(gethostcachenumber(SLIST_FIELD_ISFAVORITE, cache))
        {
                theColor = theColor * (1 - SKINALPHA_SERVERLIST_FAVORITE) + SKINCOLOR_SERVERLIST_FAVORITE * SKINALPHA_SERVERLIST_FAVORITE;
                theAlpha = theAlpha * (1 - SKINALPHA_SERVERLIST_FAVORITE) + SKINALPHA_SERVERLIST_FAVORITE;
        }
 
-       s = gethostcachestring(SLIST_FIELD_CNAME, i);
+       s = gethostcachestring(SLIST_FIELD_CNAME, cache);
 
        isv4 = isv6 = 0;
        if(substring(s, 0, 1) == "[")
@@ -796,13 +817,13 @@ void XonoticServerList_drawListBoxItem(entity me, float i, vector absSize, float
 
        s = ftos(p);
        draw_Text(me.realUpperMargin * eY + (me.columnPingOrigin + me.columnPingSize - draw_TextWidth(s, 0, me.realFontSize)) * eX, s, me.realFontSize, theColor, theAlpha, 0);
-       s = draw_TextShortenToWidth(gethostcachestring(SLIST_FIELD_NAME, i), me.columnNameSize, 0, me.realFontSize);
+       s = draw_TextShortenToWidth(gethostcachestring(SLIST_FIELD_NAME, cache), me.columnNameSize, 0, me.realFontSize);
        draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
-       s = draw_TextShortenToWidth(gethostcachestring(SLIST_FIELD_MAP, i), me.columnMapSize, 0, me.realFontSize);
+       s = draw_TextShortenToWidth(gethostcachestring(SLIST_FIELD_MAP, cache), me.columnMapSize, 0, me.realFontSize);
        draw_Text(me.realUpperMargin * eY + (me.columnMapOrigin + (me.columnMapSize - draw_TextWidth(s, 0, me.realFontSize)) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0);
        s = draw_TextShortenToWidth(typestr, me.columnTypeSize, 0, me.realFontSize);
        draw_Text(me.realUpperMargin * eY + (me.columnTypeOrigin + (me.columnTypeSize - draw_TextWidth(s, 0, me.realFontSize)) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0);
-       s = strcat(ftos(gethostcachenumber(SLIST_FIELD_NUMHUMANS, i)), "/", ftos(gethostcachenumber(SLIST_FIELD_MAXPLAYERS, i)));
+       s = strcat(ftos(gethostcachenumber(SLIST_FIELD_NUMHUMANS, cache)), "/", ftos(gethostcachenumber(SLIST_FIELD_MAXPLAYERS, cache)));
        draw_Text(me.realUpperMargin * eY + (me.columnPlayersOrigin + (me.columnPlayersSize - draw_TextWidth(s, 0, me.realFontSize)) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0);
 }