-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuff_tracker.lua
More file actions
384 lines (323 loc) · 10.3 KB
/
Copy pathbuff_tracker.lua
File metadata and controls
384 lines (323 loc) · 10.3 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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
local frame = api.Interface:CreateEmptyWindow("buffTracker")
frame:Show(true)
local width = api.Interface:GetScreenWidth() or 2560
local height = api.Interface:GetScreenHeight() or 1080
-- local width = 2560
-- local height = 1080
local alertLabel = frame:CreateChildWidget("label", "label", 0, true)
alertLabel:SetText("")
alertLabel:AddAnchor("TOPLEFT", "UIParent", width / 2, height / 2 - 350)
alertLabel.style:SetFontSize(32)
alertLabel:Show(false)
function frame:OnDragStart()
if not api.Input:IsShiftKeyDown() then
return
end
frame:StartMoving()
api.Cursor:ClearCursor()
api.Cursor:SetCursorImage(CURSOR_PATH.MOVE, 0, 0)
end
function frame:OnDragStop()
frame:StopMovingOrSizing()
api.Cursor:ClearCursor()
local x, y = frame:GetOffset()
api.File:Write("better-archeage/position.txt", {x, y})
end
frame:EnableDrag(true)
frame:SetHandler("OnDragStart", frame.OnDragStart)
frame:SetHandler("OnDragStop", frame.OnDragStop)
local function RepositionTrackers(frame)
local activeTrackers = {}
for _, tracker in ipairs(frame.trackers) do
if tracker:IsVisible() then
table.insert(activeTrackers, tracker)
end
end
-- Sort trackers by their original index to maintain consistent order
table.sort(activeTrackers, function(a, b)
local aNum = tonumber(string.match(a:GetName(), "tracker%.(%d+)")) or 0
local bNum = tonumber(string.match(b:GetName(), "tracker%.(%d+)")) or 0
return aNum < bNum
end)
-- Reposition active trackers
for i, tracker in ipairs(activeTrackers) do
tracker:RemoveAllAnchors()
tracker:AddAnchor("TOPLEFT", frame, 0, 0 + (40 * (i - 1)))
end
end
local function CreateBuffTrackerView(frame, settings)
local i = 1
if frame.trackers ~= nil then
i = #frame.trackers + 1
else
frame.trackers = {}
end
frame:SetExtent(172, 40 * i)
local tracker = frame:CreateChildWidget("emptywidget", "tracker." .. i, 0, true)
tracker:SetExtent(172, 40)
tracker:Clickable(false)
tracker.settings = settings
local buffIcon = CreateItemIconButton(i .. ".buffIcon", tracker)
buffIcon:Show(true)
buffIcon:Clickable(false)
F_SLOT.ApplySlotSkin(buffIcon, buffIcon.back, SLOT_STYLE.BUFF)
buffIcon:AddAnchor("TOPLEFT", tracker, "TOPLEFT", 0, 0)
-- F_SLOT.SetIconBackGround(zealIcon, trackedBuffInfo.path)
-- local buffTime = ...
local buffTimeBar = api.Interface:CreateStatusBar("speedo", tracker, "item_evolving_material")
buffTimeBar:Clickable(false)
function tracker:SetColor(color)
-- If color is a table, split into 3
-- If color is a string, split as hex rgb
if type(color) == "table" then
buffTimeBar:SetBarColor({
ConvertColor(color[1]),
ConvertColor(color[2]),
ConvertColor(color[3]),
1
})
elseif type(color) == "string" then
-- Parse R G B from hex string into 0-255
local r, g, b = string.match(color, "#(%x%x)(%x%x)(%x%x)")
local r = tonumber(r, 16)
local g = tonumber(g, 16)
local b = tonumber(b, 16)
buffTimeBar:SetBarColor({
ConvertColor(r),
ConvertColor(g),
ConvertColor(b),
1
})
end
buffTimeBar.bg:SetColor(ConvertColor(76), ConvertColor(45), ConvertColor(8), 0.4)
end
if settings.baseColor then
tracker:SetColor(settings.baseColor)
else
tracker:SetColor({70, 200, 66})
end
--buffTimeBar.bg:SetColor(ConvertColor(76), ConvertColor(45), ConvertColor(8), 0.4)
buffTimeBar:SetMinMaxValues(0, 100)
if settings.type == "stack" then
buffTimeBar:SetMinMaxValues(0, settings.maxStack)
end
buffTimeBar:AddAnchor("TOPLEFT", tracker, 42, 1)
buffTimeBar:AddAnchor("BOTTOMRIGHT", tracker, -1, 1)
local buffTimeLabel = tracker:CreateChildWidget("label", "buffTimeLabel", 0, true)
buffTimeLabel:AddAnchor("TOPLEFT", tracker, "CENTER", 0, 0)
buffTimeLabel.style:SetFontSize(20)
buffTimeLabel:Clickable(false)
tracker:Show(false)
local maxBuffTime = 0
tracker.lastTime = 0
function tracker:UpdateBuff(buff)
F_SLOT.SetIconBackGround(buffIcon, buff.path)
if buff.timeLeft ~= nil and maxBuffTime < buff.timeLeft then
maxBuffTime = buff.timeLeft
end
if tracker.settings.type == "stack" then
buffTimeBar:SetValue(buff.stack)
buffTimeLabel:SetText(string.format("%d/%d", buff.stack, tracker.settings.maxStack))
elseif tracker.settings.type == "stack_time" then
buffTimeBar:SetValue((buff.timeLeft / maxBuffTime) * 100)
buffTimeLabel:SetText(string.format("%d/%d", buff.stack, tracker.settings.maxStack))
elseif buff.timeLeft == nil then
buffTimeBar:SetValue(100)
buffTimeLabel:SetText("Active")
else
buffTimeBar:SetValue((buff.timeLeft / maxBuffTime) * 100)
buffTimeLabel:SetText(string.format("%.1fs", buff.timeLeft / 1000))
end
if (buff.timeLeft ~= nil and buff.timeLeft > 190) or buff.timeLeft == nil then
tracker:Show(true)
RepositionTrackers(frame)
else
tracker:Show(false)
RepositionTrackers(frame)
end
if tracker.settings.type == "alert" then
tracker:Show(false)
end
-- Compute keyframes
if settings.keyframes then
for ki, kf in ipairs(settings.keyframes) do
if kf.time ~= nil then
if tracker.lastTime > kf.time and buff.timeLeft <= kf.time then
if kf.type == "color" then
self:SetColor(kf.value)
end
end
end
if kf.remain ~= nil then
if buff.timeLeft <= kf.remain then
if kf.type == "color" then
self:SetColor(kf.value)
end
end
end
end
end
tracker.lastTime = buff.timeLeft
end
function tracker:Reset()
buffTimeBar:SetBarColor({
ConvertColor(55),
ConvertColor(200),
ConvertColor(66),
1
})
buffTimeBar.bg:SetColor(ConvertColor(76), ConvertColor(45), ConvertColor(8), 0.4)
end
table.insert(frame.trackers, tracker)
end
local defaultTrackedSettings = {
{
comment = "Tracker for Liberation on TARGET (only works on English clients)",
nameFilter = "Liberation",
trg = "target",
baseColor = "#FF0000"
},
{
comment = "Tracker for Inspired on PLAYER",
idFilter = 127,
trg = "player",
baseColor = "#37CC7B",
keyframes = {
{ type = "color", remain = 6000, value = "#FF0000"}
}
},
}
local position = { 400, 100}
local settingsData = api.File:Read("better-archeage/settings.txt")
local savedPosition = api.File:Read("better-archeage/position.txt")
local trackedSettings = defaultTrackedSettings
if settingsData then
if settingsData.buffTrackers then
-- New format with settings
trackedSettings = settingsData.buffTrackers
elseif type(settingsData) == "table" and #settingsData > 0 and settingsData[1].nameFilter then
-- Old format (just array)
trackedSettings = settingsData
end
end
if trackedSettings == nil or #trackedSettings == 0 then
trackedSettings = defaultTrackedSettings
-- Save in new format
local settingsToSave = {
buffTrackers = defaultTrackedSettings,
enableLargeHPMP = true,
enableGuildName = true,
enableGearScore = true,
useRangeFinder = true,
useSpeedometer = true,
useBufftracker = true,
rangeFinderFont = 14
}
api.File:Write("better-archeage/settings.txt", settingsToSave)
end
if savedPosition == nil then
savedPosition = position
api.File:Write("better-archeage/position.txt", savedPosition)
end
frame:AddAnchor("TOPLEFT", "UIParent", savedPosition[1], savedPosition[2])
local function RefreshTracked()
for i, v in ipairs(trackedSettings) do
CreateBuffTrackerView(frame, v)
end
end
local function IsBuffMatchingTracker(buff, tracker)
local settings = tracker.settings
local buffInfo = api.Ability:GetBuffTooltip(buff.buff_id)
if settings.idFilter and buff.buff_id ~= settings.idFilter then
return false
end
if settings.nameFilter and not string.find(string.lower(buffInfo.name), string.lower(settings.nameFilter)) then
return false
end
return true
end
local function BuffLoop(trg)
local buffCount = api.Unit:UnitBuffCount(trg)
local debuffCount = api.Unit:UnitDeBuffCount(trg)
if buffCount == 0 and debuffCount == 0 then
for _, tracker in ipairs(frame.trackers) do
if tracker.settings.trg == trg and tracker:IsVisible() then
tracker:Show(false)
tracker:Reset()
end
end
return
end
local buffsByID = {}
for i = 1, buffCount do
local buff = api.Unit:UnitBuff(trg, i)
buffsByID[buff.buff_id] = buff
end
for i = 1, debuffCount do
local debuff = api.Unit:UnitDeBuff(trg, i)
buffsByID[debuff.buff_id] = debuff
end
local hasAlert = false
for _, tracker in ipairs(frame.trackers) do
local settings = tracker.settings
if settings.trg == trg then
local foundBuff = false
if settings.idFilter and buffsByID[settings.idFilter] then
tracker:UpdateBuff(buffsByID[settings.idFilter])
foundBuff = true
if settings.alert then
hasAlert = true
end
else
for _, buff in pairs(buffsByID) do
if IsBuffMatchingTracker(buff, tracker) then
tracker:UpdateBuff(buff)
foundBuff = true
if settings.alert then
if settings.baseColor then
local color = settings.baseColor
if color:sub(1,1) == "#" then
color = color:sub(2)
end
local r = tonumber(color:sub(1,2), 16) or 255
local g = tonumber(color:sub(3,4), 16) or 255
local b = tonumber(color:sub(5,6), 16) or 255
alertLabel.style:SetColor(r/255, g/255, b/255, 1)
end
alertLabel:SetText(settings.alert)
hasAlert = true
end
break
end
end
end
if not foundBuff and tracker:IsVisible() then
tracker:Show(false)
tracker:Reset()
end
end
end
alertLabel:Show(hasAlert)
end
local updateTime = 0
local cleanupTick = 0
local function OnUpdate(dt)
updateTime = updateTime + dt
if updateTime < 100 then
return
end
updateTime = 0
local trackers = frame.trackers
local targets = {}
for _, tracker in ipairs(trackers) do
if not targets[tracker.settings.trg] then
targets[tracker.settings.trg] = true
end
end
for target, _ in pairs(targets) do
BuffLoop(target)
end
end
RefreshTracked()
api.On("UPDATE", OnUpdate)
return frame