comparison modules/ReAction_Action/ReAction_Action.lua @ 24:9e1984088124

added *more* missing files from 1.0 dev tree...
author Flick <flickerstreak@gmail.com>
date Fri, 07 Mar 2008 22:18:23 +0000
parents
children 21bcaf8215ff
comparison
equal deleted inserted replaced
23:dba04d85c799 24:9e1984088124
1 --[[
2 ReAction Action-button module.
3
4 The button module implements standard action button functionality by wrapping Blizzard's
5 ActionButton frame and associated functions. It also provides some button layout
6 modification tools.
7
8 --]]
9
10 -- local imports
11 local ReAction = ReAction
12 local L = ReAction.L
13 local _G = _G
14 local AceOO = AceLibrary("AceOO-2.0")
15 local CreateFrame = CreateFrame
16 local print = ReAction.print
17
18 -- module declaration
19 local moduleID = "Action"
20 local module = ReAction:NewModule( moduleID,
21 "AceEvent-2.0"
22 )
23
24 --
25 -- action button class declaration
26 --
27 local BtnClass = AceOO.Class()
28 local Button = BtnClass.prototype
29 module.BtnClass = BtnClass
30
31
32
33 -- module methods
34 function module:OnInitialize()
35 self.db = ReAction:AcquireDBNamespace(moduleID)
36 ReAction:RegisterDefaults(moduleID,"profile",
37 {
38 buttons = { }
39 }
40 )
41
42 self.buttons = { }
43 end
44
45 function module:OnEnable()
46 end
47
48 function module:OnDisable()
49 end
50
51 function module:OnProfileEnable()
52 end
53
54 function module:ApplyToBar(bar)
55 self:RefreshBar(bar)
56 end
57
58 function module:RefreshBar(bar)
59 if self.buttons[bar] == nil then
60 self.buttons[bar] = { }
61 end
62 local btns = self.buttons[bar]
63 local profile = self.db.profile
64 local barName = bar:GetName()
65 if profile.buttons[barName] == nil then
66 profile.buttons[barName] = {}
67 end
68 local btnCfg = profile.buttons[barName]
69
70 local r, c = bar:GetButtonGrid()
71 local n = r*c
72 for i = 1, n do
73 if btnCfg[i] == nil then
74 btnCfg[i] = {}
75 end
76 if btns[i] == nil then
77 btns[i] = self.BtnClass:new(bar,i,btnCfg[i])
78 else
79 btns[i]:Refresh(bar,i)
80 end
81 end
82 for i = n+1, #btns do
83 btns[i] = btns[i]:Destroy()
84 if btnCfg[i] then
85 btnCfg[i] = nil
86 end
87 end
88 end
89
90 function module:RemoveFromBar(bar)
91 if self.buttons[bar] then
92 local btns = self.buttons[bar]
93 for _,b in pairs(btns) do
94 if b then
95 b:Destroy()
96 end
97 end
98 self.buttons[bar] = nil
99 end
100 end
101
102 function module:EraseBarConfig(barName)
103 self.db.profile.buttons[barName] = nil
104 end
105
106 function module:ApplyConfigMode(mode,bars)
107 for _, btns in pairs(self.buttons) do
108 if btn then
109 for _, b in pairs(btns) do
110 if b then
111 if mode then
112 if not b.actionIDLabel then
113 local label = b:GetFrame():CreateFontString(nil,"OVERLAY","GameFontNormalLarge")
114 label:SetAllPoints()
115 label:SetJustifyH("CENTER")
116 label:SetShadowColor(0,0,0,1)
117 label:SetShadowOffset(2,-2)
118 label:SetText(tostring(b:GetActionID()))
119 b.actionIDLabel = label
120 end
121 b.actionIDLabel:Show()
122 elseif b.actionIDLabel then
123 b.actionIDLabel:Hide()
124 end
125 end
126 end
127 end
128 end
129 end
130
131 function module:GetGlobalBarOptions(opts)
132 if self.globalBarOpts == nil then
133 self.globalBarOpts = {
134 newActionBar = {
135 type = "execute",
136 name = L["New Action Bar"],
137 desc = L["Create a new bar of standard action buttons"],
138 func = function()
139 ReAction:GetModule("Bar"):CreateBar()
140 end,
141 disabled = InCombatLockdown,
142 }
143 }
144 end
145 return self.globalBarOpts
146 end
147
148 function module:GetBarMenuOptions(bar)
149 if not bar.modMenuOpts[moduleID] then
150 bar.modMenuOpts[moduleID] = {
151 }
152 end
153 return bar.modMenuOpts[moduleID]
154 end
155
156 function module:GetBarConfigOptions(bar)
157 if not bar.modConfigOpts[moduleID] then
158 bar.modConfigOpts[moduleID] = {
159 }
160 end
161 return bar.modConfigOpts[moduleID]
162 end
163
164
165
166 -- use-count of action IDs
167 local ActionIDList = setmetatable( {}, {
168 __index = function(self, idx)
169 if idx == nil then
170 for i = 1, 120 do
171 if rawget(self,i) == nil then
172 rawset(self,i,1)
173 return i
174 end
175 end
176 else
177 local c = rawget(self,idx) or 0
178 rawset(self,idx,c+1)
179 return idx
180 end
181 end,
182 __newindex = function(self,idx,value)
183 if value == nil then
184 value = rawget(self,idx)
185 if value == 1 then
186 value = nil
187 elseif value then
188 value = value - 1
189 end
190 end
191 rawset(self,idx,value)
192 end
193 })
194
195
196
197 -- button class methods
198 function Button:init( bar, idx, config )
199 BtnClass.super.prototype.init(self)
200 self.bar, self.idx, self.config = bar, idx, config
201
202 local barFrame = bar:GetFrame()
203
204 self.name = config.name or "ReAction_"..bar:GetName().."_"..idx
205 config.actionID = ActionIDList[config.actionID] -- gets a free one if none configured
206
207 local f = CreateFrame("CheckButton", self.name, barFrame, "ActionBarButtonTemplate")
208 -- TODO: re-implement ActionButton event handlers that don't do secure stuff
209
210 -- this will probably cause taint, using right now for display/debugging purposes
211 f:SetScript("OnAttributeChanged",
212 function()
213 ActionButton_UpdateAction()
214 end
215 )
216 f:SetAttribute("action", config.actionID)
217 barFrame:SetAttribute("addchild",f)
218 self.frame = f
219 self:Refresh(bar,idx)
220 end
221
222 function Button:Destroy()
223 local f = self.frame
224 f:UnregisterAllEvents()
225 f:Hide()
226 f:SetParent(UIParent)
227 f:ClearAllPoints()
228 if self.config.name then
229 _G[self.config.name] = nil
230 end
231 ActionIDList[self.config.actionID] = nil
232 self.frame = nil
233 self.config = nil
234 self.bar = nil
235 end
236
237 function Button:Refresh(bar,idx)
238 bar:PlaceButton(self.frame, idx, 36, 36)
239 end
240
241 function Button:GetFrame()
242 return self.frame
243 end
244
245 function Button:GetName()
246 return self.name
247 end
248
249 function Button:GetActionID()
250 return self.config.actionID
251 end