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@28
|
18 -- module declaration
|
flickerstreak@28
|
19 local moduleID = "PetAction"
|
flickerstreak@28
|
20 local module = ReAction:NewModule( moduleID )
|
flickerstreak@28
|
21
|
flickerstreak@130
|
22 -- Button class
|
flickerstreak@130
|
23 local Button = ReAction.Button.PetAction
|
flickerstreak@77
|
24
|
flickerstreak@102
|
25 -- private
|
flickerstreak@102
|
26 local function UpdateButtonLock(bar)
|
flickerstreak@102
|
27 local f = bar:GetFrame()
|
flickerstreak@102
|
28 f:SetAttribute("lockbuttons",bar.config.lockButtons)
|
flickerstreak@102
|
29 f:SetAttribute("lockbuttonscombat",bar.config.lockButtonsCombat)
|
flickerstreak@102
|
30 f:Execute(
|
flickerstreak@102
|
31 [[
|
flickerstreak@102
|
32 lockButtons = self:GetAttribute("lockbuttons")
|
flickerstreak@102
|
33 lockButtonsCombat = self:GetAttribute("lockbuttonscombat")
|
flickerstreak@102
|
34 ]])
|
flickerstreak@102
|
35 end
|
flickerstreak@102
|
36
|
flickerstreak@28
|
37 -- module methods
|
flickerstreak@28
|
38 function module:OnInitialize()
|
flickerstreak@53
|
39 self.db = ReAction.db:RegisterNamespace( moduleID,
|
flickerstreak@28
|
40 {
|
flickerstreak@28
|
41 profile = {
|
flickerstreak@28
|
42 buttons = { }
|
flickerstreak@28
|
43 }
|
flickerstreak@28
|
44 }
|
flickerstreak@28
|
45 )
|
flickerstreak@53
|
46 self.buttons = { }
|
flickerstreak@63
|
47
|
flickerstreak@63
|
48 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
|
flickerstreak@63
|
49
|
flickerstreak@63
|
50 ReAction.RegisterCallback(self, "OnCreateBar")
|
flickerstreak@63
|
51 ReAction.RegisterCallback(self, "OnDestroyBar")
|
flickerstreak@63
|
52 ReAction.RegisterCallback(self, "OnRefreshBar")
|
flickerstreak@63
|
53 ReAction.RegisterCallback(self, "OnEraseBar")
|
flickerstreak@63
|
54 ReAction.RegisterCallback(self, "OnRenameBar")
|
flickerstreak@28
|
55 end
|
flickerstreak@28
|
56
|
flickerstreak@28
|
57 function module:OnEnable()
|
flickerstreak@53
|
58 ReAction:RegisterBarType(L["Pet Action Bar"],
|
flickerstreak@53
|
59 {
|
flickerstreak@53
|
60 type = moduleID ,
|
flickerstreak@53
|
61 defaultButtonSize = 30,
|
flickerstreak@53
|
62 defaultBarRows = 1,
|
flickerstreak@53
|
63 defaultBarCols = 10,
|
flickerstreak@53
|
64 defaultBarSpacing = 8
|
flickerstreak@53
|
65 })
|
flickerstreak@28
|
66 end
|
flickerstreak@28
|
67
|
flickerstreak@28
|
68 function module:OnDisable()
|
flickerstreak@53
|
69 ReAction:UnregisterBarType(L["Pet Action Bar"])
|
flickerstreak@28
|
70 end
|
flickerstreak@28
|
71
|
flickerstreak@63
|
72 function module:OnCreateBar(event, bar, name)
|
flickerstreak@53
|
73 if bar.config.type == moduleID then
|
flickerstreak@53
|
74 -- auto show/hide when pet exists
|
flickerstreak@148
|
75 bar:RegisterUnitWatch("pet",true)
|
flickerstreak@63
|
76 self:OnRefreshBar(event, bar, name)
|
flickerstreak@28
|
77 end
|
flickerstreak@28
|
78 end
|
flickerstreak@28
|
79
|
flickerstreak@63
|
80 function module:OnRefreshBar(event, bar, name)
|
flickerstreak@53
|
81 if bar.config.type == moduleID then
|
flickerstreak@53
|
82 if self.buttons[bar] == nil then
|
flickerstreak@53
|
83 self.buttons[bar] = { }
|
flickerstreak@53
|
84 end
|
flickerstreak@53
|
85 local btns = self.buttons[bar]
|
flickerstreak@53
|
86 local profile = self.db.profile
|
flickerstreak@63
|
87 if profile.buttons[name] == nil then
|
flickerstreak@63
|
88 profile.buttons[name] = {}
|
flickerstreak@53
|
89 end
|
flickerstreak@63
|
90 local btnCfg = profile.buttons[name]
|
flickerstreak@53
|
91
|
flickerstreak@53
|
92 local r, c = bar:GetButtonGrid()
|
flickerstreak@53
|
93 local n = r*c
|
flickerstreak@53
|
94 for i = 1, n do
|
flickerstreak@53
|
95 if btnCfg[i] == nil then
|
flickerstreak@53
|
96 btnCfg[i] = {}
|
flickerstreak@53
|
97 end
|
flickerstreak@53
|
98 if btns[i] == nil then
|
flickerstreak@130
|
99 local success, r = pcall(Button.New,Button,i,btnCfg[i],bar,i>1 and btnCfg[i-1].actionID)
|
flickerstreak@94
|
100 if success and r then
|
flickerstreak@94
|
101 btns[i] = r
|
flickerstreak@94
|
102 bar:AddButton(i,r)
|
flickerstreak@94
|
103 else
|
flickerstreak@94
|
104 n = i - 1
|
flickerstreak@94
|
105 bar:ClipNButtons(n)
|
flickerstreak@94
|
106 break
|
flickerstreak@94
|
107 end
|
flickerstreak@53
|
108 end
|
flickerstreak@77
|
109 btns[i]:Refresh()
|
flickerstreak@53
|
110 end
|
flickerstreak@53
|
111 for i = n+1, #btns do
|
flickerstreak@53
|
112 if btns[i] then
|
flickerstreak@77
|
113 bar:RemoveButton(btns[i])
|
flickerstreak@53
|
114 btns[i] = btns[i]:Destroy()
|
flickerstreak@53
|
115 if btnCfg[i] then
|
flickerstreak@53
|
116 btnCfg[i] = nil
|
flickerstreak@53
|
117 end
|
flickerstreak@53
|
118 end
|
flickerstreak@53
|
119 end
|
flickerstreak@102
|
120 UpdateButtonLock(bar)
|
flickerstreak@53
|
121 end
|
flickerstreak@53
|
122 end
|
flickerstreak@53
|
123
|
flickerstreak@63
|
124 function module:OnDestroyBar(event, bar, name)
|
flickerstreak@53
|
125 if self.buttons[bar] then
|
flickerstreak@53
|
126 local btns = self.buttons[bar]
|
flickerstreak@53
|
127 for _,b in pairs(btns) do
|
flickerstreak@53
|
128 if b then
|
flickerstreak@53
|
129 b:Destroy()
|
flickerstreak@53
|
130 end
|
flickerstreak@53
|
131 end
|
flickerstreak@53
|
132 self.buttons[bar] = nil
|
flickerstreak@53
|
133 end
|
flickerstreak@53
|
134 end
|
flickerstreak@53
|
135
|
flickerstreak@63
|
136 function module:OnEraseBar(event, bar, name)
|
flickerstreak@63
|
137 self.db.profile.buttons[name] = nil
|
flickerstreak@53
|
138 end
|
flickerstreak@53
|
139
|
flickerstreak@63
|
140 function module:OnRenameBar(event, bar, oldname, newname)
|
flickerstreak@53
|
141 local b = self.db.profile.buttons
|
flickerstreak@53
|
142 b[newname], b[oldname] = b[oldname], nil
|
flickerstreak@53
|
143 end
|
flickerstreak@53
|
144
|
flickerstreak@53
|
145
|
flickerstreak@60
|
146 ---- Options ----
|
flickerstreak@102
|
147 local Handler = { }
|
flickerstreak@102
|
148 local meta = { __index = Handler }
|
flickerstreak@102
|
149
|
flickerstreak@102
|
150 function Handler:New(bar)
|
flickerstreak@102
|
151 return setmetatable(
|
flickerstreak@102
|
152 {
|
flickerstreak@102
|
153 bar = bar,
|
flickerstreak@102
|
154 config = bar.config
|
flickerstreak@102
|
155 }, meta)
|
flickerstreak@102
|
156 end
|
flickerstreak@102
|
157
|
flickerstreak@102
|
158 function Handler:GetLockButtons()
|
flickerstreak@130
|
159 return self.config.lockButtons
|
flickerstreak@102
|
160 end
|
flickerstreak@102
|
161
|
flickerstreak@102
|
162 function Handler:SetLockButtons(info, value)
|
flickerstreak@102
|
163 self.config.lockButtons = value
|
flickerstreak@102
|
164 UpdateButtonLock(self.bar)
|
flickerstreak@102
|
165 end
|
flickerstreak@102
|
166
|
flickerstreak@102
|
167 function Handler:GetLockButtonsCombat()
|
flickerstreak@102
|
168 return self.config.lockButtonsCombat
|
flickerstreak@102
|
169 end
|
flickerstreak@102
|
170
|
flickerstreak@102
|
171 function Handler:SetLockButtonsCombat(info, value)
|
flickerstreak@102
|
172 self.config.lockButtonsCombat = value
|
flickerstreak@102
|
173 UpdateButtonLock(self.bar)
|
flickerstreak@102
|
174 end
|
flickerstreak@102
|
175
|
flickerstreak@102
|
176 function Handler:LockButtonsCombatDisabled()
|
flickerstreak@130
|
177 return not self.config.lockButtons
|
flickerstreak@102
|
178 end
|
flickerstreak@102
|
179
|
flickerstreak@102
|
180
|
flickerstreak@60
|
181 function module:GetBarOptions(bar)
|
flickerstreak@91
|
182 if bar.config.type == moduleID then
|
flickerstreak@91
|
183 return {
|
flickerstreak@91
|
184 type = "group",
|
flickerstreak@91
|
185 name = L["Pet Buttons"],
|
flickerstreak@102
|
186 handler = Handler:New(bar),
|
flickerstreak@91
|
187 args = {
|
flickerstreak@102
|
188 lockButtons = {
|
flickerstreak@102
|
189 name = L["Lock Buttons"],
|
flickerstreak@147
|
190 desc = L["Prevents picking up/dragging actions (use SHIFT to override this behavior)"],
|
flickerstreak@102
|
191 order = 2,
|
flickerstreak@102
|
192 type = "toggle",
|
flickerstreak@102
|
193 get = "GetLockButtons",
|
flickerstreak@102
|
194 set = "SetLockButtons",
|
flickerstreak@102
|
195 },
|
flickerstreak@102
|
196 lockOnlyCombat = {
|
flickerstreak@102
|
197 name = L["Only in Combat"],
|
flickerstreak@102
|
198 desc = L["Only lock the buttons when in combat"],
|
flickerstreak@102
|
199 order = 3,
|
flickerstreak@102
|
200 type = "toggle",
|
flickerstreak@102
|
201 disabled = "LockButtonsCombatDisabled",
|
flickerstreak@102
|
202 get = "GetLockButtonsCombat",
|
flickerstreak@102
|
203 set = "SetLockButtonsCombat",
|
flickerstreak@102
|
204 },
|
flickerstreak@91
|
205 }
|
flickerstreak@60
|
206 }
|
flickerstreak@91
|
207 end
|
flickerstreak@59
|
208 end
|
flickerstreak@59
|
209
|
flickerstreak@53
|
210
|