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