Quantcast Autocast animated overlay trouble - WoWInterface
Thread Tools Display Modes
09-04-14, 12:04 AM   #1
kez717
A Murloc Raider
Join Date: Oct 2008
Posts: 5
Autocast animated overlay trouble

I am in need of a way to use or mimic the default autocast animated overlay (like on pet buttons). My code is in only lua, no xml. I don't have anything related to autocast in my code at the moment, every attempt resulted in various errors (over 40 attempts (with lfg "eye", autocast shine, autocast sparkles, both the bits to get them to work on my buttons and the animation parts themselves modified to directly take a button)so a lot of errors) and I ended up removing it so get on with the rest of the addon. Either a script that copies the look of the animation that I can plug my buttons into (and how to use is) or info on what I data I need (and what format to put it in) so that my buttons will play nice with blizzards default animation would be appreciated. I've puzzled out the rest of the addon I'm working on (new to lua, only started about 2-3 weeks ago), but this just doesn't seem to want to work.
  Reply With Quote
09-04-14, 01:09 AM   #2
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 329
Originally Posted by kez717 View Post
I am in need of a way to use or mimic the default autocast animated overlay (like on pet buttons). My code is in only lua, no xml. I don't have anything related to autocast in my code at the moment, every attempt resulted in various errors (over 40 attempts (with lfg "eye", autocast shine, autocast sparkles, both the bits to get them to work on my buttons and the animation parts themselves modified to directly take a button)so a lot of errors) and I ended up removing it so get on with the rest of the addon. Either a script that copies the look of the animation that I can plug my buttons into (and how to use is) or info on what I data I need (and what format to put it in) so that my buttons will play nice with blizzards default animation would be appreciated. I've puzzled out the rest of the addon I'm working on (new to lua, only started about 2-3 weeks ago), but this just doesn't seem to want to work.
Take a look at InlineAura. I'm sure there might be some useful tidbits in there for you.
  Reply With Quote
09-04-14, 03:36 AM   #3
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Hm, autocast? The "ants"?
  Reply With Quote
09-04-14, 10:00 AM   #4
kez717
A Murloc Raider
Join Date: Oct 2008
Posts: 5
I'll take a look at inline aura. And yes, the "ants" is what I'm trying to get working.
  Reply With Quote
09-04-14, 10:22 AM   #5
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
I've implemented the 'ants' animation and the glow via single textures in http://www.wowinterface.com/download...4-BABBars.html as using an animation was not possible.

Don't know if it helps, but it looks like this: (the textures are attached to this post)

Lua Code:
  1. --adding textures for ants/glow
  2. local tGlow = _G[Button:GetName().."Glow"] or Button:CreateTexture(Button:GetName().."Glow","OVERLAY")
  3. tGlow:SetTexture("Interface\\AddOns\\BAB\\textures\\IconAlertGlow.tga")
  4. tGlow:ClearAllPoints()
  5. tGlow:SetPoint("TOPLEFT", Button, "TOPLEFT")
  6. tGlow:SetPoint("BOTTOMRIGHT", Button, "BOTTOMRIGHT")
  7. tGlow:SetDrawLayer("OVERLAY", 2)
  8. tGlow:Hide()
  9.  
  10. local tAnts = _G[Button:GetName().."Ants"] or Button:CreateTexture(Button:GetName().."Ants","OVERLAY")
  11. tAnts:SetTexture("Interface\\AddOns\\BAB\\textures\\IconAlertAnts1.tga")
  12. tAnts:ClearAllPoints()
  13. tAnts:SetPoint("TOPLEFT", Button, "TOPLEFT")
  14. tAnts:SetPoint("BOTTOMRIGHT", Button, "BOTTOMRIGHT")
  15. tAnts:SetDrawLayer("OVERLAY", 2)
  16. tAnts:Hide()
  17.  
  18.  
  19. --updating the ants if _G[Button:GetName().."Ants"] is visible
  20. do
  21.     local f = CreateFrame("Frame", "BABMain", UIParent)
  22.     f:SetScript("OnUpdate", function(...)
  23.       for btni, btnv in pairs(Buttons) do
  24.         if _G[btnv:GetName().."Ants"] then
  25.             local tAnts = _G[btnv:GetName().."Ants"]
  26.             if tAnts:IsVisible() then
  27.                 if not tAnts.Step then
  28.                     tAnts.Step = 1
  29.                     tAnts.StepTime = GetTime()
  30.                 end
  31.                 if GetTime() - tAnts.StepTime > 0.025 then
  32.                      tAnts.Step = tAnts.Step + 1
  33.                      if tAnts.Step > 22 then
  34.                          tAnts.Step = 1
  35.                      end
  36.                      tAnts:SetTexture("Interface\\AddOns\\BAB\\textures\\IconAlertAnts"..tAnts.Step..".tga")
  37.                      tAnts.StepTime = GetTime()
  38.                 end
  39.             end
  40.         end            
  41.       end
  42.     end)
  43. end
Attached Files
File Type: zip IconAlertAnts.zip (103.7 KB, 87 views)

Last edited by Duugu : 09-04-14 at 10:25 AM.
  Reply With Quote
09-04-14, 11:48 AM   #6
kez717
A Murloc Raider
Join Date: Oct 2008
Posts: 5
Thanks Duugu, one question though. How do I get it to work? I tried adding it, but its giving me the one of the same errors (so far, if I keep pushing I could probably get a lot more errors from it) as the blizz animation does "bad argument #1 to 'pairs" (table expected, got nil)" for this line "for btni, btnv in pairs(buttons) do". I don't have a clue what I'm missing except that apparently the code is wanting data I'm not giving it. For some reason I can't even get generalized code to work and have to hard code everything for every button, so a simple 9 button bar is almost 2k lines long and fairly messy.
  Reply With Quote
09-04-14, 12:13 PM   #7
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
You need to provide the right data to the code.

For the first two snippets the variable 'Button' has to be a reference to the button frame object you would like to act on. Like
Lua Code:
  1. local Button = _G["ActionButton1"] --just an example ... use your actual button frame(s)
before them.

The last snippet expects a table 'Buttons' containing references to all of your button frames. Like
Lua Code:
  1. local Buttons =
  2. {
  3. _G["ActionButton1"], _G["ActionButton2"], _G["ActionButton3"] -- again, just an example
  4. }

Please keep in mind, that these code parts are generalized quick and dirty copies from of my addons code. Do not expect them to work out of the box.

If you need help with your code, then the best way would be to show what you've done so far.

Last edited by Duugu : 09-04-14 at 12:18 PM.
  Reply With Quote
09-04-14, 12:44 PM   #8
kez717
A Murloc Raider
Join Date: Oct 2008
Posts: 5
Not getting errors anymore, but also not getting the animation either.

Here's the code for this piece of my addon, there is another file with a lookup table for pet spell names, texture, spell IDs, and such that I can post if really needed. Like I said, it's really long and messy though.

Code:
---------------------
-- START OF CONFIG --
---------------------
--toggles for turning on and off autocast
local MACRO_NAME_BASIC_TOGGLE = ""
local MACRO_NAME_GROWL_TOGGLE = ""
local MACRO_NAME_COWER_TOGGLE = ""
local MACRO_NAME_SPECIAL_TOGGLE = ""
local MACRO_NAME_EXOTIC_TOGGLE = ""
local MACRO_NAME_BONUS_TOGGLE = ""
local MACRO_NAME_SPEC1_TOGGLE = ""
local MACRO_NAME_SPEC2_TOGGLE = ""
local MACRO_NAME_SPEC3_TOGGLE = ""

local _, class = UnitClass("player")
if class ~= "HUNTER" then return end
---------------------
--  END OF CONFIG  --
--------------------- 

---------------------
--  start variables  --
---------------------

	--general
local pet_name
local pet_family
local pet_spec

local level
local petBuff
local macrotext = ""

---bar settings
local BarsHoriz = true
local BarsLocked = false

local ControlBar_Enabled = true
local ControlBar_PosX = 0
local ControlBar_PosY = 40
local ControlBar_Horiz = true
local ControlBar_ButtonX = 3
local ControlBar_ButtonY = 0
local ControlBar_ButtonPrevious = "LEFT"
local ControlBar_ButtonSide = "RIGHT"

--control settings
local pet_basic_attack
local pet_basic_name = nil
local pet_basic_icon = {  bgFile = "",    edgeFile = "",  tile = false,  tileSize = 30,}
local pet_basic_cooldown
local pet_basic_autoAllowed = nil
local pet_basic_autoEnabled = nil
local pet_basic_spellbookID = nil
local pet_basic_spellID

local pet_growl_attack
local pet_growl_name = nil
local pet_growl_icon = {  bgFile = "",    edgeFile = "",  tile = false,  tileSize = 30,}
local pet_growl_cooldown
local pet_growl_autoAllowed = nil
local pet_growl_autoEnabled = nil
local pet_growl_spellbookID = nil
local pet_growl_spellID

local pet_cower_attack
local pet_cower_name = nil
local pet_cower_icon = {  bgFile = "",    edgeFile = "",  tile = false,  tileSize = 30,}
local pet_cower_cooldown
local pet_cower_autoAllowed = nil
local pet_cower_autoEnabled = nil
local pet_cower_spellbookID = nil
local pet_cower_spellID

