Titan Logo

 Menu

 Developer

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.
Intended for addons that modify the UI so they can adjust for Titan.
The anchors adjust depending on what Titan bars the user displays.

Inputs
None

Outputs
frame - TitanPanelTopAnchor frame reference - Titan uses the space ABOVE this
frame - TitanPanelBottomAnchor frame reference - 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
The value of the MinimapAdjust option


TitanUtils_SetMinimapAdjust
Set the current setting of the Titan MinimapAdjust option.

Inputs
bool - true (off) or false (on)

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 or 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
frame - The button table
string - The id of the plugin


TitanUtils_GetRealPosition
Return whether the plugin is on the top or bottom bar.

Inputs
id - is the id of the plugin

Outputs
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. Used in the right click menu on load.

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
string - 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
bool - 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
value - b (true) or c (false)


TitanUtils_Toggle
Flip the value assuming it is true or false

Inputs
value - value to start with

Outputs
bool - 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 - value of max (a, b)


GetTimeParts
Use the seconds (s) to return its parts.

Inputs
s - a time value in seconds

Outputs
int - days
int - hours
int - minutes
int - seconds


TitanUtils_GetEstTimeText
Use the seconds (s) to return an estimated time.

Inputs
s - a time value in seconds

Outputs
string - 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 - 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 - 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
frame - nil or the control frame


TitanUtils_TableContainsValue
Determine if the table contains the value.

Inputs
table - table to search
value - value to find

Outputs
int - 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
int - nil or the index


TitanUtils_GetCurrentIndex
Determine if the table contains the value.

Inputs
table - table to search
value - value to find

Outputs
int - nil or the index to value


TitanUtils_PrintArray
Debug tool that will attempt to output the index and value of the array passed in.

Inputs
array - array to output

Outputs
table - Array output to the chat window


TitanUtils_GetRedText
Make the given text red.

Inputs
text - text to color

Outputs
string - Red string with proper start and end font encoding


TitanUtils_GetGoldText
Make the given text gold.

Inputs
text - text to color

Outputs
string - Gold string with proper start and end font encoding


TitanUtils_GetGreenText
Make the given text green.

Inputs
text - text to color

Outputs
string - Green string with proper start and end font encoding


TitanUtils_GetBlueText
Make the given text blue.

Inputs
text - text to color

Outputs
string - Blue string with proper start and end font encoding


TitanUtils_GetNormalText
Make the given text normal (gray-white).

Inputs
text - text to color

Outputs
string - Normal string with proper start and end font encoding


TitanUtils_GetHighlightText
Make the given text highlight (brighter white).

Inputs
text - text to color

Outputs
string - 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
string - 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
string - 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 - 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
bool - 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
int - 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
int - 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
int - 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)

Outputs
None

Notes
- .registry is part of 'self' (the Titan plugin frame) which works great for Titan specific plugins.


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.


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

Notes
- We try to anticipate the various ways a plugin could fail to register or just plain fail.


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.


TitanUtils_IsPluginRegistered
See if the given plugin was registered successfully.

Inputs
- id - id of the plugin

Outputs
None


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


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".


TitanDisplayRightClickMenu_OnLoad
Prepare the Titan bar right click menu using the given function.

Inputs
- self - frame of the Titan bar

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)

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

Outputs
None

Notes
- This routine is for Titan bar. There is a similar routine for the Titan plugins.


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


TitanUtils_CreateName
Given the player name and server and return the Titan name.

Inputs
- player - 1st part

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


TitanUtils_GetGlobalProfile
Return the global profile setting and the global profile name, if any.

Inputs
None

Outputs
- bool Global profile value


TitanUtils_SetGlobalProfile
Return the global profile setting and the global profile name, if any.

Inputs
- bool Global profile value

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

Outputs
- string - message to chat window