annotate PVPScan.lua @ 8:2f9d1a15506a

- no more tracking on PvE servers.
author Tercioo
date Sat, 19 Dec 2015 20:05:50 -0200
parents bd92dffef495
children f2a55f2d45c8
rev   line source
tercio@0 1
tercio@2 2 PVPScan = LibStub ("AceAddon-3.0"):NewAddon ("PVPScan", "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0")
Tercio@6 3
tercio@3 4 local PVPScan = PVPScan
tercio@0 5 local LDB = LibStub ("LibDataBroker-1.1", true)
tercio@0 6 local LDBIcon = LDB and LibStub ("LibDBIcon-1.0", true)
tercio@0 7 local SharedMedia = LibStub:GetLibrary("LibSharedMedia-3.0")
tercio@0 8
tercio@0 9 local _bit_band = bit.band
tercio@2 10 local GetTime = GetTime
tercio@0 11
tercio@0 12 local REACTION_HOSTILE = 0x00000040
tercio@1 13 local REACTION_NEUTRAL = 0x00000020
tercio@1 14
tercio@0 15 local OBJECT_TYPE_PLAYER = 0x00000400
tercio@0 16
tercio@1 17 PVPScan.IsInBattleground = false
tercio@1 18 PVPScan.IsInCity = false
tercio@1 19 PVPScan.IsInArena = false
tercio@1 20 PVPScan.IsInOutDoors = true
tercio@1 21 PVPScan.ScanEnabled = true
tercio@0 22
tercio@0 23 local default_db = {
tercio@0 24 profile = {
tercio@0 25 SpotBarHeight = 20,
tercio@0 26 SpotBarAmount = 5,
tercio@0 27 SpotBarWidth = 150,
tercio@2 28 SpotBarTexture = "Blizzard Character Skills Bar",
tercio@2 29 SpotBarTimeOut = 10,
tercio@2 30 SpotBarCooldown = 5,
tercio@2 31 SpotBarPlayerCooldown = 10,
tercio@0 32 Locked = false,
tercio@0 33 SoundPlay = false,
tercio@0 34 SoundFile = "",
tercio@0 35 Minimap = {hide = false, radius = 160, minimapPos = 220},
tercio@0 36 },
tercio@0 37 }
tercio@0 38
tercio@0 39 function PVPScan:OnEnable()
tercio@0 40 end
tercio@0 41
tercio@0 42 function PVPScan:OnDisable()
tercio@0 43 end
tercio@0 44
tercio@0 45 local OptionsTable = {
tercio@0 46 name = "PVPScan",
tercio@0 47 type = "group",
tercio@0 48 args = {
tercio@0 49 SpotBarHeight = {
tercio@0 50 type = "range",
tercio@0 51 name = "Bar Height",
tercio@0 52 desc = "Change the height of spot bars.",
tercio@0 53 min = 10,
tercio@0 54 max = 40,
tercio@0 55 step = 1,
tercio@0 56 get = function() return PVPScan.db.profile.SpotBarHeight end,
tercio@0 57 set = function (self, val) PVPScan.db.profile.SpotBarHeight = val; PVPScan:RefreshSpotBars() end,
tercio@0 58 order = 1,
tercio@0 59 },
tercio@0 60 SpotBarWidth = {
tercio@0 61 type = "range",
tercio@0 62 name = "Bar Width",
tercio@0 63 desc = "Change the width of spot bars.",
tercio@0 64 min = 50,
tercio@0 65 max = 250,
tercio@0 66 step = 1,
tercio@0 67 get = function() return PVPScan.db.profile.SpotBarWidth end,
tercio@0 68 set = function (self, val) PVPScan.db.profile.SpotBarWidth = val; PVPScan:RefreshSpotBars() end,
tercio@0 69 order = 2,
tercio@0 70 },
tercio@0 71 SpotBarAmount = {
tercio@0 72 type = "range",
tercio@0 73 name = "Bar Amount",
tercio@0 74 desc = "Change the amount of spot bars.",
tercio@0 75 min = 1,
tercio@0 76 max = 40,
tercio@0 77 step = 1,
tercio@0 78 get = function() return PVPScan.db.profile.SpotBarAmount end,
tercio@0 79 set = function (self, val) PVPScan.db.profile.SpotBarAmount = val; PVPScan:RefreshSpotBars() end,
tercio@0 80 order = 3,
tercio@0 81 },
tercio@2 82 SpotBarTexture = {
tercio@2 83 type = "select",
tercio@2 84 name = "Bar Texture",
tercio@2 85 desc = "Choose the texture used on target bars.",
tercio@2 86 values = function()
tercio@2 87 local TextureTable = {}
tercio@2 88 for name, _ in pairs (SharedMedia:HashTable ("statusbar")) do
tercio@2 89 TextureTable [name] = name
tercio@2 90 end
tercio@2 91 return TextureTable
tercio@2 92 end,
tercio@2 93 get = function() return PVPScan.db.profile.SpotBarTexture end,
tercio@2 94 set = function (self, file) PVPScan.db.profile.SpotBarTexture = file; PVPScan:RefreshSpotBars() end,
tercio@2 95 order = 4,
tercio@2 96 },
tercio@2 97 SpotBarTimeOut = {
tercio@2 98 type = "range",
tercio@2 99 name = "Time Out",
tercio@2 100 desc = "How many time wait until the bar auto hide.",
tercio@2 101 min = 5,
tercio@2 102 max = 120,
tercio@2 103 step = 5,
tercio@2 104 get = function() return PVPScan.db.profile.SpotBarTimeOut end,
tercio@2 105 set = function (self, val) PVPScan.db.profile.SpotBarTimeOut = val; end,
tercio@2 106 order = 9,
tercio@2 107 },
tercio@0 108 Locked = {
tercio@0 109 type = "toggle",
tercio@1 110 name = "Lock Scan Frame",
tercio@0 111 desc = "Lock or unlock the SpotBars Frame.",
tercio@2 112 order = 5,
tercio@0 113 get = function() return PVPScan.db.profile.Locked end,
tercio@1 114 set = function (self, val) PVPScan.db.profile.Locked = not PVPScan.db.profile.Locked; PVPScan:LockScanFrame (PVPScan.db.profile.Locked) end,
tercio@0 115 },
tercio@0 116 SoundPlay = {
tercio@0 117 type = "toggle",
tercio@0 118 name = "Play Sound",
tercio@0 119 desc = "Play a sound when a enemy is found.",
tercio@2 120 order = 7,
tercio@0 121 get = function() return PVPScan.db.profile.SoundPlay end,
tercio@0 122 set = function (self, val) PVPScan.db.profile.SoundPlay = not PVPScan.db.profile.SoundPlay end,
tercio@0 123 },
tercio@0 124 SoundFile = {
tercio@0 125 type = "select",
tercio@0 126 name = "Sound File",
tercio@0 127 desc = "Choose the sound to play when a enemy is found.",
tercio@0 128 values = function()
tercio@0 129 local SoundTable = {}
tercio@0 130 for name, _ in pairs (SharedMedia:HashTable ("sound")) do
tercio@0 131 SoundTable [name] = name
tercio@0 132 end
tercio@0 133 return SoundTable
tercio@0 134 end,
tercio@0 135 get = function() return PVPScan.db.profile.SoundFile end,
tercio@0 136 set = function (self, file) PVPScan.db.profile.SoundFile = file end,
tercio@2 137 order = 8,
tercio@0 138 },
tercio@0 139 Minimap = {
tercio@0 140 type = "toggle",
tercio@0 141 name = "Hide Minimap Icon",
tercio@0 142 desc = "Show or hide the minimap icon.",
tercio@2 143 order = 6,
tercio@0 144 get = function() return PVPScan.db.profile.Minimap.hide end,
tercio@0 145 set = function (self, val)
tercio@0 146 PVPScan.db.profile.Minimap.hide = not PVPScan.db.profile.Minimap.hide
tercio@0 147 LDBIcon:Refresh ("PVPScan", PVPScan.db.profile.Minimap)
tercio@0 148 if (PVPScan.db.profile.Minimap.hide) then
tercio@0 149 LDBIcon:Hide ("PVPScan")
tercio@0 150 else
tercio@0 151 LDBIcon:Show ("PVPScan")
tercio@0 152 end
tercio@0 153 end,
tercio@0 154 },
tercio@0 155 },
tercio@0 156 }
tercio@0 157
tercio@0 158 function PVPScan:OnInitialize()
tercio@0 159
tercio@0 160 --declarar primeiro o db usando a global que é declarada no toc.
tercio@0 161 self.db = LibStub ("AceDB-3.0"):New ("PVPScanDB", default_db, true)
tercio@0 162
tercio@0 163 --declara agora as opções da tab raiz
tercio@0 164 LibStub("AceConfig-3.0"):RegisterOptionsTable ("PVPScan", OptionsTable)
tercio@0 165 PVPScan.OptionsFrame1 = LibStub ("AceConfigDialog-3.0"):AddToBlizOptions ("PVPScan", "PVPScan")
tercio@0 166 --sub tab
tercio@0 167 LibStub ("AceConfig-3.0"):RegisterOptionsTable ("PVPScan-Profiles", LibStub ("AceDBOptions-3.0"):GetOptionsTable (self.db))
tercio@0 168 PVPScan.OptionsFrame2 = LibStub ("AceConfigDialog-3.0"):AddToBlizOptions ("PVPScan-Profiles", "Profiles", "PVPScan")
tercio@0 169
tercio@0 170 if LDB then
tercio@0 171 local databroker = LDB:NewDataObject ("PVPScan", {
tercio@0 172 type = "launcher",
tercio@0 173 icon = [[Interface\PvPRankBadges\PvPRank15]],
tercio@0 174 --HotCornerIgnore = true,
tercio@0 175 OnClick = function (self, button)
tercio@0 176 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
tercio@0 177 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
tercio@0 178 end
tercio@0 179 })
tercio@0 180
tercio@0 181 if (databroker and not LDBIcon:IsRegistered ("PVPScan")) then
tercio@0 182 LDBIcon:Register ("PVPScan", databroker, PVPScan.db.profile.Minimap)
tercio@0 183 end
tercio@0 184 end
tercio@0 185
tercio@0 186 PVPScan:RefreshSpotBars()
tercio@1 187 PVPScan:LockScanFrame (PVPScan.db.profile.Locked)
tercio@2 188
tercio@2 189 PVPScan.EventFrame:SetScript ("OnEvent", PVPScan.OnParserEvent)
tercio@0 190 end
tercio@0 191
tercio@0 192 PVPScan:RegisterChatCommand ("pvpscan", function()
tercio@0 193 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
tercio@0 194 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
tercio@0 195 end)
tercio@0 196
tercio@1 197
tercio@0 198 ------------------------------------------------------------------------------------------------------------------------------------------------------------
tercio@1 199 --> general
tercio@0 200
tercio@1 201 function PVPScan:ChangeZones()
tercio@1 202
tercio@1 203 local name, type, difficulty, difficultyName, maxPlayers, playerDifficulty, isDynamicInstance, mapID, instanceGroupSize = GetInstanceInfo()
tercio@1 204 local pvpType, isFFA, faction = GetZonePVPInfo()
tercio@1 205
tercio@1 206 PVPScan.IsInBattleground = false
tercio@1 207 PVPScan.IsInCity = false
tercio@1 208 PVPScan.IsInArena = false
tercio@1 209 PVPScan.IsInOutDoors = false
tercio@1 210 PVPScan.ScanEnabled = false
tercio@1 211
tercio@1 212 if (pvpType == "contested" and (not type or type == "none")) then
tercio@1 213 PVPScan.IsInOutDoors = true
tercio@1 214 PVPScan.ScanEnabled = true
tercio@1 215
tercio@1 216 elseif (type == "pvp") then
tercio@1 217 PVPScan.IsInBattleground = true
tercio@1 218
tercio@1 219 elseif (type == "arena") then
tercio@1 220 PVPScan.IsInArena = true
tercio@1 221
tercio@1 222 elseif (type and (type == "scenario" or type == "party" or type == "raid" or pvpType == "friendly" or pvpType == "sanctuary")) then
tercio@1 223 PVPScan.ScanEnabled = false
tercio@1 224
tercio@1 225 else
tercio@1 226 PVPScan.IsInOutDoors = true
tercio@1 227 PVPScan.ScanEnabled = true
tercio@1 228 end
tercio@1 229
tercio@1 230 if (PVPScan.ScanEnabled) then
tercio@1 231 PVPScan:EnableScan()
tercio@1 232 else
tercio@1 233 PVPScan:DisableScan()
tercio@1 234 end
tercio@1 235
tercio@1 236 end
tercio@1 237
tercio@1 238 PVPScan:RegisterEvent ("ZONE_CHANGED_NEW_AREA", "ChangeZones")
tercio@1 239 PVPScan:RegisterEvent ("PLAYER_ENTERING_WORLD", "ChangeZones")
tercio@1 240
tercio@1 241 function PVPScan:EnableScan()
tercio@1 242 PVPScan.EventFrame:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
tercio@1 243 PVPScan:RefreshSpotBars()
tercio@2 244 PVPScan.NextBarCheckForHide = GetTime() + PVPScan.db.profile.SpotBarTimeOut
tercio@2 245 PVPScan.BarChecker = PVPScan:ScheduleRepeatingTimer ("CheckBarTimeOut", 5)
tercio@1 246 end
tercio@1 247
tercio@1 248 function PVPScan:DisableScan()
tercio@1 249 PVPScan.EventFrame:UnregisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
tercio@1 250 PVPScan:RefreshSpotBars()
tercio@2 251 if (PVPScan.BarChecker) then
tercio@2 252 PVPScan:CancelTimer (PVPScan.BarChecker, true)
tercio@2 253 PVPScan.BarChecker = nil
tercio@2 254 end
tercio@1 255 end
tercio@1 256
tercio@1 257 function PVPScan:LockScanFrame (IsLocked)
tercio@1 258 if (IsLocked) then
tercio@1 259 PVPScanFrame.text:SetText ("")
tercio@1 260 PVPScanFrame:SetBackdrop (nil)
tercio@1 261 PVPScanFrame:EnableMouse (false)
tercio@1 262 else
tercio@1 263 PVPScanFrame.text:SetText ("PVPScan Anchor")
tercio@1 264 PVPScanFrame:SetBackdrop ({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tile = true, TileSize = 64})
tercio@1 265 PVPScanFrame:SetBackdropColor (0, 0, 0, 1)
tercio@1 266 PVPScanFrame:EnableMouse (true)
tercio@1 267 end
tercio@1 268 end
tercio@1 269 ------------------------------------------------------------------------------------------------------------------------------------------------------------
tercio@1 270 --> outside world scan
tercio@1 271
tercio@1 272 --> parser
tercio@1 273
tercio@2 274 PVPScan.SpotBars = {} -- container para os objetos das barras
tercio@2 275
tercio@2 276 PVPScan.NeedClass = {} -- container para os jogadores que precisam saber a classe
tercio@2 277 PVPScan.CurrentShownPlayers = {} -- nomes dos jogadores que estão sendo mostrados com o index da barra no valos
tercio@2 278 PVPScan.CooldownShownPlayers = {} -- nomes dos jogadores com o tempo de quando eles podem ser mostrados novamente nas barras
tercio@1 279
tercio@1 280 PVPScan.EventFrame = CreateFrame ("frame", "PVPScanCombatLobReader", UIParent)
tercio@1 281 PVPScan.EventFrame:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
tercio@0 282
tercio@0 283 function PVPScan:OnParserEvent (event, time, token, hidding, who_serial, who_name, who_flags, who_flags2, target_serial, target_name, target_flags, target_flags2, ...)
tercio@0 284
tercio@0 285 if (PVPScan.NeedClass [who_name]) then
tercio@0 286 local class = PVPScan:GuessClass (...)
tercio@0 287 if (class) then
tercio@2 288 PVPScan:UpdateBar (PVPScan.SpotBars [PVPScan.CurrentShownPlayers [who_name]], who_name, class, true)
tercio@0 289 PVPScan.NeedClass [who_name] = nil
tercio@0 290 end
tercio@0 291 return
tercio@0 292 end
tercio@0 293
tercio@2 294 if (not PVPScan.CurrentShownPlayers [target_name] and _bit_band (target_flags, OBJECT_TYPE_PLAYER) ~= 0) then --> is player
tercio@1 295 if (_bit_band (target_flags, REACTION_HOSTILE) ~= 0) then --> is hostile
Tercioo@8 296 local pvpType, isFFA, faction = GetZonePVPInfo()
Tercioo@8 297 if (pvpType ~= "contested" and pvpType ~= "hostile") then
Tercioo@8 298 return
Tercioo@8 299 end
tercio@0 300 local class = PVPScan:GuessClass (...)
tercio@0 301 PVPScan:EnemySpoted (target_name, target_serial, target_flags, class)
tercio@0 302 end
tercio@0 303 end
tercio@0 304
tercio@2 305 if (not PVPScan.CurrentShownPlayers [who_name] and _bit_band (who_flags, OBJECT_TYPE_PLAYER) ~= 0) then --> is player
tercio@1 306 if (_bit_band (who_flags, REACTION_HOSTILE) ~= 0) then --> is hostile
Tercioo@8 307 local pvpType, isFFA, faction = GetZonePVPInfo()
Tercioo@8 308 if (pvpType ~= "contested" and pvpType ~= "hostile") then
Tercioo@8 309 return
Tercioo@8 310 end
tercio@0 311 local class = PVPScan:GuessClass (...)
tercio@0 312 PVPScan:EnemySpoted (who_name, who_serial, who_flags, class)
tercio@0 313 end
tercio@0 314 end
tercio@0 315 end
tercio@0 316
tercio@0 317 function PVPScan:LeftCombatLockdown()
tercio@0 318 if (PVPScan.schedule_frame_update) then
tercio@0 319 PVPScan.schedule_frame_update = false
tercio@0 320 PVPScan:RefreshSpotBars()
tercio@0 321 end
tercio@2 322 PVPScan:CheckNonCombatSpotBars()
tercio@0 323 end
tercio@0 324 function PVPScan:GotCombatLockdown()
tercio@0 325 end
tercio@0 326
tercio@2 327 function PVPScan:GetNextSpotBar()
tercio@2 328 for i = 1, PVPScan.db.profile.SpotBarAmount do
tercio@2 329 local bar = PVPScan.SpotBars [i]
tercio@2 330 if (not bar) then
tercio@2 331 print (i, #PVPScan.SpotBars)
tercio@2 332 end
tercio@2 333 if (not bar.InUse and bar.Cooldown < GetTime()) then
tercio@2 334 return bar
tercio@2 335 end
tercio@2 336 end
tercio@2 337 return nil
tercio@2 338 end
tercio@2 339
tercio@0 340 PVPScan:RegisterEvent ("PLAYER_REGEN_DISABLED", "GotCombatLockdown")
tercio@0 341 PVPScan:RegisterEvent ("PLAYER_REGEN_ENABLED", "LeftCombatLockdown")
tercio@0 342
tercio@1 343 -- found a enemy on the scan
tercio@2 344 function PVPScan:EnemySpoted (name, serial, flags, class)
tercio@1 345
tercio@2 346 --se nao tiver nome, nao interessa
tercio@1 347 if (not name) then
tercio@1 348 return
tercio@1 349 end
tercio@2 350
tercio@2 351 --se o player tiver no cooldown para mostrar, ignora-lo
tercio@2 352 if (PVPScan.CooldownShownPlayers [name] and PVPScan.CooldownShownPlayers [name] > GetTime()) then
tercio@2 353 return
tercio@2 354 end
tercio@1 355
tercio@2 356 local SpotBar = PVPScan:GetNextSpotBar()
tercio@2 357
tercio@2 358 if (not SpotBar) then
tercio@2 359 return
tercio@0 360 end
tercio@0 361
tercio@2 362 --seta o cooldown deste jogador
tercio@2 363 PVPScan.CooldownShownPlayers [name] = GetTime() + PVPScan.db.profile.SpotBarPlayerCooldown
tercio@2 364 --seta em qual barra o jogador esta sendo mostrado
tercio@2 365 PVPScan.CurrentShownPlayers [name] = SpotBar.Index
tercio@2 366
tercio@2 367 --se nao tiver uma classe, agendar uma pesquisa
tercio@2 368 if (not class) then
tercio@2 369 PVPScan.NeedClass [name] = true
tercio@0 370 end
tercio@0 371
tercio@2 372 --atualiza a barra
tercio@2 373 PVPScan:UpdateBar (SpotBar, name, class)
tercio@0 374
tercio@2 375 --toca o som se a configuracao permitir
tercio@2 376 if (PVPScan.db.profile.SoundPlay) then
tercio@2 377 local sound = PVPScan.db.profile.SoundFile
tercio@2 378 sound = SharedMedia:Fetch ("sound", sound)
tercio@2 379 if (sound) then
tercio@2 380 PlaySoundFile (sound, "Master")
tercio@2 381 end
tercio@0 382 end
tercio@0 383 end
tercio@0 384
tercio@1 385 -- frames
tercio@2 386
tercio@2 387 function PVPScanOnFrameEnter (self)
tercio@2 388 GameTooltip:SetOwner (self, "ANCHOR_TOPLEFT")
tercio@2 389 GameTooltip:ClearLines()
tercio@2 390 GameTooltip:AddLine ("Right Click To Open Options Panel")
tercio@2 391 GameTooltip:Show()
tercio@2 392 end
tercio@2 393
tercio@2 394 function PVPScanOnFrameLeave (self)
tercio@2 395 GameTooltip:Hide()
tercio@2 396 end
tercio@0 397
tercio@1 398 function PVPScanOnFrameMouseDown (self, button)
tercio@1 399 if (button == "LeftButton") then
tercio@1 400 if (not self.IsMoving) then
tercio@1 401 self:StartMoving()
tercio@1 402 self.IsMoving = true
tercio@1 403 end
tercio@0 404 end
tercio@0 405 end
tercio@0 406
tercio@1 407 function PVPScanOnFrameMouseUp (self, button)
tercio@1 408 if (button == "LeftButton") then
tercio@1 409 if (self.IsMoving) then
tercio@1 410 self:StopMovingOrSizing()
tercio@1 411 self.IsMoving = false
tercio@1 412 end
tercio@1 413
tercio@1 414 elseif (button == "RightButton") then
tercio@1 415 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
tercio@1 416 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
tercio@0 417 end
tercio@0 418 end
tercio@0 419
tercio@2 420 function PVPScan:CheckNonCombatSpotBars()
tercio@2 421 for i = 1, PVPScan.db.profile.SpotBarAmount do
tercio@2 422 local SpotObject = PVPScan.SpotBars [i]
tercio@2 423 if (SpotObject.InUse and (SpotObject.NonTargetFrame:IsShown() or SpotObject.NeedUpdate)) then
tercio@2 424 PVPScan:UpdateBar (SpotObject, SpotObject.PlayerName, SpotObject.PlayerClass)
tercio@2 425 end
tercio@2 426 end
tercio@2 427 end
tercio@0 428
tercio@2 429 function PVPScan:UpdateBar (SpotObject, Name, Class, ClassUpdate)
tercio@2 430
tercio@2 431 SpotObject.IsShown = true
tercio@2 432 SpotObject.InUse = true
tercio@2 433 SpotObject.PlayerName = Name
tercio@2 434 SpotObject.PlayerClass = Class
tercio@2 435 SpotObject.Cooldown = GetTime() + PVPScan.db.profile.SpotBarCooldown
tercio@2 436 SpotObject.ExpireAt = GetTime() + PVPScan.db.profile.SpotBarTimeOut
tercio@2 437 SpotObject.NeedUpdate = false
tercio@2 438
tercio@2 439 if (ClassUpdate) then
tercio@2 440 if (SpotObject.TargetFrame:IsShown()) then
tercio@2 441 if (not UnitAffectingCombat ("player") and not InCombatLockdown()) then
tercio@2 442 local color = RAID_CLASS_COLORS [Class]
tercio@2 443 local texcoord = CLASS_ICON_TCOORDS [Class]
tercio@2 444 SpotObject.TargetFrame.classtexture:SetVertexColor (color.r, color.g, color.b)
tercio@2 445 SpotObject.TargetFrame.classicon:SetTexture ([[Interface\Glues\CHARACTERCREATE\UI-CHARACTERCREATE-CLASSES]])
tercio@2 446 SpotObject.TargetFrame.classicon:SetTexCoord (unpack (texcoord))
tercio@2 447 else
tercio@2 448 SpotObject.NeedUpdate = true
tercio@2 449 end
tercio@2 450 else
tercio@2 451 local color = RAID_CLASS_COLORS [Class]
tercio@2 452 local texcoord = CLASS_ICON_TCOORDS [Class]
tercio@2 453 SpotObject.NonTargetFrame.classtexture:SetVertexColor (color.r, color.g, color.b)
tercio@2 454 SpotObject.NonTargetFrame.classicon:SetTexture ([[Interface\Glues\CHARACTERCREATE\UI-CHARACTERCREATE-CLASSES]])
tercio@2 455 SpotObject.NonTargetFrame.classicon:SetTexCoord (unpack (texcoord))
tercio@2 456 end
tercio@2 457 end
tercio@2 458
tercio@1 459 if (UnitAffectingCombat ("player") or InCombatLockdown()) then
tercio@2 460 --> enable in combat bat
tercio@2 461 if (Class) then
tercio@2 462 local color = RAID_CLASS_COLORS [Class]
tercio@2 463 local texcoord = CLASS_ICON_TCOORDS [Class]
tercio@2 464 SpotObject.NonTargetFrame.classtexture:SetVertexColor (color.r, color.g, color.b)
tercio@2 465 SpotObject.NonTargetFrame.classicon:SetTexture ([[Interface\Glues\CHARACTERCREATE\UI-CHARACTERCREATE-CLASSES]])
tercio@2 466 SpotObject.NonTargetFrame.classicon:SetTexCoord (unpack (texcoord))
tercio@2 467 else
tercio@2 468 SpotObject.NonTargetFrame.classtexture:SetVertexColor (.7, .7, .7)
tercio@2 469 SpotObject.NonTargetFrame.classicon:SetTexture ([[Interface\InventoryItems\WoWUnknownItem01]])
tercio@2 470 SpotObject.NonTargetFrame.classicon:SetTexCoord (0, 1, 0, 1)
tercio@2 471 end
tercio@2 472 SpotObject.NonTargetFrame.name:SetText (Name)
tercio@2 473 SpotObject.NonTargetFrame:Show()
tercio@2 474 SpotObject.NeedUpdate = true
tercio@2 475 else
tercio@2 476 --> enable spot bar
tercio@2 477 if (Class) then
tercio@2 478 local color = RAID_CLASS_COLORS [Class]
tercio@2 479 local texcoord = CLASS_ICON_TCOORDS [Class]
tercio@2 480 SpotObject.TargetFrame.classtexture:SetVertexColor (color.r, color.g, color.b)
tercio@2 481 SpotObject.TargetFrame.classicon:SetTexture ([[Interface\Glues\CHARACTERCREATE\UI-CHARACTERCREATE-CLASSES]])
tercio@2 482 SpotObject.TargetFrame.classicon:SetTexCoord (unpack (texcoord))
tercio@2 483 else
tercio@2 484 SpotObject.TargetFrame.classtexture:SetVertexColor (.7, .7, .7)
tercio@2 485 SpotObject.TargetFrame.classicon:SetTexture ([[Interface\InventoryItems\WoWUnknownItem01]])
tercio@2 486 SpotObject.TargetFrame.classicon:SetTexCoord (0, 1, 0, 1)
tercio@2 487 end
tercio@2 488 SpotObject.TargetFrame:SetAttribute ("macrotext", "/cleartarget\n/targetexact " .. Name)
tercio@2 489 SpotObject.TargetFrame.name:SetText (Name)
tercio@2 490 SpotObject.TargetFrame.SpotObject = SpotObject
tercio@2 491 SpotObject.NonTargetFrame:Hide()
tercio@2 492 SpotObject.TargetFrame:Show()
tercio@1 493 end
tercio@2 494 end
tercio@1 495
tercio@2 496 function PVPScan:CheckBarTimeOut()
tercio@2 497 if (not UnitAffectingCombat ("player") and not InCombatLockdown()) then
tercio@0 498
tercio@2 499 local time = GetTime()
tercio@2 500
tercio@2 501 for repeat_twice = 1, 2 do
tercio@2 502 for i = 1, PVPScan.db.profile.SpotBarAmount do
tercio@2 503
tercio@2 504 local SpotObject = PVPScan.SpotBars [i]
tercio@2 505
tercio@2 506 if (SpotObject.InUse) then
tercio@2 507 --verifica se expirou
tercio@2 508 if (SpotObject.ExpireAt < time) then
tercio@2 509 PVPScan:DisableSpotBar (SpotObject)
tercio@2 510 end
tercio@2 511 else
tercio@2 512 for o = i+1, PVPScan.db.profile.SpotBarAmount do
tercio@2 513 local NextSpotObject = PVPScan.SpotBars [o]
tercio@2 514 if (NextSpotObject.InUse) then --> transferir pra cá
tercio@2 515 --seta a nova barra
tercio@2 516 local PlayerName = NextSpotObject.PlayerName
tercio@2 517 PVPScan:UpdateBar (SpotObject, PlayerName, NextSpotObject.PlayerClass)
tercio@2 518 --desliga a barra antiga
tercio@2 519 PVPScan:DisableSpotBar (NextSpotObject)
tercio@2 520 --seta em qual barra o jogador esta sendo mostrado
tercio@2 521 PVPScan.CurrentShownPlayers [PlayerName] = i
tercio@2 522 break
tercio@2 523 end
tercio@2 524 end
tercio@2 525 end
tercio@2 526 end
tercio@2 527 end
tercio@0 528 end
tercio@0 529
tercio@2 530 end
tercio@2 531
tercio@2 532 function PVPScanSpotBarClick (self)
tercio@2 533 if (self.SpotObject) then
tercio@2 534 self.SpotObject.Cooldown = GetTime() + PVPScan.db.profile.SpotBarCooldown
tercio@2 535 self.SpotObject.ExpireAt = GetTime() + PVPScan.db.profile.SpotBarTimeOut
tercio@2 536 end
tercio@2 537 end
tercio@2 538
tercio@2 539 function PVPScan:DisableSpotBar (SpotObject)
tercio@2 540 SpotObject.TargetFrame:Hide()
tercio@2 541 SpotObject.TargetFrame.SpotObject = nil
tercio@2 542 SpotObject.NonTargetFrame:Hide()
tercio@0 543
tercio@2 544 SpotObject.IsShown = false
tercio@2 545 SpotObject.NeedUpdate = false
tercio@2 546 SpotObject.InUse = false
tercio@2 547 SpotObject.Cooldown = 0
tercio@2 548 SpotObject.ExpireAt = 0
tercio@2 549
tercio@2 550 local name = SpotObject.PlayerName
tercio@2 551
tercio@2 552 if (name) then
tercio@2 553 PVPScan.NeedClass [name] = nil
tercio@2 554 PVPScan.CurrentShownPlayers [name] = nil
tercio@2 555 PVPScan.CooldownShownPlayers [name] = nil
tercio@2 556 end
tercio@2 557
tercio@2 558 SpotObject.PlayerName = nil
tercio@2 559 SpotObject.PlayerClass = nil
tercio@0 560 end
tercio@0 561
tercio@0 562 function PVPScan:RefreshSpotBars()
tercio@0 563
tercio@0 564 if (UnitAffectingCombat ("player") or InCombatLockdown()) then
tercio@0 565 PVPScan.schedule_frame_update = true
tercio@0 566 PVPScan:Print ("When the combat finishes, the frame will be updated.")
tercio@0 567 return
tercio@0 568 end
tercio@0 569
tercio@1 570 if (not PVPScan.ScanEnabled) then
tercio@1 571 PVPScanFrame:Hide()
tercio@1 572 else
tercio@1 573 PVPScanFrame:Show()
tercio@1 574 end
tercio@1 575
tercio@0 576 local amount_bars = PVPScan.db.profile.SpotBarAmount
tercio@1 577 PVPScanFrame:SetSize (PVPScan.db.profile.SpotBarWidth, 20)
tercio@0 578
tercio@0 579 --> we need extra bars?
tercio@0 580 if (amount_bars > #PVPScan.SpotBars) then
tercio@0 581 for i = #PVPScan.SpotBars+1, amount_bars do
tercio@0 582
tercio@2 583 local NewBarObject = {
tercio@2 584 Index = i,
tercio@2 585 TargetFrame = CreateFrame ("Button", "PVPScanSpotBar" .. i, PVPScanFrame, "PVPScanSpotBarTemplate"),
tercio@2 586 NonTargetFrame = CreateFrame ("Button", "PVPScanSpotBarInCombat" .. i, PVPScanFrame, "PVPScanSpotBarInCombatTemplate"),
tercio@2 587 IsShown = false, -- se a barra esta sendo mostrada
tercio@2 588 PlayerName = nil, -- nome do jogador que esta sendo mostrado
tercio@2 589 PlayerClass = nil,
tercio@2 590 NeedUpdate = false, -- se a barra precisa de um update após o termino do combate
tercio@2 591 InUse = false, -- se a barra esta em uso
tercio@2 592 ExpireAt = 0, -- quando a barra ira sumir automaticamente
tercio@2 593 Cooldown = 0, -- tempo para poder por outro jogador nesta barra
tercio@2 594 }
tercio@2 595
tercio@2 596 NewBarObject.NonTargetFrame:SetFrameLevel (NewBarObject.TargetFrame:GetFrameLevel()+1)
tercio@0 597
tercio@0 598 local y = (i-1) * PVPScan.db.profile.SpotBarHeight * -1
tercio@0 599
tercio@2 600 NewBarObject.TargetFrame:SetPoint ("topleft", PVPScanFrame, "topleft", 0, y)
tercio@2 601 NewBarObject.NonTargetFrame:SetPoint ("topleft", PVPScanFrame, "topleft", 0, y)
tercio@0 602
tercio@2 603 NewBarObject.TargetFrame:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight)
tercio@2 604 NewBarObject.NonTargetFrame:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight)
tercio@2 605
tercio@2 606 tinsert (PVPScan.SpotBars, NewBarObject)
tercio@0 607 end
tercio@0 608 end
tercio@0 609
tercio@0 610 if (#PVPScan.SpotBars > amount_bars) then
tercio@0 611 for i = #PVPScan.SpotBars, amount_bars+1, -1 do
tercio@2 612 PVPScan:DisableSpotBar (PVPScan.SpotBars [i])
tercio@0 613 end
tercio@0 614 end
tercio@0 615
tercio@0 616 --> refresh existing
tercio@2 617 for Index, BarObject in ipairs (PVPScan.SpotBars) do
tercio@2 618 local y = (Index-1) * PVPScan.db.profile.SpotBarHeight * -1
tercio@2 619 --point
tercio@2 620 BarObject.TargetFrame:SetPoint ("topleft", PVPScanFrame, "bottomleft", 0, y)
tercio@2 621 BarObject.NonTargetFrame:SetPoint ("topleft", PVPScanFrame, "bottomleft", 0, y)
tercio@2 622 --size
tercio@2 623 BarObject.TargetFrame:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight)
tercio@2 624 BarObject.NonTargetFrame:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight)
tercio@2 625 --texture size
tercio@2 626 BarObject.TargetFrame.classtexture:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight)
tercio@2 627 BarObject.NonTargetFrame.classtexture:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight)
tercio@2 628 --bar texture
tercio@2 629 BarObject.TargetFrame.classtexture:SetTexture (SharedMedia:Fetch ("statusbar", PVPScan.db.profile.SpotBarTexture) or [[Interface\PaperDollInfoFrame\UI-Character-Skills-Bar]])
tercio@2 630 BarObject.NonTargetFrame.classtexture:SetTexture (SharedMedia:Fetch ("statusbar", PVPScan.db.profile.SpotBarTexture) or [[Interface\PaperDollInfoFrame\UI-Character-Skills-Bar]])
tercio@2 631 --icon size
tercio@2 632 BarObject.TargetFrame.classicon:SetSize (PVPScan.db.profile.SpotBarHeight, PVPScan.db.profile.SpotBarHeight)
tercio@2 633 BarObject.NonTargetFrame.classicon:SetSize (PVPScan.db.profile.SpotBarHeight, PVPScan.db.profile.SpotBarHeight)
tercio@0 634 end
tercio@0 635
tercio@0 636 end
tercio@0 637
tercio@1 638 --> misc
tercio@0 639
tercio@0 640 function PVPScan:GuessClass (...)
tercio@0 641 local arg1, arg2, arg3, arg4 = select (1, ...)
tercio@0 642
tercio@0 643 if (type (arg1) == "number") then
tercio@3 644 return PVPScan.ClassSpellList [arg1]
tercio@0 645 end
tercio@0 646
tercio@0 647 return nil
tercio@0 648 end
tercio@0 649
tercio@1 650
tercio@1 651 ------------------------------------------------------------------------------------------------------------------------------------------------------------
tercio@1 652 --> battlegrounds
tercio@1 653