X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fmenu%2Fxonotic%2Fserverlist.c;h=0a3fd91db6914cae0801f1d9ac8fc7828570055d;hb=49af10f3413b96e52055359d42288dbf5ec6972b;hp=3e89b70b5c23bd1a01ee4b28206cbd0371b9e6c4;hpb=1f1c714c231334ca941e029e7ab2094fff25b476;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/menu/xonotic/serverlist.c b/qcsrc/menu/xonotic/serverlist.c index 3e89b70b5..0a3fd91db 100644 --- a/qcsrc/menu/xonotic/serverlist.c +++ b/qcsrc/menu/xonotic/serverlist.c @@ -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); @@ -64,9 +65,8 @@ void ServerList_Filter_Change(entity box, entity me); void ServerList_Favorite_Click(entity btn, entity me); void ServerList_Info_Click(entity btn, entity me); void ServerList_Update_favoriteButton(entity btn, entity me); -#endif -#ifdef IMPLEMENTATION +#ifndef IMPLEMENTATION float SLIST_FIELD_CNAME; float SLIST_FIELD_PING; float SLIST_FIELD_GAME; @@ -82,6 +82,11 @@ float SLIST_FIELD_FREESLOTS; float SLIST_FIELD_PLAYERS; float SLIST_FIELD_QCSTATUS; float SLIST_FIELD_ISFAVORITE; +#endif + +#endif + +#ifdef IMPLEMENTATION void ServerList_UpdateFieldIDs() { SLIST_FIELD_CNAME = gethostcacheindexforkey( "cname" ); @@ -213,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); @@ -318,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; @@ -346,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); @@ -394,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) @@ -427,24 +434,24 @@ void ServerList_TypeSort_Click(entity btn, entity me) else s = ""; - for(i = 1; ; ++i) // 20 modes ought to be enough for anyone + for(i = 1; ; i *= 2) // 20 modes ought to be enough for anyone { - t = GametypeNameFromType(i); + t = MapInfo_Type_ToString(i); if(i > 1) - if(t == GametypeNameFromType(0)) // it repeats (default case) + if(t == "") // it repeats (default case) { // no type was found // choose the first one - s = t; + s = MapInfo_Type_ToString(1); break; } - if(s == GametypeNameFromType(i)) + if(s == t) { // the type was found // choose the next one - s = GametypeNameFromType(i + 1); - if(s == GametypeNameFromType(0)) - s = ""; + s = MapInfo_Type_ToString(i * 2); + if(s == "") + s = MapInfo_Type_ToString(1); break; } } @@ -533,7 +540,7 @@ void XonoticServerList_resizeNotify(entity me, vector relOrigin, vector relSize, me.realUpperMargin = 0.5 * (1 - me.realFontSize_y); me.columnIconsOrigin = 0; - me.columnIconsSize = me.realFontSize_x * 3 * me.iconsSizeFactor; + me.columnIconsSize = me.realFontSize_x * 4 * me.iconsSizeFactor; me.columnPingSize = me.realFontSize_x * 3; me.columnMapSize = me.realFontSize_x * 10; me.columnTypeSize = me.realFontSize_x * 4; @@ -592,28 +599,93 @@ 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 - string s; float p, q; float isv4, isv6; vector theColor; float theAlpha; + 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); - if(gethostcachenumber(SLIST_FIELD_FREESLOTS, i) <= 0) + s = gethostcachestring(SLIST_FIELD_QCSTATUS, cache); + m = tokenizebyseparator(s, ":"); + typestr = ""; + if(m >= 2) + { + typestr = argv(0); + versionstr = argv(1); + } + freeslots = -1; + sflags = -1; + modname = ""; + pure = 0; + for(j = 2; j < m; ++j) + { + if(argv(j) == "") + break; + k = substring(argv(j), 0, 1); + v = substring(argv(j), 1, -1); + if(k == "P") + pure = stof(v); + else if(k == "S") + freeslots = stof(v); + else if(k == "F") + sflags = stof(v); + else if(k == "M") + modname = v; + } + +#ifdef COMPAT_NO_MOD_IS_XONOTIC + if(modname == "") + modname = "Xonotic"; +#endif + + /* + SLIST_FIELD_MOD = gethostcacheindexforkey("mod"); + s = gethostcachestring(SLIST_FIELD_MOD, cache); + if(s != "data") + if(modname == "Xonotic") + modname = s; + */ + + // list the mods here on which the pure server check actually works + if(modname != "Xonotic") + if(modname != "MinstaGib") + if(modname != "CTS") + if(modname != "NIX") + if(modname != "NewToys") + pure = 0; + + if(gethostcachenumber(SLIST_FIELD_FREESLOTS, cache) <= 0) theAlpha = SKINALPHA_SERVERLIST_FULL; - else if(strstrofs(gethostcachestring(SLIST_FIELD_QCSTATUS, i), ":S0:", 0) >= 0) + 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 @@ -632,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) == "[") @@ -681,51 +753,77 @@ void XonoticServerList_drawListBoxItem(entity me, float i, vector absSize, float // 4: AES recommended and will be used // 5: AES required - s = gethostcachestring(SLIST_FIELD_QCSTATUS, i); { - vector iconSize; + vector iconSize = '0 0 0'; iconSize_y = me.realFontSize_y * me.iconsSizeFactor; iconSize_x = me.realFontSize_x * me.iconsSizeFactor; - vector iconPos; + vector iconPos = '0 0 0'; iconPos_x = (me.columnIconsSize - 3 * iconSize_x) * 0.5; iconPos_y = (1 - iconSize_y) * 0.5; + string n; + if not(me.seenIPv4 && me.seenIPv6) { iconPos_x += iconSize_x * 0.5; } else if(me.seenIPv4 && me.seenIPv6) { + n = string_null; if(isv6) - draw_Picture(iconPos, strcat(SKINGFX_SERVERLIST_ICON, "_ipv6"), iconSize, '1 1 1', 1); + draw_PreloadPictureWithFlags(n = strcat(SKINGFX_SERVERLIST_ICON, "_ipv6"), 0); // PRECACHE_PIC_MIPMAP else if(isv4) - draw_Picture(iconPos, strcat(SKINGFX_SERVERLIST_ICON, "_ipv4"), iconSize, '1 1 1', 1); + draw_PreloadPictureWithFlags(n = strcat(SKINGFX_SERVERLIST_ICON, "_ipv4"), 0); // PRECACHE_PIC_MIPMAP + if(n) + draw_Picture(iconPos, n, iconSize, '1 1 1', 1); iconPos_x += iconSize_x; } - draw_Picture(iconPos, strcat(SKINGFX_SERVERLIST_ICON, "_aeslevel", ftos(q)), iconSize, '1 1 1', 1); + if(q > 0) + { + draw_PreloadPictureWithFlags(n = strcat(SKINGFX_SERVERLIST_ICON, "_aeslevel", ftos(q)), 0); // PRECACHE_PIC_MIPMAP + draw_Picture(iconPos, n, iconSize, '1 1 1', 1); + } iconPos_x += iconSize_x; - draw_Picture(iconPos, strcat(SKINGFX_SERVERLIST_ICON, "_pure", ftos(strstrofs(s, ":P0:", 0) >= 0)), iconSize, '1 1 1', 1); + if(modname == "Xonotic") + { + if(pure == 0) + { + draw_PreloadPictureWithFlags(n = strcat(SKINGFX_SERVERLIST_ICON, "_pure1"), PRECACHE_PIC_MIPMAP); + draw_Picture(iconPos, n, iconSize, '1 1 1', 1); + } + } + else + { + draw_PreloadPictureWithFlags(n = strcat(SKINGFX_SERVERLIST_ICON, "_mod_", modname), PRECACHE_PIC_MIPMAP); + if(draw_PictureSize(n) == '0 0 0') + draw_PreloadPictureWithFlags(n = strcat(SKINGFX_SERVERLIST_ICON, "_mod_"), PRECACHE_PIC_MIPMAP); + if(pure == 0) + draw_Picture(iconPos, n, iconSize, '1 1 1', 1); + else + draw_Picture(iconPos, n, iconSize, '1 1 1', SKINALPHA_SERVERLIST_ICON_NONPURE); + } + iconPos_x += iconSize_x; + + if(sflags >= 0 && (sflags & SERVERFLAG_PLAYERSTATS)) + { + draw_PreloadPictureWithFlags(n = strcat(SKINGFX_SERVERLIST_ICON, "_stats1"), 0); // PRECACHE_PIC_MIPMAP + draw_Picture(iconPos, n, iconSize, '1 1 1', 1); + } iconPos_x += iconSize_x; } 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 = gethostcachestring(SLIST_FIELD_QCSTATUS, i); - p = strstrofs(s, ":", 0); - if(p >= 0) - s = substring(s, 0, p); - else - s = ""; - s = draw_TextShortenToWidth(s, me.columnMapSize, 0, me.realFontSize); + 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); } @@ -748,7 +846,9 @@ float XonoticServerList_keyDown(entity me, float scan, float ascii, float shift) { main.serverInfoDialog.loadServerInfo(main.serverInfoDialog, me.selectedItem); DialogOpenButton_Click_withCoords(me, main.serverInfoDialog, org, sz); + return 1; } + return 0; } else if(scan == K_INS || scan == K_MOUSE3 || scan == K_KP_INS) { @@ -757,7 +857,9 @@ float XonoticServerList_keyDown(entity me, float scan, float ascii, float shift) { ToggleFavorite(me.selectedServer); me.ipAddressBoxFocused = -1; + return 1; } + return 0; } else if(SUPER(XonoticServerList).keyDown(me, scan, ascii, shift)) return 1;