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