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