-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlogs.lua
159 lines (128 loc) · 3.89 KB
/
logs.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
local _, addon = ...
local utils = addon.utils
local L = addon.L
local mod = {}
local unitName
local UIFrame, frameName
local loaded, fetched, spellId
local logs = {}
local _G = _G
local format = _G.string.format
local function resetList()
local i = 1
local btn = _G[frameName..'_LogBtn_'..i]
while btn do
btn:Hide()
i = i + 1
btn = _G[frameName..'_LogBtn'..i]
end
end
local function resetFrameStatus()
logs = table.wipe(logs)
loaded, fetched, spellId = nil, nil, nil
resetList()
end
local function loadLogs()
if spellId then
logs = {}
for n, p in pairs(Elvin_Cooldowns[spellId].players) do
for k, v in pairs(p.logs) do
tinsert(logs, {
time = k,
player = n,
target = v
})
end
end
table.sort(logs, function(a, b) return (a.time > b.time) end)
end
loaded=true
end
local function fetchLogs()
resetList()
-- Set title
local spellName = GetSpellLink(spellId) or GetSpellInfo(spellId)
local currentTime = utils.getCurrentTime()
if spellName then
_G[frameName..'Title']:SetText(format('%2$s - %1$s', spellName, date('%Y/%m/%d', currentTime)))
end
local scrollFrame = _G[frameName..'ListScrollFrame']
local scrollChild = _G[frameName..'ListScrollFrameScrollChild']
scrollChild:SetHeight(scrollFrame:GetHeight())
scrollChild:SetWidth(scrollFrame:GetWidth())
local height = 0
for k, v in ipairs(logs) do
local btnName = frameName..'_LogBtn_'..k
local btn = _G[btnName] or CreateFrame('Button', btnName, scrollChild, 'ElvinCDs_LogsButton')
btn:SetID(k)
btn:Show()
-- Set the time:
_G[btnName..'Time']:SetText(date('%H:%M', v.time))
-- Prepare classes
local pID, tID = utils.getPlayerUnitId(v.player), utils.getPlayerUnitId(v.target)
local _, pClass = UnitClass(pID)
local name = '|cff'..utils.classColorHex(pClass)..v.player..'|r'
if tID ~= 'none' then
local _, tClass = UnitClass(tID)
name = name..' > '..'|cff'..utils.classColorHex(tClass)..v.target..'|r'
end
_G[btnName..'Name']:SetText(name)
btn:SetScript('OnClick', function(self, button)
if button == 'LeftButton' and IsControlKeyDown() then
if v.target == '' or v.target == unitName then
utils.announce(L:F('%s used %s at %s', v.player, spellName, date('%H:%M', v.castTime)), 'RAID')
else
utils.announce(L:F('%s used %s on %s at %s', v.player, spellName, v.target, date('%H:%M', v.castTime)), 'RAID')
end
end
end)
btn:SetPoint('TOPLEFT', scrollChild, 'TOPLEFT', 0, -height)
btn:SetPoint('RIGHT', scrollChild, 'RIGHT', 0, 0)
height = height + btn:GetHeight()
end
fetched=true
end
local function updateUIFrame(self, elapsed)
if utils.update(self, frameName, 0.05, elapsed) then
if not loaded then loadLogs() end
if not fetched then fetchLogs() end
local index = #logs+1
local btn = _G[frameName..'_LogBtn_'..index]
while btn do
btn:Hide()
index = index + 1
btn = _G[frameName..'_LogBtn_'..index]
end
end
end
function mod:onLoad(frame)
if not frame then return end
UIFrame = frame
frameName = frame:GetName()
frame:RegisterForDrag('LeftButton')
frame:SetScript('OnUpdate', updateUIFrame)
frame:SetScript('OnHide', resetFrameStatus)
tinsert(UISpecialFrames, frameName)
end
function mod:view(id)
if UIFrame:IsShown() then
resetFrameStatus()
end
if not id or not Elvin_Cooldowns[id] then return end
spellId = id
end
function mod:reset()
resetFrameStatus()
end
local fname = 'ElvinCDs_LogsFrame'
local mainFrame = CreateFrame('Frame', fname)
mainFrame:SetScript('OnUpdate', function(self, elapsed)
if utils.update(self, fname, 0.05, elapsed) then
if not unitName then
unitName = select(1, UnitName('player'))
addon.unitName = unitName
end
utils.showHide(UIFrame, (spellId and Elvin_Cooldowns[spellId]))
end
end)
addon.Logs = mod