local pet_special_attack
local pet_special_name = nil
local pet_special_icon = {  bgFile = "",    edgeFile = "",  tile = false,  tileSize = 30,}
local pet_special_cooldown
local pet_special_autoAllowed = nil
local pet_special_autoEnabled = nil
local pet_special_spellbookID = nil
local pet_special_spellID

local pet_exotic_attack
local pet_exotic_name = nil
local pet_exotic_icon = {  bgFile = "",    edgeFile = "",  tile = false,  tileSize = 30,}
local pet_exotic_cooldown
local pet_exotic_autoAllowed = nil
local pet_exotic_autoEnabled = nil
local pet_exotic_spellbookID = nil
local pet_exotic_spellID

local pet_bonus_attack
local pet_bonus_name = nil
local pet_bonus_icon = {  bgFile = "",    edgeFile = "",  tile = false,  tileSize = 30,}
local pet_bonus_cooldown
local pet_bonus_autoAllowed = nil
local pet_bonus_autoEnabled = nil
local pet_bonus_spellbookID = nil
local pet_bonus_spellID

local pet_spec_1_attack
local pet_spec_1_name = nil
local pet_spec_1_icon = {  bgFile = "",    edgeFile = "",  tile = false,  tileSize = 30,}
local pet_spec_1_cooldown
local pet_spec_1_autoAllowed = nil
local pet_spec_1_autoEnabled = nil
local pet_spec_1_spellbookID = nil
local pet_spec_1_spellID

local pet_spec_2_attack
local pet_spec_2_name = nil
local pet_spec_2_icon = {  bgFile = "",    edgeFile = "",  tile = false,  tileSize = 30,}
local pet_spec_2_cooldown
local pet_spec_2_autoAllowed = nil
local pet_spec_2_autoEnabled = nil
local pet_spec_2_spellbookID = nil
local pet_spec_2_spellID

local pet_spec_3_attack
local pet_spec_3_name = nil
local pet_spec_3_icon = {  bgFile = "",    edgeFile = "",  tile = false,  tileSize = 30,}
local pet_spec_3_cooldown
local pet_spec_3_autoAllowed = nil
local pet_spec_3_autoEnabled = nil
local pet_spec_3_spellbookID = nil
local pet_spec_3_spellID	

	--textures and icon variables

local petAutoCastableTexture = "Interface\\Buttons\\UI-AutoCastableOverlay"
local petAutoCastShineTexture = "interface\\SpellActivationOverlay\\IconAlertAnts"

local buttonHighlight = "Interface\\Buttons\\ButtonHilight-Square"
local buttonPushed = "Interface\\Buttons\\ui-quickslot-depress"

local barMoveable = "Interface\\common\\indicator-green"

--local iconProwlUsed = "Interface\\Icons\\Ability_Vanish"

---------------------
--  start table reference  --
---------------------
local addon, ns = ...

--attacks
local PET_ABILITIES = ns.PET_ABILITIES
local PET_BASIC = ns.PET_BASIC_LIST
local PET_SPECIAL = ns.PET_SPECIAL_LIST
local PET_EXOTIC = ns.PET_EXOTIC_LIST
local PET_BONUS = ns.PET_BONUS_LIST
local PET_ABILITY = ns.PET_ABILITY_LIST
local PET_SPEC1 = ns.PET_SPEC1_LIST
local PET_SPEC2 = ns.PET_SPEC2_LIST
local PET_SPEC3 = ns.PET_SPEC3_LIST

--attacks name only --spellbook id lookup
local PET_BASIC_NAME = ns.PET_BASIC_NAME
local PET_SPECIAL_NAME = ns.PET_SPECIAL_NAME
local PET_EXOTIC_NAME = ns.PET_EXOTIC_NAME
local PET_BONUS_NAME = ns.PET_BONUS_NAME
local PET_ABILITY_NAME = ns.PET_ABILITY_NAME
local PET_SPEC1_NAME = ns.PET_SPEC1_NAME
local PET_SPEC2_NAME = ns.PET_SPEC2_NAME
local PET_SPEC3_NAME = ns.PET_SPEC3_NAME

--cooldown lengths
local PET_ABILITIES_CD = ns.PET_CD_ABILITIES
local PET_BASIC_CD = ns.PET_BASIC_CD_LIST
local PET_SPECIAL_CD = ns.PET_SPECIAL_CD_LIST
local PET_EXOTIC_CD = ns.PET_EXOTIC_CD_LIST
local PET_BONUS_CD = ns.PET_BONUS_CD_LIST
local PET_ABILITY_CD = ns.PET_ABILITY_CD_LIST
local PET_SPEC1_CD = ns.PET_SPEC1_CD_LIST
local PET_SPEC2_CD = ns.PET_SPEC2_CD_LIST
local PET_SPEC3_CD = ns.PET_SPEC3_CD_LIST

--icons
local PET_ABILITIESICON = ns.PET_ABILITIESICON
local PET_BASICICON = ns.PET_BASIC_LISTICON
local PET_SPECIALICON = ns.PET_SPECIAL_LISTICON
local PET_EXOTICICON = ns.PET_EXOTIC_LISTICON
local PET_BONUSICON = ns.PET_BONUS_LISTICON
local PET_ABILITYICON = ns.PET_ABILITY_LISTICON
local PET_SPEC1ICON = ns.PET_SPEC1_LISTICON
local PET_SPEC2ICON = ns.PET_SPEC2_LISTICON
local PET_SPEC3ICON = ns.PET_SPEC3_LISTICON

--spellIDs
local PET_ABILITIES_SPELLID = ns.PET_ABILITIES_SPELLID
local PET_BASIC_SPELLID = ns.PET_BASIC_SPELLID
local PET_SPECIAL_SPELLID = ns.PET_SPECIAL_SPELLID
local PET_EXOTIC_SPELLID = ns.PET_EXOTIC_SPELLID
local PET_BONUS_SPELLID = ns.PET_BONUS_SPELLID
local PET_ABILITY_SPELLID = ns.PET_ABILITY_SPELLID
local PET_SPEC1_SPELLID = ns.PET_SPEC1_SPELLID
local PET_SPEC2_SPELLID = ns.PET_SPEC2_SPELLID
local PET_SPEC3_SPELLID = ns.PET_SPEC3_SPELLID

---------------------
--  start buttons and bar creation  --
---------------------
local button = CreateFrame("Button", "PetSpecialAttackButton", UIParent, "SecureActionButtonTemplate")
local myVariables = CreateFrame("Button", "MyHiddenVariables", UIParent, "SecureActionButtonTemplate")


--control bar
local NewControlBarMover = CreateFrame("Button", "PetAttackBar", UIParent, "SecureActionButtonTemplate")
local NewControlBar = CreateFrame("Button", "PetAttackBar", UIParent, "SecureActionButtonTemplate")

local buttonGrowl = CreateFrame("Button", "PetbuttonGrowl", NewControlBar, "SecureActionButtonTemplate AutoCastShineTemplate")
local buttonBasic = CreateFrame("Button", "PetbuttonBasic", NewControlBar, "SecureActionButtonTemplate")
local buttonCower = CreateFrame("Button", "PetbuttonCower", NewControlBar, "SecureActionButtonTemplate")
local buttonSpecial = CreateFrame("Button", "PetbuttonSpecial", NewControlBar, "SecureActionButtonTemplate")
local buttonExotic = CreateFrame("Button", "PetbuttonExotic", NewControlBar, "SecureActionButtonTemplate")
local buttonBonus = CreateFrame("Button", "PetbuttonBonus", NewControlBar, "SecureActionButtonTemplate")
local buttonSpec1 = CreateFrame("Button", "PetbuttonSpec1", NewControlBar, "SecureActionButtonTemplate")
local buttonSpec2 = CreateFrame("Button", "PetbuttonSpec2", NewControlBar, "SecureActionButtonTemplate")
local buttonSpec3 = CreateFrame("Button", "PetbuttonSpec3", NewControlBar, "SecureActionButtonTemplate")


---------------------
--  start buttons and bar settings  --
---------------------

--control bar buttons
NewControlBarMover:SetSize(10,10)
NewControlBarMover:SetPoint("CENTER", ControlBar_PosX, ControlBar_PosY)
NewControlBarMover:SetNormalTexture(barMoveable)
NewControlBarMover:SetMovable(true)
NewControlBarMover:EnableMouse(true)
NewControlBarMover:SetScript("OnMouseDown", function(self, button)
  if button == "LeftButton" and not self.isMoving then
   self:StartMoving();
   self.isMoving = true;
  end
end)
NewControlBarMover:SetScript("OnMouseUp", function(self, button)
  if button == "LeftButton" and self.isMoving then
   self:StopMovingOrSizing();
   self.isMoving = false;
  end
end)
NewControlBarMover:SetScript("OnHide", function(self)
  if ( self.isMoving ) then
   self:StopMovingOrSizing();
   self.isMoving = false;
  end
end)

NewControlBar:SetPoint("TOPRIGHT", NewControlBarMover, "TOPLEFT", 10, 0);
NewControlBar:Show()
NewControlBar:SetSize(30,1)

