-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathalpha.lua
More file actions
352 lines (317 loc) · 11.4 KB
/
alpha.lua
File metadata and controls
352 lines (317 loc) · 11.4 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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
local _, MoveAny = ...
local dufloaded = false
local MAAF = {}
local alphasReady = false
local isresting = nil
local ismounted = nil
local isskyriding = nil
local invehicle = nil
local incombat = nil
local inpetbattle = nil
local isstealthed = nil
local lEle = nil
local lastEle = nil
local fullHP = false
local enumAlpha = {}
enumAlpha.INIT = "INIT"
enumAlpha.ADDED = "ADDED"
enumAlpha.COMBAT = "COMBAT"
enumAlpha.RESTING = "RESTING"
enumAlpha.FULLHEALTH = "FULLHEALTH"
enumAlpha.AURA = "AURA"
enumAlpha.VEHICLE = "VEHICLE"
enumAlpha.PETBATTLE = "PETBATTLE"
enumAlpha.OLD = "OLD"
function MoveAny:GetEnumAlpha()
return enumAlpha
end
function MoveAny:GetAlphaFrames()
return MAAF
end
function MoveAny:SetEleAlpha(ele, alpha)
if ele and ele:GetAlpha() ~= alpha then
ele:SetAlpha(alpha)
end
end
function MoveAny:IsInPetBattle()
local inPetBattle = false
if C_PetBattles then
inPetBattle = C_PetBattles.IsInBattle()
end
return inPetBattle
end
function MoveAny:IsChatClosed()
for i = 1, 12 do
if _G["ChatFrame" .. i .. "EditBox"] and _G["ChatFrame" .. i .. "EditBox"]:HasFocus() then return false end
end
return true
end
function MoveAny:CurrentChatTab()
for i = 1, 12 do
local ct = _G["ChatFrame" .. i .. "EditBox"]
if ct and ct:IsShown() then return i end
end
return 0
end
function MoveAny:IsDragonriding()
return GetBonusBarIndex() == 11 and GetBonusBarOffset() == 5
end
function MoveAny:UpdateAlphaCombat(inCom)
if incombat ~= inCom then
incombat = inCom
MoveAny:SafeUpdateAlphas(MoveAny:GetEnumAlpha().COMBAT)
end
end
function MoveAny:InitAlphaCombat()
MoveAny:UpdateAlphaCombat(InCombatLockdown())
local alphaFrameCombat = CreateFrame("Frame")
MoveAny:RegisterEvent(alphaFrameCombat, "PLAYER_REGEN_DISABLED")
MoveAny:RegisterEvent(alphaFrameCombat, "PLAYER_REGEN_ENABLED")
MoveAny:OnEvent(
alphaFrameCombat,
function(sel, event, ...)
if event == "PLAYER_REGEN_DISABLED" then
MoveAny:UpdateAlphaCombat(true)
else
MoveAny:UpdateAlphaCombat(false)
end
end, "alphaFrameCombat"
)
end
function MoveAny:UpdateAlphaResting()
if IsResting and isresting ~= IsResting() then
isresting = IsResting()
MoveAny:SafeUpdateAlphas(MoveAny:GetEnumAlpha().RESTING)
end
end
function MoveAny:InitAlphaResting()
MoveAny:UpdateAlphaResting()
local alphaFrameResting = CreateFrame("Frame")
MoveAny:RegisterEvent(alphaFrameResting, "PLAYER_UPDATE_RESTING")
MoveAny:OnEvent(
alphaFrameResting,
function(sel, event, ...)
MoveAny:UpdateAlphaResting()
end, "alphaFrameResting"
)
end
function MoveAny:UpdateAlphaFullHealth()
if MoveAny:GetWoWBuildNr() >= 120000 then return end
if fullHP ~= (UnitHealth("player") >= UnitHealthMax("player")) then
fullHP = UnitHealth("player") >= UnitHealthMax("player")
MoveAny:SafeUpdateAlphas(MoveAny:GetEnumAlpha().FULLHEALTH)
end
end
function MoveAny:InitAlphaFullHealth()
local alphaFrameHealth = CreateFrame("Frame")
MoveAny:RegisterEvent(alphaFrameHealth, "UNIT_HEALTH", "player")
MoveAny:OnEvent(
alphaFrameHealth,
function(sel, event, ...)
if MoveAny:GetWoWBuildNr() >= 120000 then return end
MoveAny:UpdateAlphaFullHealth()
end, "alphaFrameHealth"
)
end
function MoveAny:UpdateAlphaAura()
local updateAlpha = false
if MoveAny.IsDragonriding and isskyriding ~= MoveAny:IsDragonriding() then
isskyriding = MoveAny:IsDragonriding()
updateAlpha = true
end
if IsMounted and ismounted ~= IsMounted() then
ismounted = IsMounted()
updateAlpha = true
end
if IsStealthed and isstealthed ~= IsStealthed() then
isstealthed = IsStealthed()
updateAlpha = true
end
if updateAlpha then
MoveAny:SafeUpdateAlphas(MoveAny:GetEnumAlpha().AURA)
end
end
function MoveAny:InitAlphaAura()
MoveAny:UpdateAlphaAura()
local alphaFrameAura = CreateFrame("Frame")
MoveAny:RegisterEvent(alphaFrameAura, "UNIT_AURA", "player")
MoveAny:OnEvent(
alphaFrameAura,
function(sel, event, ...)
MoveAny:UpdateAlphaAura()
end, "alphaFrameAura"
)
end
function MoveAny:UpdateAlphaVehicle()
if UnitInVehicle and invehicle ~= UnitInVehicle("player") then
invehicle = UnitInVehicle("player")
MoveAny:SafeUpdateAlphas(MoveAny:GetEnumAlpha().VEHICLE)
end
end
function MoveAny:InitAlphaVehicle()
MoveAny:UpdateAlphaVehicle()
local alphaFrameVehicle = CreateFrame("Frame")
MoveAny:RegisterEvent(alphaFrameVehicle, "UNIT_ENTERED_VEHICLE")
MoveAny:RegisterEvent(alphaFrameVehicle, "UNIT_EXITED_VEHICLE")
MoveAny:OnEvent(
alphaFrameVehicle,
function(sel, event, ...)
MoveAny:UpdateAlphaVehicle()
end, "alphaFrameVehicle"
)
end
function MoveAny:UpdateAlphaPetBattle()
if MoveAny.IsInPetBattle and inpetbattle ~= MoveAny:IsInPetBattle() then
inpetbattle = MoveAny:IsInPetBattle()
MoveAny:SafeUpdateAlphas(MoveAny:GetEnumAlpha().PETBATTLE)
end
end
function MoveAny:InitAlphaPetBattle()
MoveAny:UpdateAlphaPetBattle()
local alphaFramePetBattle = CreateFrame("Frame")
MoveAny:RegisterEvent(alphaFramePetBattle, "PET_BATTLE_CLOSE")
MoveAny:RegisterEvent(alphaFramePetBattle, "PET_BATTLE_OPENING_DONE")
MoveAny:RegisterEvent(alphaFramePetBattle, "PET_BATTLE_OVER")
MoveAny:OnEvent(
alphaFramePetBattle,
function(sel, event, ...)
MoveAny:UpdateAlphaPetBattle()
end, "alphaFramePetBattle"
)
end
function MoveAny:InitAlphas()
MoveAny:InitAlphaCombat()
MoveAny:InitAlphaResting()
MoveAny:InitAlphaFullHealth()
MoveAny:InitAlphaAura()
MoveAny:InitAlphaVehicle()
MoveAny:InitAlphaPetBattle()
MoveAny:CheckAlphas()
dufloaded = MoveAny:IsAddOnLoaded("DUnitFrames")
alphasReady = true
MoveAny:SafeUpdateAlphas(MoveAny:GetEnumAlpha().INIT)
end
function MoveAny:SetMouseEleAlpha(ele, last)
xpcall(
function()
MoveAny:UpdateAlphas("SETMOUSEELE", ele, lastEle)
lastEle = last
end, function(err) end
)
end
function MoveAny:CheckAlphas()
xpcall(
function()
local ele = MoveAny:GetMouseFocus()
local eleID = ele.GetDebugName and ele:GetDebugName()
if lEle == nil or (eleID and lEle ~= eleID) then
if ele and ele ~= CompactRaidFrameManager then
if ele and (ele == WorldFrame or ele == UIParent) and lastEle ~= nil and ele ~= lastEle then
MoveAny:SetMouseEleAlpha(ele, nil)
end
if ele ~= WorldFrame and ele ~= UIParent and (not dufloaded or (dufloaded and ele ~= PlayerFrame and ele ~= TargetFrame and ele.GetMAEle and ele:GetMAEle() and ele:GetMAEle() ~= PlayerFrame and ele:GetMAEle() ~= TargetFrame)) then
if tContains(MoveAny:GetAlphaFrames(), ele) then
ele:SetAlpha(1)
MoveAny:SetMouseEleAlpha(ele, ele)
elseif ele.GetMAEle then
ele = ele:GetMAEle()
if ele then
ele:SetAlpha(1)
MoveAny:SetMouseEleAlpha(ele, ele)
end
elseif lastEle then
MoveAny:SetMouseEleAlpha(ele, nil)
end
end
elseif lastEle ~= nil then
MoveAny:SetMouseEleAlpha(ele, nil)
end
end
end, function(err) end
)
MoveAny:After(
0.09,
function()
MoveAny:CheckAlphas()
end, "CheckAlphas"
)
end
function MoveAny:UpdateAlpha(ele, mouseEle)
if ele == nil then
MoveAny:MSG("UpdateAlphas: ele is nil")
else
local name = MoveAny:GetFrameName(ele)
if name ~= nil then
local alphaInCombat = MoveAny:GetEleOption(name, "ALPHAINCOMBAT", 1, "Alpha1")
local alphaIsFullHealth = MoveAny:GetEleOption(name, "ALPHAISFULLHEALTH", 1, "Alpha2")
local alphaInVehicle = MoveAny:GetEleOption(name, "ALPHAINVEHICLE", 1, "Alpha3")
local alphaIsMounted = MoveAny:GetEleOption(name, "ALPHAISMOUNTED", 1, "Alpha4")
local alphaInRestedArea = MoveAny:GetEleOption(name, "ALPHAINRESTEDAREA", 1, "Alpha5")
local alphaIsStealthed = MoveAny:GetEleOption(name, "ALPHAISSTEALTHED", 1, "Alpha6")
local alphaIsInPetBattle = MoveAny:GetEleOption(name, "ALPHAISINPETBATTLE", 1, "Alpha7")
local alphaNotInCombat = MoveAny:GetEleOption(name, "ALPHANOTINCOMBAT", 1, "Alpha8")
local alphaSkyriding = MoveAny:GetEleOption(name, "ALPHAISSKYRIDING", 1, "Alpha9")
if not dufloaded or (dufloaded and ele ~= PlayerFrame and ele ~= TargetFrame) then
if ele.ma_show ~= nil and ele.ma_show == false then
MoveAny:SetEleAlpha(ele, 0)
elseif MoveAny.IsInPetBattle and MoveAny:IsInPetBattle() then
MoveAny:SetEleAlpha(ele, alphaIsInPetBattle)
elseif ele == mouseEle then
MoveAny:SetEleAlpha(ele, 1)
elseif incombat then
MoveAny:SetEleAlpha(ele, alphaInCombat)
elseif MoveAny:GetEleOption(name, "FULLHPENABLED", false, "fullhp2") and UnitHealth("player") >= UnitHealthMax("player") then
MoveAny:SetEleAlpha(ele, alphaIsFullHealth)
elseif UnitInVehicle and invehicle then
MoveAny:SetEleAlpha(ele, alphaInVehicle)
elseif isskyriding then
MoveAny:SetEleAlpha(ele, alphaSkyriding)
elseif IsMounted and ismounted then
MoveAny:SetEleAlpha(ele, alphaIsMounted)
elseif IsResting and isresting then
MoveAny:SetEleAlpha(ele, alphaInRestedArea)
elseif IsStealthed and isstealthed then
MoveAny:SetEleAlpha(ele, alphaIsStealthed)
elseif not incombat then
MoveAny:SetEleAlpha(ele, alphaNotInCombat)
end
end
end
end
end
local timeStampAlpha = 0
local retryAlpha = false
local delayAlpha = 0.08
function MoveAny:SafeUpdateAlphas(from, mouseEle, lastMouseEle)
if timeStampAlpha >= GetTime() then
retryAlpha = true
return
end
retryAlpha = false
timeStampAlpha = GetTime() + delayAlpha
MoveAny:UpdateAlphas(from, mouseEle, lastMouseEle)
MoveAny:After(
delayAlpha + 0.02,
function()
if retryAlpha then
retryAlpha = false
MoveAny:SafeUpdateAlphas(from, mouseEle, lastMouseEle)
end
end, "retryAlpha"
)
end
function MoveAny:UpdateAlphas(from, mouseEle, lastMouseEle)
if not alphasReady then return end
if mouseEle or lastMouseEle then
if mouseEle then
MoveAny:UpdateAlpha(mouseEle, mouseEle)
end
if lastMouseEle then
MoveAny:UpdateAlpha(lastMouseEle, mouseEle)
end
else
for i, ele in pairs(MoveAny:GetAlphaFrames()) do
MoveAny:UpdateAlpha(ele, mouseEle)
end
end
end