Mercurial > wow > reaction
comparison classes/ReAction_ActionDisplay.lua @ 7:f920db5fc6b1
version 0.3
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Tue, 20 Mar 2007 21:25:29 +0000 |
parents | |
children | c05fd3e18b4f |
comparison
equal
deleted
inserted
replaced
6:2da5089ab7ff | 7:f920db5fc6b1 |
---|---|
1 -- The ReAction.ActionDisplay mixin defines 'regular' action button display functionality | |
2 -- and is an implementation of the ReAction.IDisplay and ReAction.ActionType.IDisplay interfaces. | |
3 -- | |
4 -- This Mixin assumes that it has been mixed in with a ReAction-derived class which implements | |
5 -- the ReAction.IActionType and ReAction.IColorScheme interfaces. | |
6 -- | |
7 -- This mixin uses properties of self.config to define display elements: | |
8 -- | |
9 -- self.config = { | |
10 -- keyBindLoc = "POSITION", -- keybind anchor location | |
11 -- stackCountLoc = "POSITION", -- stack count anchor location | |
12 -- showKeyBind = true/false, -- show keybind labels | |
13 -- showStackCount = true/false, -- show stack count labels | |
14 -- showMacroText = true/false, -- show macro name labels | |
15 -- showGrid = true/false, -- always show empty buttons | |
16 -- } | |
17 -- | |
18 | |
19 local AceOO = AceLibrary("AceOO-2.0") | |
20 | |
21 ReAction.ActionDisplay = AceOO.Mixin { | |
22 -- ReAction.IDisplay interface | |
23 "SetupDisplay", | |
24 "UpdateDisplay", | |
25 "TempShow", | |
26 "GetActionFrame", | |
27 "GetBaseButtonSize", | |
28 "DisplayID", | |
29 "DisplayHotkey", | |
30 | |
31 -- ReAction.ActionType.IDisplay interface | |
32 "DisplayUsable", | |
33 "DisplayEquipped", | |
34 "DisplayAutoRepeat", | |
35 "DisplayInUse", | |
36 "DisplayIcon", | |
37 "DisplayName", | |
38 "DisplayCount", | |
39 "DisplayCooldown", | |
40 | |
41 -- Event handlers | |
42 "PostClick", | |
43 "OnDragStart", | |
44 "OnReceiveDrag", | |
45 "OnEnter", | |
46 "OnLeave", | |
47 "OnUpdate", | |
48 | |
49 -- internal functions | |
50 "ApplyLayout", | |
51 "ApplyStyle", | |
52 "StartFlash", | |
53 "StopFlash", | |
54 "IsFlashing", | |
55 "DisplayVisibility", | |
56 } | |
57 | |
58 local RAAD = ReAction.ActionDisplay | |
59 | |
60 | |
61 -- private constants | |
62 local _G = getfenv(0) | |
63 | |
64 local equippedActionBorderColor = { r=0.00, g=1.00, b=0.00, a=0.35 } -- transparent green | |
65 local actionIDColor = { r=1.00, g=0.82, b=0.00, a=1.00 } -- gold | |
66 | |
67 -- private functions | |
68 -- extract and return color fields from a table, to be fed into SetVertexColor()/SetTextColor() | |
69 local function tcolor(c) | |
70 return c.r, c.g, c.b, c.a | |
71 end | |
72 | |
73 | |
74 ----------------------------------- | |
75 -- Interface Implementation Methods | |
76 ----------------------------------- | |
77 function RAAD:SetupDisplay( name ) | |
78 -- create the button widget | |
79 local b = CreateFrame("CheckButton", name, nil, "SecureActionButtonTemplate, ActionButtonTemplate") | |
80 | |
81 -- store references to the various sub-frames of ActionButtonTemplate so we don't have to look it up all the time | |
82 self.frames = { | |
83 button = b, | |
84 hotkey = _G[name.."HotKey"], | |
85 count = _G[name.."Count"], | |
86 cooldown = _G[name.."Cooldown"], | |
87 macro = _G[name.."Name"], | |
88 icon = _G[name.."Icon"], | |
89 border = _G[name.."Border"], | |
90 flash = _G[name.."Flash"], | |
91 normalTexture = _G[name.."NormalTexture"], | |
92 actionID = nil, -- defer creating actionID font string until it's actually requested | |
93 } | |
94 | |
95 -- ??? odd: why do we have to increment the cooldown frame level to get it to show? | |
96 -- (otherwise it's behind the icon). The default UI doesn't have to (or at least I can't | |
97 -- find where it does) but for some reason we have to here. | |
98 self.frames.cooldown:SetFrameLevel(self.frames.cooldown:GetFrameLevel() + 1) | |
99 | |
100 b:EnableMouse() | |
101 b:RegisterForDrag("LeftButton", "RightButton") | |
102 b:RegisterForClicks("AnyUp") | |
103 b:SetScript("PostClick", function(arg1) self:PostClick(arg1) end) | |
104 b:SetScript("OnDragStart", function(arg1) self:OnDragStart(arg1) end) | |
105 b:SetScript("OnReceiveDrag", function() self:OnReceiveDrag() end) | |
106 b:SetScript("OnEnter", function() self:OnEnter() end) | |
107 b:SetScript("OnLeave", function() self:OnLeave() end) | |
108 -- defer setting OnUpdate until actions are actually attached | |
109 | |
110 self.tmpShow_ = 0 | |
111 end | |
112 | |
113 function RAAD:UpdateDisplay() | |
114 self:ApplyLayout() | |
115 self:ApplyStyle() | |
116 self:DisplayVisibility() | |
117 -- refresh the action ID display | |
118 if ReAction.showIDs_ then | |
119 self:DisplayID(self:GetID()) | |
120 end | |
121 end | |
122 | |
123 function RAAD:TempShow( visible ) | |
124 visible = visible and true or false -- force data integrity | |
125 self.showTmp_ = max(0, (self.showTmp_ or 0) + (visible and 1 or -1)) | |
126 self:DisplayVisibility() | |
127 end | |
128 | |
129 function RAAD:GetActionFrame() | |
130 return self.frames.button | |
131 end | |
132 | |
133 function RAAD:GetBaseButtonSize() | |
134 return 36 | |
135 end | |
136 | |
137 function RAAD:DisplayID( id ) | |
138 local f = self.frames.actionID | |
139 if id then | |
140 if not f then | |
141 -- create the actionID label | |
142 f = self.frames.button:CreateFontString(nil,"ARTWORK","NumberFontNormalSmall") | |
143 f:SetPoint("BOTTOMLEFT") | |
144 f:SetTextColor( tcolor(actionIDColor) ) | |
145 self.frames.actionID = f | |
146 end | |
147 f:SetText(tostring(id)) | |
148 f:Show() | |
149 elseif f then | |
150 f:Hide() | |
151 end | |
152 end | |
153 | |
154 function RAAD:DisplayHotkey(txt) | |
155 self.frames.hotkey:SetText(string.upper(txt or "")) | |
156 self:UpdateUsable() | |
157 end | |
158 | |
159 function RAAD:DisplayUsable( isUsable, notEnoughMana, outOfRange ) | |
160 local f = self.frames | |
161 f.icon:SetVertexColor( self:GetIconColor(isUsable, notEnoughMana, outOfRange) ) | |
162 f.button:GetNormalTexture():SetVertexColor( self:GetBorderColor(isUsable, notEnoughMana, outOfRange) ) | |
163 f.hotkey:SetTextColor( self:GetHotkeyColor(isUsable, notEnoughMana, outOfRange, f.hotkey:GetText()) ) | |
164 end | |
165 | |
166 function RAAD:DisplayEquipped( equipped ) | |
167 local b = self.frames.border | |
168 if equipped then | |
169 b:Show() | |
170 else | |
171 b:Hide() | |
172 end | |
173 end | |
174 | |
175 function RAAD:DisplayAutoRepeat( r ) | |
176 if r then | |
177 self:StartFlash() | |
178 else | |
179 self:StopFlash() | |
180 end | |
181 end | |
182 | |
183 function RAAD:DisplayInUse( inUse ) | |
184 self.frames.button:SetChecked( inUse and 1 or 0 ) | |
185 end | |
186 | |
187 function RAAD:DisplayIcon( texture ) | |
188 local f = self.frames.button | |
189 local icon = self.frames.icon | |
190 if texture then | |
191 icon:SetTexture(texture) | |
192 icon:Show() | |
193 self.rangeTimer = -1 | |
194 f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2") | |
195 if f:GetScript("OnUpdate") == nil then | |
196 f:SetScript("OnUpdate", function(frame, elapsed) self:OnUpdate(elapsed) end) | |
197 end | |
198 else | |
199 icon:Hide() | |
200 self.rangeTimer = nil | |
201 f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot") | |
202 f:SetScript("OnUpdate",nil) | |
203 end | |
204 self:DisplayVisibility() | |
205 end | |
206 | |
207 function RAAD:DisplayCooldown( start, duration, enable ) | |
208 CooldownFrame_SetTimer(self.frames.cooldown, start, duration, enable) | |
209 end | |
210 | |
211 function RAAD:DisplayName( name ) | |
212 self.frames.macro:SetText(name and tostring(name) or "") | |
213 end | |
214 | |
215 function RAAD:DisplayCount( count ) | |
216 self.frames.count:SetText(count and tostring(count) or "") | |
217 end | |
218 | |
219 | |
220 | |
221 | |
222 | |
223 ---------------------- | |
224 -- Event Handlers | |
225 ---------------------- | |
226 function RAAD:PostClick() | |
227 self:UpdateInUse() | |
228 end | |
229 | |
230 function RAAD:OnDragStart() | |
231 if LOCK_ACTIONBAR ~= "1" or IsShiftKeyDown() then | |
232 self:PickupAction() | |
233 end | |
234 end | |
235 | |
236 function RAAD:OnReceiveDrag() | |
237 self:PlaceAction() | |
238 end | |
239 | |
240 function RAAD:OnEnter() | |
241 self:SetTooltip() -- from ReAction base class | |
242 self.tooltipTime = TOOLTIP_UPDATE_TIME | |
243 end | |
244 | |
245 function RAAD:OnLeave() | |
246 self:ClearTooltip() -- from ReAction base class | |
247 self.tooltipTime = nil | |
248 end | |
249 | |
250 function RAAD:OnUpdate(elapsed) | |
251 -- handle flashing | |
252 if self:IsFlashing() then | |
253 self.flashtime = self.flashtime - elapsed | |
254 if self.flashtime <= 0 then | |
255 local overtime = -self.flashtime | |
256 if overtime >= ATTACK_BUTTON_FLASH_TIME then | |
257 overtime = 0 | |
258 end | |
259 self.flashtime = ATTACK_BUTTON_FLASH_TIME - overtime | |
260 | |
261 local f = self.frames.flash | |
262 if f then | |
263 if f:IsVisible() then | |
264 f:Hide() | |
265 else | |
266 f:Show() | |
267 end | |
268 end | |
269 end | |
270 end | |
271 | |
272 -- Handle range indicator | |
273 if self.rangeTimer then | |
274 self.rangeTimer = self.rangeTimer - elapsed | |
275 if self.rangeTimer <= 0 then | |
276 self:UpdateUsable() | |
277 self.rangeTimer = TOOLTIP_UPDATE_TIME | |
278 end | |
279 end | |
280 | |
281 -- handle tooltip update | |
282 if self.tooltipTime then | |
283 self.tooltipTime = self.tooltipTime - elapsed | |
284 if self.tooltipTime <= 0 then | |
285 if GameTooltip:IsOwned(self.frames.button) then | |
286 self:UpdateTooltip() | |
287 self.tooltipTime = TOOLTIP_UPDATE_TIME | |
288 else | |
289 self.tooltipTime = nil | |
290 end | |
291 end | |
292 end | |
293 end | |
294 | |
295 | |
296 | |
297 ---------------------- | |
298 -- Internal methods | |
299 ---------------------- | |
300 | |
301 local function placeLabel( label, anchor ) | |
302 local top = string.match(anchor,"TOP") | |
303 local bottom = string.match(anchor, "BOTTOM") | |
304 label:ClearAllPoints() | |
305 label:SetWidth(40) | |
306 label:SetPoint(top or bottom or "CENTER",0,top and 2 or bottom and -2 or 0) | |
307 local j | |
308 if string.match(anchor,"LEFT") then | |
309 j = "LEFT" | |
310 elseif string.match(anchor,"RIGHT") then | |
311 j = "RIGHT" | |
312 else | |
313 j = "CENTER" | |
314 end | |
315 label:SetJustifyH(j) | |
316 end | |
317 | |
318 | |
319 function RAAD:ApplyLayout() | |
320 local f = self.frames | |
321 | |
322 if self.config.keyBindLoc then | |
323 placeLabel(f.hotkey, self.config.keyBindLoc) | |
324 end | |
325 | |
326 if self.config.stackCountLoc then | |
327 placeLabel(f.count, self.config.stackCountLoc) | |
328 end | |
329 | |
330 if self.config.showKeyBind then | |
331 f.hotkey:Show() | |
332 else | |
333 f.hotkey:Hide() | |
334 end | |
335 | |
336 if self.config.showStackCount then | |
337 f.count:Show() | |
338 else | |
339 f.count:Hide() | |
340 end | |
341 | |
342 if self.config.showMacroName then | |
343 f.macro:Show() | |
344 else | |
345 f.macro:Hide() | |
346 end | |
347 | |
348 end | |
349 | |
350 function RAAD:ApplyStyle() | |
351 local f = self.frames | |
352 -- for now, just a static style | |
353 f.hotkey:SetFontObject(NumberFontNormal) | |
354 f.count:SetFontObject(NumberFontNormalYellow) | |
355 f.border:SetVertexColor( tcolor(equippedActionBorderColor) ) | |
356 end | |
357 | |
358 function RAAD:StartFlash() | |
359 self.flashing = true | |
360 self.flashtime = 0 | |
361 end | |
362 | |
363 function RAAD:StopFlash() | |
364 self.flashing = false | |
365 self.frames.flash:Hide() | |
366 end | |
367 | |
368 function RAAD:IsFlashing() | |
369 return self.flashing | |
370 end | |
371 | |
372 function RAAD:DisplayVisibility() | |
373 local b = self.frames.button | |
374 | |
375 if b:GetAttribute("statehidden") then | |
376 -- can't hide/show in combat | |
377 if not InCombatLockdown() then | |
378 b:Hide() | |
379 end | |
380 elseif not self:IsActionEmpty() then | |
381 b:GetNormalTexture():SetAlpha(1.0) | |
382 b:SetAlpha(1) | |
383 elseif self.showTmp_ and self.showTmp_ > 0 or self.config.showGrid then | |
384 b:GetNormalTexture():SetAlpha(0.5) | |
385 self.frames.cooldown:Hide() | |
386 b:SetAlpha(1) | |
387 else | |
388 b:SetAlpha(0) | |
389 end | |
390 end | |
391 |