-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.lua
288 lines (255 loc) · 8.74 KB
/
core.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
local _, _, classIndex = UnitClass("player");
-- Exit if player is no warrior
if classIndex ~= 1 then
return
end
local LibSharedMedia = LibStub and LibStub:GetLibrary("LibSharedMedia-3.0", true)
local defaults = {
font = LibSharedMedia:Fetch(LibSharedMedia.MediaType.FONT, "Calibri"),
background = LibSharedMedia:Fetch(LibSharedMedia.MediaType.BACKGROUND, "Solid"),
fontSizeLarge = 23,
fontSizeSmall = 15,
positionX = -220,
positionY = -180,
}
-- Base frame holding the additional buttons
local baseFrame = CreateFrame("Frame", nil, UIParent)
baseFrame:SetFrameStrata("BACKGROUND")
baseFrame:SetWidth(96)
baseFrame:SetHeight(48)
baseFrame:SetMovable(true)
baseFrame:EnableMouse(true)
baseFrame:RegisterForDrag("LeftButton")
baseFrame:SetScript("OnDragStart", baseFrame.StartMoving)
baseFrame:SetScript("OnDragStop", baseFrame.StopMovingOrSizing)
-- Frame for Ignore Pain
local ignorePainFrame = CreateFrame("Frame", "IgnorePainFrame", baseFrame)
ignorePainFrame:SetFrameStrata("BACKGROUND")
ignorePainFrame:SetWidth(48)
ignorePainFrame:SetHeight(48)
ignorePainFrame:SetPoint("LEFT")
ignorePainFrame:SetBackdrop({
edgeFile = defaults.background,
edgeSize = 3,
})
ignorePainFrame:SetBackdropBorderColor(1, 0, 0)
ignorePainFrame.texture = ignorePainFrame:CreateTexture(nil, "BACKGROUND")
ignorePainFrame.texture:SetAllPoints()
ignorePainFrame.texture:SetTexture("Interface\\ICONS\\Ability_Warrior_RenewedVigor.blp")
ignorePainFrame.texture:SetTexCoord(0.1, 0.9, 0.1, 0.9)
-- Timer for Ignore Pain
local ignorePainTime = ignorePainFrame:CreateFontString(nil, "OVERLAY")
ignorePainTime:SetPoint("TOP", 0, -6)
ignorePainTime:SetTextColor(1, 1, 1)
ignorePainTime:SetFont(defaults.font, defaults.fontSizeLarge, "OUTLINE")
ignorePainFrame.text = ignorePainTime
-- Absorb for Ignore Pain
local ignorePainAmount = ignorePainFrame:CreateFontString(nil, "OVERLAY")
ignorePainAmount:SetPoint("BOTTOM", 0, 6)
ignorePainAmount:SetTextColor(1, 1, 1)
ignorePainAmount:SetFont(defaults.font, defaults.fontSizeSmall, "OUTLINE")
ignorePainFrame.text = ignorePainAmount
-- Dragon Scales
local dragonScalesFrame = CreateFrame("Frame", "IgnorePainVengeance", ignorePainFrame)
dragonScalesFrame:SetFrameStrata("BACKGROUND")
dragonScalesFrame:SetWidth(15)
dragonScalesFrame:SetHeight(15)
dragonScalesFrame:SetPoint("TOP", 0, 15)
dragonScalesFrame:SetBackdrop({
edgeFile = defaults.background,
edgeSize = 3,
})
dragonScalesFrame:SetBackdropBorderColor(0, 1, 0)
dragonScalesFrame.texture = dragonScalesFrame:CreateTexture(nil, "BACKGROUND")
dragonScalesFrame.texture:SetAllPoints()
dragonScalesFrame:Hide()
-- Vengeance: Ignore Pain
local vengeanceIgnorePainFrame = CreateFrame("Frame", "IgnorePainVengeance", ignorePainFrame)
vengeanceIgnorePainFrame:SetFrameStrata("BACKGROUND")
vengeanceIgnorePainFrame:SetWidth(15)
vengeanceIgnorePainFrame:SetHeight(15)
vengeanceIgnorePainFrame:SetPoint("TOP")
vengeanceIgnorePainFrame:SetPoint("LEFT", -15, 0)
vengeanceIgnorePainFrame:SetBackdrop({
edgeFile = defaults.background,
edgeSize = 3,
})
vengeanceIgnorePainFrame:SetBackdropBorderColor(1, 0, 0)
vengeanceIgnorePainFrame.texture = vengeanceIgnorePainFrame:CreateTexture(nil, "BACKGROUND")
vengeanceIgnorePainFrame.texture:SetAllPoints()
vengeanceIgnorePainFrame:Hide()
-- Vengeance: Focused Rage
local vengeanceFocusedRageFrame = CreateFrame("Frame", "IgnorePainVengeance", ignorePainFrame)
vengeanceFocusedRageFrame:SetFrameStrata("BACKGROUND")
vengeanceFocusedRageFrame:SetWidth(15)
vengeanceFocusedRageFrame:SetHeight(15)
vengeanceFocusedRageFrame:SetPoint("BOTTOM")
vengeanceFocusedRageFrame:SetPoint("LEFT", -15, 0)
vengeanceFocusedRageFrame:SetBackdrop({
edgeFile = defaults.background,
edgeSize = 3,
})
vengeanceFocusedRageFrame:SetBackdropBorderColor(1, 1, 0)
vengeanceFocusedRageFrame.texture = vengeanceFocusedRageFrame:CreateTexture(nil, "BACKGROUND")
vengeanceFocusedRageFrame.texture:SetAllPoints()
vengeanceFocusedRageFrame:Hide()
-- Frame for Shield Block
local shieldBlockFrame = CreateFrame("Frame", nil, baseFrame)
shieldBlockFrame:SetFrameStrata("BACKGROUND")
shieldBlockFrame:SetWidth(48)
shieldBlockFrame:SetHeight(48)
shieldBlockFrame:SetPoint("RIGHT")
shieldBlockFrame:SetBackdrop({
edgeFile = defaults.background,
edgeSize = 3,
})
shieldBlockFrame:SetBackdropBorderColor(1, 0, 0)
shieldBlockFrame.texture = shieldBlockFrame:CreateTexture(nil, "BACKGROUND")
shieldBlockFrame.texture:SetTexture("Interface\\ICONS\\Ability_Defend.blp")
shieldBlockFrame.texture:SetAllPoints()
-- Timer for Shield Block
local shieldBlockTime = shieldBlockFrame:CreateFontString(nil, "OVERLAY")
shieldBlockTime:SetPoint("CENTER", 0, 0)
shieldBlockTime:SetTextColor(1, 1, 1)
shieldBlockTime:SetFont(defaults.font, defaults.fontSizeLarge, "OUTLINE")
shieldBlockFrame.text = shieldBlockTime
local function format(time)
local result
if time >= 1000000 then
result = string.format("%.1f m", time / 1000000)
elseif time >= 1000 then
result = string.format("%d k", math.floor(time / 1000))
else result = time
end
return result
end
local function updateColor(frame, time, upper, lower)
if time > upper then
frame:SetBackdropBorderColor(0, 1, 0)
elseif time <= upper and time >= lower then
frame:SetBackdropBorderColor(1, 0.5, 0)
else
frame:SetBackdropBorderColor(1, 0, 0)
end
end
local function resetFrame(frame, ...)
frame:SetBackdropBorderColor(1, 0, 0)
local arg = {...}
for k, v in ipairs(arg) do
v:SetText("")
end
end
local expires, absorb = 0, 0
local name = nil
local ignorePainActive, shieldBlockActive = false, false
local timeLeftIgnorePain, timeLeftShieldBlock = 0, 0
local ignorePain = 0
local showVengeanceIgnorePain = function()
vengeanceFocusedRageFrame:Show()
end
local hideVengeanceIgnorePain = function()
vengeanceFocusedRageFrame:Hide()
end
local showVengeanceFocusedRage = function()
vengeanceIgnorePainFrame:Show()
end
local hideVengeanceFocusedRage = function()
vengeanceIgnorePainFrame:Hide()
end
local showDragonScales = function()
dragonScalesFrame:Show()
end
local hideDragonScales = function()
dragonScalesFrame:Hide()
end
local showShieldBlock = function()
timeLeft = math.floor(expires - GetTime())
if timeLeft > timeLeftShieldBlock then
timeLeftShieldBlock = timeLeft
end
end
local hideShieldBlock = function()
resetFrame(shieldBlockFrame, shieldBlockTime)
timeLeftShieldBlock = 0
end
local showIgnorePain = function()
ignorePain = absorb
timeLeft = math.floor(expires - GetTime())
if timeLeft > timeLeftIgnorePain then
timeLeftIgnorePain = timeLeft
end
end
local hideIgnorePain = function()
resetFrame(ignorePainFrame, ignorePainTime, ignorePainAmount)
timeLeftIgnorePain = 0
end
local spells = {
["Vengeance: Ignore Pain"] = {
show = showVengeanceIgnorePain,
hide = hideVengeanceIgnorePain,
active = false
},
["Vengeance: Focused Rage"] = {
show = showVengeanceFocusedRage,
hide = hideVengeanceFocusedRage,
active = false
},
["Dragon Scales"] = {
show = showDragonScales,
hide = hideDragonScales,
active = false
},
["Ignore Pain"] = {
show = showIgnorePain,
hide = hideIgnorePain,
active = false
},
["Shield Block"] = {
show = showShieldBlock,
hide = hideShieldBlock,
active = false
},
}
local function eventHandler(self, event, ...)
for spell, action in pairs(spells) do
name, _, _, _, _, _, expires, _, _, _, _, _, _, _, _, _, absorb, _, _ = UnitAura("player", spell)
if name then
action.active = true
action.show()
end
if not name and action.active then
action.active = false
action.hide()
end
end
end
-- TODO: Refactor, use AceTimer?
function baseFrame:onUpdate(elapsed)
-- Ignore Pain
if timeLeftIgnorePain > 0 then
self.elapsedIgnorePain = (self.elapsedIgnorePain or 0) + elapsed;
if (self.elapsedIgnorePain >= 0.1) then
updateColor(ignorePainFrame, timeLeftIgnorePain, 10, 5)
ignorePainAmount:SetText(format(ignorePain))
ignorePainTime:SetText(string.format("%.1f", timeLeftIgnorePain))
timeLeftIgnorePain = timeLeftIgnorePain - 0.1
self.elapsedIgnorePain = 0
end
end
-- Shield Block
if timeLeftShieldBlock > 0 then
self.elapsedShieldBlock = (self.elapsedShieldBlock or 0) + elapsed;
if (self.elapsedShieldBlock >= 0.1) then
updateColor(shieldBlockFrame, timeLeftShieldBlock, 4, 2)
shieldBlockTime:SetText(string.format("%.1f", timeLeftShieldBlock))
timeLeftShieldBlock = timeLeftShieldBlock - 0.1
self.elapsedShieldBlock = 0
end
end
end
baseFrame:RegisterEvent("UNIT_AURA")
baseFrame:SetScript("OnEvent", eventHandler)
baseFrame:SetScript("OnUpdate", baseFrame.onUpdate)
RegisterStateDriver(baseFrame, "visibility", "[petbattle] [vehicleui] hide; show")
baseFrame:SetPoint("CENTER", defaults.positionX, defaults.positionY)
baseFrame:Show()