annotate 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
rev   line source
flickerstreak@28 1 --[[
flickerstreak@28 2 ReAction Pet Action Bar module
flickerstreak@28 3
flickerstreak@28 4 --]]
flickerstreak@28 5
flickerstreak@28 6 -- local imports
flickerstreak@28 7 local ReAction = ReAction
flickerstreak@28 8 local L = ReAction.L
flickerstreak@28 9 local _G = _G
flickerstreak@28 10
flickerstreak@28 11 -- module declaration
flickerstreak@28 12 local moduleID = "PetAction"
flickerstreak@28 13 local module = ReAction:NewModule( moduleID )
flickerstreak@28 14
flickerstreak@28 15
flickerstreak@28 16 -- module methods
flickerstreak@28 17 function module:OnInitialize()
flickerstreak@28 18 self.db = ReAction.db:RegisterNamespace( moduleID,
flickerstreak@28 19 {
flickerstreak@28 20 profile = {
flickerstreak@28 21 buttons = { }
flickerstreak@28 22 }
flickerstreak@28 23 }
flickerstreak@28 24 )
flickerstreak@28 25
flickerstreak@28 26 self.buttons = { }
flickerstreak@28 27 end
flickerstreak@28 28
flickerstreak@28 29 function module:OnEnable()
flickerstreak@28 30 end
flickerstreak@28 31
flickerstreak@28 32 function module:OnDisable()
flickerstreak@28 33 end
flickerstreak@28 34
flickerstreak@28 35 function module:GetGlobalBarOptions(opts)
flickerstreak@28 36 if self.globalBarOpts == nil then
flickerstreak@28 37 self.globalBarOpts = {
flickerstreak@28 38 newActionBar = {
flickerstreak@28 39 type = "execute",
flickerstreak@28 40 name = L["New Pet Action Bar"],
flickerstreak@28 41 desc = L["Create a new bar of pet action buttons"],
flickerstreak@28 42 func = function()
flickerstreak@28 43 ReAction:CreateBar()
flickerstreak@28 44 end,
flickerstreak@28 45 disabled = InCombatLockdown,
flickerstreak@28 46 }
flickerstreak@28 47 }
flickerstreak@28 48 end
flickerstreak@28 49 return self.globalBarOpts
flickerstreak@28 50 end
flickerstreak@28 51
flickerstreak@28 52
flickerstreak@28 53 -- use-count of action IDs
flickerstreak@28 54 local ActionIDList = setmetatable( {}, {
flickerstreak@28 55 __index = function(self, idx)
flickerstreak@28 56 if idx == nil then
flickerstreak@28 57 for i = 1, 10 do
flickerstreak@28 58 if rawget(self,i) == nil then
flickerstreak@28 59 rawset(self,i,1)
flickerstreak@28 60 return i
flickerstreak@28 61 end
flickerstreak@28 62 end
flickerstreak@28 63 else
flickerstreak@28 64 local c = rawget(self,idx) or 0
flickerstreak@28 65 rawset(self,idx,c+1)
flickerstreak@28 66 return idx
flickerstreak@28 67 end
flickerstreak@28 68 end,
flickerstreak@28 69 __newindex = function(self,idx,value)
flickerstreak@28 70 if value == nil then
flickerstreak@28 71 value = rawget(self,idx)
flickerstreak@28 72 if value == 1 then
flickerstreak@28 73 value = nil
flickerstreak@28 74 elseif value then
flickerstreak@28 75 value = value - 1
flickerstreak@28 76 end
flickerstreak@28 77 end
flickerstreak@28 78 rawset(self,idx,value)
flickerstreak@28 79 end
flickerstreak@28 80 })
flickerstreak@28 81
flickerstreak@28 82
flickerstreak@28 83 -- button class methods
flickerstreak@28 84 local Button = { }
flickerstreak@28 85
flickerstreak@28 86 local function Constructor( self, bar, idx, config )
flickerstreak@28 87 self.bar, self.idx, self.config = bar, idx, config
flickerstreak@28 88
flickerstreak@28 89 local barFrame = bar:GetFrame()
flickerstreak@28 90
flickerstreak@28 91 self.name = config.name or "ReAction_"..bar:GetName().."_Pet_"..idx
flickerstreak@28 92 config.actionID = ActionIDList[config.actionID] -- gets a free one if none configured
flickerstreak@28 93
flickerstreak@28 94 local f = CreateFrame("CheckButton", self.name, barFrame, "PetActionButtonTemplate")
flickerstreak@28 95 f:SetID(config.actionID) -- PetActionButtonTemplate isn't a proper SecureActionButton (question: is this protected? does it cause taint?)
flickerstreak@28 96 self.frame = f
flickerstreak@28 97 barFrame:SetAttribute("addchild",f)
flickerstreak@28 98
flickerstreak@28 99 -- auto show/hide when pet exists
flickerstreak@28 100 -- this gets called once per button, which is inefficient but otherwise harmless
flickerstreak@28 101 barFrame:SetAttribute("unit","pet")
flickerstreak@28 102 RegisterUnitWatch(barFrame)
flickerstreak@28 103
flickerstreak@28 104 self:Refresh(bar,idx)
flickerstreak@28 105 end
flickerstreak@28 106
flickerstreak@28 107 function Button:Destroy()
flickerstreak@28 108 local f = self.frame
flickerstreak@28 109 f:UnregisterAllEvents()
flickerstreak@28 110 f:Hide()
flickerstreak@28 111 f:SetParent(UIParent)
flickerstreak@28 112 f:ClearAllPoints()
flickerstreak@28 113 if self.name then
flickerstreak@28 114 _G[self.name] = nil
flickerstreak@28 115 end
flickerstreak@28 116 ActionIDList[self.config.actionID] = nil
flickerstreak@28 117 self.frame = nil
flickerstreak@28 118 self.config = nil
flickerstreak@28 119 self.bar = nil
flickerstreak@28 120 end
flickerstreak@28 121
flickerstreak@28 122
flickerstreak@28 123 -- export as a class-factory to module
flickerstreak@28 124 module.BtnClass = {
flickerstreak@28 125 new = function(self, ...)
flickerstreak@28 126 local x = { }
flickerstreak@28 127 for k,v in pairs(Button) do
flickerstreak@28 128 x[k] = v
flickerstreak@28 129 end
flickerstreak@28 130 Constructor(x, ...)
flickerstreak@28 131 return x
flickerstreak@28 132 end
flickerstreak@28 133 }