buttonGrowl:SetSize(30,30)
buttonGrowl:SetAttribute("type","spell")
buttonGrowl:Show()
buttonGrowl:RegisterForClicks("LeftButtonUp","RightButtonUp")
buttonGrowl:SetAttribute("type2","macro")  

buttonBasic:SetSize(30,30)
buttonBasic:SetAttribute("type","spell")
buttonBasic:Show()
buttonBasic:RegisterForClicks("LeftButtonUp","RightButtonUp")
buttonBasic:SetAttribute("type2","macro") 

buttonSpecial:SetSize(30,30)
buttonSpecial:SetAttribute("type","spell")
buttonSpecial:Show()
buttonSpecial:RegisterForClicks("LeftButtonUp","RightButtonUp")
buttonSpecial:SetAttribute("type2","macro") 

buttonExotic:SetSize(30,30)
buttonExotic:SetAttribute("type","spell")
buttonExotic:Show()
buttonExotic:RegisterForClicks("LeftButtonUp","RightButtonUp")
buttonExotic:SetAttribute("type2","macro") 

buttonBonus:SetSize(30,30)
buttonBonus:SetAttribute("type","spell")
buttonBonus:Show()
buttonBonus:RegisterForClicks("LeftButtonUp","RightButtonUp")
buttonBonus:SetAttribute("type2","macro") 

buttonCower:SetSize(30,30)
buttonCower:SetAttribute("type","spell")
buttonCower:Show()
buttonCower:RegisterForClicks("LeftButtonUp","RightButtonUp")
buttonCower:SetAttribute("type2","macro") 

buttonSpec1:SetSize(30,30)
buttonSpec1:SetAttribute("type","spell")
buttonSpec1:Show()
buttonSpec1:RegisterForClicks("LeftButtonUp","RightButtonUp")
buttonSpec1:SetAttribute("type2","macro") 

buttonSpec2:SetSize(30,30)
buttonSpec2:SetAttribute("type","spell")
buttonSpec2:Show()
buttonSpec2:RegisterForClicks("LeftButtonUp","RightButtonUp")
buttonSpec2:SetAttribute("type2","macro") 

buttonSpec3:SetSize(30,30)
buttonSpec3:SetAttribute("type","spell")
buttonSpec3:Show()
buttonSpec3:RegisterForClicks("LeftButtonUp","RightButtonUp")
buttonSpec3:SetAttribute("type2","macro") 

	-- all button highlights

buttonBasic:SetHighlightTexture(buttonHighlight, add)
buttonGrowl:SetHighlightTexture(buttonHighlight, add)
buttonCower:SetHighlightTexture(buttonHighlight, add)
buttonSpecial:SetHighlightTexture(buttonHighlight, add)
buttonExotic:SetHighlightTexture(buttonHighlight, add)
buttonBonus:SetHighlightTexture(buttonHighlight, add)
buttonSpec1:SetHighlightTexture(buttonHighlight, add)
buttonSpec2:SetHighlightTexture(buttonHighlight, add)
buttonSpec3:SetHighlightTexture(buttonHighlight, add)

buttonBasic:SetPushedTexture(buttonPushed, add)
buttonGrowl:SetPushedTexture(buttonPushed, add)
buttonCower:SetPushedTexture(buttonPushed, add)
buttonSpecial:SetPushedTexture(buttonPushed, add)
buttonExotic:SetPushedTexture(buttonPushed, add)
buttonBonus:SetPushedTexture(buttonPushed, add)
buttonSpec1:SetPushedTexture(buttonPushed, add)
buttonSpec2:SetPushedTexture(buttonPushed, add)
buttonSpec3:SetPushedTexture(buttonPushed, add)
---------------------
--  start functions  --
---------------------

---------------start autocast textures-----------------------------
buttonGrowl.autocastable = buttonGrowl:CreateTexture("growlCastable")
buttonGrowl.autocastable:SetAllPoints(buttonGrowl);
buttonGrowl.autocastable:SetTexCoord(0.23, 0.77, 0.23, 0.77)
buttonGrowl.autocastable:SetSize(30,30);
buttonGrowl.autocastable:SetTexture(petAutoCastableTexture);

buttonBasic.autocastable = buttonBasic:CreateTexture("basicCastable")
buttonBasic.autocastable:SetAllPoints(buttonBasic);
buttonBasic.autocastable:SetTexCoord(0.23, 0.77, 0.23, 0.77)
buttonBasic.autocastable:SetSize(30,30);
buttonBasic.autocastable:SetTexture(petAutoCastableTexture);

buttonCower.autocastable = buttonCower:CreateTexture("cowerCastable")
buttonCower.autocastable:SetAllPoints(buttonCower);
buttonCower.autocastable:SetTexCoord(0.23, 0.77, 0.23, 0.77)
buttonCower.autocastable:SetSize(30,30);
buttonCower.autocastable:SetTexture(petAutoCastableTexture);

buttonSpecial.autocastable = buttonSpecial:CreateTexture("specialCastable")
buttonSpecial.autocastable:SetAllPoints(buttonSpecial);
buttonSpecial.autocastable:SetTexCoord(0.23, 0.77, 0.23, 0.77)
buttonSpecial.autocastable:SetSize(30,30);
buttonSpecial.autocastable:SetTexture(petAutoCastableTexture);

buttonExotic.autocastable = buttonExotic:CreateTexture("exoticCastable")
buttonExotic.autocastable:SetAllPoints(buttonExotic);
buttonExotic.autocastable:SetTexCoord(0.23, 0.77, 0.23, 0.77)
buttonExotic.autocastable:SetSize(30,30);
buttonExotic.autocastable:SetTexture(petAutoCastableTexture);

buttonBonus.autocastable = buttonBonus:CreateTexture("bonusCastable")
buttonBonus.autocastable:SetAllPoints(buttonBonus);
buttonBonus.autocastable:SetTexCoord(0.23, 0.77, 0.23, 0.77)
buttonBonus.autocastable:SetSize(30,30);
buttonBonus.autocastable:SetTexture(petAutoCastableTexture);

buttonSpec1.autocastable = buttonSpec1:CreateTexture("spec1Castable")
buttonSpec1.autocastable:SetAllPoints(buttonSpec1);
buttonSpec1.autocastable:SetTexCoord(0.23, 0.77, 0.23, 0.77)
buttonSpec1.autocastable:SetSize(30,30);
buttonSpec1.autocastable:SetTexture(petAutoCastableTexture);

buttonSpec2.autocastable = buttonSpec2:CreateTexture("spec2Castable")
buttonSpec2.autocastable:SetAllPoints(buttonSpec2);
buttonSpec2.autocastable:SetTexCoord(0.23, 0.77, 0.23, 0.77)
buttonSpec2.autocastable:SetSize(30,30);
buttonSpec2.autocastable:SetTexture(petAutoCastableTexture);

buttonSpec3.autocastable = buttonSpec3:CreateTexture("spec3Castable")
buttonSpec3.autocastable:SetAllPoints(buttonSpec3);
buttonSpec3.autocastable:SetTexCoord(0.23, 0.77, 0.23, 0.77)
buttonSpec3.autocastable:SetSize(30,30);
buttonSpec3.autocastable:SetTexture(petAutoCastableTexture);


---------------end autocast textures-----------------------------

------------------start autocast controls----------------
  local Button = buttonGrowl
	
local Buttons =
    {
    buttonGrowl
    }	
     --adding textures for ants/glow
    local tGlow = _G[Button:GetName().."Glow"] or Button:CreateTexture(Button:GetName().."Glow","OVERLAY")
    tGlow:SetTexture("Interface\\AddOns\\NewPetBar\\textures\\IconAlertGlow.tga")
    tGlow:ClearAllPoints()
    tGlow:SetPoint("TOPLEFT", Button, "TOPLEFT")
    tGlow:SetPoint("BOTTOMRIGHT", Button, "BOTTOMRIGHT")
    tGlow:SetDrawLayer("OVERLAY", 2)
    tGlow:Hide()
     
    local tAnts = _G[Button:GetName().."Ants"] or Button:CreateTexture(Button:GetName().."Ants","OVERLAY")
    tAnts:SetTexture("Interface\\AddOns\\NewPetBar\\textures\\IconAlertAnts1.tga")
    tAnts:ClearAllPoints()
    tAnts:SetPoint("TOPLEFT", Button, "TOPLEFT")
    tAnts:SetPoint("BOTTOMRIGHT", Button, "BOTTOMRIGHT")
    tAnts:SetDrawLayer("OVERLAY", 2)
    tAnts:Hide()
     
     
    --updating the ants if _G[Button:GetName().."Ants"] is visible
    do
        local f = CreateFrame("Frame", "BABMain", UIParent)
        f:SetScript("OnUpdate", function(...)
          for btni, btnv in pairs(Buttons) do
            if _G[btnv:GetName().."Ants"] then
                local tAnts = _G[btnv:GetName().."Ants"]
                if tAnts:IsVisible() then
                    if not tAnts.Step then
                        tAnts.Step = 1
                        tAnts.StepTime = GetTime()
                    end
                    if GetTime() - tAnts.StepTime > 0.025 then
                         tAnts.Step = tAnts.Step + 1
                         if tAnts.Step > 22 then
                             tAnts.Step = 1
                         end
                         tAnts:SetTexture("Interface\\AddOns\\NewPetBar\\textures\\IconAlertAnts"..tAnts.Step..".tga")
                         tAnts.StepTime = GetTime()
                    end
                end
            end            
          end
        end)
    end



