[zzAddOn] Add RegisterOpen, RegisterClose
This commit is contained in:
parent
ef8524f344
commit
b1dc280012
|
@ -1,13 +1,17 @@
|
||||||
local lib = LibStub:NewLibrary("zzAddOn", 10)
|
local lib = LibStub:NewLibrary("zzAddOn", 11)
|
||||||
if not lib then return end
|
if not lib then return end
|
||||||
local config = LibStub:GetLibrary("zzConfig")
|
local config = LibStub:GetLibrary("zzConfig")
|
||||||
lib['callbacks'] = lib['callbacks'] or LibStub:GetLibrary("CallbackHandler-1.0"):New(lib)
|
lib['callbacks'] = lib['callbacks'] or LibStub:GetLibrary("CallbackHandler-1.0"):New(lib)
|
||||||
lib['addons'] = lib['addons'] or {}
|
lib['addons'] = lib['addons'] or {}
|
||||||
|
lib['managerframe'] = lib['managerframe'] or {
|
||||||
|
['hide'] = {},
|
||||||
|
['show'] = {}
|
||||||
|
}
|
||||||
lib['events'] = lib['events'] or CreateFrame("FRAME")
|
lib['events'] = lib['events'] or CreateFrame("FRAME")
|
||||||
local function errormsg(err)
|
local function errormsg(err)
|
||||||
print(format("|cffff0000Error:|r %s",err))
|
print(format("|cffff0000Error:|r %s",err))
|
||||||
end
|
end
|
||||||
local mixins = {'NewAddOn', 'GetAddOn', 'AddChild', 'HasChild', 'IsChild', 'HasParent', 'GetParent', 'GetOptions', 'RegisterEvent','UnregisterEvent','IsClassic','IsBCC','IsRetail', 'GetSpecs', 'Fire'}
|
local mixins = {'NewAddOn', 'GetAddOn', 'AddChild', 'HasChild', 'IsChild', 'HasParent', 'GetParent', 'GetOptions', 'RegisterEvent','UnregisterEvent','IsClassic','IsBCC','IsRetail', 'GetSpecs', 'Fire', 'RegisterOpen', 'RegisterClose'}
|
||||||
function lib:Fire(...)
|
function lib:Fire(...)
|
||||||
lib['callbacks']:Fire(...)
|
lib['callbacks']:Fire(...)
|
||||||
end
|
end
|
||||||
|
@ -103,6 +107,43 @@ end
|
||||||
function lib:IsRetail()
|
function lib:IsRetail()
|
||||||
return WOW_PROJECT_ID == WOW_PROJECT_MAINLINE
|
return WOW_PROJECT_ID == WOW_PROJECT_MAINLINE
|
||||||
end
|
end
|
||||||
|
local function handleManagerFrameShow(event, self, event, num)
|
||||||
|
lib['callbacks']:Fire(format("show-%i", num), self, 'show', num)
|
||||||
|
end
|
||||||
|
local function handleManagerFrameHide(event, self, event, num)
|
||||||
|
lib['callbacks']:Fire(format("hide-%i", num), self, 'hide', num)
|
||||||
|
end
|
||||||
|
local function addManagerFrame(self, mode, num, globalfunc)
|
||||||
|
if(type(num) == 'table') then
|
||||||
|
for k, v in pairs(num) do
|
||||||
|
local n = k
|
||||||
|
local func = v
|
||||||
|
if(type(v) == 'number') then
|
||||||
|
n = v
|
||||||
|
func = globalfunc
|
||||||
|
end
|
||||||
|
addManagerFrame(self, mode, n, func)
|
||||||
|
end
|
||||||
|
elseif(type(num) == 'number') then
|
||||||
|
lib.RegisterCallback(self, format("%s-%i", mode, num), globalfunc)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function lib:RegisterOpen(num, func)
|
||||||
|
if(not num) then return end
|
||||||
|
local event = "PLAYER_INTERACTION_MANAGER_FRAME_SHOW"
|
||||||
|
if(not lib['events']:IsEventRegistered(event)) then
|
||||||
|
self:RegisterEvent(event, handleManagerFrameShow)
|
||||||
|
end
|
||||||
|
addManagerFrame(self, 'show', num, func)
|
||||||
|
end
|
||||||
|
function lib:RegisterClose(num, func)
|
||||||
|
if(not num) then return end
|
||||||
|
local event = "PLAYER_INTERACTION_MANAGER_FRAME_HIDE"
|
||||||
|
if(not lib['events']:IsEventRegistered(event)) then
|
||||||
|
self:RegisterEvent(event, handleManagerFrameHide)
|
||||||
|
end
|
||||||
|
addManagerFrame(self, 'hide', num, func)
|
||||||
|
end
|
||||||
function lib:NewAddOn(addonName, addonTable)
|
function lib:NewAddOn(addonName, addonTable)
|
||||||
local specs = self['specs']
|
local specs = self['specs']
|
||||||
local childName = specs['name']
|
local childName = specs['name']
|
||||||
|
|
Loading…
Reference in New Issue