Mercurial > wow > pvpscan
comparison PVPScan.lua @ 9:f2a55f2d45c8
- added LibWindow to handle the window position.
| author | Tercioo |
|---|---|
| date | Fri, 12 Feb 2016 14:11:13 -0200 |
| parents | 2f9d1a15506a |
| children | 2218520e3e64 |
comparison
equal
deleted
inserted
replaced
| 8:2f9d1a15506a | 9:f2a55f2d45c8 |
|---|---|
| 2 PVPScan = LibStub ("AceAddon-3.0"):NewAddon ("PVPScan", "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0") | 2 PVPScan = LibStub ("AceAddon-3.0"):NewAddon ("PVPScan", "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0") |
| 3 | 3 |
| 4 local PVPScan = PVPScan | 4 local PVPScan = PVPScan |
| 5 local LDB = LibStub ("LibDataBroker-1.1", true) | 5 local LDB = LibStub ("LibDataBroker-1.1", true) |
| 6 local LDBIcon = LDB and LibStub ("LibDBIcon-1.0", true) | 6 local LDBIcon = LDB and LibStub ("LibDBIcon-1.0", true) |
| 7 local LibWindow = LibStub ("LibWindow-1.1") | |
| 7 local SharedMedia = LibStub:GetLibrary("LibSharedMedia-3.0") | 8 local SharedMedia = LibStub:GetLibrary("LibSharedMedia-3.0") |
| 8 | 9 |
| 9 local _bit_band = bit.band | 10 local _bit_band = bit.band |
| 10 local GetTime = GetTime | 11 local GetTime = GetTime |
| 11 | 12 |
| 153 end, | 154 end, |
| 154 }, | 155 }, |
| 155 }, | 156 }, |
| 156 } | 157 } |
| 157 | 158 |
| 159 local WaitToRestore = function() | |
| 160 if (not UnitAffectingCombat ("player") and not InCombatLockdown()) then | |
| 161 PVPScan.RestoreTick:Cancel() | |
| 162 LibWindow.RestorePosition (PVPScanFrame) | |
| 163 PVPScan:LockScanFrame (PVPScan.db.profile.Locked) | |
| 164 PVPScan:RefreshSpotBars() | |
| 165 end | |
| 166 end | |
| 167 | |
| 158 function PVPScan:OnInitialize() | 168 function PVPScan:OnInitialize() |
| 159 | 169 |
| 160 --declarar primeiro o db usando a global que é declarada no toc. | 170 --declarar primeiro o db usando a global que é declarada no toc. |
| 161 self.db = LibStub ("AceDB-3.0"):New ("PVPScanDB", default_db, true) | 171 self.db = LibStub ("AceDB-3.0"):New ("PVPScanDB", default_db, true) |
| 162 | 172 |
| 181 if (databroker and not LDBIcon:IsRegistered ("PVPScan")) then | 191 if (databroker and not LDBIcon:IsRegistered ("PVPScan")) then |
| 182 LDBIcon:Register ("PVPScan", databroker, PVPScan.db.profile.Minimap) | 192 LDBIcon:Register ("PVPScan", databroker, PVPScan.db.profile.Minimap) |
| 183 end | 193 end |
| 184 end | 194 end |
| 185 | 195 |
| 186 PVPScan:RefreshSpotBars() | 196 if (not self.db.profile.point) then |
| 197 PVPScan.db.profile.Locked = false | |
| 198 end | |
| 199 | |
| 200 LibWindow.RegisterConfig (PVPScanFrame, self.db.profile) | |
| 201 LibWindow.RestorePosition (PVPScanFrame) | |
| 202 LibWindow.SavePosition (PVPScanFrame) | |
| 203 | |
| 204 if (UnitAffectingCombat ("player") or InCombatLockdown()) then | |
| 205 PVPScan:LockScanFrame (true) | |
| 206 self.RestoreTick = C_Timer.NewTicker (1, WaitToRestore) | |
| 207 else | |
| 208 PVPScan:RefreshSpotBars() | |
| 209 end | |
| 210 | |
| 187 PVPScan:LockScanFrame (PVPScan.db.profile.Locked) | 211 PVPScan:LockScanFrame (PVPScan.db.profile.Locked) |
| 188 | 212 |
| 189 PVPScan.EventFrame:SetScript ("OnEvent", PVPScan.OnParserEvent) | 213 PVPScan.EventFrame:SetScript ("OnEvent", PVPScan.OnParserEvent) |
| 190 end | 214 end |
| 191 | 215 |
| 196 | 220 |
| 197 | 221 |
| 198 ------------------------------------------------------------------------------------------------------------------------------------------------------------ | 222 ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 199 --> general | 223 --> general |
| 200 | 224 |
| 201 function PVPScan:ChangeZones() | 225 local check_zone = function() |
| 202 | |
| 203 local name, type, difficulty, difficultyName, maxPlayers, playerDifficulty, isDynamicInstance, mapID, instanceGroupSize = GetInstanceInfo() | 226 local name, type, difficulty, difficultyName, maxPlayers, playerDifficulty, isDynamicInstance, mapID, instanceGroupSize = GetInstanceInfo() |
| 204 local pvpType, isFFA, faction = GetZonePVPInfo() | 227 local pvpType, isFFA, faction = GetZonePVPInfo() |
| 205 | 228 |
| 206 PVPScan.IsInBattleground = false | 229 PVPScan.IsInBattleground = false |
| 207 PVPScan.IsInCity = false | 230 PVPScan.IsInCity = false |
| 224 | 247 |
| 225 else | 248 else |
| 226 PVPScan.IsInOutDoors = true | 249 PVPScan.IsInOutDoors = true |
| 227 PVPScan.ScanEnabled = true | 250 PVPScan.ScanEnabled = true |
| 228 end | 251 end |
| 229 | 252 |
| 230 if (PVPScan.ScanEnabled) then | 253 if (PVPScan.ScanEnabled) then |
| 231 PVPScan:EnableScan() | 254 PVPScan:EnableScan() |
| 232 else | 255 else |
| 233 PVPScan:DisableScan() | 256 PVPScan:DisableScan() |
| 234 end | 257 end |
| 235 | 258 end |
| 259 | |
| 260 function PVPScan:ChangeZones() | |
| 261 C_Timer.After (5, check_zone) | |
| 236 end | 262 end |
| 237 | 263 |
| 238 PVPScan:RegisterEvent ("ZONE_CHANGED_NEW_AREA", "ChangeZones") | 264 PVPScan:RegisterEvent ("ZONE_CHANGED_NEW_AREA", "ChangeZones") |
| 239 PVPScan:RegisterEvent ("PLAYER_ENTERING_WORLD", "ChangeZones") | 265 PVPScan:RegisterEvent ("PLAYER_ENTERING_WORLD", "ChangeZones") |
| 240 | 266 |
| 257 function PVPScan:LockScanFrame (IsLocked) | 283 function PVPScan:LockScanFrame (IsLocked) |
| 258 if (IsLocked) then | 284 if (IsLocked) then |
| 259 PVPScanFrame.text:SetText ("") | 285 PVPScanFrame.text:SetText ("") |
| 260 PVPScanFrame:SetBackdrop (nil) | 286 PVPScanFrame:SetBackdrop (nil) |
| 261 PVPScanFrame:EnableMouse (false) | 287 PVPScanFrame:EnableMouse (false) |
| 288 LibWindow.SavePosition (PVPScanFrame) | |
| 262 else | 289 else |
| 263 PVPScanFrame.text:SetText ("PVPScan Anchor") | 290 PVPScanFrame.text:SetText ("PVPScan Anchor") |
| 264 PVPScanFrame:SetBackdrop ({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tile = true, TileSize = 64}) | 291 PVPScanFrame:SetBackdrop ({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tile = true, TileSize = 64}) |
| 265 PVPScanFrame:SetBackdropColor (0, 0, 0, 1) | 292 PVPScanFrame:SetBackdropColor (0, 0, 0, 1) |
| 266 PVPScanFrame:EnableMouse (true) | 293 PVPScanFrame:EnableMouse (true) |
| 406 | 433 |
| 407 function PVPScanOnFrameMouseUp (self, button) | 434 function PVPScanOnFrameMouseUp (self, button) |
| 408 if (button == "LeftButton") then | 435 if (button == "LeftButton") then |
| 409 if (self.IsMoving) then | 436 if (self.IsMoving) then |
| 410 self:StopMovingOrSizing() | 437 self:StopMovingOrSizing() |
| 438 LibWindow.SavePosition (PVPScanFrame) | |
| 411 self.IsMoving = false | 439 self.IsMoving = false |
| 412 end | 440 end |
| 413 | 441 |
| 414 elseif (button == "RightButton") then | 442 elseif (button == "RightButton") then |
| 415 InterfaceOptionsFrame_OpenToCategory ("PVPScan") | 443 InterfaceOptionsFrame_OpenToCategory ("PVPScan") |
| 561 | 589 |
| 562 function PVPScan:RefreshSpotBars() | 590 function PVPScan:RefreshSpotBars() |
| 563 | 591 |
| 564 if (UnitAffectingCombat ("player") or InCombatLockdown()) then | 592 if (UnitAffectingCombat ("player") or InCombatLockdown()) then |
| 565 PVPScan.schedule_frame_update = true | 593 PVPScan.schedule_frame_update = true |
| 566 PVPScan:Print ("When the combat finishes, the frame will be updated.") | 594 --PVPScan:Print ("When the combat finishes, the frame will be updated.") |
| 567 return | 595 return |
| 568 end | 596 end |
| 569 | 597 |
| 570 if (not PVPScan.ScanEnabled) then | 598 if (not PVPScan.ScanEnabled) then |
| 571 PVPScanFrame:Hide() | 599 PVPScanFrame:Hide() |
| 590 NeedUpdate = false, -- se a barra precisa de um update após o termino do combate | 618 NeedUpdate = false, -- se a barra precisa de um update após o termino do combate |
| 591 InUse = false, -- se a barra esta em uso | 619 InUse = false, -- se a barra esta em uso |
| 592 ExpireAt = 0, -- quando a barra ira sumir automaticamente | 620 ExpireAt = 0, -- quando a barra ira sumir automaticamente |
| 593 Cooldown = 0, -- tempo para poder por outro jogador nesta barra | 621 Cooldown = 0, -- tempo para poder por outro jogador nesta barra |
| 594 } | 622 } |
| 595 | 623 |
| 596 NewBarObject.NonTargetFrame:SetFrameLevel (NewBarObject.TargetFrame:GetFrameLevel()+1) | 624 NewBarObject.NonTargetFrame:SetFrameLevel (NewBarObject.TargetFrame:GetFrameLevel()+1) |
| 597 | 625 |
| 598 local y = (i-1) * PVPScan.db.profile.SpotBarHeight * -1 | 626 local y = (i-1) * PVPScan.db.profile.SpotBarHeight * -1 |
| 599 | 627 |
| 600 NewBarObject.TargetFrame:SetPoint ("topleft", PVPScanFrame, "topleft", 0, y) | 628 NewBarObject.TargetFrame:SetPoint ("topleft", PVPScanFrame, "topleft", 0, y) |
| 639 | 667 |
| 640 function PVPScan:GuessClass (...) | 668 function PVPScan:GuessClass (...) |
| 641 local arg1, arg2, arg3, arg4 = select (1, ...) | 669 local arg1, arg2, arg3, arg4 = select (1, ...) |
| 642 | 670 |
| 643 if (type (arg1) == "number") then | 671 if (type (arg1) == "number") then |
| 672 local spellname = GetSpellInfo (arg1) | |
| 673 local class = PVPScan.ClassSpellList [arg1] | |
| 674 --print ("found enemy:", arg1, class, spellname) | |
| 644 return PVPScan.ClassSpellList [arg1] | 675 return PVPScan.ClassSpellList [arg1] |
| 645 end | 676 end |
| 646 | 677 |
| 647 return nil | 678 return nil |
| 648 end | 679 end |
