comparison ActionButton.lua @ 305:0211bcdfab70 stable

Merge 1.1 beta 12 to stable
author Flick
date Wed, 14 Nov 2012 16:47:27 -0800
parents e337b39dc491
children
comparison
equal deleted inserted replaced
294:30c9bdaad7a3 305:0211bcdfab70
44 local action = nil 44 local action = nil
45 if (doVehicle and mcVehicleState == "vehicle") or 45 if (doVehicle and mcVehicleState == "vehicle") or
46 (doMindControl and mcVehicleState == "mc") then 46 (doMindControl and mcVehicleState == "mc") then
47 local idx = self:GetAttribute("bar-idx") 47 local idx = self:GetAttribute("bar-idx")
48 local maxN = (doVehicle and mcVehicleState == "vehicle") and 7 or 12 48 local maxN = (doVehicle and mcVehicleState == "vehicle") and 7 or 12
49 local pageIndex = (doVehicle and mcVehicleState == "vehicle") and 12 or 14
49 if idx and idx <= maxN then 50 if idx and idx <= maxN then
50 action = 120 + idx 51 action = 12*(pageIndex-1) + idx
51 else 52 else
52 action = 0 53 action = 0
53 end 54 end
54 elseif state and settings[state] and settings[state].page then 55 elseif state and settings[state] and settings[state].page then
55 action = self:GetAttribute("action-"..settings[state].page) 56 action = self:GetAttribute("action-"..settings[state].page)
144 -- 145 --
145 -- private 146 -- private
146 -- 147 --
147 local eventList = { 148 local eventList = {
148 "PLAYER_ENTERING_WORLD", 149 "PLAYER_ENTERING_WORLD",
149 "ACTIONBAR_PAGE_CHANGED",
150 "ACTIONBAR_SLOT_CHANGED", 150 "ACTIONBAR_SLOT_CHANGED",
151 "UPDATE_BINDINGS", 151 "UPDATE_BINDINGS",
152 "ACTIONBAR_UPDATE_STATE",
153 "ACTIONBAR_UPDATE_USABLE", 152 "ACTIONBAR_UPDATE_USABLE",
154 "ACTIONBAR_UPDATE_COOLDOWN",
155 "UNIT_INVENTORY_CHANGED", 153 "UNIT_INVENTORY_CHANGED",
156 "LEARNED_SPELL_IN_TAB", 154 "LEARNED_SPELL_IN_TAB",
157 "UPDATE_INVENTORY_ALERTS", 155 "UPDATE_INVENTORY_ALERTS",
158 "PLAYER_TARGET_CHANGED", 156 "PLAYER_TARGET_CHANGED",
159 "TRADE_SKILL_SHOW", 157 "TRADE_SKILL_SHOW",
164 "START_AUTOREPEAT_SPELL", 162 "START_AUTOREPEAT_SPELL",
165 "STOP_AUTOREPEAT_SPELL", 163 "STOP_AUTOREPEAT_SPELL",
166 "UNIT_ENTERED_VEHICLE", 164 "UNIT_ENTERED_VEHICLE",
167 "UNIT_EXITED_VEHICLE", 165 "UNIT_EXITED_VEHICLE",
168 "COMPANION_UPDATE", 166 "COMPANION_UPDATE",
167 "UPDATE_SHAPESHIFT_FORM",
168 "SPELL_UPDATE_CHARGES",
169 "UPDATE_SUMMONPETS_ACTION",
169 } 170 }
170 171
171 -- 172 --
172 -- Action Button class 173 -- Action Button class
173 -- 174 --
184 spacing = 3, 185 spacing = 3,
185 buttons = { }, 186 buttons = { },
186 }, 187 },
187 188
188 barType = L["Action Bar"], 189 barType = L["Action Bar"],
189 buttonTypeID = buttonTypeID 190 buttonTypeID = buttonTypeID,
191 eventList = eventList
190 }, 192 },
191 { __index = Super } ) 193 { __index = Super } )
192 194
193 ReAction.Button.Action = Action 195 ReAction.Button.Action = Action
194 ReAction:RegisterBarType(Action, true) 196 ReAction:RegisterBarType(Action, true)
342 self:UpdateMacroText() 344 self:UpdateMacroText()
343 self:UpdateCount() 345 self:UpdateCount()
344 self:UpdateTooltip() 346 self:UpdateTooltip()
345 self:UpdateCheckedState() 347 self:UpdateCheckedState()
346 self:UpdateUsable() 348 self:UpdateUsable()
347 self:UpdateCooldown()
348 self:UpdateFlash() 349 self:UpdateFlash()
349 end 350 end
350 351
351 function Action:UpdateAction() 352 function Action:UpdateAction()
352 local action = self:GetActionID() 353 local action = self:GetActionID()
353 if action ~= self.actionID then 354 if action ~= self.actionID then
354 self.actionID = action 355 self.actionID = action
356
357 -- update checked state and cooldown in C-code
358 local f = self:GetFrame()
359 SetActionUIButton(f, action, f.cooldown)
360
355 self:UpdateAll() 361 self:UpdateAll()
356 end 362 end
357 end 363 end
358 364
359 function Action:UpdateShowGrid() 365 function Action:UpdateShowGrid()
392 if tLeft then 398 if tLeft then
393 icon:SetTexCoord(tLeft,tRight,tTop,tBottom) 399 icon:SetTexCoord(tLeft,tRight,tTop,tBottom)
394 end 400 end
395 icon:Show() 401 icon:Show()
396 self.rangeTimer = -1 402 self.rangeTimer = -1
397 f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2")
398 else 403 else
399 icon:Hide() 404 icon:Hide()
400 self.frames.cooldown:Hide() 405 self.frames.cooldown:Hide()
401 self.rangeTimer = nil 406 self.rangeTimer = nil
402 f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot")
403 end 407 end
404 end 408 end
405 409
406 function Action:GetIconTexture() 410 function Action:GetIconTexture()
407 return GetActionTexture(self.actionID) 411 return GetActionTexture(self.actionID)
419 end 423 end
420 end 424 end
421 425
422 function Action:UpdateMacroText() 426 function Action:UpdateMacroText()
423 local action = self.actionID 427 local action = self.actionID
424 if not IsConsumableAction(action) and not IsStackableAction(action) then 428 if not IsConsumableAction(action) and
429 not IsStackableAction(action) and
430 (IsItemAction(action) or GetActionCount(action) == 0) then
425 self.frames.name:SetText(GetActionText(action)) 431 self.frames.name:SetText(GetActionText(action))
426 else 432 else
427 self.frames.name:SetText("") 433 self.frames.name:SetText("")
428 end 434 end
429 end 435 end
430 436
431 function Action:UpdateCount() 437 function Action:UpdateCount()
432 local action = self.actionID 438 local action = self.actionID
433 if IsConsumableAction(action) or IsStackableAction(action) then 439 local count = GetActionCount(action) or 0
434 self.frames.count:SetText(GetActionCount(action)) 440 if IsConsumableAction(action) or IsStackableAction(action) or (not IsItemAction(action) and count > 0) then
435 else 441 if count > 9999 then
436 self.frames.count:SetText("") 442 self.frames.count:SetText("*")
443 else
444 self.frames.count:SetText(count)
445 end
446 else
447 local charges, maxCharges, chargeStart, chargeDuration = GetActionCharges(action)
448 charges = tonumber(charges) or 0
449 maxCharges = tonumber(maxCharges) or 0
450 if maxCharges > 1 then
451 self.frames.count:SetText(charges)
452 else
453 self.frames.count:SetText("")
454 end
437 end 455 end
438 end 456 end
439 457
440 function Action:UpdateTooltip() 458 function Action:UpdateTooltip()
441 local f = self:GetFrame() 459 local f = self:GetFrame()
500 return IsUsableAction(self.actionID) 518 return IsUsableAction(self.actionID)
501 end 519 end
502 520
503 function Action:GetInRange() 521 function Action:GetInRange()
504 return IsActionInRange(self.actionID) == 0 522 return IsActionInRange(self.actionID) == 0
505 end
506
507 function Action:UpdateCooldown()
508 CooldownFrame_SetTimer(self.frames.cooldown, self:GetCooldown())
509 end 523 end
510 524
511 function Action:GetCooldown() 525 function Action:GetCooldown()
512 return GetActionCooldown(self.actionID) 526 return GetActionCooldown(self.actionID)
513 end 527 end
640 doVehicle = self:GetAttribute("vehicle") 654 doVehicle = self:GetAttribute("vehicle")
641 control:ChildUpdate() 655 control:ChildUpdate()
642 ]]) 656 ]])
643 657
644 f:SetAttribute("_onstate-mc", _onstate_mc) 658 f:SetAttribute("_onstate-mc", _onstate_mc)
645 RegisterStateDriver(f, "mc", "[vehicleui] vehicle; [bonusbar:5] mc; none") 659 RegisterStateDriver(f, "mc", "[vehicleui] vehicle; [overridebar] mc; none")
646 660
647 f:SetAttribute("lockbuttons",config.lockButtons) 661 f:SetAttribute("lockbuttons",config.lockButtons)
648 f:SetAttribute("lockbuttonscombat",config.lockButtonsCombat) 662 f:SetAttribute("lockbuttonscombat",config.lockButtonsCombat)
649 f:Execute( 663 f:Execute(
650 [[ 664 [[
720 734
721 function Action:PLAYER_ENTERING_WORLD() 735 function Action:PLAYER_ENTERING_WORLD()
722 self:UpdateAction() 736 self:UpdateAction()
723 end 737 end
724 738
725 function Action:ACTIONBAR_PAGE_CHANGED()
726 self:UpdateAction()
727 end
728
729 function Action:UPDATE_BONUS_ACTIONBAR()
730 self:UpdateAction()
731 end
732
733 function Action:UPDATE_BINDINGS() 739 function Action:UPDATE_BINDINGS()
734 self:UpdateHotkey() 740 self:UpdateHotkey()
735 end 741 end
736 742
737 function Action:PLAYER_TARGET_CHANGED() 743 function Action:PLAYER_TARGET_CHANGED()
738 self.rangeTimer = -1 744 self.rangeTimer = -1
739 end
740
741 function Action:ACTIONBAR_UPDATE_STATE()
742 self:UpdateCheckedState()
743 end 745 end
744 746
745 function Action:TRADE_SKILL_SHOW() 747 function Action:TRADE_SKILL_SHOW()
746 self:UpdateCheckedState() 748 self:UpdateCheckedState()
747 end 749 end
763 765
764 function Action:ACTIONBAR_UPDATE_USABLE() 766 function Action:ACTIONBAR_UPDATE_USABLE()
765 self:UpdateUsable() 767 self:UpdateUsable()
766 end 768 end
767 769
768 function Action:ACTIONBAR_UPDATE_COOLDOWN() 770 function Action:SPELL_UPDATE_CHARGES()
769 self:UpdateCooldown() 771 self:UpdateCount()
770 end 772 end
771 773
772 function Action:PLAYER_ENTER_COMBAT() 774 function Action:PLAYER_ENTER_COMBAT()
773 if IsAttackAction(self.actionID) then 775 if IsAttackAction(self.actionID) then
774 self:SetFlash(true) 776 self:SetFlash(true)
791 if not IsAttackAction(self.actionID) then 793 if not IsAttackAction(self.actionID) then
792 self:SetFlash(false) 794 self:SetFlash(false)
793 end 795 end
794 end 796 end
795 797
798 function Action:UPDATE_SHAPESHIFT_FORM()
799 self:UpdateIcon()
800 end
801
796 function Action:UNIT_INVENTORY_CHANGED(unit) 802 function Action:UNIT_INVENTORY_CHANGED(unit)
797 if unit == "player" then 803 if unit == "player" then
798 self:UpdateTooltip() 804 self:UpdateTooltip()
799 end 805 end
800 end 806 end
801 807
802 function Action:LEARNED_SPELL_IN_TAB() 808 function Action:LEARNED_SPELL_IN_TAB()
803 self:UpdateTooltip() 809 self:UpdateTooltip()
804 end 810 end
811
812 function Action:UPDATE_SUMMONPETS_ACTION()
813 self:UpdateIcon()
814 end