annotate PVPScan.lua @ 2:f2456f1454af

rewrite
author tercio
date Sun, 01 Jun 2014 03:48:11 -0300
parents 726745261b87
children 1c0f88ab78b7
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@0 3
tercio@0 4 local LDB = LibStub ("LibDataBroker-1.1", true)
tercio@0 5 local LDBIcon = LDB and LibStub ("LibDBIcon-1.0", true)
tercio@0 6 local SharedMedia = LibStub:GetLibrary("LibSharedMedia-3.0")
tercio@0 7
tercio@0 8 local _bit_band = bit.band
tercio@2 9 local GetTime = GetTime
tercio@0 10
tercio@0 11 local REACTION_HOSTILE = 0x00000040
tercio@1 12 local REACTION_NEUTRAL = 0x00000020
tercio@1 13
tercio@0 14 local OBJECT_TYPE_PLAYER = 0x00000400
tercio@0 15
tercio@1 16 PVPScan.IsInBattleground = false
tercio@1 17 PVPScan.IsInCity = false
tercio@1 18 PVPScan.IsInArena = false
tercio@1 19 PVPScan.IsInOutDoors = true
tercio@1 20 PVPScan.ScanEnabled = true
tercio@0 21
tercio@0 22 local default_db = {
tercio@0 23 profile = {
tercio@0 24 SpotBarHeight = 20,
tercio@0 25 SpotBarAmount = 5,
tercio@0 26 SpotBarWidth = 150,
tercio@2 27 SpotBarTexture = "Blizzard Character Skills Bar",
tercio@2 28 SpotBarTimeOut = 10,
tercio@2 29 SpotBarCooldown = 5,
tercio@2 30 SpotBarPlayerCooldown = 10,
tercio@0 31 Locked = false,
tercio@0 32 SoundPlay = false,
tercio@0 33 SoundFile = "",
tercio@0 34 Minimap = {hide = false, radius = 160, minimapPos = 220},
tercio@0 35 },
tercio@0 36 }
tercio@0 37
tercio@0 38 function PVPScan:OnEnable()
tercio@0 39 end
tercio@0 40
tercio@0 41 function PVPScan:OnDisable()
tercio@0 42 end
tercio@0 43
tercio@0 44 local OptionsTable = {
tercio@0 45 name = "PVPScan",
tercio@0 46 type = "group",
tercio@0 47 args = {
tercio@0 48 SpotBarHeight = {
tercio@0 49 type = "range",
tercio@0 50 name = "Bar Height",
tercio@0 51 desc = "Change the height of spot bars.",
tercio@0 52 min = 10,
tercio@0 53 max = 40,
tercio@0 54 step = 1,
tercio@0 55 get = function() return PVPScan.db.profile.SpotBarHeight end,
tercio@0 56 set = function (self, val) PVPScan.db.profile.SpotBarHeight = val; PVPScan:RefreshSpotBars() end,
tercio@0 57 order = 1,
tercio@0 58 },
tercio@0 59 SpotBarWidth = {
tercio@0 60 type = "range",
tercio@0 61 name = "Bar Width",
tercio@0 62 desc = "Change the width of spot bars.",
tercio@0 63 min = 50,
tercio@0 64 max = 250,
tercio@0 65 step = 1,
tercio@0 66 get = function() return PVPScan.db.profile.SpotBarWidth end,
tercio@0 67 set = function (self, val) PVPScan.db.profile.SpotBarWidth = val; PVPScan:RefreshSpotBars() end,
tercio@0 68 order = 2,
tercio@0 69 },
tercio@0 70 SpotBarAmount = {
tercio@0 71 type = "range",
tercio@0 72 name = "Bar Amount",
tercio@0 73 desc = "Change the amount of spot bars.",
tercio@0 74 min = 1,
tercio@0 75 max = 40,
tercio@0 76 step = 1,
tercio@0 77 get = function() return PVPScan.db.profile.SpotBarAmount end,
tercio@0 78 set = function (self, val) PVPScan.db.profile.SpotBarAmount = val; PVPScan:RefreshSpotBars() end,
tercio@0 79 order = 3,
tercio@0 80 },
tercio@2 81 SpotBarTexture = {
tercio@2 82 type = "select",
tercio@2 83 name = "Bar Texture",
tercio@2 84 desc = "Choose the texture used on target bars.",
tercio@2 85 values = function()
tercio@2 86 local TextureTable = {}
tercio@2 87 for name, _ in pairs (SharedMedia:HashTable ("statusbar")) do
tercio@2 88 TextureTable [name] = name
tercio@2 89 end
tercio@2 90 return TextureTable
tercio@2 91 end,
tercio@2 92 get = function() return PVPScan.db.profile.SpotBarTexture end,
tercio@2 93 set = function (self, file) PVPScan.db.profile.SpotBarTexture = file; PVPScan:RefreshSpotBars() end,
tercio@2 94 order = 4,
tercio@2 95 },
tercio@2 96 SpotBarTimeOut = {
tercio@2 97 type = "range",
tercio@2 98 name = "Time Out",
tercio@2 99 desc = "How many time wait until the bar auto hide.",
tercio@2 100 min = 5,
tercio@2 101 max = 120,
tercio@2 102 step = 5,
tercio@2 103 get = function() return PVPScan.db.profile.SpotBarTimeOut end,
tercio@2 104 set = function (self, val) PVPScan.db.profile.SpotBarTimeOut = val; end,
tercio@2 105 order = 9,
tercio@2 106 },
tercio@0 107 Locked = {
tercio@0 108 type = "toggle",
tercio@1 109 name = "Lock Scan Frame",
tercio@0 110 desc = "Lock or unlock the SpotBars Frame.",
tercio@2 111 order = 5,
tercio@0 112 get = function() return PVPScan.db.profile.Locked end,
tercio@1 113 set = function (self, val) PVPScan.db.profile.Locked = not PVPScan.db.profile.Locked; PVPScan:LockScanFrame (PVPScan.db.profile.Locked) end,
tercio@0 114 },
tercio@0 115 SoundPlay = {
tercio@0 116 type = "toggle",
tercio@0 117 name = "Play Sound",
tercio@0 118 desc = "Play a sound when a enemy is found.",
tercio@2 119 order = 7,
tercio@0 120 get = function() return PVPScan.db.profile.SoundPlay end,
tercio@0 121 set = function (self, val) PVPScan.db.profile.SoundPlay = not PVPScan.db.profile.SoundPlay end,
tercio@0 122 },
tercio@0 123 SoundFile = {
tercio@0 124 type = "select",
tercio@0 125 name = "Sound File",
tercio@0 126 desc = "Choose the sound to play when a enemy is found.",
tercio@0 127 values = function()
tercio@0 128 local SoundTable = {}
tercio@0 129 for name, _ in pairs (SharedMedia:HashTable ("sound")) do
tercio@0 130 SoundTable [name] = name
tercio@0 131 end
tercio@0 132 return SoundTable
tercio@0 133 end,
tercio@0 134 get = function() return PVPScan.db.profile.SoundFile end,
tercio@0 135 set = function (self, file) PVPScan.db.profile.SoundFile = file end,
tercio@2 136 order = 8,
tercio@0 137 },
tercio@0 138 Minimap = {
tercio@0 139 type = "toggle",
tercio@0 140 name = "Hide Minimap Icon",
tercio@0 141 desc = "Show or hide the minimap icon.",
tercio@2 142 order = 6,
tercio@0 143 get = function() return PVPScan.db.profile.Minimap.hide end,
tercio@0 144 set = function (self, val)
tercio@0 145 PVPScan.db.profile.Minimap.hide = not PVPScan.db.profile.Minimap.hide
tercio@0 146 LDBIcon:Refresh ("PVPScan", PVPScan.db.profile.Minimap)
tercio@0 147 if (PVPScan.db.profile.Minimap.hide) then
tercio@0 148 LDBIcon:Hide ("PVPScan")
tercio@0 149 else
tercio@0 150 LDBIcon:Show ("PVPScan")
tercio@0 151 end
tercio@0 152 end,
tercio@0 153 },
tercio@0 154 },
tercio@0 155 }
tercio@0 156
tercio@0 157 function PVPScan:OnInitialize()
tercio@0 158
tercio@0 159 --declarar primeiro o db usando a global que é declarada no toc.
tercio@0 160 self.db = LibStub ("AceDB-3.0"):New ("PVPScanDB", default_db, true)
tercio@0 161
tercio@0 162 --declara agora as opções da tab raiz
tercio@0 163 LibStub("AceConfig-3.0"):RegisterOptionsTable ("PVPScan", OptionsTable)
tercio@0 164 PVPScan.OptionsFrame1 = LibStub ("AceConfigDialog-3.0"):AddToBlizOptions ("PVPScan", "PVPScan")
tercio@0 165 --sub tab
tercio@0 166 LibStub ("AceConfig-3.0"):RegisterOptionsTable ("PVPScan-Profiles", LibStub ("AceDBOptions-3.0"):GetOptionsTable (self.db))
tercio@0 167 PVPScan.OptionsFrame2 = LibStub ("AceConfigDialog-3.0"):AddToBlizOptions ("PVPScan-Profiles", "Profiles", "PVPScan")
tercio@0 168
tercio@0 169 if LDB then
tercio@0 170 local databroker = LDB:NewDataObject ("PVPScan", {
tercio@0 171 type = "launcher",
tercio@0 172 icon = [[Interface\PvPRankBadges\PvPRank15]],
tercio@0 173 --HotCornerIgnore = true,
tercio@0 174 OnClick = function (self, button)
tercio@0 175 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
tercio@0 176 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
tercio@0 177 end
tercio@0 178 })
tercio@0 179
tercio@0 180 if (databroker and not LDBIcon:IsRegistered ("PVPScan")) then
tercio@0 181 LDBIcon:Register ("PVPScan", databroker, PVPScan.db.profile.Minimap)
tercio@0 182 end
tercio@0 183 end
tercio@0 184
tercio@0 185 PVPScan:RefreshSpotBars()
tercio@1 186 PVPScan:LockScanFrame (PVPScan.db.profile.Locked)
tercio@2 187
tercio@2 188 PVPScan.EventFrame:SetScript ("OnEvent", PVPScan.OnParserEvent)
tercio@0 189 end
tercio@0 190
tercio@0 191 PVPScan:RegisterChatCommand ("pvpscan", function()
tercio@0 192 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
tercio@0 193 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
tercio@0 194 end)
tercio@0 195
tercio@1 196
tercio@0 197 ------------------------------------------------------------------------------------------------------------------------------------------------------------
tercio@1 198 --> general
tercio@0 199
tercio@1 200 function PVPScan:ChangeZones()
tercio@1 201
tercio@1 202 local name, type, difficulty, difficultyName, maxPlayers, playerDifficulty, isDynamicInstance, mapID, instanceGroupSize = GetInstanceInfo()
tercio@1 203 local pvpType, isFFA, faction = GetZonePVPInfo()
tercio@1 204
tercio@1 205 PVPScan.IsInBattleground = false
tercio@1 206 PVPScan.IsInCity = false
tercio@1 207 PVPScan.IsInArena = false
tercio@1 208 PVPScan.IsInOutDoors = false
tercio@1 209 PVPScan.ScanEnabled = false
tercio@1 210
tercio@1 211 if (pvpType == "contested" and (not type or type == "none")) then
tercio@1 212 PVPScan.IsInOutDoors = true
tercio@1 213 PVPScan.ScanEnabled = true
tercio@1 214
tercio@1 215 elseif (type == "pvp") then
tercio@1 216 PVPScan.IsInBattleground = true
tercio@1 217
tercio@1 218 elseif (type == "arena") then
tercio@1 219 PVPScan.IsInArena = true
tercio@1 220
tercio@1 221 elseif (type and (type == "scenario" or type == "party" or type == "raid" or pvpType == "friendly" or pvpType == "sanctuary")) then
tercio@1 222 PVPScan.ScanEnabled = false
tercio@1 223
tercio@1 224 else
tercio@1 225 PVPScan.IsInOutDoors = true
tercio@1 226 PVPScan.ScanEnabled = true
tercio@1 227 end
tercio@1 228
tercio@1 229 if (PVPScan.ScanEnabled) then
tercio@1 230 PVPScan:EnableScan()
tercio@1 231 else
tercio@1 232 PVPScan:DisableScan()
tercio@1 233 end
tercio@1 234
tercio@1 235 end
tercio@1 236
tercio@1 237 PVPScan:RegisterEvent ("ZONE_CHANGED_NEW_AREA", "ChangeZones")
tercio@1 238 PVPScan:RegisterEvent ("PLAYER_ENTERING_WORLD", "ChangeZones")
tercio@1 239
tercio@1 240 function PVPScan:EnableScan()
tercio@1 241 PVPScan.EventFrame:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
tercio@1 242 PVPScan:RefreshSpotBars()
tercio@2 243 PVPScan.NextBarCheckForHide = GetTime() + PVPScan.db.profile.SpotBarTimeOut
tercio@2 244 PVPScan.BarChecker = PVPScan:ScheduleRepeatingTimer ("CheckBarTimeOut", 5)
tercio@1 245 end
tercio@1 246
tercio@1 247 function PVPScan:DisableScan()
tercio@1 248 PVPScan.EventFrame:UnregisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
tercio@1 249 PVPScan:RefreshSpotBars()
tercio@2 250 if (PVPScan.BarChecker) then
tercio@2 251 PVPScan:CancelTimer (PVPScan.BarChecker, true)
tercio@2 252 PVPScan.BarChecker = nil
tercio@2 253 end
tercio@1 254 end
tercio@1 255
tercio@1 256 function PVPScan:LockScanFrame (IsLocked)
tercio@1 257 if (IsLocked) then
tercio@1 258 PVPScanFrame.text:SetText ("")
tercio@1 259 PVPScanFrame:SetBackdrop (nil)
tercio@1 260 PVPScanFrame:EnableMouse (false)
tercio@1 261 else
tercio@1 262 PVPScanFrame.text:SetText ("PVPScan Anchor")
tercio@1 263 PVPScanFrame:SetBackdrop ({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tile = true, TileSize = 64})
tercio@1 264 PVPScanFrame:SetBackdropColor (0, 0, 0, 1)
tercio@1 265 PVPScanFrame:EnableMouse (true)
tercio@1 266 end
tercio@1 267 end
tercio@1 268 ------------------------------------------------------------------------------------------------------------------------------------------------------------
tercio@1 269 --> outside world scan
tercio@1 270
tercio@1 271 --> parser
tercio@1 272
tercio@2 273 PVPScan.SpotBars = {} -- container para os objetos das barras
tercio@2 274
tercio@2 275 PVPScan.NeedClass = {} -- container para os jogadores que precisam saber a classe
tercio@2 276 PVPScan.CurrentShownPlayers = {} -- nomes dos jogadores que estão sendo mostrados com o index da barra no valos
tercio@2 277 PVPScan.CooldownShownPlayers = {} -- nomes dos jogadores com o tempo de quando eles podem ser mostrados novamente nas barras
tercio@1 278
tercio@1 279 PVPScan.EventFrame = CreateFrame ("frame", "PVPScanCombatLobReader", UIParent)
tercio@1 280 PVPScan.EventFrame:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
tercio@0 281
tercio@0 282 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 283
tercio@0 284 if (PVPScan.NeedClass [who_name]) then
tercio@0 285 local class = PVPScan:GuessClass (...)
tercio@0 286 if (class) then
tercio@2 287 PVPScan:UpdateBar (PVPScan.SpotBars [PVPScan.CurrentShownPlayers [who_name]], who_name, class, true)
tercio@0 288 PVPScan.NeedClass [who_name] = nil
tercio@0 289 end
tercio@0 290 return
tercio@0 291 end
tercio@0 292
tercio@0 293 if (PVPScan.NeedClass [target_name]) then
tercio@0 294 local class = PVPScan:GuessClass (...)
tercio@0 295 if (class) then
tercio@2 296 PVPScan:UpdateBar (PVPScan.SpotBars [PVPScan.CurrentShownPlayers [target_name]], target_name, class, true)
tercio@0 297 PVPScan.NeedClass [target_name] = nil
tercio@0 298 end
tercio@0 299 return
tercio@0 300 end
tercio@1 301
tercio@2 302 if (not PVPScan.CurrentShownPlayers [target_name] and _bit_band (target_flags, OBJECT_TYPE_PLAYER) ~= 0) then --> is player
tercio@1 303 if (_bit_band (target_flags, REACTION_HOSTILE) ~= 0) then --> is hostile
tercio@0 304 local class = PVPScan:GuessClass (...)
tercio@0 305 PVPScan:EnemySpoted (target_name, target_serial, target_flags, class)
tercio@0 306 end
tercio@0 307 end
tercio@0 308
tercio@2 309 if (not PVPScan.CurrentShownPlayers [who_name] and _bit_band (who_flags, OBJECT_TYPE_PLAYER) ~= 0) then --> is player
tercio@1 310 if (_bit_band (who_flags, REACTION_HOSTILE) ~= 0) then --> is hostile
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@0 644 if (PVPScan.ClassSpellList [arg1]) then
tercio@0 645 return PVPScan.ClassSpellList [arg1]
tercio@0 646 end
tercio@0 647 end
tercio@0 648
tercio@0 649 return nil
tercio@0 650 end
tercio@0 651
tercio@1 652
tercio@1 653 ------------------------------------------------------------------------------------------------------------------------------------------------------------
tercio@1 654 --> battlegrounds
tercio@1 655