Quantcast KG Panel Scripts - WoWInterface
Thread Tools Display Modes
03-16-13, 02:09 PM   #1
Aryae21
A Deviate Faerie Dragon
Join Date: Jan 2013
Posts: 18
Question KG Panel Scripts

Looking for 2 KG Panel scripts that seem relatively simple yet being a LUA noob cant fiqure out for myself...

- First is one to hide a panel when i am at 100% health, show it when I am not, so any damage it will show and remain to show until I am 100%... I want this however to always show in combat to. So for example its not showing on/off when healers top off my health so it hides.... then health drops to due to damage then it shows... then... well you get the picture.

- Second, is much more simple. I was sure it was hiding on a forum somewhere but Google just isn't playing nice today... A script which changes the border/texture color of a panel on mouse over. Just like a highlight. I have a few KG Panels that actually act as "buttons" for showing hiding parts of my UI.
  Reply With Quote
03-16-13, 03:51 PM   #2
Kendian
A Molten Giant
 
Kendian's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 614
I can't help with the first, but for the second, what I do, is make the panel that I want. Then make a SECOND panel that looks exactly like the first except with a diff colored border, or background, or whatever.
On that second panel, I use this:
OnLoad:
Code:
self:Show()
self:SetAlpha(0)
self:SetScript("OnEnter", function(self) self:SetAlpha(1) end)
self:SetScript("OnLeave", function(self) self:SetAlpha(0) end)
Make sure to check 'Intercept Mouse Clicks'

Hope this helps~
__________________
  Reply With Quote
03-16-13, 08:10 PM   #3
Nibelheim
local roygbi-
 
Nibelheim's Avatar
Featured
Join Date: Jan 2010
Posts: 1,600
For the borders:

On Enter / OnLeave
Code:
self:SetBackdropBorderColor(r, g, b, a)

For the health:

OnLoad
Code:
self:RegisterEvent("PLAYER_LOGIN")
self:RegisterEvent("PLAYER_REGEN_ENABLED")
self:RegisterEvent("PLAYER_REGEN_DISABLED")
self:RegisterEvent("UNIT_HEALTH")
OnEvent
Code:
local health, maxHealth = UnitHealth("player"), UnitHealthMax("player")
if ( UnitAffectingCombat("player") or (health < maxHealth) ) then
    self:SetAlpha(1)
else
    self:SetAlpha(0)
end
  Reply With Quote
03-17-13, 11:16 AM   #4
Aryae21
A Deviate Faerie Dragon
Join Date: Jan 2013
Posts: 18
It works perfectly, thank you so much for your guys' help!
  Reply With Quote
03-18-13, 04:58 PM   #5
Aryae21
A Deviate Faerie Dragon
Join Date: Jan 2013
Posts: 18
I seem to have run into a tad bit of an issue, for some reason the code for the health, while it works perfectly, shows when I log in. I have to enter combat, so it hides, then works. That is until I reload my UI or log out.

Secondly, I'd hate to make another post for this so hopefully it'll be seen here as it is related, I thought I could do it myself but after a few days I've run out of ideas. I use SLData Text for displaying some information, however I want it on one bar and all of it wont fit. I was planning on making a KGPanel "Button" so to speak to toggle between different pages, sort of like the default WoW action bar. So if it were clicked on it would switch to another set of text, clicked on again it would switch back. Ive found some scripts on other forum posts that work, but can't figure out how to hide the other "page" while the second/first is shown. Id like to accomplish this using one KGPanel if possible instead of having to make several and have to click on each one.
  Reply With Quote
03-20-13, 09:20 PM   #6
Aryae21
A Deviate Faerie Dragon
Join Date: Jan 2013
Posts: 18
Bump, does no one have an answer?
  Reply With Quote
03-21-13, 12:07 AM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
For the health, you need to check your health and set the alpha appropriately in the OnLoad script. Registering for PLAYER_LOGIN is pointless since kgPanels doesn't set up your panels until after that event has fired.

Also, I'd suggest changing RegisterEvent for UNIT_HEALTH to RegisterUnitEvent instead so you're only updating when your health changes, instead of every time any group member's (or pet's) health changes.

Try this:

Code:
-- OnLoad --------------------------------------------------
self:RegisterEvent("PLAYER_REGEN_ENABLED")
self:RegisterEvent("PLAYER_REGEN_DISABLED")
self:RegisterUnitEvent("UNIT_HEALTH", "player")

self:GetScript("OnEvent")(self, "OnLoad")

-- OnEvent -------------------------------------------------
if UnitAffectingCombat("player") or UnitHealth("player") < UnitHealthMax("player") then
    self:SetAlpha(0)
else
    self:SetAlpha(1)
end
If it isn't updating properly, that means kgPanels is running your panel's OnLoad script before it sets the OnEvent script, in which case you can work around it by simply copying and pasting the OnEvent script into the OnLoad script. It's just cleaner to not duplicate all the code.

