comparison KBF.lua @ 18:27aa0d9ffe43

allow hiding of the anchor
author Chris Mellon <arkanes@gmai.com>
date Fri, 15 Oct 2010 22:40:50 -0500
parents 233745d4774b
children a6f5a0f2d429
comparison
equal deleted inserted replaced
17:233745d4774b 18:27aa0d9ffe43
6 6
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.anchor:Show()
12 self:RegisterEvent("UNIT_AURA") 11 self:RegisterEvent("UNIT_AURA")
13 -- set up the countdown timer 12 -- set up the countdown timer
14 -- TODO: Fancy enable/disable based on whether you have any timed buffs. 13 -- TODO: Fancy enable/disable based on whether you have any timed buffs.
15 -- Not a big deal, how often do you care about that 14 -- Not a big deal, how often do you care about that
16 -- also TODO: Maybe should bucket OnUpdates somehow 15 -- also TODO: Maybe should bucket OnUpdates somehow
17 self.anchor:SetScript("OnUpdate", function() self:OnUpdate() end) 16 -- AceTimer repeating events can only happen at 0.1 seconds, which is probably
17 -- fast enough for updating, but makes the animation look jerky
18 self.update = CreateFrame("FRAME")
19 self.update:SetScript("OnUpdate", function() self:OnUpdate() end)
18 self.dirty = true -- force an immediate scan on login 20 self.dirty = true -- force an immediate scan on login
19 self:HideBlizzardBuffFrames() 21 self:HideBlizzardBuffFrames()
22 self:RegisterChatCommand("kbf", "ToggleAnchor")
20 end 23 end
21 -- naming convention 24 -- naming convention
22 -- a "frame" is the top-level button (secure button from the header, or one I make myself) 25 -- a "frame" is the top-level button (secure button from the header, or one I make myself)
23 -- that will contain the UI information about the buff 26 -- that will contain the UI information about the buff
24 27
32 frame:Hide() 35 frame:Hide()
33 frame.Show = function() end 36 frame.Show = function() end
34 end 37 end
35 HideBlizFrame(BuffFrame) 38 HideBlizFrame(BuffFrame)
36 HideBlizFrame(ConsolidatedBuffs) 39 HideBlizFrame(ConsolidatedBuffs)
37 --HideBlizFrame(TemporaryEnchantFrame) 40 HideBlizFrame(TemporaryEnchantFrame)
38 41
39 end 42 end
40 43
41 function kbf:OnUpdate() 44 function kbf:OnUpdate()
42 local unit = self.secureFrame:GetAttribute("unit") 45 local unit = self.secureFrame:GetAttribute("unit")
308 -- give it a name so it'll remember its position 311 -- give it a name so it'll remember its position
309 local anchor = CreateFrame("FRAME", "KBFAnchorFrame", UIParent) 312 local anchor = CreateFrame("FRAME", "KBFAnchorFrame", UIParent)
310 anchor:SetClampedToScreen(true) 313 anchor:SetClampedToScreen(true)
311 anchor:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background", 314 anchor:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background",
312 edgeFile = "Interface/Tooltips/UI-Tooltip-Border", 315 edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
313 tile = true, tileSize = 16, edgeSize = 16, 316 tile = true, tileSize = 16, edgeSize = 12,
314 insets = { left = 4, right = 4, top = 4, bottom = 4 }, 317 insets = { left = 4, right = 4, top = 4, bottom = 4 },
315 }) 318 })
316 local text = anchor:CreateFontString(nil, "OVERLAY") -- the label text 319 local text = anchor:CreateFontString(nil, "OVERLAY") -- the label text
317 text:SetFontObject(GameFontHighlight) 320 text:SetFontObject(GameFontHighlight)
318 text:SetFont(GameFontHighlight:GetFont()) 321 text:SetFont(GameFontHighlight:GetFont())
319 text:SetPoint("TOPLEFT", anchor, "TOPLEFT", 0, 0) 322 text:SetPoint("TOPLEFT", anchor, "TOPLEFT", 0, 0)
320 text:SetPoint("BOTTOMRIGHT", anchor, "BOTTOMRIGHT", 0, 0) 323 text:SetPoint("BOTTOMRIGHT", anchor, "BOTTOMRIGHT", 0, 0)
321 text:SetText("KBF ANCHOR") 324 text:SetText("KBF ANCHOR")
322 anchor:SetWidth(200 + 16 + 8) 325 anchor:SetWidth(200 +16)
323 anchor:SetHeight(16 + 8) 326 anchor:SetHeight(16)
324 -- movability 327 -- movability
325 anchor:EnableMouse(true) 328 anchor:EnableMouse(true)
326 anchor:SetMovable(true) 329 anchor:SetMovable(true)
327 anchor:RegisterForDrag("LeftButton") 330 anchor:RegisterForDrag("LeftButton")
328 anchor:SetScript("OnDragStart", anchor.StartMoving) 331 anchor:SetScript("OnDragStart", anchor.StartMoving)
329 anchor:SetScript("OnDragStop", anchor.StopMovingOrSizing) 332 anchor:SetScript("OnDragStop", anchor.StopMovingOrSizing)
330 anchor:ClearAllPoints() 333 anchor:ClearAllPoints()
331 anchor:SetPoint("CENTER", UIParent, "CENTER", 0, 0) 334 anchor:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
332 anchor:Hide() 335 anchor:Hide()
333 336
334 local frame = CreateFrame("FRAME", "KBFBuffFrame", anchor, "SecureAuraHeaderTemplate") 337 local frame = CreateFrame("FRAME", "KBFBuffFrame", UIParent, "SecureAuraHeaderTemplate")
335 --local frame = anchor 338 --local frame = anchor
336 frame:SetAttribute("filter", "HELPFUL") 339 frame:SetAttribute("filter", "HELPFUL")
337 frame:SetAttribute("template", "KBFSecureUnitAuraTemplate") 340 frame:SetAttribute("template", "KBFSecureUnitAuraTemplate")
338 frame:SetAttribute("point", "TOP") 341 frame:SetAttribute("point", "TOP")
339 frame:SetAttribute("wrapAfter", 100) -- required due to bugs in secure header 342 frame:SetAttribute("wrapAfter", 100) -- required due to bugs in secure header
346 frame:SetAttribute("sortMethod", "NAME") 349 frame:SetAttribute("sortMethod", "NAME")
347 frame:SetAttribute("sortOrder", "-") 350 frame:SetAttribute("sortOrder", "-")
348 -- TODO: SecureAuraHeader doesn't correcltly implement the temp enchants 351 -- TODO: SecureAuraHeader doesn't correcltly implement the temp enchants
349 frame:SetAttribute("weaponTemplate", "KBFSecureUnitAuraTemplate") 352 frame:SetAttribute("weaponTemplate", "KBFSecureUnitAuraTemplate")
350 frame:SetAttribute("includeWeapons", 1) 353 frame:SetAttribute("includeWeapons", 1)
351 frame:SetPoint("TOP", anchor, "BOTTOM", 0, 0) 354 frame:SetPoint("TOP", anchor, "TOP", 0, 0)
352 frame:Show() -- has to be shown, otherwise the child frames don't show 355 frame:Show() -- has to be shown, otherwise the child frames don't show
353 self.secureFrame = frame 356 self.secureFrame = frame
354 return anchor 357 return anchor
355 end 358 end
359
360 function kbf:ShowAnchor()
361 self.secureFrame:ClearAllPoints()
362 self.secureFrame:SetPoint("TOP", self.anchor, "BOTTOM", 0, 0)
363 self.anchor:Show()
364 end
365
366 function kbf:HideAnchor()
367 self.secureFrame:ClearAllPoints()
368 self.secureFrame:SetPoint("TOP", self.anchor, "TOP", 0, 0)
369 self.anchor:Hide()
370 end
371
372 function kbf:ToggleAnchor()
373 if self.anchor:IsShown() then
374 self:HideAnchor()
375 else
376 self:ShowAnchor()
377 end
378 end