WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Textanimation (counting upward) (https://www.wowinterface.com/forums/showthread.php?t=54582)

flow0284 10-01-16 04:18 PM

Textanimation (counting upward)
 
Hi there,

has anyone a idea how to make a textanimation like the one in the artifactui?
If the artifactui is opened and you add artifactpower the counter for the available power counts 'animated' upwards.

VincentSDSH 10-01-16 10:20 PM

I don't know how they do it but the general way is to make a box bigger than your fontstring, then position your font string within it in a loop with different coordinate values at increments that match the timing and speed you want.

BigWigs (Messages.lua) might be a good example of how to use animations.

I think the code for what they do is in ArtifactToast.lua, if you unpack the blizzard code.

lightspark 10-01-16 11:50 PM

Use AnimatedNumericFontStringMixin.

flow0284 10-02-16 12:37 PM

Quote:

Originally Posted by lightspark (Post 319590)

Thank you! Now I have to play with it to get it work for me :)

flow0284 10-03-16 07:41 AM

For whatever reason, I have no idea how to use the functions. I might be just too tired or too stupid.

lightspark 10-03-16 08:33 AM

Here's a small demo:

Lua Code:
  1. local frame = CreateFrame("Frame")
  2. local textsToAnimate = {}
  3.  
  4. local function OnUpdate(self, elapsed)
  5.     for _, text in pairs(textsToAnimate) do
  6.         text:UpdateAnimatedValue(elapsed)
  7.     end
  8. end
  9.  
  10. frame:SetScript("OnUpdate", OnUpdate)
  11.  
  12. frame:SetScript("OnEvent", function()
  13.     local text = UIParent:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
  14.     text:SetPoint("CENTER", -128, 64)
  15.     Mixin(text, AnimatedNumericFontStringMixin)
  16.     table.insert(textsToAnimate, text)
  17.  
  18.     text = UIParent:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
  19.     text:SetPoint("CENTER", -128, 32)
  20.     Mixin(text, AnimatedNumericFontStringMixin)
  21.     table.insert(textsToAnimate, text)
  22.  
  23.     text = UIParent:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
  24.     text:SetPoint("CENTER", -128, 0)
  25.     Mixin(text, AnimatedNumericFontStringMixin)
  26.     table.insert(textsToAnimate, text)
  27.  
  28.     text = UIParent:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
  29.     text:SetPoint("CENTER", -128, -32)
  30.     Mixin(text, AnimatedNumericFontStringMixin)
  31.     table.insert(textsToAnimate, text)
  32.  
  33.     C_Timer.NewTicker(2, function()
  34.         for _, text in pairs(textsToAnimate) do
  35.             text:SetAnimatedValue(math.random(10, 10000))
  36.         end
  37.     end)
  38. end)
  39.  
  40. frame:RegisterEvent("PLAYER_LOGIN")

flow0284 10-03-16 09:40 AM

Thank you for the small demo.

I have to ask, could you held me to integrade your demo into my litte addon? I am new in Lua programming. everytime a have time I read tutorial and try to learn but time for that is rare.

In the ArtifactFrame I would see how many Artifactpower was assigned to my weapon, because i like statistics :)

I would animate the assigned artifactpower text when new power was added and the frame was visible. Like the default available artifactpower text.

