X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fmenu%2Fxonotic%2Fserverlist.qc;h=11266b7c2f9e35948574f54fbd3bd9c5b60e1373;hb=3ac61b98c83be079c61cf525491d2028b2a889dc;hp=fc2ba573bbaa7448addcd648cde86d9a2ae421e2;hpb=109c5785a22fb4336ac5e91d5f1fa91678582164;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/menu/xonotic/serverlist.qc b/qcsrc/menu/xonotic/serverlist.qc index fc2ba573b..11266b7c2 100644 --- a/qcsrc/menu/xonotic/serverlist.qc +++ b/qcsrc/menu/xonotic/serverlist.qc @@ -6,6 +6,36 @@ #include "dialog_multiplayer_join_serverinfo.qh" #include +void SL_ProcessCategoryOverrides(.string override_field_string, .float override_field) +{ + string s; + for (int i = 0; i < category_ent_count; ++i) + { + s = categories[i].override_field_string; + if (s != "" && s != categories[i].cat_name) + { + int catnum = 0; + for (int x = 0; x < category_ent_count; ++x) + { + if(categories[x].cat_name == s) + { + catnum = x + 1; + break; + } + } + if (catnum) + { + strfree(categories[i].override_field_string); + categories[i].override_field = catnum; + continue; + } + LOG_INFOF("RegisterSLCategories(): Improper override '%s' for category '%s'!", s, categories[i].cat_name); + } + strfree(categories[i].override_field_string); + categories[i].override_field = 0; + } +} + void RegisterSLCategories() { entity cat; @@ -20,44 +50,8 @@ void RegisterSLCategories() SLIST_CATEGORIES #undef SLIST_CATEGORY - int i, x, catnum; - string s; - - #define PROCESS_OVERRIDE(override_string,override_field) \ - for(i = 0; i < category_ent_count; ++i) \ - { \ - s = categories[i].override_string; \ - if((s != "") && (s != categories[i].cat_name)) \ - { \ - catnum = 0; \ - for(x = 0; x < category_ent_count; ++x) \ - { if(categories[x].cat_name == s) { \ - catnum = (x+1); \ - break; \ - } } \ - if(catnum) \ - { \ - strunzone(categories[i].override_string); \ - categories[i].override_string = string_null; \ - categories[i].override_field = catnum; \ - continue; \ - } \ - else \ - { \ - LOG_INFOF( \ - "RegisterSLCategories(): Improper override '%s' for category '%s'!\n", \ - s, \ - categories[i].cat_name \ - ); \ - } \ - } \ - strunzone(categories[i].override_string); \ - categories[i].override_string = string_null; \ - categories[i].override_field = 0; \ - } - PROCESS_OVERRIDE(cat_enoverride_string, cat_enoverride) - PROCESS_OVERRIDE(cat_dioverride_string, cat_dioverride) - #undef PROCESS_OVERRIDE + SL_ProcessCategoryOverrides(cat_enoverride_string, cat_enoverride); + SL_ProcessCategoryOverrides(cat_dioverride_string, cat_dioverride); } // Supporting Functions @@ -212,7 +206,7 @@ int CheckCategoryForEntry(int entry) case "cts": case "xdf": { return CAT_DEFRAG; } - default: { LOG_TRACEF("Found strange mod type: %s\n", modtype); return CAT_MODIFIED; } + default: { LOG_TRACEF("Found strange mod type: %s", modtype); return CAT_MODIFIED; } } } @@ -308,9 +302,7 @@ void XonoticServerList_setSelected(entity me, int i) if(gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT) != me.nItems) return; // sorry, it would be wrong - if(me.selectedServer) - strunzone(me.selectedServer); - me.selectedServer = strzone(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem)); + strcpy(me.selectedServer, gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem)); me.ipAddressBox.setText(me.ipAddressBox, me.selectedServer); me.ipAddressBox.cursorPos = strlen(me.selectedServer); @@ -471,9 +463,8 @@ void XonoticServerList_draw(entity me) // entire list, otherwise there is no way to know which item is first in its category. // binary search method suggested by div - float x; float begin = 0; - for(x = 1; x <= category_ent_count; ++x) { + for(int j = 1; j <= category_ent_count; ++j) { float first = begin; float last = (itemcount - 1); if (first > last) { @@ -482,42 +473,42 @@ void XonoticServerList_draw(entity me) } float catf = gethostcachenumber(SLIST_FIELD_CATEGORY, first); float catl = gethostcachenumber(SLIST_FIELD_CATEGORY, last); - if (catf > x) { - // The first one is already > x. - // Therefore, category x does not exist. + if (catf > j) { + // The first one is already > j. + // Therefore, category j does not exist. // Higher numbered categories do exist though. - } else if (catl < x) { - // The last one is < x. + } else if (catl < j) { + // The last one is < j. // Thus this category - and any following - // don't exist. break; - } else if (catf == x) { + } else if (catf == j) { // Starts at first. This breaks the loop // invariant in the binary search and thus has // to be handled separately. - if(gethostcachenumber(SLIST_FIELD_CATEGORY, first) != x) + if(gethostcachenumber(SLIST_FIELD_CATEGORY, first) != j) error("Category mismatch I"); if(first > 0) - if(gethostcachenumber(SLIST_FIELD_CATEGORY, first - 1) == x) + if(gethostcachenumber(SLIST_FIELD_CATEGORY, first - 1) == j) error("Category mismatch II"); - category_name[category_draw_count] = x; + category_name[category_draw_count] = j; category_item[category_draw_count] = first; ++category_draw_count; begin = first + 1; } else { - // At this point, catf <= x < catl, thus + // At this point, catf <= j < catl, thus // catf < catl, thus first < last. // INVARIANTS: // last - first >= 1 // catf == gethostcachenumber(SLIST_FIELD_CATEGORY(first) // catl == gethostcachenumber(SLIST_FIELD_CATEGORY(last) - // catf < x - // catl >= x + // catf < j + // catl >= j while (last - first > 1) { float middle = floor((first + last) / 2); // By loop condition, middle != first && middle != last. float cat = gethostcachenumber(SLIST_FIELD_CATEGORY, middle); - if (cat >= x) { + if (cat >= j) { last = middle; catl = cat; } else { @@ -525,13 +516,13 @@ void XonoticServerList_draw(entity me) catf = cat; } } - if (catl == x) { - if(gethostcachenumber(SLIST_FIELD_CATEGORY, last) != x) + if (catl == j) { + if(gethostcachenumber(SLIST_FIELD_CATEGORY, last) != j) error("Category mismatch III"); if(last > 0) - if(gethostcachenumber(SLIST_FIELD_CATEGORY, last - 1) == x) + if(gethostcachenumber(SLIST_FIELD_CATEGORY, last - 1) == j) error("Category mismatch IV"); - category_name[category_draw_count] = x; + category_name[category_draw_count] = j; category_item[category_draw_count] = last; ++category_draw_count; begin = last + 1; // already scanned through these, skip 'em @@ -550,9 +541,10 @@ void XonoticServerList_draw(entity me) } else { me.nItems = gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT); } - me.connectButton.disabled = ((me.nItems == 0) && (me.ipAddressBox.text == "")); - me.infoButton.disabled = ((me.nItems == 0) || !owned); - me.favoriteButton.disabled = ((me.nItems == 0) && (me.ipAddressBox.text == "")); + me.connectButton.disabled = (me.lockedSelectedItem || (me.nItems == 0 && me.ipAddressBox.text == "")); + me.disconnectButton.disabled = (!(gamestatus & (GAME_ISSERVER | GAME_CONNECTED))); + me.infoButton.disabled = (me.lockedSelectedItem || me.nItems == 0 || !owned); + me.favoriteButton.disabled = (me.lockedSelectedItem || (me.nItems == 0 && me.ipAddressBox.text == "")); if(me.lockedSelectedItem) { @@ -560,9 +552,7 @@ void XonoticServerList_draw(entity me) { if(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem) != me.selectedServer) { - if(me.selectedServer) - strunzone(me.selectedServer); - me.selectedServer = strzone(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem)); + strcpy(me.selectedServer, gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem)); } found = true; } @@ -587,9 +577,7 @@ void XonoticServerList_draw(entity me) // selected server disappeared, select the last server (scrolling to it) if(me.selectedItem >= me.nItems) SUPER(XonoticServerList).setSelected(me, me.nItems - 1); - if(me.selectedServer) - strunzone(me.selectedServer); - me.selectedServer = strzone(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem)); + strcpy(me.selectedServer, gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem)); } } @@ -630,10 +618,8 @@ void ServerList_PlayerSort_Click(entity btn, entity me) } void ServerList_TypeSort_Click(entity btn, entity me) { - string s, t; - float i, m; - s = me.filterString; - m = strstrofs(s, ":", 0); + string s = me.filterString; + int m = strstrofs(s, ":", 0); if(m >= 0) { s = substring(s, 0, m); @@ -643,30 +629,23 @@ void ServerList_TypeSort_Click(entity btn, entity me) else s = ""; - for(i = 1; ; i *= 2) // 20 modes ought to be enough for anyone - { - t = MapInfo_Type_ToString(i); - if(i > 1) - if(t == "") // it repeats (default case) - { - // no type was found - // choose the first one - s = MapInfo_Type_ToString(1); - break; - } - if(s == t) - { - // the type was found - // choose the next one - s = MapInfo_Type_ToString(i * 2); - if(s == "") - s = MapInfo_Type_ToString(1); - break; - } + Gametype first = NULL; FOREACH(Gametypes, !first, first = it; break); + bool flag = false; + FOREACH(Gametypes, s == MapInfo_Type_ToString(it), { + // the type was found + // choose the next one + flag = true; + s = MapInfo_Type_ToString(Gametypes_from(it.m_id + 1)); + if (s == "") s = MapInfo_Type_ToString(first); + break; + }); + if (!flag) { + // no type was found + // choose the first one + s = MapInfo_Type_ToString(first); } - if(s != "") - s = strcat(s, ":"); + if(s != "") s = strcat(s, ":"); s = strcat(s, substring(me.filterString, m+1, strlen(me.filterString) - m - 1)); me.controlledTextbox.setText(me.controlledTextbox, s); @@ -676,12 +655,9 @@ void ServerList_TypeSort_Click(entity btn, entity me) } void ServerList_Filter_Change(entity box, entity me) { - if(me.filterString) - strunzone(me.filterString); + strfree(me.filterString); if(box.text != "") me.filterString = strzone(box.text); - else - me.filterString = string_null; me.refreshServerList(me, REFRESHSERVERLIST_REFILTER); me.ipAddressBox.setText(me.ipAddressBox, ""); @@ -727,9 +703,7 @@ void XonoticServerList_setSortOrder(entity me, int fld, int direction) me.sortButton4.forcePressed = 0; me.sortButton5.forcePressed = (fld == SLIST_FIELD_NUMHUMANS); me.selectedItem = 0; - if(me.selectedServer) - strunzone(me.selectedServer); - me.selectedServer = string_null; + strfree(me.selectedServer); me.refreshServerList(me, REFRESHSERVERLIST_REFILTER); } void XonoticServerList_positionSortButton(entity me, entity btn, float theOrigin, float theSize, string theTitle, void(entity, entity) theFunc) @@ -771,7 +745,7 @@ void XonoticServerList_resizeNotify(entity me, vector relOrigin, vector relSize, me.columnPlayersOrigin = me.columnTypeOrigin + me.columnTypeSize + me.realFontSize.x; me.positionSortButton(me, me.sortButton1, me.columnPingOrigin, me.columnPingSize, _("Ping"), ServerList_PingSort_Click); - me.positionSortButton(me, me.sortButton2, me.columnNameOrigin, me.columnNameSize, _("Host name"), ServerList_NameSort_Click); + me.positionSortButton(me, me.sortButton2, me.columnNameOrigin, me.columnNameSize, _("Hostname"), ServerList_NameSort_Click); me.positionSortButton(me, me.sortButton3, me.columnMapOrigin, me.columnMapSize, _("Map"), ServerList_MapSort_Click); me.positionSortButton(me, me.sortButton4, me.columnTypeOrigin, me.columnTypeSize, _("Type"), ServerList_TypeSort_Click); me.positionSortButton(me, me.sortButton5, me.columnPlayersOrigin, me.columnPlayersSize, _("Players"), ServerList_PlayerSort_Click); @@ -785,11 +759,10 @@ void XonoticServerList_resizeNotify(entity me, vector relOrigin, vector relSize, } void ServerList_Connect_Click(entity btn, entity me) { - localcmd(sprintf("connect %s\n", - ((me.ipAddressBox.text != "") ? - me.ipAddressBox.text : me.selectedServer - ) - )); + if (me.lockedSelectedItem) + return; + string sv = (me.ipAddressBox.text != "") ? me.ipAddressBox.text : me.selectedServer; + localcmd(sprintf("connect %s\n", sv)); } void ServerList_Favorite_Click(entity btn, entity this) { @@ -830,7 +803,7 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is vector oldscale = draw_scale; vector oldshift = draw_shift; #define SET_YRANGE(start,end) \ - draw_scale = boxToGlobalSize(eX * 1 + eY * (end - start), oldscale); \ + draw_scale = boxToGlobalSize(eX + eY * (end - start), oldscale); \ draw_shift = boxToGlobal(eY * start, oldshift, oldscale); for (j = 0; j < category_draw_count; ++j) { @@ -867,7 +840,7 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is } } - if(isSelected) + if(isSelected && !me.lockedSelectedItem) draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); else if(isFocused) { @@ -970,7 +943,7 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is isv6 = true; me.seenIPv6 += 1; } - else if(strstrofs("0123456789", substring(s, 0, 1), 0) >= 0) + else if(IS_DIGIT(substring(s, 0, 1))) { isv4 = true; me.seenIPv4 += 1; @@ -1070,7 +1043,7 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is t = strcat(t, _("encryption:"), " ", (q ? sprintf(_("AES level %d"), q) : ZCTX(_("ENC^none"))), ", "); t = strcat(t, sprintf(_("mod: %s"), ((modname == "xonotic") ? ZCTX(_("MOD^Default")) : original_modname))); if(pure_available) - t = strcat(t, sprintf(_(" (%s)"), (pure) ? _("official settings") : _("modified settings"))); + t = strcat(t, sprintf(" (%s)", (pure) ? _("official settings") : _("modified settings"))); t = strcat(t, ", "); t = strcat(t, ((sflags >= 0 && (sflags & SERVERFLAG_PLAYERSTATS)) ? _("stats enabled") : _("stats disabled"))); setZonedTooltip(me, t, string_null); @@ -1122,11 +1095,6 @@ float XonoticServerList_mouseMove(entity me, vector pos) bool XonoticServerList_keyDown(entity me, int scan, bool ascii, bool shift) { - vector org, sz; - - org = boxToGlobal(eY * (me.selectedItem * me.itemHeight - me.scrollPos), me.origin, me.size); - sz = boxToGlobalSize(eY * me.itemHeight + eX * (1 - me.controlWidth), me.size); - if(scan == K_ENTER || scan == K_KP_ENTER) { ServerList_Connect_Click(NULL, me); @@ -1136,6 +1104,8 @@ bool XonoticServerList_keyDown(entity me, int scan, bool ascii, bool shift) { if(me.nItems != 0) { + vector org = boxToGlobal(eY * (me.selectedItem * me.itemHeight - me.scrollPos), me.origin, me.size); + vector sz = boxToGlobalSize(eY * me.itemHeight + eX * (1 - me.controlWidth), me.size); m_play_click_sound(MENU_SOUND_OPEN); main.serverInfoDialog.loadServerInfo(main.serverInfoDialog, me.selectedItem); DialogOpenButton_Click_withCoords(me, main.serverInfoDialog, org, sz);