]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/menu/xonotic/util.qc
Listbox: highlight item under the cursor
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / util.qc
index 0eb5b215caf64888b8b680c0147942472c5a0fb7..49fe79b011df800f4ef3e553343658abb8bfcce7 100644 (file)
@@ -329,8 +329,8 @@ void UpdateNotification_URI_Get_Callback(float id, float status, string data)
                n = tokenizebyseparator(data, "\n");
 
        float i;
-       string s; 
-       
+       string s;
+
        string un_version = "";
        string un_download = "";
        string un_url = "";
@@ -339,12 +339,12 @@ void UpdateNotification_URI_Get_Callback(float id, float status, string data)
        string un_promoted = "";
        string un_recommended = "";
        string un_compatexpire = "";
-       
+
        for(i = 0; i < n; ++i)
        {
                s = substring(argv(i), 2, -1);
                if(s == "") { continue; } // ignore empty lines
-               
+
                switch(substring(argv(i), 0, 1))
                {
                        case "V":
@@ -411,7 +411,7 @@ void UpdateNotification_URI_Get_Callback(float id, float status, string data)
                        }
                }
        }
-       
+
        if(un_emergency_pk3s != "")
        {
                _Nex_ExtResponseSystem_Packs = strzone(un_emergency_pk3s);
@@ -665,12 +665,11 @@ float updateCompression()
        //GAMETYPE(MAPINFO_TYPE_INVASION) \
        /* nothing */
 
-float GameType_GetID(float cnt)
+int GameType_GetID(int cnt)
 {
-       float i;
-       i = 0;
+       int i = 0;
 
-       #define GAMETYPE(id) { if(i++ == cnt) return id; }
+       #define GAMETYPE(id) { if (i++ == cnt) return id; }
        GAMETYPES
        #undef GAMETYPE
 
@@ -679,10 +678,9 @@ float GameType_GetID(float cnt)
        return 0;
 }
 
-float GameType_GetCount()
+int GameType_GetCount()
 {
-       float i;
-       i = 0;
+       int i = 0;
 
        #define GAMETYPE(id) ++i;
        GAMETYPES
@@ -691,9 +689,9 @@ float GameType_GetCount()
        return i;
 }
 
-string GameType_GetName(float cnt)
+string GameType_GetName(int cnt)
 {
-       float i = GameType_GetID(cnt);
+       int i = GameType_GetID(cnt);
 
        if(i)
                return MapInfo_Type_ToText(i);
@@ -701,9 +699,9 @@ string GameType_GetName(float cnt)
        return "";
 }
 
-string GameType_GetIcon(float cnt)
+string GameType_GetIcon(int cnt)
 {
-       float i = GameType_GetID(cnt);
+       int i = GameType_GetID(cnt);
 
        if(i)
                return strcat("gametype_", MapInfo_Type_ToString(i));
@@ -770,6 +768,22 @@ void dialog_hudpanel_common_notoggle(entity me, string panelname)
                                e.configureXonoticTextSliderValues(e);
 }
 
+#define FADE_TIME 0.5
+#define MAX_ALPHA_INCREASE 0.1
+#define TRESHOLD_TIME 0.1
+float getHighlightAlpha(float baseAlpha, float highlightedTime)
+{
+       float alphaIncrease;
+       if (time - highlightedTime - TRESHOLD_TIME < FADE_TIME)
+       {
+               alphaIncrease = max(0, (time - highlightedTime - TRESHOLD_TIME) / FADE_TIME);
+               alphaIncrease = (1 - alphaIncrease) * MAX_ALPHA_INCREASE;
+       }
+       else
+               alphaIncrease = 0;
+       return baseAlpha + alphaIncrease;
+}
+
 void CheckSendCvars(entity me, string cvarnamestring)
 {
        if(me.sendCvars)