As for your other question, I know absolutely nothing about SLDataText, but something like this should work for toggling between any two frames, or even cycling through more than two. Left click to cycle forwards, or right click to cycle backwards.

Code:
-- OnLoad --------------------------------------------------
self.frames = { TheFirstFrame, TheOtherFrame }
self.currentFrame = 1

-- OnClick -------------------------------------------------
if pressed then return end -- run OnMouseUp only, not OnMouseDown, since kgPanels is a liar
if button == "RightButton" then
    self.currentFrame = self.currentFrame - 1
    if self.currentFrame < 1 then self.currentFrame = #self.frames end
else
    self.currentFrame = self.currentFrame + 1
    if self.currentFrame > #self.frames then self.currentFrame = 1 end
end
for i, frame in ipairs(self.frames) do
    frame:SetShown(i == self.currentFrame)
end
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!

Last edited by Phanx : 03-21-13 at 04:00 PM.
  Reply With Quote
03-21-13, 07:12 AM   #8
Aryae21
A Deviate Faerie Dragon
Join Date: Jan 2013
Posts: 18
Neither of these seem to work for me.

For the first bit, it works but still shows when logging in and/or reloading a UI, other then that it performs just like Nibelheim's code.

The second doesn't work at all. All I get is a LUA error when I click the panel (Copy and pasted error below) ... SLData Text shouldn't be causing the issue, I mean I'm pretty sure it isn't. I've tried with different panels, Bartender4 Bars and even other KGPanels just to test it and see and the same result. I named the Panel "TESTMEH" simply for easily identifying it while working on well... testing it. Not sure if I am doing something wrong, either something I'm missing to replace with a frame name or if something is up with the code itself. My LUA knowledge is limited, I can replace certain, obvious, parts. But others may escape me. SLDT Frame names are simple, they always start with SLDT_ Then followed by the module name for example, the clock would be, SLDT_Clock, Mail would be SLDT_Mail.
Shouldn't be any different then any other frame, such as Bartender4 bars, other KGpanels ect, at least in my opinion.

Code:
Message: [string "TESTMEH_OnClickDown"]:10: attempt to index global 'f' (a nil value)
Time: 03/21/13 06:01:33
Count: 1
Stack: Interface\AddOns\Auctionator\AtrErrorInspector.lua:55: in function <Interface\AddOns\Auctionator\AtrErrorInspector.lua:51>
[C]: ?
[string "TESTMEH_OnClickDown"]:10: in function <[string "TESTMEH_OnClickDown"]:1>

