flickerstreak@24
|
1 --[[
|
flickerstreak@53
|
2 ReAction Action button module.
|
flickerstreak@24
|
3
|
flickerstreak@24
|
4 The button module implements standard action button functionality by wrapping Blizzard's
|
flickerstreak@87
|
5 ActionBarButtonTemplate frame and associated functions.
|
flickerstreak@77
|
6
|
flickerstreak@87
|
7 It also provides action remapping support for multiple pages and possessed targets
|
flickerstreak@90
|
8 (Mind Control, Eyes of the Beast, Karazhan Chess event, various quests, etc).
|
flickerstreak@24
|
9 --]]
|
flickerstreak@24
|
10
|
flickerstreak@24
|
11 -- local imports
|
flickerstreak@24
|
12 local ReAction = ReAction
|
flickerstreak@24
|
13 local L = ReAction.L
|
flickerstreak@24
|
14 local _G = _G
|
flickerstreak@24
|
15 local CreateFrame = CreateFrame
|
flickerstreak@88
|
16 local format = string.format
|
flickerstreak@92
|
17 local wipe = wipe
|
flickerstreak@24
|
18
|
flickerstreak@87
|
19 ReAction:UpdateRevision("$Revision$")
|
flickerstreak@77
|
20
|
flickerstreak@88
|
21 -- libraries
|
flickerstreak@88
|
22 local KB = LibStub("LibKeyBound-1.0")
|
flickerstreak@88
|
23
|
flickerstreak@24
|
24 -- module declaration
|
flickerstreak@24
|
25 local moduleID = "Action"
|
flickerstreak@28
|
26 local module = ReAction:NewModule( moduleID )
|
flickerstreak@24
|
27
|
flickerstreak@90
|
28 -- Class declarations
|
flickerstreak@77
|
29 local Button = { }
|
flickerstreak@90
|
30 local Handle = { }
|
flickerstreak@90
|
31 local PropHandler = { }
|
flickerstreak@87
|
32
|
flickerstreak@77
|
33 -- Event handlers
|
flickerstreak@24
|
34 function module:OnInitialize()
|
flickerstreak@28
|
35 self.db = ReAction.db:RegisterNamespace( moduleID,
|
flickerstreak@24
|
36 {
|
flickerstreak@28
|
37 profile = {
|
flickerstreak@75
|
38 bars = { },
|
flickerstreak@28
|
39 }
|
flickerstreak@24
|
40 }
|
flickerstreak@24
|
41 )
|
flickerstreak@90
|
42 self.handles = setmetatable({ }, weak)
|
flickerstreak@49
|
43
|
flickerstreak@63
|
44 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
|
flickerstreak@63
|
45
|
flickerstreak@90
|
46 ReAction.RegisterCallback(self, "OnCreateBar")
|
flickerstreak@90
|
47 ReAction.RegisterCallback(self, "OnRefreshBar")
|
flickerstreak@63
|
48 ReAction.RegisterCallback(self, "OnDestroyBar")
|
flickerstreak@63
|
49 ReAction.RegisterCallback(self, "OnEraseBar")
|
flickerstreak@63
|
50 ReAction.RegisterCallback(self, "OnRenameBar")
|
flickerstreak@63
|
51 ReAction.RegisterCallback(self, "OnConfigModeChanged")
|
flickerstreak@63
|
52
|
flickerstreak@88
|
53 KB.RegisterCallback(self, "LIBKEYBOUND_ENABLED")
|
flickerstreak@88
|
54 KB.RegisterCallback(self, "LIBKEYBOUND_DISABLED")
|
flickerstreak@88
|
55 KB.RegisterCallback(self, "LIBKEYBOUND_MODE_COLOR_CHANGED","LIBKEYBOUND_ENABLED")
|
flickerstreak@24
|
56 end
|
flickerstreak@24
|
57
|
flickerstreak@24
|
58 function module:OnEnable()
|
flickerstreak@53
|
59 ReAction:RegisterBarType(L["Action Bar"],
|
flickerstreak@53
|
60 {
|
flickerstreak@53
|
61 type = moduleID,
|
flickerstreak@91
|
62 defaultButtonSize = 36,
|
flickerstreak@53
|
63 defaultBarRows = 1,
|
flickerstreak@53
|
64 defaultBarCols = 12,
|
flickerstreak@53
|
65 defaultBarSpacing = 3
|
flickerstreak@53
|
66 }, true)
|
flickerstreak@90
|
67 ReAction:GetModule("State"):RegisterStateProperty("page", nil, PropHandler.GetOptions(), PropHandler)
|
flickerstreak@24
|
68 end
|
flickerstreak@24
|
69
|
flickerstreak@24
|
70 function module:OnDisable()
|
flickerstreak@53
|
71 ReAction:UnregisterBarType(L["Action Bar"])
|
flickerstreak@90
|
72 ReAction:GetModule("State"):UnregisterStateProperty("page")
|
flickerstreak@90
|
73 end
|
flickerstreak@90
|
74
|
flickerstreak@90
|
75 function module:OnCreateBar(event, bar, name)
|
flickerstreak@90
|
76 if bar.config.type == moduleID then
|
flickerstreak@90
|
77 local profile = self.db.profile
|
flickerstreak@90
|
78 if profile.bars[name] == nil then
|
flickerstreak@90
|
79 profile.bars[name] = {
|
flickerstreak@90
|
80 buttons = { }
|
flickerstreak@90
|
81 }
|
flickerstreak@90
|
82 end
|
flickerstreak@90
|
83 if self.handles[bar] == nil then
|
flickerstreak@90
|
84 self.handles[bar] = Handle:New(bar, profile.bars[name])
|
flickerstreak@90
|
85 end
|
flickerstreak@90
|
86 end
|
flickerstreak@24
|
87 end
|
flickerstreak@24
|
88
|
flickerstreak@63
|
89 function module:OnRefreshBar(event, bar, name)
|
flickerstreak@90
|
90 if self.handles[bar] then
|
flickerstreak@90
|
91 self.handles[bar]:Refresh()
|
flickerstreak@24
|
92 end
|
flickerstreak@24
|
93 end
|
flickerstreak@24
|
94
|
flickerstreak@63
|
95 function module:OnDestroyBar(event, bar, name)
|
flickerstreak@90
|
96 if self.handles[bar] then
|
flickerstreak@90
|
97 self.handles[bar]:Destroy()
|
flickerstreak@90
|
98 self.handles[bar] = nil
|
flickerstreak@24
|
99 end
|
flickerstreak@24
|
100 end
|
flickerstreak@24
|
101
|
flickerstreak@63
|
102 function module:OnEraseBar(event, bar, name)
|
flickerstreak@75
|
103 self.db.profile.bars[name] = nil
|
flickerstreak@24
|
104 end
|
flickerstreak@24
|
105
|
flickerstreak@63
|
106 function module:OnRenameBar(event, bar, oldname, newname)
|
flickerstreak@75
|
107 b = self.db.profile.bars
|
flickerstreak@75
|
108 b[newname], b[oldname] = b[oldname], nil
|
flickerstreak@48
|
109 end
|
flickerstreak@48
|
110
|
flickerstreak@63
|
111 function module:OnConfigModeChanged(event, mode)
|
flickerstreak@90
|
112 for _, h in pairs(self.handles) do
|
flickerstreak@90
|
113 h:SetConfigMode(mode)
|
flickerstreak@24
|
114 end
|
flickerstreak@24
|
115 end
|
flickerstreak@24
|
116
|
flickerstreak@88
|
117 function module:LIBKEYBOUND_ENABLED(evt)
|
flickerstreak@90
|
118 for _, h in pairs(self.handles) do
|
flickerstreak@90
|
119 h:SetKeybindMode(true)
|
flickerstreak@88
|
120 end
|
flickerstreak@88
|
121 end
|
flickerstreak@88
|
122
|
flickerstreak@88
|
123 function module:LIBKEYBOUND_DISABLED(evt)
|
flickerstreak@90
|
124 for _, h in pairs(self.handles) do
|
flickerstreak@90
|
125 h:SetKeybindMode(false)
|
flickerstreak@88
|
126 end
|
flickerstreak@88
|
127 end
|
flickerstreak@88
|
128
|
flickerstreak@50
|
129
|
flickerstreak@90
|
130 ---- Interface ----
|
flickerstreak@90
|
131 function module:GetBarOptions(bar)
|
flickerstreak@90
|
132 local h = self.handles[bar]
|
flickerstreak@90
|
133 if h then
|
flickerstreak@90
|
134 return h:GetOptions()
|
flickerstreak@90
|
135 end
|
flickerstreak@90
|
136 end
|
flickerstreak@90
|
137
|
flickerstreak@90
|
138
|
flickerstreak@90
|
139 ---- Bar Handle ----
|
flickerstreak@90
|
140
|
flickerstreak@87
|
141 do
|
flickerstreak@87
|
142 local options = {
|
flickerstreak@87
|
143 hideEmpty = {
|
flickerstreak@87
|
144 name = L["Hide Empty Buttons"],
|
flickerstreak@87
|
145 order = 1,
|
flickerstreak@87
|
146 type = "toggle",
|
flickerstreak@87
|
147 width = "double",
|
flickerstreak@87
|
148 get = "GetHideEmpty",
|
flickerstreak@87
|
149 set = "SetHideEmpty",
|
flickerstreak@87
|
150 },
|
flickerstreak@87
|
151 pages = {
|
flickerstreak@87
|
152 name = L["# Pages"],
|
flickerstreak@87
|
153 desc = L["Use the Dynamic State tab to specify page transitions"],
|
flickerstreak@87
|
154 order = 2,
|
flickerstreak@87
|
155 type = "range",
|
flickerstreak@87
|
156 min = 1,
|
flickerstreak@87
|
157 max = 10,
|
flickerstreak@87
|
158 step = 1,
|
flickerstreak@87
|
159 get = "GetNumPages",
|
flickerstreak@87
|
160 set = "SetNumPages",
|
flickerstreak@87
|
161 },
|
flickerstreak@90
|
162 mindcontrol = {
|
flickerstreak@90
|
163 name = L["Mind Control Support"],
|
flickerstreak@90
|
164 desc = L["When possessing a target (e.g. via Mind Control), map the first 12 buttons of this bar to the possessed target's actions."],
|
flickerstreak@90
|
165 order = 3,
|
flickerstreak@90
|
166 type = "toggle",
|
flickerstreak@90
|
167 width = "double",
|
flickerstreak@90
|
168 set = "SetMindControl",
|
flickerstreak@90
|
169 get = "GetMindControl",
|
flickerstreak@90
|
170 },
|
flickerstreak@87
|
171 actions = {
|
flickerstreak@87
|
172 name = L["Edit Action IDs"],
|
flickerstreak@90
|
173 order = 4,
|
flickerstreak@87
|
174 type = "group",
|
flickerstreak@87
|
175 inline = true,
|
flickerstreak@87
|
176 args = {
|
flickerstreak@87
|
177 method = {
|
flickerstreak@87
|
178 name = L["Assign"],
|
flickerstreak@87
|
179 order = 1,
|
flickerstreak@87
|
180 type = "select",
|
flickerstreak@87
|
181 width = "double",
|
flickerstreak@87
|
182 values = { [0] = L["Choose Method..."],
|
flickerstreak@87
|
183 [1] = L["Individually"],
|
flickerstreak@87
|
184 [2] = L["All at Once"], },
|
flickerstreak@87
|
185 get = "GetActionEditMethod",
|
flickerstreak@87
|
186 set = "SetActionEditMethod",
|
flickerstreak@87
|
187 },
|
flickerstreak@87
|
188 rowSelect = {
|
flickerstreak@87
|
189 name = L["Row"],
|
flickerstreak@87
|
190 desc = L["Rows are numbered top to bottom"],
|
flickerstreak@87
|
191 order = 2,
|
flickerstreak@87
|
192 type = "select",
|
flickerstreak@87
|
193 width = "half",
|
flickerstreak@87
|
194 hidden = "IsButtonSelectHidden",
|
flickerstreak@87
|
195 values = "GetRowList",
|
flickerstreak@87
|
196 get = "GetSelectedRow",
|
flickerstreak@87
|
197 set = "SetSelectedRow",
|
flickerstreak@87
|
198 },
|
flickerstreak@87
|
199 colSelect = {
|
flickerstreak@87
|
200 name = L["Col"],
|
flickerstreak@87
|
201 desc = L["Columns are numbered left to right"],
|
flickerstreak@87
|
202 order = 3,
|
flickerstreak@87
|
203 type = "select",
|
flickerstreak@87
|
204 width = "half",
|
flickerstreak@87
|
205 hidden = "IsButtonSelectHidden",
|
flickerstreak@87
|
206 values = "GetColumnList",
|
flickerstreak@87
|
207 get = "GetSelectedColumn",
|
flickerstreak@87
|
208 set = "SetSelectedColumn",
|
flickerstreak@87
|
209 },
|
flickerstreak@87
|
210 pageSelect = {
|
flickerstreak@87
|
211 name = L["Page"],
|
flickerstreak@87
|
212 order = 4,
|
flickerstreak@87
|
213 type = "select",
|
flickerstreak@87
|
214 width = "half",
|
flickerstreak@87
|
215 hidden = "IsPageSelectHidden",
|
flickerstreak@87
|
216 values = "GetPageList",
|
flickerstreak@87
|
217 get = "GetSelectedPage",
|
flickerstreak@87
|
218 set = "SetSelectedPage",
|
flickerstreak@87
|
219 },
|
flickerstreak@87
|
220 single = {
|
flickerstreak@87
|
221 name = L["Action ID"],
|
flickerstreak@87
|
222 usage = L["Specify ID 1-120"],
|
flickerstreak@87
|
223 order = 5,
|
flickerstreak@87
|
224 type = "input",
|
flickerstreak@87
|
225 width = "half",
|
flickerstreak@87
|
226 hidden = "IsButtonSelectHidden",
|
flickerstreak@87
|
227 get = "GetActionID",
|
flickerstreak@87
|
228 set = "SetActionID",
|
flickerstreak@87
|
229 validate = "ValidateActionID",
|
flickerstreak@87
|
230 },
|
flickerstreak@87
|
231 multi = {
|
flickerstreak@87
|
232 name = L["ID List"],
|
flickerstreak@87
|
233 usage = L["Specify a comma-separated list of IDs for each button in the bar (in order). Separate multiple pages with semicolons (;)"],
|
flickerstreak@87
|
234 order = 6,
|
flickerstreak@87
|
235 type = "input",
|
flickerstreak@87
|
236 multiline = true,
|
flickerstreak@87
|
237 width = "double",
|
flickerstreak@87
|
238 hidden = "IsMultiIDHidden",
|
flickerstreak@87
|
239 get = "GetMultiID",
|
flickerstreak@87
|
240 set = "SetMultiID",
|
flickerstreak@87
|
241 validate = "ValidateMultiID",
|
flickerstreak@90
|
242 },
|
flickerstreak@90
|
243 },
|
flickerstreak@87
|
244 },
|
flickerstreak@87
|
245 }
|
flickerstreak@77
|
246
|
flickerstreak@90
|
247 local weak = { __mode="k" }
|
flickerstreak@90
|
248 local meta = { __index = Handle }
|
flickerstreak@90
|
249
|
flickerstreak@90
|
250 function Handle:New( bar, config )
|
flickerstreak@90
|
251 local self = setmetatable(
|
flickerstreak@90
|
252 {
|
flickerstreak@90
|
253 bar = bar,
|
flickerstreak@90
|
254 config = config,
|
flickerstreak@90
|
255 btns = { }
|
flickerstreak@90
|
256 },
|
flickerstreak@90
|
257 meta)
|
flickerstreak@90
|
258
|
flickerstreak@90
|
259 if self.config.buttons == nil then
|
flickerstreak@90
|
260 self.config.buttons = { }
|
flickerstreak@90
|
261 end
|
flickerstreak@90
|
262 self:Refresh()
|
flickerstreak@92
|
263 self:SetKeybindMode(ReAction:GetKeybindMode())
|
flickerstreak@90
|
264 return self
|
flickerstreak@90
|
265 end
|
flickerstreak@90
|
266
|
flickerstreak@90
|
267 function Handle:Refresh()
|
flickerstreak@90
|
268 local r, c = self.bar:GetButtonGrid()
|
flickerstreak@90
|
269 local n = r*c
|
flickerstreak@90
|
270 local btnCfg = self.config.buttons
|
flickerstreak@90
|
271 if n ~= #self.btns then
|
flickerstreak@90
|
272 for i = 1, n do
|
flickerstreak@90
|
273 if btnCfg[i] == nil then
|
flickerstreak@90
|
274 btnCfg[i] = {}
|
flickerstreak@90
|
275 end
|
flickerstreak@90
|
276 if self.btns[i] == nil then
|
flickerstreak@90
|
277 local b = Button:New(self, i, btnCfg[i], self.config)
|
flickerstreak@90
|
278 self.btns[i] = b
|
flickerstreak@90
|
279 self.bar:AddButton(i,b)
|
flickerstreak@90
|
280 end
|
flickerstreak@90
|
281 end
|
flickerstreak@90
|
282 for i = n+1, #self.btns do
|
flickerstreak@90
|
283 if self.btns[i] then
|
flickerstreak@90
|
284 self.bar:RemoveButton(self.btns[i])
|
flickerstreak@90
|
285 self.btns[i]:Destroy()
|
flickerstreak@90
|
286 self.btns[i] = nil
|
flickerstreak@90
|
287 btnCfg[i] = nil
|
flickerstreak@90
|
288 end
|
flickerstreak@90
|
289 end
|
flickerstreak@90
|
290 end
|
flickerstreak@90
|
291 for _, b in ipairs(self.btns) do
|
flickerstreak@90
|
292 b:Refresh()
|
flickerstreak@90
|
293 end
|
flickerstreak@90
|
294 local f = self.bar:GetFrame()
|
flickerstreak@90
|
295 f:SetAttribute("mindcontrol",self.config.mindcontrol)
|
flickerstreak@90
|
296 f:Execute(
|
flickerstreak@90
|
297 [[
|
flickerstreak@90
|
298 doMindControl = self:GetAttribute("mindcontrol")
|
flickerstreak@90
|
299 control:ChildUpdate()
|
flickerstreak@90
|
300 ]])
|
flickerstreak@90
|
301
|
flickerstreak@90
|
302 f:SetAttribute("_onstate-mindcontrol",
|
flickerstreak@90
|
303 -- function _onstate-mindcontrol(self, stateid, newstate)
|
flickerstreak@90
|
304 [[
|
flickerstreak@90
|
305 control:ChildUpdate()
|
flickerstreak@90
|
306 ]])
|
flickerstreak@90
|
307 RegisterStateDriver(f, "mindcontrol", "[bonusbar:5] mc; none")
|
flickerstreak@90
|
308 end
|
flickerstreak@90
|
309
|
flickerstreak@90
|
310 function Handle:Destroy()
|
flickerstreak@90
|
311 for _,b in pairs(self.btns) do
|
flickerstreak@90
|
312 if b then
|
flickerstreak@90
|
313 b:Destroy()
|
flickerstreak@90
|
314 end
|
flickerstreak@90
|
315 end
|
flickerstreak@90
|
316 end
|
flickerstreak@90
|
317
|
flickerstreak@90
|
318 function Handle:SetConfigMode(mode)
|
flickerstreak@90
|
319 for _, b in pairs(self.btns) do
|
flickerstreak@90
|
320 b:ShowGrid(mode)
|
flickerstreak@90
|
321 b:ShowActionIDLabel(mode)
|
flickerstreak@90
|
322 end
|
flickerstreak@90
|
323 end
|
flickerstreak@90
|
324
|
flickerstreak@90
|
325 function Handle:SetKeybindMode(mode)
|
flickerstreak@90
|
326 for _, b in pairs(self.btns) do
|
flickerstreak@90
|
327 if mode then
|
flickerstreak@90
|
328 -- set the border for all buttons to the keybind-enable color
|
flickerstreak@92
|
329 b.border:SetVertexColor(KB:GetColorKeyBoundMode())
|
flickerstreak@90
|
330 b.border:Show()
|
flickerstreak@92
|
331 elseif IsEquippedAction(b:GetActionID()) then
|
flickerstreak@92
|
332 b.border:SetVertexColor(0, 1.0, 0, 0.35) -- from ActionButton.lua
|
flickerstreak@90
|
333 else
|
flickerstreak@90
|
334 b.border:Hide()
|
flickerstreak@90
|
335 end
|
flickerstreak@90
|
336 end
|
flickerstreak@90
|
337 end
|
flickerstreak@90
|
338
|
flickerstreak@90
|
339 function Handle:GetLastButton()
|
flickerstreak@90
|
340 return self.btns[#self.btns]
|
flickerstreak@90
|
341 end
|
flickerstreak@90
|
342
|
flickerstreak@90
|
343 -- options handlers
|
flickerstreak@90
|
344 function Handle:GetOptions()
|
flickerstreak@87
|
345 return {
|
flickerstreak@87
|
346 type = "group",
|
flickerstreak@87
|
347 name = L["Action Buttons"],
|
flickerstreak@90
|
348 handler = self,
|
flickerstreak@87
|
349 args = options
|
flickerstreak@87
|
350 }
|
flickerstreak@77
|
351 end
|
flickerstreak@77
|
352
|
flickerstreak@90
|
353 function Handle:SetHideEmpty(info, value)
|
flickerstreak@90
|
354 if value ~= self.config.hideEmpty then
|
flickerstreak@77
|
355 for b in self.bar:IterateButtons() do
|
flickerstreak@77
|
356 b:ShowGrid(not value)
|
flickerstreak@77
|
357 end
|
flickerstreak@90
|
358 self.config.hideEmpty = value
|
flickerstreak@77
|
359 end
|
flickerstreak@77
|
360 end
|
flickerstreak@77
|
361
|
flickerstreak@90
|
362 function Handle:GetHideEmpty()
|
flickerstreak@90
|
363 return self.config.hideEmpty
|
flickerstreak@77
|
364 end
|
flickerstreak@87
|
365
|
flickerstreak@90
|
366 function Handle:GetNumPages()
|
flickerstreak@90
|
367 return self.config.nPages
|
flickerstreak@87
|
368 end
|
flickerstreak@87
|
369
|
flickerstreak@90
|
370 function Handle:SetNumPages(info, value)
|
flickerstreak@90
|
371 self.config.nPages = value
|
flickerstreak@90
|
372 self:Refresh()
|
flickerstreak@87
|
373 end
|
flickerstreak@87
|
374
|
flickerstreak@90
|
375 function Handle:GetMindControl()
|
flickerstreak@90
|
376 return self.config.mindcontrol
|
flickerstreak@90
|
377 end
|
flickerstreak@90
|
378
|
flickerstreak@90
|
379 function Handle:SetMindControl(info, value)
|
flickerstreak@90
|
380 self.config.mindcontrol = value
|
flickerstreak@90
|
381 self:Refresh()
|
flickerstreak@90
|
382 end
|
flickerstreak@90
|
383
|
flickerstreak@90
|
384 function Handle:GetActionEditMethod()
|
flickerstreak@87
|
385 return self.editMethod or 0
|
flickerstreak@87
|
386 end
|
flickerstreak@87
|
387
|
flickerstreak@90
|
388 function Handle:SetActionEditMethod(info, value)
|
flickerstreak@87
|
389 self.editMethod = value
|
flickerstreak@87
|
390 end
|
flickerstreak@87
|
391
|
flickerstreak@90
|
392 function Handle:IsButtonSelectHidden()
|
flickerstreak@87
|
393 return self.editMethod ~= 1
|
flickerstreak@87
|
394 end
|
flickerstreak@87
|
395
|
flickerstreak@90
|
396 function Handle:GetRowList()
|
flickerstreak@87
|
397 local r,c = self.bar:GetButtonGrid()
|
flickerstreak@87
|
398 if self.rowList == nil or #self.rowList ~= r then
|
flickerstreak@87
|
399 local list = { }
|
flickerstreak@87
|
400 for i = 1, r do
|
flickerstreak@87
|
401 table.insert(list,i)
|
flickerstreak@87
|
402 end
|
flickerstreak@87
|
403 self.rowList = list
|
flickerstreak@87
|
404 end
|
flickerstreak@87
|
405 return self.rowList
|
flickerstreak@87
|
406 end
|
flickerstreak@87
|
407
|
flickerstreak@90
|
408 function Handle:GetSelectedRow()
|
flickerstreak@87
|
409 local r, c = self.bar:GetButtonGrid()
|
flickerstreak@87
|
410 local row = self.selectedRow or 1
|
flickerstreak@87
|
411 if row > r then
|
flickerstreak@87
|
412 row = 1
|
flickerstreak@87
|
413 end
|
flickerstreak@87
|
414 self.selectedRow = row
|
flickerstreak@87
|
415 return row
|
flickerstreak@87
|
416 end
|
flickerstreak@87
|
417
|
flickerstreak@90
|
418 function Handle:SetSelectedRow(info, value)
|
flickerstreak@87
|
419 self.selectedRow = value
|
flickerstreak@87
|
420 end
|
flickerstreak@87
|
421
|
flickerstreak@90
|
422 function Handle:GetColumnList()
|
flickerstreak@87
|
423 local r,c = self.bar:GetButtonGrid()
|
flickerstreak@87
|
424 if self.columnList == nil or #self.columnList ~= c then
|
flickerstreak@87
|
425 local list = { }
|
flickerstreak@87
|
426 for i = 1, c do
|
flickerstreak@87
|
427 table.insert(list,i)
|
flickerstreak@87
|
428 end
|
flickerstreak@87
|
429 self.columnList = list
|
flickerstreak@87
|
430 end
|
flickerstreak@87
|
431 return self.columnList
|
flickerstreak@87
|
432 end
|
flickerstreak@87
|
433
|
flickerstreak@90
|
434 function Handle:GetSelectedColumn()
|
flickerstreak@87
|
435 local r, c = self.bar:GetButtonGrid()
|
flickerstreak@87
|
436 local col = self.selectedColumn or 1
|
flickerstreak@87
|
437 if col > c then
|
flickerstreak@87
|
438 col = 1
|
flickerstreak@87
|
439 end
|
flickerstreak@87
|
440 self.selectedColumn = col
|
flickerstreak@87
|
441 return col
|
flickerstreak@87
|
442 end
|
flickerstreak@87
|
443
|
flickerstreak@90
|
444 function Handle:SetSelectedColumn(info, value)
|
flickerstreak@87
|
445 self.selectedColumn = value
|
flickerstreak@87
|
446 end
|
flickerstreak@87
|
447
|
flickerstreak@90
|
448 function Handle:IsPageSelectHidden()
|
flickerstreak@90
|
449 return self.editMethod ~= 1 or (self.config.nPages or 1) < 2
|
flickerstreak@87
|
450 end
|
flickerstreak@87
|
451
|
flickerstreak@90
|
452 function Handle:GetPageList()
|
flickerstreak@90
|
453 local n = self.config.nPages or 1
|
flickerstreak@87
|
454 if self.pageList == nil or #self.pageList ~= n then
|
flickerstreak@87
|
455 local p = { }
|
flickerstreak@87
|
456 for i = 1, n do
|
flickerstreak@87
|
457 table.insert(p,i)
|
flickerstreak@87
|
458 end
|
flickerstreak@87
|
459 self.pageList = p
|
flickerstreak@87
|
460 end
|
flickerstreak@87
|
461 return self.pageList
|
flickerstreak@87
|
462 end
|
flickerstreak@87
|
463
|
flickerstreak@90
|
464 function Handle:GetSelectedPage()
|
flickerstreak@87
|
465 local p = self.selectedPage or 1
|
flickerstreak@90
|
466 if p > (self.config.nPages or 1) then
|
flickerstreak@87
|
467 p = 1
|
flickerstreak@87
|
468 end
|
flickerstreak@87
|
469 self.selectedPage = p
|
flickerstreak@87
|
470 return p
|
flickerstreak@87
|
471 end
|
flickerstreak@87
|
472
|
flickerstreak@90
|
473 function Handle:SetSelectedPage(info, value)
|
flickerstreak@87
|
474 self.selectedPage = value
|
flickerstreak@87
|
475 end
|
flickerstreak@87
|
476
|
flickerstreak@90
|
477 function Handle:GetActionID()
|
flickerstreak@87
|
478 local row = self.selectedRow or 1
|
flickerstreak@87
|
479 local col = self.selectedColumn or 1
|
flickerstreak@87
|
480 local r, c = self.bar:GetButtonGrid()
|
flickerstreak@87
|
481 local n = (row-1) * c + col
|
flickerstreak@90
|
482 local btn = self.btns[n]
|
flickerstreak@87
|
483 if btn then
|
flickerstreak@87
|
484 return tostring(btn:GetActionID(self.selectedPage or 1))
|
flickerstreak@87
|
485 end
|
flickerstreak@87
|
486 end
|
flickerstreak@87
|
487
|
flickerstreak@90
|
488 function Handle:SetActionID(info, value)
|
flickerstreak@87
|
489 local row = self.selectedRow or 1
|
flickerstreak@87
|
490 local col = self.selectedColumn or 1
|
flickerstreak@87
|
491 local r, c = self.bar:GetButtonGrid()
|
flickerstreak@87
|
492 local n = (row-1) * c + col
|
flickerstreak@90
|
493 local btn = self.btns[n]
|
flickerstreak@87
|
494 if btn then
|
flickerstreak@87
|
495 btn:SetActionID(tonumber(value), self.selectedPage or 1)
|
flickerstreak@87
|
496 end
|
flickerstreak@87
|
497 end
|
flickerstreak@87
|
498
|
flickerstreak@90
|
499 function Handle:ValidateActionID(info, value)
|
flickerstreak@87
|
500 value = tonumber(value)
|
flickerstreak@87
|
501 if value == nil or value < 1 or value > 120 then
|
flickerstreak@87
|
502 return L["Specify ID 1-120"]
|
flickerstreak@87
|
503 end
|
flickerstreak@87
|
504 return true
|
flickerstreak@87
|
505 end
|
flickerstreak@87
|
506
|
flickerstreak@90
|
507 function Handle:IsMultiIDHidden()
|
flickerstreak@87
|
508 return self.editMethod ~= 2
|
flickerstreak@87
|
509 end
|
flickerstreak@87
|
510
|
flickerstreak@90
|
511 function Handle:GetMultiID()
|
flickerstreak@87
|
512 local p = { }
|
flickerstreak@90
|
513 for i = 1, self.config.nPages or 1 do
|
flickerstreak@87
|
514 local b = { }
|
flickerstreak@90
|
515 for _, btn in ipairs(self.btns) do
|
flickerstreak@87
|
516 table.insert(b, btn:GetActionID(i))
|
flickerstreak@87
|
517 end
|
flickerstreak@87
|
518 table.insert(p, table.concat(b,","))
|
flickerstreak@87
|
519 end
|
flickerstreak@87
|
520 return table.concat(p,";\n")
|
flickerstreak@87
|
521 end
|
flickerstreak@87
|
522
|
flickerstreak@87
|
523
|
flickerstreak@87
|
524 local function ParseMultiID(nBtns, nPages, s)
|
flickerstreak@87
|
525 if s:match("[^%d%s,;]") then
|
flickerstreak@87
|
526 ReAction:Print("items other than digits, spaces, commas, and semicolons in string",s)
|
flickerstreak@87
|
527 return nil
|
flickerstreak@87
|
528 end
|
flickerstreak@87
|
529 local p = { }
|
flickerstreak@87
|
530 for list in s:gmatch("[^;]+") do
|
flickerstreak@87
|
531 local pattern = ("^%s?$"):format(("%s*(%d+)%s*,"):rep(nBtns))
|
flickerstreak@87
|
532 local ids = { list:match(pattern) }
|
flickerstreak@87
|
533 if #ids ~= nBtns then
|
flickerstreak@87
|
534 ReAction:Print("found",#ids,"buttons instead of",nBtns)
|
flickerstreak@87
|
535 return nil
|
flickerstreak@87
|
536 end
|
flickerstreak@87
|
537 table.insert(p,ids)
|
flickerstreak@87
|
538 end
|
flickerstreak@87
|
539 if #p ~= nPages then
|
flickerstreak@87
|
540 ReAction:Print("found",#p,"pages instead of",nPages)
|
flickerstreak@87
|
541 return nil
|
flickerstreak@87
|
542 end
|
flickerstreak@87
|
543 return p
|
flickerstreak@87
|
544 end
|
flickerstreak@87
|
545
|
flickerstreak@90
|
546 function Handle:SetMultiID(info, value)
|
flickerstreak@91
|
547 local p = ParseMultiID(#self.btns, self.config.nPages or 1, value)
|
flickerstreak@87
|
548 for page, b in ipairs(p) do
|
flickerstreak@87
|
549 for button, id in ipairs(b) do
|
flickerstreak@90
|
550 self.btns[button]:SetActionID(id, page)
|
flickerstreak@87
|
551 end
|
flickerstreak@87
|
552 end
|
flickerstreak@87
|
553 end
|
flickerstreak@87
|
554
|
flickerstreak@90
|
555 function Handle:ValidateMultiID(info, value)
|
flickerstreak@87
|
556 local bad = L["Invalid action ID list string"]
|
flickerstreak@90
|
557 if value == nil or ParseMultiID(#self.btns, self.config.nPages or 1, value) == nil then
|
flickerstreak@87
|
558 return bad
|
flickerstreak@87
|
559 end
|
flickerstreak@87
|
560 return true
|
flickerstreak@87
|
561 end
|
flickerstreak@77
|
562 end
|
flickerstreak@77
|
563
|
flickerstreak@77
|
564
|
flickerstreak@87
|
565 ------ State property options ------
|
flickerstreak@87
|
566 do
|
flickerstreak@87
|
567 local pageOptions = {
|
flickerstreak@87
|
568 page = {
|
flickerstreak@92
|
569 name = L["Show Page #"],
|
flickerstreak@92
|
570 order = 11,
|
flickerstreak@92
|
571 type = "select",
|
flickerstreak@92
|
572 width = "half",
|
flickerstreak@87
|
573 disabled = "IsPageDisabled",
|
flickerstreak@87
|
574 hidden = "IsPageHidden",
|
flickerstreak@87
|
575 values = "GetPageValues",
|
flickerstreak@87
|
576 set = "SetProp",
|
flickerstreak@87
|
577 get = "GetPage",
|
flickerstreak@87
|
578 },
|
flickerstreak@87
|
579 }
|
flickerstreak@50
|
580
|
flickerstreak@90
|
581 local function GetBarConfig(bar)
|
flickerstreak@90
|
582 return module.db.profile.bars[bar:GetName()]
|
flickerstreak@87
|
583 end
|
flickerstreak@87
|
584
|
flickerstreak@90
|
585 function PropHandler.GetOptions()
|
flickerstreak@90
|
586 return pageOptions
|
flickerstreak@87
|
587 end
|
flickerstreak@87
|
588
|
flickerstreak@90
|
589 function PropHandler:IsPageDisabled()
|
flickerstreak@90
|
590 local c = GetBarConfig(self.bar)
|
flickerstreak@90
|
591 local n = c and c.nPages or 1
|
flickerstreak@90
|
592 return not (n > 1)
|
flickerstreak@87
|
593 end
|
flickerstreak@87
|
594
|
flickerstreak@90
|
595 function PropHandler:IsPageHidden()
|
flickerstreak@87
|
596 return not GetBarConfig(self.bar)
|
flickerstreak@87
|
597 end
|
flickerstreak@87
|
598
|
flickerstreak@90
|
599 function PropHandler:GetPageValues()
|
flickerstreak@92
|
600 if not self._pagevalues then
|
flickerstreak@92
|
601 self._pagevalues = { }
|
flickerstreak@92
|
602 end
|
flickerstreak@87
|
603 local c = GetBarConfig(self.bar)
|
flickerstreak@87
|
604 if c then
|
flickerstreak@87
|
605 local n = c.nPages
|
flickerstreak@92
|
606 -- cache the results
|
flickerstreak@87
|
607 if self._npages ~= n then
|
flickerstreak@87
|
608 self._npages = n
|
flickerstreak@92
|
609 wipe(self._pagevalues)
|
flickerstreak@87
|
610 for i = 1, n do
|
flickerstreak@90
|
611 self._pagevalues["page"..i] = i
|
flickerstreak@87
|
612 end
|
flickerstreak@87
|
613 end
|
flickerstreak@87
|
614 end
|
flickerstreak@92
|
615 return self._pagevalues
|
flickerstreak@87
|
616 end
|
flickerstreak@87
|
617
|
flickerstreak@90
|
618 function PropHandler:GetPage(info)
|
flickerstreak@87
|
619 return self:GetProp(info) or 1
|
flickerstreak@87
|
620 end
|
flickerstreak@90
|
621
|
flickerstreak@87
|
622 end
|
flickerstreak@87
|
623
|
flickerstreak@87
|
624 ------ ActionID allocation ------
|
flickerstreak@87
|
625 -- this needs to be high performance when requesting new IDs,
|
flickerstreak@87
|
626 -- or certain controls will become sluggish. However, the new-request
|
flickerstreak@87
|
627 -- infrastructure can be built lazily the first time that a new request
|
flickerstreak@87
|
628 -- comes in (which will only happen at user config time: at static startup
|
flickerstreak@87
|
629 -- config time all actionIDs should already have been assigned and stored
|
flickerstreak@87
|
630 -- in the config file)
|
flickerstreak@87
|
631
|
flickerstreak@87
|
632 local IDAlloc
|
flickerstreak@87
|
633 do
|
flickerstreak@87
|
634 local n = 120
|
flickerstreak@87
|
635
|
flickerstreak@87
|
636 IDAlloc = setmetatable({ wrap = 1, freecount = n }, {__index = function() return 0 end})
|
flickerstreak@87
|
637
|
flickerstreak@87
|
638 function IDAlloc:Acquire(id, hint)
|
flickerstreak@87
|
639 id = tonumber(id)
|
flickerstreak@87
|
640 hint = tonumber(hint)
|
flickerstreak@87
|
641 if id and (id < 1 or id > n) then
|
flickerstreak@87
|
642 id = nil
|
flickerstreak@87
|
643 end
|
flickerstreak@87
|
644 if hint and (hint < 1 or hint > n) then
|
flickerstreak@87
|
645 hint = nil
|
flickerstreak@87
|
646 end
|
flickerstreak@87
|
647 if id == nil then
|
flickerstreak@87
|
648 -- get a free ID
|
flickerstreak@87
|
649 if hint and self[hint] == 0 then
|
flickerstreak@87
|
650 -- use the hint if it's free
|
flickerstreak@87
|
651 id = hint
|
flickerstreak@87
|
652 elseif self.freecount > 0 then
|
flickerstreak@87
|
653 -- if neither the id nor the hint are defined or free, but
|
flickerstreak@87
|
654 -- the list is known to have free IDs, then start searching
|
flickerstreak@87
|
655 -- at the hint for a free one
|
flickerstreak@87
|
656 for i = hint or 1, n do
|
flickerstreak@87
|
657 if self[i] == 0 then
|
flickerstreak@87
|
658 id = i
|
flickerstreak@87
|
659 break
|
flickerstreak@87
|
660 end
|
flickerstreak@87
|
661 end
|
flickerstreak@87
|
662 -- self.wrap the search
|
flickerstreak@87
|
663 if id == nil and hint and hint > 1 then
|
flickerstreak@87
|
664 for i = 1, hint - 1 do
|
flickerstreak@87
|
665 if self[i] == 0 then
|
flickerstreak@87
|
666 id = i
|
flickerstreak@87
|
667 break
|
flickerstreak@87
|
668 end
|
flickerstreak@87
|
669 end
|
flickerstreak@87
|
670 end
|
flickerstreak@87
|
671 end
|
flickerstreak@87
|
672 if id == nil then
|
flickerstreak@87
|
673 -- if there are no free IDs, start wrapping at 1
|
flickerstreak@87
|
674 id = self.wrap
|
flickerstreak@87
|
675 self.wrap = id + 1
|
flickerstreak@87
|
676 if self.wrap > n then
|
flickerstreak@87
|
677 self.wrap = 1
|
flickerstreak@87
|
678 end
|
flickerstreak@24
|
679 end
|
flickerstreak@24
|
680 end
|
flickerstreak@87
|
681 if self[id] == 0 then
|
flickerstreak@87
|
682 self.freecount = self.freecount - 1
|
flickerstreak@87
|
683 end
|
flickerstreak@87
|
684 self[id] = self[id] + 1
|
flickerstreak@87
|
685 return id
|
flickerstreak@24
|
686 end
|
flickerstreak@24
|
687
|
flickerstreak@87
|
688 function IDAlloc:Release(id)
|
flickerstreak@87
|
689 id = tonumber(id)
|
flickerstreak@87
|
690 if id and (id >= 1 or id <= n) then
|
flickerstreak@87
|
691 self[id] = self[id] - 1
|
flickerstreak@87
|
692 if self[id] == 0 then
|
flickerstreak@87
|
693 self.freecount = self.freecount + 1
|
flickerstreak@87
|
694 self.wrap = 1
|
flickerstreak@87
|
695 end
|
flickerstreak@87
|
696 end
|
flickerstreak@87
|
697 end
|
flickerstreak@87
|
698 end
|
flickerstreak@87
|
699
|
flickerstreak@88
|
700 ------ Button class ------
|
flickerstreak@88
|
701
|
flickerstreak@88
|
702 do
|
flickerstreak@90
|
703 local frameRecycler = { }
|
flickerstreak@90
|
704 local trash = CreateFrame("Frame")
|
flickerstreak@90
|
705 local OnUpdate, KBAttach, GetActionName, GetHotkey, SetKey, FreeKey, ClearBindings, GetBindings
|
flickerstreak@90
|
706 do
|
flickerstreak@90
|
707 local ATTACK_BUTTON_FLASH_TIME = ATTACK_BUTTON_FLASH_TIME
|
flickerstreak@90
|
708 local IsActionInRange = IsActionInRange
|
flickerstreak@87
|
709
|
flickerstreak@90
|
710 local buttonLookup = setmetatable({},{__mode="kv"})
|
flickerstreak@88
|
711
|
flickerstreak@90
|
712 function OnUpdate(frame, elapsed)
|
flickerstreak@90
|
713 -- note: This function taints frame.flashtime and frame.rangeTimer. Both of these
|
flickerstreak@90
|
714 -- are only read by ActionButton_OnUpdate (which this function replaces). In
|
flickerstreak@90
|
715 -- all other places they're just written, so it doesn't taint any secure code.
|
flickerstreak@90
|
716 if frame.flashing == 1 then
|
flickerstreak@90
|
717 frame.flashtime = frame.flashtime - elapsed
|
flickerstreak@90
|
718 if frame.flashtime <= 0 then
|
flickerstreak@90
|
719 local overtime = -frame.flashtime
|
flickerstreak@90
|
720 if overtime >= ATTACK_BUTTON_FLASH_TIME then
|
flickerstreak@90
|
721 overtime = 0
|
flickerstreak@90
|
722 end
|
flickerstreak@90
|
723 frame.flashtime = ATTACK_BUTTON_FLASH_TIME - overtime
|
flickerstreak@90
|
724
|
flickerstreak@90
|
725 local flashTexture = frame.flash
|
flickerstreak@90
|
726 if flashTexture:IsShown() then
|
flickerstreak@90
|
727 flashTexture:Hide()
|
flickerstreak@90
|
728 else
|
flickerstreak@90
|
729 flashTexture:Show()
|
flickerstreak@90
|
730 end
|
flickerstreak@88
|
731 end
|
flickerstreak@90
|
732 end
|
flickerstreak@90
|
733
|
flickerstreak@90
|
734 if frame.rangeTimer then
|
flickerstreak@90
|
735 frame.rangeTimer = frame.rangeTimer - elapsed;
|
flickerstreak@88
|
736
|
flickerstreak@90
|
737 if frame.rangeTimer <= 0 then
|
flickerstreak@90
|
738 if IsActionInRange(frame.action) == 0 then
|
flickerstreak@90
|
739 frame.icon:SetVertexColor(1.0,0.1,0.1)
|
flickerstreak@90
|
740 else
|
flickerstreak@90
|
741 ActionButton_UpdateUsable(frame)
|
flickerstreak@90
|
742 end
|
flickerstreak@90
|
743 frame.rangeTimer = 0.1
|
flickerstreak@88
|
744 end
|
flickerstreak@88
|
745 end
|
flickerstreak@88
|
746 end
|
flickerstreak@90
|
747
|
flickerstreak@90
|
748 -- Use KeyBound-1.0 for binding, but use Override bindings instead of
|
flickerstreak@90
|
749 -- regular bindings to support multiple profile use. This is a little
|
flickerstreak@90
|
750 -- weird with the KeyBound dialog box (which has per-char selector as well
|
flickerstreak@90
|
751 -- as an OK/Cancel box) but it's the least amount of effort to implement.
|
flickerstreak@90
|
752 function GetActionName(f)
|
flickerstreak@90
|
753 local b = buttonLookup[f]
|
flickerstreak@90
|
754 if b then
|
flickerstreak@90
|
755 return format("%s:%s", b.bar:GetName(), b.idx)
|
flickerstreak@90
|
756 end
|
flickerstreak@90
|
757 end
|
flickerstreak@90
|
758
|
flickerstreak@90
|
759 function GetHotkey(f)
|
flickerstreak@90
|
760 local b = buttonLookup[f]
|
flickerstreak@90
|
761 if b then
|
flickerstreak@90
|
762 return KB:ToShortKey(b:GetConfig().hotkey)
|
flickerstreak@90
|
763 end
|
flickerstreak@90
|
764 end
|
flickerstreak@90
|
765
|
flickerstreak@90
|
766 function SetKey(f, key)
|
flickerstreak@90
|
767 local b = buttonLookup[f]
|
flickerstreak@90
|
768 if b then
|
flickerstreak@90
|
769 local c = b:GetConfig()
|
flickerstreak@90
|
770 if c.hotkey then
|
flickerstreak@90
|
771 SetOverrideBinding(f, false, c.hotkey, nil)
|
flickerstreak@90
|
772 end
|
flickerstreak@90
|
773 if key then
|
flickerstreak@90
|
774 SetOverrideBindingClick(f, false, key, f:GetName(), nil)
|
flickerstreak@90
|
775 end
|
flickerstreak@90
|
776 c.hotkey = key
|
flickerstreak@90
|
777 b:DisplayHotkey(GetHotkey(f))
|
flickerstreak@90
|
778 end
|
flickerstreak@90
|
779 end
|
flickerstreak@90
|
780
|
flickerstreak@90
|
781 function FreeKey(f, key)
|
flickerstreak@90
|
782 local b = buttonLookup[f]
|
flickerstreak@90
|
783 if b then
|
flickerstreak@90
|
784 local c = b:GetConfig()
|
flickerstreak@90
|
785 if c.hotkey == key then
|
flickerstreak@90
|
786 local action = f:GetActionName()
|
flickerstreak@90
|
787 SetOverrideBinding(f, false, c.hotkey, nil)
|
flickerstreak@90
|
788 c.hotkey = nil
|
flickerstreak@90
|
789 b:DisplayHotkey(nil)
|
flickerstreak@90
|
790 return action
|
flickerstreak@90
|
791 end
|
flickerstreak@90
|
792 end
|
flickerstreak@90
|
793 return ReAction:FreeOverrideHotkey(key)
|
flickerstreak@90
|
794 end
|
flickerstreak@90
|
795
|
flickerstreak@90
|
796 function ClearBindings(f)
|
flickerstreak@90
|
797 SetKey(f, nil)
|
flickerstreak@90
|
798 end
|
flickerstreak@90
|
799
|
flickerstreak@90
|
800 function GetBindings(f)
|
flickerstreak@90
|
801 local b = buttonLookup[f]
|
flickerstreak@90
|
802 if b then
|
flickerstreak@90
|
803 return b:GetConfig().hotkey
|
flickerstreak@90
|
804 end
|
flickerstreak@90
|
805 end
|
flickerstreak@90
|
806
|
flickerstreak@90
|
807 function KBAttach( button )
|
flickerstreak@90
|
808 local f = button:GetFrame()
|
flickerstreak@90
|
809 f.GetActionName = GetActionName
|
flickerstreak@90
|
810 f.GetHotkey = GetHotkey
|
flickerstreak@90
|
811 f.SetKey = SetKey
|
flickerstreak@90
|
812 f.FreeKey = FreeKey
|
flickerstreak@90
|
813 f.ClearBindings = ClearBindings
|
flickerstreak@90
|
814 f.GetBindings = GetBindings
|
flickerstreak@90
|
815 buttonLookup[f] = button
|
flickerstreak@90
|
816 f:SetKey(button:GetConfig().hotkey)
|
flickerstreak@90
|
817 ReAction:RegisterKeybindFrame(f)
|
flickerstreak@92
|
818 if ReAction:GetKeybindMode() then
|
flickerstreak@92
|
819 button.border:SetVertexColor(KB:GetColorKeyBoundMode())
|
flickerstreak@92
|
820 button.border:Show()
|
flickerstreak@92
|
821 end
|
flickerstreak@90
|
822 end
|
flickerstreak@90
|
823 end
|
flickerstreak@90
|
824
|
flickerstreak@90
|
825 local meta = {__index = Button}
|
flickerstreak@90
|
826
|
flickerstreak@90
|
827 function Button:New( handle, idx, config, barConfig )
|
flickerstreak@90
|
828 local bar = handle.bar
|
flickerstreak@90
|
829
|
flickerstreak@90
|
830 -- create new self
|
flickerstreak@90
|
831 self = setmetatable(
|
flickerstreak@90
|
832 {
|
flickerstreak@90
|
833 bar = bar,
|
flickerstreak@90
|
834 idx = idx,
|
flickerstreak@90
|
835 config = config,
|
flickerstreak@90
|
836 barConfig = barConfig,
|
flickerstreak@90
|
837 }, meta )
|
flickerstreak@90
|
838
|
flickerstreak@90
|
839 local name = config.name or ("ReAction_%s_%s_%d"):format(bar:GetName(),moduleID,idx)
|
flickerstreak@90
|
840 self.name = name
|
flickerstreak@90
|
841 config.name = name
|
flickerstreak@90
|
842 local lastButton = handle:GetLastButton()
|
flickerstreak@90
|
843 config.actionID = IDAlloc:Acquire(config.actionID, lastButton and lastButton.config.actionID) -- gets a free one if none configured
|
flickerstreak@90
|
844 self.nPages = 1
|
flickerstreak@88
|
845
|
flickerstreak@90
|
846 -- have to recycle frames with the same name: CreateFrame() doesn't overwrite
|
flickerstreak@90
|
847 -- existing globals. Can't set to nil in the global because it's then tainted.
|
flickerstreak@90
|
848 local parent = bar:GetFrame()
|
flickerstreak@90
|
849 local f = frameRecycler[name]
|
flickerstreak@90
|
850 if f then
|
flickerstreak@90
|
851 f:SetParent(parent)
|
flickerstreak@90
|
852 else
|
flickerstreak@90
|
853 f = CreateFrame("CheckButton", name, parent, "ActionBarButtonTemplate")
|
flickerstreak@90
|
854 -- ditch the old hotkey text because it's tied in ActionButton_Update() to the
|
flickerstreak@90
|
855 -- standard binding. We use override bindings.
|
flickerstreak@90
|
856 local hotkey = _G[name.."HotKey"]
|
flickerstreak@90
|
857 hotkey:SetParent(trash)
|
flickerstreak@90
|
858 hotkey = f:CreateFontString(nil, "ARTWORK", "NumberFontNormalSmallGray")
|
flickerstreak@90
|
859 hotkey:SetWidth(36)
|
flickerstreak@90
|
860 hotkey:SetHeight(18)
|
flickerstreak@90
|
861 hotkey:SetJustifyH("RIGHT")
|
flickerstreak@90
|
862 hotkey:SetJustifyV("TOP")
|
flickerstreak@90
|
863 hotkey:SetPoint("TOPLEFT",f,"TOPLEFT",-2,-2)
|
flickerstreak@90
|
864 f.hotkey = hotkey
|
flickerstreak@90
|
865 f.icon = _G[name.."Icon"]
|
flickerstreak@90
|
866 f.flash = _G[name.."Flash"]
|
flickerstreak@90
|
867 f:SetScript("OnUpdate",OnUpdate)
|
flickerstreak@90
|
868 end
|
flickerstreak@88
|
869
|
flickerstreak@90
|
870 self.hotkey = f.hotkey
|
flickerstreak@90
|
871 self.border = _G[name.."Border"]
|
flickerstreak@90
|
872
|
flickerstreak@90
|
873 f:SetAttribute("action", config.actionID)
|
flickerstreak@90
|
874 -- install mind control actions for all buttons just for simplicity
|
flickerstreak@90
|
875 if self.idx <= 12 then
|
flickerstreak@90
|
876 f:SetAttribute("*action-mc", 120 + self.idx)
|
flickerstreak@90
|
877 end
|
flickerstreak@90
|
878
|
flickerstreak@90
|
879 -- set a _childupdate handler, called within the header's context
|
flickerstreak@90
|
880 f:SetAttribute("_childupdate",
|
flickerstreak@90
|
881 -- function _childupdate(self, snippetid, message)
|
flickerstreak@90
|
882 [[
|
flickerstreak@90
|
883 local action = "action"
|
flickerstreak@90
|
884 if doMindControl and GetBonusBarOffset() == 5 then
|
flickerstreak@90
|
885 action = "*action-mc"
|
flickerstreak@90
|
886 elseif page and state and page[state] then
|
flickerstreak@90
|
887 action = "*action-"..page[state]
|
flickerstreak@90
|
888 end
|
flickerstreak@90
|
889 local value = self:GetAttribute(action)
|
flickerstreak@92
|
890 self:SetAttribute("action",value)
|
flickerstreak@90
|
891 ]])
|
flickerstreak@90
|
892
|
flickerstreak@90
|
893 self.frame = f
|
flickerstreak@90
|
894 self.normalTexture = getglobal(format("%sNormalTexture",f:GetName()))
|
flickerstreak@90
|
895
|
flickerstreak@90
|
896 -- initialize the hide state
|
flickerstreak@90
|
897 f:SetAttribute("showgrid",0)
|
flickerstreak@90
|
898 self:ShowGrid(not barConfig.hideEmpty)
|
flickerstreak@90
|
899 if ReAction:GetConfigMode() then
|
flickerstreak@90
|
900 self:ShowGrid(true)
|
flickerstreak@90
|
901 end
|
flickerstreak@90
|
902
|
flickerstreak@90
|
903 -- show the ID label if applicable
|
flickerstreak@90
|
904 self:ShowActionIDLabel(ReAction:GetConfigMode())
|
flickerstreak@90
|
905
|
flickerstreak@90
|
906 -- attach the keybinder
|
flickerstreak@90
|
907 KBAttach(self)
|
flickerstreak@90
|
908
|
flickerstreak@90
|
909 self:Refresh()
|
flickerstreak@90
|
910 return self
|
flickerstreak@90
|
911 end
|
flickerstreak@90
|
912
|
flickerstreak@90
|
913 function Button:Destroy()
|
flickerstreak@90
|
914 local f = self.frame
|
flickerstreak@90
|
915 f:UnregisterAllEvents()
|
flickerstreak@90
|
916 f:Hide()
|
flickerstreak@90
|
917 f:SetParent(UIParent)
|
flickerstreak@90
|
918 f:ClearAllPoints()
|
flickerstreak@90
|
919 if self.name then
|
flickerstreak@90
|
920 frameRecycler[self.name] = f
|
flickerstreak@90
|
921 end
|
flickerstreak@90
|
922 if self.config.actionID then
|
flickerstreak@90
|
923 IDAlloc:Release(self.config.actionID)
|
flickerstreak@90
|
924 end
|
flickerstreak@90
|
925 if self.config.pageactions then
|
flickerstreak@90
|
926 for _, id in ipairs(self.config.pageactions) do
|
flickerstreak@90
|
927 IDAlloc:Release(id)
|
flickerstreak@90
|
928 end
|
flickerstreak@90
|
929 end
|
flickerstreak@90
|
930 self.frame = nil
|
flickerstreak@90
|
931 self.config = nil
|
flickerstreak@90
|
932 self.bar = nil
|
flickerstreak@90
|
933 end
|
flickerstreak@90
|
934
|
flickerstreak@90
|
935 function Button:Refresh()
|
flickerstreak@90
|
936 local f = self.frame
|
flickerstreak@90
|
937 self.bar:PlaceButton(self, 36, 36)
|
flickerstreak@90
|
938 self:RefreshPages()
|
flickerstreak@90
|
939 end
|
flickerstreak@90
|
940
|
flickerstreak@90
|
941 function Button:GetFrame()
|
flickerstreak@90
|
942 return self.frame
|
flickerstreak@90
|
943 end
|
flickerstreak@90
|
944
|
flickerstreak@90
|
945 function Button:GetName()
|
flickerstreak@90
|
946 return self.name
|
flickerstreak@90
|
947 end
|
flickerstreak@90
|
948
|
flickerstreak@90
|
949 function Button:GetConfig()
|
flickerstreak@90
|
950 return self.config
|
flickerstreak@90
|
951 end
|
flickerstreak@90
|
952
|
flickerstreak@90
|
953 function Button:GetActionID(page)
|
flickerstreak@90
|
954 if page == nil then
|
flickerstreak@90
|
955 -- get the effective ID
|
flickerstreak@90
|
956 return self.frame.action -- kept up-to-date by Blizzard's ActionButton_CalculateAction()
|
flickerstreak@90
|
957 else
|
flickerstreak@90
|
958 if page == 1 then
|
flickerstreak@90
|
959 return self.config.actionID
|
flickerstreak@90
|
960 else
|
flickerstreak@90
|
961 return self.config.pageactions and self.config.pageactions[page] or self.config.actionID
|
flickerstreak@88
|
962 end
|
flickerstreak@88
|
963 end
|
flickerstreak@88
|
964 end
|
flickerstreak@88
|
965
|
flickerstreak@90
|
966 function Button:SetActionID( id, page )
|
flickerstreak@90
|
967 id = tonumber(id)
|
flickerstreak@90
|
968 page = tonumber(page)
|
flickerstreak@90
|
969 if id == nil or id < 1 or id > 120 then
|
flickerstreak@90
|
970 error("Button:SetActionID - invalid action ID")
|
flickerstreak@90
|
971 end
|
flickerstreak@90
|
972 if page and page ~= 1 then
|
flickerstreak@90
|
973 if not self.config.pageactions then
|
flickerstreak@90
|
974 self.config.pageactions = { }
|
flickerstreak@90
|
975 end
|
flickerstreak@90
|
976 if self.config.pageactions[page] then
|
flickerstreak@90
|
977 IDAlloc:Release(self.config.pageactions[page])
|
flickerstreak@90
|
978 end
|
flickerstreak@90
|
979 self.config.pageactions[page] = id
|
flickerstreak@90
|
980 IDAlloc:Acquire(self.config.pageactions[page])
|
flickerstreak@90
|
981 self.frame:SetAttribute(("*action-page%d"):format(page),id)
|
flickerstreak@90
|
982 else
|
flickerstreak@90
|
983 IDAlloc:Release(self.config.actionID)
|
flickerstreak@90
|
984 self.config.actionID = id
|
flickerstreak@90
|
985 IDAlloc:Acquire(self.config.actionID)
|
flickerstreak@90
|
986 self.frame:SetAttribute("action",id)
|
flickerstreak@90
|
987 if self.config.pageactions then
|
flickerstreak@90
|
988 self.config.pageactions[1] = id
|
flickerstreak@90
|
989 self.frame:SetAttribute("*action-page1",id)
|
flickerstreak@90
|
990 end
|
flickerstreak@88
|
991 end
|
flickerstreak@88
|
992 end
|
flickerstreak@88
|
993
|
flickerstreak@90
|
994 function Button:RefreshPages( force )
|
flickerstreak@90
|
995 local nPages = self.barConfig.nPages
|
flickerstreak@90
|
996 if nPages and (nPages ~= self.nPages or force) then
|
flickerstreak@90
|
997 local f = self:GetFrame()
|
flickerstreak@90
|
998 local c = self.config.pageactions
|
flickerstreak@90
|
999 if nPages > 1 and not c then
|
flickerstreak@90
|
1000 c = { }
|
flickerstreak@90
|
1001 self.config.pageactions = c
|
flickerstreak@90
|
1002 end
|
flickerstreak@90
|
1003 for i = 1, nPages do
|
flickerstreak@90
|
1004 if i > 1 then
|
flickerstreak@90
|
1005 c[i] = IDAlloc:Acquire(c[i], self.config.actionID + (i-1)*self.bar:GetNumButtons())
|
flickerstreak@90
|
1006 else
|
flickerstreak@90
|
1007 c[i] = self.config.actionID -- page 1 is the same as the base actionID
|
flickerstreak@90
|
1008 end
|
flickerstreak@90
|
1009 f:SetAttribute(("*action-page%d"):format(i),c[i])
|
flickerstreak@90
|
1010 end
|
flickerstreak@90
|
1011 for i = nPages+1, #c do
|
flickerstreak@90
|
1012 IDAlloc:Release(c[i])
|
flickerstreak@90
|
1013 c[i] = nil
|
flickerstreak@90
|
1014 f:SetAttribute(("*action-page%d"):format(i),nil)
|
flickerstreak@90
|
1015 end
|
flickerstreak@90
|
1016 self.nPages = nPages
|
flickerstreak@88
|
1017 end
|
flickerstreak@88
|
1018 end
|
flickerstreak@88
|
1019
|
flickerstreak@90
|
1020 function Button:ShowGrid( show )
|
flickerstreak@90
|
1021 if not InCombatLockdown() then
|
flickerstreak@90
|
1022 local f = self.frame
|
flickerstreak@90
|
1023 local count = f:GetAttribute("showgrid")
|
flickerstreak@90
|
1024 if show then
|
flickerstreak@90
|
1025 count = count + 1
|
flickerstreak@90
|
1026 else
|
flickerstreak@90
|
1027 count = count - 1
|
flickerstreak@88
|
1028 end
|
flickerstreak@90
|
1029 if count < 0 then
|
flickerstreak@90
|
1030 count = 0
|
flickerstreak@88
|
1031 end
|
flickerstreak@90
|
1032 f:SetAttribute("showgrid",count)
|
flickerstreak@90
|
1033
|
flickerstreak@90
|
1034 if count >= 1 and not f:GetAttribute("statehidden") then
|
flickerstreak@90
|
1035 self.normalTexture:SetVertexColor(1.0, 1.0, 1.0, 0.5);
|
flickerstreak@90
|
1036 f:Show()
|
flickerstreak@90
|
1037 elseif count < 1 and not HasAction(self:GetActionID()) then
|
flickerstreak@90
|
1038 f:Hide()
|
flickerstreak@90
|
1039 end
|
flickerstreak@88
|
1040 end
|
flickerstreak@88
|
1041 end
|
flickerstreak@88
|
1042
|
flickerstreak@90
|
1043 function Button:ShowActionIDLabel( show )
|
flickerstreak@90
|
1044 local f = self:GetFrame()
|
flickerstreak@90
|
1045 if show then
|
flickerstreak@90
|
1046 local id = self:GetActionID()
|
flickerstreak@90
|
1047 if not f.actionIDLabel then
|
flickerstreak@90
|
1048 local label = f:CreateFontString(nil,"OVERLAY","GameFontNormalLarge")
|
flickerstreak@90
|
1049 label:SetAllPoints()
|
flickerstreak@90
|
1050 label:SetJustifyH("CENTER")
|
flickerstreak@90
|
1051 label:SetShadowColor(0,0,0,1)
|
flickerstreak@90
|
1052 label:SetShadowOffset(2,-2)
|
flickerstreak@90
|
1053 f.actionIDLabel = label -- store the label with the frame for recycling
|
flickerstreak@90
|
1054
|
flickerstreak@90
|
1055 f:HookScript("OnAttributeChanged",
|
flickerstreak@90
|
1056 function(frame, attr, value)
|
flickerstreak@90
|
1057 if label:IsVisible() and attr:match("action") then
|
flickerstreak@90
|
1058 label:SetText(tostring(frame.action))
|
flickerstreak@90
|
1059 end
|
flickerstreak@90
|
1060 end)
|
flickerstreak@88
|
1061 end
|
flickerstreak@90
|
1062 f.actionIDLabel:SetText(tostring(id))
|
flickerstreak@90
|
1063 f.actionIDLabel:Show()
|
flickerstreak@90
|
1064 elseif f.actionIDLabel then
|
flickerstreak@90
|
1065 f.actionIDLabel:Hide()
|
flickerstreak@88
|
1066 end
|
flickerstreak@88
|
1067 end
|
flickerstreak@88
|
1068
|
flickerstreak@90
|
1069 function Button:DisplayHotkey( key )
|
flickerstreak@90
|
1070 self.hotkey:SetText(key or "")
|
flickerstreak@88
|
1071 end
|
flickerstreak@88
|
1072 end
|