diff KBF.lua @ 68:f5bd73181349

true in-combat vehicle swapping hooray!
author Chris Mellon <arkanes@gmail.com>
date Sat, 30 Jun 2012 18:18:18 -0500
parents 673fd9893f1e
children b467bba0224d
line wrap: on
line diff
--- a/KBF.lua	Sat Jun 30 15:44:10 2012 -0500
+++ b/KBF.lua	Sat Jun 30 18:18:18 2012 -0500
@@ -11,11 +11,9 @@
     self.db = LibStub("AceDB-3.0"):New("KBFSavedVars", self.defaultConfig, true)
     -- create frames here so that they will be correctly stored in location cache by 
     -- the UI.
-    self.anchor, self.secureHeader, self.consolidateHeader, self.consolidateProxy = self:CreateCoreFrames()
+    self.anchor, self.secureHeader, self.consolidateHeader, self.consolidateProxy, self.vehicleHeader = self:CreateCoreFrames()
     self.debuffFrames = {}
     self:RegisterEvent("UNIT_AURA")
-    self:RegisterEvent("UNIT_ENTERING_VEHICLE", "PollForVehicleChange")
-    self:RegisterEvent("UNIT_EXITING_VEHICLE", "PollForVehicleChange")
     LibStub("AceConfig-3.0"):RegisterOptionsTable("KBF", self.options);
     self.profilesFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("KBF", "KBF");
     self:RegisterChatCommand("kbf", "ToggleAnchor")
@@ -41,25 +39,6 @@
 -- that will contain the UI information about the buff
 -- 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 only works out of combat. But thats better than nothing...
-function kbf:PollForVehicleChange(event, unit)
-    if unit ~= "player" then return end
-    self.dirty = true
-    local function performSwap()
-        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.secureHeader:SetAttribute("unit", "vehicle")
-        else
-            self.secureHeader:SetAttribute("unit", "player")
-        end
-    end
-    self:QueueForOOC(performSwap)
-end
 
 function kbf:HideBlizzardBuffFrames()
     local function HideBlizFrame(frame)
@@ -147,6 +126,23 @@
         end
         buffCount = buffCount+1
     end
+
+    if self.vehicleHeader:IsShown() then
+        local unit = "vehicle"
+        for idx=1,99 do
+            local frame = self.vehicleHeader:GetAttribute("child"..idx)
+            if not (frame and frame:IsShown()) then break end
+            if true then 
+                if self:BindBarToBuff(frame, unit) then break end
+            end
+            self:UpdateBarExpirationTime(frame)
+            -- Don't forget to refresh shown tooltips
+            if ( GameTooltip:IsOwned(frame) ) then
+                self:OnEnter(frame)
+            end
+        end
+    end
+
     -- SAH correctly binds the weapon enchant templates now, but when temp enchants
     -- are present and used, it seems that it doesn't correctly hide un-bound 
     -- buff frames, which breaks all the layout and so forth.
@@ -176,7 +172,7 @@
                 break 
             end
             if not frame then
-                frame = self:ConstructBar(nil, 1, 0, 0)
+                frame = self:ConstructBar(nil, 1, 0, 0, self.secureHeader)
                 self.debuffFrames[idx] = frame
             end
             self:SetBarAppearance(frame, name, icon, stacks, duration, expirationTime)
@@ -362,7 +358,7 @@
 end
 
 -- creates a icon + statusbar bar
-function kbf:ConstructBar(frame, r, g, b)
+function kbf:ConstructBar(frame, r, g, b, parent)
     local texture = "Interface\\TargetingFrame\\UI-StatusBar"
     -- Because of secureframe suckiness, these height & width numbers
     -- have to be consistent with the stuff in KBF.xml
@@ -379,7 +375,8 @@
     local textcolor = {1, 1, 1, 1}
     local timertextcolor = {1, 1, 1, 1}
     if not frame then
-        frame = CreateFrame("Button", "ABC", UIParent) -- the "top level" frame that represents the bar as a whole
+        parent = parent or UIParent
+        frame = CreateFrame("Button", "ABC", parent) -- the "top level" frame that represents the bar as a whole
         frame:SetHeight(height)
         frame:SetWidth(width + height)
     end
@@ -508,7 +505,36 @@
     consolidateHeader:SetHeight(height)
     consolidateHeader:Show()
     
-    return anchor, secureHeader, consolidateHeader, consolidateProxy
+    local vehicleHeader = CreateFrame("FRAME", "KBFBuffFrame", UIParent, "SecureAuraHeaderTemplate")
+    self:SetCommonSecureHeaderAttributes(vehicleHeader)
+    vehicleHeader:SetAttribute("unit", "vehicle")
+    vehicleHeader:SetPoint("TOP", anchor, "TOP", 0, 0)
+    vehicleHeader:SetWidth(height + width)
+    vehicleHeader:SetHeight(height)
+    RegisterUnitWatch(vehicleHeader)
+    
+
+    local frameHider = CreateFrame("FRAME", "KBFFrameHider", UIParent, "SecureHandlerStateTemplate")
+    frameHider:SetAttribute("unit", "vehicle")
+    frameHider:SetFrameRef("frame1", secureHeader)
+    frameHider:SetFrameRef("frame2", consolidateHeader)
+    frameHider:SetFrameRef("frame3", consolidateProxy)
+    frameHider:SetAttribute("_onstate-unitexists", [[
+        for idx=1,99 do
+            local frame = self:GetFrameRef("frame"..idx)
+            if frame then
+                if newstate then
+                    frame:Hide()
+                else
+                    frame:Show()
+                end
+            end
+        end
+    ]])
+    RegisterUnitWatch(frameHider, true)
+
+
+    return anchor, secureHeader, consolidateHeader, consolidateProxy, vehicleHeader
 end
 
 --- sets the attributes needed by all the headers