]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
New cvar menu_tootips
authorterencehill <piuntn@gmail.com>
Fri, 31 Dec 2010 11:45:11 +0000 (12:45 +0100)
committerterencehill <piuntn@gmail.com>
Fri, 31 Dec 2010 11:45:11 +0000 (12:45 +0100)
0 disabled, 1 enabled, 2 also shows cvar or console command (when available) changed or executed by the item

Added radio buttons in Settings-Misc for it.

defaultXonotic.cfg
qcsrc/menu/menu.qc
qcsrc/menu/xonotic/checkbox_slider_invalid.c
qcsrc/menu/xonotic/dialog_settings_misc.c
qcsrc/menu/xonotic/slider.c
qcsrc/menu/xonotic/util.qc
qcsrc/menu/xonotic/util.qh
tooltips.db

index 4e9c2a95bfc3e1c834569cc19eef2b7c39b083f8..930087a220c54b395488a3b825a8cbf08b3021e1 100644 (file)
@@ -1360,6 +1360,7 @@ seta slowmo 1
 seta menu_skin "luminos"
 set menu_slowmo 1
 seta menu_sounds 0 "enables menu sound effects. 1 enables click sounds, 2 also enables hover sounds"
+seta menu_tooltips 1 "menu tooltips: 0 disabled, 1 enabled, 2 also shows cvar or console command (when available) changed or executed by the item"
 
 r_textbrightness 0.2
 r_textcontrast 0.8
index 7bec34ea0b0a1ff91aad1c9ed91d051f34ca7fc9..89505c73d953baee3860395cf4e6010c5c9a80ef 100644 (file)
@@ -241,8 +241,8 @@ void draw_Picture_Aligned(vector algn, float scalemode, string img, float a)
 
        sz = draw_PictureSize(img);
        width_is_larger = (sz_x * draw_scale_y >= sz_y * draw_scale_x);
-       isz_w = '1 0 0' + '0 1 0' * ((sz_y / sz_x) * (draw_scale_x / draw_scale_y)); 
-       isz_h = '0 1 0' + '1 0 0' * ((sz_x / sz_y) * (draw_scale_y / draw_scale_x)); 
+       isz_w = '1 0 0' + '0 1 0' * ((sz_y / sz_x) * (draw_scale_x / draw_scale_y));
+       isz_h = '0 1 0' + '1 0 0' * ((sz_x / sz_y) * (draw_scale_y / draw_scale_x));
 
        switch(scalemode)
        {
@@ -318,16 +318,19 @@ void(string img, float a, string algn, float force1) drawBackground =
        }
 }
 
+float menu_tooltips;
+float menu_tooltips_old;
 vector menuTooltipAveragedMousePos;
 entity menuTooltipItem;
 vector menuTooltipOrigin;
 vector menuTooltipSize;
 float menuTooltipAlpha;
-float menuTooltipState; // 0: no tooltip, 1: fading in, 2: displaying, 3: fading out
-float m_testmousetooltipbox(vector pos)
+string menuTooltipText;
+float menuTooltipState; // 0: static, 1: fading in, 2: fading out
+float m_testmousetooltipbox()
 {
-       if(pos_x >= menuTooltipOrigin_x && pos_x < menuTooltipOrigin_x + menuTooltipSize_x)
-       if(pos_y >= menuTooltipOrigin_y && pos_y < menuTooltipOrigin_y + menuTooltipSize_y)
+       if(menuMousePos_x >= menuTooltipOrigin_x && menuMousePos_x < menuTooltipOrigin_x + menuTooltipSize_x)
+       if(menuMousePos_y >= menuTooltipOrigin_y && menuMousePos_y < menuTooltipOrigin_y + menuTooltipSize_y)
                return FALSE;
        return TRUE;
 }
@@ -414,6 +417,8 @@ entity m_findtooltipitem(entity root, vector pos)
                        it = it.itemFromPoint(it, pos);
                        if(it.tooltip)
                                best = it;
+                       else if(menu_tooltips == 2 && (it.cvarName || it.onClickCommand))
+                               best = it;
                        it = world;
                }
                else if(it.instanceOfModalController)
@@ -424,28 +429,62 @@ entity m_findtooltipitem(entity root, vector pos)
                        break;
                if(it.tooltip)
                        best = it;
+               else if(menu_tooltips == 2 && (it.cvarName || it.onClickCommand))
+                       best = it;
                pos = globalToBox(pos, it.Container_origin, it.Container_size);
        }
 
        return best;
 }
