diff --git a/modules/actionbar.lua b/modules/actionbar.lua index 827f13cd..6fc9978d 100644 --- a/modules/actionbar.lua +++ b/modules/actionbar.lua @@ -161,113 +161,83 @@ pfUI:RegisterModule("actionbar", function () [12] = "Pet", } + -- Button animations scale and fade a copy of the icon through keyframes of + -- { duration, scale, alpha, smoothing }. Styles with hideicon hide the icon + -- while the copy plays. local button_animations = { - ["none"] = function() - this.active = nil - this:Hide() - end, - ["zoomfade"] = function() - if this.active == 0 then - -- init animation - this:SetSize(this.parent:GetSize()) - this:SetScale(this.parent:GetScale()) - this.tex:SetTexture(this.parent.icon:GetTexture()) - this.tex:SetVertexColor(this.parent.icon:GetVertexColor()) - this:SetAlpha(1) - this.active = 1 - return - elseif this.active == 1 then - -- run animation - local fade = 30/GetFramerate()*0.05 - this:SetAlpha(this:GetAlpha() - fade) - this:SetScale(this:GetScale() + fade) - if this:GetAlpha() > 0 then return end - end - - -- stop animation - this.active = nil - this:Hide() - end, - ["shrinkreturn"] = function() - if this.active == 0 then - -- init animation - this:SetSize(this.parent:GetSize()) - this:SetScale(this.parent:GetScale()) - this.tex:SetTexture(this.parent.icon:GetTexture()) - this.tex:SetVertexColor(this.parent.icon:GetVertexColor()) - this:SetAlpha(1) - this.parent.icon:Hide() - this.active = 1 - this.time = 0 - return - elseif this.active == 1 then - -- run animation - this.time = this.time + 30/GetFramerate()*0.1 - local fade = 1 -math.exp(-this.time)*math.sin(this.time*math.pi) - this:SetAlpha(fade) - this:SetScale(fade) - if this.time < 1 then return end - end - - -- stop animation - this.active = nil - this:Hide() - this.parent.icon:Show() - end, - ["elasticzoom"] = function() - if this.active == 0 then - -- init animation - this:SetSize(this.parent:GetSize()) - this:SetScale(this.parent:GetScale()) - this.tex:SetTexture(this.parent.icon:GetTexture()) - this.tex:SetVertexColor(this.parent.icon:GetVertexColor()) - this:SetAlpha(1) - this.parent.icon:Hide() - this.active = 1 - this.time = 0 - return - elseif this.active == 1 then - -- run animation - this.time = this.time + 30/GetFramerate()*0.03 - local fade = 1 -math.exp(-this.time*6)*math.sin(this.time*4*math.pi) - this:SetAlpha(fade) - this:SetScale(fade) - if this.time < 1 then return end - end - - -- stop animation - this.active = nil - this:Hide() - this.parent.icon:Show() - end, - ["wobblezoom"] = function() - if this.active == 0 then - -- init animation - this:SetSize(this.parent:GetSize()) - this:SetScale(this.parent:GetScale()) - this.tex:SetTexture(this.parent.icon:GetTexture()) - this.tex:SetVertexColor(this.parent.icon:GetVertexColor()) - this:SetAlpha(1) - this.parent.icon:Hide() - this.active = 1 - this.time = 0 - return - elseif this.active == 1 then - -- run animation - this.time = this.time + 30/GetFramerate()*0.02 - local fade = 1 -math.exp(-this.time*6)*math.sin(this.time*10*math.pi) - this:SetAlpha(fade) - this:SetScale(fade) - if this.time < 1 then return end - end - - -- stop animation - this.active = nil - this:Hide() - this.parent.icon:Show() - end, + ["zoomfade"] = { + { .67, 2, 0, "NONE" }, + }, + ["shrinkreturn"] = { hideicon = true, + { .13, .36, .36, "OUT" }, + { .2, 1, 1, "IN" }, + }, + ["elasticzoom"] = { hideicon = true, + { .1, .47, .47, "OUT" }, + { .28, 1.12, 1, "IN_OUT" }, + { .28, .97, .97, "IN_OUT" }, + { .46, 1, 1, "IN_OUT" }, + }, + ["wobblezoom"] = { hideicon = true, + { .07, .25, .25, "OUT" }, + { .17, 1.41, 1, "IN_OUT" }, + { .17, .77, .77, "IN_OUT" }, + { .17, 1.12, 1, "IN_OUT" }, + { .17, .93, .93, "IN_OUT" }, + { .17, 1.04, 1, "IN_OUT" }, + { .17, .98, .98, "IN_OUT" }, + { .59, 1, 1, "IN_OUT" }, + }, } + local function CreateButtonAnimation(button, style) + local group = button.animation.tex:CreateAnimationGroup() + group:SetIgnoreFramerateThrottle(true) + + local scale, alpha = 1, 1 + for order, key in ipairs(style) do + local duration, nextscale, nextalpha, smoothing = unpack(key) + + local zoom = group:CreateAnimation("Scale") + zoom:SetOrder(order) + zoom:SetDuration(duration) + zoom:SetSmoothing(smoothing) + zoom:SetScale(nextscale / scale, nextscale / scale) + + local fade = group:CreateAnimation("Alpha") + fade:SetOrder(order) + fade:SetDuration(duration) + fade:SetSmoothing(smoothing) + fade:SetChange(nextalpha - alpha) + + scale, alpha = nextscale, nextalpha + end + + local function Done() + button.animation:Hide() + button.icon:Show() + end + group:SetScript("OnFinished", Done) + group:SetScript("OnStop", Done) + + return group + end + + local function PlayButtonAnimation(button) + local style = button_animations[C.bars.animation] + if not style then return end + + local animation = button.animation + animation.groups[style] = animation.groups[style] or CreateButtonAnimation(button, style) + + animation.tex:StopAnimating() + animation.tex:SetTexture(button.icon:GetTexture()) + animation.tex:SetVertexColor(button.icon:GetVertexColor()) + animation:Show() + if style.hideicon then button.icon:Hide() end + animation.groups[style]:Play() + end + local function GetActiveBar() if CURRENT_ACTIONBAR_PAGE == 1 and GetBonusBarOffset() ~= 0 then return NUM_ACTIONBAR_PAGES + GetBonusBarOffset() @@ -310,8 +280,7 @@ pfUI:RegisterModule("actionbar", function () -- trigger action animation if ( pfUI_config.bars.keydown == "1" and keystate == "down" ) or (pfUI_config.bars.keydown == "0" and keystate == "up" ) or self.bar == 11 or mouse then if C.bars.animmode == "keypress" and ( self:GetAlpha() > .1 or C.bars.animalways == "1" ) then - self.animation.active = 0 - self.animation:Show() + PlayButtonAnimation(self) end end @@ -461,8 +430,7 @@ pfUI:RegisterModule("actionbar", function () -- active border if active then if C.bars.animmode == "statechange" and not self.active:IsShown() then - self.animation.active = 0 - self.animation:Show() + PlayButtonAnimation(self) end self.backdrop:SetBackdropBorderColor(cr,cg,cb,1) @@ -1038,8 +1006,8 @@ pfUI:RegisterModule("actionbar", function () -- animation f.animation = CreateFrame("Frame", button_name .. "Animation", f) - f.animation.parent = f - f.animation:SetPoint("CENTER", 0, 0) + f.animation.groups = {} + f.animation:SetAllPoints() f.animation:Hide() f.animation.tex = f.animation:CreateTexture(button_name .. "AnimationTexture", "BACKGROUND") f.animation.tex:SetTexCoord(.08, .92, .08, .92) @@ -1098,9 +1066,6 @@ pfUI:RegisterModule("actionbar", function () f:RegisterForClicks("LeftButtonUp", "RightButtonUp") end - -- set animation - f.animation:SetScript("OnUpdate", button_animations[C.bars.animation]) - -- pet autocast if bar == 12 then f.autocast:SetScale(C.bars["bar"..bar].icon_size / 25)