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