]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/xonotic/serverlist.qc
Merge branch 'terencehill/slider_drag_fix' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / serverlist.qc
index 33203c52b9dc72c10f80ad23183b609494d3310a..e2c6472092fe53d19068e426b1adbcff9a0f279a 100644 (file)
@@ -2,14 +2,14 @@
 #define SERVERLIST_H
 #include "listbox.qc"
 CLASS(XonoticServerList, XonoticListBox)
-       METHOD(XonoticServerList, configureXonoticServerList, void(entity))
+       METHOD(XonoticServerList, configureXonoticServerList, void(entity));
        ATTRIB(XonoticServerList, rowsPerItem, float, 1)
-       METHOD(XonoticServerList, draw, void(entity))
-       METHOD(XonoticServerList, drawListBoxItem, void(entity, int, vector, bool, bool))
-       METHOD(XonoticServerList, doubleClickListBoxItem, void(entity, float, vector))
-       METHOD(XonoticServerList, resizeNotify, void(entity, vector, vector, vector, vector))
-       METHOD(XonoticServerList, keyDown, float(entity, float, float, float))
-       METHOD(XonoticServerList, toggleFavorite, void(entity, string))
+       METHOD(XonoticServerList, draw, void(entity));
+       METHOD(XonoticServerList, drawListBoxItem, void(entity, int, vector, bool, bool));
+       METHOD(XonoticServerList, doubleClickListBoxItem, void(entity, float, vector));
+       METHOD(XonoticServerList, resizeNotify, void(entity, vector, vector, vector, vector));
+       METHOD(XonoticServerList, keyDown, float(entity, float, float, float));
+       METHOD(XonoticServerList, toggleFavorite, void(entity, string));
 
        ATTRIB(XonoticServerList, iconsSizeFactor, float, 0.85)
 
@@ -27,10 +27,11 @@ CLASS(XonoticServerList, XonoticListBox)
        ATTRIB(XonoticServerList, columnTypeSize, float, 0)
        ATTRIB(XonoticServerList, columnPlayersOrigin, float, 0)
        ATTRIB(XonoticServerList, columnPlayersSize, float, 0)
+       ATTRIB(XonoticServerList, lockedSelectedItem, bool, true) // initially keep selected the first item of the list, avoiding an unwanted scrolling
 
        ATTRIB(XonoticServerList, selectedServer, string, string_null) // to restore selected server when needed
-       METHOD(XonoticServerList, setSelected, void(entity, float))
-       METHOD(XonoticServerList, setSortOrder, void(entity, float, float))
+       METHOD(XonoticServerList, setSelected, void(entity, float));
+       METHOD(XonoticServerList, setSortOrder, void(entity, float, float));
        ATTRIB(XonoticServerList, filterShowEmpty, float, 1)
        ATTRIB(XonoticServerList, filterShowFull, float, 1)
        ATTRIB(XonoticServerList, filterString, string, string_null)
@@ -38,10 +39,10 @@ CLASS(XonoticServerList, XonoticListBox)
        ATTRIB(XonoticServerList, ipAddressBox, entity, NULL)
        ATTRIB(XonoticServerList, favoriteButton, entity, NULL)
        ATTRIB(XonoticServerList, nextRefreshTime, float, 0)
-       METHOD(XonoticServerList, refreshServerList, void(entity, float)) // refresh mode: REFRESHSERVERLIST_*
+       METHOD(XonoticServerList, refreshServerList, void(entity, float)); // refresh mode: REFRESHSERVERLIST_*
        ATTRIB(XonoticServerList, needsRefresh, float, 1)
-       METHOD(XonoticServerList, focusEnter, void(entity))
-       METHOD(XonoticServerList, positionSortButton, void(entity, entity, float, float, string, void(entity, entity)))
+       METHOD(XonoticServerList, focusEnter, void(entity));
+       METHOD(XonoticServerList, positionSortButton, void(entity, entity, float, float, string, void(entity, entity)));
        ATTRIB(XonoticServerList, sortButton1, entity, NULL)
        ATTRIB(XonoticServerList, sortButton2, entity, NULL)
        ATTRIB(XonoticServerList, sortButton3, entity, NULL)
@@ -58,10 +59,10 @@ CLASS(XonoticServerList, XonoticListBox)
        ATTRIB(XonoticServerList, seenIPv6, float, 0)
        ATTRIB(XonoticServerList, categoriesHeight, float, 1.25)
 
