]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/xonotic/serverlist.c
Some cleanup
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / serverlist.c
index 9f987449f33d43a7e81d64d13001a4ce00e0d0ee..69f5d47374e32fde63deb1663901505c552c5b01 100644 (file)
@@ -49,7 +49,6 @@ CLASS(XonoticServerList) EXTENDS(XonoticListBox)
        ATTRIB(XonoticServerList, infoButton, entity, NULL)
        ATTRIB(XonoticServerList, currentSortOrder, float, 0)
        ATTRIB(XonoticServerList, currentSortField, float, -1)
-       ATTRIB(XonoticServerList, lastBumpSelectTime, float, 0)
        ATTRIB(XonoticServerList, lastClickedServer, float, -1)
        ATTRIB(XonoticServerList, lastClickedTime, float, 0)
 
@@ -57,7 +56,7 @@ CLASS(XonoticServerList) EXTENDS(XonoticListBox)
 
        ATTRIB(XonoticServerList, seenIPv4, float, 0)
        ATTRIB(XonoticServerList, seenIPv6, float, 0)
-       ATTRIB(XonoticServerList, categoriesHeight, float, 1.5)
+       ATTRIB(XonoticServerList, categoriesHeight, float, 1.25)
 
        METHOD(XonoticServerList, getTotalHeight, float(entity))
        METHOD(XonoticServerList, getItemAtPos, float(entity, float))
@@ -67,16 +66,15 @@ ENDCLASS(XonoticServerList)
 entity makeXonoticServerList();
 
 #ifndef IMPLEMENTATION
-var float autocvar_menu_slist_categories = TRUE;
-var float autocvar_menu_slist_categories_onlyifmultiple = TRUE; 
-var float autocvar_menu_slist_purethreshold = 10;
-var float autocvar_menu_slist_modimpurity = 10;
-var float autocvar_menu_slist_recommendations = 2;
-var float autocvar_menu_slist_recommendations_maxping = 150;
-var float autocvar_menu_slist_recommendations_minfreeslots = 1; 
-var float autocvar_menu_slist_recommendations_minhumans = 1;
-var float autocvar_menu_slist_recommendations_purethreshold = -1; 
-//var string autocvar_menu_slist_recommended = "76.124.107.5:26004";
+float autocvar_menu_slist_categories;
+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_minhumans;
+float autocvar_menu_slist_recommendations_purethreshold; 
 
 // server cache fields
 #define SLIST_FIELDS \
@@ -107,12 +105,13 @@ const float REFRESHSERVERLIST_ASK = 2;       // ..., also suggest querying serve
 const float REFRESHSERVERLIST_RESET = 3;     // ..., also clear the list first
 
 // function declarations
-entity RetrieveCategoryEnt(float catnum);
-
 float IsServerInList(string list, string srv);
 #define IsFavorite(srv) IsServerInList(cvar_string("net_slist_favorites"), srv)
+#define IsPromoted(srv) IsServerInList(_Nex_ExtResponseSystem_PromotedServers, srv)
 #define IsRecommended(srv) IsServerInList(_Nex_ExtResponseSystem_RecommendedServers, srv)
 
+entity RetrieveCategoryEnt(float catnum);
+
 float CheckCategoryOverride(float cat);
 float CheckCategoryForEntry(float entry); 
 float m_gethostcachecategory(float entry) { return CheckCategoryOverride(CheckCategoryForEntry(entry)); }
