forked from Sidoine/Ovale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpellFlash.lua
355 lines (334 loc) · 10.1 KB
/
SpellFlash.lua
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
353
354
355
--[[--------------------------------------------------------------------
Copyright (C) 2014, 2015 Johnny C. Lam.
See the file LICENSE.txt for copying permission.
--]]--------------------------------------------------------------------
local OVALE, Ovale = ...
local OvaleSpellFlash = Ovale:NewModule("OvaleSpellFlash", "AceEvent-3.0")
Ovale.OvaleSpellFlash = OvaleSpellFlash
--<private-static-properties>
local L = Ovale.L
local OvaleOptions = Ovale.OvaleOptions
-- Forward declarations for module dependencies.
local OvaleData = nil
local OvaleFuture = nil
local OvaleSpellBook = nil
local OvaleStance = nil
local pairs = pairs
local type = type
local API_GetTime = GetTime
local API_UnitHasVehicleUI = UnitHasVehicleUI
local API_UnitExists = UnitExists
local API_UnitIsDead = UnitIsDead
local API_UnitCanAttack = UnitCanAttack
-- GLOBALS: _G
-- Local reference to SpellFlashCore addon.
local SpellFlashCore = nil
-- Flash colors.
local colorMain = {}
local colorShortCd = {}
local colorCd = {}
local colorInterrupt = {}
-- Map icon help text to a flash color.
local FLASH_COLOR = {
main = colorMain,
cd = colorCd,
shortcd = colorCd,
}
-- Standard colors defined by SpellFlashCore.
local COLORTABLE = {
aqua = { r = 0, g = 1, b = 1 },
blue = { r = 0, g = 0, b = 1 },
gray = { r = 0.5, g = 0.5, b = 0.5 },
green = { r = 0.1, g = 1, b = 0.1 },
orange = { r = 1, g = 0.5, b = 0.25 },
pink = { r = 0.9, g = 0.4, b = 0.4 },
purple = { r = 1, g = 0, b = 1 },
red = { r = 1, g = 0.1, b = 0.1 },
white = { r = 1, g = 1, b = 1 },
yellow = { r = 1, g = 1, b = 0 },
}
do
local defaultDB = {
-- Store all SpellFlash settings into a separate table.
spellFlash = {
brightness = 1,
enabled = true,
hasHostileTarget = false,
hasTarget = false,
hideInVehicle = false,
inCombat = false,
size = 2.4,
threshold = 500,
colorMain = { r = 1, g = 1, b = 1 }, -- white
colorShortCd = { r = 1, g = 1, b = 0 }, -- yellow
colorCd = { r = 1, g = 1, b = 0 }, -- yellow
colorInterrupt = { r = 0, g = 1, b = 1 }, -- aqua
},
}
local options = {
spellFlash = {
type = "group",
name = "SpellFlash",
disabled = function()
return not SpellFlashCore
end,
get = function(info)
return Ovale.db.profile.apparence.spellFlash[info[#info]]
end,
set = function(info, value)
Ovale.db.profile.apparence.spellFlash[info[#info]] = value
OvaleOptions:SendMessage("Ovale_OptionChanged")
end,
args = {
enabled = {
order = 10,
type = "toggle",
name = L["Enabled"],
desc = L["Flash spells on action bars when they are ready to be cast. Requires SpellFlashCore."],
width = "full",
},
inCombat = {
order = 10,
type = "toggle",
name = L["En combat uniquement"],
disabled = function()
return not SpellFlashCore or not Ovale.db.profile.apparence.spellFlash.enabled
end,
},
hasTarget = {
order = 20,
type = "toggle",
name = L["Si cible uniquement"],
disabled = function()
return not SpellFlashCore or not Ovale.db.profile.apparence.spellFlash.enabled
end,
},
hasHostileTarget = {
order = 30,
type = "toggle",
name = L["Cacher si cible amicale ou morte"],
disabled = function()
return not SpellFlashCore or not Ovale.db.profile.apparence.spellFlash.enabled
end,
},
hideInVehicle = {
order = 40,
type = "toggle",
name = L["Cacher dans les véhicules"],
disabled = function()
return not SpellFlashCore or not Ovale.db.profile.apparence.spellFlash.enabled
end,
},
brightness = {
order = 50,
type = "range",
name = L["Flash brightness"],
min = 0, max = 1, bigStep = 0.01,
isPercent = true,
disabled = function()
return not SpellFlashCore or not Ovale.db.profile.apparence.spellFlash.enabled
end,
},
size = {
order = 60,
type = "range",
name = L["Flash size"],
min = 0, max = 3, bigStep = 0.01,
isPercent = true,
disabled = function()
return not SpellFlashCore or not Ovale.db.profile.apparence.spellFlash.enabled
end,
},
threshold = {
order = 70,
type = "range",
name = L["Flash threshold"],
desc = L["Time (in milliseconds) to begin flashing the spell to use before it is ready."],
min = 0, max = 1000, step = 1, bigStep = 50,
disabled = function()
return not SpellFlashCore or not Ovale.db.profile.apparence.spellFlash.enabled
end,
},
colors = {
order = 80,
type = "group",
name = L["Colors"],
inline = true,
disabled = function()
return not SpellFlashCore or not Ovale.db.profile.apparence.spellFlash.enabled
end,
get = function(info)
local color = Ovale.db.profile.apparence.spellFlash[info[#info]]
return color.r, color.g, color.b, 1.0
end,
set = function(info, r, g, b, a)
local color = Ovale.db.profile.apparence.spellFlash[info[#info]]
color.r = r
color.g = g
color.b = b
OvaleOptions:SendMessage("Ovale_OptionChanged")
end,
args = {
colorMain = {
order = 10,
type = "color",
name = L["Main attack"],
hasAlpha = false,
},
colorCd = {
order = 20,
type = "color",
name = L["Long cooldown abilities"],
hasAlpha = false,
},
colorShortCd = {
order = 30,
type = "color",
name = L["Short cooldown abilities"],
hasAlpha = false,
},
colorInterrupt = {
order = 40,
type = "color",
name = L["Interrupts"],
hasAlpha = false,
},
},
},
},
},
}
-- Insert defaults and options into OvaleOptions.
for k, v in pairs(defaultDB) do
OvaleOptions.defaultDB.profile.apparence[k] = v
end
for k, v in pairs(options) do
OvaleOptions.options.args.apparence.args[k] = v
end
OvaleOptions:RegisterOptions(OvaleSpellFlash)
end
--</private-static-properties>
--<public-static-methods>
function OvaleSpellFlash:OnInitialize()
-- Resolve module dependencies.
OvaleData = Ovale.OvaleData
OvaleFuture = Ovale.OvaleFuture
OvaleSpellBook = Ovale.OvaleSpellBook
OvaleStance = Ovale.OvaleStance
end
function OvaleSpellFlash:OnEnable()
SpellFlashCore = _G["SpellFlashCore"]
self:RegisterMessage("Ovale_OptionChanged")
self:Ovale_OptionChanged()
end
function OvaleSpellFlash:OnDisable()
SpellFlashCore = nil
self:UnregisterMessage("Ovale_OptionChanged")
end
function OvaleSpellFlash:Ovale_OptionChanged()
local db = Ovale.db.profile.apparence.spellFlash
-- Main attack.
colorMain.r = db.colorMain.r
colorMain.g = db.colorMain.g
colorMain.b = db.colorMain.b
-- Long cooldown abilities.
colorCd.r = db.colorCd.r
colorCd.g = db.colorCd.g
colorCd.b = db.colorCd.b
-- Short cooldown abilities.
colorShortCd.r = db.colorShortCd.r
colorShortCd.g = db.colorShortCd.g
colorShortCd.b = db.colorShortCd.b
-- Interrupts.
colorInterrupt.r = db.colorInterrupt.r
colorInterrupt.g = db.colorInterrupt.g
colorInterrupt.b = db.colorInterrupt.b
end
function OvaleSpellFlash:IsSpellFlashEnabled()
local enabled = (SpellFlashCore ~= nil)
local db = Ovale.db.profile.apparence.spellFlash
if enabled and not db.enabled then
enabled = false
end
if enabled and db.inCombat and not OvaleFuture.inCombat then
enabled = false
end
if enabled and db.hideInVehicle and API_UnitHasVehicleUI("player") then
enabled = false
end
if enabled and db.hasTarget and not API_UnitExists("target") then
enabled = false
end
if enabled and db.hasHostileTarget and (API_UnitIsDead("target") or not API_UnitCanAttack("player", "target")) then
enabled = false
end
return enabled
end
function OvaleSpellFlash:Flash(state, node, element, start, now)
-- SpellFlash settings.
local db = Ovale.db.profile.apparence.spellFlash
now = now or API_GetTime()
if self:IsSpellFlashEnabled() and start and start - now <= db.threshold / 1000 then
-- Check that element is an action.
if element and element.type == "action" then
local spellId, spellInfo
if element.lowername == "spell" then
spellId = element.positionalParams[1]
spellInfo = OvaleData.spellInfo[spellId]
end
local interrupt = spellInfo and spellInfo.interrupt
-- Flash color.
local color = nil -- default color is white
local flash = element.namedParams and element.namedParams.flash
local iconFlash = node.namedParams.flash
local iconHelp = node.namedParams.help
if flash and COLORTABLE[flash] then
-- Highest priority is known flash color set in the action parameters.
color = COLORTABLE[flash]
elseif iconFlash and COLORTABLE[iconFlash] then
-- Next highest priority is known flash color set in the icon parameters.
color = COLORTABLE[iconFlash]
elseif iconHelp and FLASH_COLOR[iconHelp] then
-- Fall back to color based on the help set in the icon parameters.
color = FLASH_COLOR[iconHelp]
-- Adjust color if it's a "cd" ability that is showing an interrupt.
if interrupt == 1 and iconHelp == "cd" then
color = colorInterrupt
end
end
-- Flash size (percent).
local size = db.size * 100
if iconHelp == "cd" then
-- Adjust to half size for "cd" abilities.
if interrupt ~= 1 then
size = size * 0.5
end
end
-- Flash brightness (percent).
local brightness = db.brightness * 100
if element.lowername == "spell" then
if OvaleStance:IsStanceSpell(spellId) then
SpellFlashCore.FlashForm(spellId, color, size, brightness)
end
if OvaleSpellBook:IsPetSpell(spellId) then
SpellFlashCore.FlashPet(spellId, color, size, brightness)
end
SpellFlashCore.FlashAction(spellId, color, size, brightness)
elseif element.lowername == "item" then
-- Item ID.
local itemId = element.positionalParams[1]
SpellFlashCore.FlashItem(itemId, color, size, brightness)
end
end
end
end
function OvaleSpellFlash:UpgradeSavedVariables()
local profile = Ovale.db.profile
-- SpellFlash options have been moved and renamed.
if profile.apparence.spellFlash and type(profile.apparence.spellFlash) ~= "table" then
local enabled = profile.apparence.spellFlash
profile.apparence.spellFlash = {}
profile.apparence.spellFlash.enabled = enabled
end
end
--</public-static-methods>