WowAce.com
Home
Addons
Authors
Forums
Knowledge base
Paste
Site issues
Sign in
kgPanels
Overview
Files
Tickets
Pages
Repository
Localization
Subscriptions
Donate
Curse
Sample Scripts
r4
Source
Markup:
*
===Sample scripts culled from the forums, credits to thos who posted in the kgPanel thread.=== ==Adjusting Panels based on Raid or 5 Main party== In each Panel set the OnLoad script <pre> self:RegisterEvent("PLAYER_ENTERING_WORLD") self:RegisterEvent("PARTY_MEMBERS_CHANGED") self:RegisterEvent("RAID_ROSTER_UPDATE") </pre> Then in each Panel OnEvent script: <pre><nowiki> local pmems = GetNumPartyMembers() local rmems = GetNumRaidMembers() if (pmems < 1 and rmems < 1) or (pmems > 0 and pmems < 6 and rmems < 6) then self:Hide() else self:Show() end </nowiki></pre> ==Resizing your panel on the fly== Example script to resize based on chatwindow size For OnLoad Code: <pre><nowiki>self.resized = false</nowiki></pre> For OnUpdate Code: <pre><nowiki>if not self.resized then ChatFrame1:SetScript("OnSizeChanged", function(f) self:SetWidth(f:GetWidth()) self:SetHeight(f:GetHeight()) end) self:SetWidth(ChatFrame1:GetWidth()) self:SetHeight(ChatFrame1:GetHeight()) end </nowiki></pre> What this script does: In OnlLoad we create a variable for the frame called resized, and set it to false In OnUpdate we check that 1. We havent resized yet 2. The the frame we are trying to resize to exists Once this check is passed, we set the OnSizechanged script to call back to this frame an adjust according to the other frame, please NOTE this doesnt have to be the parent or the anchor. We use OnUpdate since it is called often and kgPanels may be loaded before the frame you are trying to hook exists yet. ==Using a onClick handler== Be sure you enable mouse clicks on your panel Example: Hide/Show recount when you click the panel <pre><nowiki> if Recount.MainWindow:IsVisible() then Recount.MainWindow:Hide() else Recount.MainWindow:Show() end </nowiki></pre> ==Changing a frame based on Target== OnLoad <pre><nowiki> self:RegisterEvent("UNIT_TARGET") self:Hide() </nowiki></pre> OnEvent <pre><nowiki> if UnitExists("target") == nil then self:Hide() return end local cl = UnitClassification("target") if (cl == "elite") or (cl == "worldboss") or (cl == "rareeleite") then self:SetBackdropColor(0.1, 0.1, 0.1, 0.1) self:Show() else self:SetBackdropColor(1, 1, 1, 1) self:Show() end </nowiki></pre> ==Hooking another frame to control your own frame== Examples uses Violation Script Dependacy: Violation OnLoad <pre><nowiki> local myPanel = self if Violation0 then Violation0:SetScript("OnShow",function(frame) myPanel:Show() end) Violation0:SetScript("OnHide",function(frame) myPanel:Hide() end) end if Violation0:IsVisible() then self:Show() else self:Hide() end </nowiki></pre> ==Controlling a panel based on entering a major city== OnLoad <pre><nowiki> self:RegsiterEvent('CHAT_MSG_CHANNEL_NOTICE') </nowiki></pre> OnEvent: <pre><nowiki> if event == "CHAT_MSG_CHANNEL_NOTICE" then -- arg1 is either "YOU JOINED", "YOU LEFT" or "THROTTLED" -- arg7 is channel type (trade is type 2) -- so if arg1 == "YOU_JOINED" and arg7 == 2 then self:Show() end if arg1 == "YOU_LEFT" and arg7 == 2 then self:Hide() end end </nowiki></pre> ==Make your own spell damage display== Create a panel OnLoad <pre><nowiki> self:RegisterEvent("PLAYER_AURAS_CHANGED") </nowiki></pre> OnEvent: <pre><nowiki> dmg = GetSpellBonusDamage(6); self.text:SetText(dmg) </nowiki></pre> ==Change a frame color based on your class== OnLoad <pre><nowiki> local _, class = UnitClass("player"); if class == "WARRIOR" then self.bg:SetVertexColor(0.95, 0.23, 0.23, self.bg:GetAlpha()) elseif class == "PRIEST" then self.bg:SetVertexColor(1, 0.96, 0.98, self.bg:GetAlpha()) elseif class == "MAGE" then self.bg:SetVertexColor(0.00, 1, 1, self.bg:GetAlpha()) elseif class == "DRUID" then self.bg:SetVertexColor(1, 0.49, 0.04, self.bg:GetAlpha()) elseif class == "PALADIN" then self.bg:SetVertexColor(0.92, 0.22, 0.46, self.bg:GetAlpha()) elseif class == "HUNTER" then self.bg:SetVertexColor(0.33, 0.86, 0.00, self.bg:GetAlpha()) elseif class == "ROGUE" then self.bg:SetVertexColor(1, 0.94, 0.16, self.bg:GetAlpha()) elseif class == "SHAMAN" then self.bg:SetVertexColor(0.13, 0.42, 1, self.bg:GetAlpha()) elseif class == "WARLOCK" then self.bg:SetVertexColor(0.36, 0.18, 1, self.bg:GetAlpha()) end </nowiki></pre> ==Show a panel based on being in combat== OnLoad <pre><nowiki> self:RegisterEvent("PLAYER_REGEN_DISABLED") self:RegisterEvent("PLAYER_REGEN_ENABLED") </nowiki></pre> OnEvent <pre><nowiki> if event == "PLAYER_REGEN_ENABLED" then self:Hide() elseif event == "PLAYER_REGEN_DISABLED" then self:Show() end </nowiki></pre> ==How to get 8 value tex coords form 4 value examples== For instance you want to use the raid icons blizz provides as a texture. foirst add teh texture to your art library or add it to sharedmedia up to you. On a Mac ive found use the / slash when entering items is much easier. Now lets use the status icon as an exmaple I used onLoad to quickly get the information i wanted. <pre><nowiki> -- coords found in the FrameXML files -- left,right,top,bottom self.bg:SetTexCoord(0.5,1,0,0.5) local ULx,ULy,LLx,LLy,URx,URy,LRx,LRy = self.bg:GetTexCoord() print(" ULX: "..ULx) print(" ULy:"..ULy) print(" LLX:"..LLx) print(" LLy:"..LLy) print(" URx: "..URx) print(" URy:"..URy) print(" LRx:"..LRx) print(" LRy:"..LRy) </nowiki></pre> Now i have the 8 position coords for the combat icon which is UL(0.5,0) LL(0.5,0.5) UR(1,0) LR(1,0.5) Its a little bit of a pain, but the 8 coord setup allows for so much more flexibility as you can do transforms. Yhe 4 position method only allows you to make rectangles.
Markup Type:
*
The type of markup for this entry.
Click here for details
.
WikiCreole
BBCode
Safe HTML
Plain Text
Markdown
Textile
Curse Wiki (Deprecated)