comparison PVPScan.lua @ 2:f2456f1454af

rewrite
author tercio
date Sun, 01 Jun 2014 03:48:11 -0300
parents 726745261b87
children 1c0f88ab78b7
comparison
equal deleted inserted replaced
1:726745261b87 2:f2456f1454af
1 1
2 PVPScan = LibStub ("AceAddon-3.0"):NewAddon ("PVPScan", "AceConsole-3.0", "AceEvent-3.0") 2 PVPScan = LibStub ("AceAddon-3.0"):NewAddon ("PVPScan", "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0")
3 3
4 local LDB = LibStub ("LibDataBroker-1.1", true) 4 local LDB = LibStub ("LibDataBroker-1.1", true)
5 local LDBIcon = LDB and LibStub ("LibDBIcon-1.0", true) 5 local LDBIcon = LDB and LibStub ("LibDBIcon-1.0", true)
6 local SharedMedia = LibStub:GetLibrary("LibSharedMedia-3.0") 6 local SharedMedia = LibStub:GetLibrary("LibSharedMedia-3.0")
7 7
8 local _bit_band = bit.band 8 local _bit_band = bit.band
9 local GetTime = GetTime
9 10
10 local REACTION_HOSTILE = 0x00000040 11 local REACTION_HOSTILE = 0x00000040
11 local REACTION_NEUTRAL = 0x00000020 12 local REACTION_NEUTRAL = 0x00000020
12 13
13 local OBJECT_TYPE_PLAYER = 0x00000400 14 local OBJECT_TYPE_PLAYER = 0x00000400
21 local default_db = { 22 local default_db = {
22 profile = { 23 profile = {
23 SpotBarHeight = 20, 24 SpotBarHeight = 20,
24 SpotBarAmount = 5, 25 SpotBarAmount = 5,
25 SpotBarWidth = 150, 26 SpotBarWidth = 150,
27 SpotBarTexture = "Blizzard Character Skills Bar",
28 SpotBarTimeOut = 10,
29 SpotBarCooldown = 5,
30 SpotBarPlayerCooldown = 10,
26 Locked = false, 31 Locked = false,
27 SoundPlay = false, 32 SoundPlay = false,
28 SoundFile = "", 33 SoundFile = "",
29 Minimap = {hide = false, radius = 160, minimapPos = 220}, 34 Minimap = {hide = false, radius = 160, minimapPos = 220},
30 }, 35 },
71 step = 1, 76 step = 1,
72 get = function() return PVPScan.db.profile.SpotBarAmount end, 77 get = function() return PVPScan.db.profile.SpotBarAmount end,
73 set = function (self, val) PVPScan.db.profile.SpotBarAmount = val; PVPScan:RefreshSpotBars() end, 78 set = function (self, val) PVPScan.db.profile.SpotBarAmount = val; PVPScan:RefreshSpotBars() end,
74 order = 3, 79 order = 3,
75 }, 80 },
81 SpotBarTexture = {
82 type = "select",
83 name = "Bar Texture",
84 desc = "Choose the texture used on target bars.",
85 values = function()
86 local TextureTable = {}
87 for name, _ in pairs (SharedMedia:HashTable ("statusbar")) do
88 TextureTable [name] = name
89 end
90 return TextureTable
91 end,
92 get = function() return PVPScan.db.profile.SpotBarTexture end,
93 set = function (self, file) PVPScan.db.profile.SpotBarTexture = file; PVPScan:RefreshSpotBars() end,
94 order = 4,
95 },
96 SpotBarTimeOut = {
97 type = "range",
98 name = "Time Out",
99 desc = "How many time wait until the bar auto hide.",
100 min = 5,
101 max = 120,
102 step = 5,
103 get = function() return PVPScan.db.profile.SpotBarTimeOut end,
104 set = function (self, val) PVPScan.db.profile.SpotBarTimeOut = val; end,
105 order = 9,
106 },
76 Locked = { 107 Locked = {
77 type = "toggle", 108 type = "toggle",
78 name = "Lock Scan Frame", 109 name = "Lock Scan Frame",
79 desc = "Lock or unlock the SpotBars Frame.", 110 desc = "Lock or unlock the SpotBars Frame.",
80 order = 4, 111 order = 5,
81 get = function() return PVPScan.db.profile.Locked end, 112 get = function() return PVPScan.db.profile.Locked end,
82 set = function (self, val) PVPScan.db.profile.Locked = not PVPScan.db.profile.Locked; PVPScan:LockScanFrame (PVPScan.db.profile.Locked) end, 113 set = function (self, val) PVPScan.db.profile.Locked = not PVPScan.db.profile.Locked; PVPScan:LockScanFrame (PVPScan.db.profile.Locked) end,
83 }, 114 },
84 SoundPlay = { 115 SoundPlay = {
85 type = "toggle", 116 type = "toggle",
86 name = "Play Sound", 117 name = "Play Sound",
87 desc = "Play a sound when a enemy is found.", 118 desc = "Play a sound when a enemy is found.",
88 order = 5, 119 order = 7,
89 get = function() return PVPScan.db.profile.SoundPlay end, 120 get = function() return PVPScan.db.profile.SoundPlay end,
90 set = function (self, val) PVPScan.db.profile.SoundPlay = not PVPScan.db.profile.SoundPlay end, 121 set = function (self, val) PVPScan.db.profile.SoundPlay = not PVPScan.db.profile.SoundPlay end,
91 }, 122 },
92 SoundFile = { 123 SoundFile = {
93 type = "select", 124 type = "select",
100 end 131 end
101 return SoundTable 132 return SoundTable
102 end, 133 end,
103 get = function() return PVPScan.db.profile.SoundFile end, 134 get = function() return PVPScan.db.profile.SoundFile end,
104 set = function (self, file) PVPScan.db.profile.SoundFile = file end, 135 set = function (self, file) PVPScan.db.profile.SoundFile = file end,
105 order = 6, 136 order = 8,
106 }, 137 },
107 Minimap = { 138 Minimap = {
108 type = "toggle", 139 type = "toggle",
109 name = "Hide Minimap Icon", 140 name = "Hide Minimap Icon",
110 desc = "Show or hide the minimap icon.", 141 desc = "Show or hide the minimap icon.",
111 order = 7, 142 order = 6,
112 get = function() return PVPScan.db.profile.Minimap.hide end, 143 get = function() return PVPScan.db.profile.Minimap.hide end,
113 set = function (self, val) 144 set = function (self, val)
114 PVPScan.db.profile.Minimap.hide = not PVPScan.db.profile.Minimap.hide 145 PVPScan.db.profile.Minimap.hide = not PVPScan.db.profile.Minimap.hide
115 LDBIcon:Refresh ("PVPScan", PVPScan.db.profile.Minimap) 146 LDBIcon:Refresh ("PVPScan", PVPScan.db.profile.Minimap)
116 if (PVPScan.db.profile.Minimap.hide) then 147 if (PVPScan.db.profile.Minimap.hide) then
151 end 182 end
152 end 183 end
153 184
154 PVPScan:RefreshSpotBars() 185 PVPScan:RefreshSpotBars()
155 PVPScan:LockScanFrame (PVPScan.db.profile.Locked) 186 PVPScan:LockScanFrame (PVPScan.db.profile.Locked)
187
188 PVPScan.EventFrame:SetScript ("OnEvent", PVPScan.OnParserEvent)
156 end 189 end
157 190
158 PVPScan:RegisterChatCommand ("pvpscan", function() 191 PVPScan:RegisterChatCommand ("pvpscan", function()
159 InterfaceOptionsFrame_OpenToCategory ("PVPScan") 192 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
160 InterfaceOptionsFrame_OpenToCategory ("PVPScan") 193 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
205 PVPScan:RegisterEvent ("PLAYER_ENTERING_WORLD", "ChangeZones") 238 PVPScan:RegisterEvent ("PLAYER_ENTERING_WORLD", "ChangeZones")
206 239
207 function PVPScan:EnableScan() 240 function PVPScan:EnableScan()
208 PVPScan.EventFrame:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED") 241 PVPScan.EventFrame:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
209 PVPScan:RefreshSpotBars() 242 PVPScan:RefreshSpotBars()
243 PVPScan.NextBarCheckForHide = GetTime() + PVPScan.db.profile.SpotBarTimeOut
244 PVPScan.BarChecker = PVPScan:ScheduleRepeatingTimer ("CheckBarTimeOut", 5)
210 end 245 end
211 246
212 function PVPScan:DisableScan() 247 function PVPScan:DisableScan()
213 PVPScan.EventFrame:UnregisterEvent ("COMBAT_LOG_EVENT_UNFILTERED") 248 PVPScan.EventFrame:UnregisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
214 PVPScan:RefreshSpotBars() 249 PVPScan:RefreshSpotBars()
250 if (PVPScan.BarChecker) then
251 PVPScan:CancelTimer (PVPScan.BarChecker, true)
252 PVPScan.BarChecker = nil
253 end
215 end 254 end
216 255
217 function PVPScan:LockScanFrame (IsLocked) 256 function PVPScan:LockScanFrame (IsLocked)
218 if (IsLocked) then 257 if (IsLocked) then
219 PVPScanFrame.text:SetText ("") 258 PVPScanFrame.text:SetText ("")
229 ------------------------------------------------------------------------------------------------------------------------------------------------------------ 268 ------------------------------------------------------------------------------------------------------------------------------------------------------------
230 --> outside world scan 269 --> outside world scan
231 270
232 --> parser 271 --> parser
233 272
234 PVPScan.SpotBars = {} 273 PVPScan.SpotBars = {} -- container para os objetos das barras
235 PVPScan.NeedClass = {} 274
236 PVPScan.NextSpotBar = 1 275 PVPScan.NeedClass = {} -- container para os jogadores que precisam saber a classe
237 276 PVPScan.CurrentShownPlayers = {} -- nomes dos jogadores que estão sendo mostrados com o index da barra no valos
238 local CurrentShownIndex = {} 277 PVPScan.CooldownShownPlayers = {} -- nomes dos jogadores com o tempo de quando eles podem ser mostrados novamente nas barras
239 local CurrentShownHash = {} 278
240 local CurrentShownTime = {}
241 local NeutralCandidate = {}
242
243 local find_neutral_players = false
244
245 PVPScan.EventFrame = CreateFrame ("frame", "PVPScanCombatLobReader", UIParent) 279 PVPScan.EventFrame = CreateFrame ("frame", "PVPScanCombatLobReader", UIParent)
246 PVPScan.EventFrame:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED") 280 PVPScan.EventFrame:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
247 281
248 function PVPScan:OnParserEvent (event, time, token, hidding, who_serial, who_name, who_flags, who_flags2, target_serial, target_name, target_flags, target_flags2, ...) 282 function PVPScan:OnParserEvent (event, time, token, hidding, who_serial, who_name, who_flags, who_flags2, target_serial, target_name, target_flags, target_flags2, ...)
249 283
250 if (PVPScan.NeedClass [who_name]) then 284 if (PVPScan.NeedClass [who_name]) then
251 local class = PVPScan:GuessClass (...) 285 local class = PVPScan:GuessClass (...)
252 if (class) then 286 if (class) then
253 PVPScan:UpdateBar (PVPScan.NeedClass [who_name], class, who_name) 287 PVPScan:UpdateBar (PVPScan.SpotBars [PVPScan.CurrentShownPlayers [who_name]], who_name, class, true)
254 PVPScan.NeedClass [who_name] = nil 288 PVPScan.NeedClass [who_name] = nil
255 end 289 end
256 return 290 return
257 end 291 end
258 292
259 if (PVPScan.NeedClass [target_name]) then 293 if (PVPScan.NeedClass [target_name]) then
260 local class = PVPScan:GuessClass (...) 294 local class = PVPScan:GuessClass (...)
261 if (class) then 295 if (class) then
262 PVPScan:UpdateBar (PVPScan.NeedClass [target_name], class, target_name) 296 PVPScan:UpdateBar (PVPScan.SpotBars [PVPScan.CurrentShownPlayers [target_name]], target_name, class, true)
263 PVPScan.NeedClass [target_name] = nil 297 PVPScan.NeedClass [target_name] = nil
264 end 298 end
265 return 299 return
266 end 300 end
267 301
268 if (not CurrentShownHash [target_name] and _bit_band (target_flags, OBJECT_TYPE_PLAYER) ~= 0) then --> is player 302 if (not PVPScan.CurrentShownPlayers [target_name] and _bit_band (target_flags, OBJECT_TYPE_PLAYER) ~= 0) then --> is player
269 if (_bit_band (target_flags, REACTION_HOSTILE) ~= 0) then --> is hostile 303 if (_bit_band (target_flags, REACTION_HOSTILE) ~= 0) then --> is hostile
270 local class = PVPScan:GuessClass (...) 304 local class = PVPScan:GuessClass (...)
271 PVPScan:EnemySpoted (target_name, target_serial, target_flags, class) 305 PVPScan:EnemySpoted (target_name, target_serial, target_flags, class)
272 306 end
273 elseif (find_neutral_players and _bit_band (target_flags, REACTION_NEUTRAL) ~= 0) then 307 end
274 if (NeutralCandidate [target_name]) then 308
275 NeutralCandidate [target_name] = NeutralCandidate [target_name] + 1 309 if (not PVPScan.CurrentShownPlayers [who_name] and _bit_band (who_flags, OBJECT_TYPE_PLAYER) ~= 0) then --> is player
276 if (NeutralCandidate [target_name] == 5) then
277 --print ("neutral", target_name)
278 local class = PVPScan:GuessClass (...)
279 PVPScan:EnemySpoted (target_name, target_serial, target_flags, class)
280 end
281 else
282 NeutralCandidate [target_name] = 1
283 end
284
285 elseif (NeutralCandidate [target_name]) then
286 NeutralCandidate [target_name] = nil
287 end
288 end
289
290 if (not CurrentShownHash [who_name] and _bit_band (who_flags, OBJECT_TYPE_PLAYER) ~= 0) then --> is player
291 if (_bit_band (who_flags, REACTION_HOSTILE) ~= 0) then --> is hostile 310 if (_bit_band (who_flags, REACTION_HOSTILE) ~= 0) then --> is hostile
292 local class = PVPScan:GuessClass (...) 311 local class = PVPScan:GuessClass (...)
293 PVPScan:EnemySpoted (who_name, who_serial, who_flags, class) 312 PVPScan:EnemySpoted (who_name, who_serial, who_flags, class)
294 313 end
295 elseif (find_neutral_players and _bit_band (who_flags, REACTION_NEUTRAL) ~= 0) then 314 end
296 if (NeutralCandidate [who_name]) then 315 end
297 NeutralCandidate [who_name] = NeutralCandidate [who_name] + 1 316
298 if (NeutralCandidate [who_name] == 5) then
299 --print ("neutral", who_name)
300 local class = PVPScan:GuessClass (...)
301 PVPScan:EnemySpoted (who_name, who_serial, who_flags, class)
302 end
303 else
304 NeutralCandidate [who_name] = 1
305 end
306
307 elseif (NeutralCandidate [who_name]) then
308 NeutralCandidate [who_name] = nil
309 end
310 end
311 end
312
313 PVPScan.EventFrame:SetScript ("OnEvent", PVPScan.OnParserEvent)
314
315 function PVPScan:LeftCombatLockdown() 317 function PVPScan:LeftCombatLockdown()
316 if (PVPScan.schedule_frame_update) then 318 if (PVPScan.schedule_frame_update) then
317 PVPScan.schedule_frame_update = false 319 PVPScan.schedule_frame_update = false
318 PVPScan:RefreshSpotBars() 320 PVPScan:RefreshSpotBars()
319 end 321 end
322 PVPScan:CheckNonCombatSpotBars()
320 end 323 end
321 function PVPScan:GotCombatLockdown() 324 function PVPScan:GotCombatLockdown()
325 end
326
327 function PVPScan:GetNextSpotBar()
328 for i = 1, PVPScan.db.profile.SpotBarAmount do
329 local bar = PVPScan.SpotBars [i]
330 if (not bar) then
331 print (i, #PVPScan.SpotBars)
332 end
333 if (not bar.InUse and bar.Cooldown < GetTime()) then
334 return bar
335 end
336 end
337 return nil
322 end 338 end
323 339
324 PVPScan:RegisterEvent ("PLAYER_REGEN_DISABLED", "GotCombatLockdown") 340 PVPScan:RegisterEvent ("PLAYER_REGEN_DISABLED", "GotCombatLockdown")
325 PVPScan:RegisterEvent ("PLAYER_REGEN_ENABLED", "LeftCombatLockdown") 341 PVPScan:RegisterEvent ("PLAYER_REGEN_ENABLED", "LeftCombatLockdown")
326 342
327 -- found a enemy on the scan 343 -- found a enemy on the scan
328
329 function PVPScan:EnemySpoted (name, serial, flags, class) 344 function PVPScan:EnemySpoted (name, serial, flags, class)
330 345
346 --se nao tiver nome, nao interessa
331 if (not name) then 347 if (not name) then
332 return 348 return
333 end 349 end
334 350
335 --> check for overwrite 351 --se o player tiver no cooldown para mostrar, ignora-lo
336 local current_player_shown = CurrentShownIndex [PVPScan.NextSpotBar] 352 if (PVPScan.CooldownShownPlayers [name] and PVPScan.CooldownShownPlayers [name] > GetTime()) then
337 if (current_player_shown) then 353 return
338 PVPScan.NeedClass [current_player_shown] = nil 354 end
339 end 355
340 356 local SpotBar = PVPScan:GetNextSpotBar()
341 local SpotBar = PVPScan.SpotBars [PVPScan.NextSpotBar] 357
342 358 if (not SpotBar) then
343 if (class) then 359 return
344 PVPScan:UpdateBar (PVPScan.NextSpotBar, class, name) 360 end
345 else 361
346 PVPScan:UpdateBar (PVPScan.NextSpotBar, nil, name) 362 --seta o cooldown deste jogador
347 PVPScan.NeedClass [name] = PVPScan.NextSpotBar 363 PVPScan.CooldownShownPlayers [name] = GetTime() + PVPScan.db.profile.SpotBarPlayerCooldown
348 end 364 --seta em qual barra o jogador esta sendo mostrado
349 365 PVPScan.CurrentShownPlayers [name] = SpotBar.Index
350 CurrentShownIndex [PVPScan.NextSpotBar] = name 366
351 CurrentShownHash [name] = PVPScan.NextSpotBar 367 --se nao tiver uma classe, agendar uma pesquisa
352 CurrentShownTime [name] = GetTime() 368 if (not class) then
353 369 PVPScan.NeedClass [name] = true
354 if (not UnitAffectingCombat ("player") and not InCombatLockdown()) then 370 end
355 SpotBar:SetAttribute ("macrotext", "/cleartarget\n/targetexact " .. name) 371
356 end 372 --atualiza a barra
357 373 PVPScan:UpdateBar (SpotBar, name, class)
358 SpotBar:Show() 374
359 375 --toca o som se a configuracao permitir
360 PVPScan.NextSpotBar = PVPScan.NextSpotBar + 1 376 if (PVPScan.db.profile.SoundPlay) then
361 if (PVPScan.NextSpotBar > PVPScan.db.profile.SpotBarAmount) then 377 local sound = PVPScan.db.profile.SoundFile
362 PVPScan.NextSpotBar = 1 378 sound = SharedMedia:Fetch ("sound", sound)
363 end 379 if (sound) then
364 380 PlaySoundFile (sound, "Master")
381 end
382 end
365 end 383 end
366 384
367 -- frames 385 -- frames
386
387 function PVPScanOnFrameEnter (self)
388 GameTooltip:SetOwner (self, "ANCHOR_TOPLEFT")
389 GameTooltip:ClearLines()
390 GameTooltip:AddLine ("Right Click To Open Options Panel")
391 GameTooltip:Show()
392 end
393
394 function PVPScanOnFrameLeave (self)
395 GameTooltip:Hide()
396 end
368 397
369 function PVPScanOnFrameMouseDown (self, button) 398 function PVPScanOnFrameMouseDown (self, button)
370 if (button == "LeftButton") then 399 if (button == "LeftButton") then
371 if (not self.IsMoving) then 400 if (not self.IsMoving) then
372 self:StartMoving() 401 self:StartMoving()
386 InterfaceOptionsFrame_OpenToCategory ("PVPScan") 415 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
387 InterfaceOptionsFrame_OpenToCategory ("PVPScan") 416 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
388 end 417 end
389 end 418 end
390 419
391 function PVPScan:UpdateBar (index, class, name) 420 function PVPScan:CheckNonCombatSpotBars()
392 421 for i = 1, PVPScan.db.profile.SpotBarAmount do
422 local SpotObject = PVPScan.SpotBars [i]
423 if (SpotObject.InUse and (SpotObject.NonTargetFrame:IsShown() or SpotObject.NeedUpdate)) then
424 PVPScan:UpdateBar (SpotObject, SpotObject.PlayerName, SpotObject.PlayerClass)
425 end
426 end
427 end
428
429 function PVPScan:UpdateBar (SpotObject, Name, Class, ClassUpdate)
430
431 SpotObject.IsShown = true
432 SpotObject.InUse = true
433 SpotObject.PlayerName = Name
434 SpotObject.PlayerClass = Class
435 SpotObject.Cooldown = GetTime() + PVPScan.db.profile.SpotBarCooldown
436 SpotObject.ExpireAt = GetTime() + PVPScan.db.profile.SpotBarTimeOut
437 SpotObject.NeedUpdate = false
438
439 if (ClassUpdate) then
440 if (SpotObject.TargetFrame:IsShown()) then
441 if (not UnitAffectingCombat ("player") and not InCombatLockdown()) then
442 local color = RAID_CLASS_COLORS [Class]
443 local texcoord = CLASS_ICON_TCOORDS [Class]
444 SpotObject.TargetFrame.classtexture:SetVertexColor (color.r, color.g, color.b)
445 SpotObject.TargetFrame.classicon:SetTexture ([[Interface\Glues\CHARACTERCREATE\UI-CHARACTERCREATE-CLASSES]])
446 SpotObject.TargetFrame.classicon:SetTexCoord (unpack (texcoord))
447 else
448 SpotObject.NeedUpdate = true
449 end
450 else
451 local color = RAID_CLASS_COLORS [Class]
452 local texcoord = CLASS_ICON_TCOORDS [Class]
453 SpotObject.NonTargetFrame.classtexture:SetVertexColor (color.r, color.g, color.b)
454 SpotObject.NonTargetFrame.classicon:SetTexture ([[Interface\Glues\CHARACTERCREATE\UI-CHARACTERCREATE-CLASSES]])
455 SpotObject.NonTargetFrame.classicon:SetTexCoord (unpack (texcoord))
456 end
457 end
458
393 if (UnitAffectingCombat ("player") or InCombatLockdown()) then 459 if (UnitAffectingCombat ("player") or InCombatLockdown()) then
394 --return 460 --> enable in combat bat
395 end 461 if (Class) then
396 462 local color = RAID_CLASS_COLORS [Class]
397 local SpotBar = PVPScan.SpotBars [index] 463 local texcoord = CLASS_ICON_TCOORDS [Class]
398 464 SpotObject.NonTargetFrame.classtexture:SetVertexColor (color.r, color.g, color.b)
399 if (class) then 465 SpotObject.NonTargetFrame.classicon:SetTexture ([[Interface\Glues\CHARACTERCREATE\UI-CHARACTERCREATE-CLASSES]])
400 local color = RAID_CLASS_COLORS [class] 466 SpotObject.NonTargetFrame.classicon:SetTexCoord (unpack (texcoord))
401 SpotBar.classtexture:SetVertexColor (color.r, color.g, color.b) 467 else
402 468 SpotObject.NonTargetFrame.classtexture:SetVertexColor (.7, .7, .7)
403 local texcoord = CLASS_ICON_TCOORDS [class] 469 SpotObject.NonTargetFrame.classicon:SetTexture ([[Interface\InventoryItems\WoWUnknownItem01]])
404 SpotBar.classicon:SetTexture ([[Interface\Glues\CHARACTERCREATE\UI-CHARACTERCREATE-CLASSES]]) 470 SpotObject.NonTargetFrame.classicon:SetTexCoord (0, 1, 0, 1)
405 SpotBar.classicon:SetTexCoord (unpack (texcoord)) 471 end
472 SpotObject.NonTargetFrame.name:SetText (Name)
473 SpotObject.NonTargetFrame:Show()
474 SpotObject.NeedUpdate = true
406 else 475 else
407 SpotBar.classtexture:SetVertexColor (.7, .7, .7) 476 --> enable spot bar
408 SpotBar.classicon:SetTexture ([[Interface\InventoryItems\WoWUnknownItem01]]) 477 if (Class) then
409 SpotBar.classicon:SetTexCoord (0, 1, 0, 1) 478 local color = RAID_CLASS_COLORS [Class]
410 end 479 local texcoord = CLASS_ICON_TCOORDS [Class]
411 480 SpotObject.TargetFrame.classtexture:SetVertexColor (color.r, color.g, color.b)
412 SpotBar.name:SetText (name) 481 SpotObject.TargetFrame.classicon:SetTexture ([[Interface\Glues\CHARACTERCREATE\UI-CHARACTERCREATE-CLASSES]])
413 482 SpotObject.TargetFrame.classicon:SetTexCoord (unpack (texcoord))
483 else
484 SpotObject.TargetFrame.classtexture:SetVertexColor (.7, .7, .7)
485 SpotObject.TargetFrame.classicon:SetTexture ([[Interface\InventoryItems\WoWUnknownItem01]])
486 SpotObject.TargetFrame.classicon:SetTexCoord (0, 1, 0, 1)
487 end
488 SpotObject.TargetFrame:SetAttribute ("macrotext", "/cleartarget\n/targetexact " .. Name)
489 SpotObject.TargetFrame.name:SetText (Name)
490 SpotObject.TargetFrame.SpotObject = SpotObject
491 SpotObject.NonTargetFrame:Hide()
492 SpotObject.TargetFrame:Show()
493 end
494 end
495
496 function PVPScan:CheckBarTimeOut()
497 if (not UnitAffectingCombat ("player") and not InCombatLockdown()) then
498
499 local time = GetTime()
500
501 for repeat_twice = 1, 2 do
502 for i = 1, PVPScan.db.profile.SpotBarAmount do
503
504 local SpotObject = PVPScan.SpotBars [i]
505
506 if (SpotObject.InUse) then
507 --verifica se expirou
508 if (SpotObject.ExpireAt < time) then
509 PVPScan:DisableSpotBar (SpotObject)
510 end
511 else
512 for o = i+1, PVPScan.db.profile.SpotBarAmount do
513 local NextSpotObject = PVPScan.SpotBars [o]
514 if (NextSpotObject.InUse) then --> transferir pra cá
515 --seta a nova barra
516 local PlayerName = NextSpotObject.PlayerName
517 PVPScan:UpdateBar (SpotObject, PlayerName, NextSpotObject.PlayerClass)
518 --desliga a barra antiga
519 PVPScan:DisableSpotBar (NextSpotObject)
520 --seta em qual barra o jogador esta sendo mostrado
521 PVPScan.CurrentShownPlayers [PlayerName] = i
522 break
523 end
524 end
525 end
526 end
527 end
528 end
529
530 end
531
532 function PVPScanSpotBarClick (self)
533 if (self.SpotObject) then
534 self.SpotObject.Cooldown = GetTime() + PVPScan.db.profile.SpotBarCooldown
535 self.SpotObject.ExpireAt = GetTime() + PVPScan.db.profile.SpotBarTimeOut
536 end
537 end
538
539 function PVPScan:DisableSpotBar (SpotObject)
540 SpotObject.TargetFrame:Hide()
541 SpotObject.TargetFrame.SpotObject = nil
542 SpotObject.NonTargetFrame:Hide()
543
544 SpotObject.IsShown = false
545 SpotObject.NeedUpdate = false
546 SpotObject.InUse = false
547 SpotObject.Cooldown = 0
548 SpotObject.ExpireAt = 0
549
550 local name = SpotObject.PlayerName
551
552 if (name) then
553 PVPScan.NeedClass [name] = nil
554 PVPScan.CurrentShownPlayers [name] = nil
555 PVPScan.CooldownShownPlayers [name] = nil
556 end
557
558 SpotObject.PlayerName = nil
559 SpotObject.PlayerClass = nil
414 end 560 end
415 561
416 function PVPScan:RefreshSpotBars() 562 function PVPScan:RefreshSpotBars()
417 563
418 if (UnitAffectingCombat ("player") or InCombatLockdown()) then 564 if (UnitAffectingCombat ("player") or InCombatLockdown()) then
432 578
433 --> we need extra bars? 579 --> we need extra bars?
434 if (amount_bars > #PVPScan.SpotBars) then 580 if (amount_bars > #PVPScan.SpotBars) then
435 for i = #PVPScan.SpotBars+1, amount_bars do 581 for i = #PVPScan.SpotBars+1, amount_bars do
436 582
437 local new_bar = CreateFrame ("Button", "PVPScanSpotBar" .. i, PVPScanFrame, "PVPScanSpotBarTemplate") 583 local NewBarObject = {
584 Index = i,
585 TargetFrame = CreateFrame ("Button", "PVPScanSpotBar" .. i, PVPScanFrame, "PVPScanSpotBarTemplate"),
586 NonTargetFrame = CreateFrame ("Button", "PVPScanSpotBarInCombat" .. i, PVPScanFrame, "PVPScanSpotBarInCombatTemplate"),
587 IsShown = false, -- se a barra esta sendo mostrada
588 PlayerName = nil, -- nome do jogador que esta sendo mostrado
589 PlayerClass = nil,
590 NeedUpdate = false, -- se a barra precisa de um update após o termino do combate
591 InUse = false, -- se a barra esta em uso
592 ExpireAt = 0, -- quando a barra ira sumir automaticamente
593 Cooldown = 0, -- tempo para poder por outro jogador nesta barra
594 }
595
596 NewBarObject.NonTargetFrame:SetFrameLevel (NewBarObject.TargetFrame:GetFrameLevel()+1)
438 597
439 local y = (i-1) * PVPScan.db.profile.SpotBarHeight * -1 598 local y = (i-1) * PVPScan.db.profile.SpotBarHeight * -1
440 599
441 new_bar:SetPoint ("topleft", PVPScanFrame, "topleft", 0, y) 600 NewBarObject.TargetFrame:SetPoint ("topleft", PVPScanFrame, "topleft", 0, y)
442 new_bar:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight) 601 NewBarObject.NonTargetFrame:SetPoint ("topleft", PVPScanFrame, "topleft", 0, y)
443 602
444 tinsert (PVPScan.SpotBars, new_bar) 603 NewBarObject.TargetFrame:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight)
604 NewBarObject.NonTargetFrame:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight)
605
606 tinsert (PVPScan.SpotBars, NewBarObject)
445 end 607 end
446 end 608 end
447 609
448 if (#PVPScan.SpotBars > amount_bars) then 610 if (#PVPScan.SpotBars > amount_bars) then
449 for i = #PVPScan.SpotBars, amount_bars+1, -1 do 611 for i = #PVPScan.SpotBars, amount_bars+1, -1 do
450 PVPScan.SpotBars [i]:Hide() 612 PVPScan:DisableSpotBar (PVPScan.SpotBars [i])
451 local name = CurrentShownIndex [i]
452 if (name) then
453 tremove (CurrentShownIndex, i)
454 CurrentShownHash [name] = nil
455 CurrentShownTime [name] = nil
456 PVPScan.NeedClass [name] = nil
457 end
458 end 613 end
459 end 614 end
460 615
461 --> refresh existing 616 --> refresh existing
462 for index, bar in ipairs (PVPScan.SpotBars) do 617 for Index, BarObject in ipairs (PVPScan.SpotBars) do
463 local y = (index-1) * PVPScan.db.profile.SpotBarHeight * -1 618 local y = (Index-1) * PVPScan.db.profile.SpotBarHeight * -1
464 bar:SetPoint ("topleft", PVPScanFrame, "bottomleft", 0, y) 619 --point
465 bar:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight) 620 BarObject.TargetFrame:SetPoint ("topleft", PVPScanFrame, "bottomleft", 0, y)
466 bar.classtexture:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight) 621 BarObject.NonTargetFrame:SetPoint ("topleft", PVPScanFrame, "bottomleft", 0, y)
467 bar.classicon:SetSize (PVPScan.db.profile.SpotBarHeight, PVPScan.db.profile.SpotBarHeight) 622 --size
623 BarObject.TargetFrame:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight)
624 BarObject.NonTargetFrame:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight)
625 --texture size
626 BarObject.TargetFrame.classtexture:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight)
627 BarObject.NonTargetFrame.classtexture:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight)
628 --bar texture
629 BarObject.TargetFrame.classtexture:SetTexture (SharedMedia:Fetch ("statusbar", PVPScan.db.profile.SpotBarTexture) or [[Interface\PaperDollInfoFrame\UI-Character-Skills-Bar]])
630 BarObject.NonTargetFrame.classtexture:SetTexture (SharedMedia:Fetch ("statusbar", PVPScan.db.profile.SpotBarTexture) or [[Interface\PaperDollInfoFrame\UI-Character-Skills-Bar]])
631 --icon size
632 BarObject.TargetFrame.classicon:SetSize (PVPScan.db.profile.SpotBarHeight, PVPScan.db.profile.SpotBarHeight)
633 BarObject.NonTargetFrame.classicon:SetSize (PVPScan.db.profile.SpotBarHeight, PVPScan.db.profile.SpotBarHeight)
468 end 634 end
469 635
470 end 636 end
471 637
472 --> misc 638 --> misc
477 if (type (arg1) == "number") then 643 if (type (arg1) == "number") then
478 if (PVPScan.ClassSpellList [arg1]) then 644 if (PVPScan.ClassSpellList [arg1]) then
479 return PVPScan.ClassSpellList [arg1] 645 return PVPScan.ClassSpellList [arg1]
480 end 646 end
481 end 647 end
482 648
483 if (type (arg3) == "number") then
484 if (PVPScan.ClassSpellList [arg3]) then
485 return PVPScan.ClassSpellList [arg3]
486 end
487 end
488
489 if (type (arg2) == "number") then
490 if (PVPScan.ClassSpellList [arg3]) then
491 return PVPScan.ClassSpellList [arg3]
492 end
493 end
494
495 if (type (arg4) == "number") then
496 if (PVPScan.ClassSpellList [arg4]) then
497 return PVPScan.ClassSpellList [arg4]
498 end
499 end
500
501 return nil 649 return nil
502 end 650 end
503 651
504 652
505 ------------------------------------------------------------------------------------------------------------------------------------------------------------ 653 ------------------------------------------------------------------------------------------------------------------------------------------------------------