Thread Tools Display Modes
07-26-16, 04:21 AM   #1
spelgubbe2
A Defias Bandit
Join Date: Jul 2016
Posts: 3
Exclamation Animation on MultiBars play "behind" the button

Basically this script makes your buttons light up with an animation when you press them. It was called SnowfallKeypress but it seems nobody is really keeping it up to date anymore. I have used this script forever, and I recently made some small changes to it for it to work in Legion.

However, it does not work properly for buttons which are on any of the MultiBars.

On all the buttons at the MultiBars (MultiBarBottomLeftButton11 is one of them, for example), the animation from this script is not shown at the highest layer (even though it looks to be). Since the animation is a bit larger than the actionbar buttons you can see the outer part of it when you press a button.

I have tried to change the strata of the frame where the animation is played, and it's level. I have also looked at it with /fstack and came to the conclusion that clicks on ActionButtons 1-12 behave the same way as clicks on the MultiBars. The difference would be a layer called *buttonName*FloatingBG, which appears on buttons at the MultiBars. However, when I tried hiding it, it made no difference.

Pictures of snowfall working on Frostbolt (ActionButton1), and then not working properly on Ice Nova (MultiBarBottomLeftButton5).

Not working vs working example

I think the problem is in the animate function. I would be happy if you could help me figure out what is causing this problem. I have tried lot of different functions to try to solve this issue, but nothing really seems to work.

Here's the code:

Code:
local animationsCount, animations = 5, {}
local animationNum = 1
local replace = string.gsub
local frame, texture, animationGroup, alpha1, scale1, scale2, rotation2

for i = 1, animationsCount do
frame = CreateFrame("Frame")

texture = frame:CreateTexture()
texture:SetTexture([[Interface\Cooldown\star4]])
texture:SetAlpha(0)
texture:SetAllPoints()
texture:SetBlendMode("ADD")

-- no difference
--texture:SetDrawLayer("ARTWORK", 7)
--print(texture:GetDrawLayer())

animationGroup = texture:CreateAnimationGroup()

alpha1 = animationGroup:CreateAnimation("Alpha")
alpha1:SetFromAlpha(0)
alpha1:SetToAlpha(1)
alpha1:SetDuration(0)
alpha1:SetOrder(1)

scale1 = animationGroup:CreateAnimation("Scale")
scale1:SetFromScale(1.0, 1.0) -- looks better/is bigger this way
scale1:SetToScale(1.5, 1.5)
--scale1:SetScale(1.5, 1.5) -- original
scale1:SetDuration(0)
scale1:SetOrder(1)

scale2 = animationGroup:CreateAnimation("Scale")
--scale2:SetScale(0, 0) -- original
scale2:SetFromScale(1.5, 1.5)
scale2:SetToScale(0,0)
scale2:SetDuration(0.3)
scale2:SetOrder(2)

rotation2 = animationGroup:CreateAnimation("Rotation")
rotation2:SetDegrees(90)
rotation2:SetDuration(0.3)
rotation2:SetOrder(2)

animations[i] = {frame = frame, animationGroup = animationGroup}
end

local animate = function(button)
	if not button:IsVisible() then
		return true
	end
	local animation = animations[animationNum]
	local frame = animation.frame
	local animationGroup = animation.animationGroup
	
	--[[
	local FloatingBG = _G[button:GetName() .. 'FloatingBG']
	if FloatingBG then
		FloatingBG:Hide()
	end
		-- on multibars there was a weird layer called barname+FloatingBG
		-- this didn't make a difference though
	]] 
	frame:SetFrameStrata(button:GetFrameStrata())
	frame:SetFrameLevel(button:GetFrameLevel() + 10)
	frame:SetAllPoints(button)
	animationGroup:Stop()
	animationGroup:Play()
	animationNum = (animationNum % animationsCount) + 1
	return true
end

