Originally Posted by Lombra
If you just want to toggle a frame, do this:
Code:
frame:SetShown(not frame:IsShown())
otherwise I don't understand.
|
Since TBC things are much more complicated for secure frames like buttons able to cast spells (see "Iriel's Field Guide to Secure Handlers"). You can't Show/Hide such frames while in combat in insecure way.
Thanks to elcius, final code slightly more complicated but it works. In case someone find it useful (as is):
somewhere in Init before creating frames
Code:
CreateFrame("BUTTON", "TEB_Toggler", UIParent, "SecureHandlerClickTemplate")
TEB_Toggler:SetAttribute("_onclick", TEB_ToggleSnippet)
TEB_Toggler:SetAttribute("toggle_enabled", false)
SetBinding("CTRL-BUTTON3", "CLICK TEB_Toggler:LeftButton")
snippet
Code:
local TEB_ToggleSnippet = [=[
--print("TEB_ToggleSnippet")
local count = self:GetAttribute("FramesCount")
--print("FramesCount", count)
local toggle_enabled = self:GetAttribute("toggle_enabled")
toggle_enabled = not(toggle_enabled)
self:SetAttribute("toggle_enabled", toggle_enabled)
if count then
for i = 1, count do
local bf = self:GetFrameRef("TEB_ButtonFrame"..i)
--print("bf", bf)
if bf then
--print(bf:GetName())
if toggle_enabled then
--print("Hide")
UnregisterStateDriver(bf, "visibility")
bf:Hide()
else
--print("Show")
bf:Show()
local DriverString = bf:GetAttribute("StateDriverString")
if DriverString then
RegisterStateDriver(bf, "visibility", DriverString)
end
end
end
end
end
]=]
on creating frame affected by all that stuff
Code:
function TEB_ButtonFrame_New(id, parent)
local bf = _G[parent:GetName().."ButtonFrame"..id]
if not(bf) then
bf = CreateFrame("Frame", parent:GetName().."ButtonFrame"..id, UIParent, "TinyExtraBarsButtonFrameTemplate")
local count = TEB_Toggler:GetAttribute("FramesCount")
if not(count) then
count = 1
else
count = count + 1
end
TEB_Toggler:SetAttribute("FramesCount", count)
TEB_Toggler:SetFrameRef("TEB_ButtonFrame"..count, bf)
end
...
on updating visibility driver
Code:
...
local customText = self.visibility["Custom"]
if (customText ~= "") then
RegisterStateDriver(self, "visibility", text..customText)
self:SetAttribute("StateDriverString", text..customText)
else
if (text ~= "") then
RegisterStateDriver(self, "visibility", text.."show")
self:SetAttribute("StateDriverString", text.."show")
else
UnregisterStateDriver(self, "visibility")
self:SetAttribute("StateDriverString", "")
end
end