Mercurial > wow > kbf
comparison 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 |
comparison
equal
deleted
inserted
replaced
67:673fd9893f1e | 68:f5bd73181349 |
---|---|
9 self.oocQueue = {} | 9 self.oocQueue = {} |
10 -- config settings - account wide shared profile by default | 10 -- config settings - account wide shared profile by default |
11 self.db = LibStub("AceDB-3.0"):New("KBFSavedVars", self.defaultConfig, true) | 11 self.db = LibStub("AceDB-3.0"):New("KBFSavedVars", self.defaultConfig, true) |
12 -- create frames here so that they will be correctly stored in location cache by | 12 -- create frames here so that they will be correctly stored in location cache by |
13 -- the UI. | 13 -- the UI. |
14 self.anchor, self.secureHeader, self.consolidateHeader, self.consolidateProxy = self:CreateCoreFrames() | 14 self.anchor, self.secureHeader, self.consolidateHeader, self.consolidateProxy, self.vehicleHeader = self:CreateCoreFrames() |
15 self.debuffFrames = {} | 15 self.debuffFrames = {} |
16 self:RegisterEvent("UNIT_AURA") | 16 self:RegisterEvent("UNIT_AURA") |
17 self:RegisterEvent("UNIT_ENTERING_VEHICLE", "PollForVehicleChange") | |
18 self:RegisterEvent("UNIT_EXITING_VEHICLE", "PollForVehicleChange") | |
19 LibStub("AceConfig-3.0"):RegisterOptionsTable("KBF", self.options); | 17 LibStub("AceConfig-3.0"):RegisterOptionsTable("KBF", self.options); |
20 self.profilesFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("KBF", "KBF"); | 18 self.profilesFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("KBF", "KBF"); |
21 self:RegisterChatCommand("kbf", "ToggleAnchor") | 19 self:RegisterChatCommand("kbf", "ToggleAnchor") |
22 | 20 |
23 | 21 |
39 -- naming convention | 37 -- naming convention |
40 -- a "frame" is the top-level button (secure button from the header, or one I make myself) | 38 -- a "frame" is the top-level button (secure button from the header, or one I make myself) |
41 -- that will contain the UI information about the buff | 39 -- that will contain the UI information about the buff |
42 -- a "bar" is a frame that has the icon, status bar, ect associated with it | 40 -- a "bar" is a frame that has the icon, status bar, ect associated with it |
43 | 41 |
44 -- Secure aura header doesn't self-bind to vehicle, | |
45 -- so this only works out of combat. But thats better than nothing... | |
46 function kbf:PollForVehicleChange(event, unit) | |
47 if unit ~= "player" then return end | |
48 self.dirty = true | |
49 local function performSwap() | |
50 if UnitHasVehicleUI("player") then | |
51 -- only swap if we're in a "real" vehicle with its own actions | |
52 -- There is possibly a timing issue here where | |
53 -- we have set the poll flag but the unit is not | |
54 -- actually "in" the vehicle yet. I'm hoping thats | |
55 -- handled by using exited/entered events instead of exiting/entering | |
56 self.secureHeader:SetAttribute("unit", "vehicle") | |
57 else | |
58 self.secureHeader:SetAttribute("unit", "player") | |
59 end | |
60 end | |
61 self:QueueForOOC(performSwap) | |
62 end | |
63 | 42 |
64 function kbf:HideBlizzardBuffFrames() | 43 function kbf:HideBlizzardBuffFrames() |
65 local function HideBlizFrame(frame) | 44 local function HideBlizFrame(frame) |
66 if not frame then return end | 45 if not frame then return end |
67 frame:UnregisterAllEvents() | 46 frame:UnregisterAllEvents() |
145 self:OnEnter(frame) | 124 self:OnEnter(frame) |
146 end | 125 end |
147 end | 126 end |
148 buffCount = buffCount+1 | 127 buffCount = buffCount+1 |
149 end | 128 end |
129 | |
130 if self.vehicleHeader:IsShown() then | |
131 local unit = "vehicle" | |
132 for idx=1,99 do | |
133 local frame = self.vehicleHeader:GetAttribute("child"..idx) | |
134 if not (frame and frame:IsShown()) then break end | |
135 if true then | |
136 if self:BindBarToBuff(frame, unit) then break end | |
137 end | |
138 self:UpdateBarExpirationTime(frame) | |
139 -- Don't forget to refresh shown tooltips | |
140 if ( GameTooltip:IsOwned(frame) ) then | |
141 self:OnEnter(frame) | |
142 end | |
143 end | |
144 end | |
145 | |
150 -- SAH correctly binds the weapon enchant templates now, but when temp enchants | 146 -- SAH correctly binds the weapon enchant templates now, but when temp enchants |
151 -- are present and used, it seems that it doesn't correctly hide un-bound | 147 -- are present and used, it seems that it doesn't correctly hide un-bound |
152 -- buff frames, which breaks all the layout and so forth. | 148 -- buff frames, which breaks all the layout and so forth. |
153 for weapon=3,1,-1 do | 149 for weapon=3,1,-1 do |
154 local tempEnchant = self.secureHeader:GetAttribute("tempEnchant"..weapon) | 150 local tempEnchant = self.secureHeader:GetAttribute("tempEnchant"..weapon) |
174 if bar then bar:Hide() else break end | 170 if bar then bar:Hide() else break end |
175 end | 171 end |
176 break | 172 break |
177 end | 173 end |
178 if not frame then | 174 if not frame then |
179 frame = self:ConstructBar(nil, 1, 0, 0) | 175 frame = self:ConstructBar(nil, 1, 0, 0, self.secureHeader) |
180 self.debuffFrames[idx] = frame | 176 self.debuffFrames[idx] = frame |
181 end | 177 end |
182 self:SetBarAppearance(frame, name, icon, stacks, duration, expirationTime) | 178 self:SetBarAppearance(frame, name, icon, stacks, duration, expirationTime) |
183 frame:ClearAllPoints() | 179 frame:ClearAllPoints() |
184 -- position it under all the buffs, with a half-bar spacing | 180 -- position it under all the buffs, with a half-bar spacing |
360 end | 356 end |
361 end | 357 end |
362 end | 358 end |
363 | 359 |
364 -- creates a icon + statusbar bar | 360 -- creates a icon + statusbar bar |
365 function kbf:ConstructBar(frame, r, g, b) | 361 function kbf:ConstructBar(frame, r, g, b, parent) |
366 local texture = "Interface\\TargetingFrame\\UI-StatusBar" | 362 local texture = "Interface\\TargetingFrame\\UI-StatusBar" |
367 -- Because of secureframe suckiness, these height & width numbers | 363 -- Because of secureframe suckiness, these height & width numbers |
368 -- have to be consistent with the stuff in KBF.xml | 364 -- have to be consistent with the stuff in KBF.xml |
369 local height = self.staticConfig.BAR_HEIGHT | 365 local height = self.staticConfig.BAR_HEIGHT |
370 local width = self.staticConfig.BAR_WIDTH -- this is the width *without* the icon | 366 local width = self.staticConfig.BAR_WIDTH -- this is the width *without* the icon |
377 local fontsize = 11 | 373 local fontsize = 11 |
378 local timertextwidth = fontsize * 3.6 | 374 local timertextwidth = fontsize * 3.6 |
379 local textcolor = {1, 1, 1, 1} | 375 local textcolor = {1, 1, 1, 1} |
380 local timertextcolor = {1, 1, 1, 1} | 376 local timertextcolor = {1, 1, 1, 1} |
381 if not frame then | 377 if not frame then |
382 frame = CreateFrame("Button", "ABC", UIParent) -- the "top level" frame that represents the bar as a whole | 378 parent = parent or UIParent |
379 frame = CreateFrame("Button", "ABC", parent) -- the "top level" frame that represents the bar as a whole | |
383 frame:SetHeight(height) | 380 frame:SetHeight(height) |
384 frame:SetWidth(width + height) | 381 frame:SetWidth(width + height) |
385 end | 382 end |
386 local bar = frame | 383 local bar = frame |
387 bar.icon = CreateFrame("Button", "ABC-Icon", bar) -- the icon | 384 bar.icon = CreateFrame("Button", "ABC-Icon", bar) -- the icon |
506 consolidateHeader:SetPoint("TOPRIGHT", anchor, "TOPLEFT", 0, 0) | 503 consolidateHeader:SetPoint("TOPRIGHT", anchor, "TOPLEFT", 0, 0) |
507 consolidateHeader:SetWidth(height + width) | 504 consolidateHeader:SetWidth(height + width) |
508 consolidateHeader:SetHeight(height) | 505 consolidateHeader:SetHeight(height) |
509 consolidateHeader:Show() | 506 consolidateHeader:Show() |
510 | 507 |
511 return anchor, secureHeader, consolidateHeader, consolidateProxy | 508 local vehicleHeader = CreateFrame("FRAME", "KBFBuffFrame", UIParent, "SecureAuraHeaderTemplate") |
509 self:SetCommonSecureHeaderAttributes(vehicleHeader) | |
510 vehicleHeader:SetAttribute("unit", "vehicle") | |
511 vehicleHeader:SetPoint("TOP", anchor, "TOP", 0, 0) | |
512 vehicleHeader:SetWidth(height + width) | |
513 vehicleHeader:SetHeight(height) | |
514 RegisterUnitWatch(vehicleHeader) | |
515 | |
516 | |
517 local frameHider = CreateFrame("FRAME", "KBFFrameHider", UIParent, "SecureHandlerStateTemplate") | |
518 frameHider:SetAttribute("unit", "vehicle") | |
519 frameHider:SetFrameRef("frame1", secureHeader) | |
520 frameHider:SetFrameRef("frame2", consolidateHeader) | |
521 frameHider:SetFrameRef("frame3", consolidateProxy) | |
522 frameHider:SetAttribute("_onstate-unitexists", [[ | |
523 for idx=1,99 do | |
524 local frame = self:GetFrameRef("frame"..idx) | |
525 if frame then | |
526 if newstate then | |
527 frame:Hide() | |
528 else | |
529 frame:Show() | |
530 end | |
531 end | |
532 end | |
533 ]]) | |
534 RegisterUnitWatch(frameHider, true) | |
535 | |
536 | |
537 return anchor, secureHeader, consolidateHeader, consolidateProxy, vehicleHeader | |
512 end | 538 end |
513 | 539 |
514 --- sets the attributes needed by all the headers | 540 --- sets the attributes needed by all the headers |
515 function kbf:SetCommonSecureHeaderAttributes(frame) | 541 function kbf:SetCommonSecureHeaderAttributes(frame) |
516 frame:SetAttribute("filter", "HELPFUL") | 542 frame:SetAttribute("filter", "HELPFUL") |