TitanUtils.lua
TitanUtils.lua This file contains various utility routines used by Titan and routines available to plugin developers.
TitanUtils_GetBarAnchors Get the anchors of the bottom most top bar and the top most bottom bar.
Inputs None
Outputs frame - TitanPanelTopAnchor - Titan uses the space ABOVE this frame - TitanPanelBottomAnchor - Titan uses the space BELOW this
Notes - The two anchors are implemented as 2 frames that are moved by Titan depending on which bars are shown.
TitanUtils_GetMinimapAdjust Return the current setting of the Titan MinimapAdjust option.
Inputs None
Outputs value - of the MinimapAdjust option
TitanUtils_SetMinimapAdjust Set the current setting of the Titan MinimapAdjust option.
Inputs None
Outputs None
TitanUtils_AddonAdjust Tell Titan to adjust (or not) a frame.
Inputs frame - is the name (string) of the frame bool - true if the addon will adjust the frame; false if Titan will adjust
Outputs None
TitanUtils_GetButton Return the actual button frame and the plugin id.
Inputs id - is the id of the plugin
Outputs table - of the button or nil string - id of the plugin or nil
TitanUtils_GetRealPosition Return whether the plugin is on the top or bottom bar.
Inputs id - is the id of the plugin
Outputs int - bottom(2) or top(1)-default
Notes - This returns top or bottom NOT which bar (1-4) the plugin is on.
TitanUtils_GetButtonID Return the plugin id of the given name. This can be used to see if a plugin exists.
Inputs name - is the id of the plugin
Outputs string - plugin id or nil
TitanUtils_GetParentButtonID Return the plugin id of the parent of the given name, if it exists.
Inputs name - is the id of the plugin
Outputs string - plugin id or nil
TitanUtils_GetButtonIDFromMenu Return the plugin id of whatever the mouse is over.
Inputs self - is the id of the frame
Outputs string - plugin id or nil
Notes - The plugin id returned could be the Titan bar or a plugin or nil.
TitanUtils_GetPlugin Return the plugin itself (table and all).
Inputs id - is the id of the plugin
Outputs table - plugin or nil
TitanUtils_GetWhichBar Return the bar the plugin is shown on.
Inputs id - is the id of the plugin
Outputs string - bar name or nil
TitanUtils_PickBar Return the first bar that is shown.
Inputs None
Outputs bar name or nil
TitanUtils_ToRight See if the plugin is to be on the right. There are 3 methods to place a plugin on the right: 1) DisplayOnRightSide saved variable logic (preferred) 2) Create a plugin button using the TitanPanelIconTemplate 3) Place a plugin in TITAN_PANEL_NONMOVABLE_PLUGINS (NOT preferred)
Inputs None
Outputs true or nil; true if the plugin is to be placed on the right side of a bar.
TitanUtils_Ternary Return b or c if true or false respectively
Inputs a - value to determine true or false b - value to use if true c - value to use if false or nil
Outputs b (true) or c (false)
TitanUtils_Toggle Flip the value assuming it is true or false
Inputs value - value to start with
Outputs true or false
TitanUtils_Min Return the min of a or b
Inputs a - a value b - a value
Outputs value of min (a, b)
TitanUtils_Max Return the max of a or b
Inputs a - a value b - a value
Outputs value of max (a, b)
GetTimeParts Use the seconds (s) to return its parts.
Inputs s - a time value in seconds
Outputs days hours minutes seconds
TitanUtils_GetEstTimeText Use the seconds (s) to return an estimated time.
Inputs s - a time value in seconds
Outputs string with localized, estimated elapsed time using spaces and leaving off the rest
TitanUtils_GetFullTimeText break the seconds (s) into days, hours, minutes, and seconds
Inputs s - a time value in seconds
Outputs string with localized days, hours, minutes, and seconds using commas and including zeroes
TitanUtils_GetAbbrTimeText break the seconds (s) into days, hours, minutes, and seconds
Inputs s - a time value in seconds
Outputs string with localized days, hours, minutes, and seconds using spaces and including zeroes
TitanUtils_GetControlFrame return the control frame, if one was created.
Inputs id - id of the plugin
Outputs nil or the control frame
TitanUtils_TableContainsValue Determine if the table contains the value.
Inputs table - table to search value - value to find
Outputs nil or the index to value
TitanUtils_TableContainsIndex Determine if the table contains the index.
Inputs table - table to search index - index to find
Outputs nil or the index
TitanUtils_GetCurrentIndex Determine if the table contains the value.
Inputs table - table to search value - value to find
Outputs nil or the index to value
TitanUtils_GetRedText Make the given text red.
Inputs text - text to color
Outputs Red string with proper start and end font encoding
TitanUtils_GetYellowText Make the given text yellow.
Inputs text - text to color
Outputs Yellow string with proper start and end font encoding
TitanUtils_GetGoldText Make the given text gold.
Inputs text - text to color
Outputs Gold string with proper start and end font encoding
TitanUtils_GetGreenText Make the given text green.
Inputs text - text to color
Outputs Green string with proper start and end font encoding
TitanUtils_GetBlueText Make the given text blue.
Inputs text - text to color
Outputs Blue string with proper start and end font encoding
TitanUtils_GetNormalText Make the given text normal (gray-white).
Inputs text - text to color
Outputs Normal string with proper start and end font encoding
TitanUtils_GetHighlightText Make the given text highlight (brighter white).
Inputs text - text to color
Outputs Highlight string with proper start and end font encoding
TitanUtils_GetColoredText Make the given text a custom color.
Inputs text - text to color color - color is the color table with r, b, g values set.
Outputs Custom color string with proper start and end font encoding
TitanUtils_GetThresholdColor Flexable routine that returns the threshold color for a given value using a table as input.
Inputs ThresholdTable - table holding the list of colors and values value -
Outputs The color value from the treshhold table
TitanUtils_ToString Routine that returns the text or an empty string.
Inputs text - text to check
Outputs string of text or ""
TitanPanelRightClickMenu_AddTitle Menu - add a title at the given level in the form of a button.
Inputs title - text to show level - level to put text
Outputs None
TitanPanelRightClickMenu_AddCommand Menu - add a command at the given level in the form of a button.
Inputs title - text to show value - value of the command functionName - routine to run when clicked level - level to put command
Outputs None
TitanPanelRightClickMenu_AddSpacer Menu - add a blank line at the given level in the form of an inactive button.
Inputs level - level to put the line
Outputs None
TitanPanelRightClickMenu_Hide This will remove the plugin from the Titan bar.
Inputs value - id of the plugin
Outputs None
TitanPanelRightClickMenu_AddToggleVar Menu - add a toggle variable command at the given level in the form of a button.
Inputs text - text to show id - id of the plugin var - the saved variable of the plugin to toggle toggleTable - control table (called with other than nil??) level - level to put the line
Outputs None
TitanPanelRightClickMenu_AddToggleIcon Menu - add a toggle Icon (localized) command at the given level in the form of a button. Titan will properly control the "ShowIcon"
Inputs id - id of the plugin level - level to put the line
Outputs None
TitanPanelRightClickMenu_AddToggleLabelText Menu - add a toggle Label (localized) command at the given level in the form of a button. Titan will properly control the "ShowLabelText"
Inputs id - id of the plugin level - level to put the line
Outputs None
TitanPanelRightClickMenu_AddToggleColoredText Menu - add a toggle Colored Text (localized) command at the given level in the form of a button. Titan will properly control the "ShowColoredText"
Inputs id - id of the plugin level - level to put the line
Outputs None
TitanPanelRightClickMenu_AddHide Menu - add a Hide (localized) command at the given level in the form of a button. When clicked this will remove the plugin from the Titan bar.
Inputs id - id of the plugin level - level to put the line
Outputs None
TitanPanelRightClickMenu_ToggleVar This will toggle the Titan variable and the update the button.
Inputs value - table of (id of the plugin, saved var to be updated, control table)
Outputs None
TitanPanelRightClickMenu_AllVarNil Check if all the variables in the table are nil/false.
Inputs id - id of the plugin toggleTable - table of saved var to be checked
Outputs true (1) or nil
TitanPanelRightClickMenu_AddToggleColoredText This will toggle the "ShowColoredText" Titan variable then update the button
Inputs id - id of the plugin level - level to put the line
Outputs None
TitanUtils_SwapButtonOnBar This will swap two buttons on the Titan bars. Once swapped then 'reinit' the buttons to show properly. This is currently used as part of the shift left / right.
Inputs from_id - id of the plugin to_id - id of the plugin
Outputs None
TitanUtils_GetNextButtonOnBar Find the next button that is on the same bar and is on the same side.
Inputs bar - The Titan bar to search id - id of the plugin to see if there is a plugin next to it side - right or left
Outputs index of the next button or nil if none found
Notes -- buttons on Left are placed L to R; buttons on Right are placed R to L. Next and prev depend on which side we need to check.
TitanUtils_GetPrevButtonOnBar Find the previous button that is on the same bar and is on the same side.
Inputs bar - The Titan bar to search id - id of the plugin to see if there is a plugin previous to it side - right or left
Outputs index of the previous button or nil if none found
Notes -- buttons on Left are placed L to R; buttons on Right are placed R to L. Next and prev depend on which side we need to check.
TitanUtils_AddButtonOnBar Add the given plugin to the given bar. Then reinit the plugins to show it properly.
Inputs bar - The Titan bar to add the plugin id - id of the plugin to add
Outputs None.
TitanUtils_GetFirstButtonOnBar Find the first button that is on the given bar and is on the given side.
Inputs bar - The Titan bar to search side - right or left
Outputs index of the first button or nil if none found
Notes -- buttons on Left are placed L to R; buttons on Right are placed R to L. Next and prev depend on which side we need to check. -- buttons on Right are placed R to L
TitanUtils_ShiftButtonOnBarLeft Find the button that is on the bar and is on the side and left of the given button
Inputs name - id of the plugin
Outputs None
TitanUtils_ShiftButtonOnBarRight Find the button that is on the bar and is on the side and right of the given button
Inputs name - id of the plugin
Outputs None
TitanUtils_PluginToRegister Place the plugin to be registered later by Titan
Inputs self - frame of the plugin (must be a Titan template) isChildButton - true if the frame is a child of a Titan frame
Outputs None
Notes - .registry is part of 'self' (the Titan plugin frame) which works great for Titan specific plugins. Titan plugins create the registry as part of the frame _OnLoad. But this does not work for LDB buttons. The frame is created THEN the registry is added to the frame. - Any read of the registry must assume it may not exist. Also assume the registry could be updated after this routine. - This is called when a Titan plugin frame is created. Normally these are held until the player 'enters world' then the plugin is registered. Sometimes plugin frames are created after this process. Right now only LDB plugins are handled. If someone where to start creating Titan frames after the registration process were complete then it would fail to be registered... -!For LDB plugins the 'registry' is attached to the frame AFTER the frame is created... - The fields put into "Attempted" are defaulted here in preperation of being registered.
TitanUtils_PluginFail Place the plugin to be registered later by Titan
Inputs plugin - frame of the plugin (must be a Titan template)
Outputs None
Notes - This is called when a plugin is unsupported. Cuurently this is used if a LDB data object is not supported. See SupportedDOTypes in LDBToTitan.lua for more detail. It is intended mainly for developers. It is a place to put relevant info for debug and so users can supply troubleshooting info. The key is set the status to 'fail' so there is no further attempt to register the plugin. - The results will show in "Attempted" so the developer has a shot at figuring out what was wrong. - plugin is expected to hold as much relevant info as possible...
TitanUtils_RegisterPluginProtected This routine is intended to be called in a protected manner (pcall) by Titan when it attempts to register a plugin.
Inputs plugin - frame of the plugin (must be a Titan template)
Outputs table (see notes)
Notes - Table values: .issue : Show the user what prevented the plugin from registering .result : Used so we know which plugins were processed .id : The name used to lookup the plugin .cat : The 'bucket' to use off the main Titan menu .ptype : For now just Titan or LDB type - We try to anticipate the various ways a plugin could fail to register or just plain fail. The intent is to keep Titan whole so a plugin does not prevent Titan from loading. And attempt to tell the user / developer what went wrong. - If successful the plugin will be in TitanPlugins as a registered plugin and will be available for display on the Titan bars.
TitanUtils_RegisterPlugin Attempt to register a plugin that has requested to be registered
Inputs plugin - frame of the plugin (must be a Titan template)
Outputs None
Notes - Lets be extremely paranoid here because registering plugins that do not play nice can cause real headaches...
TitanUtils_RegisterPluginList Attempt to register the list of plugins that have requested to be registered
Inputs None
Outputs None
Notes - Tell the user when this starts and ends only on the first time. This could be called if a plugin requests to be registered after the first loop through.
TitanUtils_IsPluginRegistered See if the given plugin was registered successfully.
Inputs id - id of the plugin
Outputs true (successful) or false
TitanUtils_CloseRightClickMenu Close the right click menu of any plugin if it was open. Only one can be open at a time.
Inputs None
Outputs None
TitanRightClick_UIScale Scale the right click menu to the user requested value.
Inputs None
Outputs float - x scaled float - y scaled float - scale used
TitanRightClickMenu_OnLoad Prepare the plugin right click menu using the function given by the plugin.
Inputs plugin - frame of the plugin (must be a Titan template)
Outputs None
Notes - The function name is assumed to be "TitanPanelRightClickMenu_Prepare"..plugin_id.."Menu". - This routine is for Titan plugins. There is a similar routine for the Titan bar.
TitanDisplayRightClickMenu_OnLoad Prepare the Titan bar right click menu using the given function.
Inputs self - frame of the Titan bar func - function to create the menu
Outputs None
Notes - This routine is for Titan bar. There is a similar routine for the Titan plugins.
TitanPanelRightClickMenu_Toggle Call the routine to build the plugin menu then place it properly.
Inputs self - frame of the plugin (must be a Titan template) isChildButton - function to create the menu
Outputs None
Notes - This routine is for Titan plugins. There is a similar routine for the Titan bar.
TitanPanelDisplayRightClickMenu_Toggle Call the routine to build the Titan bar menu then place it properly.
Inputs self - frame of the Titan bar isChildButton - function to create the menu
Outputs None
Notes - This routine is for Titan bar. There is a similar routine for the Titan plugins. - This is close to TitanPanelRightClickMenu_Toggle but geared to the Titan display bars. This routine allows the Titan display bars to be independent rather than rely on bars being a 'sort of' plugin. - This relies on name="$parentRightClickMenu" being part of the display bar template.
TitanPanelRightClickMenu_IsVisible Determine if a right click menu is shown. There can only be one.
Inputs None
Outputs true (IsVisible) or false
TitanPanelRightClickMenu_Close Close the right click menu if shown. There can only be one.
Inputs None
Outputs None
TitanUtils_ParseName Parse the player name and return the parts.
Inputs name - the name to break up
Outputs string player name only string realm name only
TitanUtils_CreateName Given the player name and server and return the Titan name.
Inputs player - 1st part realm - 2nd part. Could be realm or 'custom'
Outputs string - Titan name
TitanUtils_GetPlayer Create the player name (toon being played) and return the parts.
Inputs None
Outputs string - Titan player name or nil string - player name only string - realm name only
TitanUtils_GetGlobalProfile Return the global profile setting and the global profile name, if any.
Inputs None
Outputs bool - Global profile value string - Global profile name or default string - player name only or blank string - realm name only or blank
TitanUtils_SetGlobalProfile Return the global profile setting and the global profile name, if any.
Inputs bool Global profile value string Global profile name or default
Outputs None
TitanPanel_GetVersion Get the Titan version into a string.
Inputs None
Outputs string containing the version
TitanPrint Output a message to the user in a consistent format.
Inputs message - string to output msg_type - "info" | "warning" | "error" | "plain"
Outputs string - message to chat window
TitanUtils_PrintArray Debug tool that will attempt to output the index and value of the array passed in.
Inputs array - array to output
Outputs Array output to the chat window
|