Mercurial > wow > reaction
diff modules/ReAction_PetAction/ReAction_PetAction.lua @ 77:da8ba8783924
- added revision updater to each code file
- Changed button/bar class mechanic to metatable-based
- Changed buttons to live within a sub-frame, to play nicely between show-empty-buttons and hidestates
- bar frame is now available only via accessor
- Changed some semantics with AddButton/PlaceButton
- Cleaned up action buttons options, fixed hide-when-empty option
- moved show-action-ID-label as a button method
- converted drag overlay from nested-frame to :Raise()
- fixed ReAction:SetConfigMode() to not call event when mode doesn't change
- Fixed ordering for dynamic state tab (always last)
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Mon, 23 Jun 2008 22:27:50 +0000 |
parents | 06cd74bdc7da |
children | 42ec2938d65a |
line wrap: on
line diff
--- a/modules/ReAction_PetAction/ReAction_PetAction.lua Thu Jun 19 17:48:57 2008 +0000 +++ b/modules/ReAction_PetAction/ReAction_PetAction.lua Mon Jun 23 22:27:50 2008 +0000 @@ -2,8 +2,7 @@ ReAction Pet Action button module The button module implements standard action button functionality by wrapping Blizzard's - PetActionButton frame and associated functions. It also provides some button layout - modification tools. + PetActionButton frame and associated functions. --]] @@ -13,10 +12,15 @@ local _G = _G local CreateFrame = CreateFrame +ReAction:UpdateRevision("$Revision: 103 $") + -- module declaration local moduleID = "PetAction" local module = ReAction:NewModule( moduleID ) +-- Button class declaration +local Button = { } + -- module methods function module:OnInitialize() self.db = ReAction.db:RegisterNamespace( moduleID, @@ -81,18 +85,15 @@ btnCfg[i] = {} end if btns[i] == nil then - local ok, b = pcall(self.BtnClass.new, self.BtnClass, bar, i, btnCfg[i]) - if ok and b then - btns[i] = b - bar:AddButton(i,b) - end - else - btns[i]:Refresh(bar,i) + local b = Button:New(bar,i,btnCfg[i]) + btns[i] = b + bar:AddButton(i,b) end + btns[i]:Refresh() end for i = n+1, #btns do if btns[i] then - bar:RemoveButton(b) + bar:RemoveButton(btns[i]) btns[i] = btns[i]:Destroy() if btnCfg[i] then btnCfg[i] = nil @@ -125,17 +126,13 @@ 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 pairs(self.buttons[bar]) do - if b then - if mode then - self:showActionIDLabel(b) - else - self:hideActionIDLabel(b) - end - end - end local f = bar:GetFrame() if mode then UnregisterUnitWatch(f) @@ -147,25 +144,6 @@ end end -function module:showActionIDLabel(button) - -- store the action ID label in the frame due to frame recycling - if not button:GetFrame().actionIDLabel and button:GetActionID() then - local label = button:GetFrame():CreateFontString(nil,"OVERLAY","GameFontNormalLarge") - label:SetAllPoints() - label:SetJustifyH("CENTER") - label:SetShadowColor(0,0,0,1) - label:SetShadowOffset(2,-2) - label:SetText(tostring(button:GetActionID())) - button:GetFrame().actionIDLabel = label - end - button:GetFrame().actionIDLabel:Show() -end - -function module:hideActionIDLabel(button) - if button:GetFrame().actionIDLabel then - button:GetFrame().actionIDLabel:Hide() - end -end ---- Options ---- function module:GetBarOptions(bar) @@ -180,6 +158,8 @@ +------ Button class ------ + -- use-count of action IDs local nActionIDs = NUM_PET_ACTION_SLOTS local ActionIDList = setmetatable( {}, { @@ -213,18 +193,14 @@ local frameRecycler = {} - ------- Button class ------ -local Button = { } - -local function Constructor( self, bar, idx, config ) +function Button:New( bar, idx, config ) + -- create new self + self = setmetatable( { }, { __index = Button } ) self.bar, self.idx, self.config = bar, idx, config - local barFrame = bar:GetFrame() - local name = config.name or ("ReAction_%s_Pet_%d"):format(bar:GetName(),idx) config.name = name - self.name = config.name + self.name = name config.actionID = ActionIDList[config.actionID] -- gets a free one if none configured -- have to recycle frames with the same name: @@ -232,20 +208,17 @@ -- doesn't overwrite existing globals (below) -- or, if you set them to nil in the global table, you get taint because of the -- crappy PetActionBar code. + local parent = bar:GetButtonFrame() local f = frameRecycler[name] if f then - f:SetParent(barFrame) - f:Show() + f:SetParent(parent) else - f = CreateFrame("CheckButton", name, barFrame, "PetActionButtonTemplate") + f = CreateFrame("CheckButton", name, parent, "PetActionButtonTemplate") end if config.actionID then f:SetID(config.actionID) -- PetActionButtonTemplate isn't a proper SecureActionButton end f:SetFrameStrata("MEDIUM") - - barFrame:SetAttribute("addchild",f) - self.frame = f self.icon = _G[("%sIcon"):format(name)] self.acTex = _G[("%sAutoCastable"):format(name)] @@ -256,7 +229,7 @@ f:HookScript("OnDragStart", function() self:Update() end) f:HookScript("OnReceiveDrag", function() self:Update() end) - f:RegisterEvent("PLAYER_CONTROL_LOST"); + f:RegisterEvent("PLAYER_CONTROL_LOST"); f:RegisterEvent("PLAYER_CONTROL_GAINED"); f:RegisterEvent("PLAYER_FARSIGHT_FOCUS_CHANGED"); f:RegisterEvent("UNIT_PET"); @@ -276,7 +249,8 @@ end end) - self:Refresh(bar,idx) + self:Refresh() + return self end function Button:Destroy() @@ -297,8 +271,8 @@ self.bar = nil end -function Button:Refresh(bar,idx) - bar:PlaceButton(self, 30, 30) +function Button:Refresh() + self.bar:PlaceButton(self, 30, 30) self:Update() self:UpdateHotkey() end @@ -370,14 +344,20 @@ end --- export as a class-factory to module -module.BtnClass = { - new = function(self, ...) - local x = { } - for k,v in pairs(Button) do - x[k] = v +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 - Constructor(x, ...) - return x + self.actionIDLabel:Show() + elseif self.actionIDLabel then + self.actionIDLabel:Hide() end -} +end