Gello,
Here is the complete code that, from using your code as a template, I’ve implemented to display floating combat text. These functions and variables that support them are defined in FloatingText.lua. Of course, any fubar code is mine, not yours.
The last problem (I think) to be solved is how to setup updateAnimation() and C_Timer:After() such that the text will print individually and not on top of one another.
Oh, and thanks for the explanation of the duration and distance parameters to updateAnimation(). Makes perfect sense, now. But, now I have a question about the Animation:Play() function. When f.animGroup:Play() is invoked, I presume that it accesses the animation configuration to determine how the animation is to proceed. What I don’t understand is how does the function (:Play()) know to animate the f.Text:GetText() string?
Here are the variables global within the module (FloatingText.lua):
local DEFAULT_STARTING_REGION = ft.DEFAULT_STARTING_REGION
local DEFAULT_STARTING_XPOS = ft.DEFAULT_STARTING_XPOS
local DEFAULT_STARTING_YPOS = ft.DEFAULT_STARTING_YPOS
local framePool = CreateFramePool(“Frame”, UIParent, “BackdropTemplate”)
Here is the configAnimation() function (essentially your animate() function renamed):
local function configAnimation(f)
f.animGroup = f:CreateAnimationGroup()
f.animGroup.fadein = f.animGroup:CreateAnimation("alpha")
f.animGroup.fadein:SetFromAlpha(0)
f.animGroup.fadein:SetToAlpha(1)
f.animGroup.fadein:SetOrder(1)
f.animGroup.movein = f.animGroup:CreateAnimation("translation")
f.animGroup.movein:SetOrder(1)
f.animGroup.move = f.animGroup:CreateAnimation("translation")
f.animGroup.move:SetOrder(2)
f.animGroup.fadeout = f.animGroup:CreateAnimation("alpha")
f.animGroup.fadeout:SetFromAlpha(1)
f.animGroup.fadeout:SetToAlpha(0)
f.animGroup.fadeout:SetOrder(3)
f.animGroup.moveout = f.animGroup:CreateAnimation("translation")
f.animGroup.moveout:SetOrder(3)
-- hide and release the frame when animation ends
f.animGroup:SetScript("OnFinished",
function(self)
self:GetParent():Hide()
framePool:Release(f)
end)
end
And now the getframe() function:
function ft:getFrame( region, startingXpos, startingYpos)
f = framePool:Acquire()
f.Text = f:CreateFontString(nil,"ARTWORK","GameFontNormalLarge")
f.Text:SetPoint("LEFT", 0, 0 )
f:SetSize(400,30)
-- When the frame is created f.SetPoint() is the starting position
if startingXpos == nil then startingXpos = DEFAULT_STARTING_XPOS end
if startingYpos == nil then startingYpos = DEFAULT_STARTING_YPOS end
f:SetPoint(region, startingXpos, startingYpos )
f:SetAlpha(0)
f.ScrollXMax = (UIParent:GetWidth() * UIParent:GetEffectiveScale())/2
f.ScrollYMax = (UIParent:GetHeight() * UIParent:GetEffectiveScale())/2
configAnimation(f)
f:Show()
return f
end
And finally the function that displays the text.
function ft:displayText(f, threatTable )
local str = {}
for i, entry in ipairs( threatTable ) do
f.Text:SetText( entry[2] )
local duration = 12
local Xdistance = 0
local Ydistance = f.ScrollYMax -- ScrollYMax = 384
updateAnimation(f, duration, Xdistance, Ydistance )
local delay = (i - 1)/2
C_Timer.After( delay,
function()
f.animGroup:Play()
end)
end
end
Finally, to display the text, ft:displayThreatTable called from the “UNIT_THREAT_LIST_UPDATE” handler after all the relevant data has been collected.
local f = ft:getFrame( "CENTER", DEFAULT_STARTING_XPOS, DEFAULT_STARTING_YPOS )
ft:displayThreatTable(f, threatTable )
One final note: I test this by taking a party of 2 of my 60s into Draenor and letting the elites bang on 'em. The team generates lots of threat (they’re disarmed and hit with their fists), Even a 60 takes a long time to kill a 40 elite with just its fists, so it’s a good test.
cheers,
Edit: I placed some logging code into the C_Timer.After() function:
C_Timer.After( (i - 1)/2 + 1,
function()
msg:postMsg( sprintf("%0.1f : %s\n", delay, f.Text:GetText() ))
f.animGroup:Play()
end)
Here were the results:
1.0 : Shadowraîth: 36235 threat generated (89.4% of 40541)
1.0 : Shadowraîth: 72470 threat generated (89.4% of 81082)
1.5 : Zippora: 4306 threat generated (10.6% of 40541)
1.5 : Zippora: 8612 threat generated (10.6% of 81082)
2.0 : Shadowraîth: 36235 threat generated (89.4% of 40541)
2.0 : Shadowraîth: 72470 threat generated (89.4% of 81082)
2.5 : Zippora: 8612 threat generated (10.6% of 81082)
2.5 : Zippora: 4306 threat generated (10.6% of 40541)
I’m curious why 2 lines of text get written at each time interval? Wouldn’t this explain the overlapping lines of text?
ddd