diff KBF.lua @ 0:1516559044e3

initial commit for hg
author Chris Mellon <arkanes@gmai.com>
date Tue, 12 Oct 2010 06:00:39 -0500
parents
children 3d4128c79074
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/KBF.lua	Tue Oct 12 06:00:39 2010 -0500
@@ -0,0 +1,201 @@
+local _, kbf = ...
+
+KBF = kbf -- make global for debugging
+
+local kbf = LibStub("AceAddon-3.0"):NewAddon(kbf, "KBF", "AceEvent-3.0", "AceConsole-3.0")
+
+
+function kbf:OnInitialize()
+    self.options = {
+        barWidth = 200 + 16 + 8,
+        barHeight = 16 + 8
+    }
+    self.anchor = self:CreateAnchorFrame()
+    self.buffFrames = {}
+-- for idx=1,40 do
+--     self:ConstructBuffFrame(idx)
+-- end
+    self.anchor:Show()
+    self:RegisterEvent("UNIT_AURA")
+    self.unit = "player" -- TODO: Vehicle support
+end
+
+function kbf:UNIT_AURA(event, unit)
+    if unit ~= self.unit then return end 
+    for idx=1,9 do
+        local frame = self:BindFrameToBuff(idx)
+        if not frame then break end
+    end
+    
+    for idx=1,9 do
+        self:Print("SecureScanning", idx)
+        local frame = self.secureFrame:GetAttribute("child"..idx)
+        if not frame then break end
+        self:Print(frame:GetObjectType())
+        local name, rank, icon, count, debuffType, duration, expirationTime, 
+            unitCaster, isStealable, shouldConsolidate, spellId = UnitAura(self.unit, idx, "HELPFUL")
+        frame:SetNormalTexture(icon)
+    end
+end
+
+function kbf:BindFrameToBuff(idx)
+    local name, rank, icon, count, debuffType, duration, expirationTime, 
+        unitCaster, isStealable, shouldConsolidate, spellId = UnitAura(self.unit, idx, "HELPFUL")
+    if not name then
+        if self.buffFrames[idx] then
+            self.buffFrames[idx]:Hide()
+        end
+        return nil
+    end
+    local frame = self.buffFrames[idx] or self:ConstructBuffFrame(idx)
+    frame.icon:SetNormalTexture(icon)
+    if stacks and stacks > 0 then
+        frame.text:SetText(string.format("%s(%d)", name, stacks))
+    else
+        frame.text:SetText(name)
+    end
+    frame:Show()
+    return frame
+end
+
+function kbf:ConstructBuffFrame(idx)
+    local frame = self:ConstructFrame()
+    frame:RegisterForClicks("RightButtonUp")
+    frame:SetAttribute("type*", "cancelaura" )
+    frame:SetAttribute("unit", "player")
+    frame:SetAttribute("index", idx)
+    -- position
+    local parent = self.buffFrames[idx-1] or self.anchor
+    frame:SetPoint("TOP", parent, "BOTTOM", 0, 0)
+    self.buffFrames[idx] = frame
+    return frame
+end
+
+function kbf:ConstructFrame()
+    local texture = "Interface\\TargetingFrame\\UI-StatusBar"
+    local height = 16
+    local font, _ style = GameFontHighlight:GetFont()
+    local width = 200 -- this is the width *without* the icon
+    local bgcolor = {1, 0, 0, 0.5}
+    local color = {0, 1, 0, 1}
+    local fontsize = 11
+    local timertextwidth = fontsize * 3.6
+    local textcolor = {1, 1, 1, 1}
+    local timertextcolor = {1, 1, 1, 1}
+    local bar = CreateFrame("Button", nil, UIParent, "SecureActionButtonTemplate") -- the "top level" frame that represents the bar as a whole
+    bar.icon = CreateFrame("Button", nil, bar) -- the icon
+    bar.statusbarbg = CreateFrame("StatusBar", nil, bar) -- the bars background
+    bar.statusbar = CreateFrame("StatusBar", nil, bar) -- and the bars foreground
+    --bar.spark = bar.statusbar:CreateTexture(nil, "OVERLAY") -- the spark
+    bar.text = bar.statusbar:CreateFontString(nil, "OVERLAY") -- the label text
+    bar.timertext = bar.statusbar:CreateFontString(nil, "OVERLAY") -- and the timer text
+    -- the bar as a whole
+    bar:SetHeight(height)
+    bar:SetWidth(height + width)
+
+    -- the icon
+    bar.icon:ClearAllPoints()
+    bar.icon:SetPoint("LEFT", bar, "LEFT", 0, 0)
+    -- icons are square
+    bar.icon:SetWidth(height)
+    bar.icon:SetHeight(height)
+    bar.icon:EnableMouse(false)
+    -- the status bar background & foreground
+    local function setupStatusBar(sb, color)
+        sb:ClearAllPoints()
+        sb:SetHeight(height)
+        sb:SetWidth(width)
+        -- offset the height of the frame on the x-axis for the icon.
+        sb:SetPoint("TOPLEFT", bar, "TOPLEFT", height, 0)
+        sb:SetStatusBarTexture(texture)
+        sb:GetStatusBarTexture():SetVertTile(false)
+        sb:GetStatusBarTexture():SetHorizTile(false)
+        sb:SetStatusBarColor(unpack(color))
+        sb:SetMinMaxValues(0,1)
+        sb:SetValue(1)
+    end
+    setupStatusBar(bar.statusbarbg, bgcolor)
+    setupStatusBar(bar.statusbar, color)
+    bar.statusbarbg:SetFrameLevel(bar.statusbarbg:GetFrameLevel()-1) -- make sure the bg frame stays in the back
+    -- timer text
+    bar.timertext:SetFontObject(GameFontHighlight)
+    bar.timertext:SetFont(GameFontHighlight:GetFont())
+    bar.timertext:SetHeight(height)
+    bar.timertext:SetWidth(timertextwidth)
+    bar.timertext:SetPoint("LEFT", bar.statusbar, "LEFT", 0, 0)
+    bar.timertext:SetJustifyH("RIGHT")
+    bar.timertext:SetText("time")
+    bar.timertext:SetTextColor(timertextcolor[1], timertextcolor[2], timertextcolor[3], timertextcolor[4])
+
+    -- and the label text
+    bar.text:SetFontObject(GameFontHighlight)
+    bar.text:SetFont(GameFontHighlight:GetFont())
+    bar.text:SetHeight(height)
+    bar.text:SetWidth((width - timertextwidth) *.9)
+    bar.text:SetPoint("RIGHT", bar.statusbar, "RIGHT", 0, 0)
+    bar.text:SetJustifyH("LEFT")
+    bar.text:SetText("text")
+    bar.text:SetTextColor(textcolor[1], textcolor[2], textcolor[3], textcolor[4])
+    -- the status bar foreground
+    -- the spark
+    --bar.spark:SetTexture("Interface\\CastingBar\\UI-CastingBar-Spark")
+    --bar.spark:SetWidth(16)
+    --bar.spark:SetHeight(height + 25)
+    --bar.spark:SetBlendMode("ADD")
+
+    --bar:SetAlpha(0.7)
+    bar:EnableMouse(true)
+    return bar
+end
+
+function kbf:CreateAnchorFrame()
+    -- give it a name so it'll remember its position
+    local anchor = CreateFrame("FRAME", "KBFAnchorFrame", UIParent)
+    anchor:SetClampedToScreen(true)
+    anchor:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background", 
+                         edgeFile = "Interface/Tooltips/UI-Tooltip-Border", 
+                         tile = true, tileSize = 16, edgeSize = 16,
+                         insets = { left = 4, right = 4, top = 4, bottom = 4 },
+                         })
+    local text = anchor:CreateFontString(nil, "OVERLAY") -- the label text
+    text:SetFontObject(GameFontHighlight)
+    text:SetFont(GameFontHighlight:GetFont())
+    text:SetPoint("TOPLEFT", anchor, "TOPLEFT", 0, 0)
+    text:SetPoint("BOTTOMRIGHT", anchor, "BOTTOMRIGHT", 0, 0)
+    text:SetText("KBF ANCHOR")
+    anchor:SetWidth(self.options.barWidth)
+    anchor:SetHeight(self.options.barHeight)
+    -- movability
+    anchor:EnableMouse(true)
+    anchor:SetMovable(true)
+    anchor:RegisterForDrag("LeftButton")
+    anchor:SetScript("OnDragStart", anchor.StartMoving)
+    anchor:SetScript("OnDragStop",  anchor.StopMovingOrSizing)
+    anchor:ClearAllPoints()
+    anchor:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
+    anchor:Hide()
+    
+    local frame = CreateFrame("FRAME", "KBFBuffFrame", anchor, "SecureAuraHeaderTemplate")
+    --local frame = anchor
+    frame:SetAttribute("filter", "HELPFUL")
+    frame:SetAttribute("template", "KBFSecureUnitAuraTemplate")
+    frame:SetAttribute("point", "CENTER")
+    frame:SetAttribute("wrapAfter", 100) -- required due to bugs in secure header
+    frame:SetAttribute("consolidateTo", nil)
+    --frame:SetAttribute("wrapXOffset", 0)
+    --frame:SetAttribute("wrapYOffset", -34)
+    frame:SetAttribute("xOffset", 32)
+    frame:SetAttribute("yOffset", 0)
+    frame:SetAttribute("minWidth", 32)
+    frame:SetAttribute("minHeight", 32)
+    frame:SetAttribute("unit", "player")
+    frame:SetPoint("BOTTOM", anchor, "TOP", 0, 0)
+    frame:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background", 
+                         edgeFile = "Interface/Tooltips/UI-Tooltip-Border", 
+                         tile = true, tileSize = 16, edgeSize = 16,
+                         insets = { left = 4, right = 4, top = 4, bottom = 4 },
+                         })
+    frame:Show()
+    self.secureFrame = frame
+    return anchor
+end