Mercurial > wow > reaction
diff modules/ReAction_PetAction/ReAction_PetAction.lua @ 28:21bcaf8215ff
- converted to Ace3
- rearranged file layout
- configGUI menus not working right now
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Mon, 17 Mar 2008 18:24:53 +0000 |
parents | |
children | 7e09c02ae620 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/ReAction_PetAction/ReAction_PetAction.lua Mon Mar 17 18:24:53 2008 +0000 @@ -0,0 +1,133 @@ +--[[ + ReAction Pet Action Bar module + +--]] + +-- local imports +local ReAction = ReAction +local L = ReAction.L +local _G = _G + +-- module declaration +local moduleID = "PetAction" +local module = ReAction:NewModule( moduleID ) + + +-- module methods +function module:OnInitialize() + self.db = ReAction.db:RegisterNamespace( moduleID, + { + profile = { + buttons = { } + } + } + ) + + self.buttons = { } +end + +function module:OnEnable() +end + +function module:OnDisable() +end + +function module:GetGlobalBarOptions(opts) + if self.globalBarOpts == nil then + self.globalBarOpts = { + newActionBar = { + type = "execute", + name = L["New Pet Action Bar"], + desc = L["Create a new bar of pet action buttons"], + func = function() + ReAction:CreateBar() + end, + disabled = InCombatLockdown, + } + } + end + return self.globalBarOpts +end + + +-- use-count of action IDs +local ActionIDList = setmetatable( {}, { + __index = function(self, idx) + if idx == nil then + for i = 1, 10 do + if rawget(self,i) == nil then + rawset(self,i,1) + return i + end + end + 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 +}) + + +-- button class methods +local Button = { } + +local function Constructor( self, bar, idx, config ) + self.bar, self.idx, self.config = bar, idx, config + + local barFrame = bar:GetFrame() + + self.name = config.name or "ReAction_"..bar:GetName().."_Pet_"..idx + config.actionID = ActionIDList[config.actionID] -- gets a free one if none configured + + local f = CreateFrame("CheckButton", self.name, barFrame, "PetActionButtonTemplate") + f:SetID(config.actionID) -- PetActionButtonTemplate isn't a proper SecureActionButton (question: is this protected? does it cause taint?) + self.frame = f + barFrame:SetAttribute("addchild",f) + + -- auto show/hide when pet exists + -- this gets called once per button, which is inefficient but otherwise harmless + barFrame:SetAttribute("unit","pet") + RegisterUnitWatch(barFrame) + + self:Refresh(bar,idx) +end + +function Button:Destroy() + local f = self.frame + f:UnregisterAllEvents() + f:Hide() + f:SetParent(UIParent) + f:ClearAllPoints() + if self.name then + _G[self.name] = nil + end + ActionIDList[self.config.actionID] = nil + self.frame = nil + self.config = nil + self.bar = nil +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 + end + Constructor(x, ...) + return x + end +}