diff 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
line wrap: on
line diff
--- a/PVPScan.lua	Sat Dec 19 20:05:50 2015 -0200
+++ b/PVPScan.lua	Fri Feb 12 14:11:13 2016 -0200
@@ -4,6 +4,7 @@
 local PVPScan = PVPScan
 local LDB = LibStub ("LibDataBroker-1.1", true)
 local LDBIcon = LDB and LibStub ("LibDBIcon-1.0", true)
+local LibWindow = LibStub ("LibWindow-1.1")
 local SharedMedia = LibStub:GetLibrary("LibSharedMedia-3.0")
 
 local _bit_band = bit.band
@@ -155,6 +156,15 @@
 	},
 }
 
+local WaitToRestore = function()
+	if (not UnitAffectingCombat ("player") and not InCombatLockdown()) then
+		PVPScan.RestoreTick:Cancel()
+		LibWindow.RestorePosition (PVPScanFrame)
+		PVPScan:LockScanFrame (PVPScan.db.profile.Locked)
+		PVPScan:RefreshSpotBars()
+	end
+end
+
 function PVPScan:OnInitialize()
 
 	--declarar primeiro o db usando a global que é declarada no toc.
@@ -183,7 +193,21 @@
 		end	
 	end
 	
-	PVPScan:RefreshSpotBars()
+	if (not self.db.profile.point) then
+		PVPScan.db.profile.Locked = false
+	end
+	
+	LibWindow.RegisterConfig (PVPScanFrame, self.db.profile)
+	LibWindow.RestorePosition (PVPScanFrame)
+	LibWindow.SavePosition (PVPScanFrame)
+	
+	if (UnitAffectingCombat ("player") or InCombatLockdown()) then
+		PVPScan:LockScanFrame (true)
+		self.RestoreTick = C_Timer.NewTicker (1, WaitToRestore)
+	else
+		PVPScan:RefreshSpotBars()
+	end
+	
 	PVPScan:LockScanFrame (PVPScan.db.profile.Locked)
 	
 	PVPScan.EventFrame:SetScript ("OnEvent", PVPScan.OnParserEvent)
@@ -198,8 +222,7 @@
 ------------------------------------------------------------------------------------------------------------------------------------------------------------
 --> general
 
-function PVPScan:ChangeZones()
-
+local check_zone = function()
 	local name, type, difficulty, difficultyName, maxPlayers, playerDifficulty, isDynamicInstance, mapID, instanceGroupSize = GetInstanceInfo()
 	local pvpType, isFFA, faction = GetZonePVPInfo()
 	
@@ -226,13 +249,16 @@
 		PVPScan.IsInOutDoors = true
 		PVPScan.ScanEnabled = true
 	end
-
+	
 	if (PVPScan.ScanEnabled) then
 		PVPScan:EnableScan()
 	else
 		PVPScan:DisableScan()
 	end
-	
+end
+
+function PVPScan:ChangeZones()
+	C_Timer.After (5, check_zone)
 end
 
 PVPScan:RegisterEvent ("ZONE_CHANGED_NEW_AREA", "ChangeZones")
@@ -259,6 +285,7 @@
 		PVPScanFrame.text:SetText ("")
 		PVPScanFrame:SetBackdrop (nil)
 		PVPScanFrame:EnableMouse (false)
+		LibWindow.SavePosition (PVPScanFrame)
 	else
 		PVPScanFrame.text:SetText ("PVPScan Anchor")
 		PVPScanFrame:SetBackdrop ({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tile = true, TileSize = 64})
@@ -408,6 +435,7 @@
 		if (button == "LeftButton") then
 			if (self.IsMoving) then
 				self:StopMovingOrSizing()
+				LibWindow.SavePosition (PVPScanFrame)
 				self.IsMoving = false
 			end
 			
@@ -563,7 +591,7 @@
 	
 		if (UnitAffectingCombat ("player") or InCombatLockdown()) then
 			PVPScan.schedule_frame_update = true
-			PVPScan:Print ("When the combat finishes, the frame will be updated.")
+			--PVPScan:Print ("When the combat finishes, the frame will be updated.")
 			return
 		end
 		
@@ -592,7 +620,7 @@
 					ExpireAt = 0, -- quando a barra ira sumir automaticamente
 					Cooldown = 0, -- tempo para poder por outro jogador nesta barra
 				}
-			
+				
 				NewBarObject.NonTargetFrame:SetFrameLevel (NewBarObject.TargetFrame:GetFrameLevel()+1)
 				
 				local y = (i-1) * PVPScan.db.profile.SpotBarHeight * -1
@@ -641,6 +669,9 @@
 		local arg1, arg2, arg3, arg4 = select (1, ...)
 		
 		if (type (arg1) == "number") then
+			local spellname = GetSpellInfo (arg1)
+			local class = PVPScan.ClassSpellList [arg1]
+			--print ("found enemy:", arg1, class, spellname)
 			return PVPScan.ClassSpellList [arg1]
 		end