forked from skennedysocal/WoW_Hardcore
-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathTextureUtils.lua
More file actions
312 lines (293 loc) · 9.11 KB
/
TextureUtils.lua
File metadata and controls
312 lines (293 loc) · 9.11 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
local _G = _G
_G.HCTextureUtils = {}
HCTextureUtils = _G.HCTextureUtils
local animation_frames = {} -- List of frames to animate
-- Update general texture.
-- @param texture A texture object.
-- @param points Points used to position texture.
-- @param texture_info Additional loading, animation, and positioning metadata for specific texture.
function HCTextureUtils.UpdateTexture(texture, points, texture_info)
texture:SetTexture(texture_info.Str)
texture:ClearAllPoints()
for k, v in pairs(points) do
if k == 1 then
texture:SetPoint(
v.Anchor,
v.RelativeFrame,
v.RelativeAnchor,
(v.OffsetX + texture_info.OffsetX_0),
(v.OffsetY + texture_info.OffsetY_0)
)
else
texture:SetPoint(
v.Anchor,
v.RelativeFrame,
v.RelativeAnchor,
(v.OffsetX + texture_info.OffsetX_1),
(v.OffsetY + texture_info.OffsetY_1)
)
end
end
texture:SetTexCoord(
texture_info.TexCoords[1],
texture_info.TexCoords[2],
texture_info.TexCoords[3],
texture_info.TexCoords[4]
)
if PlayerFrame:IsClampedToScreen() == false or force then
PlayerFrame:SetClampedToScreen(true)
end
end
-- Only update texture points and texcoords.
-- @param texture A texture object.
-- @param points Points used to position texture.
-- @param texture_info Additional loading, animation, and positioning metadata for specific texture.
function HCTextureUtils.UpdateTexturePoints(texture, points, texture_info)
texture:ClearAllPoints()
for k, v in pairs(points) do
if k == 1 then
texture:SetPoint(
v.Anchor,
v.RelativeFrame,
v.RelativeAnchor,
(v.OffsetX + texture_info.OffsetX_0),
(v.OffsetY + texture_info.OffsetY_0)
)
else
texture:SetPoint(
v.Anchor,
v.RelativeFrame,
v.RelativeAnchor,
(v.OffsetX + texture_info.OffsetX_1),
(v.OffsetY + texture_info.OffsetY_1)
)
end
end
texture:SetTexCoord(
texture_info.TexCoords[1],
texture_info.TexCoords[2],
texture_info.TexCoords[3],
texture_info.TexCoords[4]
)
end
-- Update general texture' accent.
-- @param texture A texture object.
-- @param points Points used to position texture.
-- @param texture_info Additional loading, animation, and positioning metadata for specific texture.
-- @param color Color to give the texture.
function HCTextureUtils.UpdateAccentTexture(texture, points, texture_info, color)
texture:SetTexture(texture_info.AccentStr)
texture:ClearAllPoints()
for k, v in pairs(points) do
if k == 1 then
texture:SetPoint(
v.Anchor,
v.RelativeFrame,
v.RelativeAnchor,
(v.OffsetX + texture_info.OffsetX_0),
(v.OffsetY + texture_info.OffsetY_0)
)
else
texture:SetPoint(
v.Anchor,
v.RelativeFrame,
v.RelativeAnchor,
(v.OffsetX + texture_info.OffsetX_1),
(v.OffsetY + texture_info.OffsetY_1)
)
end
end
texture:SetTexCoord(
texture_info.TexCoords[1],
texture_info.TexCoords[2],
texture_info.TexCoords[3],
texture_info.TexCoords[4]
)
if PlayerFrame:IsClampedToScreen() == false or force then
PlayerFrame:SetClampedToScreen(true)
end
texture:SetVertexColor(color[1], color[2], color[3], color[4])
end
-- Update location of the level text PlayerLevelText, PlayerFrameSettings.Tables.Points.PlayerLevelText
-- @param display_text Level texture.
-- @param text Texture position.
-- @param texture_info Additional loading, animation, and positioning metadata for specific texture.
function HCTextureUtils.UpdateLevelText(display_text, text, texture_info)
if #text >= 1 then
display_text:ClearAllPoints()
for k, v in pairs(text) do
display_text:SetPoint(
v.Anchor,
v.RelativeFrame,
v.RelativeAnchor,
(v.OffsetX + texture_info.LevelOffsetX),
(v.OffsetY + texture_info.LevelOffsetY)
)
end
end
end
-- Update location of the rest icon
-- @param points Texture position information.
-- @param texture_info Additional loading, animation, and positioning metadata for specific texture.
function HCTextureUtils.UpdatePlayerFrameRestIcon(points, texture_info)
if PlayerFrameSettings.Vars.PlayerLoaded then
for k, v in pairs(points) do
if k == 1 then
PlayerRestIcon:SetPoint(
v.Anchor,
v.RelativeFrame,
v.RelativeAnchor,
(v.OffsetX + texture_info.RestIconOffsetX),
v.OffsetY + texture_info.RestIconOffsetY
)
end
end
end
end
-- [ Animation functions ] --
--
-- Animate the texture by moving TexCoords. Texture should be a sprite map.
-- @param texture Texture to animate. Texture should be a spritemap.
-- @param textureWidth Width of the texture. Used for helping to detect texcoords.
-- @param textureHeight Height of the texture. Used for helping to detect texcoords.
-- @param frameWidth Width of the sprite. Used for helping to detect texcoords.
-- @param frameHeight Height of the sprite. Used for helping to detect texcoords.
-- @param elapsed Time since last update.
-- @param throttle Duration between frames (1/fps)
function HCTextureUtils.AnimateTexCoords(
texture,
textureWidth,
textureHeight,
frameWidth,
frameHeight,
numFrames,
elapsed,
throttle
)
if not texture.frame then
-- initialize everything
texture.frame = 1
texture.throttle = throttle
texture.numColumns = floor(textureWidth / frameWidth)
texture.numRows = floor(textureHeight / frameHeight)
texture.columnWidth = frameWidth / textureWidth
texture.rowHeight = frameHeight / textureHeight
end
local frame = texture.frame
if not texture.throttle or texture.throttle > throttle then
local framesToAdvance = floor(texture.throttle / throttle)
while frame + framesToAdvance > numFrames do
frame = frame - numFrames
end
frame = frame + framesToAdvance
texture.throttle = 0
local left = mod(frame - 1, texture.numColumns) * texture.columnWidth
local right = left + texture.columnWidth
local bottom = ceil(frame / texture.numColumns) * texture.rowHeight
local top = bottom - texture.rowHeight
texture:SetTexCoord(left, right, top, bottom)
texture.frame = frame
else
texture.throttle = texture.throttle + elapsed
end
end
-- Animate active textures which require animation.
-- @param elapsed Time since last update.
function HCTextureUtils.Animate_OnUpdate(elapsed)
for _, v in pairs(animation_frames) do
HCTextureUtils.AnimateTexCoords(
v.Texture,
v.TextureWidth,
v.TextureHeight,
v.SpriteWidth,
v.SpriteHeight,
v.NumFrames,
elapsed,
v.Throttle
)
end
end
-- Add texture to active animation.
-- @param ID Identification of the animation
-- @param InputTexture Texture to animate
-- @param AnimationInfo Animation meta data.
function HCTextureUtils:AddToAnimationFrames(ID, InputTexture, AnimationInfo)
if AnimationInfo ~= nil then
animation_frames[ID] = {
Texture = InputTexture,
TextureWidth = AnimationInfo.TextureWidth,
TextureHeight = AnimationInfo.TextureHeight,
SpriteWidth = AnimationInfo.SpriteWidth,
SpriteHeight = AnimationInfo.SpriteHeight,
NumFrames = AnimationInfo.NumFrames,
Throttle = AnimationInfo.Throttle,
}
else
animation_frames[ID] = nil
end
end
-- Fill out Blizzard texture points from existing frames
-- @param frame_data Reference to FrameData, which holds frame points
-- @param force Fill out point data even if they already have been.
function HCTextureUtils.FillTexturePointsTable(frame_data, force)
if force or frame_data.points == nil then
if UnitExists("player") then
frame_data.points = {}
local points = frame_data.texture:GetNumPoints()
local i = 1
while i <= points do
local anchor, relativeFrame, relativeAnchor, x, y = frame_data.texture:GetPoint(i)
tinsert(frame_data.points, {
["Anchor"] = anchor,
["RelativeFrame"] = relativeFrame,
["RelativeAnchor"] = relativeAnchor,
["OffsetX"] = x,
["OffsetY"] = y,
})
i = i + 1
end
end
end
end
-- Fill out Blizzard level texture points from existing frames
-- @param frame_data Reference to FrameData, which holds frame points
-- @param force Fill out point data even if they already have been.
function HCTextureUtils.FillLevelTextPointsTable(frame_data, force)
if force or frame_data.points == nil then
frame_data.points = {}
TargetFrame.levelText:SetWordWrap(false) -- Todo; remove? move to loaded
local points = frame_data.texture:GetNumPoints()
local i = 1
while i <= points do
local anchor, relativeFrame, relativeAnchor, x, y = frame_data.texture:GetPoint(i)
tinsert(frame_data.points, {
["Anchor"] = anchor,
["RelativeFrame"] = relativeFrame,
["RelativeAnchor"] = relativeAnchor,
["OffsetX"] = x,
["OffsetY"] = y,
})
i = i + 1
end
end
end
-- Fill out Blizzard rest icon texture points from existing frames
-- @param frame_data Reference to FrameData, which holds frame points
function HCTextureUtils.FillRestIconPointsTable(frame_data)
if UnitExists("player") then
frame_data.points = {}
local points = PlayerRestIcon:GetNumPoints()
local i = 1
while i <= points do
local anchor, relativeFrame, relativeAnchor, x, y = PlayerRestIcon:GetPoint(i)
tinsert(frame_data.points, {
["Anchor"] = anchor,
["RelativeFrame"] = relativeFrame,
["RelativeAnchor"] = relativeAnchor,
["OffsetX"] = x,
["OffsetY"] = y,
})
i = i + 1
end
end
end