tercio@0: tercio@2: PVPScan = LibStub ("AceAddon-3.0"):NewAddon ("PVPScan", "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0") Tercio@6: tercio@3: local PVPScan = PVPScan tercio@0: local LDB = LibStub ("LibDataBroker-1.1", true) tercio@0: local LDBIcon = LDB and LibStub ("LibDBIcon-1.0", true) Tercioo@9: local LibWindow = LibStub ("LibWindow-1.1") tercio@0: local SharedMedia = LibStub:GetLibrary("LibSharedMedia-3.0") tercio@0: tercio@0: local _bit_band = bit.band tercio@2: local GetTime = GetTime tercio@0: tercio@0: local REACTION_HOSTILE = 0x00000040 tercio@1: local REACTION_NEUTRAL = 0x00000020 tercio@1: tercio@0: local OBJECT_TYPE_PLAYER = 0x00000400 tercio@0: tercio@1: PVPScan.IsInBattleground = false tercio@1: PVPScan.IsInCity = false tercio@1: PVPScan.IsInArena = false tercio@1: PVPScan.IsInOutDoors = true tercio@1: PVPScan.ScanEnabled = true tercio@0: tercio@0: local default_db = { tercio@0: profile = { tercio@0: SpotBarHeight = 20, tercio@0: SpotBarAmount = 5, tercio@0: SpotBarWidth = 150, tercio@2: SpotBarTexture = "Blizzard Character Skills Bar", tercio@2: SpotBarTimeOut = 10, tercio@2: SpotBarCooldown = 5, tercio@2: SpotBarPlayerCooldown = 10, tercio@0: Locked = false, tercio@0: SoundPlay = false, tercio@0: SoundFile = "", tercio@0: Minimap = {hide = false, radius = 160, minimapPos = 220}, tercio@0: }, tercio@0: } tercio@0: tercio@0: function PVPScan:OnEnable() tercio@0: end tercio@0: tercio@0: function PVPScan:OnDisable() tercio@0: end tercio@0: tercio@0: local OptionsTable = { tercio@0: name = "PVPScan", tercio@0: type = "group", tercio@0: args = { tercio@0: SpotBarHeight = { tercio@0: type = "range", tercio@0: name = "Bar Height", tercio@0: desc = "Change the height of spot bars.", tercio@0: min = 10, tercio@0: max = 40, tercio@0: step = 1, tercio@0: get = function() return PVPScan.db.profile.SpotBarHeight end, tercio@0: set = function (self, val) PVPScan.db.profile.SpotBarHeight = val; PVPScan:RefreshSpotBars() end, tercio@0: order = 1, tercio@0: }, tercio@0: SpotBarWidth = { tercio@0: type = "range", tercio@0: name = "Bar Width", tercio@0: desc = "Change the width of spot bars.", tercio@0: min = 50, tercio@0: max = 250, tercio@0: step = 1, tercio@0: get = function() return PVPScan.db.profile.SpotBarWidth end, tercio@0: set = function (self, val) PVPScan.db.profile.SpotBarWidth = val; PVPScan:RefreshSpotBars() end, tercio@0: order = 2, tercio@0: }, tercio@0: SpotBarAmount = { tercio@0: type = "range", tercio@0: name = "Bar Amount", tercio@0: desc = "Change the amount of spot bars.", tercio@0: min = 1, tercio@0: max = 40, tercio@0: step = 1, tercio@0: get = function() return PVPScan.db.profile.SpotBarAmount end, tercio@0: set = function (self, val) PVPScan.db.profile.SpotBarAmount = val; PVPScan:RefreshSpotBars() end, tercio@0: order = 3, tercio@0: }, tercio@2: SpotBarTexture = { tercio@2: type = "select", tercio@2: name = "Bar Texture", tercio@2: desc = "Choose the texture used on target bars.", tercio@2: values = function() tercio@2: local TextureTable = {} tercio@2: for name, _ in pairs (SharedMedia:HashTable ("statusbar")) do tercio@2: TextureTable [name] = name tercio@2: end tercio@2: return TextureTable tercio@2: end, tercio@2: get = function() return PVPScan.db.profile.SpotBarTexture end, tercio@2: set = function (self, file) PVPScan.db.profile.SpotBarTexture = file; PVPScan:RefreshSpotBars() end, tercio@2: order = 4, tercio@2: }, tercio@2: SpotBarTimeOut = { tercio@2: type = "range", tercio@2: name = "Time Out", tercio@2: desc = "How many time wait until the bar auto hide.", tercio@2: min = 5, tercio@2: max = 120, tercio@2: step = 5, tercio@2: get = function() return PVPScan.db.profile.SpotBarTimeOut end, tercio@2: set = function (self, val) PVPScan.db.profile.SpotBarTimeOut = val; end, tercio@2: order = 9, tercio@2: }, tercio@0: Locked = { tercio@0: type = "toggle", tercio@1: name = "Lock Scan Frame", tercio@0: desc = "Lock or unlock the SpotBars Frame.", tercio@2: order = 5, tercio@0: get = function() return PVPScan.db.profile.Locked end, tercio@1: set = function (self, val) PVPScan.db.profile.Locked = not PVPScan.db.profile.Locked; PVPScan:LockScanFrame (PVPScan.db.profile.Locked) end, tercio@0: }, tercio@0: SoundPlay = { tercio@0: type = "toggle", tercio@0: name = "Play Sound", tercio@0: desc = "Play a sound when a enemy is found.", tercio@2: order = 7, tercio@0: get = function() return PVPScan.db.profile.SoundPlay end, tercio@0: set = function (self, val) PVPScan.db.profile.SoundPlay = not PVPScan.db.profile.SoundPlay end, tercio@0: }, tercio@0: SoundFile = { tercio@0: type = "select", tercio@0: name = "Sound File", tercio@0: desc = "Choose the sound to play when a enemy is found.", tercio@0: values = function() tercio@0: local SoundTable = {} tercio@0: for name, _ in pairs (SharedMedia:HashTable ("sound")) do tercio@0: SoundTable [name] = name tercio@0: end tercio@0: return SoundTable tercio@0: end, tercio@0: get = function() return PVPScan.db.profile.SoundFile end, tercio@0: set = function (self, file) PVPScan.db.profile.SoundFile = file end, tercio@2: order = 8, tercio@0: }, tercio@0: Minimap = { tercio@0: type = "toggle", tercio@0: name = "Hide Minimap Icon", tercio@0: desc = "Show or hide the minimap icon.", tercio@2: order = 6, tercio@0: get = function() return PVPScan.db.profile.Minimap.hide end, tercio@0: set = function (self, val) tercio@0: PVPScan.db.profile.Minimap.hide = not PVPScan.db.profile.Minimap.hide tercio@0: LDBIcon:Refresh ("PVPScan", PVPScan.db.profile.Minimap) tercio@0: if (PVPScan.db.profile.Minimap.hide) then tercio@0: LDBIcon:Hide ("PVPScan") tercio@0: else tercio@0: LDBIcon:Show ("PVPScan") tercio@0: end tercio@0: end, tercio@0: }, tercio@0: }, tercio@0: } tercio@0: Tercioo@9: local WaitToRestore = function() Tercioo@9: if (not UnitAffectingCombat ("player") and not InCombatLockdown()) then Tercioo@9: PVPScan.RestoreTick:Cancel() Tercioo@9: LibWindow.RestorePosition (PVPScanFrame) Tercioo@9: PVPScan:LockScanFrame (PVPScan.db.profile.Locked) Tercioo@9: PVPScan:RefreshSpotBars() Tercioo@9: end Tercioo@9: end Tercioo@9: tercio@0: function PVPScan:OnInitialize() tercio@0: tercio@0: --declarar primeiro o db usando a global que é declarada no toc. tercio@0: self.db = LibStub ("AceDB-3.0"):New ("PVPScanDB", default_db, true) tercio@0: tercio@0: --declara agora as opções da tab raiz tercio@0: LibStub("AceConfig-3.0"):RegisterOptionsTable ("PVPScan", OptionsTable) tercio@0: PVPScan.OptionsFrame1 = LibStub ("AceConfigDialog-3.0"):AddToBlizOptions ("PVPScan", "PVPScan") tercio@0: --sub tab tercio@0: LibStub ("AceConfig-3.0"):RegisterOptionsTable ("PVPScan-Profiles", LibStub ("AceDBOptions-3.0"):GetOptionsTable (self.db)) tercio@0: PVPScan.OptionsFrame2 = LibStub ("AceConfigDialog-3.0"):AddToBlizOptions ("PVPScan-Profiles", "Profiles", "PVPScan") tercio@0: tercio@0: if LDB then tercio@0: local databroker = LDB:NewDataObject ("PVPScan", { tercio@0: type = "launcher", tercio@0: icon = [[Interface\PvPRankBadges\PvPRank15]], tercio@0: --HotCornerIgnore = true, tercio@0: OnClick = function (self, button) tercio@0: InterfaceOptionsFrame_OpenToCategory ("PVPScan") tercio@0: InterfaceOptionsFrame_OpenToCategory ("PVPScan") tercio@0: end tercio@0: }) tercio@0: tercio@0: if (databroker and not LDBIcon:IsRegistered ("PVPScan")) then tercio@0: LDBIcon:Register ("PVPScan", databroker, PVPScan.db.profile.Minimap) tercio@0: end tercio@0: end tercio@0: Tercioo@9: if (not self.db.profile.point) then Tercioo@9: PVPScan.db.profile.Locked = false Tercioo@9: end Tercioo@9: Tercioo@9: LibWindow.RegisterConfig (PVPScanFrame, self.db.profile) Tercioo@9: LibWindow.RestorePosition (PVPScanFrame) Tercioo@9: LibWindow.SavePosition (PVPScanFrame) Tercioo@9: Tercioo@9: if (UnitAffectingCombat ("player") or InCombatLockdown()) then Tercioo@9: PVPScan:LockScanFrame (true) Tercioo@9: self.RestoreTick = C_Timer.NewTicker (1, WaitToRestore) Tercioo@9: else Tercioo@9: PVPScan:RefreshSpotBars() Tercioo@9: end Tercioo@9: tercio@1: PVPScan:LockScanFrame (PVPScan.db.profile.Locked) tercio@2: tercio@2: PVPScan.EventFrame:SetScript ("OnEvent", PVPScan.OnParserEvent) tercio@0: end tercio@0: tercio@0: PVPScan:RegisterChatCommand ("pvpscan", function() tercio@0: InterfaceOptionsFrame_OpenToCategory ("PVPScan") tercio@0: InterfaceOptionsFrame_OpenToCategory ("PVPScan") tercio@0: end) tercio@0: tercio@1: tercio@0: ------------------------------------------------------------------------------------------------------------------------------------------------------------ tercio@1: --> general tercio@0: Tercioo@9: local check_zone = function() tercio@1: local name, type, difficulty, difficultyName, maxPlayers, playerDifficulty, isDynamicInstance, mapID, instanceGroupSize = GetInstanceInfo() tercio@1: local pvpType, isFFA, faction = GetZonePVPInfo() tercio@1: tercio@1: PVPScan.IsInBattleground = false tercio@1: PVPScan.IsInCity = false tercio@1: PVPScan.IsInArena = false tercio@1: PVPScan.IsInOutDoors = false tercio@1: PVPScan.ScanEnabled = false tercio@1: tercio@1: if (pvpType == "contested" and (not type or type == "none")) then tercio@1: PVPScan.IsInOutDoors = true tercio@1: PVPScan.ScanEnabled = true tercio@1: tercio@1: elseif (type == "pvp") then tercio@1: PVPScan.IsInBattleground = true tercio@1: tercio@1: elseif (type == "arena") then tercio@1: PVPScan.IsInArena = true tercio@1: tercio@1: elseif (type and (type == "scenario" or type == "party" or type == "raid" or pvpType == "friendly" or pvpType == "sanctuary")) then tercio@1: PVPScan.ScanEnabled = false tercio@1: tercio@1: else tercio@1: PVPScan.IsInOutDoors = true tercio@1: PVPScan.ScanEnabled = true tercio@1: end Tercioo@9: tercio@1: if (PVPScan.ScanEnabled) then tercio@1: PVPScan:EnableScan() tercio@1: else tercio@1: PVPScan:DisableScan() tercio@1: end Tercioo@9: end Tercioo@9: Tercioo@9: function PVPScan:ChangeZones() Tercioo@9: C_Timer.After (5, check_zone) tercio@1: end tercio@1: tercio@1: PVPScan:RegisterEvent ("ZONE_CHANGED_NEW_AREA", "ChangeZones") tercio@1: PVPScan:RegisterEvent ("PLAYER_ENTERING_WORLD", "ChangeZones") tercio@1: tercio@1: function PVPScan:EnableScan() tercio@1: PVPScan.EventFrame:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED") tercio@1: PVPScan:RefreshSpotBars() tercio@2: PVPScan.NextBarCheckForHide = GetTime() + PVPScan.db.profile.SpotBarTimeOut tercio@2: PVPScan.BarChecker = PVPScan:ScheduleRepeatingTimer ("CheckBarTimeOut", 5) tercio@1: end tercio@1: tercio@1: function PVPScan:DisableScan() tercio@1: PVPScan.EventFrame:UnregisterEvent ("COMBAT_LOG_EVENT_UNFILTERED") tercio@1: PVPScan:RefreshSpotBars() tercio@2: if (PVPScan.BarChecker) then tercio@2: PVPScan:CancelTimer (PVPScan.BarChecker, true) tercio@2: PVPScan.BarChecker = nil tercio@2: end tercio@1: end tercio@1: tercio@1: function PVPScan:LockScanFrame (IsLocked) tercio@1: if (IsLocked) then tercio@1: PVPScanFrame.text:SetText ("") tercio@1: PVPScanFrame:SetBackdrop (nil) tercio@1: PVPScanFrame:EnableMouse (false) Tercioo@9: LibWindow.SavePosition (PVPScanFrame) tercio@1: else tercio@1: PVPScanFrame.text:SetText ("PVPScan Anchor") tercio@1: PVPScanFrame:SetBackdrop ({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tile = true, TileSize = 64}) tercio@1: PVPScanFrame:SetBackdropColor (0, 0, 0, 1) tercio@1: PVPScanFrame:EnableMouse (true) tercio@1: end tercio@1: end tercio@1: ------------------------------------------------------------------------------------------------------------------------------------------------------------ tercio@1: --> outside world scan tercio@1: tercio@1: --> parser tercio@1: tercio@2: PVPScan.SpotBars = {} -- container para os objetos das barras tercio@2: tercio@2: PVPScan.NeedClass = {} -- container para os jogadores que precisam saber a classe tercio@2: PVPScan.CurrentShownPlayers = {} -- nomes dos jogadores que estão sendo mostrados com o index da barra no valos tercio@2: PVPScan.CooldownShownPlayers = {} -- nomes dos jogadores com o tempo de quando eles podem ser mostrados novamente nas barras tercio@1: tercio@1: PVPScan.EventFrame = CreateFrame ("frame", "PVPScanCombatLobReader", UIParent) tercio@1: PVPScan.EventFrame:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED") tercio@0: tercio@0: 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: tercio@0: if (PVPScan.NeedClass [who_name]) then tercio@0: local class = PVPScan:GuessClass (...) tercio@0: if (class) then tercio@2: PVPScan:UpdateBar (PVPScan.SpotBars [PVPScan.CurrentShownPlayers [who_name]], who_name, class, true) tercio@0: PVPScan.NeedClass [who_name] = nil tercio@0: end tercio@0: return tercio@0: end tercio@0: tercio@2: if (not PVPScan.CurrentShownPlayers [target_name] and _bit_band (target_flags, OBJECT_TYPE_PLAYER) ~= 0) then --> is player tercio@1: if (_bit_band (target_flags, REACTION_HOSTILE) ~= 0) then --> is hostile Tercioo@8: local pvpType, isFFA, faction = GetZonePVPInfo() Tercioo@8: if (pvpType ~= "contested" and pvpType ~= "hostile") then Tercioo@8: return Tercioo@8: end tercio@0: local class = PVPScan:GuessClass (...) tercio@0: PVPScan:EnemySpoted (target_name, target_serial, target_flags, class) tercio@0: end tercio@0: end tercio@0: tercio@2: if (not PVPScan.CurrentShownPlayers [who_name] and _bit_band (who_flags, OBJECT_TYPE_PLAYER) ~= 0) then --> is player tercio@1: if (_bit_band (who_flags, REACTION_HOSTILE) ~= 0) then --> is hostile Tercioo@8: local pvpType, isFFA, faction = GetZonePVPInfo() Tercioo@8: if (pvpType ~= "contested" and pvpType ~= "hostile") then Tercioo@8: return Tercioo@8: end tercio@0: local class = PVPScan:GuessClass (...) tercio@0: PVPScan:EnemySpoted (who_name, who_serial, who_flags, class) tercio@0: end tercio@0: end tercio@0: end tercio@0: tercio@0: function PVPScan:LeftCombatLockdown() tercio@0: if (PVPScan.schedule_frame_update) then tercio@0: PVPScan.schedule_frame_update = false tercio@0: PVPScan:RefreshSpotBars() tercio@0: end tercio@2: PVPScan:CheckNonCombatSpotBars() tercio@0: end tercio@0: function PVPScan:GotCombatLockdown() tercio@0: end tercio@0: tercio@2: function PVPScan:GetNextSpotBar() tercio@2: for i = 1, PVPScan.db.profile.SpotBarAmount do tercio@2: local bar = PVPScan.SpotBars [i] tercio@2: if (not bar) then tercio@2: print (i, #PVPScan.SpotBars) tercio@2: end tercio@2: if (not bar.InUse and bar.Cooldown < GetTime()) then tercio@2: return bar tercio@2: end tercio@2: end tercio@2: return nil tercio@2: end tercio@2: tercio@0: PVPScan:RegisterEvent ("PLAYER_REGEN_DISABLED", "GotCombatLockdown") tercio@0: PVPScan:RegisterEvent ("PLAYER_REGEN_ENABLED", "LeftCombatLockdown") tercio@0: tercio@1: -- found a enemy on the scan tercio@2: function PVPScan:EnemySpoted (name, serial, flags, class) tercio@1: tercio@2: --se nao tiver nome, nao interessa tercio@1: if (not name) then tercio@1: return tercio@1: end tercio@2: tercio@2: --se o player tiver no cooldown para mostrar, ignora-lo tercio@2: if (PVPScan.CooldownShownPlayers [name] and PVPScan.CooldownShownPlayers [name] > GetTime()) then tercio@2: return tercio@2: end tercio@1: tercio@2: local SpotBar = PVPScan:GetNextSpotBar() tercio@2: tercio@2: if (not SpotBar) then tercio@2: return tercio@0: end tercio@0: tercio@2: --seta o cooldown deste jogador tercio@2: PVPScan.CooldownShownPlayers [name] = GetTime() + PVPScan.db.profile.SpotBarPlayerCooldown tercio@2: --seta em qual barra o jogador esta sendo mostrado tercio@2: PVPScan.CurrentShownPlayers [name] = SpotBar.Index tercio@2: tercio@2: --se nao tiver uma classe, agendar uma pesquisa tercio@2: if (not class) then tercio@2: PVPScan.NeedClass [name] = true tercio@0: end tercio@0: tercio@2: --atualiza a barra tercio@2: PVPScan:UpdateBar (SpotBar, name, class) tercio@0: tercio@2: --toca o som se a configuracao permitir tercio@2: if (PVPScan.db.profile.SoundPlay) then tercio@2: local sound = PVPScan.db.profile.SoundFile tercio@2: sound = SharedMedia:Fetch ("sound", sound) tercio@2: if (sound) then tercio@2: PlaySoundFile (sound, "Master") tercio@2: end tercio@0: end tercio@0: end tercio@0: tercio@1: -- frames tercio@2: tercio@2: function PVPScanOnFrameEnter (self) tercio@2: GameTooltip:SetOwner (self, "ANCHOR_TOPLEFT") tercio@2: GameTooltip:ClearLines() tercio@2: GameTooltip:AddLine ("Right Click To Open Options Panel") tercio@2: GameTooltip:Show() tercio@2: end tercio@2: tercio@2: function PVPScanOnFrameLeave (self) tercio@2: GameTooltip:Hide() tercio@2: end tercio@0: tercio@1: function PVPScanOnFrameMouseDown (self, button) tercio@1: if (button == "LeftButton") then tercio@1: if (not self.IsMoving) then tercio@1: self:StartMoving() tercio@1: self.IsMoving = true tercio@1: end tercio@0: end tercio@0: end tercio@0: tercio@1: function PVPScanOnFrameMouseUp (self, button) tercio@1: if (button == "LeftButton") then tercio@1: if (self.IsMoving) then tercio@1: self:StopMovingOrSizing() Tercioo@9: LibWindow.SavePosition (PVPScanFrame) tercio@1: self.IsMoving = false tercio@1: end tercio@1: tercio@1: elseif (button == "RightButton") then tercio@1: InterfaceOptionsFrame_OpenToCategory ("PVPScan") tercio@1: InterfaceOptionsFrame_OpenToCategory ("PVPScan") tercio@0: end tercio@0: end tercio@0: tercio@2: function PVPScan:CheckNonCombatSpotBars() tercio@2: for i = 1, PVPScan.db.profile.SpotBarAmount do tercio@2: local SpotObject = PVPScan.SpotBars [i] Tercio@10: if (SpotObject and SpotObject.InUse and (SpotObject.NonTargetFrame:IsShown() or SpotObject.NeedUpdate)) then tercio@2: PVPScan:UpdateBar (SpotObject, SpotObject.PlayerName, SpotObject.PlayerClass) tercio@2: end tercio@2: end tercio@2: end tercio@0: tercio@2: function PVPScan:UpdateBar (SpotObject, Name, Class, ClassUpdate) tercio@2: tercio@2: SpotObject.IsShown = true tercio@2: SpotObject.InUse = true tercio@2: SpotObject.PlayerName = Name tercio@2: SpotObject.PlayerClass = Class tercio@2: SpotObject.Cooldown = GetTime() + PVPScan.db.profile.SpotBarCooldown tercio@2: SpotObject.ExpireAt = GetTime() + PVPScan.db.profile.SpotBarTimeOut tercio@2: SpotObject.NeedUpdate = false tercio@2: tercio@2: if (ClassUpdate) then tercio@2: if (SpotObject.TargetFrame:IsShown()) then tercio@2: if (not UnitAffectingCombat ("player") and not InCombatLockdown()) then tercio@2: local color = RAID_CLASS_COLORS [Class] tercio@2: local texcoord = CLASS_ICON_TCOORDS [Class] tercio@2: SpotObject.TargetFrame.classtexture:SetVertexColor (color.r, color.g, color.b) tercio@2: SpotObject.TargetFrame.classicon:SetTexture ([[Interface\Glues\CHARACTERCREATE\UI-CHARACTERCREATE-CLASSES]]) tercio@2: SpotObject.TargetFrame.classicon:SetTexCoord (unpack (texcoord)) tercio@2: else tercio@2: SpotObject.NeedUpdate = true tercio@2: end tercio@2: else tercio@2: local color = RAID_CLASS_COLORS [Class] tercio@2: local texcoord = CLASS_ICON_TCOORDS [Class] tercio@2: SpotObject.NonTargetFrame.classtexture:SetVertexColor (color.r, color.g, color.b) tercio@2: SpotObject.NonTargetFrame.classicon:SetTexture ([[Interface\Glues\CHARACTERCREATE\UI-CHARACTERCREATE-CLASSES]]) tercio@2: SpotObject.NonTargetFrame.classicon:SetTexCoord (unpack (texcoord)) tercio@2: end tercio@2: end tercio@2: tercio@1: if (UnitAffectingCombat ("player") or InCombatLockdown()) then tercio@2: --> enable in combat bat tercio@2: if (Class) then tercio@2: local color = RAID_CLASS_COLORS [Class] tercio@2: local texcoord = CLASS_ICON_TCOORDS [Class] tercio@2: SpotObject.NonTargetFrame.classtexture:SetVertexColor (color.r, color.g, color.b) tercio@2: SpotObject.NonTargetFrame.classicon:SetTexture ([[Interface\Glues\CHARACTERCREATE\UI-CHARACTERCREATE-CLASSES]]) tercio@2: SpotObject.NonTargetFrame.classicon:SetTexCoord (unpack (texcoord)) tercio@2: else tercio@2: SpotObject.NonTargetFrame.classtexture:SetVertexColor (.7, .7, .7) tercio@2: SpotObject.NonTargetFrame.classicon:SetTexture ([[Interface\InventoryItems\WoWUnknownItem01]]) tercio@2: SpotObject.NonTargetFrame.classicon:SetTexCoord (0, 1, 0, 1) tercio@2: end tercio@2: SpotObject.NonTargetFrame.name:SetText (Name) tercio@2: SpotObject.NonTargetFrame:Show() tercio@2: SpotObject.NeedUpdate = true tercio@2: else tercio@2: --> enable spot bar tercio@2: if (Class) then tercio@2: local color = RAID_CLASS_COLORS [Class] tercio@2: local texcoord = CLASS_ICON_TCOORDS [Class] tercio@2: SpotObject.TargetFrame.classtexture:SetVertexColor (color.r, color.g, color.b) tercio@2: SpotObject.TargetFrame.classicon:SetTexture ([[Interface\Glues\CHARACTERCREATE\UI-CHARACTERCREATE-CLASSES]]) tercio@2: SpotObject.TargetFrame.classicon:SetTexCoord (unpack (texcoord)) tercio@2: else tercio@2: SpotObject.TargetFrame.classtexture:SetVertexColor (.7, .7, .7) tercio@2: SpotObject.TargetFrame.classicon:SetTexture ([[Interface\InventoryItems\WoWUnknownItem01]]) tercio@2: SpotObject.TargetFrame.classicon:SetTexCoord (0, 1, 0, 1) tercio@2: end tercio@2: SpotObject.TargetFrame:SetAttribute ("macrotext", "/cleartarget\n/targetexact " .. Name) tercio@2: SpotObject.TargetFrame.name:SetText (Name) tercio@2: SpotObject.TargetFrame.SpotObject = SpotObject tercio@2: SpotObject.NonTargetFrame:Hide() tercio@2: SpotObject.TargetFrame:Show() tercio@1: end tercio@2: end tercio@1: tercio@2: function PVPScan:CheckBarTimeOut() tercio@2: if (not UnitAffectingCombat ("player") and not InCombatLockdown()) then tercio@0: tercio@2: local time = GetTime() tercio@2: tercio@2: for repeat_twice = 1, 2 do tercio@2: for i = 1, PVPScan.db.profile.SpotBarAmount do tercio@2: tercio@2: local SpotObject = PVPScan.SpotBars [i] tercio@2: tercio@2: if (SpotObject.InUse) then tercio@2: --verifica se expirou tercio@2: if (SpotObject.ExpireAt < time) then tercio@2: PVPScan:DisableSpotBar (SpotObject) tercio@2: end tercio@2: else tercio@2: for o = i+1, PVPScan.db.profile.SpotBarAmount do tercio@2: local NextSpotObject = PVPScan.SpotBars [o] tercio@2: if (NextSpotObject.InUse) then --> transferir pra cá tercio@2: --seta a nova barra tercio@2: local PlayerName = NextSpotObject.PlayerName tercio@2: PVPScan:UpdateBar (SpotObject, PlayerName, NextSpotObject.PlayerClass) tercio@2: --desliga a barra antiga tercio@2: PVPScan:DisableSpotBar (NextSpotObject) tercio@2: --seta em qual barra o jogador esta sendo mostrado tercio@2: PVPScan.CurrentShownPlayers [PlayerName] = i tercio@2: break tercio@2: end tercio@2: end tercio@2: end tercio@2: end tercio@2: end tercio@0: end tercio@0: tercio@2: end tercio@2: tercio@2: function PVPScanSpotBarClick (self) tercio@2: if (self.SpotObject) then tercio@2: self.SpotObject.Cooldown = GetTime() + PVPScan.db.profile.SpotBarCooldown tercio@2: self.SpotObject.ExpireAt = GetTime() + PVPScan.db.profile.SpotBarTimeOut tercio@2: end tercio@2: end tercio@2: tercio@2: function PVPScan:DisableSpotBar (SpotObject) tercio@2: SpotObject.TargetFrame:Hide() tercio@2: SpotObject.TargetFrame.SpotObject = nil tercio@2: SpotObject.NonTargetFrame:Hide() tercio@0: tercio@2: SpotObject.IsShown = false tercio@2: SpotObject.NeedUpdate = false tercio@2: SpotObject.InUse = false tercio@2: SpotObject.Cooldown = 0 tercio@2: SpotObject.ExpireAt = 0 tercio@2: tercio@2: local name = SpotObject.PlayerName tercio@2: tercio@2: if (name) then tercio@2: PVPScan.NeedClass [name] = nil tercio@2: PVPScan.CurrentShownPlayers [name] = nil tercio@2: PVPScan.CooldownShownPlayers [name] = nil tercio@2: end tercio@2: tercio@2: SpotObject.PlayerName = nil tercio@2: SpotObject.PlayerClass = nil tercio@0: end tercio@0: tercio@0: function PVPScan:RefreshSpotBars() tercio@0: tercio@0: if (UnitAffectingCombat ("player") or InCombatLockdown()) then tercio@0: PVPScan.schedule_frame_update = true Tercioo@9: --PVPScan:Print ("When the combat finishes, the frame will be updated.") tercio@0: return tercio@0: end tercio@0: tercio@1: if (not PVPScan.ScanEnabled) then tercio@1: PVPScanFrame:Hide() tercio@1: else tercio@1: PVPScanFrame:Show() tercio@1: end tercio@1: tercio@0: local amount_bars = PVPScan.db.profile.SpotBarAmount tercio@1: PVPScanFrame:SetSize (PVPScan.db.profile.SpotBarWidth, 20) tercio@0: tercio@0: --> we need extra bars? tercio@0: if (amount_bars > #PVPScan.SpotBars) then tercio@0: for i = #PVPScan.SpotBars+1, amount_bars do tercio@0: tercio@2: local NewBarObject = { tercio@2: Index = i, tercio@2: TargetFrame = CreateFrame ("Button", "PVPScanSpotBar" .. i, PVPScanFrame, "PVPScanSpotBarTemplate"), tercio@2: NonTargetFrame = CreateFrame ("Button", "PVPScanSpotBarInCombat" .. i, PVPScanFrame, "PVPScanSpotBarInCombatTemplate"), tercio@2: IsShown = false, -- se a barra esta sendo mostrada tercio@2: PlayerName = nil, -- nome do jogador que esta sendo mostrado tercio@2: PlayerClass = nil, tercio@2: NeedUpdate = false, -- se a barra precisa de um update após o termino do combate tercio@2: InUse = false, -- se a barra esta em uso tercio@2: ExpireAt = 0, -- quando a barra ira sumir automaticamente tercio@2: Cooldown = 0, -- tempo para poder por outro jogador nesta barra tercio@2: } Tercioo@9: tercio@2: NewBarObject.NonTargetFrame:SetFrameLevel (NewBarObject.TargetFrame:GetFrameLevel()+1) tercio@0: tercio@0: local y = (i-1) * PVPScan.db.profile.SpotBarHeight * -1 tercio@0: tercio@2: NewBarObject.TargetFrame:SetPoint ("topleft", PVPScanFrame, "topleft", 0, y) tercio@2: NewBarObject.NonTargetFrame:SetPoint ("topleft", PVPScanFrame, "topleft", 0, y) tercio@0: tercio@2: NewBarObject.TargetFrame:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight) tercio@2: NewBarObject.NonTargetFrame:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight) tercio@2: tercio@2: tinsert (PVPScan.SpotBars, NewBarObject) tercio@0: end tercio@0: end tercio@0: tercio@0: if (#PVPScan.SpotBars > amount_bars) then tercio@0: for i = #PVPScan.SpotBars, amount_bars+1, -1 do tercio@2: PVPScan:DisableSpotBar (PVPScan.SpotBars [i]) tercio@0: end tercio@0: end tercio@0: tercio@0: --> refresh existing tercio@2: for Index, BarObject in ipairs (PVPScan.SpotBars) do tercio@2: local y = (Index-1) * PVPScan.db.profile.SpotBarHeight * -1 tercio@2: --point tercio@2: BarObject.TargetFrame:SetPoint ("topleft", PVPScanFrame, "bottomleft", 0, y) tercio@2: BarObject.NonTargetFrame:SetPoint ("topleft", PVPScanFrame, "bottomleft", 0, y) tercio@2: --size tercio@2: BarObject.TargetFrame:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight) tercio@2: BarObject.NonTargetFrame:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight) tercio@2: --texture size tercio@2: BarObject.TargetFrame.classtexture:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight) tercio@2: BarObject.NonTargetFrame.classtexture:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight) tercio@2: --bar texture tercio@2: BarObject.TargetFrame.classtexture:SetTexture (SharedMedia:Fetch ("statusbar", PVPScan.db.profile.SpotBarTexture) or [[Interface\PaperDollInfoFrame\UI-Character-Skills-Bar]]) tercio@2: BarObject.NonTargetFrame.classtexture:SetTexture (SharedMedia:Fetch ("statusbar", PVPScan.db.profile.SpotBarTexture) or [[Interface\PaperDollInfoFrame\UI-Character-Skills-Bar]]) tercio@2: --icon size tercio@2: BarObject.TargetFrame.classicon:SetSize (PVPScan.db.profile.SpotBarHeight, PVPScan.db.profile.SpotBarHeight) tercio@2: BarObject.NonTargetFrame.classicon:SetSize (PVPScan.db.profile.SpotBarHeight, PVPScan.db.profile.SpotBarHeight) tercio@0: end tercio@0: tercio@0: end tercio@0: tercio@1: --> misc tercio@0: tercio@0: function PVPScan:GuessClass (...) Tercio@10: local arg1 = select (1, ...) tercio@0: tercio@0: if (type (arg1) == "number") then Tercioo@9: local spellname = GetSpellInfo (arg1) Tercioo@9: local class = PVPScan.ClassSpellList [arg1] Tercioo@9: --print ("found enemy:", arg1, class, spellname) tercio@3: return PVPScan.ClassSpellList [arg1] tercio@0: end tercio@0: tercio@0: return nil tercio@0: end tercio@0: tercio@1: tercio@1: ------------------------------------------------------------------------------------------------------------------------------------------------------------ tercio@1: --> battlegrounds tercio@1: