-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathunitscan.lua
317 lines (292 loc) · 8.52 KB
/
unitscan.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
local unitscan = CreateFrame'Frame'
local forbidden
unitscan:SetScript('OnUpdate', function() unitscan.UPDATE() end)
unitscan:SetScript('OnEvent', function(_, event, arg1)
if event == 'ADDON_LOADED' and arg1 == 'unitscan' then
unitscan.LOAD()
elseif event == 'ADDON_ACTION_FORBIDDEN' and arg1 == 'unitscan' then
forbidden = true
elseif event == 'PLAYER_TARGET_CHANGED' then
if UnitName'target' and strupper(UnitName'target') == unitscan.button:GetText() and not GetRaidTargetIndex'target' and (not IsInRaid() or UnitIsGroupAssistant'player' or UnitIsGroupLeader'player') then
SetRaidTarget('target', 4)
end
end
end)
unitscan:RegisterEvent'ADDON_LOADED'
unitscan:RegisterEvent'ADDON_ACTION_FORBIDDEN'
unitscan:RegisterEvent'PLAYER_TARGET_CHANGED'
local BROWN = {.7, .15, .05}
local YELLOW = {1, 1, .15}
unitscan_targets = {}
local found = {}
do
local last_played
function unitscan.play_sound()
if not last_played or GetTime() - last_played > 8 then
PlaySoundFile([[Interface\AddOns\unitscan\Event_wardrum_ogre.ogg]], 'Master')
PlaySoundFile([[Interface\AddOns\unitscan\scourge_horn.ogg]], 'Master')
last_played = GetTime()
end
end
end
function unitscan.target(name)
forbidden = false
TargetUnit(name, true)
if forbidden then
if not found[name] then
found[name] = true
FlashClientIcon()
unitscan.play_sound()
unitscan.flash.animation:Play()
unitscan.discovered_unit = name
end
else
found[name] = false
end
end
function unitscan.LOAD()
do
local flash = CreateFrame'Frame'
unitscan.flash = flash
flash:Show()
flash:SetAllPoints()
flash:SetAlpha(0)
flash:SetFrameStrata'FULLSCREEN_DIALOG'
local texture = flash:CreateTexture()
texture:SetBlendMode'ADD'
texture:SetAllPoints()
texture:SetTexture[[Interface\FullScreenTextures\LowHealth]]
flash.animation = CreateFrame'Frame'
flash.animation:Hide()
flash.animation:SetScript('OnUpdate', function(self)
local t = GetTime() - self.t0
if t <= .5 then
flash:SetAlpha(t * 2)
elseif t <= 1 then
flash:SetAlpha(1)
elseif t <= 1.5 then
flash:SetAlpha(1 - (t - 1) * 2)
else
flash:SetAlpha(0)
self.loops = self.loops - 1
if self.loops == 0 then
self.t0 = nil
self:Hide()
else
self.t0 = GetTime()
end
end
end)
function flash.animation:Play()
if self.t0 then
self.loops = 4
else
self.t0 = GetTime()
self.loops = 3
end
self:Show()
end
end
local button = CreateFrame('Button', 'unitscan_button', UIParent, 'SecureActionButtonTemplate,BackdropTemplate')
button:SetAttribute('type', 'macro')
button:Hide()
unitscan.button = button
button:SetPoint('BOTTOM', UIParent, 0, 128)
button:SetWidth(150)
button:SetHeight(42)
button:SetScale(1.25)
button:SetMovable(true)
button:SetUserPlaced(true)
button:SetClampedToScreen(true)
button:SetScript('OnMouseDown', function(self)
if IsControlKeyDown() then
self:RegisterForClicks()
self:StartMoving()
end
end)
button:SetScript('OnMouseUp', function(self)
self:StopMovingOrSizing()
self:RegisterForClicks'LeftButtonDown'
end)
button:SetFrameStrata'FULLSCREEN_DIALOG'
button:SetNormalTexture[[Interface\AddOns\unitscan\UI-Achievement-Parchment-Horizontal]]
button:SetBackdrop{
tile = true,
edgeSize = 16,
edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]],
}
button:SetBackdropBorderColor(unpack(BROWN))
button:SetScript('OnEnter', function(self)
self:SetBackdropBorderColor(unpack(YELLOW))
end)
button:SetScript('OnLeave', function(self)
self:SetBackdropBorderColor(unpack(BROWN))
end)
function button:set_target(name)
self:SetText(name)
self:SetAttribute('macrotext', '/cleartarget\n/targetexact ' .. name)
self:Show()
self.glow.animation:Play()
self.shine.animation:Play()
end
do
local background = button:GetNormalTexture()
background:SetDrawLayer'BACKGROUND'
background:ClearAllPoints()
background:SetPoint('BOTTOMLEFT', 3, 3)
background:SetPoint('TOPRIGHT', -3, -3)
background:SetTexCoord(0, 1, 0, .25)
end
do
local title_background = button:CreateTexture(nil, 'BORDER')
title_background:SetTexture[[Interface\AddOns\unitscan\UI-Achievement-Title]]
title_background:SetPoint('TOPRIGHT', -5, -5)
title_background:SetPoint('LEFT', 5, 0)
title_background:SetHeight(18)
title_background:SetTexCoord(0, .9765625, 0, .3125)
title_background:SetAlpha(.8)
local title = button:CreateFontString(nil, 'OVERLAY', 'GameFontHighlightMedium')
title:SetWordWrap(false)
title:SetPoint('TOPLEFT', title_background, 0, 0)
title:SetPoint('RIGHT', title_background)
button:SetFontString(title)
local subtitle = button:CreateFontString(nil, 'OVERLAY', 'GameFontBlackTiny')
subtitle:SetPoint('TOPLEFT', title, 'BOTTOMLEFT', 0, -4)
subtitle:SetPoint('RIGHT', title)
subtitle:SetText'Unit Found!'
end
do
local model = CreateFrame('PlayerModel', nil, button)
button.model = model
model:SetPoint('BOTTOMLEFT', button, 'TOPLEFT', 0, -4)
model:SetPoint('RIGHT', 0, 0)
model:SetHeight(button:GetWidth() * .6)
end
do
local close = CreateFrame('Button', nil, button, 'UIPanelCloseButton')
close:SetPoint('TOPRIGHT', 0, 0)
close:SetWidth(32)
close:SetHeight(32)
close:SetScale(.8)
close:SetHitRectInsets(8, 8, 8, 8)
end
do
local glow = button.model:CreateTexture(nil, 'OVERLAY')
button.glow = glow
glow:SetPoint('CENTER', button, 'CENTER')
glow:SetWidth(400 / 300 * button:GetWidth())
glow:SetHeight(171 / 70 * button:GetHeight())
glow:SetTexture[[Interface\AddOns\unitscan\UI-Achievement-Alert-Glow]]
glow:SetBlendMode'ADD'
glow:SetTexCoord(0, .78125, 0, .66796875)
glow:SetAlpha(0)
glow.animation = CreateFrame'Frame'
glow.animation:Hide()
glow.animation:SetScript('OnUpdate', function(self)
local t = GetTime() - self.t0
if t <= .2 then
glow:SetAlpha(t * 5)
elseif t <= .7 then
glow:SetAlpha(1 - (t - .2) * 2)
else
glow:SetAlpha(0)
self:Hide()
end
end)
function glow.animation:Play()
self.t0 = GetTime()
self:Show()
end
end
do
local shine = button:CreateTexture(nil, 'ARTWORK')
button.shine = shine
shine:SetPoint('TOPLEFT', button, 0, 8)
shine:SetWidth(67 / 300 * button:GetWidth())
shine:SetHeight(1.28 * button:GetHeight())
shine:SetTexture[[Interface\AddOns\unitscan\UI-Achievement-Alert-Glow]]
shine:SetBlendMode'ADD'
shine:SetTexCoord(.78125, .912109375, 0, .28125)
shine:SetAlpha(0)
shine.animation = CreateFrame'Frame'
shine.animation:Hide()
shine.animation:SetScript('OnUpdate', function(self)
local t = GetTime() - self.t0
if t <= .3 then
shine:SetPoint('TOPLEFT', button, 0, 8)
elseif t <= .7 then
shine:SetPoint('TOPLEFT', button, (t - .3) * 2.5 * self.distance, 8)
end
if t <= .3 then
shine:SetAlpha(0)
elseif t <= .5 then
shine:SetAlpha(1)
elseif t <= .7 then
shine:SetAlpha(1 - (t - .5) * 5)
else
shine:SetAlpha(0)
self:Hide()
end
end)
function shine.animation:Play()
self.t0 = GetTime()
self.distance = button:GetWidth() - shine:GetWidth() + 8
self:Show()
end
end
end
do
local target_name = nil
function unitscan.UPDATE()
if unitscan.discovered_unit and not InCombatLockdown() then
unitscan.button:set_target(unitscan.discovered_unit)
unitscan.discovered_unit = nil
end
if next(unitscan_targets) then
target_name = next(unitscan_targets, unitscan_targets[target_name] and target_name) or next(unitscan_targets)
local event_registered = UIParent:IsEventRegistered'ADDON_ACTION_FORBIDDEN'
if event_registered then
UIParent:UnregisterEvent'ADDON_ACTION_FORBIDDEN'
end
unitscan.target(target_name)
if event_registered then
UIParent:RegisterEvent'ADDON_ACTION_FORBIDDEN'
end
end
end
end
function unitscan.print(msg)
if DEFAULT_CHAT_FRAME then
DEFAULT_CHAT_FRAME:AddMessage(LIGHTYELLOW_FONT_COLOR_CODE .. '<unitscan> ' .. msg)
end
end
function unitscan.sorted_targets()
local sorted_targets = {}
for key in pairs(unitscan_targets) do
tinsert(sorted_targets, key)
end
sort(sorted_targets, function(key1, key2) return key1 < key2 end)
return sorted_targets
end
function unitscan.toggle_target(name)
local key = strupper(name)
if unitscan_targets[key] then
unitscan_targets[key] = nil
found[key] = nil
unitscan.print('- ' .. key)
elseif key ~= '' then
unitscan_targets[key] = true
unitscan.print('+ ' .. key)
end
end
SLASH_UNITSCAN1 = '/unitscan'
function SlashCmdList.UNITSCAN(parameter)
local _, _, name = strfind(parameter, '^%s*(.-)%s*$')
if name == '' then
for _, key in ipairs(unitscan.sorted_targets()) do
unitscan.print(key)
end
else
unitscan.toggle_target(name)
end
end