]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
cleanup slist
authorMartin Taibr <taibr.martin@gmail.com>
Sun, 12 Apr 2020 17:56:02 +0000 (19:56 +0200)
committerMartin Taibr <taibr.martin@gmail.com>
Sun, 12 Apr 2020 17:56:02 +0000 (19:56 +0200)
qcsrc/menu/xonotic/serverlist.qc

index 021e9765119d7bf70861a5cdccca8d99c1108280..04b45d0c6228d615eafccd79bfe106147d46cc3a 100644 (file)
@@ -788,33 +788,22 @@ void XonoticServerList_doubleClickListBoxItem(entity me, int i, vector where)
 }
 void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
 {
-       // layout: Ping, Server name, Map name, NP, TP, MP
-       float p;
-       int q;
-       bool isv4, isv6;
-       vector theColor;
-       float theAlpha;
-       bool pure = false, pure_available = false;
-       int freeslots = -1, sflags = -1, j, m;
-       string s, typestr, versionstr, k, v, modname;
-
-       //printf("time: %f, i: %d, item: %d, nitems: %d\n", time, i, item, me.nItems);
-
        vector oldscale = draw_scale;
        vector oldshift = draw_shift;
 #define SET_YRANGE(start,end) \
        draw_scale = boxToGlobalSize(eX + eY * (end - start), oldscale); \
        draw_shift = boxToGlobal(eY * start, oldshift, oldscale);
 
-       for (j = 0; j < category_draw_count; ++j) {
+       int c;
+       for (c = 0; c < category_draw_count; ++c) {
                // Matches exactly the headings with increased height.
-               if (i == category_item[j])
+               if (i == category_item[c])
                        break;
        }
 
-       if (j < category_draw_count)
+       if (c < category_draw_count)
        {
-               entity catent = RetrieveCategoryEnt(category_name[j]);
+               entity catent = RetrieveCategoryEnt(category_name[c]);
                if(catent)
                {
                        SET_YRANGE(
@@ -848,33 +837,34 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is
                draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
        }
 
-       s = gethostcachestring(SLIST_FIELD_QCSTATUS, i);
-       m = tokenizebyseparator(s, ":");
-       typestr = "";
+       string s = gethostcachestring(SLIST_FIELD_QCSTATUS, i);
+       int m = tokenizebyseparator(s, ":");
+       string typestr = "", versionstr = "";
        if(m >= 2)
        {
                typestr = argv(0);
                versionstr = argv(1);
        }
-       freeslots = -1;
-       modname = "";
-       for(j = 2; j < m; ++j)
+       bool pure = false, pure_available = false;
+       int freeslots = -1, sflags = -1;
+       string modname = "";
+       for(int j = 2; j < m; ++j)
        {
                if(argv(j) == "")
                        break;
-               k = substring(argv(j), 0, 1);
-               v = substring(argv(j), 1, -1);
-               if(k == "P")
+               string key = substring(argv(j), 0, 1);
+               string value = substring(argv(j), 1, -1);
+               if(key == "P")
                {
-                       pure = (stof(v) == 0);
+                       pure = (stof(value) == 0);
                        pure_available = true;
                }
-               else if(k == "S")
-                       freeslots = stof(v);
-               else if(k == "F")
-                       sflags = stoi(v);
-               else if(k == "M")
-                       modname = v;
+               else if(key == "S")
+                       freeslots = stof(value);
+               else if(key == "F")
+                       sflags = stoi(value);
+               else if(key == "M")
+                       modname = value;
        }
 
 #ifdef COMPAT_NO_MOD_IS_XONOTIC
@@ -901,6 +891,7 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is
        if(modname != "newtoys")
                pure_available = false;
 
+       float theAlpha;
        if(gethostcachenumber(SLIST_FIELD_FREESLOTS, i) <= 0)
                theAlpha = SKINALPHA_SERVERLIST_FULL;
        else if(freeslots == 0)
@@ -910,18 +901,19 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is
        else
                theAlpha = 1;
 
-       p = gethostcachenumber(SLIST_FIELD_PING, i);
+       float ping = gethostcachenumber(SLIST_FIELD_PING, i);
        const int PING_LOW = 75;
        const int PING_MED = 200;
        const int PING_HIGH = 500;
-       if(p < PING_LOW)
-               theColor = SKINCOLOR_SERVERLIST_LOWPING + (SKINCOLOR_SERVERLIST_MEDPING - SKINCOLOR_SERVERLIST_LOWPING) * (p / PING_LOW);
-       else if(p < PING_MED)
-               theColor = SKINCOLOR_SERVERLIST_MEDPING + (SKINCOLOR_SERVERLIST_HIGHPING - SKINCOLOR_SERVERLIST_MEDPING) * ((p - PING_LOW) / (PING_MED - PING_LOW));
-       else if(p < PING_HIGH)
+       vector theColor;
+       if(ping < PING_LOW)
+               theColor = SKINCOLOR_SERVERLIST_LOWPING + (SKINCOLOR_SERVERLIST_MEDPING - SKINCOLOR_SERVERLIST_LOWPING) * (ping / PING_LOW);
+       else if(ping < PING_MED)
+               theColor = SKINCOLOR_SERVERLIST_MEDPING + (SKINCOLOR_SERVERLIST_HIGHPING - SKINCOLOR_SERVERLIST_MEDPING) * ((ping - PING_LOW) / (PING_MED - PING_LOW));
+       else if(ping < PING_HIGH)
        {
                theColor = SKINCOLOR_SERVERLIST_HIGHPING;
-               theAlpha *= 1 + (SKINALPHA_SERVERLIST_HIGHPING - 1) * ((p - PING_MED) / (PING_HIGH - PING_MED));
+               theAlpha *= 1 + (SKINALPHA_SERVERLIST_HIGHPING - 1) * ((ping - PING_MED) / (PING_HIGH - PING_MED));
        }
        else
        {
@@ -937,7 +929,7 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is
 
        s = gethostcachestring(SLIST_FIELD_CNAME, i);
 
-       isv4 = isv6 = false;
+       bool isv4 = false, isv6 = false;
        if(substring(s, 0, 1) == "[")
        {
                isv6 = true;
@@ -949,27 +941,27 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is
                me.seenIPv4 += 1;
        }
 
-       q = stof(substring(crypto_getencryptlevel(s), 0, 1));
-       if((q <= 0 && cvar("crypto_aeslevel") >= 3) || (q >= 3 && cvar("crypto_aeslevel") <= 0))
+       int crypto = stof(substring(crypto_getencryptlevel(s), 0, 1));
+       if((crypto <= 0 && cvar("crypto_aeslevel") >= 3) || (crypto >= 3 && cvar("crypto_aeslevel") <= 0))
        {
                theColor = SKINCOLOR_SERVERLIST_IMPOSSIBLE;
                theAlpha = SKINALPHA_SERVERLIST_IMPOSSIBLE;
        }
 
-       if(q == 1)
+       if(crypto == 1)
        {
                if(cvar("crypto_aeslevel") >= 2)
-                       q |= 4;
+                       crypto |= 4;
        }
-       if(q == 2)
+       if(crypto == 2)
        {
                if(cvar("crypto_aeslevel") >= 1)
-                       q |= 4;
+                       crypto |= 4;
        }
-       if(q == 3)
-               q = 5;
-       else if(q >= 3)
-               q -= 2;
+       if(crypto == 3)
+               crypto = 5;
+       else if(crypto >= 3)
+               crypto -= 2;
        // possible status:
        // 0: crypto off
        // 1: AES possible
@@ -1001,8 +993,8 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is
        iconPos.x += iconSize.x;
 
        // AES
-       if(q > 0)
-               draw_Picture(iconPos, strcat("icon_aeslevel", ftos(q)), iconSize, '1 1 1', 1);
+       if(crypto > 0)
+               draw_Picture(iconPos, strcat("icon_aeslevel", ftos(crypto)), iconSize, '1 1 1', 1);
 
        iconPos.x += iconSize.x;
 
@@ -1040,7 +1032,7 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is
                string t = "";
                if(me.seenIPv4 && me.seenIPv6)
                        t = strcat(t, (isv6) ? "IPv6, " : "IPv4, ");
-               t = strcat(t, _("encryption:"), " ", (q ? sprintf(_("AES level %d"), q) : ZCTX(_("ENC^none"))), ", ");
+               t = strcat(t, _("encryption:"), " ", (crypto ? sprintf(_("AES level %d"), crypto) : ZCTX(_("ENC^none"))), ", ");
                t = strcat(t, sprintf(_("mod: %s"), ((modname == "xonotic") ? ZCTX(_("MOD^Default")) : original_modname)));
                if(pure_available)
                        t = strcat(t, sprintf(" (%s)", (pure) ? _("official settings") : _("modified settings")));
@@ -1053,7 +1045,7 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is
        // --------------
 
        // ping
-       s = ftos(p);
+       s = ftos(ping);
        draw_Text(me.realUpperMargin * eY + (me.columnPingOrigin + me.columnPingSize - draw_TextWidth(s, 0, me.realFontSize)) * eX, s, me.realFontSize, theColor, theAlpha, 0);
 
        // server name