-
Notifications
You must be signed in to change notification settings - Fork 0
namespace
In each example namespace
refers to the 2nd value of the addon vararg, e.g:
local _, namespace = ...
Checks if the current client is running the "retail" version.
Checks if the current client is running the "classic era" version (e.g. vanilla).
Checks if the current client is running the "classic" version.
Checks if the current client is running a build equal to or newer than the specified.
Optionally also check against the interface version.
Defers a function callback
(with optional arguments) until after combat ends.
Callback can be the global name of a function.
Triggers immediately if player is not in combat.
Defers a method
on object
(with optional arguments) until after combat ends.
Triggers immediately if player is not in combat.
These methods are also available as methods directly on namespace
, e.g:
namespace:RegisterEvent('BAG_UPDATE', function(self, ...)
-- do something
end)
Registers a frame event
with the callback
function.
If the callback returns positive it will be unregistered.
Unregisters a frame event
from the callback
function.
Checks if the frame event
is registered with the callback
function.
Manually trigger the event
(with optional arguments) on all registered callbacks.
If the callback returns positive it will be unregistered.
Registers a unit
-specific frame event
with the callback
function.
If the callback returns positive it will be unregistered for that unit.
Unregisters a unit
-specific frame event
from the callback
function.
Checks if the unit
-specific frame event
is registered with the callback
function.
Manually trigger the unit
-specific event
(with optional arguments) on all registered callbacks.
If the callback returns positive it will be unregistered.
Registers a combat subEvent
with the callback
function.
If the callback returns positive it will be unregistered.
Unregisters a combat subEvent
from the callback
function.
Manually trigger the combat subEvent
on all registered callbacks.
If the callback returns positive it will be unregistered.
- Note: this is pretty useless on it's own, and should only ever be triggered by the event system.
Shorthand for the ADDON_LOADED
for the addon.
Usage:
function namespace:OnLoad()
-- I'm loaded!
end
Shorthand for the PLAYER_LOGIN
.
Usage:
function namespace:OnLogin()
-- player has logged in!
end
Registers a to an anonymous function.
Usage:
function namespace:BAG_UPDATE(bagID)
-- do something
end
Manually trigger all registered anonymous event
callbacks, with optional arguments.
Usage:
namespace:BAG_UPDATE(1) -- triggers the above example
Registers chat slash command
(s) with a callback
function.
Usage:
namespace:RegisterSlash('/hello', '/hi', function(input)
print('Hi')
end)
Returns the number of entries in the table
.
Works for associative tables as opposed to #table
.
Checks if the first string starts with the 2nd string.
Checks whether the addon exists and is enabled.
Registers a hook for when an addon with the name addonName
loads with a callback
function.
Sets a localization string
for the given locale
.
Usage:
local L = namespace.L('deDE')
L['New string'] = 'Neue saite'
Reads a localized string
for the active locale.
If a localized string for the active locale is not available the string
will be read back.
Usage:
print(namespace.L['New string']) --> "Neue saite" on german clients, "New string" on all others
print(namespace.L['Unknown']) --> "Unknown" on all clients since there are no localizations
Checks if the argument arg
at position argIndex
is of type(s).
Returns the individual fields from the given guid
, typecast to their correct types.
Returns the integer id
of the given unit
.
Generates an item link from an itemID
.
This is a crude generation and won't have valid data for complex items.
Returns the ID of the current map the zone the player is located in.
Returns the x
and y
coordinates for the player in the given mapID
(if they are valid).
Returns the aura by spellID
on the unit
, if it exists.
Wrapper for CreateColor that can handle >1-255 range as well.
Alpha (a
) will always be in the 0-1 range.
Wrapper for CreateColor that can handle hex colors (both RRGGBB
and AARRGGBB
).
Formats the given timeInSeconds
to a readable, but abbreviated format.
Forcefully hide an object
, or its child
.
It will recurse down to the last child if provided.
Prints out a message in the chat frame, prefixed with the addon name in color.
Wrapper for namespace:Print(...)
and string.format
.
Wrapper for DevTools_Dump
.
Similar to namespace:Dump(object)
; a wrapper for the graphical version.
Registers a set of settings
with the interface options panel.
The values will be stored by the settings
' objects' key
in savedvariables
.
Should be used with the options methods below.
Usage:
namespace:RegisterSettings('MyAddOnDB', {
{
key = 'myToggle',
type = 'toggle',
title = 'My Toggle',
tooltip = 'Longer description of the toggle in a tooltip',
default = false,
},
{
key = 'mySlider',
type = 'slider',
title = 'My Slider',
tooltip = 'Longer description of the slider in a tooltip',
default = 0.5,
minValue = 0.1,
maxValue = 1.0,
valueStep = 0.01,
valueFormat = formatter, -- callback function or a string for string.format
},
{
key = 'myMenu',
type = 'menu',
title = 'My Menu',
tooltip = 'Longer description of the menu in a tooltip',
default = 'key1',
options = {
{value = key1, label = 'First option'},
{value = key2, label = 'Second option'},
{value = key3, label = 'Third option'},
},
},
{
key = 'myColor',
type = 'color',
title = 'My Color',
tooltip = 'Longer description of the color in a tooltip',
default = 'ff00ff', -- either "RRGGBB" or "AARRGGBB" format
}
})
Registers a set of settings
as a sub-category. name
must be unique.
The savedvariables will be stored under the main savedvariables in a table entry named after name
.
The settings
are identical to that of namespace:RegisterSettings
.
Registers a canvas sub-category. This does not handle savedvariables.
name
must be unique, and callback
is called with a canvas frame
as payload.
Canvas frame has a custom method SetDefaultsHandler
which takes a callback as arg1.
This callback is triggered when the "Defaults" button is clicked.
Wrapper for namespace:RegisterSlash(...)
, except the callback is provided and will open the settings panel for this addon.
Returns the value for the given option key
.
Sets a new value
to the given options key
.
Checks to see if the savedvariables has been loaded in the game.
Register a callback
function with the option key
.
Trigger all registered option callbacks for the given key
, supplying the value
.
Registers a set of settings
to inject into the world map tracking menu.
The values will be stored by the settings
' objects' key
in savedvariables
.
The settings
object is identical to the one for RegisterSetting.
A wrapper for CreateFrame
, mixed in with namespace.eventMixin
.
A wrapper for namespace:CreateFrame(...)
, but will handle key direction preferences of the client.
Use this specifically to create clickable buttons.
Creates and returns a scroll box with scroll bar and a data provider in a list representation. It gets automatically sized to fill the space of the parent.
It provides the following methods, and is initialized whenever data is provided, so do that last.
-
list:SetInsets([top], [bottom], [left], [right])
- sets scroll box insets (all optional) -
list:SetElementType(kind)
- sets the element type or template (required) -
list:SetElementHeight(height)
- sets the element height (required) -
list:SetElementSpacing(spacing)
- sets the spacing between elements (optional) -
list:SetElementSortingMethod(callback)
- sets the sort method for element data (optional) -
list:SetElementOnLoad(callback)
- sets the OnLoad method for each element (optional)- the callback signature is
(element)
- the callback signature is
-
list:SetElementOnUpdate(callback)
- sets the callback for element data updates (optional)- the callback signature is
(element, data)
- the callback signature is
-
list:SetElementOnScript(script, callback)
- sets the script handler for an element (optional) list:AddData(...)
list:AddDataByKeys(table)
list:RemoveData(...)
list:ResetData()
Creates and returns a scroll box with scroll bar and a data provider in a grid representation.
It gets automatically sized to fill the space of the parent.
It provides the following methods, and is initialized whenever data is provided, so do that last.
-
grid:SetInsets([top], [bottom], [left], [right])
- sets scroll box insets (all optional) -
grid:SetElementType(kind)
- sets the element type or template (required) -
grid:SetElementHeight(height)
- sets the element height (required) -
grid:SetElementWidth(width)
- sets the element width (required) -
grid:SetElementSize(width[, height])
- sets the element width and height, shorthand for the two above, height falls back to width if not provided -
grid:SetElementSpacing(horizontal[, vertical])
- sets the spacing between elements, vertical falls back to horizontal if not provided (optional) -
grid:SetElementSortingMethod(callback)
- sets the sort method for element data (optional) -
grid:SetElementOnLoad(callback)
- sets the OnLoad method for each element (optional)- the callback signature is
(element)
- the callback signature is
-
grid:SetElementOnUpdate(callback)
- sets the callback for element data updates (optional)- the callback signature is
(element, data)
- the callback signature is
-
grid:SetElementOnScript(script, callback)
- sets the script handler for an element (optional) grid:AddData(...)
grid:AddDataByKeys(table)
grid:RemoveData(...)
grid:ResetData()