-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBearEmotesAnimator.lua
More file actions
155 lines (133 loc) · 6.29 KB
/
BearEmotesAnimator.lua
File metadata and controls
155 lines (133 loc) · 6.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
local BEAREMOTES_TimeSinceLastUpdate = 0
local BEAREMOTES_T = 0;
local issecretvalue = issecretvalue or function()
return false
end
function BearEmotesAnimator_OnUpdate(self, elapsed)
if (BEAREMOTES_TimeSinceLastUpdate >= 0.033) then
-- Update animated emotes in chat windows
for _, frameName in pairs(CHAT_FRAMES) do
for _, visibleLine in ipairs(_G[frameName].visibleLines) do
if (_G[frameName]:IsShown() and visibleLine.messageInfo ~= BearEmotes_HoverMessageInfo) then
BearEmotesAnimator_UpdateEmoteInFontString(visibleLine, 28, 28);
end
end
end
-- Update animated emotes in suggestion list
if (EditBoxAutoCompleteBox and EditBoxAutoCompleteBox:IsShown() and
EditBoxAutoCompleteBox.existingButtonCount ~= nil) then
for i = 1, EditBoxAutoCompleteBox.existingButtonCount do
local cBtn = EditBoxAutoComplete_GetAutoCompleteButton(i);
if (cBtn:IsVisible()) then
BearEmotesAnimator_UpdateEmoteInFontString(cBtn, 16, 16);
else
break
end
end
end
-- Update animated emotes in statistics screen
if (BearStatsScreen:IsVisible()) then
local topSentImagePath = BearEmotes_defaultpack[BearEmoteSentStatKeys[1]] or "Interface\\AddOns\\BearEmotes\\Emotes\\beargun.tga:28:28";
local animdata = BearEmotes_animation_metadata[topSentImagePath:match("(Interface\\AddOns\\BearEmotes\\Emotes.-.tga)")]
if (animdata ~= nil) then
local cFrame = BearEmotes_GetCurrentFrameNum(animdata)
BearStatsScreen.topSentEmoteTexture:SetTexCoord(BearEmotes_GetTexCoordsForFrame(animdata, cFrame))
end
local topSeenImagePath = BearEmotes_defaultpack[BearEmoteRecievedStatKeys[1]] or "Interface\\AddOns\\BearEmotes\\Emotes\\beargun.tga:28:28";
animdata = BearEmotes_animation_metadata[topSeenImagePath:match("(Interface\\AddOns\\BearEmotes\\Emotes.-.tga)")]
if (animdata ~= nil) then
local cFrame = BearEmotes_GetCurrentFrameNum(animdata)
BearStatsScreen.topSeenEmoteTexture:SetTexCoord(BearEmotes_GetTexCoordsForFrame(animdata, cFrame))
end
for line = 1, 17 do
local sentEntry = getglobal("BearStatsSentEntry" .. line)
local recievedEntry = getglobal("BearStatsRecievedEntry" .. line)
if (sentEntry:IsVisible()) then
BearEmotesAnimator_UpdateEmoteInFontString(sentEntry, 16, 16);
end
if (recievedEntry:IsVisible()) then
BearEmotesAnimator_UpdateEmoteInFontString(recievedEntry, 16, 16);
end
end
end
BEAREMOTES_TimeSinceLastUpdate = 0;
end
BEAREMOTES_T = BEAREMOTES_T + elapsed
BEAREMOTES_TimeSinceLastUpdate = BEAREMOTES_TimeSinceLastUpdate + elapsed;
end
local function escpattern(x)
return (
x:gsub('%+', '%%+')
:gsub('%-', '%%-')
)
end
-- This will update the texture escape sequence of an animated emote
-- if it exists in the contents of the fontstring.
function BearEmotesAnimator_UpdateEmoteInFontString(fontstring, widthOverride, heightOverride)
local txt = fontstring:GetText();
if issecretvalue(txt) == true then
return
end
if (txt ~= nil) then
for emoteTextureString in txt:gmatch("(|TInterface\\AddOns\\BearEmotes\\Emotes.-|t)") do
local imagepath = emoteTextureString:match("|T(Interface\\AddOns\\BearEmotes\\Emotes.-.tga).-|t")
local animdata = BearEmotes_animation_metadata[imagepath];
if (animdata ~= nil) then
local framenum = BearEmotes_GetCurrentFrameNum(animdata);
local nTxt;
if (widthOverride ~= nil or heightOverride ~= nil) then
nTxt = txt:gsub(
escpattern(emoteTextureString),
BearEmotes_BuildEmoteFrameStringWithDimensions(imagepath, animdata, framenum, widthOverride, heightOverride)
)
else
nTxt = txt:gsub(
escpattern(emoteTextureString),
BearEmotes_BuildEmoteFrameString(imagepath, animdata, framenum)
)
end
if (fontstring.messageInfo ~= nil) then
fontstring.messageInfo.message = nTxt
end
fontstring:SetText(nTxt);
txt = nTxt;
end
end
end
end
function BearEmotes_GetAnimData(imagepath)
return BearEmotes_animation_metadata[imagepath]
end
function BearEmotes_GetCurrentFrameNum(animdata)
if (animdata.pingpong) then
local vframen = math.floor((BEAREMOTES_T * animdata.framerate) % ((animdata.nFrames * 2) - 1));
if vframen > animdata.nFrames then
vframen = animdata.nFrames - (vframen % animdata.nFrames)
end
return vframen
end
return math.floor((BEAREMOTES_T * animdata.framerate) % animdata.nFrames);
end
function BearEmotes_GetTexCoordsForFrame(animdata, framenum)
local fHeight = animdata.frameHeight;
return 0, 1, framenum * fHeight / animdata.imageHeight, ((framenum * fHeight) + fHeight) / animdata.imageHeight
end
function BearEmotes_BuildEmoteFrameString(imagepath, animdata, framenum)
local top = framenum * animdata.frameHeight;
local bottom = top + animdata.frameHeight;
local emoteStr = "|T" .. imagepath .. ":" .. animdata.frameWidth .. ":" ..
animdata.frameHeight .. ":0:0:" .. animdata.imageWidth ..
":" .. animdata.imageHeight .. ":0:" ..
animdata.frameWidth .. ":" .. top .. ":" .. bottom ..
"|t";
return emoteStr
end
function BearEmotes_BuildEmoteFrameStringWithDimensions(imagepath, animdata, framenum, framewidth, frameheight)
local top = framenum * animdata.frameHeight;
local bottom = top + animdata.frameHeight;
local emoteStr = "|T" .. imagepath .. ":" .. framewidth .. ":" ..
frameheight .. ":0:0:" .. animdata.imageWidth .. ":" ..
animdata.imageHeight .. ":0:" .. animdata.frameWidth ..
":" .. top .. ":" .. bottom .. "|t";
return emoteStr
end