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