comparison 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
comparison
equal deleted inserted replaced
26:547b70e235fe 27:9967caf18b2a
7 7
8 function kbf:OnInitialize() 8 function kbf:OnInitialize()
9 self.debuffFrames = {} 9 self.debuffFrames = {}
10 self.anchor = self:CreateAnchorFrame() 10 self.anchor = self:CreateAnchorFrame()
11 self:RegisterEvent("UNIT_AURA") 11 self:RegisterEvent("UNIT_AURA")
12 self:RegisterEvent("UNIT_ENTERING_VEHICLE") 12 self:RegisterEvent("UNIT_ENTERING_VEHICLE", "PollForVehicleChange")
13 self:RegisterEvent("UNIT_EXITING_VEHICLE") 13 self:RegisterEvent("UNIT_EXITING_VEHICLE", "PollForVehicleChange")
14 -- set up the countdown timer 14 -- set up the countdown timer
15 -- TODO: Fancy enable/disable based on whether you have any timed buffs. 15 -- TODO: Fancy enable/disable based on whether you have any timed buffs.
16 -- Not a big deal, how often do you care about that 16 -- Not a big deal, how often do you care about that
17 -- also TODO: Maybe should bucket OnUpdates somehow 17 -- also TODO: Maybe should bucket OnUpdates somehow
18 -- AceTimer repeating events can only happen at 0.1 seconds, which is probably 18 -- AceTimer repeating events can only happen at 0.1 seconds, which is probably
19 -- fast enough for updating, but makes the animation look jerky 19 -- fast enough for updating, but makes the animation look jerky
20 -- need to experiment with using animation groups
20 self.update = CreateFrame("FRAME") 21 self.update = CreateFrame("FRAME")
21 self.update:SetScript("OnUpdate", function() self:OnUpdate() end) 22 self.update:SetScript("OnUpdate", function() self:OnUpdate() end)
22 self.dirty = true -- force an immediate scan on login 23 self.dirty = true -- force an immediate scan on login
23 self:HideBlizzardBuffFrames() 24 self:HideBlizzardBuffFrames()
24 self:RegisterChatCommand("kbf", "ToggleAnchor") 25 self:RegisterChatCommand("kbf", "ToggleAnchor")
27 -- a "frame" is the top-level button (secure button from the header, or one I make myself) 28 -- a "frame" is the top-level button (secure button from the header, or one I make myself)
28 -- that will contain the UI information about the buff 29 -- that will contain the UI information about the buff
29 -- a "bar" is a frame that has the icon, status bar, ect associated with it 30 -- a "bar" is a frame that has the icon, status bar, ect associated with it
30 31
31 -- Secure aura header doesn't self-bind to vehicle, 32 -- Secure aura header doesn't self-bind to vehicle,
32 -- so this probably only works out of combat. But thats better than nothing... 33 -- so this only works out of combat. But thats better than nothing...
33 function kbf:UNIT_ENTERING_VEHICLE(event, unit) 34 function kbf:PollForVehicleChange(event, unit)
34 if unit ~= "player" then return end 35 if unit ~= "player" then return end
35 self.dirty = true 36 self.dirty = true
36 -- hax until SAH supports vehicles - do the swap after we come out of combat 37 -- hax until SAH supports vehicles - do the swap after we come out of combat
37 if not InCombatLockdown() then 38 -- always poll instead of insta-swapping OOC in order to simplify the UnitHasVehicleUI logic
38 self.secureFrame:SetAttribute("unit", "vehicle") 39 self.pollForUnitChange = true
39 else
40 self.pollForUnitChange = true
41 end
42 end
43
44 function kbf:UNIT_EXITING_VEHICLE(event, unit)
45 if unit ~= "player" then return end
46 self.dirty = true
47 -- hax until SAH supports vehicles - do the swap after we come out of combat
48 if not InCombatLockdown() then
49 self.secureFrame:SetAttribute("unit", "player")
50 else
51 self.pollForUnitChange = true
52 end
53 end 40 end
54 41
55 function kbf:HideBlizzardBuffFrames() 42 function kbf:HideBlizzardBuffFrames()
56 local function HideBlizFrame(frame) 43 local function HideBlizFrame(frame)
57 if not frame then return end 44 if not frame then return end
67 end 54 end
68 55
69 function kbf:OnUpdate() 56 function kbf:OnUpdate()
70 if self.pollForUnitChange and not InCombatLockdown() then 57 if self.pollForUnitChange and not InCombatLockdown() then
71 if UnitHasVehicleUI("player") then 58 if UnitHasVehicleUI("player") then
59 -- only swap if we're in a "real" vehicle with its own actions
60 -- There is possibly a timing issue here where
61 -- we have set the poll flag but the unit is not
62 -- actually "in" the vehicle yet. I'm hoping thats
63 -- handled by using exited/entered events instead of exiting/entering
72 self.secureFrame:SetAttribute("unit", "vehicle") 64 self.secureFrame:SetAttribute("unit", "vehicle")
73 else 65 else
74 self.secureFrame:SetAttribute("unit", "player") 66 self.secureFrame:SetAttribute("unit", "player")
75 end 67 end
76 self.pollForUnitChange = nil 68 self.pollForUnitChange = nil