-void m_tooltip(vector pos)
+string gettooltip()
+{
+       if (menu_tooltips == 2)
+       {
+               string s;
+               if (menuTooltipItem.cvarName)
+               {
+                       if (getCvarsMulti(menuTooltipItem))
+                               s = strcat("[", menuTooltipItem.cvarName, " ", getCvarsMulti(menuTooltipItem), "]");
+                       else
+                               s = strcat("[", menuTooltipItem.cvarName, "]");
+               }
+               else if (menuTooltipItem.onClickCommand)
+                       s = strcat("<", menuTooltipItem.onClickCommand, ">");
+               else
+                       return menuTooltipItem.tooltip;
+               if (menuTooltipItem.tooltip)
+                       return strcat(menuTooltipItem.tooltip, " ", s);
+               return s;
+       }
+       return menuTooltipItem.tooltip;
+}
+void m_tooltip()
 {
        float f, i, w;
        entity it;
        vector fontsize, p;
        string s;
 
-       fontsize = '1 0 0' * (SKINFONTSIZE_TOOLTIP / conwidth) + '0 1 0' * (SKINFONTSIZE_TOOLTIP / conheight);
-
-       f = bound(0, frametime * 2, 1);
-       menuTooltipAveragedMousePos = menuTooltipAveragedMousePos * (1 - f) + pos * f;
-       f = vlen(pos - menuTooltipAveragedMousePos);
-
-       if(f < 0.01)
-               it = m_findtooltipitem(main, pos);
-       else    
+       menu_tooltips = cvar("menu_tooltips");
+       if (!menu_tooltips)
+       {
+               // don't return immediately, fade out the active tooltip first
+               if (menuTooltipItem == world)
+                       return;
                it = world;
+               menu_tooltips_old = menu_tooltips;
+       }
+       else
+       {
+               f = bound(0, frametime * 2, 1);
+               menuTooltipAveragedMousePos = menuTooltipAveragedMousePos * (1 - f) + menuMousePos * f;
+               f = vlen(menuMousePos - menuTooltipAveragedMousePos);
+               if(f < 0.01)
+                       it = m_findtooltipitem(main, menuMousePos);
+               else
+                       it = world;
+       }
+       fontsize = '1 0 0' * (SKINFONTSIZE_TOOLTIP / conwidth) + '0 1 0' * (SKINFONTSIZE_TOOLTIP / conheight);
 
        // float menuTooltipState; // 0: static, 1: fading in, 2: fading out
        if(it != menuTooltipItem)
@@ -465,9 +504,11 @@ void m_tooltip(vector pos)
                                        menuTooltipItem = it;
 
                                        menuTooltipOrigin_x = -1; // unallocated
+
+                                       menuTooltipText = strzone(gettooltip());
                                        i = 0;
-                                       w =  0;
-                                       getWrappedLine_remaining = it.tooltip;
+                                       w = 0;
+                                       getWrappedLine_remaining = menuTooltipText;
                                        while(getWrappedLine_remaining)
                                        {
                                                s = getWrappedLine(SKINWIDTH_TOOLTIP, fontsize, draw_TextWidth_WithoutColors);
@@ -494,7 +535,7 @@ void m_tooltip(vector pos)
                menuTooltipState = 1;
 
        if(menuTooltipItem)
-               if(!m_testmousetooltipbox(pos))
+               if(!m_testmousetooltipbox())
                        menuTooltipState = 2; // fade out if mouse touches it
 
        switch(menuTooltipState)
@@ -516,8 +557,14 @@ void m_tooltip(vector pos)
 
        if(menuTooltipItem)
        {
-               if(menuTooltipOrigin_x < 0) // unallocated?
-                       m_allocatetooltipbox(pos);
+               if(menu_tooltips != menu_tooltips_old)
+               {
+                       if (menu_tooltips != 0 && menu_tooltips_old != 0)
+                               menuTooltipItem = world; // reload tooltip next frame
+                       menu_tooltips_old = menu_tooltips;
+               }
+               else if(menuTooltipOrigin_x < 0) // unallocated?
+                       m_allocatetooltipbox(menuMousePos);
 
                if(menuTooltipOrigin_x >= 0)
                {
@@ -529,7 +576,7 @@ void m_tooltip(vector pos)
                        p = menuTooltipOrigin;
                        p_x += SKINMARGIN_TOOLTIP_x / conwidth;
                        p_y += SKINMARGIN_TOOLTIP_y / conheight;
-                       getWrappedLine_remaining = menuTooltipItem.tooltip;
+                       getWrappedLine_remaining = menuTooltipText;
                        while(getWrappedLine_remaining)
                        {
                                s = getWrappedLine(SKINWIDTH_TOOLTIP, fontsize, draw_TextWidth_WithoutColors);
@@ -705,7 +752,7 @@ void() m_draw =
        }
        main.draw(main);
 
-       m_tooltip(menuMousePos);
+       m_tooltip();
 
        draw_alpha = max(draw_alpha, SKINALPHA_CURSOR_INTRO * bound(0, menuLogoAlpha, 1));
 
index a9d2becc3d9ef8f47f7c5309918634a856edddad..c5500394bd46d550a14b615c6a798e00f2356016 100644 (file)
@@ -42,6 +42,7 @@ void XonoticSliderCheckBox_configureXonoticSliderCheckBox(entity me, float theOf
        me.controlledSlider = theControlledSlider;
        me.configureCheckBox(me, theText, me.fontSize, me.image);
        me.tooltip = theControlledSlider.tooltip;
+       me.cvarName = theControlledSlider.cvarName; // in case we want to display the cvar in the tooltip
 }
 void XonoticSliderCheckBox_draw(entity me)
 {
index 14293d7f2c6c330b497872fd821460365b3de114..5c76953a5597d0e22a935748ba182fc1fc1b284a 100644 (file)
@@ -68,6 +68,12 @@ void XonoticMiscSettingsTab_fill(entity me)
                me.TDempty(me, 0.2);
                me.TD(me, 1, 2.8, e = makeXonoticCheckBox(0, "cl_maxfps_alwayssleep", "Minimize input latency"));
        me.TR(me);
+       me.TR(me);
+               me.TD(me, 1, 1, e = makeXonoticTextLabel(0, "Menu Tooltips:"));
+               me.TD(me, 1, 0.4, e = makeXonoticRadioButton(2, "menu_tooltips", "0", "Off"));
+               me.TD(me, 1, 0.8, e = makeXonoticRadioButton(2, "menu_tooltips", "1", "Standard"));
+               me.TD(me, 1, 0.8, e = makeXonoticRadioButton(2, "menu_tooltips", "2", "Advanced"));
+       me.TR(me);
        me.TR(me);
                me.TDempty(me, 0.5);
                me.TD(me, 1, 2, e = makeXonoticButton("Advanced settings...", '0 0 0'));
index 46a01bb5ac0e3c1c1e089a90836c4de3b851370f..e833bb1251379f49535c3edd1599a662b8fc6721 100644 (file)
@@ -45,8 +45,7 @@ void XonoticSlider_configureXonoticSlider(entity me, float theValueMin, float th
        {
                me.cvarName = theCvar;
                me.loadCvars(me);
-               if(tooltipdb >= 0)
-                       me.tooltip = getZonedTooltipForIdentifier(theCvar);
+               me.tooltip = getZonedTooltipForIdentifier(theCvar);
        }
 }
 void XonoticSlider_setValue(entity me, float val)
index f6ffa387c996624bb06acef3ea585a580423b803..3bfdb855256f9274542f8a9cfc818c72556a1805 100644 (file)
@@ -21,7 +21,7 @@ void unloadTooltips()
 string getZonedTooltipForIdentifier(string s)
 {
        string t;
-       if(s == "")
+       if(s == "" || tooltipdb < 0)
                return string_null;
        t = db_get(tooltipdb, s);
        if(t == "-")
@@ -65,6 +65,12 @@ void loadAllCvars(entity root)
 
 .string cvarNames_Multi;
 .void(entity me) saveCvars_Multi;
+string getCvarsMulti(entity me)
+{
+       if (me.cvarNames_Multi)
+               return me.cvarNames_Multi;
+       return string_null;
+}
 void saveCvarsMulti(entity me)
 {
        float n, i;
index 053c5073095f6c64a65f08166dbafd8ad2df46eb..03f0d8db7d506967661bba68f24b26889d2f261c 100644 (file)
@@ -6,6 +6,7 @@ void saveAllCvars(entity root);
 void loadAllCvars(entity root);
 
 void makeMulti(entity me, string otherCvars);
+string getCvarsMulti(entity me);
 void makeCallback(entity me, entity cbent, void(entity, entity) cbfunc);
 
 void setDependent(entity e, string theCvarName, float theCvarMin, float theCvarMax);
@@ -15,7 +16,6 @@ void setDependentAND3(entity e, string theCvarName, float theCvarMin, float theC
 void setDependentStringNotEqual(entity e, string theCvarName, string theCvarValue);
 void setDependentWeird(entity e, float(entity) func);
 
-float tooltipdb;
 void loadTooltips();
 void unloadTooltips();
 string getZonedTooltipForIdentifier(string s);
index e8aa0f6cd1ee6ee2817a7b3098b5ee394e9b21ef..563a5b2a87eae8b3dcbbd9153b35fde88011d67b 100644 (file)
 \cl_port\Force client to use chosen port unless it is set to 0
 
 \XonoticSettingsDialog/Misc\Misc settings
+\menu_tooltips\Menu tooltips: disabled, standard or advanced (also shows cvar or console command bound to the menu item)
 \showtime\Show current time of day, useful on screenshots
 \showdate\Show current date, useful on screenshots
 \showfps\Show your rendered frames per second