diff KBF.lua @ 27:9967caf18b2a

updates to how vehicle swapping is handled
author Chris Mellon <arkanes@gmail.com>
date Mon, 13 Dec 2010 09:01:53 -0600
parents 547b70e235fe
children 2986c72f64ba
line wrap: on
line diff
--- a/KBF.lua	Tue Nov 16 07:09:20 2010 -0600
+++ b/KBF.lua	Mon Dec 13 09:01:53 2010 -0600
@@ -9,14 +9,15 @@
     self.debuffFrames = {}
     self.anchor = self:CreateAnchorFrame()
     self:RegisterEvent("UNIT_AURA")
-    self:RegisterEvent("UNIT_ENTERING_VEHICLE")
-    self:RegisterEvent("UNIT_EXITING_VEHICLE")
+    self:RegisterEvent("UNIT_ENTERING_VEHICLE", "PollForVehicleChange")
+    self:RegisterEvent("UNIT_EXITING_VEHICLE", "PollForVehicleChange")
     -- set up the countdown timer
     -- TODO: Fancy enable/disable based on whether you have any timed buffs.
     -- Not a big deal, how often do you care about that
     -- also TODO: Maybe should bucket OnUpdates somehow
     -- AceTimer repeating events can only happen at 0.1 seconds, which is probably
     -- fast enough for updating, but makes the animation look jerky
+    -- need to experiment with using animation groups
     self.update = CreateFrame("FRAME")
     self.update:SetScript("OnUpdate", function() self:OnUpdate() end)
     self.dirty = true -- force an immediate scan on login
@@ -29,27 +30,13 @@
 -- a "bar" is a frame that has the icon, status bar, ect associated with it
 
 -- Secure aura header doesn't self-bind to vehicle,
--- so this probably only works out of combat. But thats better than nothing...
-function kbf:UNIT_ENTERING_VEHICLE(event, unit)
+-- so this only works out of combat. But thats better than nothing...
+function kbf:PollForVehicleChange(event, unit)
     if unit ~= "player" then return end
     self.dirty = true
     -- hax until SAH supports vehicles - do the swap after we come out of combat
-    if not InCombatLockdown() then
-        self.secureFrame:SetAttribute("unit", "vehicle")
-    else
-        self.pollForUnitChange = true
-    end
-end
-
-function kbf:UNIT_EXITING_VEHICLE(event, unit)
-    if unit ~= "player" then return end
-    self.dirty = true
-    -- hax until SAH supports vehicles - do the swap after we come out of combat
-    if not InCombatLockdown() then
-        self.secureFrame:SetAttribute("unit", "player")
-    else
-        self.pollForUnitChange = true
-    end
+    -- always poll instead of insta-swapping OOC in order to simplify the UnitHasVehicleUI logic
+	self.pollForUnitChange = true
 end
 
 function kbf:HideBlizzardBuffFrames()
@@ -69,6 +56,11 @@
 function kbf:OnUpdate()
     if self.pollForUnitChange and not InCombatLockdown() then
         if UnitHasVehicleUI("player") then
+			-- only swap if we're in a "real" vehicle with its own actions
+        	-- There is possibly a timing issue here where
+        	-- we have set the poll flag but the unit is not 
+        	-- actually "in" the vehicle yet. I'm hoping thats 
+        	-- handled by using exited/entered events instead of exiting/entering
             self.secureFrame:SetAttribute("unit", "vehicle")
         else
             self.secureFrame:SetAttribute("unit", "player")