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