local function AutoCastControl() -- keep autocast textures accurate
	if pet_growl_autoAllowed == 1 then
		buttonGrowl.autocastable:Show()	
	else 
		buttonGrowl.autocastable:Hide()	
	end
	if pet_basic_autoAllowed == 1 then
		buttonBasic.autocastable:Show()	
	else 
		buttonGrowl.autocastable:Hide()	
	end
	if pet_cower_autoAllowed == 1 then
		buttonCower.autocastable:Show()	
	else 
		buttonCower.autocastable:Hide()	
	end
	if pet_special_autoAllowed == 1 then
		buttonSpecial.autocastable:Show()	
	else 
		buttonSpecial.autocastable:Hide()	
	end
	if pet_exotic_autoAllowed == 1 then
		buttonExotic.autocastable:Show()	
	else 
		buttonExotic.autocastable:Hide()	
	end
	if pet_bonus_autoAllowed == 1 then
		buttonBonus.autocastable:Show()	
	else 
		buttonBonus.autocastable:Hide()	
	end
	if pet_spec_1_autoAllowed == 1 then
		buttonSpec1.autocastable:Show()	
	else 
		buttonSpec1.autocastable:Hide()	
	end
	if pet_spec_2_autoAllowed == 1 then
		buttonSpec2.autocastable:Show()	
	else 
		buttonSpec2.autocastable:Hide()	
	end
	if pet_spec_3_autoAllowed == 1 then
		buttonSpec3.autocastable:Show()	
	else 
		buttonSpec3.autocastable:Hide()	
	end

		if ( pet_growl_autoEnabled ) then
--				buttonGrowl.Ants:Show()
--				buttonGrowlAnts:Show()
		else
--				buttonGrowl.Ants:Hide()
--				buttonGrowlAnts:Hide()
		end

--[[
	if pet_basic_autoEnabled == 1 then
		buttonBasic.autoCast:Show()
	else 
		buttonBasic.autoCast:Hide()
	end
	if pet_cower_autoEnabled == 1 then
		buttonCower.autoCast:Show()
	else 
		buttonCower.autoCast:Hide()
	end
	if pet_special_autoEnabled == 1 then
		buttonSpecial.autoCast:Show()
	else 
		buttonSpecial.autoCast:Hide()
	end
	if pet_exotic_autoEnabled == 1 then
		buttonExotic.autoCast:Show()
	else 
		buttonExotic.autoCast:Hide()
	end
	if pet_bonus_autoEnabled == 1 then
		buttonBonus.autoCast:Show()
	else 
		buttonBonus.autoCast:Hide()
	end
	if pet_spec_1_autoEnabled == 1 then
		buttonSpec1.autoCast:Show()
	else 
		buttonSpec1.autoCast:Hide()
	end
	if pet_spec_2_autoEnabled == 1 then
		buttonSpec2.autoCast:Show()
	else 
		buttonSpec2.autoCast:Hide()
	end
	if pet_spec_3_autoEnabled == 1 then
		buttonSpec3.autoCast:Show()
	else 
		buttonSpec3.autoCast:Hide()
	end	]]
end
------------------end autocast controls----------------





function basic_OnEnter(self)
  GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
GameTooltip:SetSpellByID(pet_basic_spellID)
  GameTooltip:Show()
end
function growl_OnEnter(self)
  GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
GameTooltip:SetSpellByID(pet_growl_spellID)
  GameTooltip:Show()
end
function cower_OnEnter(self)
  GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
GameTooltip:SetSpellByID(pet_cower_spellID)
  GameTooltip:Show()
end
function special_OnEnter(self)
  GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
GameTooltip:SetSpellByID(pet_special_spellID)
  GameTooltip:Show()
end
function exotic_OnEnter(self)
if pet_exotic_spellID~=nil then
  GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
GameTooltip:SetSpellByID(pet_exotic_spellID)
  GameTooltip:Show()
  else
  end
end
function bonus_OnEnter(self)
if pet_bonus_spellID~=nil then
  GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
GameTooltip:SetSpellByID(pet_bonus_spellID)
  GameTooltip:Show()
  else
  end
end
function spec1_OnEnter(self)
if pet_spec_1_spellID~=nil then
  GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
GameTooltip:SetSpellByID(pet_spec_1_spellID)
  GameTooltip:Show()
  else
  end
end
function spec2_OnEnter(self)
if pet_spec_2_spellID~=nil then
  GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
GameTooltip:SetSpellByID(pet_spec_2_spellID)
  GameTooltip:Show()
  else
  end
end
function spec3_OnEnter(self)
if pet_spec_3_spellID~=nil then
  GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
GameTooltip:SetSpellByID(pet_spec_3_spellID)
  GameTooltip:Show()
  else
  end
end

local function OnLeave(self)
  GameTooltip:Hide()
end

buttonBasic:SetScript("OnEnter", basic_OnEnter)
buttonGrowl:SetScript("OnEnter", growl_OnEnter)
buttonCower:SetScript("OnEnter", cower_OnEnter)
buttonSpecial:SetScript("OnEnter", special_OnEnter)
buttonExotic:SetScript("OnEnter", exotic_OnEnter)
buttonBonus:SetScript("OnEnter", bonus_OnEnter)
buttonSpec1:SetScript("OnEnter", spec1_OnEnter)
buttonSpec2:SetScript("OnEnter", spec2_OnEnter)
buttonSpec3:SetScript("OnEnter", spec3_OnEnter)

buttonBasic:SetScript("OnLeave", OnLeave)
buttonGrowl:SetScript("OnLeave", OnLeave)
buttonCower:SetScript("OnLeave", OnLeave)
buttonSpecial:SetScript("OnLeave", OnLeave)
buttonExotic:SetScript("OnLeave", OnLeave)
buttonBonus:SetScript("OnLeave", OnLeave)
buttonSpec1:SetScript("OnLeave", OnLeave)
buttonSpec2:SetScript("OnLeave", OnLeave)
buttonSpec3:SetScript("OnLeave", OnLeave)


local function UpdateMacro() --keep macro commands updated --call nil
	SetMacroSpell(MACRO_NAME_BASIC_TOGGLE, pet_basic_attack or "")
	SetMacroSpell(MACRO_NAME_GROWL_TOGGLE, pet_growl_attack or "")
	SetMacroSpell(MACRO_NAME_COWER_TOGGLE, pet_cower_attack or "")
	SetMacroSpell(MACRO_NAME_SPECIAL_TOGGLE, pet_special_attack or "")
	SetMacroSpell(MACRO_NAME_EXOTIC_TOGGLE, pet_exotic_attack or "")
	SetMacroSpell(MACRO_NAME_BONUS_TOGGLE, pet_bonus_attack or "")
	SetMacroSpell(MACRO_NAME_SPEC1_TOGGLE, pet_spec_1_attack or "")
	SetMacroSpell(MACRO_NAME_SPEC2_TOGGLE, pet_spec_2_attack or "")
	SetMacroSpell(MACRO_NAME_SPEC3_TOGGLE, pet_spec_3_attack or "")
end

local function UpdateMyIcons() -- update icons --call nil
	if doIhaveApet then
		
		--get icons for attacks
	pet_basic_icon.bgFile = PET_BASICICON[pet_family]
	pet_growl_icon.bgFile = PET_ABILITYICON["growl"]
	pet_cower_icon.bgFile = PET_ABILITYICON["cower"]
	pet_exotic_icon.bgFile = PET_EXOTICICON[pet_family]
	pet_spec_1_icon.bgFile = PET_SPEC1ICON[pet_spec]
	pet_spec_2_icon.bgFile = PET_SPEC2ICON[pet_spec]
	pet_spec_3_icon.bgFile = PET_SPEC3ICON[pet_spec]
	pet_special_icon.bgFile = PET_SPECIALICON[pet_family]
	if (petBuff=="Prowl") or (petBuff=="Spirit Walk") then
		pet_bonus_icon.bgFile = "Interface\\Icons\\Ability_Vanish"
	else
		pet_bonus_icon.bgFile = PET_BONUSICON[pet_family]
	end	
		--assign icons to buttons if the pet has them and get their icons
		if (pet_Exotic ~= "nil") or (pet_exotic ~= nil)  then
			buttonExotic:Show()
		end

		if (pet_Bonus ~= "nil") or (pet_Bonus ~= nil)  then
			buttonBonus:Show()
		end
			
	--assign icons to buttons
