flickerstreak@28
|
1 --[[
|
flickerstreak@53
|
2 ReAction Pet Action button module
|
flickerstreak@53
|
3
|
flickerstreak@53
|
4 The button module implements standard action button functionality by wrapping Blizzard's
|
flickerstreak@77
|
5 PetActionButton frame and associated functions.
|
flickerstreak@28
|
6
|
flickerstreak@28
|
7 --]]
|
flickerstreak@28
|
8
|
flickerstreak@28
|
9 -- local imports
|
flickerstreak@28
|
10 local ReAction = ReAction
|
flickerstreak@28
|
11 local L = ReAction.L
|
flickerstreak@28
|
12 local _G = _G
|
flickerstreak@53
|
13 local CreateFrame = CreateFrame
|
flickerstreak@95
|
14 local format = string.format
|
flickerstreak@28
|
15
|
flickerstreak@80
|
16 ReAction:UpdateRevision("$Revision$")
|
flickerstreak@77
|
17
|
flickerstreak@93
|
18 -- libraries
|
flickerstreak@93
|
19 local KB = LibStub("LibKeyBound-1.0")
|
flickerstreak@93
|
20
|
flickerstreak@28
|
21 -- module declaration
|
flickerstreak@28
|
22 local moduleID = "PetAction"
|
flickerstreak@28
|
23 local module = ReAction:NewModule( moduleID )
|
flickerstreak@28
|
24
|
flickerstreak@130
|
25 -- Button class
|
flickerstreak@130
|
26 local Button = ReAction.Button.PetAction
|
flickerstreak@77
|
27
|
flickerstreak@102
|
28 -- private
|
flickerstreak@102
|
29 local function UpdateButtonLock(bar)
|
flickerstreak@102
|
30 local f = bar:GetFrame()
|
flickerstreak@102
|
31 f:SetAttribute("lockbuttons",bar.config.lockButtons)
|
flickerstreak@102
|
32 f:SetAttribute("lockbuttonscombat",bar.config.lockButtonsCombat)
|
flickerstreak@102
|
33 f:Execute(
|
flickerstreak@102
|
34 [[
|
flickerstreak@102
|
35 lockButtons = self:GetAttribute("lockbuttons")
|
flickerstreak@102
|
36 lockButtonsCombat = self:GetAttribute("lockbuttonscombat")
|
flickerstreak@102
|
37 ]])
|
flickerstreak@102
|
38 end
|
flickerstreak@102
|
39
|
flickerstreak@28
|
40 -- module methods
|
flickerstreak@28
|
41 function module:OnInitialize()
|
flickerstreak@53
|
42 self.db = ReAction.db:RegisterNamespace( moduleID,
|
flickerstreak@28
|
43 {
|
flickerstreak@28
|
44 profile = {
|
flickerstreak@28
|
45 buttons = { }
|
flickerstreak@28
|
46 }
|
flickerstreak@28
|
47 }
|
flickerstreak@28
|
48 )
|
flickerstreak@53
|
49 self.buttons = { }
|
flickerstreak@63
|
50
|
flickerstreak@63
|
51 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
|
flickerstreak@63
|
52
|
flickerstreak@63
|
53 ReAction.RegisterCallback(self, "OnCreateBar")
|
flickerstreak@63
|
54 ReAction.RegisterCallback(self, "OnDestroyBar")
|
flickerstreak@63
|
55 ReAction.RegisterCallback(self, "OnRefreshBar")
|
flickerstreak@63
|
56 ReAction.RegisterCallback(self, "OnEraseBar")
|
flickerstreak@63
|
57 ReAction.RegisterCallback(self, "OnRenameBar")
|
flickerstreak@63
|
58 ReAction.RegisterCallback(self, "OnConfigModeChanged")
|
flickerstreak@93
|
59
|
flickerstreak@93
|
60 KB.RegisterCallback(self, "LIBKEYBOUND_ENABLED")
|
flickerstreak@93
|
61 KB.RegisterCallback(self, "LIBKEYBOUND_DISABLED")
|
flickerstreak@93
|
62 KB.RegisterCallback(self, "LIBKEYBOUND_MODE_COLOR_CHANGED","LIBKEYBOUND_ENABLED")
|
flickerstreak@28
|
63 end
|
flickerstreak@28
|
64
|
flickerstreak@28
|
65 function module:OnEnable()
|
flickerstreak@53
|
66 ReAction:RegisterBarType(L["Pet Action Bar"],
|
flickerstreak@53
|
67 {
|
flickerstreak@53
|
68 type = moduleID ,
|
flickerstreak@53
|
69 defaultButtonSize = 30,
|
flickerstreak@53
|
70 defaultBarRows = 1,
|
flickerstreak@53
|
71 defaultBarCols = 10,
|
flickerstreak@53
|
72 defaultBarSpacing = 8
|
flickerstreak@53
|
73 })
|
flickerstreak@28
|
74 end
|
flickerstreak@28
|
75
|
flickerstreak@28
|
76 function module:OnDisable()
|
flickerstreak@53
|
77 ReAction:UnregisterBarType(L["Pet Action Bar"])
|
flickerstreak@28
|
78 end
|
flickerstreak@28
|
79
|
flickerstreak@63
|
80 function module:OnCreateBar(event, bar, name)
|
flickerstreak@53
|
81 if bar.config.type == moduleID then
|
flickerstreak@53
|
82 -- auto show/hide when pet exists
|
flickerstreak@53
|
83 bar:GetFrame():SetAttribute("unit","pet")
|
flickerstreak@90
|
84 if not ReAction:GetConfigMode() then
|
flickerstreak@90
|
85 RegisterUnitWatch(bar:GetFrame())
|
flickerstreak@90
|
86 end
|
flickerstreak@63
|
87 self:OnRefreshBar(event, bar, name)
|
flickerstreak@28
|
88 end
|
flickerstreak@28
|
89 end
|
flickerstreak@28
|
90
|
flickerstreak@63
|
91 function module:OnRefreshBar(event, bar, name)
|
flickerstreak@53
|
92 if bar.config.type == moduleID then
|
flickerstreak@53
|
93 if self.buttons[bar] == nil then
|
flickerstreak@53
|
94 self.buttons[bar] = { }
|
flickerstreak@53
|
95 end
|
flickerstreak@53
|
96 local btns = self.buttons[bar]
|
flickerstreak@53
|
97 local profile = self.db.profile
|
flickerstreak@63
|
98 if profile.buttons[name] == nil then
|
flickerstreak@63
|
99 profile.buttons[name] = {}
|
flickerstreak@53
|
100 end
|
flickerstreak@63
|
101 local btnCfg = profile.buttons[name]
|
flickerstreak@53
|
102
|
flickerstreak@53
|
103 local r, c = bar:GetButtonGrid()
|
flickerstreak@53
|
104 local n = r*c
|
flickerstreak@53
|
105 for i = 1, n do
|
flickerstreak@53
|
106 if btnCfg[i] == nil then
|
flickerstreak@53
|
107 btnCfg[i] = {}
|
flickerstreak@53
|
108 end
|
flickerstreak@53
|
109 if btns[i] == nil then
|
flickerstreak@130
|
110 local success, r = pcall(Button.New,Button,i,btnCfg[i],bar,i>1 and btnCfg[i-1].actionID)
|
flickerstreak@94
|
111 if success and r then
|
flickerstreak@94
|
112 btns[i] = r
|
flickerstreak@94
|
113 bar:AddButton(i,r)
|
flickerstreak@94
|
114 else
|
flickerstreak@94
|
115 n = i - 1
|
flickerstreak@94
|
116 bar:ClipNButtons(n)
|
flickerstreak@94
|
117 break
|
flickerstreak@94
|
118 end
|
flickerstreak@53
|
119 end
|
flickerstreak@77
|
120 btns[i]:Refresh()
|
flickerstreak@53
|
121 end
|
flickerstreak@53
|
122 for i = n+1, #btns do
|
flickerstreak@53
|
123 if btns[i] then
|
flickerstreak@77
|
124 bar:RemoveButton(btns[i])
|
flickerstreak@53
|
125 btns[i] = btns[i]:Destroy()
|
flickerstreak@53
|
126 if btnCfg[i] then
|
flickerstreak@53
|
127 btnCfg[i] = nil
|
flickerstreak@53
|
128 end
|
flickerstreak@53
|
129 end
|
flickerstreak@53
|
130 end
|
flickerstreak@102
|
131 UpdateButtonLock(bar)
|
flickerstreak@53
|
132 end
|
flickerstreak@53
|
133 end
|
flickerstreak@53
|
134
|
flickerstreak@63
|
135 function module:OnDestroyBar(event, bar, name)
|
flickerstreak@53
|
136 if self.buttons[bar] then
|
flickerstreak@53
|
137 local btns = self.buttons[bar]
|
flickerstreak@53
|
138 for _,b in pairs(btns) do
|
flickerstreak@53
|
139 if b then
|
flickerstreak@53
|
140 b:Destroy()
|
flickerstreak@53
|
141 end
|
flickerstreak@53
|
142 end
|
flickerstreak@53
|
143 self.buttons[bar] = nil
|
flickerstreak@53
|
144 end
|
flickerstreak@53
|
145 end
|
flickerstreak@53
|
146
|
flickerstreak@63
|
147 function module:OnEraseBar(event, bar, name)
|
flickerstreak@63
|
148 self.db.profile.buttons[name] = nil
|
flickerstreak@53
|
149 end
|
flickerstreak@53
|
150
|
flickerstreak@63
|
151 function module:OnRenameBar(event, bar, oldname, newname)
|
flickerstreak@53
|
152 local b = self.db.profile.buttons
|
flickerstreak@53
|
153 b[newname], b[oldname] = b[oldname], nil
|
flickerstreak@53
|
154 end
|
flickerstreak@53
|
155
|
flickerstreak@53
|
156
|
flickerstreak@63
|
157 function module:OnConfigModeChanged(event, mode)
|
flickerstreak@63
|
158 for _, bar in ReAction:IterateBars() do
|
flickerstreak@53
|
159 if bar and self.buttons[bar] then
|
flickerstreak@130
|
160 for b in bar:IterateButtons() do
|
flickerstreak@130
|
161 b:UpdateActionIDLabel(mode)
|
flickerstreak@130
|
162 end
|
flickerstreak@53
|
163 local f = bar:GetFrame()
|
flickerstreak@53
|
164 if mode then
|
flickerstreak@53
|
165 UnregisterUnitWatch(f)
|
flickerstreak@53
|
166 f:Show()
|
flickerstreak@53
|
167 else
|
flickerstreak@53
|
168 RegisterUnitWatch(f)
|
flickerstreak@53
|
169 end
|
flickerstreak@53
|
170 end
|
flickerstreak@53
|
171 end
|
flickerstreak@53
|
172 end
|
flickerstreak@53
|
173
|
flickerstreak@93
|
174 function module:LIBKEYBOUND_ENABLED(evt)
|
flickerstreak@93
|
175 for _, buttons in pairs(self.buttons) do
|
flickerstreak@93
|
176 for _, b in pairs(buttons) do
|
flickerstreak@93
|
177 b:SetKeybindMode(true)
|
flickerstreak@93
|
178 end
|
flickerstreak@93
|
179 end
|
flickerstreak@93
|
180 end
|
flickerstreak@93
|
181
|
flickerstreak@93
|
182 function module:LIBKEYBOUND_DISABLED(evt)
|
flickerstreak@93
|
183 for _, buttons in pairs(self.buttons) do
|
flickerstreak@93
|
184 for _, b in pairs(buttons) do
|
flickerstreak@93
|
185 b:SetKeybindMode(false)
|
flickerstreak@93
|
186 end
|
flickerstreak@93
|
187 end
|
flickerstreak@93
|
188 end
|
flickerstreak@93
|
189
|
flickerstreak@53
|
190
|
flickerstreak@60
|
191 ---- Options ----
|
flickerstreak@102
|
192 local Handler = { }
|
flickerstreak@102
|
193 local meta = { __index = Handler }
|
flickerstreak@102
|
194
|
flickerstreak@102
|
195 function Handler:New(bar)
|
flickerstreak@102
|
196 return setmetatable(
|
flickerstreak@102
|
197 {
|
flickerstreak@102
|
198 bar = bar,
|
flickerstreak@102
|
199 config = bar.config
|
flickerstreak@102
|
200 }, meta)
|
flickerstreak@102
|
201 end
|
flickerstreak@102
|
202
|
flickerstreak@102
|
203 function Handler:GetLockButtons()
|
flickerstreak@130
|
204 return self.config.lockButtons
|
flickerstreak@102
|
205 end
|
flickerstreak@102
|
206
|
flickerstreak@102
|
207 function Handler:SetLockButtons(info, value)
|
flickerstreak@102
|
208 self.config.lockButtons = value
|
flickerstreak@102
|
209 UpdateButtonLock(self.bar)
|
flickerstreak@102
|
210 end
|
flickerstreak@102
|
211
|
flickerstreak@102
|
212 function Handler:GetLockButtonsCombat()
|
flickerstreak@102
|
213 return self.config.lockButtonsCombat
|
flickerstreak@102
|
214 end
|
flickerstreak@102
|
215
|
flickerstreak@102
|
216 function Handler:SetLockButtonsCombat(info, value)
|
flickerstreak@102
|
217 self.config.lockButtonsCombat = value
|
flickerstreak@102
|
218 UpdateButtonLock(self.bar)
|
flickerstreak@102
|
219 end
|
flickerstreak@102
|
220
|
flickerstreak@102
|
221 function Handler:LockButtonsCombatDisabled()
|
flickerstreak@130
|
222 return not self.config.lockButtons
|
flickerstreak@102
|
223 end
|
flickerstreak@102
|
224
|
flickerstreak@102
|
225
|
flickerstreak@60
|
226 function module:GetBarOptions(bar)
|
flickerstreak@91
|
227 if bar.config.type == moduleID then
|
flickerstreak@91
|
228 return {
|
flickerstreak@91
|
229 type = "group",
|
flickerstreak@91
|
230 name = L["Pet Buttons"],
|
flickerstreak@102
|
231 handler = Handler:New(bar),
|
flickerstreak@91
|
232 args = {
|
flickerstreak@102
|
233 lockButtons = {
|
flickerstreak@102
|
234 name = L["Lock Buttons"],
|
flickerstreak@102
|
235 desc = L["Prevents picking up/dragging actions.|nNOTE: This setting is overridden by the global setting in Blizzard's Action Buttons tab"],
|
flickerstreak@102
|
236 order = 2,
|
flickerstreak@102
|
237 type = "toggle",
|
flickerstreak@102
|
238 get = "GetLockButtons",
|
flickerstreak@102
|
239 set = "SetLockButtons",
|
flickerstreak@102
|
240 },
|
flickerstreak@102
|
241 lockOnlyCombat = {
|
flickerstreak@102
|
242 name = L["Only in Combat"],
|
flickerstreak@102
|
243 desc = L["Only lock the buttons when in combat"],
|
flickerstreak@102
|
244 order = 3,
|
flickerstreak@102
|
245 type = "toggle",
|
flickerstreak@102
|
246 disabled = "LockButtonsCombatDisabled",
|
flickerstreak@102
|
247 get = "GetLockButtonsCombat",
|
flickerstreak@102
|
248 set = "SetLockButtonsCombat",
|
flickerstreak@102
|
249 },
|
flickerstreak@91
|
250 }
|
flickerstreak@60
|
251 }
|
flickerstreak@91
|
252 end
|
flickerstreak@59
|
253 end
|
flickerstreak@59
|
254
|
flickerstreak@53
|
255
|