-       METHOD(XonoticServerList, getTotalHeight, float(entity))
-       METHOD(XonoticServerList, getItemAtPos, float(entity, float))
-       METHOD(XonoticServerList, getItemStart, float(entity, float))
-       METHOD(XonoticServerList, getItemHeight, float(entity, float))
+       METHOD(XonoticServerList, getTotalHeight, float(entity));
+       METHOD(XonoticServerList, getItemAtPos, float(entity, float));
+       METHOD(XonoticServerList, getItemStart, float(entity, float));
+       METHOD(XonoticServerList, getItemHeight, float(entity, float));
 ENDCLASS(XonoticServerList)
 entity makeXonoticServerList();
 
@@ -205,7 +206,7 @@ void RegisterSLCategories()
                                } \
                                else \
                                { \
-                                       printf( \
+                                       LOG_INFOF( \
                                                "RegisterSLCategories(): Improper override '%s' for category '%s'!\n", \
                                                s, \
                                                categories[i].cat_name \
@@ -230,7 +231,7 @@ entity RetrieveCategoryEnt(int catnum)
        else
        {
                error(sprintf("RetrieveCategoryEnt(%d): Improper category number!\n", catnum));
-               return world;
+               return NULL;
        }
 }
 
@@ -372,7 +373,7 @@ int CheckCategoryForEntry(int entry)
                        case "cts":
                        case "xdf": { return CAT_DEFRAG; }
 
-                       default: { dprintf("Found strange mod type: %s\n", modtype); return CAT_MODIFIED; }
+                       default: { LOG_TRACEF("Found strange mod type: %s\n", modtype); return CAT_MODIFIED; }
                }
        }
 
@@ -432,11 +433,17 @@ void XonoticServerList_toggleFavorite(entity me, string srv)
 
 void ServerList_Update_favoriteButton(entity btn, entity me)
 {
-       me.favoriteButton.setText(me.favoriteButton,
-               (IsFavorite(me.ipAddressBox.text) ?
-                       _("Remove") : _("Favorite")
-               )
-       );
+       entity e = me.favoriteButton;
+       if(IsFavorite(me.ipAddressBox.text))
+       {
+               e.setText(e, _("Remove"));
+               clearTooltip(e);
+       }
+       else
+       {
+               e.setText(e, _("Favorite"));
+               setZonedTooltip(e, _("Bookmark the currently highlighted server so that it's faster to find in the future"), string_null);
+       }
 }
 
 entity makeXonoticServerList()
@@ -460,6 +467,7 @@ void XonoticServerList_configureXonoticServerList(entity me)
 }
 void XonoticServerList_setSelected(entity me, int i)
 {
+       me.lockedSelectedItem = false;
        //int save = me.selectedItem;
        SUPER(XonoticServerList).setSelected(me, i);
        /*
@@ -717,12 +725,26 @@ void XonoticServerList_draw(entity me)
        me.infoButton.disabled = ((me.nItems == 0) || !owned);
        me.favoriteButton.disabled = ((me.nItems == 0) && (me.ipAddressBox.text == ""));
 
-       if(me.selectedServer)
+       if(me.lockedSelectedItem)
+       {
+               if(me.nItems > 0)
+               {
+                       if(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem) != me.selectedServer)
+                       {
+                               if(me.selectedServer)
+                                       strunzone(me.selectedServer);
+                               me.selectedServer = strzone(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem));
+                       }
+                       found = true;
+               }
+       }
+       else if(me.selectedServer)
        {
                for(i = 0; i < me.nItems; ++i)
                {
                        if(gethostcachestring(SLIST_FIELD_CNAME, i) == me.selectedServer)
                        {
+                               // don't follow the selected item with SUPER(XonoticServerList).setSelected(me, i);
                                me.selectedItem = i;
                                found = true;
                                break;
@@ -733,8 +755,9 @@ void XonoticServerList_draw(entity me)
        {
                if(me.nItems > 0)
                {
+                       // selected server disappeared, select the last server (scrolling to it)
                        if(me.selectedItem >= me.nItems)
-                               me.selectedItem = me.nItems - 1;
+                               SUPER(XonoticServerList).setSelected(me, me.nItems - 1);
                        if(me.selectedServer)
                                strunzone(me.selectedServer);
                        me.selectedServer = strzone(gethostcachestring(SLIST_FIELD_CNAME, me.selectedItem));