Mercurial > wow > reaction
diff modules/PetAction.lua @ 130:6e4a11b9d290
Converted PetAction to new class layout
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Fri, 06 Mar 2009 23:44:55 +0000 |
parents | fb48811a8736 |
children | 901c91dc1bf2 |
line wrap: on
line diff
--- a/modules/PetAction.lua Fri Mar 06 23:44:33 2009 +0000 +++ b/modules/PetAction.lua Fri Mar 06 23:44:55 2009 +0000 @@ -22,8 +22,8 @@ local moduleID = "PetAction" local module = ReAction:NewModule( moduleID ) --- Button class declaration -local Button = { } +-- Button class +local Button = ReAction.Button.PetAction -- private local function UpdateButtonLock(bar) @@ -107,7 +107,7 @@ btnCfg[i] = {} end if btns[i] == nil then - local success, r = pcall(Button.New,Button,bar,i,btnCfg[i]) + local success, r = pcall(Button.New,Button,i,btnCfg[i],bar,i>1 and btnCfg[i-1].actionID) if success and r then btns[i] = r bar:AddButton(i,r) @@ -155,13 +155,11 @@ function module:OnConfigModeChanged(event, mode) - for _, buttons in pairs(self.buttons) do - for _, b in pairs(buttons) do - b:ShowActionIDLabel(mode) - end - end for _, bar in ReAction:IterateBars() do if bar and self.buttons[bar] then + for b in bar:IterateButtons() do + b:UpdateActionIDLabel(mode) + end local f = bar:GetFrame() if mode then UnregisterUnitWatch(f) @@ -203,7 +201,7 @@ end function Handler:GetLockButtons() - return LOCK_ACTIONBAR == "1" or self.config.lockButtons + return self.config.lockButtons end function Handler:SetLockButtons(info, value) @@ -211,10 +209,6 @@ UpdateButtonLock(self.bar) end -function Handler:LockButtonsDisabled() - return LOCK_ACTIONBAR == "1" -end - function Handler:GetLockButtonsCombat() return self.config.lockButtonsCombat end @@ -225,7 +219,7 @@ end function Handler:LockButtonsCombatDisabled() - return LOCK_ACTIONBAR == "1" or not self.config.lockButtons + return not self.config.lockButtons end @@ -241,7 +235,6 @@ desc = L["Prevents picking up/dragging actions.|nNOTE: This setting is overridden by the global setting in Blizzard's Action Buttons tab"], order = 2, type = "toggle", - disabled = "LockButtonsDisabled", get = "GetLockButtons", set = "SetLockButtons", }, @@ -260,304 +253,3 @@ end - ------- Button class ------ - --- use-count of action IDs -local nActionIDs = NUM_PET_ACTION_SLOTS -local ActionIDList = setmetatable( {}, { - __index = function(self, idx) - if idx == nil then - for i = 1, nActionIDs do - if rawget(self,i) == nil then - rawset(self,i,1) - return i - end - end - error("ran out of pet action IDs") - else - local c = rawget(self,idx) or 0 - rawset(self,idx,c+1) - return idx - end - end, - __newindex = function(self,idx,value) - if value == nil then - value = rawget(self,idx) - if value == 1 then - value = nil - elseif value then - value = value - 1 - end - end - rawset(self,idx,value) - end -}) - -local frameRecycler = {} -local trash = CreateFrame("Frame") - -local function GetActionName(f) - local b = f and f._reactionButton - if b then - return format("%s:%s", b.bar:GetName(), b.idx) - end -end - -local function GetHotkey(f) - return KB:ToShortKey(GetBindingKey(format("CLICK %s:LeftButton",f:GetName()))) -end - -local function OnEnter( self ) - if ReAction:GetKeybindMode() then - KB:Set(self) - elseif self.tooltipName then - local uber = GetCVar("UberTooltips") - if self.isToken or (uber == "0") then - if uber == "0" then - GameTooltip:SetOwner(self, "ANCHOR_RIGHT") - else - GameTooltip_SetDefaultAnchor(GameTooltip, self) - end - GameTooltip:SetText(self.tooltipName) - if self.tooltipSubtext then - GameTooltip:AddLine(self.tooltipSubtext, "", 0.5, 0.5, 0.5) - end - GameTooltip:Show() - else - GameTooltip_SetDefaultAnchor(GameTooltip, self) - GameTooltip:SetPetAction(self:GetID()) - end - end -end - -local function OnLeave() - GameTooltip:Hide() -end - -local meta = { __index = Button } - -function Button:New( bar, idx, config ) - -- create new self - self = setmetatable( - { - bar = bar, - idx = idx, - config = config, - }, meta ) - - local name = config.name or ("ReAction_%s_%s_%d"):format(bar:GetName(),moduleID,idx) - config.name = name - self.name = name - config.actionID = ActionIDList[config.actionID] -- gets a free one if none configured - - -- have to recycle frames with the same name: - -- otherwise you either get references to old textures because named CreateFrame() - -- doesn't overwrite existing globals. Can't set them to nil in the global table, - -- as it causes taint. - local parent = bar:GetFrame() - local f = frameRecycler[name] - if f then - f:SetParent(parent) - else - f = CreateFrame("CheckButton", name, parent, "PetActionButtonTemplate") - -- ditch the old hotkey text because it's tied in ActionButton_Update() to the - -- standard binding. We use override bindings. - local hotkey = _G[name.."HotKey"] - hotkey:SetParent(trash) - hotkey = f:CreateFontString(nil, "ARTWORK", "NumberFontNormalSmallGray") - hotkey:SetWidth(36) - hotkey:SetHeight(18) - hotkey:SetJustifyH("RIGHT") - hotkey:SetJustifyV("TOP") - hotkey:SetPoint("TOPLEFT",f,"TOPLEFT",-2,-2) - f.hotkey = hotkey - f:HookScript("OnDragStart", function() self:Update() end) - f:HookScript("OnReceiveDrag", function() self:Update() end) - f:SetScript("OnEnter", OnEnter) - f:SetScript("OnLeave", OnLeave) - end - if config.actionID then - f:SetID(config.actionID) -- PetActionButtonTemplate isn't a proper SecureActionButton - end - f:SetFrameStrata("MEDIUM") - self.frame = f - self.icon = _G[("%sIcon"):format(name)] - self.acTex = _G[("%sAutoCastable"):format(name)] - self.acModel = _G[("%sShine"):format(name)] - self.cooldown = _G[("%sCooldown"):format(name)] - self.hotkey = f.hotkey - self.border = _G[("%sBorder"):format(name)] - - f._reactionButton = self - - f:RegisterEvent("PLAYER_CONTROL_LOST") - f:RegisterEvent("PLAYER_CONTROL_GAINED") - f:RegisterEvent("PLAYER_FARSIGHT_FOCUS_CHANGED") - f:RegisterEvent("UNIT_PET") - f:RegisterEvent("UNIT_FLAGS") - f:RegisterEvent("UNIT_AURA") - f:RegisterEvent("PET_BAR_UPDATE") - f:RegisterEvent("PET_BAR_UPDATE_COOLDOWN") - - f:SetScript("OnEvent", - function(event,arg1) - if event =="PET_BAR_UPDATE_COOLDOWN" then - self:UpdateCooldown() - elseif event == "UPDATE_BINDINGS" then - self:UpdateHotkey() - else - self:Update() - end - end) - - -- install drag wrappers to lock buttons - bar:GetFrame():WrapScript(f, "OnDragStart", - -- OnDragStart(self, button, kind, value, ...) - [[ - if lockButtons and (PlayerInCombat() or not lockButtonsCombat) and not IsModifiedClick("PICKUPACTION") then - return "clear" - end - ]]) - - -- attach to skinner - bar:SkinButton(self, - { - HotKey = self.hotkey, - } - ) - - self:Refresh() - self:UpdateHotkey() - self:SetKeybindMode(ReAction:GetKeybindMode()) - - return self -end - -function Button:Destroy() - local f = self.frame - f:UnregisterAllEvents() - f:Hide() - f:SetParent(UIParent) - f:ClearAllPoints() - if self.name then - frameRecycler[self.name] = f - _G[self.name] = nil - end - if self.config.actionID then - ActionIDList[self.config.actionID] = nil - end - f._reactionButton = nil - self.frame = nil - self.config = nil - self.bar = nil -end - -function Button:Refresh() - self.bar:PlaceButton(self, 30, 30) - self:Update() - self:UpdateHotkey() - self.frame:Show() -end - -function Button:GetFrame() - return self.frame -end - -function Button:GetName() - return self.name -end - -function Button:GetConfig() - return self.config -end - -function Button:GetActionID() - return self.config.actionID -end - -function Button:Update() - local id = self.frame:GetID() - local name, subtext, texture, isToken, isActive, autoCastAllowed, autoCastEnabled = GetPetActionInfo(id) - local f = self.frame - - if isToken then - self.icon:SetTexture(_G[texture]) - f.tooltipName = _G[name] - else - self.icon:SetTexture(texture) - f.tooltipName = name - end - - f.isToken = isToken - f.tooltipSubtext = subtext - f:SetChecked( isActive and 1 or 0) - - if autoCastAllowed then - self.acTex:Show() - else - self.acTex:Hide() - end - - if autoCastEnabled then - AutoCastShine_AutoCastStart(self.acModel) - else - AutoCastShine_AutoCastStop(self.acModel) - end - - if texture then - if GetPetActionSlotUsable(id) then - SetDesaturation(self.icon,nil) - else - SetDesaturation(self.icon,1) - end - self.icon:Show() - f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2") - else - self.icon:Hide() - f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot") - end - - self:UpdateCooldown() -end - -function Button:UpdateCooldown() - local start, duration, enable = GetPetActionCooldown(self.frame:GetID()) - CooldownFrame_SetTimer(self.cooldown, start, duration, enable) -end - -function Button:UpdateHotkey() - self.hotkey:SetText(GetHotkey(self.frame) or "") -end - -function Button:ShowActionIDLabel(show) - if show then - -- store the action ID label in the frame due to frame recycling - if not self.actionIDLabel and self:GetActionID() then - local label = self.frame:CreateFontString(nil,"OVERLAY","GameFontNormalLarge") - label:SetAllPoints() - label:SetJustifyH("CENTER") - label:SetShadowColor(0,0,0,1) - label:SetShadowOffset(2,-2) - label:SetText(tostring(self:GetActionID())) - self.actionIDLabel = label - end - self.actionIDLabel:Show() - elseif self.actionIDLabel then - self.actionIDLabel:Hide() - end -end - - -function Button:SetKeybindMode(mode) - if mode then - local f = self.frame - f.GetActionName = GetActionName - f.GetHotkey = GetHotkey - self.border:SetVertexColor(KB:GetColorKeyBoundMode()) - self.border:Show() - else - self.border:Hide() - end -end -