comparison modules/ReAction_PetAction/ReAction_PetAction.lua @ 102:ad49739d110d

Added feature to lock buttons (per-bar), with optional only-in-combat selector.
author Flick <flickerstreak@gmail.com>
date Sun, 26 Oct 2008 02:26:31 +0000
parents 168cae4aa8bd
children b2fb8f7dc780
comparison
equal deleted inserted replaced
101:3699d7dad312 102:ad49739d110d
22 local moduleID = "PetAction" 22 local moduleID = "PetAction"
23 local module = ReAction:NewModule( moduleID ) 23 local module = ReAction:NewModule( moduleID )
24 24
25 -- Button class declaration 25 -- Button class declaration
26 local Button = { } 26 local Button = { }
27
28 -- private
29 local function UpdateButtonLock(bar)
30 local f = bar:GetFrame()
31 f:SetAttribute("lockbuttons",bar.config.lockButtons)
32 f:SetAttribute("lockbuttonscombat",bar.config.lockButtonsCombat)
33 f:Execute(
34 [[
35 lockButtons = self:GetAttribute("lockbuttons")
36 lockButtonsCombat = self:GetAttribute("lockbuttonscombat")
37 ]])
38 end
27 39
28 -- module methods 40 -- module methods
29 function module:OnInitialize() 41 function module:OnInitialize()
30 self.db = ReAction.db:RegisterNamespace( moduleID, 42 self.db = ReAction.db:RegisterNamespace( moduleID,
31 { 43 {
114 if btnCfg[i] then 126 if btnCfg[i] then
115 btnCfg[i] = nil 127 btnCfg[i] = nil
116 end 128 end
117 end 129 end
118 end 130 end
131 UpdateButtonLock(bar)
119 end 132 end
120 end 133 end
121 134
122 function module:OnDestroyBar(event, bar, name) 135 function module:OnDestroyBar(event, bar, name)
123 if self.buttons[bar] then 136 if self.buttons[bar] then
176 end 189 end
177 end 190 end
178 191
179 192
180 ---- Options ---- 193 ---- Options ----
194 local Handler = { }
195 local meta = { __index = Handler }
196
197 function Handler:New(bar)
198 return setmetatable(
199 {
200 bar = bar,
201 config = bar.config
202 }, meta)
203 end
204
205 function Handler:GetLockButtons()
206 return LOCK_ACTIONBAR == "1" or self.config.lockButtons
207 end
208
209 function Handler:SetLockButtons(info, value)
210 self.config.lockButtons = value
211 UpdateButtonLock(self.bar)
212 end
213
214 function Handler:LockButtonsDisabled()
215 return LOCK_ACTIONBAR == "1"
216 end
217
218 function Handler:GetLockButtonsCombat()
219 return self.config.lockButtonsCombat
220 end
221
222 function Handler:SetLockButtonsCombat(info, value)
223 self.config.lockButtonsCombat = value
224 UpdateButtonLock(self.bar)
225 end
226
227 function Handler:LockButtonsCombatDisabled()
228 return LOCK_ACTIONBAR == "1" or not self.config.lockButtons
229 end
230
231
181 function module:GetBarOptions(bar) 232 function module:GetBarOptions(bar)
182 if bar.config.type == moduleID then 233 if bar.config.type == moduleID then
183 return { 234 return {
184 type = "group", 235 type = "group",
185 name = L["Pet Buttons"], 236 name = L["Pet Buttons"],
237 handler = Handler:New(bar),
186 args = { 238 args = {
239 lockButtons = {
240 name = L["Lock Buttons"],
241 desc = L["Prevents picking up/dragging actions.|nNOTE: This setting is overridden by the global setting in Blizzard's Action Buttons tab"],
242 order = 2,
243 type = "toggle",
244 disabled = "LockButtonsDisabled",
245 get = "GetLockButtons",
246 set = "SetLockButtons",
247 },
248 lockOnlyCombat = {
249 name = L["Only in Combat"],
250 desc = L["Only lock the buttons when in combat"],
251 order = 3,
252 type = "toggle",
253 disabled = "LockButtonsCombatDisabled",
254 get = "GetLockButtonsCombat",
255 set = "SetLockButtonsCombat",
256 },
187 } 257 }
188 } 258 }
189 end 259 end
190 end 260 end
191 261
412 else 482 else
413 self:Update() 483 self:Update()
414 end 484 end
415 end) 485 end)
416 486
487 -- install drag wrappers to lock buttons
488 bar:GetFrame():WrapScript(f, "OnDragStart",
489 -- OnDragStart(self, button, kind, value, ...)
490 [[
491 if lockButtons and (PlayerInCombat() or not lockButtonsCombat) and not IsModifiedClick("PICKUPACTION") then
492 return "clear"
493 end
494 ]])
495
417 KBAttach(self) 496 KBAttach(self)
418 497
419 self:Refresh() 498 self:Refresh()
420 self:SetKeybindMode(ReAction:GetKeybindMode()) 499 self:SetKeybindMode(ReAction:GetKeybindMode())
421 500