--[[
		buttonBasic:SetNormalTexture(pet_basic_icon)
		buttonGrowl:SetNormalTexture(pet_growl_icon)
		buttonCower:SetNormalTexture(pet_cower_icon)
		buttonBonus:SetNormalTexture(pet_bonus_icon)
		buttonExotic:SetNormalTexture(pet_exotic_icon)
		buttonSpecial:SetNormalTexture(pet_special_icon)
		buttonSpec1:SetNormalTexture(pet_spec_1_icon)
		buttonSpec2:SetNormalTexture(pet_spec_2_icon)
		buttonSpec3:SetNormalTexture(pet_spec_3_icon)
]]
		buttonBasic:SetBackdrop(pet_basic_icon)
		buttonGrowl:SetBackdrop(pet_growl_icon)
		buttonCower:SetBackdrop(pet_cower_icon)
		buttonBonus:SetBackdrop(pet_bonus_icon)
		buttonExotic:SetBackdrop(pet_exotic_icon)
		buttonSpecial:SetBackdrop(pet_special_icon)
		buttonSpec1:SetBackdrop(pet_spec_1_icon)
		buttonSpec2:SetBackdrop(pet_spec_2_icon)
		buttonSpec3:SetBackdrop(pet_spec_3_icon)
	end
end

local function ManageButtons() --hide / show buttons -- call nil

-- hide spells that pets do not have	
	if (level < 80) and (doIhaveApet) then
		if ((pet_family == "Cat") or (pet_family == "Spirit Beast"))then 
			buttonSpecial:Hide()
			hidespecial = true
		else
			buttonSpecial:Show()
			hidespecial = false
		end
	end

	if hidespecial == true then
	--if not exotic
		if (pet_exotic_attack == "nil") or (pet_exotic_attack == nil) and BarsLocked==true then
		buttonExotic:Hide()
			buttonBonus:SetPoint(ControlBar_ButtonPrevious, buttonBasic, ControlBar_ButtonSide, ControlBar_ButtonX, ControlBar_ButtonY);

	--if no bonus skill
		elseif (pet_Bonus_attack == "nil") or (pet_Bonus_attack == nil) and BarsLocked==true then
		buttonBonus:Hide()
			buttonExotic:SetPoint(ControlBar_ButtonPrevious, buttonBasic, ControlBar_ButtonSide, ControlBar_ButtonX, ControlBar_ButtonY);

	--if not exotic and no bonus skill
		elseif ((pet_Bonus_attack == "nil") or (pet_Bonus_attack == nil)) and	((pet_exotic_attack == "nil") or (pet_exotic_attack == nil)) and BarsLocked==true then
			buttonExotic:Hide()
			buttonBonus:Hide()
			buttonCower:SetPoint(ControlBar_ButtonPrevious, buttonBasic, ControlBar_ButtonSide, ControlBar_ButtonX, ControlBar_ButtonY);
		else
			buttonExotic:Show()
			buttonBonus:Show()
		end
	elseif hidespecial == false then
	--if not exotic
		if (pet_exotic_attack == "nil") or (pet_exotic_attack == nil) and BarsLocked==true then
			buttonExotic:Hide()
			buttonBonus:SetPoint(ControlBar_ButtonPrevious, buttonSpecial, ControlBar_ButtonSide, ControlBar_ButtonX, ControlBar_ButtonY);
			buttonCower:SetPoint(ControlBar_ButtonPrevious, buttonBonus, ControlBar_ButtonSide, ControlBar_ButtonX, ControlBar_ButtonY);
			
	--if no bonus skill
		elseif (pet_Bonus_attack == "nil") or (pet_Bonus_attack == nil) and BarsLocked==true then
			buttonBonus:Hide()
			buttonExotic:SetPoint(ControlBar_ButtonPrevious, buttonSpecial, ControlBar_ButtonSide, ControlBar_ButtonX, ControlBar_ButtonY);
			buttonCower:SetPoint(ControlBar_ButtonPrevious, buttonExotic, ControlBar_ButtonSide, ControlBar_ButtonX, ControlBar_ButtonY);
			
	--if not exotic and no bonus skill
		elseif ((pet_Bonus_attack == "nil") or (pet_Bonus_attack == nil)) and	((pet_exotic_attack == "nil") or (pet_exotic_attack == nil)) and BarsLocked==true then
			buttonExotic:Hide()
			buttonBonus:Hide()
			buttonCower:SetPoint(ControlBar_ButtonPrevious, buttonSpecial, ControlBar_ButtonSide, ControlBar_ButtonX, ControlBar_ButtonY);
		else
			buttonExotic:Show()
			buttonBonus:Show()
		end
	else
		buttonExotic:Show()
		buttonBonus:Show()
		buttonExotic:SetPoint(ControlBar_ButtonPrevious, buttonSpecial, ControlBar_ButtonSide, ControlBar_ButtonX, ControlBar_ButtonY);
		buttonBonus:SetPoint(ControlBar_ButtonPrevious, buttonExotic, ControlBar_ButtonSide, ControlBar_ButtonX, ControlBar_ButtonY);
		buttonCower:SetPoint(ControlBar_ButtonPrevious, buttonBonus, ControlBar_ButtonSide, ControlBar_ButtonX, ControlBar_ButtonY);
	end	
end


local function GetSpellBookIDs() --use spell name to get spell book id and use it to get autocast info

	for i=1, 24 do
		local name = GetSpellInfo(i, "pet")
		local autocastAllowed, autocastEnabled = GetSpellAutocast(i, "pet")
		if name == pet_basic_name then
			pet_basic_spellbookID = i
			pet_basic_autoAllowed = autocastAllowed
			pet_basic_autoEnabled = autocastEnabled
		elseif name == pet_growl_name then
			pet_growl_spellbookID = i
			pet_growl_autoAllowed = autocastAllowed
			pet_growl_autoEnabled = autocastEnabled
		elseif name == pet_cower_name then
			pet_cower_spellbookID = i
			pet_cower_autoAllowed = autocastAllowed
			pet_cower_autoEnabled = autocastEnabled
		elseif name == pet_special_name then 			
			pet_special_spellbookID = i
			pet_special_autoAllowed = autocastAllowed
			pet_special_autoEnabled = autocastEnabled
		elseif name == pet_exotic_name then 			
			pet_exotic_spellbookID = i
			pet_exotic_autoAllowed = autocastAllowed
			pet_exotic_autoEnabled = autocastEnabled
		elseif name == pet_bonus_name then 			
			pet_bonus_spellbookID = i
			pet_bonus_autoAllowed = autocastAllowed
			pet_bonus_autoEnabled = autocastEnabled
		elseif name == pet_spec_1_name then 			
			pet_spec_1_spellbookID = i
			pet_spec_1_autoAllowed = autocastAllowed
			pet_spec_1_autoEnabled = autocastEnabled
		elseif name == pet_spec_2_name then 			
			pet_spec_2_spellbookID = i
			pet_spec_2_autoAllowed = autocastAllowed
			pet_spec_2_autoEnabled = autocastEnabled
		elseif name == pet_spec_3_name then 			
			pet_spec_3_spellbookID = i
			pet_spec_3_autoAllowed = autocastAllowed
			pet_spec_3_autoEnabled = autocastEnabled
		end
	end

AutoCastControl()
end

local function SetMyMacros() --create macros and attach to buttons --call nil
		
-- pet attacks
	if doIhaveApet then
			
--assign spells to buttons if the pet has them and get their icons
--move attack buttons to hide ability slots pets do not have				
		if (pet_exotic_attack == "nil") or (pet_exotic_attack == nil) then
			macrotext_exotic = macrotext .. ("")
			macrotext_exotic_toggle = macrotext .. ("")
			
		elseif pet_exotic_attack ~= nil then
			macrotext_exotic_toggle = macrotext .. ("/petautocasttoggle %s"):format(pet_exotic_attack)
			buttonExotic:SetAttribute("spell",pet_exotic_attack)
			
		elseif (pet_bonusattack == "nil") or (pet_bonus_attack == nil) then
			macrotext_bonus = macrotext .. ("")
			macrotext_bonus_toggle = macrotext .. ("")
			
		elseif pet_bonus_attack ~= nil then
			macrotext_bonus_toggle = macrotext .. ("/petautocasttoggle %s"):format(pet_bonus_attack)
			buttonBonus:SetAttribute("spell",pet_bonus_attack)
		else

		end


--set autocast right click toggle to macros 
			macrotext_basic_toggle = macrotext .. ("/petautocasttoggle %s"):format(pet_basic_attack)
			macrotext_growl_toggle = macrotext .. ("/petautocasttoggle Growl(Basic Ability)"):format(pet_growl_attack)
			macrotext_cower_toggle = macrotext .. ("/petautocasttoggle Cower(Basic Ability)"):format(pet_cower_attack)
			macrotext_special_toggle = macrotext .. ("/petautocasttoggle %s"):format(pet_special_attack)
			
-- pet has no spec or spec isnt found, then stop errors before they start				
		if (pet_spec==nil) or (pet_spec==Unknown) then
			macrotext_spec1 = macrotext .. ("")
			macrotext_spec2 = macrotext .. ("")
			macrotext_spec3 = macrotext .. ("")
			macrotext_spec1_toggle = macrotext .. ("")
			macrotext_spec2_toggle = macrotext .. ("")
			macrotext_spec3_toggle = macrotext .. ("")

		else
			if macrotext_spec1_toggle ~= nil then
				macrotext_spec1_toggle = macrotext .. ("/petautocasttoggle %s"):format(pet_spec_1_attack)
			end
			if macrotext_spec2_toggle ~= nil then
				macrotext_spec2_toggle = macrotext .. ("/petautocasttoggle %s"):format(pet_spec_2_attack)
			end
			if macrotext_spec2_toggle ~= nil then
				macrotext_spec3_toggle = macrotext .. ("/petautocasttoggle %s"):format(pet_spec_3_attack)
			end
		end 
	end
	

