Thread Tools Display Modes
07-29-13, 08:04 PM   #1
shamby
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Apr 2010
Posts: 17
Want button to display both states of spell.

Tired of searching and time to ask the experts. Trap Launcher has 2 icons - one for activated and one for not activated. While the addon's created button works, it only displays the Launcher's original button when activated or not. I've looked and cannot find if there's a different template or another way to have it indicate that the Launcher is activated. I'm guessing that someone here can hook me up with an answer or a link. Thank ya.
  Reply With Quote
07-30-13, 03:53 AM   #2
Malsomnus
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Apr 2013
Posts: 203
I'm not an expert, but I think the experts would want more info
What add-on is it? Is it something you wrote, something you downloaded? If it's yours, how did you assign the icon to the button? If you just gave it the path to the Trap Launcher icon and didn't replace it for the second icon, well, it kinda answers the question, although I have no idea whether manually changing icons is the sort of thing you can do on secure buttons... anyway, more info
__________________
SanityCheck - If you've ever said the words "Sorry, I forgot" then you need this add-on.

Remember, every time you post a comment on an add-on, a kitten gets its wings!
  Reply With Quote
07-30-13, 11:46 AM   #3
shamby
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Apr 2010
Posts: 17
My bad-here's more...

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)
  Reply With Quote
07-30-13, 12:33 PM   #4
Malsomnus
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Apr 2013
Posts: 203
Well, that seems to simply set the texture to a specific icon. It wouldn't change its texture automatically, because... well, why would it?

I haven't worked much with secure buttons, so I don't know what's involved in changing their texture... if nobody more qualified picks up the glove, I suppose I could try to take a look.
__________________
SanityCheck - If you've ever said the words "Sorry, I forgot" then you need this add-on.

Remember, every time you post a comment on an add-on, a kitten gets its wings!
  Reply With Quote
07-30-13, 12:51 PM   #5
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
I'm about 99% sure the interface uses GetActionTexture(slot) to figure out which texture to display for the action button.

If you want to simulate the same effect without using slots you could check if the trap launcher aura is currently on the player and set the texture accordingly.

I'm sure there's probably a better way to do that, though.
  Reply With Quote
07-30-13, 08:11 PM   #6
shamby
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Apr 2010
Posts: 17
Pretty much does what I wanted now.

Thanks for the suggestions. Went the aura route and it works fine on login. Need to see why the launcher button wants to hide after a reload. It does show up when you click where it should be. I appreciate your help. Again, thanks to all.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Want button to display both states of spell.

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