-- didn't run on PLAYER_ENTERING_WORLD
--hooksecurefunc('ActionButton_UpdateHotkeys', function(button, buttonType)
hooksecurefunc('ActionButton_Update', function(button, actionbuttonType)
if InCombatLockdown() then return end -- no animation while in CC
if not button.hooked then
local id, actionButtonType, key
if not actionButtonType then
actionButtonType = button:GetAttribute('binding') or string.upper(button:GetName())

-- here the button names are translated to work with the GetBindingKey function
-- no problems here

actionButtonType = replace(actionButtonType, 'BOTTOMLEFT', '1')
actionButtonType = replace(actionButtonType, 'BOTTOMRIGHT', '2')
actionButtonType = replace(actionButtonType, 'RIGHT', '3')
actionButtonType = replace(actionButtonType, 'LEFT', '4')
actionButtonType = replace(actionButtonType, 'MULTIBAR', 'MULTIACTIONBAR')
end
local key = GetBindingKey(actionButtonType)
if key then
button:RegisterForClicks("AnyDown")
SetOverrideBinding(button, true, key, 'CLICK '..button:GetName()..':LeftButton')
-- SetOverrideBindingClick(button, true, key, button:GetName(), "LeftButton") -- same thing...
end
button.AnimateThis = animate
SecureHandlerWrapScript(button, "OnClick", button, [[ control:CallMethod("AnimateThis", self) ]])
button.hooked = true
end
-- this whole segment seems to work, the problem lies in the animate function most likely
end)
  Reply With Quote
07-26-16, 08:26 AM   #2
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
You need to increase the frame's strata and/or level:

Lua Code:
  1. frame:SetFrameStrata("HIGH") --BACKGROUND,LOW,MEDIUM,HIGH,DIALOG,FULLSCREEN,FULLSCREEN_DIALOG,TOOLTIP
  2. frame:SetFrameLevel(20) -- 0-20
  Reply With Quote
07-26-16, 11:17 AM   #3
spelgubbe2
A Defias Bandit
Join Date: Jul 2016
Posts: 3
Originally Posted by Resike View Post
You need to increase the frame's strata and/or level:

Lua Code:
  1. frame:SetFrameStrata("HIGH") --BACKGROUND,LOW,MEDIUM,HIGH,DIALOG,FULLSCREEN,FULLSCREEN_DIALOG,TOOLTIP
  2. frame:SetFrameLevel(20) -- 0-20
Thank you so much. I have been struggling so much
  Reply With Quote
07-28-16, 12:38 PM   #4
spelgubbe2
A Defias Bandit
Join Date: Jul 2016
Posts: 3
It seems I have to hook the function to 'PetActionBar_Update' to access the pet action bar, but I am getting some weird LUA error.
Code:
Interface\FrameXML\SecureHandlers.lua:610: Header frame must be explicitly protected
Interface\FrameXML\SecureHandlers.lua:610: in function `SecureHandlerWrapScript'
I found the error specified in here: https://github.com/Ennie/wow-ui-sour...dlers.lua#L596

Can I get around this or is the frame protected and untouchable?


Here is the code:
Code:
hooksecurefunc('PetActionBar_Update', function(button)
	if InCombatLockdown() then return end -- can't hook functions in combat
	if not button.hooked then
		local actionButtonType, key
		actionButtonType = button:GetAttribute('binding') or string.upper(button:GetName())
		actionButtonType = replace(actionButtonType, 'PETACTION', 'BONUSACTION')
		
                local key = GetBindingKey(actionButtonType)
		if key then
			button:RegisterForClicks("AnyDown")
			SetOverrideBindingClick(button, true, key, button:GetName(), "LeftButton")
		end
		button.AnimateThis = animate
                -- the next line causes the error
		SecureHandlerWrapScript(button, "OnClick", button, [[ control:CallMethod("AnimateThis", self) ]])
		button.hooked = true
	end
end)

Last edited by spelgubbe2 : 07-28-16 at 04:59 PM.
  Reply With Quote
08-02-16, 01:18 PM   #5
haylingz
A Kobold Labourer
Join Date: Aug 2016
Posts: 1
Thanks alot for this, i've been looking for this all day!!! You sir made my day.
  Reply With Quote
08-18-16, 11:40 AM   #6
Noxious1899
A Murloc Raider
Join Date: Aug 2016
Posts: 9
Guys if you managed to fix it, could someone post full code please?
  Reply With Quote
08-18-16, 01:29 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by spelgubbe2 View Post
It seems I have to hook the function to 'PetActionBar_Update' to access the pet action bar, but I am getting some weird LUA error.
Maybe I'm missing something, but I don't know why you'd need (or want) to use a secure wrapper to run an animation. Unless you're animating the button itself (as opposed to something on top of the button) you're not doing anything that requires a secure environment.

Try replacing the SecureHandlerWrapScript line with this:
Code:
button:HookScript("OnClick", button.AnimateThis)
However, you didn't post the entire code (or even a link to the unmodified addon, and the addon SnowfallKeyPress that you named doesn't say anything about animations in its description so I'm not sure you got the name right) so the amount of help anyone can provide is limited.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
08-18-16, 01:41 PM   #8
mich125
A Fallenroot Satyr
Join Date: Jan 2010
Posts: 27
Originally Posted by Phanx View Post
Try replacing the SecureHandlerWrapScript line with this:
Code:
button:HookScript("OnClick", button.AnimateThis)
That didn't rly work:

PetActionBarFrame doesn't have a "OnClick" script in function `HookScript'
  Reply With Quote
08-18-16, 02:11 PM   #9
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Okay, looking at the default UI code...

1. You should change that "button" variable in your code to "frame", since it doesn't actually refer to a button object; it refers to the entire PetActionBar frame.

2. A link to the original source of this code would be good, since based on #1 I don't know what the rest of that code in the snippet you posted is supposed to be doing either. Did you by chance remove something that resembled this in that section:

lua Code:
  1. for i=1, NUM_PET_ACTION_SLOTS, 1 do
  2.     local buttonName = "PetActionButton" .. i;

? If so, put it back.

3. Try removing the problem line instead, and adding this at the bottom of your file, outside of any functions, instead:
lua Code:
  1. hooksecurefunc("PetActionButton_OnClick", function(actionButton, mouseButton)
  2.     animate(actionButton)
  3. end)

... but without seeing the rest of the code I can't guarantee that will work.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
08-18-16, 02:42 PM   #10
mich125
A Fallenroot Satyr
Join Date: Jan 2010
Posts: 27
Got it to work perfectly now, thanks bro
  Reply With Quote
08-18-16, 03:39 PM   #11
Noxious1899
A Murloc Raider
Join Date: Aug 2016
Posts: 9
Mich125 can you put the working fullcode pls?
  Reply With Quote
08-18-16, 05:17 PM   #12
Lamebob
A Murloc Raider
Join Date: Jul 2010
Posts: 4
Originally Posted by mich125 View Post
Got it to work perfectly now, thanks bro
Can you post the full thing please?

I used to use another snowfallkeypress script but this patch broke it and really want to use this.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Animation on MultiBars play "behind" the button


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