--assign toggle macros to right clicks	
	buttonBasic:SetAttribute("macrotext", macrotext_basic_toggle)
	buttonGrowl:SetAttribute("macrotext", macrotext_growl_toggle)
	buttonCower:SetAttribute("macrotext", macrotext_cower_toggle)
	buttonSpecial:SetAttribute("macrotext", macrotext_special_toggle)
	buttonExotic:SetAttribute("macrotext", macrotext_exotic_toggle)
	buttonBonus:SetAttribute("macrotext", macrotext_bonus_toggle)
	buttonSpec1:SetAttribute("macrotext", macrotext_spec1_toggle)
	buttonSpec2:SetAttribute("macrotext", macrotext_spec2_toggle)
	buttonSpec3:SetAttribute("macrotext", macrotext_spec3_toggle)
	
-- assign dynamic spells to buttons
	buttonGrowl:SetAttribute("spell","Growl(Basic Ability)")
	buttonBasic:SetAttribute("spell",pet_basic_attack)
	buttonCower:SetAttribute("spell","Cower(Basic Ability)")
	buttonSpec1:SetAttribute("spell",pet_spec_1_attack)
	buttonSpec2:SetAttribute("spell",pet_spec_2_attack)
	buttonSpec3:SetAttribute("spell",pet_spec_3_attack)
	buttonSpecial:SetAttribute("spell",pet_special_attack)
	
	return macrotext ~= ""		
end 

--- cooldowns	----------------------------------------------------------

local exoticClicked=false
local cowerClicked=false
--local duration
local buttonClicked

buttonGrowl:SetScript("PreClick", function(self, button)
	buttonGrowl.spellID = pet_growl_spellID
	buttonGrowl.ID=pet_growl_name --self:GetAttribute("spell")
	--duration = pet_growl_cooldown
	growlClicked=true
	buttonClicked=buttonGrowl
	myVariables:RegisterEvent("SPELL_UPDATE_COOLDOWN")
end)
buttonBasic:SetScript("PreClick", function(self, button)
	buttonBasic.spellID = pet_basic_spellID
	buttonBasic.ID=pet_basic_name --self:GetAttribute("spell")
	--duration = pet_basic_cooldown
	basicClicked=true
	buttonClicked=buttonBasic
	myVariables:RegisterEvent("SPELL_UPDATE_COOLDOWN")
end)
buttonCower:SetScript("PreClick", function(self, button)
	buttonCower.spellID = pet_cower_spellID
	buttonCower.ID=pet_cower_name --self:GetAttribute("spell")
	--duration = pet_cower_cooldown
	cowerClicked=true
	buttonClicked=buttonCower
	myVariables:RegisterEvent("SPELL_UPDATE_COOLDOWN")
end)
buttonBonus:SetScript("PreClick", function(self, button)
	buttonBonus.spellID = pet_bonus_spellID
	buttonBonus.ID=pet_bonus_name --self:GetAttribute("spell")
	--duration = pet_bonus_cooldown
	bonusClicked=true
	buttonClicked=buttonBonus
	myVariables:RegisterEvent("SPELL_UPDATE_COOLDOWN")
end)
buttonExotic:SetScript("PreClick", function(self, button)
	buttonExotic.spellID = pet_exotic_spellID
	buttonExotic.ID=pet_exotic_name --self:GetAttribute("spell")
	--duration = pet_exotic_cooldown
	exoticClicked=true
	buttonClicked=buttonExotic
	myVariables:RegisterEvent("SPELL_UPDATE_COOLDOWN")
end)
buttonSpecial:SetScript("PreClick", function(self, button)
	buttonSpecial.spellID = pet_special_spellID
	buttonSpecial.ID=pet_special_name --self:GetAttribute("spell")
	--duration = pet_special_cooldown
	specialClicked=true
	buttonClicked=buttonSpecial
	myVariables:RegisterEvent("SPELL_UPDATE_COOLDOWN")
end)
buttonSpec1:SetScript("PreClick", function(self, button)
	buttonSpec1.spellID = pet_spec_1_spellID
	buttonSpec1.ID=pet_spec_1_name --self:GetAttribute("spell")
	--duration = pet_spec_1_cooldown
	spec1Clicked=true
	buttonClicked=buttonSpec1
	myVariables:RegisterEvent("SPELL_UPDATE_COOLDOWN")
end)
buttonSpec2:SetScript("PreClick", function(self, button)
	buttonSpec2.spellID = pet_spec_2_spellID
	buttonSpec2.ID=pet_spec_2_name --self:GetAttribute("spell")
	--duration = pet_spec_2_cooldown
	spec2Clicked=true
	buttonClicked=buttonSpec2
	myVariables:RegisterEvent("SPELL_UPDATE_COOLDOWN")
end)
buttonSpec3:SetScript("PreClick", function(self, button)
	buttonSpec3.spellID = pet_spec_3_spellID
	buttonSpec3.ID=pet_spec_3_name --self:GetAttribute("spell")
	--duration = pet_spec_3_cooldown
	spec3Clicked=true
	buttonClicked=buttonSpec3
	myVariables:RegisterEvent("SPELL_UPDATE_COOLDOWN")
end)

buttonGrowl:SetScript("PostClick", function(self, button)
GetSpellBookIDs()
end)
buttonBasic:SetScript("PostClick", function(self, button)
GetSpellBookIDs()
end)
buttonCower:SetScript("PostClick", function(self, button)
GetSpellBookIDs()
end)
buttonBonus:SetScript("PostClick", function(self, button)
GetSpellBookIDs()
end)
buttonExotic:SetScript("PostClick", function(self, button)
GetSpellBookIDs()
end)
buttonSpecial:SetScript("PostClick", function(self, button)
GetSpellBookIDs()
end)
buttonSpec1:SetScript("PostClick", function(self, button)
GetSpellBookIDs()
end)
buttonSpec2:SetScript("PostClick", function(self, button)
GetSpellBookIDs()
end)
buttonSpec3:SetScript("PostClick", function(self, button)
GetSpellBookIDs()
end)


local function myVariables_OnEvent(self, event, ...)--[[
if (buttonClicked==buttonSpec1 or buttonClicked==buttonSpec2 or buttonClicked==buttonSpec3) and buttonClicked.spellID == nil then
print("No Spec for cooldown")
end]]
	--local start = GetTime()
	local start, duration = GetSpellCooldown(buttonClicked.spellID)
	--	if duration > 0 then
--				print(buttonClicked:GetAttribute("spell"), "is on cooldown for", duration, "seconds.")
				buttonClicked.cooldown:Show()
				buttonClicked.start=start
				buttonClicked.cooldown:SetCooldown(start, duration)
--[[		else
				print(buttonClicked:GetAttribute("spell"), "is not on cooldown.")
				buttonClicked.cooldown:Hide()
		end]]
	if buttonClicked==buttonBasic and duration < 2 then  --only unregister cooldown if basic wasnt hit and it doesnt have less then a 2 sec cooldown
	else
		myVariables:UnregisterEvent("SPELL_UPDATE_COOLDOWN")
	end
--	print("SPELL_UPDATE_COOLDOWN - pet_spec: ", pet_spec)
--	print("SPELL_UPDATE_COOLDOWN - buttonClicked: ", buttonClicked)
--	print("SPELL_UPDATE_COOLDOWN - buttonClicked.spellID: ", buttonClicked.spellID)
--	print("SPELL_UPDATE_COOLDOWN - buttonClicked.cooldown: ", buttonClicked.cooldown)
end
	
-- Add a cooldown to the button:
local growlCD = CreateFrame("Cooldown", "$parentCooldown", buttonGrowl, "CooldownFrameTemplate")
buttonGrowl.cooldown = growlCD
growlCD:SetAllPoints(true)
growlCD:Hide()
local basicCD = CreateFrame("Cooldown", "$parentCooldown", buttonBasic, "CooldownFrameTemplate")
buttonBasic.cooldown = basicCD
basicCD:SetAllPoints(true)
basicCD:Hide()
local specialCD = CreateFrame("Cooldown", "$parentCooldown", buttonSpecial, "CooldownFrameTemplate")
buttonSpecial.cooldown = specialCD
specialCD:SetAllPoints(true)
specialCD:Hide()
local exoticCD = CreateFrame("Cooldown", "$parentCooldown", buttonExotic, "CooldownFrameTemplate")
buttonExotic.cooldown = exoticCD
exoticCD:SetAllPoints(true)
exoticCD:Hide()
local bonusCD = CreateFrame("Cooldown", "$parentCooldown", buttonBonus, "CooldownFrameTemplate")
buttonBonus.cooldown = bonusCD
bonusCD:SetAllPoints(true)
bonusCD:Hide()
local cowerCD = CreateFrame("Cooldown", "$parentCooldown", buttonCower, "CooldownFrameTemplate")
buttonCower.cooldown = cowerCD
cowerCD:SetAllPoints(true)
cowerCD:Hide()
local spec1CD = CreateFrame("Cooldown", "$parentCooldown", buttonSpec1, "CooldownFrameTemplate")
buttonSpec1.cooldown = spec1CD
spec1CD:SetAllPoints(true)
spec1CD:Hide()
local spec2CD = CreateFrame("Cooldown", "$parentCooldown", buttonSpec2, "CooldownFrameTemplate")
buttonSpec2.cooldown = spec2CD
spec2CD:SetAllPoints(true)
spec2CD:Hide()
local spec3CD = CreateFrame("Cooldown", "$parentCooldown", buttonSpec3, "CooldownFrameTemplate")
buttonSpec3.cooldown = spec3CD
spec3CD:SetAllPoints(true)
spec3CD:Hide()

