From a815eac87d47b74c06dea10cee1d9cfa315d87ab Mon Sep 17 00:00:00 2001 From: terencehill Date: Fri, 31 Dec 2010 12:45:11 +0100 Subject: [PATCH] New cvar menu_tootips 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 | 1 + qcsrc/menu/menu.qc | 93 +++++++++++++++----- qcsrc/menu/xonotic/checkbox_slider_invalid.c | 1 + qcsrc/menu/xonotic/dialog_settings_misc.c | 6 ++ qcsrc/menu/xonotic/slider.c | 3 +- qcsrc/menu/xonotic/util.qc | 8 +- qcsrc/menu/xonotic/util.qh | 2 +- tooltips.db | 1 + 8 files changed, 88 insertions(+), 27 deletions(-) diff --git a/defaultXonotic.cfg b/defaultXonotic.cfg index 4e9c2a95bf..930087a220 100644 --- a/defaultXonotic.cfg +++ b/defaultXonotic.cfg @@ -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 diff --git a/qcsrc/menu/menu.qc b/qcsrc/menu/menu.qc index 7bec34ea0b..89505c73d9 100644 --- a/qcsrc/menu/menu.qc +++ b/qcsrc/menu/menu.qc @@ -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)); diff --git a/qcsrc/menu/xonotic/checkbox_slider_invalid.c b/qcsrc/menu/xonotic/checkbox_slider_invalid.c index a9d2becc3d..c5500394bd 100644 --- a/qcsrc/menu/xonotic/checkbox_slider_invalid.c +++ b/qcsrc/menu/xonotic/checkbox_slider_invalid.c @@ -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) { diff --git a/qcsrc/menu/xonotic/dialog_settings_misc.c b/qcsrc/menu/xonotic/dialog_settings_misc.c index 14293d7f2c..5c76953a55 100644 --- a/qcsrc/menu/xonotic/dialog_settings_misc.c +++ b/qcsrc/menu/xonotic/dialog_settings_misc.c @@ -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')); diff --git a/qcsrc/menu/xonotic/slider.c b/qcsrc/menu/xonotic/slider.c index 46a01bb5ac..e833bb1251 100644 --- a/qcsrc/menu/xonotic/slider.c +++ b/qcsrc/menu/xonotic/slider.c @@ -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) diff --git a/qcsrc/menu/xonotic/util.qc b/qcsrc/menu/xonotic/util.qc index f6ffa387c9..3bfdb85525 100644 --- a/qcsrc/menu/xonotic/util.qc +++ b/qcsrc/menu/xonotic/util.qc @@ -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; diff --git a/qcsrc/menu/xonotic/util.qh b/qcsrc/menu/xonotic/util.qh index 053c507309..03f0d8db7d 100644 --- a/qcsrc/menu/xonotic/util.qh +++ b/qcsrc/menu/xonotic/util.qh @@ -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); diff --git a/tooltips.db b/tooltips.db index e8aa0f6cd1..563a5b2a87 100644 --- a/tooltips.db +++ b/tooltips.db @@ -187,6 +187,7 @@ \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 -- 2.39.2