X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fmenu%2Fxonotic%2Fserverlist.qc;h=6eb169d880ab9bbd3e5d137511690101f5767a52;hp=98f0aba1b6fec44238e817d79ce637fdae44a171;hb=20387ff9f8cef7536362de05c76cc0062416a64c;hpb=7d31226bcb7eb09c889f3a817562270573f32c66 diff --git a/qcsrc/menu/xonotic/serverlist.qc b/qcsrc/menu/xonotic/serverlist.qc index 98f0aba1b6..6eb169d880 100644 --- a/qcsrc/menu/xonotic/serverlist.qc +++ b/qcsrc/menu/xonotic/serverlist.qc @@ -3,7 +3,7 @@ CLASS(XonoticServerList) EXTENDS(XonoticListBox) METHOD(XonoticServerList, configureXonoticServerList, void(entity)) ATTRIB(XonoticServerList, rowsPerItem, float, 1) METHOD(XonoticServerList, draw, void(entity)) - METHOD(XonoticServerList, drawListBoxItem, void(entity, float, vector, float)) + METHOD(XonoticServerList, drawListBoxItem, void(entity, int, vector, bool, float)) METHOD(XonoticServerList, doubleClickListBoxItem, void(entity, float, vector)) METHOD(XonoticServerList, resizeNotify, void(entity, vector, vector, vector, vector)) METHOD(XonoticServerList, keyDown, float(entity, float, float, float)) @@ -65,14 +65,14 @@ entity makeXonoticServerList(); #ifndef IMPLEMENTATION float autocvar_menu_slist_categories; -float autocvar_menu_slist_categories_onlyifmultiple; +float autocvar_menu_slist_categories_onlyifmultiple; float autocvar_menu_slist_purethreshold; float autocvar_menu_slist_modimpurity; float autocvar_menu_slist_recommendations; float autocvar_menu_slist_recommendations_maxping; -float autocvar_menu_slist_recommendations_minfreeslots; +float autocvar_menu_slist_recommendations_minfreeslots; float autocvar_menu_slist_recommendations_minhumans; -float autocvar_menu_slist_recommendations_purethreshold; +float autocvar_menu_slist_recommendations_purethreshold; // server cache fields #define SLIST_FIELDS \ @@ -111,7 +111,7 @@ float IsServerInList(string list, string srv); entity RetrieveCategoryEnt(float catnum); float CheckCategoryOverride(float cat); -float CheckCategoryForEntry(float entry); +float CheckCategoryForEntry(float entry); float m_gethostcachecategory(float entry) { return CheckCategoryOverride(CheckCategoryForEntry(entry)); } void RegisterSLCategories(); @@ -126,10 +126,10 @@ void ServerList_Info_Click(entity btn, entity me); void ServerList_Update_favoriteButton(entity btn, entity me); // fields for category entities -const float MAX_CATEGORIES = 9; -const float CATEGORY_FIRST = 1; +const int MAX_CATEGORIES = 9; +const int CATEGORY_FIRST = 1; entity categories[MAX_CATEGORIES]; -float category_ent_count; +int category_ent_count; .string cat_name; .string cat_string; .string cat_enoverride_string; @@ -138,9 +138,9 @@ float category_ent_count; .float cat_dioverride; // fields for drawing categories -float category_name[MAX_CATEGORIES]; -float category_item[MAX_CATEGORIES]; -float category_draw_count; +int category_name[MAX_CATEGORIES]; +int category_item[MAX_CATEGORIES]; +int category_draw_count; #define SLIST_CATEGORIES \ SLIST_CATEGORY(CAT_FAVORITED, "", "", ZCTX(_("SLCAT^Favorites"))) \ @@ -155,7 +155,7 @@ float category_draw_count; #define SLIST_CATEGORY_AUTOCVAR(name) autocvar_menu_slist_categories_##name##_override #define SLIST_CATEGORY(name,enoverride,dioverride,str) \ - float name; \ + int name; \ string SLIST_CATEGORY_AUTOCVAR(name) = enoverride; SLIST_CATEGORIES #undef SLIST_CATEGORY @@ -180,7 +180,7 @@ void RegisterSLCategories() SLIST_CATEGORIES #undef SLIST_CATEGORY - float i, x, catnum; + int i, x, catnum; string s; #define PROCESS_OVERRIDE(override_string,override_field) \ @@ -219,7 +219,7 @@ void RegisterSLCategories() } // Supporting Functions -entity RetrieveCategoryEnt(float catnum) +entity RetrieveCategoryEnt(int catnum) { if((catnum > 0) && (catnum <= category_ent_count)) { @@ -232,10 +232,10 @@ entity RetrieveCategoryEnt(float catnum) } } -float IsServerInList(string list, string srv) +bool IsServerInList(string list, string srv) { string p; - float i, n; + int i, n; if(srv == "") return false; srv = netaddress_resolve(srv, 26000); @@ -260,12 +260,12 @@ float IsServerInList(string list, string srv) return false; } -float CheckCategoryOverride(float cat) +int CheckCategoryOverride(int cat) { entity catent = RetrieveCategoryEnt(cat); if(catent) { - float override = (autocvar_menu_slist_categories ? catent.cat_enoverride : catent.cat_dioverride); + int override = (autocvar_menu_slist_categories ? catent.cat_enoverride : catent.cat_dioverride); if(override) { return override; } else { return cat; } } @@ -276,10 +276,10 @@ float CheckCategoryOverride(float cat) } } -float CheckCategoryForEntry(float entry) +int CheckCategoryForEntry(int entry) { string s, k, v, modtype = ""; - float j, m, impure = 0, freeslots = 0, sflags = 0; + int j, m, impure = 0, freeslots = 0, sflags = 0; s = gethostcachestring(SLIST_FIELD_QCSTATUS, entry); m = tokenizebyseparator(s, ":"); @@ -306,7 +306,7 @@ float CheckCategoryForEntry(float entry) if(autocvar_menu_slist_recommendations) { string cname = gethostcachestring(SLIST_FIELD_CNAME, entry); - + if(IsPromoted(cname)) { return CAT_RECOMMENDED; } else { @@ -321,21 +321,21 @@ float CheckCategoryForEntry(float entry) if( ///// check for minimum free slots (freeslots >= autocvar_menu_slist_recommendations_minfreeslots) - + && // check for purity requirement ( (autocvar_menu_slist_recommendations_purethreshold < 0) || (impure <= autocvar_menu_slist_recommendations_purethreshold) ) - + && // check for minimum amount of humans ( gethostcachenumber(SLIST_FIELD_NUMHUMANS, entry) >= autocvar_menu_slist_recommendations_minhumans ) - + && // check for maximum latency ( gethostcachenumber(SLIST_FIELD_PING, entry) @@ -358,7 +358,7 @@ float CheckCategoryForEntry(float entry) { // old servers which don't report their mod name are considered modified now case "": { return CAT_MODIFIED; } - + case "xpm": { return CAT_XPM; } case "minstagib": case "instagib": { return CAT_INSTAGIB; } @@ -367,9 +367,9 @@ float CheckCategoryForEntry(float entry) //case "newtoys": { return CAT_NEWTOYS; } // "cts" is allowed as compat, xdf is replacement - case "cts": + case "cts": case "xdf": { return CAT_DEFRAG; } - + default: { dprintf("Found strange mod type: %s\n", modtype); return CAT_MODIFIED; } } } @@ -381,12 +381,12 @@ float CheckCategoryForEntry(float entry) void XonoticServerList_toggleFavorite(entity me, string srv) { string s, s0, s1, s2, srv_resolved, p; - float i, n, f; + int i, n; + bool f = false; srv_resolved = netaddress_resolve(srv, 26000); p = crypto_getidfp(srv_resolved); s = cvar_string("net_slist_favorites"); n = tokenize_console(s); - f = 0; for(i = 0; i < n; ++i) { if(substring(argv(i), 0, 1) != "[" && strlen(argv(i)) == 44 && strstrofs(argv(i), ".", 0) < 0) @@ -410,7 +410,7 @@ void XonoticServerList_toggleFavorite(entity me, string srv) cvar_set("net_slist_favorites", strcat(s0, s1, s2)); s = cvar_string("net_slist_favorites"); n = tokenize_console(s); - f = 1; + f = true; --i; } @@ -456,10 +456,9 @@ void XonoticServerList_configureXonoticServerList(entity me) // clear list me.nItems = 0; } -void XonoticServerList_setSelected(entity me, float i) +void XonoticServerList_setSelected(entity me, int i) { - float save; - save = me.selectedItem; + //int save = me.selectedItem; SUPER(XonoticServerList).setSelected(me, i); /* if(me.selectedItem == save) @@ -478,14 +477,15 @@ void XonoticServerList_setSelected(entity me, float i) me.ipAddressBox.cursorPos = strlen(me.selectedServer); me.ipAddressBoxFocused = -1; } -void XonoticServerList_refreshServerList(entity me, float mode) +void XonoticServerList_refreshServerList(entity me, int mode) { //print("refresh of type ", ftos(mode), "\n"); if(mode >= REFRESHSERVERLIST_REFILTER) { - float m, i, n; - float listflags = 0; + float m; + int i, n; + int listflags = 0; string s, typestr, modstr; s = me.filterString; @@ -554,13 +554,14 @@ void XonoticServerList_refreshServerList(entity me, float mode) if(me.currentSortOrder < 0) { listflags |= SLSF_DESCENDING; } sethostcachesort(me.currentSortField, listflags); } - + resorthostcache(); if(mode >= REFRESHSERVERLIST_ASK) refreshhostcache(mode >= REFRESHSERVERLIST_RESET); } void XonoticServerList_focusEnter(entity me) { + SUPER(XonoticServerList).focusEnter(me); if(time < me.nextRefreshTime) { //print("sorry, no refresh yet\n"); @@ -572,7 +573,8 @@ void XonoticServerList_focusEnter(entity me) void XonoticServerList_draw(entity me) { - float i, found, owned; + int i; + bool found = false, owned; if(_Nex_ExtResponseSystem_BannedServersNeedsRefresh) { @@ -624,7 +626,7 @@ void XonoticServerList_draw(entity me) { float itemcount = gethostcachevalue(SLIST_HOSTCACHEVIEWCOUNT); me.nItems = itemcount; - + //float visible = floor(me.scrollPos / me.itemHeight); // ^ unfortunately no such optimization can be made-- we must process through the // entire list, otherwise there is no way to know which item is first in its category. @@ -713,7 +715,6 @@ void XonoticServerList_draw(entity me) me.infoButton.disabled = ((me.nItems == 0) || !owned); me.favoriteButton.disabled = ((me.nItems == 0) && (me.ipAddressBox.text == "")); - found = 0; if(me.selectedServer) { for(i = 0; i < me.nItems; ++i) @@ -721,7 +722,7 @@ void XonoticServerList_draw(entity me) if(gethostcachestring(SLIST_FIELD_CNAME, i) == me.selectedServer) { me.selectedItem = i; - found = 1; + found = true; break; } } @@ -737,7 +738,7 @@ void XonoticServerList_draw(entity me) me.selectedServer = strzone(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem)); } } - + if(owned) { if(me.selectedServer != me.ipAddressBox.text) @@ -860,7 +861,7 @@ void ServerList_ShowFull_Click(entity box, entity me) me.ipAddressBox.cursorPos = 0; me.ipAddressBoxFocused = -1; } -void XonoticServerList_setSortOrder(entity me, float fld, float direction) +void XonoticServerList_setSortOrder(entity me, int fld, int direction) { if(me.currentSortField == fld) direction = -me.currentSortOrder; @@ -921,8 +922,7 @@ void XonoticServerList_resizeNotify(entity me, vector relOrigin, vector relSize, 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); - float f; - f = me.currentSortField; + int f = me.currentSortField; if(f >= 0) { me.currentSortField = -1; @@ -943,6 +943,7 @@ void ServerList_Favorite_Click(entity btn, entity me) ipstr = netaddress_resolve(me.ipAddressBox.text, 26000); if(ipstr != "") { + m_play_click_sound(MENU_SOUND_SELECT); me.toggleFavorite(me, me.ipAddressBox.text); me.ipAddressBoxFocused = -1; } @@ -956,18 +957,20 @@ void ServerList_Info_Click(entity btn, entity me) vector sz = boxToGlobalSize(eY * me.itemHeight + eX * (1 - me.controlWidth), me.size); DialogOpenButton_Click_withCoords(me, main.serverInfoDialog, org, sz); } -void XonoticServerList_doubleClickListBoxItem(entity me, float i, vector where) +void XonoticServerList_doubleClickListBoxItem(entity me, int i, vector where) { ServerList_Connect_Click(NULL, me); } -void XonoticServerList_drawListBoxItem(entity me, float i, vector absSize, float isSelected) +void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool isSelected, float highlightedTime) { // layout: Ping, Server name, Map name, NP, TP, MP - float p, q; - float isv4, isv6; + float p; + int q; + bool isv4, isv6; vector theColor; float theAlpha; - float m, pure, freeslots, j, sflags; + bool pure = false; + int freeslots = -1, sflags = -1, j, m; string s, typestr, versionstr, k, v, modname; //printf("time: %f, i: %d, item: %d, nitems: %d\n", time, i, item, me.nItems); @@ -1011,9 +1014,11 @@ void XonoticServerList_drawListBoxItem(entity me, float i, vector absSize, float SET_YRANGE(me.categoriesHeight / (me.categoriesHeight + 1), 1); } } - + if(isSelected) draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED); + else if(highlightedTime) + draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, getHighlightAlpha(SKINALPHA_LISTBOX_SELECTED * 0.1, highlightedTime)); s = gethostcachestring(SLIST_FIELD_QCSTATUS, i); m = tokenizebyseparator(s, ":"); @@ -1024,9 +1029,7 @@ void XonoticServerList_drawListBoxItem(entity me, float i, vector absSize, float versionstr = argv(1); } freeslots = -1; - sflags = -1; modname = ""; - pure = 0; for(j = 2; j < m; ++j) { if(argv(j) == "") @@ -1034,11 +1037,11 @@ void XonoticServerList_drawListBoxItem(entity me, float i, vector absSize, float k = substring(argv(j), 0, 1); v = substring(argv(j), 1, -1); if(k == "P") - pure = stof(v); + pure = stob(v); else if(k == "S") freeslots = stof(v); else if(k == "F") - sflags = stof(v); + sflags = stoi(v); else if(k == "M") modname = v; } @@ -1062,7 +1065,7 @@ void XonoticServerList_drawListBoxItem(entity me, float i, vector absSize, float if(modname != "CTS") if(modname != "NIX") if(modname != "NewToys") - pure = 0; + pure = false; if(gethostcachenumber(SLIST_FIELD_FREESLOTS, i) <= 0) theAlpha = SKINALPHA_SERVERLIST_FULL; @@ -1074,9 +1077,9 @@ void XonoticServerList_drawListBoxItem(entity me, float i, vector absSize, float theAlpha = 1; p = gethostcachenumber(SLIST_FIELD_PING, i); - const float PING_LOW = 75; - const float PING_MED = 200; - const float PING_HIGH = 500; + const int PING_LOW = 75; + const int PING_MED = 200; + const int PING_HIGH = 500; if(p < PING_LOW) theColor = SKINCOLOR_SERVERLIST_LOWPING + (SKINCOLOR_SERVERLIST_MEDPING - SKINCOLOR_SERVERLIST_LOWPING) * (p / PING_LOW); else if(p < PING_MED) @@ -1100,15 +1103,15 @@ void XonoticServerList_drawListBoxItem(entity me, float i, vector absSize, float s = gethostcachestring(SLIST_FIELD_CNAME, i); - isv4 = isv6 = 0; + isv4 = isv6 = false; if(substring(s, 0, 1) == "[") { - isv6 = 1; + isv6 = true; me.seenIPv6 += 1; } else if(strstrofs("0123456789", substring(s, 0, 1), 0) >= 0) { - isv4 = 1; + isv4 = true; me.seenIPv4 += 1; } @@ -1203,11 +1206,11 @@ void XonoticServerList_drawListBoxItem(entity me, float i, vector absSize, float draw_Picture(iconPos, n, iconSize, '1 1 1', 1); } iconPos.x += iconSize.x; - + // -------------- // RENDER TEXT // -------------- - + // ping s = ftos(p); draw_Text(me.realUpperMargin * eY + (me.columnPingOrigin + me.columnPingSize - draw_TextWidth(s, 0, me.realFontSize)) * eX, s, me.realFontSize, theColor, theAlpha, 0); @@ -1229,7 +1232,7 @@ void XonoticServerList_drawListBoxItem(entity me, float i, vector absSize, float draw_Text(me.realUpperMargin * eY + (me.columnPlayersOrigin + (me.columnPlayersSize - draw_TextWidth(s, 0, me.realFontSize)) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0); } -float XonoticServerList_keyDown(entity me, float scan, float ascii, float shift) +bool XonoticServerList_keyDown(entity me, int scan, bool ascii, bool shift) { vector org, sz; @@ -1239,17 +1242,18 @@ float XonoticServerList_keyDown(entity me, float scan, float ascii, float shift) if(scan == K_ENTER || scan == K_KP_ENTER) { ServerList_Connect_Click(NULL, me); - return 1; + return true; } else if(scan == K_MOUSE2 || scan == K_SPACE) { if(me.nItems != 0) { + m_play_click_sound(MENU_SOUND_OPEN); main.serverInfoDialog.loadServerInfo(main.serverInfoDialog, me.selectedItem); DialogOpenButton_Click_withCoords(me, main.serverInfoDialog, org, sz); - return 1; + return true; } - return 0; + return false; } else if(scan == K_INS || scan == K_MOUSE3 || scan == K_KP_INS) { @@ -1257,28 +1261,30 @@ float XonoticServerList_keyDown(entity me, float scan, float ascii, float shift) { me.toggleFavorite(me, me.selectedServer); me.ipAddressBoxFocused = -1; - return 1; + return true; } - return 0; + return false; } else if(SUPER(XonoticServerList).keyDown(me, scan, ascii, shift)) - return 1; + return true; else if(!me.controlledTextbox) - return 0; + return false; else return me.controlledTextbox.keyDown(me.controlledTextbox, scan, ascii, shift); } -float XonoticServerList_getTotalHeight(entity me) { +float XonoticServerList_getTotalHeight(entity me) +{ float num_normal_rows = me.nItems; - float num_headers = category_draw_count; + int num_headers = category_draw_count; return me.itemHeight * (num_normal_rows + me.categoriesHeight * num_headers); } -float XonoticServerList_getItemAtPos(entity me, float pos) { +int XonoticServerList_getItemAtPos(entity me, float pos) +{ pos = pos / me.itemHeight; - float i; + int i; for (i = category_draw_count - 1; i >= 0; --i) { - float itemidx = category_item[i]; + int itemidx = category_item[i]; float itempos = i * me.categoriesHeight + category_item[i]; if (pos >= itempos + me.categoriesHeight + 1) return itemidx + 1 + floor(pos - (itempos + me.categoriesHeight + 1)); @@ -1288,10 +1294,11 @@ float XonoticServerList_getItemAtPos(entity me, float pos) { // No category matches? Note that category 0 is... 0. Therefore no headings exist at all. return floor(pos); } -float XonoticServerList_getItemStart(entity me, float item) { - float i; +float XonoticServerList_getItemStart(entity me, int item) +{ + int i; for (i = category_draw_count - 1; i >= 0; --i) { - float itemidx = category_item[i]; + int itemidx = category_item[i]; float itempos = i * me.categoriesHeight + category_item[i]; if (item >= itemidx + 1) return (itempos + me.categoriesHeight + 1 + item - (itemidx + 1)) * me.itemHeight; @@ -1301,8 +1308,9 @@ float XonoticServerList_getItemStart(entity me, float item) { // No category matches? Note that category 0 is... 0. Therefore no headings exist at all. return item * me.itemHeight; } -float XonoticServerList_getItemHeight(entity me, float item) { - float i; +float XonoticServerList_getItemHeight(entity me, int item) +{ + int i; for (i = 0; i < category_draw_count; ++i) { // Matches exactly the headings with increased height. if (item == category_item[i])