@@ -308,42 +307,50 @@ float CheckCategoryForEntry(float entry)
        // now check if it's recommended
        if(autocvar_menu_slist_recommendations)
        {
-               float recommended = 0;
-               if(autocvar_menu_slist_recommendations & 1)
-               {
-                       if(IsRecommended(gethostcachestring(SLIST_FIELD_CNAME, entry)))
-                               { ++recommended; }
-                       else
-                               { --recommended; }
-               }
-               if(autocvar_menu_slist_recommendations & 2)
+               string cname = gethostcachestring(SLIST_FIELD_CNAME, entry);
+               
+               if(IsPromoted(cname)) { return CAT_RECOMMENDED; }
+               else
                {
-                       if(
-                               (freeslots >= autocvar_menu_slist_recommendations_minfreeslots)
-                               &&
-                               (
-                                       (autocvar_menu_slist_recommendations_purethreshold < 0)
-                                       ||
-                                       (impure <= autocvar_menu_slist_recommendations_purethreshold)
-                               )
-                               &&
-                               (
-                                       gethostcachenumber(SLIST_FIELD_NUMHUMANS, entry)
-                                       >=
-                                       autocvar_menu_slist_recommendations_minhumans
-                               )
-                               &&
-                               (
-                                       gethostcachenumber(SLIST_FIELD_PING, entry)
-                                       <=
-                                       autocvar_menu_slist_recommendations_maxping
+                       float recommended = 0;
+                       if(autocvar_menu_slist_recommendations & 1)
+                       {
+                               if(IsRecommended(cname)) { ++recommended; }
+                               else { --recommended; }
+                       }
+                       if(autocvar_menu_slist_recommendations & 2)
+                       {
+                               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)
+                                               <=
+                                               autocvar_menu_slist_recommendations_maxping
+                                       )
                                )
-                       )
-                               { ++recommended; }
-                       else
-                               { --recommended; }
+                                       { ++recommended; }
+                               else
+                                       { --recommended; }
+                       }
+                       if(recommended > 0) { return CAT_RECOMMENDED; }
                }
-               if(recommended > 0) { return CAT_RECOMMENDED; }
        }
 
        // if not favorited or recommended, check modname
@@ -426,7 +433,7 @@ void ServerList_Update_favoriteButton(entity btn, entity me)
 {
        me.favoriteButton.setText(me.favoriteButton,
                (IsFavorite(me.ipAddressBox.text) ?
-                       _("Remove") : _("Bookmark")
+                       _("Remove") : _("Favorite")
                )
        );
 }
@@ -575,6 +582,13 @@ void XonoticServerList_draw(entity me)
                _Nex_ExtResponseSystem_BannedServersNeedsRefresh = 0;
        }
 
+       if(_Nex_ExtResponseSystem_PromotedServersNeedsRefresh)
+       {
+               if(!me.needsRefresh)
+                       me.needsRefresh = 3;
+               _Nex_ExtResponseSystem_PromotedServersNeedsRefresh = 0;
+       }
+
        if(_Nex_ExtResponseSystem_RecommendedServersNeedsRefresh)
        {
                if(!me.needsRefresh)
@@ -986,20 +1000,24 @@ void XonoticServerList_drawListBoxItem(entity me, float i, vector absSize, float
                {
                        SET_YRANGE(
                                (me.categoriesHeight - 1) / (me.categoriesHeight + 1),
-                               me.categoriesHeight / (me.categoriesHeight + 1));
+                               me.categoriesHeight / (me.categoriesHeight + 1)
+                       );
                        draw_Text(
                                eY * me.realUpperMargin
                                +
+#if 0
                                eX * (me.columnNameOrigin + (me.columnNameSize - draw_TextWidth(catent.cat_string, 0, me.realFontSize)) * 0.5),
                                catent.cat_string,
+#else
+                               eX * (me.columnNameOrigin),
+                               strcat(catent.cat_string, ":"),
+#endif
                                me.realFontSize,
                                '1 1 1',
                                SKINALPHA_TEXT,
                                0
                        );
-                       SET_YRANGE(
-                               me.categoriesHeight / (me.categoriesHeight + 1),
-                               1);
+                       SET_YRANGE(me.categoriesHeight / (me.categoriesHeight + 1), 1);
                }
        }
        
@@ -1222,14 +1240,11 @@ void XonoticServerList_drawListBoxItem(entity me, float i, vector absSize, float
 
 float XonoticServerList_keyDown(entity me, float scan, float ascii, float shift)
 {
-       float i = me.selectedItem;
        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);
 
-       me.lastBumpSelectTime = 0;
-
        if(scan == K_ENTER || scan == K_KP_ENTER)
        {
                ServerList_Connect_Click(NULL, me);
@@ -1239,7 +1254,7 @@ float XonoticServerList_keyDown(entity me, float scan, float ascii, float shift)
        {
                if(me.nItems != 0)
                {
-                       main.serverInfoDialog.loadServerInfo(main.serverInfoDialog, i);
+                       main.serverInfoDialog.loadServerInfo(main.serverInfoDialog, me.selectedItem);
                        DialogOpenButton_Click_withCoords(me, main.serverInfoDialog, org, sz);
                        return 1;
                }