First, thanks to Mal. I appreciate your gentleness-
. I thought that maybe my question was a general issue concerning a button that changed looks when activated as opposed to one that does not.
This addon was born on WI's forum and if I can remember how I'll do the code thing. I am wanting the Trap Launcher button to reflect if it is activated or not as does Blizzard's. This is what I'm looking at now:
Code:
-- Disable the addon if the player is not a hunter:
if select(2, UnitClass("player")) ~= "HUNTER" then
return DisableAddOn("EZTrap")
end
------------------------------------------------------------------------
-- Create the base frame:
local EZTrap = CreateFrame("Frame", "EZTrap", UIParent)
EZTrap:SetPoint("CENTER", -1, -144)
EZTrap:SetSize(140, 140)
-- Make it draggable and resizable:
EZTrap:SetMovable(true)
EZTrap:SetResizable(true)
EZTrap:EnableMouse(true)
EZTrap:SetMaxResize(140,140)
EZTrap:SetMinResize(70,70)
EZTrap:RegisterForDrag("RightButton", "LeftButton")
EZTrap:SetScript("OnMouseDown", function(self, button)
local shiftDown = IsShiftKeyDown();
if button == "RightButton" and not self.isMoving then
self:StartMoving();
self.isMoving = true;
elseif ( IsShiftKeyDown() ) and (button == "LeftButton" and not self.isSizing) then
self:StartSizing();
self.isSizing = true
end
end)
EZTrap:SetScript("OnMouseUp", function(self, button)
if button == "RightButton" and self.isMoving then
self:StopMovingOrSizing();
self.isMoving = false;
elseif (button == "LeftButton" and self.isSizing) then
self:StopMovingOrSizing();
self.isSizing = false
end
end)
EZTrap:SetScript("OnHide", function(self)
if ( self.isMoving ) or (self.isSizing) then
self:StopMovingOrSizing();
self.isMoving = false;
self.isSizing = false;
end
end)
-- Add the background:
EZTrap:SetBackdrop({
bgFile = [[Interface\Icons\ability_ensnare]], tile = false, tileSize = 0,
edgeFile = [[Interface\DialogFrame\UI-DialogBox-Border]], edgeSize = 32,
insets = { left = 16, right = 17, top = 17, bottom = 16,}
})
EZTrap:SetBackdropColor(0,0,0,0.3)
------------------------------------------------------------------------
------------------------------------------------------------------------
-- Add a button for Trap Launcher:
local f = CreateFrame("Button", "Launcher", EZTrap, "SecureActionButtonTemplate")
f:ClearAllPoints()
f:SetPoint("CENTER",0,0)
f:SetSize(60, 20)
f:SetAttribute("type", "spell")
f:SetAttribute("spell", "Trap Launcher")
f:SetNormalTexture([[Interface\Icons\ability_hunter_traplauncher]])
------------------------------------------------------------------------
-- Set up a button factory:
local CreateTrapButton
do
-- Share the same event handler function between buttons
-- instead of creating duplicate functions:
local function TrapButton_OnEvent(self, event, ...)
local start, duration = GetSpellCooldown(self.spellID)
if duration > 0 then
self.cooldown:Show()
self.cooldown:SetCooldown(start, duration)
end
end
function CreateTrapButton(spellID)
-- Get the name and icon for the specified spell:
local spellName, _, spellIcon = GetSpellInfo(spellID)
if not spellName then
-- That's not a valid spell ID!
return
end
-- Create the button:
local button = CreateFrame("Button", "$parent"..gsub(spellName, "[^%a]", ""), EZTrap, "SecureActionButtonTemplate")
-- Set the correct trap spell properties:
button:SetAttribute("type", "spell")
button:SetAttribute("spell", spellName)
button:SetNormalTexture(spellIcon)
button.spellID = spellID
-- Add a cooldown to the button:
local cd = CreateFrame("Cooldown", "$parentCooldown", button, "CooldownFrameTemplate")
button.cooldown = cd
cd:SetAllPoints(true)
cd:Hide()
-- Update the cooldown when needed:
button:RegisterEvent("SPELL_UPDATE_COOLDOWN")
button:SetScript("OnEvent", TrapButton_OnEvent)
-- Hand the button back to the calling code:
return button
end
end
------------------------------------------------------------------------
-- Add a button for Freezing Trap:
local Freezing = CreateTrapButton(1499)
Freezing:ClearAllPoints()
Freezing:SetPoint("TOPLEFT", EZTrap, "TOPLEFT", 10, -10)
Freezing:SetPoint("TOPRIGHT", EZTrap, "CENTER", 0, 0)
Freezing:SetPoint("BOTTOMLEFT", EZTrap, "CENTER", 0, 6)
Freezing:SetPoint("BOTTOMRIGHT", EZTrap, "CENTER", 0, 6)
Freezing:SetSize(20, 20)
------------------------------------------------------------------------
-- Add a button for Explosive Trap:
local Explosive = CreateTrapButton(13813)
Explosive:ClearAllPoints()
Explosive:SetPoint("TOPLEFT", Freezing, "BOTTOMLEFT", 3, -15)
Explosive:SetPoint("BOTTOMLEFT", EZTrap, "BOTTOMLEFT", 10, 10)
Explosive:SetPoint("TOPRIGHT", Freezing, "BOTTOMRIGHT", 3, 0)
Explosive:SetSize(20, 20)
------------------------------------------------------------------------
-- Add a button for Ice Trap:
local Ice = CreateTrapButton(13809)
Ice:ClearAllPoints()
Ice:SetPoint("TOPRIGHT", EZTrap, "TOPRIGHT", -10, 0)
Ice:SetPoint("TOPLEFT", Freezing, "TOPRIGHT", 0, 0)
Ice:SetPoint("BOTTOMLEFT", Freezing, "BOTTOMLEFT", 0, 0)
Ice:SetSize(20, 20)
------------------------------------------------------------------------
-- Add a button for SnakeTrap:
local Snake = CreateTrapButton(34600)
Snake:ClearAllPoints()
Snake:SetPoint("BOTTOMRIGHT", EZTrap, "BOTTOMRIGHT", 0, 0)
Snake:SetPoint("BOTTOMLEFT", Explosive, "BOTTOMRIGHT", 0, 0)
Snake:SetPoint("TOPLEFT", Explosive, "TOPRIGHT", 0, -1)
Snake:SetPoint("TOPRIGHT", Ice, "BOTTOMRIGHT", 0, -1)
Snake:SetSize(20, 20)