Lua Code:
  1. AssignedArtifactPower = LibStub("AceAddon-3.0"):NewAddon("Assigned Artifact Power", "AceEvent-3.0")
  2.  
  3. --Make a 'Comma/Point' Value
  4. function AssignedArtifactPower:comma_value(n)
  5.    local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')
  6.    return left..(num:reverse():gsub('(%d%d%d)','%1.'):reverse())..right
  7. end
  8.  
  9. function AssignedArtifactPower:calc_ap()
  10.    local c, ge, gc, xp, ps, n, _ = _G.C_ArtifactUI
  11.    _, _, n, _, xp, ps = c.GetEquippedArtifactInfo()
  12.    for i=1,ps-1 do
  13.       xp = xp + c.GetCostForPointAtRank(i)
  14.    end
  15.    AP = self:comma_value(xp)
  16. end
  17.    
  18. function AssignedArtifactPower:OnEnable()
  19.     self:RegisterEvent("ARTIFACT_UPDATE")
  20.     self:RegisterEvent("ARTIFACT_XP_UPDATE")
  21.     self:RegisterEvent("ARTIFACT_MAX_RANKS_UPDATE")
  22.     self:Refresh()
  23. end
  24.  
  25. function AssignedArtifactPower:ARTIFACT_UPDATE()
  26.     self:Refresh()
  27. end
  28.  
  29. function AssignedArtifactPower:ARTIFACT_XP_UPDATE()
  30.     self:Refresh()
  31. end
  32.  
  33. function AssignedArtifactPower:ARTIFACT_MAX_RANKS_UPDATE()
  34.     self:Refresh()
  35. end
  36.  
  37. function AssignedArtifactPower:Overlay()
  38.     AFP = ArtifactFrame.PerksTab
  39.     if not AFP.AssignedArtifactPower then
  40.         AF = AFP.TitleContainer
  41.         AFPoints = AF.PointsRemainingLabel
  42.         AFLabel = AF.ArtifactPower
  43.         --New Frame for available Artifactpower
  44.         AFP.ArtifactPower = CreateFrame("Frame", "ArtifactPower", AFP)
  45.         AFP.ArtifactPower:SetPoint("TOP", -75, -120, "CENTER")
  46.         AFP.ArtifactPower:SetWidth(150)
  47.         AFP.ArtifactPower:SetHeight(40)
  48.        
  49.         AFLabel:ClearAllPoints()
  50.         AFLabel:SetPoint("TOP", AFP.ArtifactPower, 0, 0, "CENTER")
  51.         AFPoints:ClearAllPoints()
  52.         AFPoints:SetPoint("BOTTOM", AFLabel, 0, -15, "CENTER")
  53.  
  54.         --New Frame for assigned Artifactpower
  55.         AFP.AssignedArtifactPower = CreateFrame("Frame", "AssignedArtifactPower", AFP)
  56.         AFP.AssignedArtifactPower:SetPoint("TOP", 75, -120, "CENTER")
  57.         AFP.AssignedArtifactPower:SetWidth(150)
  58.         AFP.AssignedArtifactPower:SetHeight(40)
  59.  
  60.         tAPL = AFP.AssignedArtifactPower:CreateFontString("ArtifactPowerLabel", "ARTWORK")
  61.         tAPL:SetFont(AFLabel:GetFont())
  62.         tAPL:SetPoint("TOP", AFP.AssignedArtifactPower, 0, 0, "CENTER")
  63.         tAPL:SetTextColor(AFLabel:GetTextColor())
  64.         tAPL:SetText("Assigned")
  65.  
  66.         tAP = AFP.AssignedArtifactPower:CreateFontString("ArtifactPowerPoints", "ARTWORK")
  67.         tAP:SetFont(AFPoints:GetFont())
  68.         tAP:SetPoint("BOTTOM", tAPL, 0, -15, "CENTER")
  69.         tAP:SetTextColor(AFPoints:GetTextColor())
  70.         self:calc_ap()
  71.         tAP:SetText(AP)
  72.        
  73.         AFP.AssignedArtifactPower:SetScript("OnEnter", function(self, motion)
  74.             GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
  75.             GameTooltip:ClearLines()
  76.             GameTooltip:SetText("Total assigned artifact power")
  77.             GameTooltip:AddLine("Resetting your weapons artifact power will reset this counter!", 1, 1, 1)
  78.             GameTooltip:Show()
  79.         end)
  80.  
  81.         AFP.AssignedArtifactPower:SetScript("OnLeave", function(self, motion)
  82.             GameTooltip:Hide()
  83.         end)
  84.  
  85.     else
  86.         self:calc_ap()
  87.         tAP:SetText(AP)
  88.     end
  89. end
  90.  
  91. function AssignedArtifactPower:Refresh()
  92.     if not ArtifactFrame or not ArtifactFrame.PerksTab then return end
  93.     self:Overlay()
  94. end

Of course my code is a bit dirty but it works :)

lightspark 10-03-16 02:46 PM

