X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fmenu%2Fxonotic%2Fserverlist.qc;h=a06349cec04fe5574bbe7bb47f27e5e975249310;hb=db7c0f258711d75763876f234a08ad8e5bb5a6c5;hp=8bf70cc33307d06fe1ae5130649d602a8ef164fc;hpb=cf4d36d9d295ce940e9e9bdf7a711e4036de0b3c;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/menu/xonotic/serverlist.qc b/qcsrc/menu/xonotic/serverlist.qc index 8bf70cc33..a06349cec 100644 --- a/qcsrc/menu/xonotic/serverlist.qc +++ b/qcsrc/menu/xonotic/serverlist.qc @@ -2,14 +2,14 @@ #define SERVERLIST_H #include "listbox.qc" CLASS(XonoticServerList, XonoticListBox) - METHOD(XonoticServerList, configureXonoticServerList, void(entity)) + METHOD(XonoticServerList, configureXonoticServerList, void(entity)); ATTRIB(XonoticServerList, rowsPerItem, float, 1) - METHOD(XonoticServerList, draw, void(entity)) - METHOD(XonoticServerList, drawListBoxItem, void(entity, int, vector, bool, bool)) - METHOD(XonoticServerList, doubleClickListBoxItem, void(entity, float, vector)) - METHOD(XonoticServerList, resizeNotify, void(entity, vector, vector, vector, vector)) - METHOD(XonoticServerList, keyDown, float(entity, float, float, float)) - METHOD(XonoticServerList, toggleFavorite, void(entity, string)) + METHOD(XonoticServerList, draw, void(entity)); + METHOD(XonoticServerList, drawListBoxItem, void(entity, int, vector, bool, bool)); + METHOD(XonoticServerList, doubleClickListBoxItem, void(entity, float, vector)); + METHOD(XonoticServerList, resizeNotify, void(entity, vector, vector, vector, vector)); + METHOD(XonoticServerList, keyDown, float(entity, float, float, float)); + METHOD(XonoticServerList, toggleFavorite, void(entity, string)); ATTRIB(XonoticServerList, iconsSizeFactor, float, 0.85) @@ -27,10 +27,11 @@ CLASS(XonoticServerList, XonoticListBox) ATTRIB(XonoticServerList, columnTypeSize, float, 0) ATTRIB(XonoticServerList, columnPlayersOrigin, float, 0) ATTRIB(XonoticServerList, columnPlayersSize, float, 0) + ATTRIB(XonoticServerList, lockedSelectedItem, bool, true) // initially keep selected the first item of the list, avoiding an unwanted scrolling ATTRIB(XonoticServerList, selectedServer, string, string_null) // to restore selected server when needed - METHOD(XonoticServerList, setSelected, void(entity, float)) - METHOD(XonoticServerList, setSortOrder, void(entity, float, float)) + METHOD(XonoticServerList, setSelected, void(entity, float)); + METHOD(XonoticServerList, setSortOrder, void(entity, float, float)); ATTRIB(XonoticServerList, filterShowEmpty, float, 1) ATTRIB(XonoticServerList, filterShowFull, float, 1) ATTRIB(XonoticServerList, filterString, string, string_null) @@ -38,10 +39,10 @@ CLASS(XonoticServerList, XonoticListBox) ATTRIB(XonoticServerList, ipAddressBox, entity, NULL) ATTRIB(XonoticServerList, favoriteButton, entity, NULL) ATTRIB(XonoticServerList, nextRefreshTime, float, 0) - METHOD(XonoticServerList, refreshServerList, void(entity, float)) // refresh mode: REFRESHSERVERLIST_* + METHOD(XonoticServerList, refreshServerList, void(entity, float)); // refresh mode: REFRESHSERVERLIST_* ATTRIB(XonoticServerList, needsRefresh, float, 1) - METHOD(XonoticServerList, focusEnter, void(entity)) - METHOD(XonoticServerList, positionSortButton, void(entity, entity, float, float, string, void(entity, entity))) + METHOD(XonoticServerList, focusEnter, void(entity)); + METHOD(XonoticServerList, positionSortButton, void(entity, entity, float, float, string, void(entity, entity))); ATTRIB(XonoticServerList, sortButton1, entity, NULL) ATTRIB(XonoticServerList, sortButton2, entity, NULL) ATTRIB(XonoticServerList, sortButton3, entity, NULL) @@ -58,10 +59,10 @@ CLASS(XonoticServerList, XonoticListBox) ATTRIB(XonoticServerList, seenIPv6, float, 0) ATTRIB(XonoticServerList, categoriesHeight, float, 1.25) - METHOD(XonoticServerList, getTotalHeight, float(entity)) - METHOD(XonoticServerList, getItemAtPos, float(entity, float)) - METHOD(XonoticServerList, getItemStart, float(entity, float)) - METHOD(XonoticServerList, getItemHeight, float(entity, float)) + METHOD(XonoticServerList, getTotalHeight, float(entity)); + METHOD(XonoticServerList, getItemAtPos, float(entity, float)); + METHOD(XonoticServerList, getItemStart, float(entity, float)); + METHOD(XonoticServerList, getItemHeight, float(entity, float)); ENDCLASS(XonoticServerList) entity makeXonoticServerList(); @@ -172,9 +173,7 @@ void RegisterSLCategories() #define SLIST_CATEGORY(name,enoverride,dioverride,str) \ SET_FIELD_COUNT(name, CATEGORY_FIRST, category_ent_count) \ CHECK_MAX_COUNT(name, MAX_CATEGORIES, category_ent_count, "SLIST_CATEGORY") \ - cat = spawn(); \ - categories[name - 1] = cat; \ - cat.classname = "slist_category"; \ + cat = categories[name - 1] = new(slist_category); \ cat.cat_name = strzone(#name); \ cat.cat_enoverride_string = strzone(SLIST_CATEGORY_AUTOCVAR(name)); \ cat.cat_dioverride_string = strzone(dioverride); \ @@ -205,7 +204,7 @@ void RegisterSLCategories() } \ else \ { \ - printf( \ + LOG_INFOF( \ "RegisterSLCategories(): Improper override '%s' for category '%s'!\n", \ s, \ categories[i].cat_name \ @@ -230,7 +229,7 @@ entity RetrieveCategoryEnt(int catnum) else { error(sprintf("RetrieveCategoryEnt(%d): Improper category number!\n", catnum)); - return world; + return NULL; } } @@ -372,7 +371,7 @@ int CheckCategoryForEntry(int entry) case "cts": case "xdf": { return CAT_DEFRAG; } - default: { dprintf("Found strange mod type: %s\n", modtype); return CAT_MODIFIED; } + default: { LOG_TRACEF("Found strange mod type: %s\n", modtype); return CAT_MODIFIED; } } } @@ -432,11 +431,17 @@ void XonoticServerList_toggleFavorite(entity me, string srv) void ServerList_Update_favoriteButton(entity btn, entity me) { - me.favoriteButton.setText(me.favoriteButton, - (IsFavorite(me.ipAddressBox.text) ? - _("Remove") : _("Favorite") - ) - ); + entity e = me.favoriteButton; + if(IsFavorite(me.ipAddressBox.text)) + { + e.setText(e, _("Remove")); + clearTooltip(e); + } + else + { + e.setText(e, _("Favorite")); + setZonedTooltip(e, _("Bookmark the currently highlighted server so that it's faster to find in the future"), string_null); + } } entity makeXonoticServerList() @@ -460,6 +465,7 @@ void XonoticServerList_configureXonoticServerList(entity me) } void XonoticServerList_setSelected(entity me, int i) { + me.lockedSelectedItem = false; //int save = me.selectedItem; SUPER(XonoticServerList).setSelected(me, i); /* @@ -717,12 +723,26 @@ void XonoticServerList_draw(entity me) me.infoButton.disabled = ((me.nItems == 0) || !owned); me.favoriteButton.disabled = ((me.nItems == 0) && (me.ipAddressBox.text == "")); - if(me.selectedServer) + if(me.lockedSelectedItem) + { + if(me.nItems > 0) + { + if(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem) != me.selectedServer) + { + if(me.selectedServer) + strunzone(me.selectedServer); + me.selectedServer = strzone(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem)); + } + found = true; + } + } + else if(me.selectedServer) { for(i = 0; i < me.nItems; ++i) { if(gethostcachestring(SLIST_FIELD_CNAME, i) == me.selectedServer) { + // don't follow the selected item with SUPER(XonoticServerList).setSelected(me, i); me.selectedItem = i; found = true; break; @@ -733,8 +753,9 @@ void XonoticServerList_draw(entity me) { if(me.nItems > 0) { + // selected server disappeared, select the last server (scrolling to it) if(me.selectedItem >= me.nItems) - me.selectedItem = me.nItems - 1; + SUPER(XonoticServerList).setSelected(me, me.nItems - 1); if(me.selectedServer) strunzone(me.selectedServer); me.selectedServer = strzone(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem)); @@ -971,7 +992,7 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is bool isv4, isv6; vector theColor; float theAlpha; - bool pure = false; + bool pure = false, pure_available = false; int freeslots = -1, sflags = -1, j, m; string s, typestr, versionstr, k, v, modname; @@ -1042,7 +1063,10 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is k = substring(argv(j), 0, 1); v = substring(argv(j), 1, -1); if(k == "P") - pure = stob(v); + { + pure = (stof(v) == 0); + pure_available = true; + } else if(k == "S") freeslots = stof(v); else if(k == "F") @@ -1053,24 +1077,26 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is #ifdef COMPAT_NO_MOD_IS_XONOTIC if(modname == "") - modname = "Xonotic"; + modname = "xonotic"; #endif + modname = strtolower(modname); + /* SLIST_FIELD_MOD = gethostcacheindexforkey("mod"); s = gethostcachestring(SLIST_FIELD_MOD, i); if(s != "data") - if(modname == "Xonotic") + if(modname == "xonotic") modname = s; */ // list the mods here on which the pure server check actually works - if(modname != "Xonotic") - if(modname != "InstaGib" || modname != "MinstaGib") - if(modname != "CTS") - if(modname != "NIX") - if(modname != "NewToys") - pure = false; + if(modname != "xonotic") + if(modname != "instagib" || modname != "minstagib") + if(modname != "cts") + if(modname != "nix") + if(modname != "newtoys") + pure_available = false; if(gethostcachenumber(SLIST_FIELD_FREESLOTS, i) <= 0) theAlpha = SKINALPHA_SERVERLIST_FULL; @@ -1160,57 +1186,51 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is iconPos_x = (me.columnIconsSize - 3 * iconSize.x) * 0.5; iconPos_y = (1 - iconSize.y) * 0.5; - string n; - - if (!(me.seenIPv4 && me.seenIPv6)) - { - iconPos.x += iconSize.x * 0.5; - } - else if(me.seenIPv4 && me.seenIPv6) + // IP + if(me.seenIPv4 && me.seenIPv6) { - n = string_null; if(isv6) - draw_PreloadPictureWithFlags(n = strcat(SKINGFX_SERVERLIST_ICON, "_ipv6"), 0); // PRECACHE_PIC_MIPMAP + draw_Picture(iconPos, "icon_ipv6", iconSize, '1 1 1', 1); else if(isv4) - 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, "icon_ipv4", iconSize, '1 1 1', 1); } + iconPos.x += iconSize.x; + + // AES 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); - } + draw_Picture(iconPos, strcat("icon_aeslevel", ftos(q)), iconSize, '1 1 1', 1); + iconPos.x += iconSize.x; - if(modname == "Xonotic") + // Mod + 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); - } + // Here, pure_available should always be set. If not, consider + // it an impurity. + if(pure_available && pure) + draw_Picture(iconPos, "icon_pure1", 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); + string icon = strcat("icon_mod_", modname); + if(draw_PictureSize(icon) == '0 0 0') + icon = "icon_mod_"; + + // In mods, pure_available not being present indicates + // non-support of the feature. Just show the mod icon as is + // then. + if(pure_available && !pure) + draw_Picture(iconPos, icon, iconSize, '1 1 1', SKINALPHA_SERVERLIST_ICON_NONPURE); else - draw_Picture(iconPos, n, iconSize, '1 1 1', SKINALPHA_SERVERLIST_ICON_NONPURE); + draw_Picture(iconPos, icon, iconSize, '1 1 1', 1); } + iconPos.x += iconSize.x; + // Stats 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; + draw_Picture(iconPos, "icon_stats1", iconSize, '1 1 1', 1); // -------------- // RENDER TEXT