4 CLASS(XonoticServerList, XonoticListBox)
5 METHOD(XonoticServerList, configureXonoticServerList, void(entity));
6 ATTRIB(XonoticServerList, rowsPerItem, float, 1)
7 METHOD(XonoticServerList, draw, void(entity));
8 METHOD(XonoticServerList, drawListBoxItem, void(entity, int, vector, bool, bool));
9 METHOD(XonoticServerList, doubleClickListBoxItem, void(entity, float, vector));
10 METHOD(XonoticServerList, resizeNotify, void(entity, vector, vector, vector, vector));
11 METHOD(XonoticServerList, keyDown, float(entity, float, float, float));
12 METHOD(XonoticServerList, toggleFavorite, void(entity, string));
14 ATTRIB(XonoticServerList, iconsSizeFactor, float, 0.85)
15 METHOD(XonoticServerList, mouseMove, float(entity, vector));
16 ATTRIB(XonoticServerList, mouseOverIcons, bool, false)
17 METHOD(XonoticServerList, focusedItemChangeNotify, void(entity));
19 ATTRIB(XonoticServerList, realFontSize, vector, '0 0 0')
20 ATTRIB(XonoticServerList, realUpperMargin, float, 0)
21 ATTRIB(XonoticServerList, columnIconsOrigin, float, 0)
22 ATTRIB(XonoticServerList, columnIconsSize, float, 0)
23 ATTRIB(XonoticServerList, columnPingOrigin, float, 0)
24 ATTRIB(XonoticServerList, columnPingSize, float, 0)
25 ATTRIB(XonoticServerList, columnNameOrigin, float, 0)
26 ATTRIB(XonoticServerList, columnNameSize, float, 0)
27 ATTRIB(XonoticServerList, columnMapOrigin, float, 0)
28 ATTRIB(XonoticServerList, columnMapSize, float, 0)
29 ATTRIB(XonoticServerList, columnTypeOrigin, float, 0)
30 ATTRIB(XonoticServerList, columnTypeSize, float, 0)
31 ATTRIB(XonoticServerList, columnPlayersOrigin, float, 0)
32 ATTRIB(XonoticServerList, columnPlayersSize, float, 0)
33 ATTRIB(XonoticServerList, lockedSelectedItem, bool, true) // initially keep selected the first item of the list, avoiding an unwanted scrolling
35 ATTRIB(XonoticServerList, selectedServer, string, string_null) // to restore selected server when needed
36 METHOD(XonoticServerList, setSelected, void(entity, float));
37 METHOD(XonoticServerList, setSortOrder, void(entity, float, float));
38 ATTRIB(XonoticServerList, filterShowEmpty, float, 1)
39 ATTRIB(XonoticServerList, filterShowFull, float, 1)
40 ATTRIB(XonoticServerList, filterString, string, string_null)
41 ATTRIB(XonoticServerList, controlledTextbox, entity, NULL)
42 ATTRIB(XonoticServerList, ipAddressBox, entity, NULL)
43 ATTRIB(XonoticServerList, favoriteButton, entity, NULL)
44 ATTRIB(XonoticServerList, nextRefreshTime, float, 0)
45 METHOD(XonoticServerList, refreshServerList, void(entity, float)); // refresh mode: REFRESHSERVERLIST_*
46 ATTRIB(XonoticServerList, needsRefresh, float, 1)
47 METHOD(XonoticServerList, focusEnter, void(entity));
48 METHOD(XonoticServerList, positionSortButton, void(entity, entity, float, float, string, void(entity, entity)));
49 ATTRIB(XonoticServerList, sortButton1, entity, NULL)
50 ATTRIB(XonoticServerList, sortButton2, entity, NULL)
51 ATTRIB(XonoticServerList, sortButton3, entity, NULL)
52 ATTRIB(XonoticServerList, sortButton4, entity, NULL)
53 ATTRIB(XonoticServerList, sortButton5, entity, NULL)
54 ATTRIB(XonoticServerList, connectButton, entity, NULL)
55 ATTRIB(XonoticServerList, infoButton, entity, NULL)
56 ATTRIB(XonoticServerList, currentSortOrder, float, 0)
57 ATTRIB(XonoticServerList, currentSortField, float, -1)
59 ATTRIB(XonoticServerList, ipAddressBoxFocused, float, -1)
61 ATTRIB(XonoticServerList, seenIPv4, float, 0)
62 ATTRIB(XonoticServerList, seenIPv6, float, 0)
63 ATTRIB(XonoticServerList, categoriesHeight, float, 1.25)
65 METHOD(XonoticServerList, getTotalHeight, float(entity));
66 METHOD(XonoticServerList, getItemAtPos, float(entity, float));
67 METHOD(XonoticServerList, getItemStart, float(entity, float));
68 METHOD(XonoticServerList, getItemHeight, float(entity, float));
69 ENDCLASS(XonoticServerList)
70 entity makeXonoticServerList();
72 #ifndef IMPLEMENTATION
73 float autocvar_menu_slist_categories;
74 float autocvar_menu_slist_categories_onlyifmultiple;
75 float autocvar_menu_slist_purethreshold;
76 float autocvar_menu_slist_modimpurity;
77 float autocvar_menu_slist_recommendations;
78 float autocvar_menu_slist_recommendations_maxping;
79 float autocvar_menu_slist_recommendations_minfreeslots;
80 float autocvar_menu_slist_recommendations_minhumans;
81 float autocvar_menu_slist_recommendations_purethreshold;
83 // server cache fields
84 #define SLIST_FIELDS \
85 SLIST_FIELD(CNAME, "cname") \
86 SLIST_FIELD(PING, "ping") \
87 SLIST_FIELD(GAME, "game") \
88 SLIST_FIELD(MOD, "mod") \
89 SLIST_FIELD(MAP, "map") \
90 SLIST_FIELD(NAME, "name") \
91 SLIST_FIELD(MAXPLAYERS, "maxplayers") \
92 SLIST_FIELD(NUMPLAYERS, "numplayers") \
93 SLIST_FIELD(NUMHUMANS, "numhumans") \
94 SLIST_FIELD(NUMBOTS, "numbots") \
95 SLIST_FIELD(PROTOCOL, "protocol") \
96 SLIST_FIELD(FREESLOTS, "freeslots") \
97 SLIST_FIELD(PLAYERS, "players") \
98 SLIST_FIELD(QCSTATUS, "qcstatus") \
99 SLIST_FIELD(CATEGORY, "category") \
100 SLIST_FIELD(ISFAVORITE, "isfavorite")
102 #define SLIST_FIELD(suffix,name) float SLIST_FIELD_##suffix;
106 const float REFRESHSERVERLIST_RESORT = 0; // sort the server list again to update for changes to e.g. favorite status, categories
107 const float REFRESHSERVERLIST_REFILTER = 1; // ..., also update filter and sort criteria
108 const float REFRESHSERVERLIST_ASK = 2; // ..., also suggest querying servers now
109 const float REFRESHSERVERLIST_RESET = 3; // ..., also clear the list first
111 // function declarations
112 float IsServerInList(string list, string srv);
113 #define IsFavorite(srv) IsServerInList(cvar_string("net_slist_favorites"), srv)
114 #define IsPromoted(srv) IsServerInList(_Nex_ExtResponseSystem_PromotedServers, srv)
115 #define IsRecommended(srv) IsServerInList(_Nex_ExtResponseSystem_RecommendedServers, srv)
117 entity RetrieveCategoryEnt(float catnum);
119 float CheckCategoryOverride(float cat);
120 float CheckCategoryForEntry(float entry);
121 float m_gethostcachecategory(float entry) { return CheckCategoryOverride(CheckCategoryForEntry(entry)); }
123 void RegisterSLCategories();
125 void ServerList_Connect_Click(entity btn, entity me);
126 void ServerList_Categories_Click(entity box, entity me);
127 void ServerList_ShowEmpty_Click(entity box, entity me);
128 void ServerList_ShowFull_Click(entity box, entity me);
129 void ServerList_Filter_Change(entity box, entity me);
130 void ServerList_Favorite_Click(entity btn, entity me);
131 void ServerList_Info_Click(entity btn, entity me);
132 void ServerList_Update_favoriteButton(entity btn, entity me);
134 // fields for category entities
135 const int MAX_CATEGORIES = 9;
136 const int CATEGORY_FIRST = 1;
137 entity categories[MAX_CATEGORIES];
138 int category_ent_count;
141 .string cat_enoverride_string;
142 .string cat_dioverride_string;
143 .float cat_enoverride;
144 .float cat_dioverride;
146 // fields for drawing categories
147 int category_name[MAX_CATEGORIES];
148 int category_item[MAX_CATEGORIES];
149 int category_draw_count;
151 #define SLIST_CATEGORIES \
152 SLIST_CATEGORY(CAT_FAVORITED, "", "", CTX(_("SLCAT^Favorites"))) \
153 SLIST_CATEGORY(CAT_RECOMMENDED, "", "", CTX(_("SLCAT^Recommended"))) \
154 SLIST_CATEGORY(CAT_NORMAL, "", "CAT_SERVERS", CTX(_("SLCAT^Normal Servers"))) \
155 SLIST_CATEGORY(CAT_SERVERS, "CAT_NORMAL", "CAT_SERVERS", CTX(_("SLCAT^Servers"))) \
156 SLIST_CATEGORY(CAT_XPM, "CAT_NORMAL", "CAT_SERVERS", CTX(_("SLCAT^Competitive Mode"))) \
157 SLIST_CATEGORY(CAT_MODIFIED, "", "CAT_SERVERS", CTX(_("SLCAT^Modified Servers"))) \
158 SLIST_CATEGORY(CAT_OVERKILL, "", "CAT_SERVERS", CTX(_("SLCAT^Overkill Mode"))) \
159 SLIST_CATEGORY(CAT_INSTAGIB, "", "CAT_SERVERS", CTX(_("SLCAT^InstaGib Mode"))) \
160 SLIST_CATEGORY(CAT_DEFRAG, "", "CAT_SERVERS", CTX(_("SLCAT^Defrag Mode")))
162 #define SLIST_CATEGORY_AUTOCVAR(name) autocvar_menu_slist_categories_##name##_override
163 #define SLIST_CATEGORY(name,enoverride,dioverride,str) \
165 string SLIST_CATEGORY_AUTOCVAR(name) = enoverride;
167 #undef SLIST_CATEGORY
171 #ifdef IMPLEMENTATION
173 void RegisterSLCategories()
176 #define SLIST_CATEGORY(name,enoverride,dioverride,str) \
177 SET_FIELD_COUNT(name, CATEGORY_FIRST, category_ent_count) \
178 CHECK_MAX_COUNT(name, MAX_CATEGORIES, category_ent_count, "SLIST_CATEGORY") \
179 cat = categories[name - 1] = new(slist_category); \
180 cat.cat_name = #name; \
181 cat.cat_enoverride_string = strzone(SLIST_CATEGORY_AUTOCVAR(name)); \
182 cat.cat_dioverride_string = strzone(dioverride); \
183 cat.cat_string = strzone(str);
185 #undef SLIST_CATEGORY
190 #define PROCESS_OVERRIDE(override_string,override_field) \
191 for(i = 0; i < category_ent_count; ++i) \
193 s = categories[i].override_string; \
194 if((s != "") && (s != categories[i].cat_name)) \
197 for(x = 0; x < category_ent_count; ++x) \
198 { if(categories[x].cat_name == s) { \
204 strunzone(categories[i].override_string); \
205 categories[i].override_string = string_null; \
206 categories[i].override_field = catnum; \
212 "RegisterSLCategories(): Improper override '%s' for category '%s'!\n", \
214 categories[i].cat_name \
218 strunzone(categories[i].override_string); \
219 categories[i].override_string = string_null; \
220 categories[i].override_field = 0; \
222 PROCESS_OVERRIDE(cat_enoverride_string, cat_enoverride)
223 PROCESS_OVERRIDE(cat_dioverride_string, cat_dioverride)
224 #undef PROCESS_OVERRIDE
227 // Supporting Functions
228 entity RetrieveCategoryEnt(int catnum)
230 if((catnum > 0) && (catnum <= category_ent_count))
232 return categories[catnum - 1];
236 error(sprintf("RetrieveCategoryEnt(%d): Improper category number!\n", catnum));
241 bool IsServerInList(string list, string srv)
247 srv = netaddress_resolve(srv, 26000);
250 p = crypto_getidfp(srv);
251 n = tokenize_console(list);
252 for(i = 0; i < n; ++i)
254 if(substring(argv(i), 0, 1) != "[" && strlen(argv(i)) == 44 && strstrofs(argv(i), ".", 0) < 0)
262 if(srv == netaddress_resolve(argv(i), 26000))
269 int CheckCategoryOverride(int cat)
271 entity catent = RetrieveCategoryEnt(cat);
274 int override = (autocvar_menu_slist_categories ? catent.cat_enoverride : catent.cat_dioverride);
275 if(override) { return override; }
280 error(sprintf("CheckCategoryOverride(%d): Improper category number!\n", cat));
285 int CheckCategoryForEntry(int entry)
287 string s, k, v, modtype = "";
288 int j, m, impure = 0, freeslots = 0, sflags = 0;
289 s = gethostcachestring(SLIST_FIELD_QCSTATUS, entry);
290 m = tokenizebyseparator(s, ":");
292 for(j = 2; j < m; ++j)
294 if(argv(j) == "") { break; }
295 k = substring(argv(j), 0, 1);
296 v = substring(argv(j), 1, -1);
299 case "P": { impure = stof(v); break; }
300 case "S": { freeslots = stof(v); break; }
301 case "F": { sflags = stof(v); break; }
302 case "M": { modtype = strtolower(v); break; }
306 if(modtype != "xonotic") { impure += autocvar_menu_slist_modimpurity; }
308 // check if this server is favorited
309 if(gethostcachenumber(SLIST_FIELD_ISFAVORITE, entry)) { return CAT_FAVORITED; }
311 // now check if it's recommended
312 if(autocvar_menu_slist_recommendations)
314 string cname = gethostcachestring(SLIST_FIELD_CNAME, entry);
316 if(IsPromoted(cname)) { return CAT_RECOMMENDED; }
319 float recommended = 0;
320 if(autocvar_menu_slist_recommendations & 1)
322 if(IsRecommended(cname)) { ++recommended; }
323 else { --recommended; }
325 if(autocvar_menu_slist_recommendations & 2)
328 ///// check for minimum free slots
329 (freeslots >= autocvar_menu_slist_recommendations_minfreeslots)
331 && // check for purity requirement
333 (autocvar_menu_slist_recommendations_purethreshold < 0)
335 (impure <= autocvar_menu_slist_recommendations_purethreshold)
338 && // check for minimum amount of humans
340 gethostcachenumber(SLIST_FIELD_NUMHUMANS, entry)
342 autocvar_menu_slist_recommendations_minhumans
345 && // check for maximum latency
347 gethostcachenumber(SLIST_FIELD_PING, entry)
349 autocvar_menu_slist_recommendations_maxping
356 if(recommended > 0) { return CAT_RECOMMENDED; }
360 // if not favorited or recommended, check modname
361 if(modtype != "xonotic")
365 // old servers which don't report their mod name are considered modified now
366 case "": { return CAT_MODIFIED; }
368 case "xpm": { return CAT_XPM; }
370 case "instagib": { return CAT_INSTAGIB; }
371 case "overkill": { return CAT_OVERKILL; }
372 //case "nix": { return CAT_NIX; }
373 //case "newtoys": { return CAT_NEWTOYS; }
375 // "cts" is allowed as compat, xdf is replacement
377 case "xdf": { return CAT_DEFRAG; }
379 default: { LOG_TRACEF("Found strange mod type: %s\n", modtype); return CAT_MODIFIED; }
383 // must be normal or impure server
384 return ((impure > autocvar_menu_slist_purethreshold) ? CAT_MODIFIED : CAT_NORMAL);
387 METHOD(XonoticServerList, toggleFavorite, void(XonoticServerList this, string srv))
390 string srv_resolved = netaddress_resolve(srv, 26000);
391 string p = crypto_getidfp(srv_resolved);
392 string s = cvar_string("net_slist_favorites");
394 for (int i = 0, n = tokenize_console(s); i < n; ++i)
397 if (substring(argv(i), 0, 1) != "[" && strlen(argv(i)) == 44 && strstrofs(argv(i), ".", 0) < 0)
399 // it's a pubkey hash
400 match = (p && p == argv(i));
405 match = (srv_resolved == netaddress_resolve(argv(i), 26000));
407 if (!match) continue;
410 string before = (i > 0) ? substring(s, 0, argv_end_index(i - 1)) : "";
411 string after = (i < n - 1) ? substring(s, argv_start_index(i + 1), -1) : "";
412 s = strcat(before, (before != "" && after != "" ? " " : ""), after);
415 // TODO: why not break here?
416 n = tokenize_console(s);
417 --i; // offset the increment that is about to happen
421 ret = strcat(s, (s != "" ? " " : ""), p ? p : srv);
423 cvar_set("net_slist_favorites", ret);
424 this.refreshServerList(this, REFRESHSERVERLIST_RESORT);
427 void ServerList_Update_favoriteButton(entity btn, entity me)
429 entity e = me.favoriteButton;
430 if(IsFavorite(me.ipAddressBox.text))
432 e.setText(e, _("Remove"));
437 e.setText(e, _("Favorite"));
438 setZonedTooltip(e, _("Bookmark the currently highlighted server so that it's faster to find in the future"), string_null);
442 entity makeXonoticServerList()
445 me = NEW(XonoticServerList);
446 me.configureXonoticServerList(me);
449 void XonoticServerList_configureXonoticServerList(entity me)
451 me.configureXonoticListBox(me);
454 #define SLIST_FIELD(suffix,name) SLIST_FIELD_##suffix = gethostcacheindexforkey(name);
461 void XonoticServerList_setSelected(entity me, int i)
463 me.lockedSelectedItem = false;
464 //int save = me.selectedItem;
465 SUPER(XonoticServerList).setSelected(me, i);
467 if(me.selectedItem == save)
472 if(gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT) != me.nItems)
473 return; // sorry, it would be wrong
475 if(me.selectedServer)
476 strunzone(me.selectedServer);
477 me.selectedServer = strzone(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem));
479 me.ipAddressBox.setText(me.ipAddressBox, me.selectedServer);
480 me.ipAddressBox.cursorPos = strlen(me.selectedServer);
481 me.ipAddressBoxFocused = -1;
483 void XonoticServerList_refreshServerList(entity me, int mode)
485 //print("refresh of type ", ftos(mode), "\n");
487 if(mode >= REFRESHSERVERLIST_REFILTER)
492 string s, typestr, modstr;
496 m = strstrofs(s, ":", 0);
499 typestr = substring(s, 0, m);
500 s = substring(s, m + 1, strlen(s) - m - 1);
501 while(substring(s, 0, 1) == " ")
502 s = substring(s, 1, strlen(s) - 1);
507 modstr = cvar_string("menu_slist_modfilter");
509 m = SLIST_MASK_AND - 1;
510 resethostcachemasks();
512 // ping: reject negative ping (no idea why this happens in the first place, engine bug)
513 sethostcachemasknumber(++m, SLIST_FIELD_PING, 0, SLIST_TEST_GREATEREQUAL);
516 if(!me.filterShowFull)
518 sethostcachemasknumber(++m, SLIST_FIELD_FREESLOTS, 1, SLIST_TEST_GREATEREQUAL); // legacy
519 sethostcachemaskstring(++m, SLIST_FIELD_QCSTATUS, ":S0:", SLIST_TEST_NOTCONTAIN); // g_maxplayers support
523 if(!me.filterShowEmpty)
524 sethostcachemasknumber(++m, SLIST_FIELD_NUMHUMANS, 1, SLIST_TEST_GREATEREQUAL);
526 // gametype filtering
528 sethostcachemaskstring(++m, SLIST_FIELD_QCSTATUS, strcat(typestr, ":"), SLIST_TEST_STARTSWITH);
533 if(substring(modstr, 0, 1) == "!")
534 sethostcachemaskstring(++m, SLIST_FIELD_MOD, resolvemod(substring(modstr, 1, strlen(modstr) - 1)), SLIST_TEST_NOTEQUAL);
536 sethostcachemaskstring(++m, SLIST_FIELD_MOD, resolvemod(modstr), SLIST_TEST_EQUAL);
540 n = tokenizebyseparator(_Nex_ExtResponseSystem_BannedServers, " ");
541 for(i = 0; i < n; ++i)
543 sethostcachemaskstring(++m, SLIST_FIELD_CNAME, argv(i), SLIST_TEST_NOTSTARTSWITH);
545 m = SLIST_MASK_OR - 1;
548 sethostcachemaskstring(++m, SLIST_FIELD_NAME, s, SLIST_TEST_CONTAINS);
549 sethostcachemaskstring(++m, SLIST_FIELD_MAP, s, SLIST_TEST_CONTAINS);
550 sethostcachemaskstring(++m, SLIST_FIELD_PLAYERS, s, SLIST_TEST_CONTAINS);
551 sethostcachemaskstring(++m, SLIST_FIELD_QCSTATUS, strcat(s, ":"), SLIST_TEST_STARTSWITH);
555 //listflags |= SLSF_FAVORITES;
556 listflags |= SLSF_CATEGORIES;
557 if(me.currentSortOrder < 0) { listflags |= SLSF_DESCENDING; }
558 sethostcachesort(me.currentSortField, listflags);
562 if(mode >= REFRESHSERVERLIST_ASK)
563 refreshhostcache(mode >= REFRESHSERVERLIST_RESET);
565 void XonoticServerList_focusEnter(entity me)
567 SUPER(XonoticServerList).focusEnter(me);
568 if(time < me.nextRefreshTime)
570 //print("sorry, no refresh yet\n");
573 me.nextRefreshTime = time + 10;
574 me.refreshServerList(me, REFRESHSERVERLIST_ASK);
577 void XonoticServerList_draw(entity me)
580 bool found = false, owned;
582 if(_Nex_ExtResponseSystem_BannedServersNeedsRefresh)
586 _Nex_ExtResponseSystem_BannedServersNeedsRefresh = 0;
589 if(_Nex_ExtResponseSystem_PromotedServersNeedsRefresh)
593 _Nex_ExtResponseSystem_PromotedServersNeedsRefresh = 0;
596 if(_Nex_ExtResponseSystem_RecommendedServersNeedsRefresh)
600 _Nex_ExtResponseSystem_RecommendedServersNeedsRefresh = 0;
603 if(me.currentSortField == -1)
605 me.setSortOrder(me, SLIST_FIELD_PING, +1);
606 me.refreshServerList(me, REFRESHSERVERLIST_RESET);
608 else if(me.needsRefresh == 1)
610 me.needsRefresh = 2; // delay by one frame to make sure "slist" has been executed
612 else if(me.needsRefresh == 2)
615 me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
617 else if(me.needsRefresh == 3)
620 me.refreshServerList(me, REFRESHSERVERLIST_RESORT);
623 owned = ((me.selectedServer == me.ipAddressBox.text) && (me.ipAddressBox.text != ""));
625 for(i = 0; i < category_draw_count; ++i) { category_name[i] = -1; category_item[i] = -1; }
626 category_draw_count = 0;
628 if(autocvar_menu_slist_categories >= 0) // if less than 0, don't even draw a category heading for favorites
630 float itemcount = gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT);
631 me.nItems = itemcount;
633 //float visible = floor(me.scrollPos / me.itemHeight);
634 // ^ unfortunately no such optimization can be made-- we must process through the
635 // entire list, otherwise there is no way to know which item is first in its category.
637 // binary search method suggested by div
640 for(x = 1; x <= category_ent_count; ++x) {
642 float last = (itemcount - 1);
647 float catf = gethostcachenumber(SLIST_FIELD_CATEGORY, first);
648 float catl = gethostcachenumber(SLIST_FIELD_CATEGORY, last);
650 // The first one is already > x.
651 // Therefore, category x does not exist.
652 // Higher numbered categories do exist though.
653 } else if (catl < x) {
654 // The last one is < x.
655 // Thus this category - and any following -
658 } else if (catf == x) {
659 // Starts at first. This breaks the loop
660 // invariant in the binary search and thus has
661 // to be handled separately.
662 if(gethostcachenumber(SLIST_FIELD_CATEGORY, first) != x)
663 error("Category mismatch I");
665 if(gethostcachenumber(SLIST_FIELD_CATEGORY, first - 1) == x)
666 error("Category mismatch II");
667 category_name[category_draw_count] = x;
668 category_item[category_draw_count] = first;
669 ++category_draw_count;
672 // At this point, catf <= x < catl, thus
673 // catf < catl, thus first < last.
676 // catf == gethostcachenumber(SLIST_FIELD_CATEGORY(first)
677 // catl == gethostcachenumber(SLIST_FIELD_CATEGORY(last)
680 while (last - first > 1) {
681 float middle = floor((first + last) / 2);
682 // By loop condition, middle != first && middle != last.
683 float cat = gethostcachenumber(SLIST_FIELD_CATEGORY, middle);
693 if(gethostcachenumber(SLIST_FIELD_CATEGORY, last) != x)
694 error("Category mismatch III");
696 if(gethostcachenumber(SLIST_FIELD_CATEGORY, last - 1) == x)
697 error("Category mismatch IV");
698 category_name[category_draw_count] = x;
699 category_item[category_draw_count] = last;
700 ++category_draw_count;
701 begin = last + 1; // already scanned through these, skip 'em
704 begin = last; // already scanned through these, skip 'em
707 if(autocvar_menu_slist_categories_onlyifmultiple && (category_draw_count == 1))
709 category_name[0] = -1;
710 category_item[0] = -1;
711 category_draw_count = 0;
712 me.nItems = itemcount;
715 else { me.nItems = gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT); }
717 me.connectButton.disabled = ((me.nItems == 0) && (me.ipAddressBox.text == ""));
718 me.infoButton.disabled = ((me.nItems == 0) || !owned);
719 me.favoriteButton.disabled = ((me.nItems == 0) && (me.ipAddressBox.text == ""));
721 if(me.lockedSelectedItem)
725 if(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem) != me.selectedServer)
727 if(me.selectedServer)
728 strunzone(me.selectedServer);
729 me.selectedServer = strzone(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem));
734 else if(me.selectedServer)
736 for(i = 0; i < me.nItems; ++i)
738 if(gethostcachestring(SLIST_FIELD_CNAME, i) == me.selectedServer)
740 // don't follow the selected item with SUPER(XonoticServerList).setSelected(me, i);
751 // selected server disappeared, select the last server (scrolling to it)
752 if(me.selectedItem >= me.nItems)
753 SUPER(XonoticServerList).setSelected(me, me.nItems - 1);
754 if(me.selectedServer)
755 strunzone(me.selectedServer);
756 me.selectedServer = strzone(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem));
762 if(me.selectedServer != me.ipAddressBox.text)
764 me.ipAddressBox.setText(me.ipAddressBox, me.selectedServer);
765 me.ipAddressBox.cursorPos = strlen(me.selectedServer);
766 me.ipAddressBoxFocused = -1;
770 if(me.ipAddressBoxFocused != me.ipAddressBox.focused)
772 if(me.ipAddressBox.focused || me.ipAddressBoxFocused < 0)
773 ServerList_Update_favoriteButton(NULL, me);
774 me.ipAddressBoxFocused = me.ipAddressBox.focused;
777 SUPER(XonoticServerList).draw(me);
779 void ServerList_PingSort_Click(entity btn, entity me)
781 me.setSortOrder(me, SLIST_FIELD_PING, +1);
783 void ServerList_NameSort_Click(entity btn, entity me)
785 me.setSortOrder(me, SLIST_FIELD_NAME, -1); // why?
787 void ServerList_MapSort_Click(entity btn, entity me)
789 me.setSortOrder(me, SLIST_FIELD_MAP, -1); // why?
791 void ServerList_PlayerSort_Click(entity btn, entity me)
793 me.setSortOrder(me, SLIST_FIELD_NUMHUMANS, -1);
795 void ServerList_TypeSort_Click(entity btn, entity me)
800 m = strstrofs(s, ":", 0);
803 s = substring(s, 0, m);
804 while(substring(s, m+1, 1) == " ") // skip spaces
810 for(i = 1; ; i *= 2) // 20 modes ought to be enough for anyone
812 t = MapInfo_Type_ToString(i);
814 if(t == "") // it repeats (default case)
817 // choose the first one
818 s = MapInfo_Type_ToString(1);
823 // the type was found
824 // choose the next one
825 s = MapInfo_Type_ToString(i * 2);
827 s = MapInfo_Type_ToString(1);
834 s = strcat(s, substring(me.filterString, m+1, strlen(me.filterString) - m - 1));
836 me.controlledTextbox.setText(me.controlledTextbox, s);
837 me.controlledTextbox.keyDown(me.controlledTextbox, K_END, 0, 0);
838 me.controlledTextbox.keyUp(me.controlledTextbox, K_END, 0, 0);
839 //ServerList_Filter_Change(me.controlledTextbox, me);
841 void ServerList_Filter_Change(entity box, entity me)
844 strunzone(me.filterString);
846 me.filterString = strzone(box.text);
848 me.filterString = string_null;
849 me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
851 me.ipAddressBox.setText(me.ipAddressBox, "");
852 me.ipAddressBox.cursorPos = 0;
853 me.ipAddressBoxFocused = -1;
855 void ServerList_Categories_Click(entity box, entity me)
857 box.setChecked(box, autocvar_menu_slist_categories = !autocvar_menu_slist_categories);
858 me.refreshServerList(me, REFRESHSERVERLIST_RESORT);
860 me.ipAddressBox.setText(me.ipAddressBox, "");
861 me.ipAddressBox.cursorPos = 0;
862 me.ipAddressBoxFocused = -1;
864 void ServerList_ShowEmpty_Click(entity box, entity me)
866 box.setChecked(box, me.filterShowEmpty = !me.filterShowEmpty);
867 me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
869 me.ipAddressBox.setText(me.ipAddressBox, "");
870 me.ipAddressBox.cursorPos = 0;
871 me.ipAddressBoxFocused = -1;
873 void ServerList_ShowFull_Click(entity box, entity me)
875 box.setChecked(box, me.filterShowFull = !me.filterShowFull);
876 me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
878 me.ipAddressBox.setText(me.ipAddressBox, "");
879 me.ipAddressBox.cursorPos = 0;
880 me.ipAddressBoxFocused = -1;
882 void XonoticServerList_setSortOrder(entity me, int fld, int direction)
884 if(me.currentSortField == fld)
885 direction = -me.currentSortOrder;
886 me.currentSortOrder = direction;
887 me.currentSortField = fld;
888 me.sortButton1.forcePressed = (fld == SLIST_FIELD_PING);
889 me.sortButton2.forcePressed = (fld == SLIST_FIELD_NAME);
890 me.sortButton3.forcePressed = (fld == SLIST_FIELD_MAP);
891 me.sortButton4.forcePressed = 0;
892 me.sortButton5.forcePressed = (fld == SLIST_FIELD_NUMHUMANS);
894 if(me.selectedServer)
895 strunzone(me.selectedServer);
896 me.selectedServer = string_null;
897 me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
899 void XonoticServerList_positionSortButton(entity me, entity btn, float theOrigin, float theSize, string theTitle, void(entity, entity) theFunc)
901 vector originInLBSpace, sizeInLBSpace;
902 originInLBSpace = eY * (-me.itemHeight);
903 sizeInLBSpace = eY * me.itemHeight + eX * (1 - me.controlWidth);
905 vector originInDialogSpace, sizeInDialogSpace;
906 originInDialogSpace = boxToGlobal(originInLBSpace, me.Container_origin, me.Container_size);
907 sizeInDialogSpace = boxToGlobalSize(sizeInLBSpace, me.Container_size);
909 btn.Container_origin_x = originInDialogSpace.x + sizeInDialogSpace.x * theOrigin;
910 btn.Container_size_x = sizeInDialogSpace.x * theSize;
911 btn.setText(btn, theTitle);
912 btn.onClick = theFunc;
913 btn.onClickEntity = me;
916 void XonoticServerList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
918 SUPER(XonoticServerList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
920 me.realFontSize_y = me.fontSize / (absSize.y * me.itemHeight);
921 me.realFontSize_x = me.fontSize / (absSize.x * (1 - me.controlWidth));
922 me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
924 me.columnIconsOrigin = 0;
925 me.columnIconsSize = me.realFontSize.x * 4 * me.iconsSizeFactor;
926 me.columnPingSize = me.realFontSize.x * 3;
927 me.columnMapSize = me.realFontSize.x * 10;
928 me.columnTypeSize = me.realFontSize.x * 4;
929 me.columnPlayersSize = me.realFontSize.x * 5;
930 me.columnNameSize = 1 - me.columnPlayersSize - me.columnMapSize - me.columnPingSize - me.columnIconsSize - me.columnTypeSize - 5 * me.realFontSize.x;
931 me.columnPingOrigin = me.columnIconsOrigin + me.columnIconsSize + me.realFontSize.x;
932 me.columnNameOrigin = me.columnPingOrigin + me.columnPingSize + me.realFontSize.x;
933 me.columnMapOrigin = me.columnNameOrigin + me.columnNameSize + me.realFontSize.x;
934 me.columnTypeOrigin = me.columnMapOrigin + me.columnMapSize + me.realFontSize.x;
935 me.columnPlayersOrigin = me.columnTypeOrigin + me.columnTypeSize + me.realFontSize.x;
937 me.positionSortButton(me, me.sortButton1, me.columnPingOrigin, me.columnPingSize, _("Ping"), ServerList_PingSort_Click);
938 me.positionSortButton(me, me.sortButton2, me.columnNameOrigin, me.columnNameSize, _("Host name"), ServerList_NameSort_Click);
939 me.positionSortButton(me, me.sortButton3, me.columnMapOrigin, me.columnMapSize, _("Map"), ServerList_MapSort_Click);
940 me.positionSortButton(me, me.sortButton4, me.columnTypeOrigin, me.columnTypeSize, _("Type"), ServerList_TypeSort_Click);
941 me.positionSortButton(me, me.sortButton5, me.columnPlayersOrigin, me.columnPlayersSize, _("Players"), ServerList_PlayerSort_Click);
943 int f = me.currentSortField;
946 me.currentSortField = -1;
947 me.setSortOrder(me, f, me.currentSortOrder); // force resetting the sort order
950 void ServerList_Connect_Click(entity btn, entity me)
952 localcmd(sprintf("connect %s\n",
953 ((me.ipAddressBox.text != "") ?
954 me.ipAddressBox.text : me.selectedServer
958 void ServerList_Favorite_Click(entity btn, entity this)
960 string addr = this.ipAddressBox.text;
961 string ipstr = netaddress_resolve(addr, 26000);
962 if (ipstr == "") return;
963 m_play_click_sound(MENU_SOUND_SELECT);
964 this.toggleFavorite(this, addr);
965 this.ipAddressBoxFocused = -1;
967 void ServerList_Info_Click(entity btn, entity me)
970 main.serverInfoDialog.loadServerInfo(main.serverInfoDialog, me.selectedItem);
972 vector org = boxToGlobal(eY * (me.selectedItem * me.itemHeight - me.scrollPos), me.origin, me.size);
973 vector sz = boxToGlobalSize(eY * me.itemHeight + eX * (1 - me.controlWidth), me.size);
974 DialogOpenButton_Click_withCoords(me, main.serverInfoDialog, org, sz);
976 void XonoticServerList_doubleClickListBoxItem(entity me, int i, vector where)
978 ServerList_Connect_Click(NULL, me);
980 void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
982 // layout: Ping, Server name, Map name, NP, TP, MP
988 bool pure = false, pure_available = false;
989 int freeslots = -1, sflags = -1, j, m;
990 string s, typestr, versionstr, k, v, modname;
992 //printf("time: %f, i: %d, item: %d, nitems: %d\n", time, i, item, me.nItems);
994 vector oldscale = draw_scale;
995 vector oldshift = draw_shift;
996 #define SET_YRANGE(start,end) \
997 draw_scale = boxToGlobalSize(eX * 1 + eY * (end - start), oldscale); \
998 draw_shift = boxToGlobal(eY * start, oldshift, oldscale);
1000 for (j = 0; j < category_draw_count; ++j) {
1001 // Matches exactly the headings with increased height.
1002 if (i == category_item[j])
1006 if (j < category_draw_count)
1008 entity catent = RetrieveCategoryEnt(category_name[j]);
1012 (me.categoriesHeight - 1) / (me.categoriesHeight + 1),
1013 me.categoriesHeight / (me.categoriesHeight + 1)
1016 eY * me.realUpperMargin
1019 eX * (me.columnNameOrigin + (me.columnNameSize - draw_TextWidth(catent.cat_string, 0, me.realFontSize)) * 0.5),
1022 eX * (me.columnNameOrigin),
1023 strcat(catent.cat_string, ":"),
1026 SKINCOLOR_SERVERLIST_CATEGORY,
1027 SKINALPHA_SERVERLIST_CATEGORY,
1030 SET_YRANGE(me.categoriesHeight / (me.categoriesHeight + 1), 1);
1035 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
1038 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
1039 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
1042 s = gethostcachestring(SLIST_FIELD_QCSTATUS, i);
1043 m = tokenizebyseparator(s, ":");
1048 versionstr = argv(1);
1052 for(j = 2; j < m; ++j)
1056 k = substring(argv(j), 0, 1);
1057 v = substring(argv(j), 1, -1);
1060 pure = (stof(v) == 0);
1061 pure_available = true;
1064 freeslots = stof(v);
1071 #ifdef COMPAT_NO_MOD_IS_XONOTIC
1073 modname = "Xonotic";
1076 string original_modname = modname;
1077 modname = strtolower(modname);
1080 SLIST_FIELD_MOD = gethostcacheindexforkey("mod");
1081 s = gethostcachestring(SLIST_FIELD_MOD, i);
1083 if(modname == "xonotic")
1087 // list the mods here on which the pure server check actually works
1088 if(modname != "xonotic")
1089 if(modname != "instagib" || modname != "minstagib")
1090 if(modname != "cts")
1091 if(modname != "nix")
1092 if(modname != "newtoys")
1093 pure_available = false;
1095 if(gethostcachenumber(SLIST_FIELD_FREESLOTS, i) <= 0)
1096 theAlpha = SKINALPHA_SERVERLIST_FULL;
1097 else if(freeslots == 0)
1098 theAlpha = SKINALPHA_SERVERLIST_FULL; // g_maxplayers support
1099 else if (!gethostcachenumber(SLIST_FIELD_NUMHUMANS, i))
1100 theAlpha = SKINALPHA_SERVERLIST_EMPTY;
1104 p = gethostcachenumber(SLIST_FIELD_PING, i);
1105 const int PING_LOW = 75;
1106 const int PING_MED = 200;
1107 const int PING_HIGH = 500;
1109 theColor = SKINCOLOR_SERVERLIST_LOWPING + (SKINCOLOR_SERVERLIST_MEDPING - SKINCOLOR_SERVERLIST_LOWPING) * (p / PING_LOW);
1110 else if(p < PING_MED)
1111 theColor = SKINCOLOR_SERVERLIST_MEDPING + (SKINCOLOR_SERVERLIST_HIGHPING - SKINCOLOR_SERVERLIST_MEDPING) * ((p - PING_LOW) / (PING_MED - PING_LOW));
1112 else if(p < PING_HIGH)
1114 theColor = SKINCOLOR_SERVERLIST_HIGHPING;
1115 theAlpha *= 1 + (SKINALPHA_SERVERLIST_HIGHPING - 1) * ((p - PING_MED) / (PING_HIGH - PING_MED));
1120 theAlpha *= SKINALPHA_SERVERLIST_HIGHPING;
1123 if(gethostcachenumber(SLIST_FIELD_ISFAVORITE, i))
1125 theColor = theColor * (1 - SKINALPHA_SERVERLIST_FAVORITE) + SKINCOLOR_SERVERLIST_FAVORITE * SKINALPHA_SERVERLIST_FAVORITE;
1126 theAlpha = theAlpha * (1 - SKINALPHA_SERVERLIST_FAVORITE) + SKINALPHA_SERVERLIST_FAVORITE;
1129 s = gethostcachestring(SLIST_FIELD_CNAME, i);
1131 isv4 = isv6 = false;
1132 if(substring(s, 0, 1) == "[")
1137 else if(strstrofs("0123456789", substring(s, 0, 1), 0) >= 0)
1143 q = stof(substring(crypto_getencryptlevel(s), 0, 1));
1144 if((q <= 0 && cvar("crypto_aeslevel") >= 3) || (q >= 3 && cvar("crypto_aeslevel") <= 0))
1146 theColor = SKINCOLOR_SERVERLIST_IMPOSSIBLE;
1147 theAlpha = SKINALPHA_SERVERLIST_IMPOSSIBLE;
1152 if(cvar("crypto_aeslevel") >= 2)
1157 if(cvar("crypto_aeslevel") >= 1)
1167 // 2: AES recommended but not available
1168 // 3: AES possible and will be used
1169 // 4: AES recommended and will be used
1175 vector iconSize = '0 0 0';
1176 iconSize_y = me.realFontSize.y * me.iconsSizeFactor;
1177 iconSize_x = me.realFontSize.x * me.iconsSizeFactor;
1179 vector iconPos = '0 0 0';
1180 iconPos_x = (me.columnIconsSize - 3 * iconSize.x) * 0.5;
1181 iconPos_y = (1 - iconSize.y) * 0.5;
1184 if(me.seenIPv4 && me.seenIPv6)
1187 draw_Picture(iconPos, "icon_ipv6", iconSize, '1 1 1', 1);
1189 draw_Picture(iconPos, "icon_ipv4", iconSize, '1 1 1', 1);
1192 iconPos.x += iconSize.x;
1196 draw_Picture(iconPos, strcat("icon_aeslevel", ftos(q)), iconSize, '1 1 1', 1);
1198 iconPos.x += iconSize.x;
1201 if(modname == "xonotic")
1203 // Here, pure_available should always be set. If not, consider
1205 if(pure_available && pure)
1206 draw_Picture(iconPos, "icon_pure1", iconSize, '1 1 1', 1);
1210 string icon = strcat("icon_mod_", modname);
1211 if(draw_PictureSize(icon) == '0 0 0')
1214 // In mods, pure_available not being present indicates
1215 // non-support of the feature. Just show the mod icon as is
1217 if(pure_available && !pure)
1218 draw_Picture(iconPos, icon, iconSize, '1 1 1', SKINALPHA_SERVERLIST_ICON_NONPURE);
1220 draw_Picture(iconPos, icon, iconSize, '1 1 1', 1);
1223 iconPos.x += iconSize.x;
1226 if(sflags >= 0 && (sflags & SERVERFLAG_PLAYERSTATS))
1227 draw_Picture(iconPos, "icon_stats1", iconSize, '1 1 1', 1);
1229 if(isFocused && me.mouseOverIcons && !me.tooltip)
1232 if(me.seenIPv4 && me.seenIPv6)
1233 t = strcat(t, (isv6) ? "IPv6, " : "IPv4, ");
1234 t = strcat(t, _("encryption:"), " ", (q ? sprintf(_("AES level %d"), q) : ZCTX(_("ENC^none"))), ", ");
1235 t = strcat(t, sprintf(_("mod: %s"), ((modname == "xonotic") ? ZCTX(_("MOD^Default")) : original_modname)));
1237 t = strcat(t, sprintf(_(" (%s)"), (pure) ? _("official settings") : _("modified settings")));
1238 t = strcat(t, ", ");
1239 t = strcat(t, ((sflags >= 0 && (sflags & SERVERFLAG_PLAYERSTATS)) ? _("stats enabled") : _("stats disabled")));
1240 setZonedTooltip(me, t, string_null);
1248 draw_Text(me.realUpperMargin * eY + (me.columnPingOrigin + me.columnPingSize - draw_TextWidth(s, 0, me.realFontSize)) * eX, s, me.realFontSize, theColor, theAlpha, 0);
1251 s = draw_TextShortenToWidth(gethostcachestring(SLIST_FIELD_NAME, i), me.columnNameSize, 0, me.realFontSize);
1252 draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
1255 s = draw_TextShortenToWidth(gethostcachestring(SLIST_FIELD_MAP, i), me.columnMapSize, 0, me.realFontSize);
1256 draw_Text(me.realUpperMargin * eY + (me.columnMapOrigin + (me.columnMapSize - draw_TextWidth(s, 0, me.realFontSize)) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0);
1259 s = draw_TextShortenToWidth(typestr, me.columnTypeSize, 0, me.realFontSize);
1260 draw_Text(me.realUpperMargin * eY + (me.columnTypeOrigin + (me.columnTypeSize - draw_TextWidth(s, 0, me.realFontSize)) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0);
1262 // server playercount
1263 s = strcat(ftos(gethostcachenumber(SLIST_FIELD_NUMHUMANS, i)), "/", ftos(gethostcachenumber(SLIST_FIELD_MAXPLAYERS, i)));
1264 draw_Text(me.realUpperMargin * eY + (me.columnPlayersOrigin + (me.columnPlayersSize - draw_TextWidth(s, 0, me.realFontSize)) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0);
1267 void XonoticServerList_focusedItemChangeNotify(entity me)
1272 float XonoticServerList_mouseMove(entity me, vector pos)
1274 if(!SUPER(XonoticServerList).mouseMove(me, pos))
1276 me.mouseOverIcons = false;
1281 me.mouseOverIcons = (pos_x <= me.columnIconsSize);
1282 if(!me.mouseOverIcons)
1287 bool XonoticServerList_keyDown(entity me, int scan, bool ascii, bool shift)
1291 org = boxToGlobal(eY * (me.selectedItem * me.itemHeight - me.scrollPos), me.origin, me.size);
1292 sz = boxToGlobalSize(eY * me.itemHeight + eX * (1 - me.controlWidth), me.size);
1294 if(scan == K_ENTER || scan == K_KP_ENTER)
1296 ServerList_Connect_Click(NULL, me);
1299 else if(scan == K_MOUSE2 || scan == K_SPACE)
1303 m_play_click_sound(MENU_SOUND_OPEN);
1304 main.serverInfoDialog.loadServerInfo(main.serverInfoDialog, me.selectedItem);
1305 DialogOpenButton_Click_withCoords(me, main.serverInfoDialog, org, sz);
1310 else if(scan == K_INS || scan == K_MOUSE3 || scan == K_KP_INS)
1314 me.toggleFavorite(me, me.selectedServer);
1315 me.ipAddressBoxFocused = -1;
1320 else if(SUPER(XonoticServerList).keyDown(me, scan, ascii, shift))
1322 else if(!me.controlledTextbox)
1325 return me.controlledTextbox.keyDown(me.controlledTextbox, scan, ascii, shift);
1328 float XonoticServerList_getTotalHeight(entity me)
1330 float num_normal_rows = me.nItems;
1331 int num_headers = category_draw_count;
1332 return me.itemHeight * (num_normal_rows + me.categoriesHeight * num_headers);
1334 int XonoticServerList_getItemAtPos(entity me, float pos)
1336 pos = pos / me.itemHeight;
1338 for (i = category_draw_count - 1; i >= 0; --i) {
1339 int itemidx = category_item[i];
1340 float itempos = i * me.categoriesHeight + category_item[i];
1341 if (pos >= itempos + me.categoriesHeight + 1)
1342 return itemidx + 1 + floor(pos - (itempos + me.categoriesHeight + 1));
1346 // No category matches? Note that category 0 is... 0. Therefore no headings exist at all.
1349 float XonoticServerList_getItemStart(entity me, int item)
1352 for (i = category_draw_count - 1; i >= 0; --i) {
1353 int itemidx = category_item[i];
1354 float itempos = i * me.categoriesHeight + category_item[i];
1355 if (item >= itemidx + 1)
1356 return (itempos + me.categoriesHeight + 1 + item - (itemidx + 1)) * me.itemHeight;
1357 if (item >= itemidx)
1358 return itempos * me.itemHeight;
1360 // No category matches? Note that category 0 is... 0. Therefore no headings exist at all.
1361 return item * me.itemHeight;
1363 float XonoticServerList_getItemHeight(entity me, int item)
1366 for (i = 0; i < category_draw_count; ++i) {
1367 // Matches exactly the headings with increased height.
1368 if (item == category_item[i])
1369 return me.itemHeight * (me.categoriesHeight + 1);
1371 return me.itemHeight;