]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/serverlist.qc
more cleanup
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / serverlist.qc
1 #include "serverlist.qh"
2
3 #include "checkbox.qh"
4 #include "inputbox.qh"
5 #include "mainwindow.qh"
6 #include "dialog_multiplayer_join_serverinfo.qh"
7 #include <common/mapinfo.qh>
8
9 void SL_ProcessCategoryOverrides(.string override_field_string, .float override_field)
10 {
11         for (int i = 0; i < category_ent_count; ++i)
12         {
13                 string s = categories[i].override_field_string;
14                 if (s != "" && s != categories[i].cat_name)
15                 {
16                         int catnum = 0;
17                         for (int x = 0; x < category_ent_count; ++x)
18                         {
19                                 if(categories[x].cat_name == s)
20                                 {
21                                         catnum = x + 1;
22                                         break;
23                                 }
24                         }
25                         if (catnum)
26                         {
27                                 strfree(categories[i].override_field_string);
28                                 categories[i].override_field = catnum;
29                                 continue;
30                         }
31                         LOG_INFOF("RegisterSLCategories(): Improper override '%s' for category '%s'!", s, categories[i].cat_name);
32                 }
33                 strfree(categories[i].override_field_string);
34                 categories[i].override_field = 0;
35         }
36 }
37
38 void RegisterSLCategories()
39 {
40         entity cat;
41         #define SLIST_CATEGORY(name,enoverride,dioverride,str) \
42                 SET_FIELD_COUNT(name, CATEGORY_FIRST, category_ent_count) \
43                 CHECK_MAX_COUNT(name, MAX_CATEGORIES, category_ent_count, "SLIST_CATEGORY") \
44                 cat = categories[name - 1] = new(slist_category); \
45                 cat.cat_name = #name; \
46                 cat.cat_enoverride_string = strzone(SLIST_CATEGORY_AUTOCVAR(name)); \
47                 cat.cat_dioverride_string = strzone(dioverride); \
48                 cat.cat_string = strzone(str);
49         SLIST_CATEGORIES
50         #undef SLIST_CATEGORY
51
52         SL_ProcessCategoryOverrides(cat_enoverride_string, cat_enoverride);
53         SL_ProcessCategoryOverrides(cat_dioverride_string, cat_dioverride);
54 }
55
56 // Supporting Functions
57 entity RetrieveCategoryEnt(int catnum)
58 {
59         if((catnum > 0) && (catnum <= category_ent_count))
60         {
61                 return categories[catnum - 1];
62         }
63         else
64         {
65                 error(sprintf("RetrieveCategoryEnt(%d): Improper category number!\n", catnum));
66                 return NULL;
67         }
68 }
69
70 bool IsServerInList(string list, string srv)
71 {
72         if(srv == "")
73                 return false;
74         srv = netaddress_resolve(srv, 26000);
75         if(srv == "")
76                 return false;
77         string p = crypto_getidfp(srv);
78         int n = tokenize_console(list);
79         for(int i = 0; i < n; ++i)
80         {
81                 if(substring(argv(i), 0, 1) != "[" && strlen(argv(i)) == 44 && strstrofs(argv(i), ".", 0) < 0)
82                 {
83                         if(p && argv(i) == p)
84                                 return true;
85                 }
86                 else
87                 {
88                         if(srv == netaddress_resolve(argv(i), 26000))
89                                 return true;
90                 }
91         }
92         return false;
93 }
94
95 int CheckCategoryOverride(int cat)
96 {
97         entity catent = RetrieveCategoryEnt(cat);
98         if(catent)
99         {
100                 int override = (autocvar_menu_slist_categories ? catent.cat_enoverride : catent.cat_dioverride);
101                 if(override) { return override; }
102                 else { return cat; }
103         }
104         else
105         {
106                 error(sprintf("CheckCategoryOverride(%d): Improper category number!\n", cat));
107                 return cat;
108         }
109 }
110
111 int CheckCategoryForEntry(int entry)
112 {
113         string s, k, v, modtype = "";
114         int j, m, impure = 0, freeslots = 0, sflags = 0;
115         s = gethostcachestring(SLIST_FIELD_QCSTATUS, entry);
116         m = tokenizebyseparator(s, ":");
117
118         for(j = 2; j < m; ++j)
119         {
120                 if(argv(j) == "") { break; }
121                 k = substring(argv(j), 0, 1);
122                 v = substring(argv(j), 1, -1);
123                 switch(k)
124                 {
125                         case "P": { impure = stof(v); break; }
126                         case "S": { freeslots = stof(v); break; }
127                         case "F": { sflags = stof(v); break; }
128                         case "M": { modtype = strtolower(v); break; }
129                 }
130         }
131
132         if(modtype != "xonotic") { impure += autocvar_menu_slist_modimpurity; }
133
134         // check if this server is favorited
135         if(gethostcachenumber(SLIST_FIELD_ISFAVORITE, entry)) { return CAT_FAVORITED; }
136
137         // now check if it's recommended
138         if(autocvar_menu_slist_recommendations)
139         {
140                 string cname = gethostcachestring(SLIST_FIELD_CNAME, entry);
141
142                 if(IsPromoted(cname)) { return CAT_RECOMMENDED; }
143                 else
144                 {
145                         float recommended = 0;
146                         if(autocvar_menu_slist_recommendations & 1)
147                         {
148                                 if(IsRecommended(cname)) { ++recommended; }
149                                 else { --recommended; }
150                         }
151                         if(autocvar_menu_slist_recommendations & 2)
152                         {
153                                 if(
154                                         ///// check for minimum free slots
155                                         (freeslots >= autocvar_menu_slist_recommendations_minfreeslots)
156
157                                         && // check for purity requirement
158                                         (
159                                                 (autocvar_menu_slist_recommendations_purethreshold < 0)
160                                                 ||
161                                                 (impure <= autocvar_menu_slist_recommendations_purethreshold)
162                                         )
163
164                                         && // check for minimum amount of humans
165                                         (
166                                                 gethostcachenumber(SLIST_FIELD_NUMHUMANS, entry)
167                                                 >=
168                                                 autocvar_menu_slist_recommendations_minhumans
169                                         )
170
171                                         && // check for maximum latency
172                                         (
173                                                 gethostcachenumber(SLIST_FIELD_PING, entry)
174                                                 <=
175                                                 autocvar_menu_slist_recommendations_maxping
176                                         )
177                                 )
178                                         { ++recommended; }
179                                 else
180                                         { --recommended; }
181                         }
182                         if(recommended > 0) { return CAT_RECOMMENDED; }
183                 }
184         }
185
186         // if not favorited or recommended, check modname
187         if(modtype != "xonotic")
188         {
189                 switch(modtype)
190                 {
191                         // old servers which don't report their mod name are considered modified now
192                         case "": { return CAT_MODIFIED; }
193
194                         case "xpm": { return CAT_XPM; }
195                         case "minstagib":
196                         case "instagib": { return CAT_INSTAGIB; }
197                         case "overkill": { return CAT_OVERKILL; }
198                         //case "nix": { return CAT_NIX; }
199                         //case "newtoys": { return CAT_NEWTOYS; }
200
201                         // "cts" is allowed as compat, xdf is replacement
202                         case "cts":
203                         case "xdf": { return CAT_DEFRAG; }
204
205                         default: { LOG_TRACEF("Found strange mod type: %s", modtype); return CAT_MODIFIED; }
206                 }
207         }
208
209         // must be normal or impure server
210         return ((impure > autocvar_menu_slist_purethreshold) ? CAT_MODIFIED : CAT_NORMAL);
211 }
212
213 METHOD(XonoticServerList, toggleFavorite, void(XonoticServerList this, string srv))
214 {
215         bool adding = true;
216         string srv_resolved = netaddress_resolve(srv, 26000);
217         string p = crypto_getidfp(srv_resolved);
218         string s = cvar_string("net_slist_favorites");
219         string ret = s;
220         for (int i = 0, n = tokenize_console(s); i < n; ++i)
221         {
222                 bool match;
223                 if (substring(argv(i), 0, 1) != "[" && strlen(argv(i)) == 44 && strstrofs(argv(i), ".", 0) < 0)
224                 {
225                         // it's a pubkey hash
226                         match = (p && p == argv(i));
227                 }
228                 else
229                 {
230                         // it's an ip
231                         match = (srv_resolved == netaddress_resolve(argv(i), 26000));
232                 }
233                 if (!match) continue;
234                 // on match: remove
235                 adding = false;
236                 string before = (i > 0) ? substring(s, 0, argv_end_index(i - 1)) : "";
237                 string after = (i < n - 1) ? substring(s, argv_start_index(i + 1), -1) : "";
238                 s = strcat(before, (before != "" && after != "" ? " " : ""), after);
239                 ret = s;
240                 // keep searching
241                 // TODO: why not break here?
242                 n = tokenize_console(s);
243                 --i; // offset the increment that is about to happen
244         }
245         if (adding)
246         {
247                 ret = strcat(s, (s != "" ? " " : ""), p ? p : srv);
248         }
249         cvar_set("net_slist_favorites", ret);
250         this.refreshServerList(this, REFRESHSERVERLIST_RESORT);
251 }
252
253 void ServerList_Update_favoriteButton(entity btn, entity me)
254 {
255         entity e = me.favoriteButton;
256         if(IsFavorite(me.ipAddressBox.text))
257         {
258                 e.setText(e, _("Remove"));
259                 clearTooltip(e);
260         }
261         else
262         {
263                 e.setText(e, _("Favorite"));
264                 setZonedTooltip(e, _("Bookmark the currently highlighted server so that it's faster to find in the future"), string_null);
265         }
266 }
267
268 entity makeXonoticServerList()
269 {
270         entity me;
271         me = NEW(XonoticServerList);
272         me.configureXonoticServerList(me);
273         return me;
274 }
275 void XonoticServerList_configureXonoticServerList(entity me)
276 {
277         me.configureXonoticListBox(me);
278
279         // update field ID's
280         #define SLIST_FIELD(suffix,name) SLIST_FIELD_##suffix = gethostcacheindexforkey(name);
281         SLIST_FIELDS
282         #undef SLIST_FIELD
283
284         // clear list
285         me.nItems = 0;
286 }
287 void XonoticServerList_setSelected(entity me, int i)
288 {
289         me.lockedSelectedItem = false;
290         //int save = me.selectedItem;
291         SUPER(XonoticServerList).setSelected(me, i);
292         /*
293         if(me.selectedItem == save)
294                 return;
295         */
296         if(me.nItems == 0)
297                 return;
298         if(gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT) != me.nItems)
299                 return; // sorry, it would be wrong
300
301         strcpy(me.selectedServer, gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem));
302
303         me.ipAddressBox.setText(me.ipAddressBox, me.selectedServer);
304         me.ipAddressBox.cursorPos = strlen(me.selectedServer);
305         me.ipAddressBoxFocused = -1;
306 }
307 void XonoticServerList_refreshServerList(entity me, int mode)
308 {
309         //print("refresh of type ", ftos(mode), "\n");
310
311         if(mode >= REFRESHSERVERLIST_REFILTER)
312         {
313                 float m;
314                 int i, n;
315                 int listflags = 0;
316                 string s, typestr, modstr;
317
318                 s = me.filterString;
319
320                 m = strstrofs(s, ":", 0);
321                 if(m >= 0)
322                 {
323                         typestr = substring(s, 0, m);
324                         s = substring(s, m + 1, strlen(s) - m - 1);
325                         while(substring(s, 0, 1) == " ")
326                                 s = substring(s, 1, strlen(s) - 1);
327                 }
328                 else
329                         typestr = "";
330
331                 modstr = cvar_string("menu_slist_modfilter");
332
333                 m = SLIST_MASK_AND - 1;
334                 resethostcachemasks();
335
336                 // ping: reject negative ping (no idea why this happens in the first place, engine bug)
337                 sethostcachemasknumber(++m, SLIST_FIELD_PING, 0, SLIST_TEST_GREATEREQUAL);
338
339                 // show full button
340                 if(!me.filterShowFull)
341                 {
342                         sethostcachemasknumber(++m, SLIST_FIELD_FREESLOTS, 1, SLIST_TEST_GREATEREQUAL); // legacy
343                         sethostcachemaskstring(++m, SLIST_FIELD_QCSTATUS, ":S0:", SLIST_TEST_NOTCONTAIN); // g_maxplayers support
344                 }
345
346                 // show empty button
347                 if(!me.filterShowEmpty)
348                         sethostcachemasknumber(++m, SLIST_FIELD_NUMHUMANS, 1, SLIST_TEST_GREATEREQUAL);
349
350                 // gametype filtering
351                 if(typestr != "")
352                         sethostcachemaskstring(++m, SLIST_FIELD_QCSTATUS, strcat(typestr, ":"), SLIST_TEST_STARTSWITH);
353
354                 // mod filtering
355                 if(modstr != "")
356                 {
357                         if(substring(modstr, 0, 1) == "!")
358                                 sethostcachemaskstring(++m, SLIST_FIELD_MOD, resolvemod(substring(modstr, 1, strlen(modstr) - 1)), SLIST_TEST_NOTEQUAL);
359                         else
360                                 sethostcachemaskstring(++m, SLIST_FIELD_MOD, resolvemod(modstr), SLIST_TEST_EQUAL);
361                 }
362
363                 // server banning
364                 n = tokenizebyseparator(_Nex_ExtResponseSystem_BannedServers, " ");
365                 for(i = 0; i < n; ++i)
366                         if(argv(i) != "")
367                                 sethostcachemaskstring(++m, SLIST_FIELD_CNAME, argv(i), SLIST_TEST_NOTSTARTSWITH);
368
369                 m = SLIST_MASK_OR - 1;
370                 if(s != "")
371                 {
372                         sethostcachemaskstring(++m, SLIST_FIELD_NAME, s, SLIST_TEST_CONTAINS);
373                         sethostcachemaskstring(++m, SLIST_FIELD_MAP, s, SLIST_TEST_CONTAINS);
374                         sethostcachemaskstring(++m, SLIST_FIELD_PLAYERS, s, SLIST_TEST_CONTAINS);
375                         sethostcachemaskstring(++m, SLIST_FIELD_QCSTATUS, strcat(s, ":"), SLIST_TEST_STARTSWITH);
376                 }
377
378                 // sorting flags
379                 //listflags |= SLSF_FAVORITES;
380                 listflags |= SLSF_CATEGORIES;
381                 if(me.currentSortOrder < 0) { listflags |= SLSF_DESCENDING; }
382                 sethostcachesort(me.currentSortField, listflags);
383         }
384
385         resorthostcache();
386         if(mode >= REFRESHSERVERLIST_ASK)
387                 refreshhostcache(mode >= REFRESHSERVERLIST_RESET);
388 }
389 void XonoticServerList_focusEnter(entity me)
390 {
391         SUPER(XonoticServerList).focusEnter(me);
392         if(time < me.nextRefreshTime)
393         {
394                 //print("sorry, no refresh yet\n");
395                 return;
396         }
397         me.nextRefreshTime = time + 10;
398         me.refreshServerList(me, REFRESHSERVERLIST_ASK);
399 }
400
401 void XonoticServerList_draw(entity me)
402 {
403         int i;
404         bool found = false, owned;
405
406         if(_Nex_ExtResponseSystem_BannedServersNeedsRefresh)
407         {
408                 if(!me.needsRefresh)
409                         me.needsRefresh = 2;
410                 _Nex_ExtResponseSystem_BannedServersNeedsRefresh = 0;
411         }
412
413         if(_Nex_ExtResponseSystem_PromotedServersNeedsRefresh)
414         {
415                 if(!me.needsRefresh)
416                         me.needsRefresh = 3;
417                 _Nex_ExtResponseSystem_PromotedServersNeedsRefresh = 0;
418         }
419
420         if(_Nex_ExtResponseSystem_RecommendedServersNeedsRefresh)
421         {
422                 if(!me.needsRefresh)
423                         me.needsRefresh = 3;
424                 _Nex_ExtResponseSystem_RecommendedServersNeedsRefresh = 0;
425         }
426
427         if(me.currentSortField == -1)
428         {
429                 me.setSortOrder(me, SLIST_FIELD_PING, +1);
430                 me.refreshServerList(me, REFRESHSERVERLIST_RESET);
431         }
432         else if(me.needsRefresh == 1)
433         {
434                 me.needsRefresh = 2; // delay by one frame to make sure "slist" has been executed
435         }
436         else if(me.needsRefresh == 2)
437         {
438                 me.needsRefresh = 0;
439                 me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
440         }
441         else if(me.needsRefresh == 3)
442         {
443                 me.needsRefresh = 0;
444                 me.refreshServerList(me, REFRESHSERVERLIST_RESORT);
445         }
446
447         owned = ((me.selectedServer == me.ipAddressBox.text) && (me.ipAddressBox.text != ""));
448
449         for(i = 0; i < category_draw_count; ++i) { category_name[i] = -1; category_item[i] = -1; }
450         category_draw_count = 0;
451
452         if(autocvar_menu_slist_categories >= 0) // if less than 0, don't even draw a category heading for favorites
453         {
454                 float itemcount = gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT);
455                 me.nItems = itemcount;
456
457                 //float visible = floor(me.scrollPos / me.itemHeight);
458                 // ^ unfortunately no such optimization can be made-- we must process through the
459                 // entire list, otherwise there is no way to know which item is first in its category.
460
461                 // binary search method suggested by div
462                 float begin = 0;
463                 for(int j = 1; j <= category_ent_count; ++j) {
464                         float first = begin;
465                         float last = (itemcount - 1);
466                         if (first > last) {
467                                 // List is empty.
468                                 break;
469                         }
470                         float catf = gethostcachenumber(SLIST_FIELD_CATEGORY, first);
471                         float catl = gethostcachenumber(SLIST_FIELD_CATEGORY, last);
472                         if (catf > j) {
473                                 // The first one is already > j.
474                                 // Therefore, category j does not exist.
475                                 // Higher numbered categories do exist though.
476                         } else if (catl < j) {
477                                 // The last one is < j.
478                                 // Thus this category - and any following -
479                                 // don't exist.
480                                 break;
481                         } else if (catf == j) {
482                                 // Starts at first. This breaks the loop
483                                 // invariant in the binary search and thus has
484                                 // to be handled separately.
485                                 if(gethostcachenumber(SLIST_FIELD_CATEGORY, first) != j)
486                                         error("Category mismatch I");
487                                 if(first > 0)
488                                         if(gethostcachenumber(SLIST_FIELD_CATEGORY, first - 1) == j)
489                                                 error("Category mismatch II");
490                                 category_name[category_draw_count] = j;
491                                 category_item[category_draw_count] = first;
492                                 ++category_draw_count;
493                                 begin = first + 1;
494                         } else {
495                                 // At this point, catf <= j < catl, thus
496                                 // catf < catl, thus first < last.
497                                 // INVARIANTS:
498                                 // last - first >= 1
499                                 // catf == gethostcachenumber(SLIST_FIELD_CATEGORY(first)
500                                 // catl == gethostcachenumber(SLIST_FIELD_CATEGORY(last)
501                                 // catf < j
502                                 // catl >= j
503                                 while (last - first > 1) {
504                                         float middle = floor((first + last) / 2);
505                                         // By loop condition, middle != first && middle != last.
506                                         float cat = gethostcachenumber(SLIST_FIELD_CATEGORY, middle);
507                                         if (cat >= j) {
508                                                 last = middle;
509                                                 catl = cat;
510                                         } else {
511                                                 first = middle;
512                                                 catf = cat;
513                                         }
514                                 }
515                                 if (catl == j) {
516                                         if(gethostcachenumber(SLIST_FIELD_CATEGORY, last) != j)
517                                                 error("Category mismatch III");
518                                         if(last > 0)
519                                                 if(gethostcachenumber(SLIST_FIELD_CATEGORY, last - 1) == j)
520                                                         error("Category mismatch IV");
521                                         category_name[category_draw_count] = j;
522                                         category_item[category_draw_count] = last;
523                                         ++category_draw_count;
524                                         begin = last + 1; // already scanned through these, skip 'em
525                                 }
526                                 else
527                                         begin = last; // already scanned through these, skip 'em
528                         }
529                 }
530                 if(autocvar_menu_slist_categories_onlyifmultiple && (category_draw_count == 1))
531                 {
532                         category_name[0] = -1;
533                         category_item[0] = -1;
534                         category_draw_count = 0;
535                         me.nItems = itemcount;
536                 }
537         }
538         else { me.nItems = gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT); }
539
540         me.connectButton.disabled = (me.lockedSelectedItem || (me.nItems == 0 && me.ipAddressBox.text == ""));
541         //me.disconnectButton.disabled = (!(gamestatus & (GAME_ISSERVER | GAME_CONNECTED)));
542         me.infoButton.disabled = (me.lockedSelectedItem || me.nItems == 0 || !owned);
543         me.favoriteButton.disabled = (me.lockedSelectedItem || (me.nItems == 0 && me.ipAddressBox.text == ""));
544
545         if(me.lockedSelectedItem)
546         {
547                 if(me.nItems > 0)
548                 {
549                         if(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem) != me.selectedServer)
550                         {
551                                 strcpy(me.selectedServer, gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem));
552                         }
553                         found = true;
554                 }
555         }
556         else if(me.selectedServer)
557         {
558                 for(i = 0; i < me.nItems; ++i)
559                 {
560                         if(gethostcachestring(SLIST_FIELD_CNAME, i) == me.selectedServer)
561                         {
562                                 // don't follow the selected item with SUPER(XonoticServerList).setSelected(me, i);
563                                 me.selectedItem = i;
564                                 found = true;
565                                 break;
566                         }
567                 }
568         }
569         if(!found)
570         {
571                 if(me.nItems > 0)
572                 {
573                         // selected server disappeared, select the last server (scrolling to it)
574                         if(me.selectedItem >= me.nItems)
575                                 SUPER(XonoticServerList).setSelected(me, me.nItems - 1);
576                         strcpy(me.selectedServer, gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem));
577                 }
578         }
579
580         if(owned)
581         {
582                 if(me.selectedServer != me.ipAddressBox.text)
583                 {
584                         me.ipAddressBox.setText(me.ipAddressBox, me.selectedServer);
585                         me.ipAddressBox.cursorPos = strlen(me.selectedServer);
586                         me.ipAddressBoxFocused = -1;
587                 }
588         }
589
590         if(me.ipAddressBoxFocused != me.ipAddressBox.focused)
591         {
592                 if(me.ipAddressBox.focused || me.ipAddressBoxFocused < 0)
593                         ServerList_Update_favoriteButton(NULL, me);
594                 me.ipAddressBoxFocused = me.ipAddressBox.focused;
595         }
596
597         SUPER(XonoticServerList).draw(me);
598 }
599 void ServerList_PingSort_Click(entity btn, entity me)
600 {
601         me.setSortOrder(me, SLIST_FIELD_PING, +1);
602 }
603 void ServerList_NameSort_Click(entity btn, entity me)
604 {
605         me.setSortOrder(me, SLIST_FIELD_NAME, -1); // why?
606 }
607 void ServerList_MapSort_Click(entity btn, entity me)
608 {
609         me.setSortOrder(me, SLIST_FIELD_MAP, -1); // why?
610 }
611 void ServerList_PlayerSort_Click(entity btn, entity me)
612 {
613         me.setSortOrder(me, SLIST_FIELD_NUMHUMANS, -1);
614 }
615 void ServerList_TypeSort_Click(entity btn, entity me)
616 {
617         string s = me.filterString;
618         int m = strstrofs(s, ":", 0);
619         if(m >= 0)
620         {
621                 s = substring(s, 0, m);
622                 while(substring(s, m+1, 1) == " ") // skip spaces
623                         ++m;
624         }
625         else
626                 s = "";
627
628         Gametype first = NULL; FOREACH(Gametypes, !first, first = it; break);
629         bool flag = false;
630         FOREACH(Gametypes, s == MapInfo_Type_ToString(it), {
631                 // the type was found
632                 // choose the next one
633                 flag = true;
634                 s = MapInfo_Type_ToString(Gametypes_from(it.m_id + 1));
635                 if (s == "") s = MapInfo_Type_ToString(first);
636                 break;
637         });
638         if (!flag) {
639                 // no type was found
640                 // choose the first one
641                 s = MapInfo_Type_ToString(first);
642         }
643
644         if(s != "") s = strcat(s, ":");
645         s = strcat(s, substring(me.filterString, m+1, strlen(me.filterString) - m - 1));
646
647         me.controlledTextbox.setText(me.controlledTextbox, s);
648         me.controlledTextbox.keyDown(me.controlledTextbox, K_END, 0, 0);
649         me.controlledTextbox.keyUp(me.controlledTextbox, K_END, 0, 0);
650         //ServerList_Filter_Change(me.controlledTextbox, me);
651 }
652 void ServerList_Filter_Change(entity box, entity me)
653 {
654         strfree(me.filterString);
655         if(box.text != "")
656                 me.filterString = strzone(box.text);
657         me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
658
659         me.ipAddressBox.setText(me.ipAddressBox, "");
660         me.ipAddressBox.cursorPos = 0;
661         me.ipAddressBoxFocused = -1;
662 }
663 void ServerList_Categories_Click(entity box, entity me)
664 {
665         box.setChecked(box, autocvar_menu_slist_categories = !autocvar_menu_slist_categories);
666         me.refreshServerList(me, REFRESHSERVERLIST_RESORT);
667
668         me.ipAddressBox.setText(me.ipAddressBox, "");
669         me.ipAddressBox.cursorPos = 0;
670         me.ipAddressBoxFocused = -1;
671 }
672 void ServerList_ShowEmpty_Click(entity box, entity me)
673 {
674         box.setChecked(box, me.filterShowEmpty = !me.filterShowEmpty);
675         me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
676
677         me.ipAddressBox.setText(me.ipAddressBox, "");
678         me.ipAddressBox.cursorPos = 0;
679         me.ipAddressBoxFocused = -1;
680 }
681 void ServerList_ShowFull_Click(entity box, entity me)
682 {
683         box.setChecked(box, me.filterShowFull = !me.filterShowFull);
684         me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
685
686         me.ipAddressBox.setText(me.ipAddressBox, "");
687         me.ipAddressBox.cursorPos = 0;
688         me.ipAddressBoxFocused = -1;
689 }
690 void XonoticServerList_setSortOrder(entity me, int fld, int direction)
691 {
692         if(me.currentSortField == fld)
693                 direction = -me.currentSortOrder;
694         me.currentSortOrder = direction;
695         me.currentSortField = fld;
696         me.sortButton1.forcePressed = (fld == SLIST_FIELD_PING);
697         me.sortButton2.forcePressed = (fld == SLIST_FIELD_NAME);
698         me.sortButton3.forcePressed = (fld == SLIST_FIELD_MAP);
699         me.sortButton4.forcePressed = 0;
700         me.sortButton5.forcePressed = (fld == SLIST_FIELD_NUMHUMANS);
701         me.selectedItem = 0;
702         strfree(me.selectedServer);
703         me.refreshServerList(me, REFRESHSERVERLIST_REFILTER);
704 }
705 void XonoticServerList_positionSortButton(entity me, entity btn, float theOrigin, float theSize, string theTitle, void(entity, entity) theFunc)
706 {
707         vector originInLBSpace, sizeInLBSpace;
708         originInLBSpace = eY * (-me.itemHeight);
709         sizeInLBSpace = eY * me.itemHeight + eX * (1 - me.controlWidth);
710
711         vector originInDialogSpace, sizeInDialogSpace;
712         originInDialogSpace = boxToGlobal(originInLBSpace, me.Container_origin, me.Container_size);
713         sizeInDialogSpace = boxToGlobalSize(sizeInLBSpace, me.Container_size);
714
715         btn.Container_origin_x = originInDialogSpace.x + sizeInDialogSpace.x * theOrigin;
716         btn.Container_size_x   =                         sizeInDialogSpace.x * theSize;
717         btn.setText(btn, theTitle);
718         btn.onClick = theFunc;
719         btn.onClickEntity = me;
720         btn.resized = 1;
721 }
722 void XonoticServerList_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
723 {
724         SUPER(XonoticServerList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
725
726         me.realFontSize_y = me.fontSize / (absSize.y * me.itemHeight);
727         me.realFontSize_x = me.fontSize / (absSize.x * (1 - me.controlWidth));
728         me.realUpperMargin = 0.5 * (1 - me.realFontSize.y);
729
730         me.columnIconsOrigin = 0;
731         me.columnIconsSize = me.realFontSize.x * 4 * me.iconsSizeFactor;
732         me.columnPingSize = me.realFontSize.x * 3;
733         me.columnMapSize = me.realFontSize.x * 10;
734         me.columnTypeSize = me.realFontSize.x * 4;
735         me.columnPlayersSize = me.realFontSize.x * 5;
736         me.columnNameSize = 1 - me.columnPlayersSize - me.columnMapSize - me.columnPingSize - me.columnIconsSize - me.columnTypeSize - 5 * me.realFontSize.x;
737         me.columnPingOrigin = me.columnIconsOrigin + me.columnIconsSize + me.realFontSize.x;
738         me.columnNameOrigin = me.columnPingOrigin + me.columnPingSize + me.realFontSize.x;
739         me.columnMapOrigin = me.columnNameOrigin + me.columnNameSize + me.realFontSize.x;
740         me.columnTypeOrigin = me.columnMapOrigin + me.columnMapSize + me.realFontSize.x;
741         me.columnPlayersOrigin = me.columnTypeOrigin + me.columnTypeSize + me.realFontSize.x;
742
743         me.positionSortButton(me, me.sortButton1, me.columnPingOrigin, me.columnPingSize, _("Ping"), ServerList_PingSort_Click);
744         me.positionSortButton(me, me.sortButton2, me.columnNameOrigin, me.columnNameSize, _("Hostname"), ServerList_NameSort_Click);
745         me.positionSortButton(me, me.sortButton3, me.columnMapOrigin, me.columnMapSize, _("Map"), ServerList_MapSort_Click);
746         me.positionSortButton(me, me.sortButton4, me.columnTypeOrigin, me.columnTypeSize, _("Type"), ServerList_TypeSort_Click);
747         me.positionSortButton(me, me.sortButton5, me.columnPlayersOrigin, me.columnPlayersSize, _("Players"), ServerList_PlayerSort_Click);
748
749         int f = me.currentSortField;
750         if(f >= 0)
751         {
752                 me.currentSortField = -1;
753                 me.setSortOrder(me, f, me.currentSortOrder); // force resetting the sort order
754         }
755 }
756 void ServerList_Connect_Click(entity btn, entity me)
757 {
758         if (me.lockedSelectedItem)
759                 return;
760         string sv = (me.ipAddressBox.text != "") ? me.ipAddressBox.text : me.selectedServer;
761         localcmd(sprintf("connect %s\n", sv));
762 }
763 void ServerList_Favorite_Click(entity btn, entity this)
764 {
765         string addr = this.ipAddressBox.text;
766         string ipstr = netaddress_resolve(addr, 26000);
767         if (ipstr == "") return;
768         m_play_click_sound(MENU_SOUND_SELECT);
769         this.toggleFavorite(this, addr);
770         this.ipAddressBoxFocused = -1;
771 }
772 void ServerList_Info_Click(entity btn, entity me)
773 {
774         if (me.nItems != 0)
775                 main.serverInfoDialog.loadServerInfo(main.serverInfoDialog, me.selectedItem);
776
777         vector org = boxToGlobal(eY * (me.selectedItem * me.itemHeight - me.scrollPos), me.origin, me.size);
778         vector sz = boxToGlobalSize(eY * me.itemHeight + eX * (1 - me.controlWidth), me.size);
779         DialogOpenButton_Click_withCoords(me, main.serverInfoDialog, org, sz);
780 }
781 void XonoticServerList_doubleClickListBoxItem(entity me, int i, vector where)
782 {
783         ServerList_Connect_Click(NULL, me);
784 }
785 void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, bool isFocused)
786 {
787         vector oldscale = draw_scale;
788         vector oldshift = draw_shift;
789 #define SET_YRANGE(start,end) \
790         draw_scale = boxToGlobalSize(eX + eY * (end - start), oldscale); \
791         draw_shift = boxToGlobal(eY * start, oldshift, oldscale);
792
793         int c;
794         for (c = 0; c < category_draw_count; ++c) {
795                 // Matches exactly the headings with increased height.
796                 if (i == category_item[c])
797                         break;
798         }
799
800         if (c < category_draw_count)
801         {
802                 entity catent = RetrieveCategoryEnt(category_name[c]);
803                 if(catent)
804                 {
805                         SET_YRANGE(
806                                 (me.categoriesHeight - 1) / (me.categoriesHeight + 1),
807                                 me.categoriesHeight / (me.categoriesHeight + 1)
808                         );
809                         draw_Text(
810                                 eY * me.realUpperMargin
811                                 +
812 #if 0
813                                 eX * (me.columnNameOrigin + (me.columnNameSize - draw_TextWidth(catent.cat_string, 0, me.realFontSize)) * 0.5),
814                                 catent.cat_string,
815 #else
816                                 eX * (me.columnNameOrigin),
817                                 strcat(catent.cat_string, ":"),
818 #endif
819                                 me.realFontSize,
820                                 SKINCOLOR_SERVERLIST_CATEGORY,
821                                 SKINALPHA_SERVERLIST_CATEGORY,
822                                 0
823                         );
824                         SET_YRANGE(me.categoriesHeight / (me.categoriesHeight + 1), 1);
825                 }
826         }
827
828         if(isSelected && !me.lockedSelectedItem)
829                 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
830         else if(isFocused)
831         {
832                 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
833                 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
834         }
835
836         string s = gethostcachestring(SLIST_FIELD_QCSTATUS, i);
837         int m = tokenizebyseparator(s, ":");
838         string typestr = "", versionstr = "";
839         if(m >= 2)
840         {
841                 typestr = argv(0);
842                 versionstr = argv(1);
843         }
844         bool pure = false, pure_available = false;
845         int freeslots = -1, sflags = -1;
846         string modname = "";
847         for(int j = 2; j < m; ++j)
848         {
849                 if(argv(j) == "")
850                         break;
851                 string key = substring(argv(j), 0, 1);
852                 string value = substring(argv(j), 1, -1);
853                 if(key == "P")
854                 {
855                         pure = (stof(value) == 0);
856                         pure_available = true;
857                 }
858                 else if(key == "S")
859                         freeslots = stof(value);
860                 else if(key == "F")
861                         sflags = stoi(value);
862                 else if(key == "M")
863                         modname = value;
864         }
865
866 #ifdef COMPAT_NO_MOD_IS_XONOTIC
867         if(modname == "")
868                 modname = "Xonotic";
869 #endif
870
871         string original_modname = modname;
872         modname = strtolower(modname);
873
874         /*
875         SLIST_FIELD_MOD = gethostcacheindexforkey("mod");
876         s = gethostcachestring(SLIST_FIELD_MOD, i);
877         if(s != "data")
878                 if(modname == "xonotic")
879                         modname = s;
880         */
881
882         // list the mods here on which the pure server check actually works
883         if(modname != "xonotic")
884         if(modname != "instagib" || modname != "minstagib")
885         if(modname != "cts")
886         if(modname != "nix")
887         if(modname != "newtoys")
888                 pure_available = false;
889
890         float theAlpha;
891         if(gethostcachenumber(SLIST_FIELD_FREESLOTS, i) <= 0)
892                 theAlpha = SKINALPHA_SERVERLIST_FULL;
893         else if(freeslots == 0)
894                 theAlpha = SKINALPHA_SERVERLIST_FULL; // g_maxplayers support
895         else if (!gethostcachenumber(SLIST_FIELD_NUMHUMANS, i))
896                 theAlpha = SKINALPHA_SERVERLIST_EMPTY;
897         else
898                 theAlpha = 1;
899
900         float ping = gethostcachenumber(SLIST_FIELD_PING, i);
901         const int PING_LOW = 75;
902         const int PING_MED = 200;
903         const int PING_HIGH = 500;
904         vector theColor;
905         if(ping < PING_LOW)
906                 theColor = SKINCOLOR_SERVERLIST_LOWPING + (SKINCOLOR_SERVERLIST_MEDPING - SKINCOLOR_SERVERLIST_LOWPING) * (ping / PING_LOW);
907         else if(ping < PING_MED)
908                 theColor = SKINCOLOR_SERVERLIST_MEDPING + (SKINCOLOR_SERVERLIST_HIGHPING - SKINCOLOR_SERVERLIST_MEDPING) * ((ping - PING_LOW) / (PING_MED - PING_LOW));
909         else if(ping < PING_HIGH)
910         {
911                 theColor = SKINCOLOR_SERVERLIST_HIGHPING;
912                 theAlpha *= 1 + (SKINALPHA_SERVERLIST_HIGHPING - 1) * ((ping - PING_MED) / (PING_HIGH - PING_MED));
913         }
914         else
915         {
916                 theColor = eX;
917                 theAlpha *= SKINALPHA_SERVERLIST_HIGHPING;
918         }
919
920         if(gethostcachenumber(SLIST_FIELD_ISFAVORITE, i))
921         {
922                 theColor = theColor * (1 - SKINALPHA_SERVERLIST_FAVORITE) + SKINCOLOR_SERVERLIST_FAVORITE * SKINALPHA_SERVERLIST_FAVORITE;
923                 theAlpha = theAlpha * (1 - SKINALPHA_SERVERLIST_FAVORITE) + SKINALPHA_SERVERLIST_FAVORITE;
924         }
925
926         s = gethostcachestring(SLIST_FIELD_CNAME, i);
927
928         bool isv4 = false, isv6 = false;
929         if(substring(s, 0, 1) == "[")
930         {
931                 isv6 = true;
932                 me.seenIPv6 += 1;
933         }
934         else if(IS_DIGIT(substring(s, 0, 1)))
935         {
936                 isv4 = true;
937                 me.seenIPv4 += 1;
938         }
939
940         int crypto = stof(substring(crypto_getencryptlevel(s), 0, 1));
941         if((crypto <= 0 && cvar("crypto_aeslevel") >= 3) || (crypto >= 3 && cvar("crypto_aeslevel") <= 0))
942         {
943                 theColor = SKINCOLOR_SERVERLIST_IMPOSSIBLE;
944                 theAlpha = SKINALPHA_SERVERLIST_IMPOSSIBLE;
945         }
946
947         if(crypto == 1)
948         {
949                 if(cvar("crypto_aeslevel") >= 2)
950                         crypto |= 4;
951         }
952         if(crypto == 2)
953         {
954                 if(cvar("crypto_aeslevel") >= 1)
955                         crypto |= 4;
956         }
957         if(crypto == 3)
958                 crypto = 5;
959         else if(crypto >= 3)
960                 crypto -= 2;
961         // possible status:
962         // 0: crypto off
963         // 1: AES possible
964         // 2: AES recommended but not available
965         // 3: AES possible and will be used
966         // 4: AES recommended and will be used
967         // 5: AES required
968
969         // --------------
970         //  RENDER ICONS
971         // --------------
972         vector iconSize = '0 0 0';
973         iconSize_y = me.realFontSize.y * me.iconsSizeFactor;
974         iconSize_x = me.realFontSize.x * me.iconsSizeFactor;
975
976         vector iconPos = '0 0 0';
977         iconPos_x = (me.columnIconsSize - 3 * iconSize.x) * 0.5;
978         iconPos_y = (1 - iconSize.y) * 0.5;
979
980         // IP
981         if(me.seenIPv4 && me.seenIPv6)
982         {
983                 if(isv6)
984                         draw_Picture(iconPos, "icon_ipv6", iconSize, '1 1 1', 1);
985                 else if(isv4)
986                         draw_Picture(iconPos, "icon_ipv4", iconSize, '1 1 1', 1);
987         }
988
989         iconPos.x += iconSize.x;
990
991         // AES
992         if(crypto > 0)
993                 draw_Picture(iconPos, strcat("icon_aeslevel", ftos(crypto)), iconSize, '1 1 1', 1);
994
995         iconPos.x += iconSize.x;
996
997         // Mod
998         if(modname == "xonotic")
999         {
1000                 // Here, pure_available should always be set. If not, consider
1001                 // it an impurity.
1002                 if(pure_available && pure)
1003                         draw_Picture(iconPos, "icon_pure1", iconSize, '1 1 1', 1);
1004         }
1005         else
1006         {
1007                 string icon = strcat("icon_mod_", modname);
1008                 if(draw_PictureSize(icon) == '0 0 0')
1009                         icon = "icon_mod_";
1010
1011                 // In mods, pure_available not being present indicates
1012                 // non-support of the feature. Just show the mod icon as is
1013                 // then.
1014                 if(pure_available && !pure)
1015                         draw_Picture(iconPos, icon, iconSize, '1 1 1', SKINALPHA_SERVERLIST_ICON_NONPURE);
1016                 else
1017                         draw_Picture(iconPos, icon, iconSize, '1 1 1', 1);
1018         }
1019
1020         iconPos.x += iconSize.x;
1021
1022         // Stats
1023         if(sflags >= 0 && (sflags & SERVERFLAG_PLAYERSTATS))
1024                 draw_Picture(iconPos, "icon_stats1", iconSize, '1 1 1', 1);
1025
1026         if(isFocused && me.mouseOverIcons && !me.tooltip)
1027         {
1028                 string t = "";
1029                 if(me.seenIPv4 && me.seenIPv6)
1030                         t = strcat(t, (isv6) ? "IPv6, " : "IPv4, ");
1031                 t = strcat(t, _("encryption:"), " ", (crypto ? sprintf(_("AES level %d"), crypto) : ZCTX(_("ENC^none"))), ", ");
1032                 t = strcat(t, sprintf(_("mod: %s"), ((modname == "xonotic") ? ZCTX(_("MOD^Default")) : original_modname)));
1033                 if(pure_available)
1034                         t = strcat(t, sprintf(" (%s)", (pure) ? _("official settings") : _("modified settings")));
1035                 t = strcat(t, ", ");
1036                 t = strcat(t, ((sflags >= 0 && (sflags & SERVERFLAG_PLAYERSTATS)) ? _("stats enabled") : _("stats disabled")));
1037                 setZonedTooltip(me, t, string_null);
1038         }
1039         // --------------
1040         //  RENDER TEXT
1041         // --------------
1042
1043         // ping
1044         s = ftos(ping);
1045         draw_Text(me.realUpperMargin * eY + (me.columnPingOrigin + me.columnPingSize - draw_TextWidth(s, 0, me.realFontSize)) * eX, s, me.realFontSize, theColor, theAlpha, 0);
1046
1047         // server name
1048         s = draw_TextShortenToWidth(gethostcachestring(SLIST_FIELD_NAME, i), me.columnNameSize, 0, me.realFontSize);
1049         draw_Text(me.realUpperMargin * eY + me.columnNameOrigin * eX, s, me.realFontSize, theColor, theAlpha, 0);
1050
1051         // server map
1052         s = draw_TextShortenToWidth(gethostcachestring(SLIST_FIELD_MAP, i), me.columnMapSize, 0, me.realFontSize);
1053         draw_Text(me.realUpperMargin * eY + (me.columnMapOrigin + (me.columnMapSize - draw_TextWidth(s, 0, me.realFontSize)) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0);
1054
1055         // server gametype
1056         s = draw_TextShortenToWidth(typestr, me.columnTypeSize, 0, me.realFontSize);
1057         draw_Text(me.realUpperMargin * eY + (me.columnTypeOrigin + (me.columnTypeSize - draw_TextWidth(s, 0, me.realFontSize)) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0);
1058
1059         // server playercount
1060         s = strcat(ftos(gethostcachenumber(SLIST_FIELD_NUMHUMANS, i)), "/", ftos(gethostcachenumber(SLIST_FIELD_MAXPLAYERS, i)));
1061         draw_Text(me.realUpperMargin * eY + (me.columnPlayersOrigin + (me.columnPlayersSize - draw_TextWidth(s, 0, me.realFontSize)) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0);
1062 }
1063
1064 void XonoticServerList_focusedItemChangeNotify(entity me)
1065 {
1066         clearTooltip(me);
1067 }
1068
1069 float XonoticServerList_mouseMove(entity me, vector pos)
1070 {
1071         if(!SUPER(XonoticServerList).mouseMove(me, pos))
1072         {
1073                 me.mouseOverIcons = false;
1074                 clearTooltip(me);
1075                 return 1;
1076         }
1077
1078         me.mouseOverIcons = (pos_x <= me.columnIconsSize);
1079         if(!me.mouseOverIcons)
1080                 clearTooltip(me);
1081         return 1;
1082 }
1083
1084 bool XonoticServerList_keyDown(entity me, int scan, bool ascii, bool shift)
1085 {
1086         if(scan == K_ENTER || scan == K_KP_ENTER)
1087         {
1088                 ServerList_Connect_Click(NULL, me);
1089                 return true;
1090         }
1091         else if(scan == K_MOUSE2 || scan == K_SPACE)
1092         {
1093                 if(me.nItems != 0)
1094                 {
1095                         vector org = boxToGlobal(eY * (me.selectedItem * me.itemHeight - me.scrollPos), me.origin, me.size);
1096                         vector sz = boxToGlobalSize(eY * me.itemHeight + eX * (1 - me.controlWidth), me.size);
1097                         m_play_click_sound(MENU_SOUND_OPEN);
1098                         main.serverInfoDialog.loadServerInfo(main.serverInfoDialog, me.selectedItem);
1099                         DialogOpenButton_Click_withCoords(me, main.serverInfoDialog, org, sz);
1100                         return true;
1101                 }
1102                 return false;
1103         }
1104         else if(scan == K_INS || scan == K_MOUSE3 || scan == K_KP_INS)
1105         {
1106                 if(me.nItems != 0)
1107                 {
1108                         me.toggleFavorite(me, me.selectedServer);
1109                         me.ipAddressBoxFocused = -1;
1110                         return true;
1111                 }
1112                 return false;
1113         }
1114         else if(SUPER(XonoticServerList).keyDown(me, scan, ascii, shift))
1115                 return true;
1116         else if(!me.controlledTextbox)
1117                 return false;
1118         else
1119                 return me.controlledTextbox.keyDown(me.controlledTextbox, scan, ascii, shift);
1120 }
1121
1122 float XonoticServerList_getTotalHeight(entity me)
1123 {
1124         float num_normal_rows = me.nItems;
1125         int num_headers = category_draw_count;
1126         return me.itemHeight * (num_normal_rows + me.categoriesHeight * num_headers);
1127 }
1128 int XonoticServerList_getItemAtPos(entity me, float pos)
1129 {
1130         pos = pos / me.itemHeight;
1131         int i;
1132         for (i = category_draw_count - 1; i >= 0; --i) {
1133                 int itemidx = category_item[i];
1134                 float itempos = i * me.categoriesHeight + category_item[i];
1135                 if (pos >= itempos + me.categoriesHeight + 1)
1136                         return itemidx + 1 + floor(pos - (itempos + me.categoriesHeight + 1));
1137                 if (pos >= itempos)
1138                         return itemidx;
1139         }
1140         // No category matches? Note that category 0 is... 0. Therefore no headings exist at all.
1141         return floor(pos);
1142 }
1143 float XonoticServerList_getItemStart(entity me, int item)
1144 {
1145         int i;
1146         for (i = category_draw_count - 1; i >= 0; --i) {
1147                 int itemidx = category_item[i];
1148                 float itempos = i * me.categoriesHeight + category_item[i];
1149                 if (item >= itemidx + 1)
1150                         return (itempos + me.categoriesHeight + 1 + item - (itemidx + 1)) * me.itemHeight;
1151                 if (item >= itemidx)
1152                         return itempos * me.itemHeight;
1153         }
1154         // No category matches? Note that category 0 is... 0. Therefore no headings exist at all.
1155         return item * me.itemHeight;
1156 }
1157 float XonoticServerList_getItemHeight(entity me, int item)
1158 {
1159         int i;
1160         for (i = 0; i < category_draw_count; ++i) {
1161                 // Matches exactly the headings with increased height.
1162                 if (item == category_item[i])
1163                         return me.itemHeight * (me.categoriesHeight + 1);
1164         }
1165         return me.itemHeight;
1166 }