[zzAddOn] Fix to make sure ManagerFrameEvent is fired only once

This commit is contained in:
Robin Hüskes 2022-12-03 16:14:42 +01:00
parent 97302fda67
commit fdd8d7edc3
1 changed files with 15 additions and 11 deletions

View File

@ -3,10 +3,7 @@ if not lib then return end
local config = LibStub:GetLibrary("zzConfig")
lib['callbacks'] = lib['callbacks'] or LibStub:GetLibrary("CallbackHandler-1.0"):New(lib)
lib['addons'] = lib['addons'] or {}
lib['managerframe'] = lib['managerframe'] or {
['hide'] = {},
['show'] = {}
}
lib['managerframe'] = lib['managerframe'] or CreateFrame("FRAME")
lib['events'] = lib['events'] or CreateFrame("FRAME")
local function errormsg(err)
print(format("|cffff0000Error:|r %s",err))
@ -107,11 +104,12 @@ end
function lib:IsRetail()
return WOW_PROJECT_ID == WOW_PROJECT_MAINLINE
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)
local function handleManagerFrame(self, event, num)
if(event == "PLAYER_INTERACTION_MANAGER_FRAME_SHOW") then
lib['callbacks']:Fire(format("show-%i", num))
else
lib['callbacks']:Fire(format("show-%i", num))
end
end
local function addManagerFrame(self, mode, num, globalfunc)
if(type(num) == 'table') then
@ -130,12 +128,18 @@ local function addManagerFrame(self, mode, num, globalfunc)
end
function lib:RegisterOpen(num, func)
if(not num) then return end
self:RegisterEvent("PLAYER_INTERACTION_MANAGER_FRAME_SHOW", handleManagerFrameShow)
if(not lib['managerframe']:IsEventRegistered("PLAYER_INTERACTION_MANAGER_FRAME_SHOW")) then
lib['managerframe']:RegisterEvent("PLAYER_INTERACTION_MANAGER_FRAME_SHOW")
lib['managerframe']:SetScript("OnEvent", handleManagerFrame)
end
addManagerFrame(self, 'show', num, func)
end
function lib:RegisterClose(num, func)
if(not num) then return end
self:RegisterEvent("PLAYER_INTERACTION_MANAGER_FRAME_HIDE", handleManagerFrameHide)
if(not lib['managerframe']:IsEventRegistered("PLAYER_INTERACTION_MANAGER_FRAME_HIDE")) then
lib['managerframe']:RegisterEvent("PLAYER_INTERACTION_MANAGER_FRAME_HIDE")
lib['managerframe']:SetScript("OnEvent", handleManagerFrame)
end
addManagerFrame(self, 'hide', num, func)
end
function lib:NewAddOn(addonName, addonTable)