Locals: inAtrErrorHandler = true
origErrorHandler = <function> defined *:OnLoad:1
zc = <table> {
 msg_red = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:608
 IsEnglishLocale = <function> defined @Interface\AddOns\Auctionator\AuctionatorLocalize.lua:52
 msg_badErr = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:644
 tallyAdd = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:1121
 msg = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:737
 GetArrayElemOrFirst = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:150
 NumToBool = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:562
 msg_color = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:614
 ParseBattlePetLink = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:429
 ShowHide = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:36
 StringStartsWith = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:930
 printmem = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:1031
 round = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:602
 StringContains = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:892
 CopyDeep = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:1003
 CheckDeferredCall = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:332
 priceToMoneyString = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:841
 tallyPrint = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:1133
 TrimBrackets = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:974
 GetArrayElemOrNil = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:165
 BoolToNum = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:552
 If = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:99
 periodic = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:355
 Min = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:69
 msg_pink = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:609
 SetTextIf = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:47
 TrimQuotes = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:954
 msg_str = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:627
 ItemNamefromLink = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:471
 enc64 = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:215
 Val = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:58
 IsBattlePetLink = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:421
 StringEndsWith = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:910
 printableLink = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:1018
 PrintTable = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:385
 StringSame = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:874
 priceToString = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:805
 PullItemIntoMemory = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:520
 val2gsc = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:787
 PrintKeysSorted = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:110
 msg_ex = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:746
 Negate = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:572
 ClearTable = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:994
 BoolToString = <function> defined @Interface\AddOns\Auctionator\zcUtils.lua:542
 ItemIDfromLink = <function> defined @Interface\AddOns\Au
  Reply With Quote
03-21-13, 08:52 AM   #9
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
There's an error in Phanx's onclick code:
Code:
if down then return end -- run OnMouseUp only, not OnMouseDown, since kgPanels is a liar
if button == "RightButton" then
    self.currentFrame = self.currentFrame - 1
    if self.currentFrame < 1 then self.currentFrame = #self.frames end
else
    self.currentFrame = self.currentFrame + 1
    if self.currentFrame > #self.frames then self.currentFrame = 1 end
end
for i, frame in ipairs(self.frames) do
    frame:SetShown(i == self.currentFrame)
end
  Reply With Quote
03-21-13, 10:42 AM   #10
Aryae21
A Deviate Faerie Dragon
Join Date: Jan 2013
Posts: 18
Now its working, properly thank you! But one more thing, I have to hold down the mouse button for it to show the second frame. Is it pretty much stuck like that or is it possible to have a 1 click, permanently show until I click it again to switch back?
  Reply With Quote
03-21-13, 01:42 PM   #11
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
That's what it should do already. Can you be more specific? Is it switching to the second frame only while you have the mouse button pressed, and then switching back to the first frame if you release the button? Is it switching to the second frame and never switching back to the first frame?
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
  Reply With Quote
03-21-13, 03:40 PM   #12
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,722
the kgPanels variable for mousedown is pressed, not down.

http://www.wowace.com/addons/kg-panels/
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
03-21-13, 03:59 PM   #13
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
There we go. Change "down" to "pressed", and I've edited my previous post to reflect that change.
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
  Reply With Quote
03-21-13, 05:17 PM   #14
Aryae21
A Deviate Faerie Dragon
Join Date: Jan 2013
Posts: 18
Bah, seems I've run into another issue. Every time I log in, reload ui, or leave combat (I have SLDT to disappear during combat so a cool down bar can appear there.) They all reappear at once, which overlaps and makes a unsightly text mess. Running the script fixes it... But I don't want to have to click 12 times to reset it. Any ideas?

Last edited by Aryae21 : 03-22-13 at 08:23 AM.
  Reply With Quote
03-22-13, 12:41 PM   #15
Kendian
A Molten Giant
 
Kendian's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 614
Try adding this to:
OnLoad:

Code:
 self:RegisterEvent("PLAYER_ENTERING_WORLD")
__________________
  Reply With Quote
03-26-13, 11:20 AM   #16
Aryae21
A Deviate Faerie Dragon
Join Date: Jan 2013
Posts: 18
Sorry for the late reply! Real life likes to interfere with my projects heh. This script works but it only seems to work for some of the panels some of the time. For example, I have 4 panels that run this script, each I can click on to "page" between different SLDT Modules. They all disappear during combat, and reappear when leaving combat. (Reason for this is a minimalistic design, I tend to favor hiding things when OOC/IC etc. To keep things on a need to know basis and keep it minimalist without sacrificing the information I need and/or want.) However when I leave combat, the paging all resets, and they all show at once. Making a jumble of text, I have to click each one to reset it to where it should be. This also happens on re-load UI and log in. This script above works... but it seems random. Sometimes all but one will work, sometimes non of them work. Other times only one will work etc. Is there anyway to make all of them work... all of the time? Or do I need to reduce it to a single panel?

Last edited by Aryae21 : 03-26-13 at 11:29 AM.
  Reply With Quote
03-26-13, 10:59 PM   #17
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If you have some other code (eg. in SLDataText) calling :Hide() and :Show() on the frames, that's obviously going to conflict with your kgPanels script. You'd be better off setting SLDT to never Hide/Show the frames, and let your kgPanels script be the only thing hiding and showing those frames.

To the same kgPanel you're using for the OnClick script, add, in the OnLoad function:

Code:
self:RegisterEvent("PLAYER_REGEN_DISABLED")
self:RegisterEvent("PLAYER_REGEN_ENABLED")
Then add an OnEvent script:
Code:
if UnitAffectingCombat("player") then
    for i, frame in ipairs(self.frames) do
        frame:Hide()
    end
else
    for i, frame in ipairs(self.frames) do
        frame:SetShown(i == self.currentFrame)
    end
end
[/code]
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
  Reply With Quote
03-27-13, 08:29 AM   #18
Aryae21
A Deviate Faerie Dragon
Join Date: Jan 2013
Posts: 18
It works! Thank you so much for all the help!


In case anyone stumbles upon this post later on for their own needs this is the end result of the KGPanels code that's working for me...

For any other frames other then SLDT simply change...

{ SLDT_Mail, SLDT_Coords, SLDT_Clock }

...to whatever frame name of the desire frame. Type /fstack in game and mouse over to get the names of frames.

On Load:
Code:
self.frames = { SLDT_Mail, SLDT_Coords, SLDT_Clock }
self.currentFrame = 1

self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("PLAYER_REGEN_DISABLED")
self:RegisterEvent("PLAYER_REGEN_ENABLED")
On Event:
Code:
if UnitAffectingCombat("player") then
    for i, frame in ipairs(self.frames) do
        frame:Hide()
    end
else
    for i, frame in ipairs(self.frames) do
        frame:SetShown(i == self.currentFrame)
    end
end
On Click:
Code:
if pressed then return end -- run OnMouseUp only, not OnMouseDown, since kgPanels is a liar
if button == "RightButton" then
    self.currentFrame = self.currentFrame - 1
    if self.currentFrame < 1 then self.currentFrame = #self.frames end
else
    self.currentFrame = self.currentFrame + 1
    if self.currentFrame > #self.frames then self.currentFrame = 1 end
end
for i, frame in ipairs(self.frames) do
    frame:SetShown(i == self.currentFrame)
end

Last edited by Aryae21 : 03-27-13 at 02:20 PM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » KG Panel Scripts

Thread Tools
Display Modes

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