myVariables:SetScript("OnEvent", myVariables_OnEvent)

--- end cooldowns	----------------------------------------------------------


local function FindPetSpec()
		local currentSpec = GetSpecialization(false,true)
		if currentSpec == 1 then 
			talent = "Ferocity"
		elseif currentSpec == 2 then 
			talent = "Tenacity"
		elseif currentSpec == 3 then 
			talent = "Cunning"
		else 
			talent = "Unknown" 
		end

		
end	
local function SetMySkills2() --find pet data and retrieve attacks --part 2 of 2  --call SetMyMacros() GetSpellBookIDs()
	if pet_spec==nil or pet_spec=="Unknown" then
		local currentSpec = GetSpecialization(false,true)
		if currentSpec == 1 then 
			talent = "Ferocity"
		elseif currentSpec == 2 then 
			talent = "Tenacity"
		elseif currentSpec == 3 then 
			talent = "Cunning"
		else 
			talent = "Unknown" 
		end
	end	
		
		pet_basic_cooldown = PET_BASIC_CD[pet_family]
		pet_growl_cooldown = PET_ABILITY_CD["growl"]
		pet_cower_cooldown = PET_ABILITY_CD["cower"]
		pet_special_cooldown = PET_SPECIAL_CD[pet_family]
		pet_exotic_cooldown = PET_EXOTIC_CD[pet_family]
		pet_bonus_cooldown = PET_BONUS_CD[pet_family]
		pet_spec_1_cooldown = PET_SPEC1_CD[pet_spec]
		pet_spec_2_cooldown = PET_SPEC2_CD[pet_spec]
		pet_spec_3_cooldown = PET_SPEC3_CD[pet_spec]

		pet_basic_spellID = PET_BASIC_SPELLID[pet_family]
		pet_growl_spellID = PET_ABILITY_SPELLID["growl"]
		pet_cower_spellID = PET_ABILITY_SPELLID["cower"]
		pet_special_spellID = PET_SPECIAL_SPELLID[pet_family]
		pet_exotic_spellID = PET_EXOTIC_SPELLID[pet_family]
		pet_bonus_spellID = PET_BONUS_SPELLID[pet_family]
		pet_spec_1_spellID = PET_SPEC1_SPELLID[pet_spec]
		pet_spec_2_spellID = PET_SPEC2_SPELLID[pet_spec]
		pet_spec_3_spellID = PET_SPEC3_SPELLID[pet_spec]
		


--	print("SetMySkills2() - pet_spec: ", pet_spec)
--	print("SetMySkills2() - pet_family: ", pet_family)
--	print("SetMySkills2() - pet_spec_1_spellID: ", pet_spec_1_spellID)
--	print("SetMySkills2() - pet_spec_1_cooldown: ", pet_spec_1_cooldown)

--create macros and attach to buttons
	SetMyMacros()

--get spellbook IDs
	GetSpellBookIDs()
	
--resize bar for what attacks pet has
ManageButtons()

end

local function SetMySkills1() --find pet data and retrieve attacks --part 1 of 2 --call SetMySkill2()
	if pet_spec==nil or pet_spec=="Unknown" then
		local currentSpec = GetSpecialization(false,true)
		if currentSpec == 1 then 
			talent = "Ferocity"
		elseif currentSpec == 2 then 
			talent = "Tenacity"
		elseif currentSpec == 3 then 
			talent = "Cunning"
		else 
			talent = "Unknown" 
		end
	end	
	
	
-- pet attacks
	if doIhaveApet then
		pet_basic_attack = PET_BASIC[pet_family]
		pet_growl_attack = PET_ABILITY["growl"]
		pet_cower_attack = PET_ABILITY["cower"]
		pet_special_attack = PET_SPECIAL[pet_family]
		pet_exotic_attack = PET_EXOTIC[pet_family]
		pet_bonus_attack = PET_BONUS[pet_family]
		pet_spec_1_attack = PET_SPEC1[pet_spec]
		pet_spec_2_attack = PET_SPEC2[pet_spec]
		pet_spec_3_attack = PET_SPEC3[pet_spec]
			
		pet_basic_name = PET_BASIC_NAME[pet_family]
		pet_growl_name = PET_ABILITY_NAME["growl"]
		pet_cower_name = PET_ABILITY_NAME["cower"]
		pet_special_name = PET_SPECIAL_NAME[pet_family]
		pet_exotic_name = PET_EXOTIC_NAME[pet_family]
		pet_bonus_name = PET_BONUS_NAME[pet_family]
		pet_spec_1_name = PET_SPEC1_NAME[pet_spec]
		pet_spec_2_name = PET_SPEC2_NAME[pet_spec]
		pet_spec_3_name = PET_SPEC3_NAME[pet_spec]

	end
	
--	print("SetMySkills1() - pet_spec: ", pet_spec)
--	print("SetMySkills1() - pet_family: ", pet_family)
	
SetMySkills2()
	
end

local function UpdatePets() -- gather current pet data --call	 UpdateMyIcons() UpdateMacro() 	UpdatePetCallBar()	 SetMySkills()

	if InCombatLockdown() then return end --freeze updating if in combat
		level = UnitLevel("player")
	local isHunterPet = HasPetUI() -- check if pet is hunter pet
	doIhaveApet = isHunterPet

	petBuff = UnitBuff("pet", "Prowl") or UnitBuff("pet", "Spirit Walk")

	--  get info of current pet  --
	local petname = UnitName("pet"); 
	local petfamily= UnitCreatureFamily("pet")
	local talent 

	local currentSpec = GetSpecialization(false,true)
		if currentSpec == 1 then 
			talent = "Ferocity"
		elseif currentSpec == 2 then 
			talent = "Tenacity"
		elseif currentSpec == 3 then 
			talent = "Cunning"
		else 
			talent = "Unknown" 
		end

--set data for current pet
	pet_name = petname
	pet_family = petfamily
	pet_spec = talent
	
--	print("UpdatePets() - pet_spec: ", pet_spec)
--	print("UpdatePets() - pet_family: ", pet_family)
--find attacks
	SetMySkills1()	
	
--call update for icons
	UpdateMyIcons()
	
--call update for macros
	UpdateMacro()			
		
end

local function UpdateBars() --apply button alignments --call nil
--control bar buttons
buttonGrowl:SetPoint(ControlBar_ButtonPrevious, NewControlBar, ControlBar_ButtonSide, ControlBar_ButtonX, ControlBar_ButtonY);
buttonBasic:SetPoint(ControlBar_ButtonPrevious, buttonGrowl, ControlBar_ButtonSide, ControlBar_ButtonX, ControlBar_ButtonY);
buttonSpecial:SetPoint(ControlBar_ButtonPrevious, buttonBasic, ControlBar_ButtonSide, ControlBar_ButtonX, ControlBar_ButtonY);
buttonExotic:SetPoint(ControlBar_ButtonPrevious, buttonSpecial, ControlBar_ButtonSide, ControlBar_ButtonX, ControlBar_ButtonY);
buttonBonus:SetPoint(ControlBar_ButtonPrevious, buttonExotic, ControlBar_ButtonSide, ControlBar_ButtonX, ControlBar_ButtonY);
buttonCower:SetPoint(ControlBar_ButtonPrevious, buttonBonus, ControlBar_ButtonSide, ControlBar_ButtonX, ControlBar_ButtonY);
buttonSpec1:SetPoint(ControlBar_ButtonPrevious, buttonCower, ControlBar_ButtonSide, ControlBar_ButtonX, ControlBar_ButtonY);
buttonSpec2:SetPoint(ControlBar_ButtonPrevious, buttonSpec1, ControlBar_ButtonSide, ControlBar_ButtonX, ControlBar_ButtonY);
buttonSpec3:SetPoint(ControlBar_ButtonPrevious, buttonSpec2, ControlBar_ButtonSide, ControlBar_ButtonX, ControlBar_ButtonY);

UpdatePets()
end

local function RealignButtons() --set button alignment --call UpdateBars()

	if ControlBar_Horiz==false then
		ControlBar_ButtonX = -30
		ControlBar_ButtonY = -33
		ControlBar_ButtonPrevious = "LEFT"
		ControlBar_ButtonSide = "RIGHT"
	elseif ControlBar_Horiz==true then
		ControlBar_ButtonX = 3
		ControlBar_ButtonY = 0
		ControlBar_ButtonPrevious = "LEFT"
		ControlBar_ButtonSide = "RIGHT"
	end
	
	if ControlBar_Enabled == false then
		NewControlBar:Hide()
	elseif (not doIhaveApet) and (ControlBar == true) then		
		NewControlBar:Show()
	end
		if BarsLocked==false then
		NewControlBar:Show()
	elseif BarsLocked==true and ControlBar_Enabled == false then
		NewControlBar:Hide()
	elseif (not doIhaveApet) and (ControlBar_Enabled == true) and BarsLocked==true then		
		NewControlBar:Show()
	end