Lua Code:
  1. AssignedArtifactPower = LibStub("AceAddon-3.0"):NewAddon("Assigned Artifact Power", "AceEvent-3.0")
  2.  
  3. function AssignedArtifactPower:calc_ap()
  4.     local c, ge, gc, xp, ps, n, _ = _G.C_ArtifactUI
  5.     _, _, n, _, xp, ps = c.GetEquippedArtifactInfo()
  6.     for i=1,ps-1 do
  7.         xp = xp + c.GetCostForPointAtRank(i)
  8.     end
  9.     AP = xp
  10. end
  11.  
  12. function AssignedArtifactPower:OnEnable()
  13.     self:RegisterEvent("ARTIFACT_UPDATE")
  14.     self:RegisterEvent("ARTIFACT_XP_UPDATE")
  15.     self:RegisterEvent("ARTIFACT_MAX_RANKS_UPDATE")
  16.     self:Refresh()
  17. end
  18.  
  19. function AssignedArtifactPower:ARTIFACT_UPDATE()
  20.     self:Refresh()
  21. end
  22.  
  23. function AssignedArtifactPower:ARTIFACT_XP_UPDATE()
  24.     self:Refresh()
  25. end
  26.  
  27. function AssignedArtifactPower:ARTIFACT_MAX_RANKS_UPDATE()
  28.     self:Refresh()
  29. end
  30.  
  31. function AssignedArtifactPower:Overlay()
  32.     AFP = ArtifactFrame.PerksTab
  33.     if not AFP.AssignedArtifactPower then
  34.         AF = AFP.TitleContainer
  35.         AFPoints = AF.PointsRemainingLabel
  36.         AFLabel = AF.ArtifactPower
  37.         --New Frame for available Artifactpower
  38.         AFP.ArtifactPower = CreateFrame("Frame", "ArtifactPower", AFP)
  39.         AFP.ArtifactPower:SetPoint("TOP", -75, -120, "CENTER")
  40.         AFP.ArtifactPower:SetWidth(150)
  41.         AFP.ArtifactPower:SetHeight(40)
  42.  
  43.         AFLabel:ClearAllPoints()
  44.         AFLabel:SetPoint("TOP", AFP.ArtifactPower, 0, 0, "CENTER")
  45.         AFPoints:ClearAllPoints()
  46.         AFPoints:SetPoint("BOTTOM", AFLabel, 0, -15, "CENTER")
  47.  
  48.         --New Frame for assigned Artifactpower
  49.         AFP.AssignedArtifactPower = CreateFrame("Frame", "AssignedArtifactPower", AFP)
  50.         AFP.AssignedArtifactPower:SetPoint("TOP", 75, -120, "CENTER")
  51.         AFP.AssignedArtifactPower:SetWidth(150)
  52.         AFP.AssignedArtifactPower:SetHeight(40)
  53.  
  54.         tAPL = AFP.AssignedArtifactPower:CreateFontString("ArtifactPowerLabel", "ARTWORK")
  55.         tAPL:SetFont(AFLabel:GetFont())
  56.         tAPL:SetPoint("TOP", AFP.AssignedArtifactPower, 0, 0, "CENTER")
  57.         tAPL:SetTextColor(AFLabel:GetTextColor())
  58.         tAPL:SetText("Assigned")
  59.  
  60.         tAP = AFP.AssignedArtifactPower:CreateFontString("ArtifactPowerPoints", "ARTWORK")
  61.         Mixin(tAP, AnimatedNumericFontStringMixin)
  62.         tAP:SetFont(AFPoints:GetFont())
  63.         tAP:SetPoint("BOTTOM", tAPL, 0, -15, "CENTER")
  64.         tAP:SetTextColor(AFPoints:GetTextColor())
  65.         self:calc_ap()
  66.         tAP:SetAnimatedValue(0) -- for extra prettiness :p
  67.         tAP:SetAnimatedValue(AP)
  68.  
  69.         -- TBH, it's not the best of setting OnUpdate script, but style is style :p
  70.         -- Read [url]https://www.wowinterface.com/forums/showpost.php?p=257783&postcount=2[/url]
  71.         -- (2) Defining a function inside another function
  72.         AFP.AssignedArtifactPower:SetScript("OnUpdate", function(self, elapsed)
  73.             tAP:UpdateAnimatedValue(elapsed)
  74.         end)
  75.  
  76.         AFP.AssignedArtifactPower:SetScript("OnEnter", function(self, motion)
  77.             GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
  78.             GameTooltip:ClearLines()
  79.             GameTooltip:SetText("Total assigned artifact power")
  80.             GameTooltip:AddLine("Resetting your weapons artifact power will reset this counter!", 1, 1, 1)
  81.             GameTooltip:Show()
  82.         end)
  83.  
  84.         AFP.AssignedArtifactPower:SetScript("OnLeave", function(self, motion)
  85.             GameTooltip:Hide()
  86.         end)
  87.  
  88.     else
  89.         self:calc_ap()
  90.         tAP:SetAnimatedValue(AP)
  91.     end
  92. end
  93.  
  94. function AssignedArtifactPower:Refresh()
  95.     if not ArtifactFrame or not ArtifactFrame.PerksTab then return end
  96.     self:Overlay()
  97. end

As I noted in code comments, setting "OnUpdate" the way I did isn't optimal, like at all... Read this post for more info.

I also hope that tAPL, and many other variables are locals...

flow0284 10-04-16 12:55 PM

Holy sh.t i thank you so much :o


All times are GMT -6. The time now is 02:01 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI