This commit is contained in:
Crum
2018-02-21 11:23:00 -06:00
parent 3717ffbca1
commit 612c53d6d5
11 changed files with 275 additions and 258 deletions
+122 -119
View File
@@ -8,6 +8,9 @@ local argcheck = Private.argcheck
local print = Private.print
local error = Private.error
local gsub, lower, match, split, upper = string.gsub, string.lower, string.match, string.split, string.upper
local insert, remove = table.insert, table.remove
local styles, style = {}
local callback, units, objects, headers = {}, {}, {}, {}
@@ -20,11 +23,11 @@ local function enableTargetUpdate(object)
object.__eventless = true
local total = 0
object:SetScript('OnUpdate', function()
object:SetScript("OnUpdate", function()
if not this.unit then
return
elseif total > this.onUpdateFrequency then
this:UpdateAllElements('OnUpdate')
this:UpdateAllElements("OnUpdate")
total = 0
end
@@ -38,23 +41,23 @@ local function updateActiveUnit(self, event, unit)
end
local function iterateChildren(...)
for i = 1, table.getn(arg) do
for i = 1, getn(arg) do
local obj = arg[i]
if(type(obj) == 'table' and obj.isChild) then
updateActiveUnit(obj, 'iterateChildren')
if(type(obj) == "table" and obj.isChild) then
updateActiveUnit(obj, "iterateChildren")
end
end
end
local function onAttributeChanged(self, name, value)
if(name == 'unit' and value) then
if(name == "unit" and value) then
if(self.hasChildren) then
iterateChildren(self:GetChildren())
end
if(not self.onlyProcessChildren) then
updateActiveUnit(self, 'OnAttributeChanged')
updateActiveUnit(self, "OnAttributeChanged")
end
--[[
if(self.unit and self.unit == value) then
@@ -69,30 +72,30 @@ local function onAttributeChanged(self, name, value)
end
local frame_metatable = {
__index = CreateFrame('Button')
__index = CreateFrame("Button")
}
Private.frame_metatable = frame_metatable
for k, v in next, {
UpdateElement = function(self, name)
local unit = self.unit
if(not unit or not UnitExists(unit)) then return end
if(not unit or not UnitExists(unit)) then return end
local element = elements[name]
if(not element or not self:IsElementEnabled(name) or not activeElements[self]) then return end
if(element.update) then
element.update(self, 'OnShow', unit)
element.update(self, "OnShow", unit)
end
end,
UpdateElement = function(self, name)
local unit = self.unit
if(not unit or not UnitExists(unit)) then return end
if(not unit or not UnitExists(unit)) then return end
local element = elements[name]
if(not element or not self:IsElementEnabled(name) or not activeElements[self]) then return end
if(element.update) then
element.update(self, 'OnShow', unit)
element.update(self, "OnShow", unit)
end
end,
@@ -101,14 +104,14 @@ for k, v in next, {
* self - unit frame for which the element should be enabled
* name - name of the element to be enabled (string)
* unit - unit to be passed to the element's Enable function. Defaults to the frame's unit (string?)
* unit - unit to be passed to the element"s Enable function. Defaults to the frame"s unit (string?)
--]]
EnableElement = function(self, name, unit)
local unit = unit or self.unit
if not unit then return end
argcheck(name, 2, 'string')
argcheck(unit or self.unit, 3, 'string', 'nil')
argcheck(name, 2, "string")
argcheck(unit or self.unit, 3, "string", "nil")
local element = elements[name]
if(not element or self:IsElementEnabled(name) or not activeElements[self]) then return end
@@ -117,7 +120,7 @@ for k, v in next, {
activeElements[self][name] = true
if(element.update) then
table.insert(self.__elements, element.update)
insert(self.__elements, element.update)
end
end
end,
@@ -129,7 +132,7 @@ for k, v in next, {
* name - name of the element to be disabled (string)
--]]
DisableElement = function(self, name)
argcheck(name, 2, 'string')
argcheck(name, 2, "string")
local enabled = self:IsElementEnabled(name)
if(not enabled) then return end
@@ -137,7 +140,7 @@ for k, v in next, {
local update = elements[name].update
for k, func in next, self.__elements do
if(func == update) then
table.remove(self.__elements, k)
remove(self.__elements, k)
break
end
end
@@ -148,7 +151,7 @@ for k, v in next, {
-- The main reason we do this is to make sure the full update is completed
-- if an element for some reason removes itself _during_ the update
-- progress.
self:UpdateAllElements('DisableElement')
self:UpdateAllElements("DisableElement")
return elements[name].disable(self)
end,
@@ -160,7 +163,7 @@ for k, v in next, {
* name - name of the element (string)
--]]
IsElementEnabled = function(self, name)
argcheck(name, 2, 'string')
argcheck(name, 2, "string")
local element = elements[name]
if(not element) then return end
@@ -174,7 +177,7 @@ for k, v in next, {
`RegisterUnitWatch`.
* self - unit frame
* asState - if true, the frame's "state-unitexists" attribute will be set to a boolean value denoting whether the
* asState - if true, the frame"s "state-unitexists" attribute will be set to a boolean value denoting whether the
unit exists; if false, the frame will be shown if its unit exists, and hidden if it does not (boolean)
--]]
Enable = RegisterUnitWatch,
@@ -192,13 +195,13 @@ for k, v in next, {
Used to update all enabled elements on the given frame.
* self - unit frame
* event - event name to pass to the elements' update functions (string)
* event - event name to pass to the elements" update functions (string)
--]]
UpdateAllElements = function(self, event)
local unit = self.unit
if(not UnitExists(unit)) then return end
assert(type(event) == 'string', "Invalid argument 'event' in UpdateAllElements.")
assert(type(event) == "string", "Invalid argument 'event' in UpdateAllElements.")
if(self.PreUpdate) then
self:PreUpdate(event)
@@ -227,23 +230,23 @@ local function InitializeSecureMenu()
local unit = SecureTemplatesDropdown.unit
if(not unit) then return end
local unitType = string.match(unit, '^([a-z]+)[0-9]+$') or unit
local unitType = match(unit, "^([a-z]+)[0-9]+$") or unit
local menu
if(unitType == 'party') then
menu = 'PARTY'
elseif(UnitIsUnit(unit, 'player')) then
menu = 'SELF'
elseif(UnitIsUnit(unit, 'pet')) then
menu = 'PET'
if(unitType == "party") then
menu = "PARTY"
elseif(UnitIsUnit(unit, "player")) then
menu = "SELF"
elseif(UnitIsUnit(unit, "pet")) then
menu = "PET"
elseif(UnitIsPlayer(unit)) then
if(UnitInRaid(unit) or UnitInParty(unit)) then
menu = 'PARTY'
menu = "PARTY"
else
menu = 'PLAYER'
menu = "PLAYER"
end
elseif(UnitIsUnit(unit, 'target')) then
menu = 'RAID_TARGET_ICON'
elseif(UnitIsUnit(unit, "target")) then
menu = "RAID_TARGET_ICON"
end
if(menu) then
@@ -253,33 +256,33 @@ end
local function togglemenu(self, unit)
if(not secureDropdown) then
secureDropdown = CreateFrame('Frame', 'SecureTemplatesDropdown', nil, 'UIDropDownMenuTemplate')
secureDropdown = CreateFrame("Frame", "SecureTemplatesDropdown", nil, "UIDropDownMenuTemplate")
secureDropdown:SetID(1)
table.insert(UnitPopupFrames, secureDropdown:GetName())
UIDropDownMenu_Initialize(secureDropdown, InitializeSecureMenu, 'MENU')
insert(UnitPopupFrames, secureDropdown:GetName())
UIDropDownMenu_Initialize(secureDropdown, InitializeSecureMenu, "MENU")
end
if(secureDropdown.openedFor and secureDropdown.openedFor ~= self) then
CloseDropDownMenus()
end
secureDropdown.unit = string.lower(unit)
secureDropdown.unit = lower(unit)
secureDropdown.openedFor = self
ToggleDropDownMenu(1, nil, secureDropdown, 'cursor')
ToggleDropDownMenu(1, nil, secureDropdown, "cursor")
end
local function onShow()
return this:UpdateAllElements('OnShow')
return this:UpdateAllElements("OnShow")
end
local function initObject(unit, style, styleFunc, header, ...)
local num = table.getn(arg)
local num = getn(arg)
for i = 1, num do
local object = arg[i]
local objectUnit = object.guessUnit or unit
local suffix = string.match(objectUnit or unit, '%w+target')
local suffix = match(objectUnit or unit, "%w+target")
object.__elements = {}
object.__registeredEvents = {}
@@ -287,10 +290,10 @@ local function initObject(unit, style, styleFunc, header, ...)
object = setmetatable(object, frame_metatable)
-- Expose the frame through oUF.objects.
table.insert(objects, object)
insert(objects, object)
-- We have to force update the frames when PEW fires.
object:RegisterEvent('PLAYER_ENTERING_WORLD', object.UpdateAllElements)
object:RegisterEvent("PLAYER_ENTERING_WORLD", object.UpdateAllElements)
object:SetScript("OnClick", function()
if arg1 == "RightButton" then
@@ -302,14 +305,14 @@ local function initObject(unit, style, styleFunc, header, ...)
if(not header) then
-- Other target units are handled by :HandleUnit().
if(suffix == 'target') then
if(suffix == "target") then
enableTargetUpdate(object)
else
oUF:HandleUnit(object, unit)
end
else
-- Used to update frames when they change position in a group.
object:RegisterEvent('RAID_ROSTER_UPDATE', object.UpdateAllElements)
object:RegisterEvent("RAID_ROSTER_UPDATE", object.UpdateAllElements)
if(num > 1) then
if(object:GetParent() == header) then
@@ -319,7 +322,7 @@ local function initObject(unit, style, styleFunc, header, ...)
end
end
if(suffix == 'target') then
if(suffix == "target") then
enableTargetUpdate(object)
end
end
@@ -328,8 +331,8 @@ local function initObject(unit, style, styleFunc, header, ...)
styleFunc(object, objectUnit, not header)
--object:SetScript('OnAttributeChanged', onAttributeChanged)
object:SetScript('OnShow', onShow)
--object:SetScript("OnAttributeChanged", onAttributeChanged)
object:SetScript("OnShow", onShow)
activeElements[object] = {}
for element in next, elements do
@@ -356,7 +359,7 @@ local function walkObject(object, unit)
-- Check if we should leave the main frame blank.
if(object.onlyProcessChildren) then
object.hasChildren = true
--object:SetScript('OnAttributeChanged', onAttributeChanged)
--object:SetScript("OnAttributeChanged", onAttributeChanged)
return initObject(unit, style, styleFunc, header, object:GetChildren())
end
@@ -370,7 +373,7 @@ Used to add a function to a table to be executed upon unit frame/header initiali
* func - function to be added
--]]
function oUF:RegisterInitCallback(func)
table.insert(callback, func)
insert(callback, func)
end
--[[ oUF:RegisterMetaFunction(name, func)
@@ -381,8 +384,8 @@ Used to make a (table of) function(s) available to all unit frames.
* func - function or a table of functions (function or table)
--]]
function oUF:RegisterMetaFunction(name, func)
argcheck(name, 2, 'string')
argcheck(func, 3, 'function', 'table')
argcheck(name, 2, "string")
argcheck(func, 3, "function", "table")
if(frame_metatable.__index[name]) then
return
@@ -392,17 +395,17 @@ function oUF:RegisterMetaFunction(name, func)
end
--[[ oUF:RegisterStyle(name, func)
Used to register a style with oUF. This will also set the active style if it hasn't been set yet.
Used to register a style with oUF. This will also set the active style if it hasn"t been set yet.
* self - the global oUF object
* name - name of the style
* func - function(s) defining the style (function or table)
--]]
function oUF:RegisterStyle(name, func)
argcheck(name, 2, 'string')
argcheck(func, 3, 'function', 'table')
argcheck(name, 2, "string")
argcheck(func, 3, "function", "table")
if(styles[name]) then return error('Style [%s] already registered.', name) end
if(styles[name]) then return error("Style [%s] already registered.", name) end
if(not style) then style = name end
styles[name] = func
@@ -415,15 +418,15 @@ Used to set the active style.
* name - name of the style (string)
--]]
function oUF:SetActiveStyle(name)
argcheck(name, 2, 'string')
if(not styles[name]) then return error('Style [%s] does not exist.', name) end
argcheck(name, 2, "string")
if(not styles[name]) then return error("Style [%s] does not exist.", name) end
style = name
end
do
local function iter(_, n)
-- don't expose the style functions.
-- don"t expose the style functions.
return (next(styles, n))
end
@@ -440,18 +443,18 @@ end
local getCondition
do
local conditions = {
raid40 = '[target=raid26,exists] show;',
raid25 = '[target=raid11,exists] show;',
raid10 = '[target=raid6,exists] show;',
raid = '[group:raid] show;',
party = '[group:party,nogroup:raid] show;',
solo = '[target=player,exists,nogroup:party] show;',
raid40 = "[target=raid26,exists] show;",
raid25 = "[target=raid11,exists] show;",
raid10 = "[target=raid6,exists] show;",
raid = "[group:raid] show;",
party = "[group:party,nogroup:raid] show;",
solo = "[target=player,exists,nogroup:party] show;",
}
function getCondition(...)
local cond = ''
local cond = ""
for i = 1, select('#', arg) do
for i = 1, getn(arg) do
local short = select(i, unpack(arg))
local condition = conditions[short]
@@ -460,21 +463,21 @@ do
end
end
return cond .. 'hide'
return cond .. "hide"
end
end
local function generateName(unit, ...)
local name = 'oUF_' .. style:gsub('^oUF_?', ''):gsub('[^%a%d_]+', '')
local name = "oUF_" .. gsub(style, gsub("^oUF_?", ""), gsub("[^%a%d_]+", ""))
local raid, party, groupFilter
for i = 1, select('#', arg), 2 do
for i = 1, getn(arg), 2 do
local att, val = select(i, unpack(arg))
if(att == 'showRaid') then
if(att == "showRaid") then
raid = true
elseif(att == 'showParty') then
elseif(att == "showParty") then
party = true
elseif(att == 'groupFilter') then
elseif(att == "groupFilter") then
groupFilter = val
end
end
@@ -482,27 +485,27 @@ local function generateName(unit, ...)
local append
if(raid) then
if(groupFilter) then
if(type(groupFilter) == 'number' and groupFilter > 0) then
if(type(groupFilter) == "number" and groupFilter > 0) then
append = groupFilter
elseif(groupFilter:match('TANK')) then
append = 'MainTank'
elseif(groupFilter:match('ASSIST')) then
append = 'MainAssist'
elseif(match(groupFilter, "TANK")) then
append = "MainTank"
elseif(match(groupFilter, "ASSIST")) then
append = "MainAssist"
else
local _, count = groupFilter:gsub(',', '')
local _, count = gsub(groupFilter, ",", "")
if(count == 0) then
append = 'Raid' .. groupFilter
append = "Raid" .. groupFilter
else
append = 'Raid'
append = "Raid"
end
end
else
append = 'Raid'
append = "Raid"
end
elseif(party) then
append = 'Party'
append = "Party"
elseif(unit) then
append = unit:gsub('^%l', string.upper)
append = gsub(unit, "^%l", upper)
end
if(append) then
@@ -530,17 +533,17 @@ do
local unit
if(not self.onlyProcessChildren) then
local groupFilter = header:GetAttribute('groupFilter')
local groupFilter = header:GetAttribute("groupFilter")
if(header:GetAttribute('showRaid')) then
unit = 'raid'
elseif(header:GetAttribute('showParty')) then
unit = 'party'
if(header:GetAttribute("showRaid")) then
unit = "raid"
elseif(header:GetAttribute("showParty")) then
unit = "party"
end
self.menu = togglemenu
--self:SetAttribute('type1', 'target')
--self:SetAttribute('type2', 'menu')
--self:SetAttribute("type1", "target")
--self:SetAttribute("type2", "menu")
self.guessUnit = unit
self.unit = "player"
-- self.onlyProcessChildren =true
@@ -567,7 +570,7 @@ do
* self - the global oUF object
* overrideName - unique global name to be used for the header. Defaults to an auto-generated name based on the name
of the active style and other arguments passed to `:SpawnHeader` (string?)
* template - name of a template to be used for creating the header. Defaults to `'oUF_GroupHeaderTemplate'`
* template - name of a template to be used for creating the header. Defaults to `"oUF_GroupHeaderTemplate"`
(string?)
* visibility - macro conditional(s) which define when to display the header (string).
* ... - further argument pairs. Consult [Group Headers](http://wowprogramming.com/docs/secure_template/Group_Headers)
@@ -581,20 +584,20 @@ do
* oUF-onlyProcessChildren - can be used to force headers to only process children (boolean?)
--]]
function oUF:SpawnHeader(overrideName, template, visibility, ...)
if(not style) then return error('Unable to create frame. No styles have been registered.') end
if(not style) then return error("Unable to create frame. No styles have been registered.") end
template = (template or 'oUF_GroupHeaderTemplate')
template = (template or "oUF_GroupHeaderTemplate")
local isPetHeader = string.match(template, 'PetHeader')
local isPetHeader = match(template, "PetHeader")
local name = overrideName or generateName(nil, unpack(arg))
local header = CreateFrame('Frame', name, UIParent, template)
local header = CreateFrame("Frame", name, UIParent, template)
header:Hide()
header.attributes = {}
header.SetAttribute = setAttribute
header.GetAttribute = getAttribute
--header:SetAttribute('template', 'SecureUnitButtonTemplate')
--header:SetAttribute("template", "SecureUnitButtonTemplate")
for i = 1, getn(arg), 2 do
local att, val = select(i, unpack(arg))
if(not att) then break end
@@ -607,24 +610,24 @@ do
header.visibility = visibility
-- Expose the header through oUF.headers.
table.insert(headers, header)
insert(headers, header)
header.initialConfigFunction = initialConfigFunction
header.headerType = isPetHeader and 'pet' or 'group'
header.headerType = isPetHeader and "pet" or "group"
if(header:GetAttribute('showParty')) then
self:DisableBlizzard('party')
if(header:GetAttribute("showParty")) then
self:DisableBlizzard("party")
end
--[[if(visibility) then
local type, list = string.split(' ', visibility, 2)
if(list and type == 'custom') then
RegisterStateDriver(header, 'visibility', list)
local type, list = split(" ", visibility, 2)
if(list and type == "custom") then
RegisterStateDriver(header, "visibility", list)
header.visibility = list
else
local condition = getCondition(string.split(',', visibility))
RegisterStateDriver(header, 'visibility', condition)
local condition = getCondition(split(",", visibility))
RegisterStateDriver(header, "visibility", condition)
header.visibility = condition
end
end]]
@@ -637,18 +640,18 @@ end
Used to create a single unit frame and apply the currently active style to it.
* self - the global oUF object
* unit - the frame's unit (string)
* unit - the frame"s unit (string)
* overrideName - unique global name to use for the unit frame. Defaults to an auto-generated name based on the unit
(string?)
--]]
function oUF:Spawn(unit, overrideName)
argcheck(unit, 2, 'string')
if(not style) then return error('Unable to create frame. No styles have been registered.') end
argcheck(unit, 2, "string")
if(not style) then return error("Unable to create frame. No styles have been registered.") end
unit = string.lower(unit)
unit = lower(unit)
local name = overrideName or generateName(unit)
local object = CreateFrame('Button', name, UIParent)
local object = CreateFrame("Button", name, UIParent)
object:Hide()
Private.UpdateUnits(object, unit)
@@ -671,12 +674,12 @@ Used to register an element with oUF.
* disable - used to disable the element for a given unit frame (function?)
--]]
function oUF:AddElement(name, update, enable, disable)
argcheck(name, 2, 'string')
argcheck(update, 3, 'function', 'nil')
argcheck(enable, 4, 'function', 'nil')
argcheck(disable, 5, 'function', 'nil')
argcheck(name, 2, "string")
argcheck(update, 3, "function", "nil")
argcheck(enable, 4, "function", "nil")
argcheck(disable, 5, "function", "nil")
if(elements[name]) then return error('Element [%s] is already registered.', name) end
if(elements[name]) then return error("Element [%s] is already registered.", name) end
elements[name] = {
update = update;
enable = enable;