Thread Tools Display Modes
02-09-14, 01:40 PM   #1
another
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Aug 2010
Posts: 11
Show/hide secure frame on keybind?

If I want to implement such stuff as show/hide frames of addon for example on Button3 keybind click, like via Binding.xml
Code:
<Bindings>
	<Binding name="TEB_SHOWHIDE" default="CTRL-BUTTON3">
		SomeShowHideHandler()
	</Binding>
</Bindings>
but I have several frames with buttons shown by RegisterStateDriver - what should I do? Can I use secure functions like RegisterStateDriver/UnregisterStateDriver in SomeShowHideHandler (is this like secure snippet)? Get/SetAttribute? Access to frames through FrameRef? What should I type as state string - "show" or "hide"? Or maybe something else to show/hide without touching state driver?

Thanks.
  Reply With Quote
02-09-14, 04:58 PM   #2
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
If you just want to toggle a frame, do this:
Code:
frame:SetShown(not frame:IsShown())
otherwise I don't understand.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
02-10-14, 02:01 AM   #3
elcius
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Sep 2011
Posts: 75
Lua Code:
  1. CreateFrame("BUTTON","MyToggler",UIParent,"SecureHandlerClickTemplate");
  2. MyToggler:SetAttribute("_onclick",[[
  3.     local frame = self:GetFrameRef("MyToken");
  4.     if frame:IsShown() then
  5.         frame:Hide()
  6.     else
  7.         frame:Show();
  8.     end
  9. ]])
  10. MyToggler:SetFrameRef("MyToken",TargetFrame);
/click MyToggler
SetBinding("x","CLICK MyToggler:LeftButton");
  Reply With Quote
02-10-14, 01:33 PM   #4
another
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Aug 2010
Posts: 11
Originally Posted by Lombra View Post
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
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Show/hide secure frame on keybind?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off