UpdateBars()
end

local function UnlockBars() --unlocks bars --call UpdatePets()
	BarsLocked=false
	NewControlBar:Show()
	NewControlBarMover:Show()
	NewControlBarMover:SetMovable(true)
	NewControlBarMover:EnableMouse(true)

	ManageButtons()
	UpdatePets()
end
local function LockBars() --locks bars --call UpdatePets()
	BarsLocked=true
	NewControlBarMover:Hide()
	NewControlBarMover:SetMovable(false)
	NewControlBarMover:EnableMouse(false)
	local xOffset, yOffset = NewControlBarMover:GetPoint()
	ControlBar_PosX = xOffset
	ControlBar_PosY = yOffset

		if (doIhaveApet) and (ControlBar_Enabled == true) then	
		NewControlBar:Show()
		
	elseif (not doIhaveApet) or (ControlBar_Enabled == false) then	
		NewControlBar:Hide()
	end		
	
	ManageButtons()
	UpdatePets()
end

function YavanaeLockBars()
	LockBars()
end
function YavanaeUnlockBars()
	UnlockBars()
end
function YavanaeHideBars()
NewCommandBar:Hide()
NewControlBarMover:Hide()
ControlBar_Enabled=false
end
function YavanaeUnhideBars()
NewControlBar:Show()
NewControlBarMover:Show()
ControlBar_Enabled=true
end

local function Force() -- /npb force command  
RealignButtons()
end

--button:RegisterEvent("PLAYER_LOGIN")
button:RegisterEvent("PLAYER_ENTERING_WORLD")
button:RegisterEvent("PET_STABLE_CLOSED")
button:RegisterEvent("NewPetBar_LOADED")
button:RegisterUnitEvent("UNIT_PET", "player")
button:SetScript("OnEvent", function(self, event, ...)
	self[event](self, ...)
end)


local timer = 0
local delay = 5
local runDelay = true



local function OnUpdate(self, elapsed) --call UpdatePets()
	--print("delayed onupdate called")
	timer = timer + elapsed
	if ( timer >= delay ) and runDelay==true then
			timer = 0
	--		print("delayed onupdate - delay passed")
	--		print(elapsed)
RealignButtons()
--			print("delayed onupdate - delay and rundelay passed")
			if ( pet_spec_3_spellID == nil ) then
				runDelay=false
--				print("delayed onupdate fired - nil spell id")
				UpdatePets()
			else
				runDelay=false
--				print("delayed onupdate fired - nonnil spell id")
			--	UpdatePets()
			end
	end
	
	
	

	
end

function button:PLAYER_ENTERING_WORLD()	  --call UpdatePets() RealignButtons()
	-- We only care about this event the first time it fires, so we unregister the event and nil out this method
	self:UnregisterEvent("PLAYER_ENTERING_WORLD")
	self.PLAYER_ENTERING_WORLD = nil
		
	if not UpdatePets() then -- If we don't have pet data, start the OnUpdate script to try again every 0.5 seconds
--		print("timed update pets fired")
		self:SetScript("OnUpdate", OnUpdate)
--		buttonGrowl:SetScript("OnUpdate", YavAutoCastShine_OnUpdate)
	end

DEFAULT_CHAT_FRAME:AddMessage("Yavanae's Pet Control Bar Loaded! Type /ypbctrl for help", 0.66, 0.1, 0.1, 2385, 5)	
		level = UnitLevel("player")
--		print("button player entering world fired")

	RealignButtons()
runDelay=true
end

function button:NewPetBar_LOADED()  --call UpdatePets()
--	print("button yav pet bar loaded event message")
RealignButtons()
end

function button:PET_STABLE_CLOSED()  --call UpdatePets()
--		print("button pet stables closed fired")
		runDelay=true

end

function button:UNIT_PET(unit) -- unit will always be "player"  --call UpdatePets()
--		print("button unit pet fired")

	runDelay=true

end


SlashCmdList["yavpetbarctrl"] = function(msg)
	msg = string.upper(msg)
	if msg=="UNLOCK" then
		UnlockBars()
		print("Control Bar is now being unlocked")
		
	elseif msg=="LOCK" then
		LockBars()
		print("Control Bar is now being locked")
	
	elseif msg=="TEST" then
		Test()	
			
	elseif msg=="VERT" then
		ControlBar_Horiz = false
		RealignButtons()
		print("Control Bar is now Vertical")
		
	elseif msg=="HORIZ" then
		ControlBar_Horiz = true
		RealignButtons()
		print("Control Bar is now Horizontal")
			
	elseif msg=="HIDE" then
		CommandBar_Enabled = false	
		RealignButtons()
		print("Command Bar is now disabled")
		
	elseif msg=="HIDE" then
		ControlBar_Enabled = false
		RealignButtons()
		print("Control Bar is now disabled")
		
	elseif msg=="SHOW" then
		ControlBar_Enabled = true
		RealignButtons()
		print("Control Bar is now enabled")
		
	else
		DEFAULT_CHAT_FRAME:AddMessage("|cff007fffYavanae's Pet Control Bar: |cff00ff00Commands are:\n|r/ypbctrl unlock|cff00ff00 (allows bars to be moved)\n|r/ypbctrl lock|cff00ff00 (locks bars so they cannot be moved)\n|r/ypbctrl horiz|cff00ff00 (alligns pet attack bar horizontally)\n|r/ypbctrl vert|cff00ff00 (alligns pet attack bar vertically)\n|r/ypbctrl show|cff00ff00 (enables the pet attack bar)\n|r/ypbctrl hide|cff00ff00 (disables the pet attack bar)|r")
	end
end
SLASH_yavpetbarctrl1 = "/ypbctrl"
SLASH_yavpetbarctrl2 = "/yavpetbarctrl"
  Reply With Quote
09-04-14, 12:58 PM   #9
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
As it could happen that the button should be visible without the ants animation you'll have to show/hide the ants texture according to the actual status of you button. Like
Lua Code:
  1. _G[buttonGrowl:GetName().."Ants"]:Show()
somewhere in your code.
  Reply With Quote
09-06-14, 12:02 AM   #10
kez717
A Murloc Raider
Join Date: Oct 2008
Posts: 5
Thought I'd post back and give an update. I got your code to work, but it wasn't quite what I was after (close but not quite there since blizzard updated it from the original texture it seems). After hours of more poking around in various addons and bits of code I finally managed to get it to show on a lua only button in a file with just the button (a ways from being in an actual addon, but it's progress). I thought I'd share what I managed to get incase anyone else has similar trouble or would like a clean working script to use as an example.

Its just a simple button (nothing assigned for when clicked or anything), has the on mouseover and on pushed textures working (using a backdrop was the easiest way I found to keep the on push image from over-riding the buttons icon), and most importantly the current autocast animation that is in game. the autocast is set to show when the button is checked and hide when unchecked. the color of the glow can be adjusted by changing the values on the SHINE_ variables, and the size of the "sparkles" can be changed with the multiplier at the bottom of the code.

Code:
local isMyButtonClicked = false
local buttonPet1_icon = {  bgFile = "Interface\\Icons\\ability_hunter_beastcall",    edgeFile = "",  tile = false,  tileSize = 30,}
local buttonPet1 = CreateFrame("CheckButton", "PetButtonCall1", UIParent, "SecureActionButtonTemplate,AutoCastShineTemplate")
local buttonPet1Shine = CreateFrame("CheckButton", "PetButtonCall1Shine", UIParent, "SecureActionButtonTemplate,AutoCastShineTemplate")
buttonPet1:SetSize(30,30)
buttonPet1:SetPoint("CENTER", 0, 0)
buttonPet1:Show()
buttonPet1:SetBackdrop(buttonPet1_icon)
buttonPet1:SetFrameStrata("LOW")
buttonPet1Shine:SetFrameStrata("Medium")

buttonPet1:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square", add)
buttonPet1:SetPushedTexture("Interface\\Buttons\\ui-quickslot-depress", add)

local SHINE_R = .95;
local SHINE_G = .95;
local SHINE_B = .32;

buttonPet1Shine:SetScript("OnClick", function(self, button)
	if isMyButtonClicked==false then
		buttonPet1:SetChecked(true)
		isMyButtonClicked=true
		AutoCastShine_AutoCastStart(self, SHINE_R, SHINE_G, SHINE_B)
	else
		buttonPet1:SetChecked(false)
		isMyButtonClicked=false
		AutoCastShine_AutoCastStop(self)
	end
end)

buttonPet1Shine:RegisterEvent('PLAYER_LOGIN')
buttonPet1Shine:SetScript('OnEvent', function(self)
	for _, sparkle in next, self.sparkles do
		sparkle:SetHeight(sparkle:GetHeight() * 1)
		sparkle:SetWidth(sparkle:GetWidth() * 1)
	end
end)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Autocast animated overlay trouble

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