annotate PVPScan.lua @ 27:815e95660b98 tip

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