]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/xonotic/serverlist.qc
Show a tooltip when the cursor is over the server icons in the serverlist
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / serverlist.qc
index 4a74a4ca6296a54b54e3b9af3bcea668bb311c4d..071e2ba24bef48224035695d49dea4cb760e65bd 100644 (file)
@@ -12,6 +12,9 @@ CLASS(XonoticServerList, XonoticListBox)
        METHOD(XonoticServerList, toggleFavorite, void(entity, string));
 
        ATTRIB(XonoticServerList, iconsSizeFactor, float, 0.85)
+       METHOD(XonoticServerList, mouseMove, float(entity, vector));
+       ATTRIB(XonoticServerList, mouseOverIcons, bool, false)
+       METHOD(XonoticServerList, focusedItemChangeNotify, void(entity));
 
        ATTRIB(XonoticServerList, realFontSize, vector, '0 0 0')
        ATTRIB(XonoticServerList, realUpperMargin, float, 0)
@@ -173,9 +176,7 @@ void RegisterSLCategories()
        #define SLIST_CATEGORY(name,enoverride,dioverride,str) \
                SET_FIELD_COUNT(name, CATEGORY_FIRST, category_ent_count) \
                CHECK_MAX_COUNT(name, MAX_CATEGORIES, category_ent_count, "SLIST_CATEGORY") \
-               cat = spawn(); \
-               categories[name - 1] = cat; \
-               cat.classname = "slist_category"; \
+               cat = categories[name - 1] = new(slist_category); \
                cat.cat_name = strzone(#name); \
                cat.cat_enoverride_string = strzone(SLIST_CATEGORY_AUTOCVAR(name)); \
                cat.cat_dioverride_string = strzone(dioverride); \
@@ -231,7 +232,7 @@ entity RetrieveCategoryEnt(int catnum)
        else
        {
                error(sprintf("RetrieveCategoryEnt(%d): Improper category number!\n", catnum));
-               return world;
+               return NULL;
        }
 }
 
@@ -437,17 +438,12 @@ void ServerList_Update_favoriteButton(entity btn, entity me)
        if(IsFavorite(me.ipAddressBox.text))
        {
                e.setText(e, _("Remove"));
-               if(e.tooltip)
-               {
-                       strunzone(e.tooltip);
-                       e.tooltip = string_null;
-               }
+               clearTooltip(e);
        }
        else
        {
                e.setText(e, _("Favorite"));
-               if(!e.tooltip)
-                       e.tooltip = strzone(_("Bookmark the currently highlighted server so that it's faster to find in the future"));
+               setZonedTooltip(e, _("Bookmark the currently highlighted server so that it's faster to find in the future"), string_null);
        }
 }
 
@@ -999,7 +995,7 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is
        bool isv4, isv6;
        vector theColor;
        float theAlpha;
-       bool pure = false;
+       bool pure = false, pure_available = false;
        int freeslots = -1, sflags = -1, j, m;
        string s, typestr, versionstr, k, v, modname;
 
@@ -1070,7 +1066,10 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is
                k = substring(argv(j), 0, 1);
                v = substring(argv(j), 1, -1);
                if(k == "P")
-                       pure = stob(v);
+               {
+                       pure = (stof(v) == 0);
+                       pure_available = true;
+               }
                else if(k == "S")
                        freeslots = stof(v);
                else if(k == "F")
@@ -1084,20 +1083,23 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is
                modname = "Xonotic";
 #endif
 
+       string original_modname = modname;
+       modname = strtolower(modname);
+
        /*
        SLIST_FIELD_MOD = gethostcacheindexforkey("mod");
        s = gethostcachestring(SLIST_FIELD_MOD, i);
        if(s != "data")
-               if(modname == "Xonotic")
+               if(modname == "xonotic")
                        modname = s;
        */
 
        // list the mods here on which the pure server check actually works
-       if(modname != "Xonotic")
-       if(modname != "InstaGib" || modname != "MinstaGib")
-       if(modname != "CTS")
-       if(modname != "NIX")
-       if(modname != "NewToys")
+       if(modname != "xonotic")
+       if(modname != "instagib" || modname != "minstagib")
+       if(modname != "cts")
+       if(modname != "nix")
+       if(modname != "newtoys")
                pure = false;
 
        if(gethostcachenumber(SLIST_FIELD_FREESLOTS, i) <= 0)
@@ -1206,9 +1208,11 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is
        iconPos.x += iconSize.x;
 
        // Mod
-       if(modname == "Xonotic")
+       if(modname == "xonotic")
        {
-               if(pure == 0)
+               // Here, pure_available should always be set. If not, consider
+               // it an impurity.
+               if(pure_available && pure)
                        draw_Picture(iconPos, "icon_pure1", iconSize, '1 1 1', 1);
        }
        else
@@ -1217,10 +1221,13 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is
                if(draw_PictureSize(icon) == '0 0 0')
                        icon = "icon_mod_";
 
-               if(pure == 0)
-                       draw_Picture(iconPos, icon, iconSize, '1 1 1', 1);
-               else
+               // In mods, pure_available not being present indicates
+               // non-support of the feature. Just show the mod icon as is
+               // then.
+               if(pure_available && !pure)
                        draw_Picture(iconPos, icon, iconSize, '1 1 1', SKINALPHA_SERVERLIST_ICON_NONPURE);
+               else
+                       draw_Picture(iconPos, icon, iconSize, '1 1 1', 1);
        }
 
        iconPos.x += iconSize.x;
@@ -1229,6 +1236,19 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is
        if(sflags >= 0 && (sflags & SERVERFLAG_PLAYERSTATS))
                draw_Picture(iconPos, "icon_stats1", iconSize, '1 1 1', 1);
 
+       if(isFocused && me.mouseOverIcons && !me.tooltip)
+       {
+               string t = "";
+               if(me.seenIPv4 && me.seenIPv6)
+                       t = strcat(t, (isv6) ? "IPv6, " : "IPv4, ");
+               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, ", ");
+               t = strcat(t, ((sflags >= 0 && (sflags & SERVERFLAG_PLAYERSTATS)) ? _("stats enabled") : _("stats disabled")));
+               setZonedTooltip(me, t, string_null);
+       }
        // --------------
        //  RENDER TEXT
        // --------------
@@ -1254,6 +1274,26 @@ void XonoticServerList_drawListBoxItem(entity me, int i, vector absSize, bool is
        draw_Text(me.realUpperMargin * eY + (me.columnPlayersOrigin + (me.columnPlayersSize - draw_TextWidth(s, 0, me.realFontSize)) * 0.5) * eX, s, me.realFontSize, theColor, theAlpha, 0);
 }
 
+void XonoticServerList_focusedItemChangeNotify(entity me)
+{
+       clearTooltip(me);
+}
+
+float XonoticServerList_mouseMove(entity me, vector pos)
+{
+       if(!SUPER(XonoticServerList).mouseMove(me, pos))
+       {
+               me.mouseOverIcons = false;
+               clearTooltip(me);
+               return 1;
+       }
+
+       me.mouseOverIcons = (pos_x <= me.columnIconsSize);
+       if(!me.mouseOverIcons)
+               clearTooltip(me);
+       return 1;
+}
+
 bool XonoticServerList_keyDown(entity me, int scan, bool ascii, bool shift)
 {
        vector org, sz;