annotate PVPScan.lua @ 11:6b79364e9347

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