flickerstreak@201
|
1 local addonName, addonTable = ...
|
flickerstreak@205
|
2 local pcall = pcall
|
flickerstreak@205
|
3 local pairs = pairs
|
flickerstreak@205
|
4 local type = type
|
flickerstreak@205
|
5 local geterrorhandler = geterrorhandler
|
flickerstreak@184
|
6 local LKB = LibStub("LibKeyBound-1.0")
|
flickerstreak@33
|
7 local L = LibStub("AceLocale-3.0"):GetLocale("ReAction")
|
flickerstreak@33
|
8
|
flickerstreak@205
|
9 ------ Utility ------
|
flickerstreak@205
|
10 local tcopy
|
flickerstreak@28
|
11 do
|
flickerstreak@205
|
12 function tcopy(x)
|
flickerstreak@28
|
13 if type(x) ~= "table" then
|
flickerstreak@28
|
14 return x
|
flickerstreak@28
|
15 end
|
flickerstreak@28
|
16 local r = {}
|
flickerstreak@28
|
17 for k,v in pairs(x) do
|
flickerstreak@205
|
18 r[k] = tcopy(v)
|
flickerstreak@28
|
19 end
|
flickerstreak@28
|
20 return r
|
flickerstreak@28
|
21 end
|
flickerstreak@28
|
22 end
|
flickerstreak@28
|
23
|
flickerstreak@205
|
24 ------ Core ------
|
flickerstreak@205
|
25 local ReAction = LibStub("AceAddon-3.0"):NewAddon( "ReAction",
|
flickerstreak@205
|
26 "AceEvent-3.0"
|
flickerstreak@205
|
27 )
|
flickerstreak@205
|
28 addonTable.ReAction = ReAction
|
flickerstreak@205
|
29 ReAction.version = "1.1"
|
flickerstreak@205
|
30 ReAction.L = L
|
flickerstreak@205
|
31 ReAction.LKB = LKB
|
flickerstreak@28
|
32
|
flickerstreak@205
|
33
|
flickerstreak@205
|
34 ------ Handlers ------
|
flickerstreak@28
|
35 function ReAction:OnInitialize()
|
flickerstreak@28
|
36 self.db = LibStub("AceDB-3.0"):New("ReAction_DB",
|
flickerstreak@213
|
37 self.defaultProfile,
|
flickerstreak@182
|
38 true -- use global 'Default' (locale-specific)
|
flickerstreak@28
|
39 )
|
flickerstreak@205
|
40
|
flickerstreak@213
|
41 self:UpgradeProfile()
|
flickerstreak@211
|
42
|
flickerstreak@205
|
43 self.bars = { }
|
flickerstreak@218
|
44 self.barTypes = { }
|
flickerstreak@205
|
45
|
flickerstreak@213
|
46 self.LBF = LibStub("LibButtonFacade",true)
|
flickerstreak@213
|
47 if self.LBF then
|
flickerstreak@213
|
48 self.LBF:RegisterSkinCallback("ReAction", self.OnSkinChanged, self)
|
flickerstreak@213
|
49 end
|
flickerstreak@213
|
50
|
flickerstreak@211
|
51 -- It's fairly normal to use the Blizzard vehicle bar, and to have
|
flickerstreak@211
|
52 -- your regular buttons in the same location. If you do this, and don't
|
flickerstreak@211
|
53 -- bother to hide your buttons, they'll obscure some parts of the vehicle bar.
|
flickerstreak@211
|
54 VehicleMenuBar:SetFrameLevel(VehicleMenuBar:GetFrameLevel()+3)
|
flickerstreak@211
|
55
|
flickerstreak@205
|
56 self.callbacks = LibStub("CallbackHandler-1.0"):New(self)
|
flickerstreak@184
|
57 LKB.RegisterCallback(self,"LIBKEYBOUND_ENABLED")
|
flickerstreak@184
|
58 LKB.RegisterCallback(self,"LIBKEYBOUND_DISABLED")
|
flickerstreak@207
|
59 LKB.RegisterCallback(self, "LIBKEYBOUND_MODE_COLOR_CHANGED","LIBKEYBOUND_ENABLED")
|
flickerstreak@182
|
60 self:RegisterEvent("PLAYER_REGEN_DISABLED")
|
flickerstreak@182
|
61 self:InitializeOptions()
|
flickerstreak@28
|
62 end
|
flickerstreak@28
|
63
|
flickerstreak@28
|
64 function ReAction:OnEnable()
|
flickerstreak@205
|
65 self:InitializeBars()
|
flickerstreak@28
|
66 end
|
flickerstreak@28
|
67
|
flickerstreak@28
|
68 function ReAction:OnDisable()
|
flickerstreak@205
|
69 self:TearDownBars()
|
flickerstreak@28
|
70 end
|
flickerstreak@28
|
71
|
flickerstreak@33
|
72 function ReAction:PLAYER_REGEN_DISABLED()
|
flickerstreak@205
|
73 if self.configMode == true then
|
flickerstreak@63
|
74 self:UserError(L["ReAction config mode disabled during combat."])
|
flickerstreak@33
|
75 self:SetConfigMode(false)
|
flickerstreak@88
|
76 self:SetKeybindMode(false)
|
flickerstreak@185
|
77 self:CloseEditor()
|
flickerstreak@33
|
78 end
|
flickerstreak@33
|
79 end
|
flickerstreak@33
|
80
|
flickerstreak@88
|
81 function ReAction:LIBKEYBOUND_ENABLED( evt )
|
flickerstreak@88
|
82 self:SetKeybindMode(true)
|
flickerstreak@88
|
83 end
|
flickerstreak@88
|
84
|
flickerstreak@88
|
85 function ReAction:LIBKEYBOUND_DISABLED( evt )
|
flickerstreak@88
|
86 return self:SetKeybindMode(false)
|
flickerstreak@88
|
87 end
|
flickerstreak@88
|
88
|
flickerstreak@213
|
89 function ReAction:OnSkinChanged( skinID, gloss, backdrop, group, button, colors )
|
flickerstreak@213
|
90 if group == nil then
|
flickerstreak@213
|
91 -- don't store global
|
flickerstreak@213
|
92 else
|
flickerstreak@213
|
93 -- 'group' is the bar-name
|
flickerstreak@213
|
94 local bar = self:GetBar(group)
|
flickerstreak@213
|
95 if bar then
|
flickerstreak@213
|
96 local c = bar:GetConfig().ButtonFacade
|
flickerstreak@213
|
97 if c then
|
flickerstreak@213
|
98 c.skinID = skinID
|
flickerstreak@213
|
99 c.gloss = gloss
|
flickerstreak@213
|
100 c.backdrop = backdrop
|
flickerstreak@213
|
101 c.colors = colors
|
flickerstreak@213
|
102 end
|
flickerstreak@213
|
103 end
|
flickerstreak@213
|
104 end
|
flickerstreak@213
|
105 end
|
flickerstreak@213
|
106
|
flickerstreak@33
|
107
|
flickerstreak@205
|
108 ------ Methods ------
|
flickerstreak@77
|
109
|
flickerstreak@61
|
110 function ReAction:UserError(msg)
|
flickerstreak@61
|
111 UIErrorsFrame:AddMessage(msg)
|
flickerstreak@61
|
112 end
|
flickerstreak@61
|
113
|
flickerstreak@205
|
114 function ReAction:GetBar(arg)
|
flickerstreak@205
|
115 if type(arg) == "string" then
|
flickerstreak@205
|
116 return self.bars[arg], arg
|
flickerstreak@205
|
117 elseif type(arg) == "table" then -- reverse lookup
|
flickerstreak@205
|
118 for name, bar in pairs(self.bars) do
|
flickerstreak@205
|
119 if arg == bar then
|
flickerstreak@205
|
120 return bar, name
|
flickerstreak@205
|
121 end
|
flickerstreak@205
|
122 end
|
flickerstreak@205
|
123 else
|
flickerstreak@205
|
124 error("ReAction:GetBar() requires either a name or a bar table arg")
|
flickerstreak@205
|
125 end
|
flickerstreak@184
|
126 end
|
flickerstreak@184
|
127
|
flickerstreak@205
|
128 function ReAction:IterateBars()
|
flickerstreak@205
|
129 return pairs(self.bars)
|
flickerstreak@205
|
130 end
|
flickerstreak@184
|
131
|
flickerstreak@63
|
132 -- usage:
|
flickerstreak@91
|
133 -- (1) ReAction:CreateBar(name, [cfgTable])
|
flickerstreak@63
|
134 -- (2) ReAction:CreateBar(name, "barType", [nRows], [nCols], [btnSize], [btnSpacing])
|
flickerstreak@91
|
135 function ReAction:CreateBar(name, config, ...)
|
flickerstreak@91
|
136 local profile = self.db.profile
|
flickerstreak@91
|
137
|
flickerstreak@217
|
138 name = tostring(name)
|
flickerstreak@217
|
139 if not name or name == "" then
|
flickerstreak@217
|
140 error("ReAction:CreateBar() - bar name string required")
|
flickerstreak@217
|
141 elseif self.bars[name] then
|
flickerstreak@217
|
142 self:UserError(format(L["ReAction: name '%s' already in use"],name))
|
flickerstreak@217
|
143 return nil
|
flickerstreak@91
|
144 end
|
flickerstreak@91
|
145
|
flickerstreak@91
|
146 if type(config) == "string" then
|
flickerstreak@218
|
147 local class = self.barTypes[config]
|
flickerstreak@218
|
148 if not class then
|
flickerstreak@218
|
149 error(("ReAction:CreateBar() - unknown bar type '%s'"):format(config))
|
flickerstreak@48
|
150 end
|
flickerstreak@218
|
151 config = tcopy(class:GetDefaultBarConfig())
|
flickerstreak@218
|
152 config.btnRows = select(1,...) or config.btnRows
|
flickerstreak@218
|
153 config.btnColumns = select(2,...) or config.btnColumns
|
flickerstreak@218
|
154 config.btnWidth = select(3,...) or config.btnWidth
|
flickerstreak@218
|
155 config.btnHeight = select(3,...) or config.btnHeight
|
flickerstreak@218
|
156 config.spacing = select(4,...) or config.spacing
|
flickerstreak@48
|
157 config.width = config.width or config.btnColumns*(config.btnWidth + config.spacing) + 1
|
flickerstreak@48
|
158 config.height = config.height or config.btnRows*(config.btnHeight + config.spacing) + 1
|
flickerstreak@81
|
159 config.anchor = config.anchor or "UIParent"
|
flickerstreak@81
|
160 config.point = config.point or "BOTTOM"
|
flickerstreak@81
|
161 config.relpoint = config.relpoint or "BOTTOM"
|
flickerstreak@48
|
162 config.y = config.y or 200
|
flickerstreak@48
|
163 config.x = config.x or 0
|
flickerstreak@48
|
164 end
|
flickerstreak@211
|
165 config = config or profile.bars[name] or { }
|
flickerstreak@91
|
166
|
flickerstreak@91
|
167 profile.bars[name] = config
|
flickerstreak@91
|
168 local bar = self.Bar:New( name, config ) -- ReAction.Bar defined in Bar.lua
|
flickerstreak@205
|
169 self.bars[name] = bar
|
flickerstreak@205
|
170 self.callbacks:Fire("OnCreateBar", bar, name)
|
flickerstreak@205
|
171 if self.configMode then
|
flickerstreak@33
|
172 bar:ShowControls(true)
|
flickerstreak@33
|
173 end
|
flickerstreak@33
|
174
|
flickerstreak@28
|
175 return bar
|
flickerstreak@28
|
176 end
|
flickerstreak@28
|
177
|
flickerstreak@205
|
178 function ReAction:DestroyBar(x)
|
flickerstreak@205
|
179 local bar, name = self:GetBar(x)
|
flickerstreak@63
|
180 if bar and name then
|
flickerstreak@205
|
181 self.bars[name] = nil
|
flickerstreak@205
|
182 self.callbacks:Fire("OnDestroyBar", bar, name)
|
flickerstreak@205
|
183 bar:Destroy()
|
flickerstreak@28
|
184 end
|
flickerstreak@28
|
185 end
|
flickerstreak@28
|
186
|
flickerstreak@205
|
187 function ReAction:RefreshBar(x)
|
flickerstreak@205
|
188 local bar, name = self:GetBar(x)
|
flickerstreak@205
|
189 if bar and name then
|
flickerstreak@205
|
190 self.callbacks:Fire("OnRefreshBar", bar, name)
|
flickerstreak@205
|
191 end
|
flickerstreak@63
|
192 end
|
flickerstreak@63
|
193
|
flickerstreak@205
|
194 function ReAction:InitializeBars()
|
flickerstreak@205
|
195 if not self.barsInitialized then
|
flickerstreak@211
|
196 self:ManageBlizzardBars()
|
flickerstreak@211
|
197
|
flickerstreak@205
|
198 for name, config in pairs(self.db.profile.bars) do
|
flickerstreak@205
|
199 if config then
|
flickerstreak@205
|
200 self:CreateBar(name, config)
|
flickerstreak@205
|
201 end
|
flickerstreak@205
|
202 end
|
flickerstreak@205
|
203 -- re-anchor and refresh in case anchor order does not match init order
|
flickerstreak@205
|
204 for name, bar in pairs(self.bars) do
|
flickerstreak@205
|
205 bar:ApplyAnchor()
|
flickerstreak@205
|
206 self.callbacks:Fire("OnRefreshBar", bar, name)
|
flickerstreak@205
|
207 end
|
flickerstreak@205
|
208 self.barsInitialized = true
|
flickerstreak@205
|
209 end
|
flickerstreak@205
|
210 end
|
flickerstreak@205
|
211
|
flickerstreak@205
|
212 function ReAction:TearDownBars()
|
flickerstreak@205
|
213 for name, bar in pairs(self.bars) do
|
flickerstreak@205
|
214 if bar then
|
flickerstreak@208
|
215 self.bars[name] = self:DestroyBar(bar)
|
flickerstreak@205
|
216 end
|
flickerstreak@205
|
217 end
|
flickerstreak@205
|
218 self.barsInitialized = false
|
flickerstreak@205
|
219 end
|
flickerstreak@205
|
220
|
flickerstreak@205
|
221 function ReAction:RebuildAll()
|
flickerstreak@205
|
222 self:TearDownBars()
|
flickerstreak@205
|
223 self:InitializeBars()
|
flickerstreak@28
|
224 end
|
flickerstreak@28
|
225
|
flickerstreak@28
|
226 function ReAction:RenameBar(x, newname)
|
flickerstreak@205
|
227 local bar, name = self:GetBar(x)
|
flickerstreak@63
|
228 if type(newname) ~= "string" then
|
flickerstreak@63
|
229 error("ReAction:RenameBar() - second argument must be a string")
|
flickerstreak@63
|
230 end
|
flickerstreak@63
|
231 if bar and name and #newname > 0 then
|
flickerstreak@127
|
232 if newname == name then
|
flickerstreak@127
|
233 return
|
flickerstreak@127
|
234 end
|
flickerstreak@205
|
235 if self.bars[newname] then
|
flickerstreak@127
|
236 self:UserError(format(L["ReAction: name '%s' already in use"],newname))
|
flickerstreak@47
|
237 else
|
flickerstreak@205
|
238 self.bars[newname], self.bars[name] = self.bars[name], nil
|
flickerstreak@47
|
239 bar:SetName(newname or "")
|
flickerstreak@47
|
240 local cfg = self.db.profile.bars
|
flickerstreak@47
|
241 cfg[newname], cfg[name] = cfg[name], nil
|
flickerstreak@205
|
242 self.callbacks:Fire("OnRenameBar", bar, name, newname)
|
flickerstreak@28
|
243 end
|
flickerstreak@28
|
244 end
|
flickerstreak@28
|
245 end
|
flickerstreak@28
|
246
|
flickerstreak@205
|
247 function ReAction:EraseBar(x)
|
flickerstreak@205
|
248 local bar, name = self:GetBar(x)
|
flickerstreak@63
|
249 if bar and name then
|
flickerstreak@205
|
250 self.callbacks:Fire("OnEraseBar", bar, name)
|
flickerstreak@208
|
251 self:DestroyBar(bar)
|
flickerstreak@205
|
252 self.db.profile.bars[name] = nil
|
flickerstreak@63
|
253 end
|
flickerstreak@63
|
254 end
|
flickerstreak@63
|
255
|
flickerstreak@211
|
256 local blizzFrames = {
|
flickerstreak@211
|
257 MainMenuBar,
|
flickerstreak@211
|
258 MultiBarLeft,
|
flickerstreak@211
|
259 MultiBarRight,
|
flickerstreak@211
|
260 MultiBarBottomLeft,
|
flickerstreak@211
|
261 MultiBarBottomRight,
|
flickerstreak@211
|
262 }
|
flickerstreak@211
|
263
|
flickerstreak@211
|
264 local hideFrame = CreateFrame("Frame")
|
flickerstreak@211
|
265 hideFrame:Hide()
|
flickerstreak@211
|
266 local hiddenParents = { }
|
flickerstreak@211
|
267 local function ManageBlizzFrame(f, hide)
|
flickerstreak@211
|
268 if hide and not hiddenParents[f] then
|
flickerstreak@211
|
269 hiddenParents[f] = f:GetParent()
|
flickerstreak@211
|
270 f:SetParent(hideFrame)
|
flickerstreak@211
|
271 elseif not hide and hiddenParents[f] then
|
flickerstreak@211
|
272 f:SetParent(hiddenParents[f])
|
flickerstreak@211
|
273 hiddenParents[f] = nil
|
flickerstreak@211
|
274 if f:IsShown() then
|
flickerstreak@211
|
275 f:Show() -- refresh
|
flickerstreak@211
|
276 end
|
flickerstreak@211
|
277 end
|
flickerstreak@211
|
278 end
|
flickerstreak@211
|
279
|
flickerstreak@211
|
280 function ReAction:ManageBlizzardBars()
|
flickerstreak@211
|
281 for _, f in pairs(blizzFrames) do
|
flickerstreak@211
|
282 ManageBlizzFrame(f, self.db.profile.options.hideBlizzardBars)
|
flickerstreak@211
|
283 end
|
flickerstreak@211
|
284 ManageBlizzFrame(VehicleMenuBar, self.db.profile.options.hideBlizzardVehicleBar)
|
flickerstreak@211
|
285 end
|
flickerstreak@211
|
286
|
flickerstreak@218
|
287 function ReAction:RegisterBarType( class, isDefault )
|
flickerstreak@218
|
288 local name = class:GetBarType()
|
flickerstreak@218
|
289 self.barTypes[name] = class
|
flickerstreak@218
|
290 if isDefault then
|
flickerstreak@218
|
291 self.defaultBarType = name
|
flickerstreak@48
|
292 end
|
flickerstreak@185
|
293 self:RefreshEditor()
|
flickerstreak@48
|
294 end
|
flickerstreak@48
|
295
|
flickerstreak@218
|
296 function ReAction:UnregisterBarType( class )
|
flickerstreak@218
|
297 local name = class:GetBarType()
|
flickerstreak@218
|
298 self.barTypes[name] = nil
|
flickerstreak@218
|
299 if self.defaultBarType == name then
|
flickerstreak@218
|
300 self.defaultBarType = nil
|
flickerstreak@48
|
301 end
|
flickerstreak@185
|
302 self:RefreshEditor()
|
flickerstreak@48
|
303 end
|
flickerstreak@48
|
304
|
flickerstreak@63
|
305 function ReAction:IterateBarTypes()
|
flickerstreak@218
|
306 return pairs(self.barTypes)
|
flickerstreak@63
|
307 end
|
flickerstreak@63
|
308
|
flickerstreak@218
|
309 function ReAction:GetDefaultBarConfig(barType)
|
flickerstreak@218
|
310 if barType and self.barTypes[barType] then
|
flickerstreak@218
|
311 return self.barTypes[barType]:GetDefaultBarConfig()
|
flickerstreak@63
|
312 end
|
flickerstreak@63
|
313 end
|
flickerstreak@63
|
314
|
flickerstreak@63
|
315 function ReAction:GetBarTypeOptions( fill )
|
flickerstreak@63
|
316 fill = fill or { }
|
flickerstreak@63
|
317 for k in self:IterateBarTypes() do
|
flickerstreak@63
|
318 fill[k] = k
|
flickerstreak@63
|
319 end
|
flickerstreak@63
|
320 return fill
|
flickerstreak@63
|
321 end
|
flickerstreak@63
|
322
|
flickerstreak@63
|
323 function ReAction:GetDefaultBarType()
|
flickerstreak@218
|
324 return self.defaultBarType
|
flickerstreak@63
|
325 end
|
flickerstreak@63
|
326
|
flickerstreak@33
|
327 function ReAction:SetConfigMode( mode )
|
flickerstreak@205
|
328 if mode ~= self.configMode then
|
flickerstreak@207
|
329 if mode then
|
flickerstreak@207
|
330 self:SetKeybindMode(false)
|
flickerstreak@207
|
331 end
|
flickerstreak@205
|
332 self.configMode = mode
|
flickerstreak@205
|
333 self.callbacks:Fire("OnConfigModeChanged", mode)
|
flickerstreak@77
|
334 end
|
flickerstreak@63
|
335 end
|
flickerstreak@63
|
336
|
flickerstreak@63
|
337 function ReAction:GetConfigMode()
|
flickerstreak@205
|
338 return self.configMode
|
flickerstreak@33
|
339 end
|
flickerstreak@38
|
340
|
flickerstreak@88
|
341 function ReAction:SetKeybindMode( mode )
|
flickerstreak@205
|
342 if mode ~= self.kbMode then
|
flickerstreak@88
|
343 if mode then
|
flickerstreak@207
|
344 self:SetConfigMode(false)
|
flickerstreak@184
|
345 LKB:Activate()
|
flickerstreak@88
|
346 else
|
flickerstreak@184
|
347 LKB:Deactivate()
|
flickerstreak@88
|
348 end
|
flickerstreak@207
|
349 for _, bar in self:IterateBars() do
|
flickerstreak@207
|
350 bar:SetKeybindMode(mode)
|
flickerstreak@207
|
351 end
|
flickerstreak@205
|
352 self.kbMode = LKB:IsShown() or false
|
flickerstreak@88
|
353 end
|
flickerstreak@88
|
354 end
|
flickerstreak@88
|
355
|
flickerstreak@88
|
356 function ReAction:GetKeybindMode( mode )
|
flickerstreak@205
|
357 return self.kbMode
|
flickerstreak@88
|
358 end
|