GUI Scripting:Tooltip Macro

From The DarkMod Wiki
Revision as of 17:26, 8 August 2022 by Geep (talk | contribs) (→‎Caution: Add mention of semicolon)
Jump to navigationJump to search

This page is part of a series. See GUI Scripting Language for overview.

Introduction

Specific to TDM's main menu system, a macro offers a simple way to provide an internationalized tooltip, invoked by guiDef mouse-over. The tooltip appears, not over the guiDef, but in a fixed screen location, offset to the left of the current menu. Syntax:

toolTip ("string")

Note the parentheses around the quoted string, and no semicolon at the end. As a specific example:

toolTip("#str_menu_fov_tooltip")

This macro expands into event handlers and so should be placed after the Property List. Usually, it is placed at the end of the guiDef's body, after any other event handlers.

The TDM convention is to include this as needed with choiceDefs and sliderDefs, not with their windowDef prompts. A few windowDef buttons offer tool tips:

  • At the bottom of the Settings page, the "Restart Game" button has the tool tip "Some settings need to restart for the changes to take effect". Implemented in mainmenu_settings.gui's windowDef SettingsRestartGameAction.
  • In the Settings/Video/Advanced page, the first row "HUD Size/Opacity" has an "Adjust" button, with tool tip "(click for more details)". Implemented in mainmenu_settings_video.gui's windowDef GUI_Button.

Caution

This macro expands into OnMouseEnter and OnMouseExit event handlers... so if you have those same handlers elsewhere in your guiDef, you may need check for conflicts and/or merge handler bodies manually, using showTopTip(...) and hideTooltip(). See windowDef SettingsRestartGameAction in mainmenu_settings.gui for an example. Unlike ToolTip(...), the invocation of showToolTip(...) and hideToolTip(...) must be followed by a semicolon.

Also, "noevents 1" would disable toolTip, so treat them as mutually exclusive. For example, the windowDef that provides the tic-mark background behind sliderDef appropriately has "noevents 1" set, and does not include toolTip.

Implementation

In mainmenu_utils.gui, which is included with other main menu GUIs:

...
windowDef ToolTip
{
   rect 16, 360 , 288, 120
   visible "gui::tdm_show_menu_tooltips"
   float active;
   windowDef ToolTipText
   {
      rect 00, 10, 280, 80
      MM_TT_FONT
      textscale 0.2
   }
}
#define showToolTip(TTtext)\
set "ToolTipText::text" TTtext

#define hideToolTip\
set "ToolTipText::text" ""

#define toolTip(TTtext)\
onMouseEnter\
{\
   showToolTip(TTtext);\
}\
onMouseExit\
{\
   hideToolTip;\
}

See Also