-
Posted by nibs on Tue, 10 Jul 2012 20:56:00
I've hit a block. Let me explain what I have and what I'm trying to do:
I created a panel that when clicked, opens another panel with 6 Buttons on it. Five of these Buttons place World Markers, and the last Button clears them. The code for these buttons in the OnLoad in kgPanels is as follows:
self.action = CreateFrame("Button",nil,self,"SecureActionButtonTemplate") self.action:SetAllPoints() self.action:SetAttribute("type","macro") self.action:SetAttribute("macrotext","/wm #") self.action:RegisterForClicks("AnyUp") self.action.parent = self self.action:SetScript("PostClick",function(self,...) local f=self.parent:GetScript("OnClick") if f then f(self.parent,...) end end)
Where
#=(1,2,3,4,5)
Everything works exactly as intended except one thing which i'm not sure how to program. When a world Marker button is pressed, not only do i want to be able to place the world marker, but i want it to close the frame with all of the World Marker buttons on it. I've tried (without success) giving the square (or triangle, star, etc.) marker button the OnClick command:
if pressed then if kgPanels:FetchFrame("World Marker - Panel"):IsShown() then kgPanels:FetchFrame("World Marker - Panel"):Hide() else kgPanels:FetchFrame("World Marker - Panel"):Show() end elseif released then end
"World Marker - Panel" is the name of the panel that pops up with all six buttons on when the initial panel is clicked. This last little road block is the only thing between me and a complete UI. Any help would be greatly appreciated. Thanks a lot.
-
Posted by stolenlegacy on Wed, 11 Jul 2012 12:44:40
You're going to have to give the SecureActionButton a PostClick (or PreClick) script that hides all the buttons again. Be aware that all of this stuff won't work in combat though (you can't hide/show secure templates in combat).
-
Posted by nibs on Wed, 11 Jul 2012 16:14:03
Thanks for the response. Two questions though -
Is there a way to make it work in combat? I'm alright with it not working in combat but it would be great if it did.
I'm an extreme novice when it comes to programming. Can you tell me how to program a PostClick function to close the buttons?
Thanks.
-
Posted by stolenlegacy on Wed, 11 Jul 2012 21:20:54
If you want to make it work in combat, use
:SetAlpha(0)
and:SetAlpha(1)
instead of:Hide()
and:Show()
, respectively. Note, however, that this will merely make the buttons invisible, but not unclickable.As for the closing script, you can probably use the following:
local action_postClick = function(self) self:GetParent():Hide() end
And then for every button you do:
self.action:SetScript("PostClick",action_postClick)
Replace
:Hide()
with:SetAlpha(0)
if you want to make it work in combat, as I said earlier.PS: If you don't go with the SetAlpha approach, I'd highly recommend giving your main panel an OnEvent script for
PLAYER_REGEN_DISABLED
that doesself:Hide()
- that way the panels won't be stuck in a shown state when you enter combatEDIT: Looking at your code, I just noticed that you appear have one kgPanel for each of the buttons (as you use self.action, not self[("action%d"):format(i)] or equivalent for a loop). Is that correct? If so, why don't you make a single panel with all the buttons inside it? That's what I assumed writing the post above. Your
PostClick
will get a lot more complicated if you have multiple panels (add aFetchFrame
for each of the other 4 panels, then hide them, too). -
Posted by nibs on Thu, 12 Jul 2012 19:11:46
I really appreciate your responses. I'm not sure that you understand how much of a programming novice i am though.... =P 90% of the code i have posted i was able to find on the internet. So when you are talking about self.actions and loops and making all the buttons on one panel i have no idea how to do that. I decided not to go with the SetAlpha option because that wouldn't work well with the layout of my UI. If you could explain how to put all the buttons on one panel and loops and all that, I would greatly appreciate it. Again, what i have are six buttons that i have resized and moved on to one panel that opens and closes with the push of another button on my UI. So essentially that first button, which is places at the bottom of my screen, opens a total of seven panels; the world marker panel, with six world marker buttons parented to it. Thanks again for all your help. I hope i can get this fixed soon.
-
Posted by stolenlegacy on Fri, 13 Jul 2012 10:49:13
Well, your OnLoad would probably look something like this:
local btnWidth = 30 -- the width of each button local btnHeight = 30 -- the height of each button local leftBorderOffset = 15 -- from the left border of the kgPanel to the first button local btnOffset = 10 -- pixels between the buttons self.buttons = {} local hideFunc = function(s) s.parent:Hide() end for n=1,6 do local btn = CreateFrame("Button",nil,self,"SecureActionButtonTemplate") btn:SetSize(width,height) -- replace this btn:SetPoint("LEFT",leftBorderOffset + ((n-1) * (btnWidth + btnOffset)),0) btn:SetAttribute("type","macro") btn:RegisterForClicks("AnyUp") btn.parent = self btn:SetScript("PostClick",hideFunc) if n == 6 then btn:SetAttribute("macrotext","/cwm") else btn:SetAttribute("macrotext",("/wm %d"):format(n)) end self.buttons[n] = btn end self.buttons[1]:SetNormalTexture("Interface\\Icons\\CHANGETHIS") self.buttons[2]:SetNormalTexture("Interface\\Icons\\CHANGETHIS") self.buttons[3]:SetNormalTexture("Interface\\Icons\\CHANGETHIS") self.buttons[4]:SetNormalTexture("Interface\\Icons\\CHANGETHIS") self.buttons[5]:SetNormalTexture("Interface\\Icons\\CHANGETHIS") self.buttons[6]:SetNormalTexture("Interface\\Icons\\CHANGETHIS")
Panel width should be set to
(2*leftBorderOffset + 5*btnOffset + 6*btnWidth)
. In the script for the open/close button, you'd simply :Show() this one button panel. -
Posted by nibs on Fri, 13 Jul 2012 20:31:32
That about 90% worked. It created a panel but shows only one button. Also, I'm confused because at the top of the code you have written in local btnWidth = * and local btnHeight = *, and then just below that in the next block of code it says btn:SetSize(,). Only changing the btn:SetSize variables changes the size of the buttons. The four variables, "local btnWidth", "local btnHeight", "local leftBorderOffset", and "local btnOffset" don't seem to do anything. The button is right up against the left edge of the panel which is what leads me to believe that "local leftBorderOffset" isn't doing anything.
Again, thanks so much for the help. The button that does show up is functioning exactly like i want it to. I'm really close to having this done now.
Thanks a bunch.
-
Posted by stolenlegacy on Fri, 13 Jul 2012 21:47:46
I kinda typed that post up, then had to leave and only skimmed over it before posting. You're right, that should be
:SetSize(btnWidth, btnHeight)
, and there's also some other stuff I forgot to remove. I edited the post above, try it out now. Make sure you change the six calls to:SetNormalTexture()
to point to the flares' respective textures! -
Posted by nibs on Fri, 13 Jul 2012 22:22:28
Well it is now resizing as intended via code at top, however it still seems as though the buttons are stacking on top of each other and the left border of the button is still right up against the edge of the frame and not 15 pixels offset like intended. Also, something else i noticed that was acting strange, each time i /reload the icon changes but it still does the correct action when clicked, which would be /wm 1 as would be expected of the first button if it were on top of the suspected stack. Any ideas? So close! Also, i'm curious what the "%d" does.
-
Posted by stolenlegacy on Fri, 13 Jul 2012 23:21:46
Fixed above again, I forgot to provide
0
as the third argument to:SetPoint()
.PS:
("/wm %d"):format(n)
is the same asstring.format("/wm %d",n)
. The return value will be the same as"/wm "..n
, except that I believe string.format to be more efficient than..
concatenation for numbers. -
Posted by nibs on Sat, 14 Jul 2012 00:13:03
You rock! That was it. I've got a couple other things i want to mess with and then it'll be done. I want to figure how to do it on my own though. If it turns out i need help i'll post again. Thanks so much for all the help!
-
Posted by stolenlegacy on Sat, 14 Jul 2012 00:28:01
Glad I could be of help.