From: terencehill Date: Wed, 9 Mar 2011 20:55:07 +0000 (+0100) Subject: Merge branch 'master' into terencehill/menu_tooltips_2 X-Git-Tag: xonotic-v0.6.0~40^2~108^2~8 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=commitdiff_plain;h=b8f71d297050680a3b25b063375ca5feec9ff67b;hp=09d98a2f7d09205efed74701ddea4c8a3ce24ed7 Merge branch 'master' into terencehill/menu_tooltips_2 Conflicts: defaultXonotic.cfg --- diff --git a/defaultXonotic.cfg b/defaultXonotic.cfg index e9e2f026cf..139654ea83 100644 --- a/defaultXonotic.cfg +++ b/defaultXonotic.cfg @@ -1377,6 +1377,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 0894856f1f..4ae22cd08d 100644 --- a/qcsrc/menu/menu.qc +++ b/qcsrc/menu/menu.qc @@ -242,8 +242,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) { @@ -319,16 +319,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; } @@ -410,6 +413,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) @@ -420,28 +425,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) @@ -461,9 +500,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); @@ -490,7 +531,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) @@ -512,8 +553,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) { @@ -525,7 +572,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); @@ -703,7 +750,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 7fa3dc66b3..9a0b8e060c 100644 --- a/qcsrc/menu/xonotic/dialog_settings_misc.c +++ b/qcsrc/menu/xonotic/dialog_settings_misc.c @@ -78,6 +78,12 @@ void XonoticMiscSettingsTab_fill(entity me) me.TR(me); me.TR(me); me.TD(me, 1, 3, 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); 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 1d21ba4910..3207132a45 100644 --- a/qcsrc/menu/xonotic/util.qc +++ b/qcsrc/menu/xonotic/util.qc @@ -22,7 +22,7 @@ void unloadTooltips() string getZonedTooltipForIdentifier(string s) { string t; - if(s == "") + if(s == "" || tooltipdb < 0) return string_null; if(tooltipdb >= 0) { @@ -72,6 +72,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 0d31f0150a..3844c7558f 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 a0443b7035..d0bd5636e0 100644 --- a/tooltips.db +++ b/tooltips.db @@ -188,6 +188,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