arkanes@0
|
1 local _, kbf = ...
|
arkanes@0
|
2
|
arkanes@0
|
3 KBF = kbf -- make global for debugging
|
arkanes@0
|
4
|
arkanes@0
|
5 local kbf = LibStub("AceAddon-3.0"):NewAddon(kbf, "KBF", "AceEvent-3.0", "AceConsole-3.0")
|
arkanes@0
|
6
|
arkanes@0
|
7
|
arkanes@0
|
8 function kbf:OnInitialize()
|
arkanes@0
|
9 self.options = {
|
arkanes@0
|
10 barWidth = 200 + 16 + 8,
|
arkanes@0
|
11 barHeight = 16 + 8
|
arkanes@0
|
12 }
|
arkanes@0
|
13 self.anchor = self:CreateAnchorFrame()
|
arkanes@2
|
14 self.buffBars = {}
|
arkanes@0
|
15 self.anchor:Show()
|
arkanes@0
|
16 self:RegisterEvent("UNIT_AURA")
|
arkanes@0
|
17 end
|
arkanes@1
|
18 -- naming convention
|
arkanes@1
|
19 -- "frame" is the secure aura button created by the group handler
|
arkanes@1
|
20 -- "bar" is the set of icon + status bars that we create to show the buff time
|
arkanes@0
|
21
|
arkanes@0
|
22 function kbf:UNIT_AURA(event, unit)
|
arkanes@2
|
23 if unit ~= self.secureFrame:GetAttribute("unit") then return end
|
arkanes@2
|
24 for idx=1,99 do
|
arkanes@0
|
25 local frame = self.secureFrame:GetAttribute("child"..idx)
|
arkanes@0
|
26 if not frame then break end
|
arkanes@2
|
27 self:BindBarToBuff(idx, frame, unit, "HELPFUL")
|
arkanes@0
|
28 end
|
arkanes@0
|
29 end
|
arkanes@0
|
30
|
arkanes@2
|
31 function kbf:BindBarToBuff(idx, parentFrame, unit, filter)
|
arkanes@0
|
32 local name, rank, icon, count, debuffType, duration, expirationTime,
|
arkanes@2
|
33 unitCaster, isStealable, shouldConsolidate, spellId = UnitAura(unit, idx, "HELPFUL")
|
arkanes@2
|
34 -- This shouldn't be neccesary as the bar is parented to the frame, which is
|
arkanes@2
|
35 -- hidden by the group handler
|
arkanes@2
|
36 if not parentFrame.icon then
|
arkanes@2
|
37 self:ConstructBar(parentFrame)
|
arkanes@0
|
38 end
|
arkanes@2
|
39 parentFrame.icon:SetNormalTexture(icon)
|
arkanes@0
|
40 if stacks and stacks > 0 then
|
arkanes@2
|
41 parentFrame.text:SetText(string.format("%s(%d)", name, stacks))
|
arkanes@0
|
42 else
|
arkanes@2
|
43 parentFrame.text:SetText(name)
|
arkanes@0
|
44 end
|
arkanes@0
|
45 end
|
arkanes@0
|
46
|
arkanes@1
|
47 -- creates a icon + statusbar bar
|
arkanes@1
|
48 function kbf:ConstructBar(frame)
|
arkanes@0
|
49 local texture = "Interface\\TargetingFrame\\UI-StatusBar"
|
arkanes@1
|
50 -- Because of secureframe suckiness, these height & width numbers
|
arkanes@1
|
51 -- have to be consistent with the stuff in KBF.xml
|
arkanes@0
|
52 local height = 16
|
arkanes@1
|
53 local width = 200 -- this is the width *without* the icon
|
arkanes@0
|
54 local font, _ style = GameFontHighlight:GetFont()
|
arkanes@0
|
55 local bgcolor = {1, 0, 0, 0.5}
|
arkanes@0
|
56 local color = {0, 1, 0, 1}
|
arkanes@0
|
57 local fontsize = 11
|
arkanes@0
|
58 local timertextwidth = fontsize * 3.6
|
arkanes@0
|
59 local textcolor = {1, 1, 1, 1}
|
arkanes@0
|
60 local timertextcolor = {1, 1, 1, 1}
|
arkanes@1
|
61 --local bar = CreateFrame("Button", nil, UIParent) -- the "top level" frame that represents the bar as a whole
|
arkanes@1
|
62 local bar = frame
|
arkanes@0
|
63 bar.icon = CreateFrame("Button", nil, bar) -- the icon
|
arkanes@0
|
64 bar.statusbarbg = CreateFrame("StatusBar", nil, bar) -- the bars background
|
arkanes@0
|
65 bar.statusbar = CreateFrame("StatusBar", nil, bar) -- and the bars foreground
|
arkanes@0
|
66 bar.text = bar.statusbar:CreateFontString(nil, "OVERLAY") -- the label text
|
arkanes@0
|
67 bar.timertext = bar.statusbar:CreateFontString(nil, "OVERLAY") -- and the timer text
|
arkanes@0
|
68
|
arkanes@0
|
69 -- the icon
|
arkanes@0
|
70 bar.icon:ClearAllPoints()
|
arkanes@0
|
71 bar.icon:SetPoint("LEFT", bar, "LEFT", 0, 0)
|
arkanes@0
|
72 -- icons are square
|
arkanes@0
|
73 bar.icon:SetWidth(height)
|
arkanes@0
|
74 bar.icon:SetHeight(height)
|
arkanes@2
|
75 --bar.icon:EnableMouse(false)
|
arkanes@0
|
76 -- the status bar background & foreground
|
arkanes@0
|
77 local function setupStatusBar(sb, color)
|
arkanes@0
|
78 sb:ClearAllPoints()
|
arkanes@0
|
79 sb:SetHeight(height)
|
arkanes@0
|
80 sb:SetWidth(width)
|
arkanes@0
|
81 -- offset the height of the frame on the x-axis for the icon.
|
arkanes@0
|
82 sb:SetPoint("TOPLEFT", bar, "TOPLEFT", height, 0)
|
arkanes@0
|
83 sb:SetStatusBarTexture(texture)
|
arkanes@0
|
84 sb:GetStatusBarTexture():SetVertTile(false)
|
arkanes@0
|
85 sb:GetStatusBarTexture():SetHorizTile(false)
|
arkanes@0
|
86 sb:SetStatusBarColor(unpack(color))
|
arkanes@0
|
87 sb:SetMinMaxValues(0,1)
|
arkanes@0
|
88 sb:SetValue(1)
|
arkanes@0
|
89 end
|
arkanes@0
|
90 setupStatusBar(bar.statusbarbg, bgcolor)
|
arkanes@0
|
91 setupStatusBar(bar.statusbar, color)
|
arkanes@0
|
92 bar.statusbarbg:SetFrameLevel(bar.statusbarbg:GetFrameLevel()-1) -- make sure the bg frame stays in the back
|
arkanes@0
|
93 -- timer text
|
arkanes@0
|
94 bar.timertext:SetFontObject(GameFontHighlight)
|
arkanes@0
|
95 bar.timertext:SetFont(GameFontHighlight:GetFont())
|
arkanes@0
|
96 bar.timertext:SetHeight(height)
|
arkanes@0
|
97 bar.timertext:SetWidth(timertextwidth)
|
arkanes@0
|
98 bar.timertext:SetPoint("LEFT", bar.statusbar, "LEFT", 0, 0)
|
arkanes@0
|
99 bar.timertext:SetJustifyH("RIGHT")
|
arkanes@0
|
100 bar.timertext:SetText("time")
|
arkanes@0
|
101 bar.timertext:SetTextColor(timertextcolor[1], timertextcolor[2], timertextcolor[3], timertextcolor[4])
|
arkanes@0
|
102
|
arkanes@0
|
103 -- and the label text
|
arkanes@0
|
104 bar.text:SetFontObject(GameFontHighlight)
|
arkanes@0
|
105 bar.text:SetFont(GameFontHighlight:GetFont())
|
arkanes@0
|
106 bar.text:SetHeight(height)
|
arkanes@0
|
107 bar.text:SetWidth((width - timertextwidth) *.9)
|
arkanes@0
|
108 bar.text:SetPoint("RIGHT", bar.statusbar, "RIGHT", 0, 0)
|
arkanes@0
|
109 bar.text:SetJustifyH("LEFT")
|
arkanes@0
|
110 bar.text:SetText("text")
|
arkanes@0
|
111 bar.text:SetTextColor(textcolor[1], textcolor[2], textcolor[3], textcolor[4])
|
arkanes@0
|
112
|
arkanes@0
|
113 bar:EnableMouse(true)
|
arkanes@0
|
114 return bar
|
arkanes@0
|
115 end
|
arkanes@0
|
116
|
arkanes@0
|
117 function kbf:CreateAnchorFrame()
|
arkanes@0
|
118 -- give it a name so it'll remember its position
|
arkanes@0
|
119 local anchor = CreateFrame("FRAME", "KBFAnchorFrame", UIParent)
|
arkanes@0
|
120 anchor:SetClampedToScreen(true)
|
arkanes@0
|
121 anchor:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background",
|
arkanes@0
|
122 edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
|
arkanes@0
|
123 tile = true, tileSize = 16, edgeSize = 16,
|
arkanes@0
|
124 insets = { left = 4, right = 4, top = 4, bottom = 4 },
|
arkanes@0
|
125 })
|
arkanes@0
|
126 local text = anchor:CreateFontString(nil, "OVERLAY") -- the label text
|
arkanes@0
|
127 text:SetFontObject(GameFontHighlight)
|
arkanes@0
|
128 text:SetFont(GameFontHighlight:GetFont())
|
arkanes@0
|
129 text:SetPoint("TOPLEFT", anchor, "TOPLEFT", 0, 0)
|
arkanes@0
|
130 text:SetPoint("BOTTOMRIGHT", anchor, "BOTTOMRIGHT", 0, 0)
|
arkanes@0
|
131 text:SetText("KBF ANCHOR")
|
arkanes@0
|
132 anchor:SetWidth(self.options.barWidth)
|
arkanes@0
|
133 anchor:SetHeight(self.options.barHeight)
|
arkanes@0
|
134 -- movability
|
arkanes@0
|
135 anchor:EnableMouse(true)
|
arkanes@0
|
136 anchor:SetMovable(true)
|
arkanes@0
|
137 anchor:RegisterForDrag("LeftButton")
|
arkanes@0
|
138 anchor:SetScript("OnDragStart", anchor.StartMoving)
|
arkanes@0
|
139 anchor:SetScript("OnDragStop", anchor.StopMovingOrSizing)
|
arkanes@0
|
140 anchor:ClearAllPoints()
|
arkanes@0
|
141 anchor:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
|
arkanes@0
|
142 anchor:Hide()
|
arkanes@0
|
143
|
arkanes@0
|
144 local frame = CreateFrame("FRAME", "KBFBuffFrame", anchor, "SecureAuraHeaderTemplate")
|
arkanes@0
|
145 --local frame = anchor
|
arkanes@0
|
146 frame:SetAttribute("filter", "HELPFUL")
|
arkanes@0
|
147 frame:SetAttribute("template", "KBFSecureUnitAuraTemplate")
|
arkanes@0
|
148 frame:SetAttribute("point", "CENTER")
|
arkanes@0
|
149 frame:SetAttribute("wrapAfter", 100) -- required due to bugs in secure header
|
arkanes@0
|
150 frame:SetAttribute("consolidateTo", nil)
|
arkanes@0
|
151 --frame:SetAttribute("wrapXOffset", 0)
|
arkanes@0
|
152 --frame:SetAttribute("wrapYOffset", -34)
|
arkanes@2
|
153 frame:SetAttribute("xOffset", 0)
|
arkanes@2
|
154 frame:SetAttribute("yOffset", 16)
|
arkanes@0
|
155 frame:SetAttribute("minWidth", 32)
|
arkanes@0
|
156 frame:SetAttribute("minHeight", 32)
|
arkanes@2
|
157 frame:SetAttribute("unit", "player") -- TODO: figure out the vehicle swapping stuff
|
arkanes@0
|
158 frame:SetPoint("BOTTOM", anchor, "TOP", 0, 0)
|
arkanes@0
|
159 frame:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background",
|
arkanes@0
|
160 edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
|
arkanes@0
|
161 tile = true, tileSize = 16, edgeSize = 16,
|
arkanes@0
|
162 insets = { left = 4, right = 4, top = 4, bottom = 4 },
|
arkanes@0
|
163 })
|
arkanes@0
|
164 frame:Show()
|
arkanes@0
|
165 self.secureFrame = frame
|
arkanes@0
|
166 return anchor
|
arkanes@0
|
167 end
|