comparison Button.lua @ 1:c11ca1d8ed91

Version 0.1
author Flick <flickerstreak@gmail.com>
date Tue, 20 Mar 2007 21:03:57 +0000
parents
children 8e0ff8ae4c08
comparison
equal deleted inserted replaced
0:4e2ce2894c21 1:c11ca1d8ed91
1 -- private constants
2 local namePrefix = "ReActionButton_"
3 local _G = getfenv(0)
4 local ACTION_FREE = { }
5 local MAX_ACTIONS = 120
6
7 local hotKeyDefaultColor = { r=1.0, g=1.0, b=1.0, a=1.0 }
8 local hotKeyDisabledColor = { r=0.6, g=0.6, b=0.6, a=1.0 }
9 local hotKeyOutOfRangeColor = { r=1.0, g=0.2, b=0.2, a=1.0 }
10
11 local hotKeyModifierColors = {
12 S = { r=0.6, g=0.6, b=1.0, a=1.0 }, -- shift
13 C = { r=1.0, g=0.82, b=0, a=1.0 }, -- ctrl
14 A = { r=0.1, g=1.0, b=0.1, a=1.0 }, -- alt
15 }
16
17 local equippedActionBorderColor = { r=0, g=1.0, b=0, a=0.35 }
18
19 local actionUsableColor = { r=1.0, g=1.0, b=1.0, a=1.0 }
20 local actionNotUsableColor = { r=0.4, g=0.4, b=0.4, a=1.0 }
21 local actionNotEnoughManaColor = { r=0.2, g=0.2, b=0.7, a=1.0 }
22 local actionOutOfRangeColor = { r=1.0, g=0.2, b=0.2, a=1.0 }
23
24 -- private variables
25 local kbValidate = AceLibrary("AceConsole-2.0").keybindingValidateFunc
26 local actionButtonTbl = { }
27
28
29
30 -- ReActionButton is a class prototype object.
31 ReActionButton = AceLibrary("AceOO-2.0").Class("AceEvent-2.0")
32
33 -------------------
34 -- Class methods
35 -------------------
36
37 -- In addition to supporting the 'new' creation method (in which case an action ID must be specified directly),
38 -- ReActionButton supports the 'acquire'/'release' creation method, which recycles objects and manages actionID assignment.
39
40 function ReActionButton:acquire(parent, config, barIdx)
41 local id = nil
42 for i = 1, MAX_ACTIONS do
43 if actionButtonTbl[i] == nil or actionButtonTbl[i].inUse == false then
44 id = i
45 break
46 end
47 end
48
49 if id == nil then return nil end -- all buttons and action ids are in use
50
51 local hint = config.actionIDs[barIdx]
52 if hint and (actionButtonTbl[hint] == nil or actionButtonTbl[hint].inUse == false) then
53 id = hint
54 end
55
56 if actionButtonTbl[id] == nil then
57 actionButtonTbl[id] = { }
58 end
59 local t = actionButtonTbl[id]
60
61 t.inUse = true
62 if t.button then
63 t.button:Configure(parent,config,barIdx,id)
64 else
65 t.button = self:new(parent,config,barIdx,id)
66 end
67
68 if actionButtonTbl[t.button:GetActionID()].inUse ~= true then
69 end
70
71 return t.button
72 end
73
74 function ReActionButton:release( b )
75 if b then
76 actionButtonTbl[b:GetActionID()].inUse = false
77 b:Recycle()
78 end
79 end
80
81
82
83 function ReActionButton:ShowAllActionIDs()
84 for _, b in ipairs(actionButtonTbl) do
85 b:ShowActionID()
86 end
87 end
88
89 function ReActionButton:HideAllActionIDs()
90 for _, b in ipairs(actionButtonTbl) do
91 b:HideActionID()
92 end
93 end
94
95
96 ----------------------
97 -- Instance methods
98 ----------------------
99 function ReActionButton.prototype:init( parentFrame, config, barIdx, id )
100 ReActionButton.super.prototype.init(self)
101
102 -- create the button widget
103 self.name = namePrefix.."_"..id
104 self.button = CreateFrame("CheckButton", self.name, parentFrame, "ReActionButtonTemplate")
105
106 -- create the actionID label on the control widget
107 local actionIDLabel = self.button:CreateFontString(nil,"ARTWORK", "NumberFontNormalSmall")
108 actionIDLabel:SetPoint("BOTTOMLEFT",0,0)
109 actionIDLabel:Hide()
110
111 -- store references to the various sub-frames so we don't have to look it up all the time
112 self.frames = {
113 hotkey = _G[self.name.."HotKey"],
114 count = _G[self.name.."Count"],
115 cooldown = _G[self.name.."Cooldown"],
116 -- nCooldown = _G[self.name.."CooldownNumeric"],
117 macro = _G[self.name.."Name"],
118 icon = _G[self.name.."Icon"],
119 border = _G[self.name.."Border"],
120 normalTexture = _G[self.name.."NormalTexture"],
121 flash = _G[self.name.."Flash"],
122 actionID = actionIDLabel
123 }
124
125 -- provide a reference back to this object for the frame to use in event handlers
126 self.button.rxnBtn = self
127
128 -- initialize
129 self:Configure(parentFrame, config, barIdx, id)
130 end
131
132 function ReActionButton.prototype:Recycle()
133 local b = self.button
134 local action = self:GetActionID()
135
136 self.config.actionIDs[self.barIdx] = nil
137
138 self:SetKeyBinding(nil)
139 self:UpdateDisplay()
140 b:UnregisterAllEvents()
141 b:Hide()
142 b:ClearAllPoints()
143 b:SetParent(ReActionButtonRecycleFrame)
144 end
145
146
147
148 -- set the button location
149 function ReActionButton.prototype:PlaceButton(point, x, y, sz)
150 local b = self.button
151 local scale = sz / 36
152 b:ClearAllPoints()
153 b:SetScale( scale )
154 b:SetPoint(point,x/scale,y/scale)
155 end
156
157
158 function ReActionButton.prototype:ShowActionID()
159 self.frames.actionID:Show()
160 end
161
162 function ReActionButton.prototype:HideActionID()
163 self.frames.actionID:Hide()
164 end
165
166
167
168 -- configuration and setup
169 function ReActionButton.prototype:Configure( parentFrame, config, barIdx, id )
170 self.config = config
171 self.barIdx = barIdx
172 self.showGrid = config.showGrid and 1 or 0
173
174 self.button:ClearAllPoints()
175 self.button:SetParent(parentFrame)
176
177 self:SetupAttributes()
178 self:RegisterStaticEvents()
179
180 if id then
181 -- set action ID
182 self:SetActionID(id)
183 else
184 self:ApplyActionID()
185 end
186 self:ApplyLayout()
187 self:ApplyStyle()
188
189 self:UpdateDisplay()
190 end
191
192 function ReActionButton.prototype:SetupAttributes()
193 local b = self.button
194 b:SetAttribute("type", "action")
195 b:SetAttribute("shift-type*", ATTRIBUTE_NOOP)
196 b:SetAttribute("alt-type*", ATTRIBUTE_NOOP)
197 b:SetAttribute("checkselfcast", true)
198 b:SetAttribute("useparent-unit", true)
199 end
200
201 function ReActionButton.prototype:RegisterStaticEvents()
202 self:RegisterEvent("PLAYER_ENTERING_WORLD")
203 self:RegisterEvent("ACTIONBAR_SLOT_CHANGED")
204 self:RegisterEvent("UPDATE_BINDINGS")
205 self:RegisterEvent("ACTIONBAR_SHOWGRID")
206 self:RegisterEvent("ACTIONBAR_HIDEGRID")
207 end
208
209 function ReActionButton.prototype:RegisterActionEvents()
210 self:RegisterEvent("ACTIONBAR_UPDATE_STATE")
211 self:RegisterEvent("ACTIONBAR_UPDATE_USABLE")
212 self:RegisterEvent("ACTIONBAR_UPDATE_COOLDOWN", "ACTIONBAR_UPDATE_USABLE")
213 self:RegisterEvent("UPDATE_INVENTORY_ALERTS", "ACTIONBAR_UPDATE_USABLE")
214 self:RegisterEvent("PLAYER_AURAS_CHANGED", "ACTIONBAR_UPDATE_USABLE")
215 self:RegisterEvent("PLAYER_TARGET_CHANGED", "ACTIONBAR_UPDATE_USABLE")
216 self:RegisterEvent("UNIT_INVENTORY_CHANGED")
217 self:RegisterEvent("CRAFT_SHOW")
218 self:RegisterEvent("CRAFT_CLOSE", "CRAFT_SHOW")
219 self:RegisterEvent("TRADE_SKILL_SHOW", "CRAFT_SHOW")
220 self:RegisterEvent("TRADE_SKILL_CLOSE", "CRAFT_SHOW")
221 self:RegisterEvent("PLAYER_ENTER_COMBAT", "CRAFT_SHOW")
222 self:RegisterEvent("PLAYER_LEAVE_COMBAT")
223 self:RegisterEvent("START_AUTOREPEAT_SPELL")
224 self:RegisterEvent("STOP_AUTOREPEAT_SPELL")
225
226 self.button:SetScript("OnUpdate", function() self:OnUpdate(arg1) end)
227 self.actionEventsRegistered = true
228 end
229
230 function ReActionButton.prototype:UnregisterActionEvents()
231 self:UnregisterEvent("ACTIONBAR_UPDATE_STATE")
232 self:UnregisterEvent("ACTIONBAR_UPDATE_USABLE")
233 self:UnregisterEvent("ACTIONBAR_UPDATE_COOLDOWN")
234 self:UnregisterEvent("UPDATE_INVENTORY_ALERTS")
235 self:UnregisterEvent("PLAYER_AURAS_CHANGED")
236 self:UnregisterEvent("PLAYER_TARGET_CHANGED")
237 self:UnregisterEvent("UNIT_INVENTORY_CHANGED")
238 self:UnregisterEvent("CRAFT_SHOW")
239 self:UnregisterEvent("CRAFT_CLOSE")
240 self:UnregisterEvent("TRADE_SKILL_SHOW")
241 self:UnregisterEvent("TRADE_SKILL_CLOSE")
242 self:UnregisterEvent("PLAYER_ENTER_COMBAT")
243 self:UnregisterEvent("PLAYER_LEAVE_COMBAT")
244 self:UnregisterEvent("START_AUTOREPEAT_SPELL")
245 self:UnregisterEvent("STOP_AUTOREPEAT_SPELL")
246
247 self.button:SetScript("OnUpdate", nil)
248 self.actionEventsRegistered = false
249 end
250
251
252 -- event handlers
253 function ReActionButton.prototype:ACTIONBAR_SLOT_CHANGED()
254 if arg1 == 0 or arg1 == self:GetActionID() then
255 self:UpdateDisplay()
256 end
257 end
258
259 function ReActionButton.prototype:PLAYER_ENTERING_WORLD()
260 self:UpdateDisplay()
261 end
262
263 function ReActionButton.prototype:UPDATE_BINDINGS()
264 self:UpdateDisplay()
265 end
266
267 function ReActionButton.prototype:ACTIONBAR_SHOWGRID()
268 self:ShowGridTmp()
269 end
270
271 function ReActionButton.prototype:ACTIONBAR_HIDEGRID()
272 self:HideGridTmp()
273 end
274
275 function ReActionButton.prototype:ACTIONBAR_UPDATE_STATE()
276 self:UpdateCheckedState()
277 end
278
279 function ReActionButton.prototype:ACTIONBAR_UPDATE_USABLE()
280 self:UpdateUsable()
281 self:UpdateCooldown()
282 self:ColorHotKey()
283 end
284
285 function ReActionButton.prototype:UNIT_INVENTORY_CHANGED()
286 if arg1 == "player" then
287 self:UpdateDisplay()
288 end
289 end
290
291 function ReActionButton.prototype:CRAFT_SHOW()
292 self:UpdateCheckedState()
293 end
294
295 function ReActionButton.prototype:PLAYER_ENTER_COMBAT()
296 if IsAttackAction(self:GetActionID()) then
297 self:StartFlash()
298 end
299 end
300
301 function ReActionButton.prototype:PLAYER_LEAVE_COMBAT()
302 if IsAttackAction(self:GetActionID()) then
303 self:StopFlash()
304 end
305 end
306
307 function ReActionButton.prototype:START_AUTOREPEAT_SPELL()
308 if IsAutoRepeatAction(self:GetActionID()) then
309 self:StartFlash()
310 end
311 end
312
313 function ReActionButton.prototype:STOP_AUTOREPEAT_SPELL()
314 if self:IsFlashing() and not IsAttackAction(self:GetActionID()) then
315 self:StopFlash()
316 end
317 end
318
319
320 -- OnUpdate handler
321 function ReActionButton.prototype:OnUpdate(elapsed)
322 local action = self:GetActionID()
323 local f = self.frames
324
325 -- handle flashing
326 if self:IsFlashing() then
327 self.flashtime = self.flashtime - elapsed
328 if self.flashtime <= 0 then
329 local overtime = -self.flashtime
330 if overtime >= ATTACK_BUTTON_FLASH_TIME then
331 overtime = 0
332 end
333 self.flashtime = ATTACK_BUTTON_FLASH_TIME - overtime
334
335 if f.flash:IsVisible() then
336 f.flash:Hide()
337 else
338 f.flash:Show()
339 end
340 end
341 end
342
343 -- Handle range indicator
344 if self.rangeTimer then
345 self.rangeTimer = self.rangeTimer - elapsed
346 if self.rangeTimer <= 0 then
347 self:ColorHotKey()
348 self:UpdateUsable()
349 self.rangeTimer = TOOLTIP_UPDATE_TIME
350 end
351 end
352
353 -- handle toltip update
354 if self.tooltipTime then
355 self.tooltipTime = self.tooltipTime - elapsed
356 if self.tooltipTime <= 0 then
357 if GameTooltip:IsOwned(self.button) then
358 self:UpdateTooltip()
359 else
360 self.tooltipTime = nil
361 end
362 end
363 end
364 end
365
366
367
368
369 -- keybinding functions
370 function ReActionButton.prototype:SetKeyBinding( k )
371 if k == nil or kbValidate(k) then
372 local current = self:GetKeyBinding()
373 ClearOverrideBindings(self.button)
374 if current then
375 SetBinding(current,nil)
376 end
377 if k then
378 SetBindingClick(k, self.name, "LeftButton")
379 end
380 end
381 end
382
383 function ReActionButton.prototype:GetKeyBinding()
384 return GetBindingKey("CLICK "..self.name..":LeftButton")
385 end
386
387 function ReActionButton.prototype:ShowAssignKeybinding()
388 local f = ReActionKeybindFrame
389 f:ClearAllPoints()
390 f:SetPoint("BOTTOM", self.button, "TOP", 0, 10)
391 ReActionKeybindFrameButton.keybindTarget = self
392 local k = self:GetKeyBinding()
393 if k then
394 local txt = GetBindingText(k, "KEY_")
395 ReActionKeybindFrameButton:SetText(txt or "")
396 end
397 f:Show()
398 end
399
400
401 local mouseButtonConvert = {
402 LeftButton = "BUTTON1",
403 RightButton = "BUTTON2",
404 MiddleButton = "BUTTON3",
405 Button4 = "BUTTON4",
406 Button5 = "BUTTON5"
407 }
408
409 function ReActionButton.prototype:HandleKeybindAssign(button, key, mouseButton)
410 mouseButton = mouseButton and mouseButtonConvert[mouseButton]
411 if mouseButton ~= "BUTTON1" and mouseButton ~= "BUTTON2" then
412 key = key or mouseButton
413 if key == nil or key == "UNKNOWN" or key == "SHIFT" or key == "CTRL" or key == "ALT" then
414 return
415 end
416 if key == "ESCAPE" then
417 ReActionKeybindFrame:Hide()
418 return
419 end
420 if IsShiftKeyDown() then
421 key = "SHIFT-"..key
422 end
423 if IsControlKeyDown() then
424 key = "CTRL-"..key
425 end
426 if IsAltKeyDown() then
427 keyPressed = "ALT-"..key
428 end
429 local oldAction = GetBindingAction(key)
430 local oldKey = self:GetKeyBinding()
431 if oldAction then
432 -- can't pop a modal dialog box, will need to think something up
433 end
434 if oldKey == key then
435 SetBinding(key,nil)
436 key = nil
437 end
438 self:SetKeyBinding(key)
439 button:SetText(key and GetBindingText(key, "KEY_") or "")
440 self:UpdateDisplay()
441 SaveBindings(2) -- 2 = character specific bindings... hmm...
442 end
443 button.selected = false
444 this:SetButtonState("NORMAL")
445 end
446
447
448 -- action ID functions
449 function ReActionButton.prototype:SetActionID( id )
450 self.config.actionIDs[self.barIdx] = tonumber(id) -- force data integrity
451 self:ApplyActionID()
452 end
453
454 function ReActionButton.prototype:GetActionID()
455 return self.config.actionIDs[self.barIdx]
456 end
457
458 function ReActionButton.prototype:ApplyActionID()
459 local action = tonumber(self:GetActionID())
460 self.button:SetAttribute("action",action or nil)
461 self.frames.actionID:SetText(action or "")
462 end
463
464 function ReActionButton.prototype:ShowActionID()
465 self.frames.actionID:Show()
466 end
467
468 function ReActionButton.prototype:HideActionID()
469 self.frames.actionID:Hide()
470 end
471
472 function ReActionButton:ShowAllActionIDs() -- class-wide function
473 for _, tbl in pairs(actionButtonTbl) do
474 if tbl.button then tbl.button:ShowActionID() end
475 end
476 end
477
478 function ReActionButton:HideAllActionIDs() -- class-wide function
479 for _, tbl in pairs(actionButtonTbl) do
480 if tbl.button then tbl.button:HideActionID() end
481 end
482 end
483
484
485 -- action transfer functions
486 function ReActionButton.prototype:ShouldPickupAction(mouseButton)
487 return IsShiftKeyDown() and not SecureButton_GetModifiedAttribute(self.button, "type", mouseButton)
488 end
489
490 function ReActionButton.prototype:ShowGridTmp()
491 self.showGrid = self.showGrid + 1
492 self:UpdateVisibility()
493 end
494
495 function ReActionButton.prototype:HideGridTmp()
496 self.showGrid = self.showGrid - 1
497 self:UpdateVisibility()
498 end
499
500 function ReActionButton.prototype:ShowGrid()
501 self.config.showGrid = true
502 self:ShowGridTmp()
503 end
504
505 function ReActionButton.prototype:HideGrid()
506 self.config.showGrid = false
507 self:HideGridTmp()
508 end
509
510
511
512 -- layout & style functions
513 function ReActionButton.prototype:ApplyLayout()
514 local f = self.frames
515
516 if self.config.keyBindLoc then
517 local h = f.hotkey
518 local loc = self.config.keyBindLoc
519 h:ClearAllPoints()
520 h:SetPoint(loc,0,0)
521 local j
522 if string.match(loc,"LEFT") then
523 j = "LEFT"
524 elseif string.match(loc,"RIGHT") then
525 j = "RIGHT"
526 else
527 j = "CENTER"
528 end
529 h:SetJustifyH(j)
530 end
531
532 if self.config.stackCountLoc then
533 local c = f.count
534 local loc = self.config.stackCountLoc
535 c:ClearAllPoints()
536 c:SetPoint(loc,0,0)
537 local j
538 if string.match(loc,"LEFT") then
539 j = "LEFT"
540 elseif string.match(loc,"RIGHT") then
541 j = "RIGHT"
542 else
543 j = "CENTER"
544 end
545 c:SetJustifyH(j)
546 end
547
548 if self.config.showKeyBind then
549 f.hotkey:Show()
550 else
551 f.hotkey:Hide()
552 end
553
554 if self.config.showStackCount then
555 f.count:Show()
556 else
557 f.count:Hide()
558 end
559
560 --[[
561 if self.config.showNumericCooldown then
562 f.nCooldown:Show()
563 else
564 f.nCooldown:Hide()
565 end
566 ]]
567
568 if self.config.showMacroName then
569 f.macro:Show()
570 else
571 f.macro:Hide()
572 end
573 end
574
575 function ReActionButton.prototype:ApplyStyle()
576 local f = self.frames
577 -- for now, just a static style
578 f.hotkey:SetFontObject(NumberFontNormal)
579 f.count:SetFontObject(NumberFontNormalYellow)
580 end
581
582
583
584 -- start/stop flashing
585 function ReActionButton.prototype:StartFlash()
586 self.flashing = true
587 self.flashtime = 0
588 self:UpdateCheckedState()
589 end
590
591 function ReActionButton.prototype:StopFlash()
592 self.flashing = false
593 self.frames.flash:Hide()
594 self:UpdateCheckedState()
595 end
596
597 function ReActionButton.prototype:IsFlashing()
598 return self.flashing
599 end
600
601
602
603
604
605 -- set the tooltip
606 function ReActionButton.prototype:SetTooltip()
607 GameTooltip_SetDefaultAnchor(GameTooltip, self.button)
608 self:UpdateTooltip()
609 end
610
611 function ReActionButton.prototype:ClearTooltip()
612 tooltipTime = nil
613 GameTooltip:Hide()
614 end
615
616
617
618 -- colorize the hotkey
619 function ReActionButton.prototype:ColorHotKey()
620 local action = self:GetActionID()
621 local c = hotKeyDefaultColor
622
623 if action and HasAction(action) then
624 if IsActionInRange(action) == 0 then
625 c = hotKeyOutOfRangeColor
626 elseif self.config.keyBindColorCode then
627 local modKey = string.match( self.frames.hotkey:GetText() or "", "([ACS])%-")
628 c = modKey and hotKeyModifierColors[modKey] or c
629 end
630 else
631 c = hotKeyDisabledColor
632 end
633
634 self.frames.hotkey:SetTextColor(c.r, c.g, c.b)
635 end
636
637
638
639
640 -- display update functions
641 function ReActionButton.prototype:UpdateDisplay()
642 self:UpdateIcon()
643 self:UpdateHotkey()
644 self:UpdateCount()
645 self:UpdateMacroText()
646 self:UpdateUsable()
647 self:UpdateCooldown()
648 self:UpdateFlash()
649 self:UpdateEvents()
650 self:UpdateVisibility()
651 self:UpdateTooltip()
652 end
653
654 function ReActionButton.prototype:UpdateIcon()
655 local f = self.frames
656 local b = self.button
657
658 local action = self:GetActionID()
659 local texture = action and GetActionTexture(action)
660
661 if action and texture then
662 f.icon:SetTexture(texture)
663 f.icon:Show()
664 self.rangeTimer = -1
665 b:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2")
666 else
667 f.icon:Hide()
668 f.cooldown:Hide()
669 self.rangeTimer = nil
670 b:SetNormalTexture("Interface\\Buttons\\UI-Quickslot")
671 end
672
673 self:UpdateCheckedState()
674
675 -- Add a green border if action is an equipped item
676 if action and IsEquippedAction(action) then
677 local c = equippedActionBorderColor
678 f.border:SetVertexColor(c.r, c.g, c.b, c.a or 1)
679 f.border:Show()
680 else
681 f.border:Hide()
682 end
683 end
684
685 function ReActionButton.prototype:UpdateCheckedState()
686 local action = self:GetActionID()
687 if action and (IsCurrentAction(action) or IsAutoRepeatAction(action)) then
688 self.button:SetChecked(1)
689 else
690 self.button:SetChecked(0)
691 end
692 end
693
694
695 function ReActionButton.prototype:UpdateHotkey()
696 local action = self:GetActionID()
697 local b = self.button
698 local f = self.frames
699 local key = self:GetKeyBinding()
700 local txt = GetBindingText(key, "KEY_",1)
701
702 if txt then
703 f.hotkey:SetText(string.upper(txt))
704 self:ColorHotKey()
705 else
706 f.hotkey:SetText("")
707 end
708 end
709
710 function ReActionButton.prototype:UpdateCount()
711 local action = self:GetActionID()
712 if action and (IsConsumableAction(action) or IsStackableAction(action)) then
713 self.frames.count:SetText(GetActionCount(action))
714 else
715 self.frames.count:SetText("")
716 end
717 end
718
719 function ReActionButton.prototype:UpdateMacroText()
720 local action = self:GetActionID()
721 self.frames.macro:SetText(action and GetActionText(action) or "")
722 end
723
724 function ReActionButton.prototype:UpdateUsable()
725 local f = self.frames
726 local action = self:GetActionID()
727 local isUsable, notEnoughMana
728 if action then
729 isUsable, notEnoughMana = IsUsableAction(action)
730 end
731 if isUsable then
732 local c = actionUsableColor
733 if IsActionInRange(action) == 0 then
734 c = actionOutOfRangeColor
735 else
736 f.normalTexture:SetVertexColor(c.r, c.g, c.b, c.a)
737 end
738 f.icon:SetVertexColor(c.r, c.g, c.b, c.a)
739 elseif notEnoughMana then
740 local c = actionNotEnoughManaColor
741 f.icon:SetVertexColor(c.r, c.g, c.b, c.a)
742 f.normalTexture:SetVertexColor(c.r, c.g, c.b, c.a)
743 else
744 local c = actionNotUsableColor
745 f.icon:SetVertexColor(c.r, c.g, c.b, c.a)
746 f.normalTexture:SetVertexColor(1.0, 1.0, 1.0)
747 end
748 end
749
750 function ReActionButton.prototype:UpdateCooldown()
751 local action = self:GetActionID()
752 if action then
753 local start, duration, enable = GetActionCooldown(self:GetActionID())
754 CooldownFrame_SetTimer(self.frames.cooldown, start, duration, enable)
755 -- do numeric cooldown stuff here
756 end
757 end
758
759 function ReActionButton.prototype:UpdateFlash()
760 local b = self.button
761 local action = self:GetActionID()
762 if action and ((IsAttackAction(action) and IsCurrentAction(action)) or IsAutoRepeatAction(action)) then
763 self:StartFlash()
764 else
765 self:StopFlash()
766 end
767 end
768
769 function ReActionButton.prototype:UpdateVisibility()
770 local action = self:GetActionID()
771 local b = self.button
772
773 if b:GetAttribute("statehidden") then
774 b:Hide()
775 elseif action and HasAction(action) then
776 b:GetNormalTexture():SetAlpha(1.0)
777 b:Show()
778 elseif self.showGrid > 0 then
779 b:GetNormalTexture():SetAlpha(0.5)
780 self.frames.cooldown:Hide()
781 b:Show()
782 else
783 b:Hide()
784 end
785 end
786
787 function ReActionButton.prototype:UpdateEvents()
788 local action = self:GetActionID()
789 if action and HasAction(action) then
790 self:RegisterActionEvents()
791 elseif self.actionEventsRegistered then
792 self:UnregisterActionEvents()
793 end
794 end
795
796 function ReActionButton.prototype:UpdateTooltip()
797 local action = self:GetActionID()
798 if action and GameTooltip:SetAction(action) then
799 self.tooltipTime = TOOLTIP_UPDATE_TIME
800 else
801 self.tooltipTime = nil
802 end
803 end
804
805
806