flickerstreak@7
|
1 -- main.lua
|
flickerstreak@1
|
2 --
|
flickerstreak@1
|
3 -- Top-level file for the ReAction Action Bar add-on
|
flickerstreak@1
|
4 --
|
flickerstreak@7
|
5 -- implemented in terms of the Ace 2 development framework library: http://www.wowace.com
|
flickerstreak@1
|
6 --
|
flickerstreak@1
|
7
|
flickerstreak@20
|
8
|
flickerstreak@7
|
9 -- Ace Library local object initialization
|
flickerstreak@7
|
10 local L = AceLibrary("AceLocale-2.2"):new("ReAction")
|
flickerstreak@7
|
11 local dewdrop = AceLibrary("Dewdrop-2.0")
|
flickerstreak@7
|
12 local tablet = AceLibrary("Tablet-2.0")
|
flickerstreak@17
|
13 local ReBound = AceLibrary("ReBound-1.0"):new("ReAction")
|
flickerstreak@1
|
14
|
flickerstreak@7
|
15 -- private functions
|
flickerstreak@2
|
16 local function tcopy(t)
|
flickerstreak@2
|
17 local r = { }
|
flickerstreak@2
|
18 for k, v in pairs(t) do
|
flickerstreak@2
|
19 r[k] = (type(v) == "table" and tcopy(v) or v)
|
flickerstreak@2
|
20 end
|
flickerstreak@2
|
21 return r
|
flickerstreak@2
|
22 end
|
flickerstreak@2
|
23
|
flickerstreak@7
|
24 -- private constants
|
flickerstreak@7
|
25 local EMPTY_BAR_SLOT = -1
|
flickerstreak@7
|
26
|
flickerstreak@7
|
27 -- key binding label constants
|
flickerstreak@17
|
28 BINDING_HEADER_REACTION = L["ReAction"]
|
flickerstreak@17
|
29 BINDING_NAME_REACTION_TOGGLELOCK = L["Toggle ReAction Bar Lock"]
|
flickerstreak@17
|
30 BINDING_NAME_REACTION_TOGGLEKEYBIND = L["ReAction Keybinding Mode"]
|
flickerstreak@7
|
31
|
flickerstreak@10
|
32 -- UI panel strings
|
flickerstreak@17
|
33 REACTION_KEYBIND_TITLE = L["ReAction Keybinding"]
|
flickerstreak@17
|
34 REACTION_KEYBIND_SUBTITLE = L["Click Buttons to Set Keybindings"]
|
flickerstreak@17
|
35 REACTION_KEYBIND_DONE = L["Save"]
|
flickerstreak@17
|
36 REACTION_KEYBIND_REVERT = L["Revert"]
|
flickerstreak@7
|
37
|
flickerstreak@10
|
38
|
flickerstreak@10
|
39
|
flickerstreak@10
|
40 ------------------------------
|
flickerstreak@10
|
41 -- AceAddon setup
|
flickerstreak@10
|
42 ------------------------------
|
flickerstreak@7
|
43 local main = AceLibrary("AceAddon-2.0"):new(
|
flickerstreak@7
|
44 "AceConsole-2.0",
|
flickerstreak@7
|
45 "AceEvent-2.0",
|
flickerstreak@7
|
46 "AceDB-2.0",
|
flickerstreak@7
|
47 "FuBarPlugin-2.0"
|
flickerstreak@7
|
48 )
|
flickerstreak@1
|
49
|
flickerstreak@10
|
50 function main:OnInitialize()
|
flickerstreak@10
|
51 self:RegisterChatCommand( {L["/reaction"], L["/rxn"]}, ReActionConsoleOptions, "REACTION" )
|
flickerstreak@10
|
52 self:RegisterDB("ReActionDB","ReActionDBPC")
|
flickerstreak@10
|
53 self:RegisterDefaults("profile", ReAction_DefaultProfile)
|
flickerstreak@10
|
54 self:RegisterEvent("PLAYER_REGEN_DISABLED","CombatLockdown")
|
flickerstreak@10
|
55 self:DisableDefaultKeybindings()
|
flickerstreak@1
|
56
|
flickerstreak@12
|
57 -- create update function for keybinding frame
|
flickerstreak@17
|
58 ReActionKeybindDialog:SetScript("OnHide", function(frame) main:HideKeybindDialog(frame) end)
|
flickerstreak@12
|
59
|
flickerstreak@10
|
60 -- initial non-persistent state
|
flickerstreak@10
|
61 self.locked = true
|
flickerstreak@17
|
62 self.keybindMode = false
|
flickerstreak@10
|
63 self.bars = { }
|
flickerstreak@10
|
64 end
|
flickerstreak@7
|
65
|
flickerstreak@17
|
66 -- OnEnable is called at PLAYER_LOGIN or when the addon is enabled.
|
flickerstreak@12
|
67 function main:OnEnable( )
|
flickerstreak@17
|
68 self:HideDefaultBars()
|
flickerstreak@17
|
69 self:SetupProfile( )
|
flickerstreak@10
|
70 end
|
flickerstreak@7
|
71
|
flickerstreak@10
|
72 function main:OnDisable()
|
flickerstreak@10
|
73 self:Lock()
|
flickerstreak@10
|
74 end
|
flickerstreak@10
|
75
|
flickerstreak@10
|
76 -- OnProfileEnable() is only called when switching profiles, NOT for the initial profile at load time.
|
flickerstreak@10
|
77 function main:OnProfileEnable( oldName, oldData )
|
flickerstreak@12
|
78 self:UnregisterEvent("REBOUND_BIND")
|
flickerstreak@12
|
79 self:UnregisterEvent("REBOUND_UNBIND")
|
flickerstreak@12
|
80 ReBound:ClearRegisteredBindings()
|
flickerstreak@17
|
81 self:SetupProfile()
|
flickerstreak@10
|
82 end
|
flickerstreak@10
|
83
|
flickerstreak@17
|
84 function main:SetupProfile( )
|
flickerstreak@17
|
85 local profile = self.db.profile
|
flickerstreak@17
|
86 if profile.firstRunDone ~= true then
|
flickerstreak@17
|
87 profile.bars = tcopy(ReAction_DefaultBlizzardBars)
|
flickerstreak@17
|
88 end
|
flickerstreak@17
|
89 self:DestroyAllBars()
|
flickerstreak@17
|
90 self:UpgradeProfile()
|
flickerstreak@17
|
91 self:HideArt()
|
flickerstreak@17
|
92 self:SetupBars()
|
flickerstreak@17
|
93 self:SetupKeybindings()
|
flickerstreak@17
|
94 if profile.firstRunDone ~= true then
|
flickerstreak@17
|
95 self:Unlock()
|
flickerstreak@17
|
96 profile.firstRunDone = true
|
flickerstreak@17
|
97 end
|
flickerstreak@17
|
98 end
|
flickerstreak@17
|
99
|
flickerstreak@17
|
100 -- Set a global variable for Bindings.xml (I use 'setglobal' for clarity, it's not strictly necessary)
|
flickerstreak@17
|
101 setglobal("ReActionAddOn", main)
|
flickerstreak@17
|
102
|
flickerstreak@17
|
103
|
flickerstreak@17
|
104
|
flickerstreak@17
|
105
|
flickerstreak@17
|
106 ------------------------------------------------------------
|
flickerstreak@17
|
107 -- Profile conversion functions (from old profiles)
|
flickerstreak@17
|
108 --
|
flickerstreak@17
|
109 -- NOTE: these will be REMOVED when alpha testing is over.
|
flickerstreak@17
|
110 ------------------------------------------------------------
|
flickerstreak@17
|
111 function main:UpgradeBindingConfig()
|
flickerstreak@17
|
112 if #self.db.profile.bindings == 0 then
|
flickerstreak@10
|
113 for _, bar in pairs(self.bars) do
|
flickerstreak@10
|
114 for _, button in pairs(bar.buttons) do
|
flickerstreak@10
|
115 local key = ReBound:GetBinding(button:GetActionFrame(),"LeftButton")
|
flickerstreak@10
|
116 if key and #key > 0 and not self.db.profile.bindings[key] then
|
flickerstreak@10
|
117 self:REBOUND_BIND(key,button:GetActionFrame():GetName(),"LeftButton")
|
flickerstreak@10
|
118 end
|
flickerstreak@10
|
119 end
|
flickerstreak@10
|
120 end
|
flickerstreak@10
|
121 end
|
flickerstreak@10
|
122 end
|
flickerstreak@10
|
123
|
flickerstreak@17
|
124 function main:UpgradeProfile()
|
flickerstreak@17
|
125 end
|
flickerstreak@10
|
126
|
flickerstreak@10
|
127
|
flickerstreak@10
|
128
|
flickerstreak@10
|
129 --------------------------------------------
|
flickerstreak@7
|
130 -- FuBar plugin setup
|
flickerstreak@10
|
131 -- Even if FuBar isn't installed, the plugin
|
flickerstreak@10
|
132 -- provides a nice minimap-button interface.
|
flickerstreak@10
|
133 ---------------------------------------------
|
flickerstreak@7
|
134 main.hasIcon = "Interface\\Icons\\INV_Qiraj_JewelEncased"
|
flickerstreak@7
|
135 main.hasNoColor = true
|
flickerstreak@7
|
136 main.hideMenuTitle = true
|
flickerstreak@7
|
137 main.defaultPosition = "LEFT"
|
flickerstreak@7
|
138 main.defaultMinimapPosition = 240 -- degrees
|
flickerstreak@7
|
139 main.OnMenuRequest = tcopy(ReActionGlobalMenuOptions) -- use a copy, or bar menus will have FuBar inserted items
|
flickerstreak@7
|
140 main.independentProfile = true
|
flickerstreak@7
|
141
|
flickerstreak@7
|
142 -- set the handler for the global bar menu options
|
flickerstreak@7
|
143 -- have to do this after tcopy() above, otherwise it will try to copy the handler object (bad idea)
|
flickerstreak@7
|
144 ReActionGlobalMenuOptions.handler = main
|
flickerstreak@7
|
145
|
flickerstreak@7
|
146 function main:OnTooltipUpdate()
|
flickerstreak@7
|
147 local c = tablet:AddCategory("columns", 2)
|
flickerstreak@7
|
148 c:AddLine("text", L["Bar lock"], "text2", self.locked and ("|cffff0000"..L["Locked"].."|r") or ("|cffffcc00"..L["Unlocked"].."|r"))
|
flickerstreak@7
|
149 c:AddLine("text", L["Button lock"], "text2", LOCK_ACTIONBAR == "1" and ("|cffcc0000"..L["Locked"].."|r") or ("|cff00cc00"..L["Unlocked"].."|r"))
|
flickerstreak@10
|
150 c:AddLine("text", L["Kebinding mode"], "text2", self:GetKeybindMode() and ("|cff33ff33"..L["On"].."|r") or ("|cffffcc00"..L["Off"].."|r"))
|
flickerstreak@7
|
151 tablet:SetHint(L["|cffffcc00Shift-Click for bar lock|n|cff33ff33Alt-Click|r for keybindings|nRight-click for menu"])
|
flickerstreak@7
|
152 end
|
flickerstreak@7
|
153
|
flickerstreak@7
|
154 function main:OnClick(button)
|
flickerstreak@7
|
155 if IsShiftKeyDown() then
|
flickerstreak@7
|
156 self:ToggleLocked()
|
flickerstreak@7
|
157 self:UpdateDisplay()
|
flickerstreak@7
|
158 elseif IsAltKeyDown() then
|
flickerstreak@10
|
159 self:ToggleKeybindMode()
|
flickerstreak@7
|
160 self:UpdateDisplay()
|
flickerstreak@7
|
161 end
|
flickerstreak@7
|
162 end
|
flickerstreak@7
|
163
|
flickerstreak@7
|
164
|
flickerstreak@10
|
165
|
flickerstreak@10
|
166
|
flickerstreak@10
|
167 ------------------------------
|
flickerstreak@10
|
168 -- Key binding functions
|
flickerstreak@10
|
169 ------------------------------
|
flickerstreak@10
|
170 function main:DisableDefaultKeybindings()
|
flickerstreak@17
|
171 -- change the labels on all actionbar keybindings in the default interface.
|
flickerstreak@10
|
172 local label = "|cff999999("..L["Use ReAction"]..")|r"
|
flickerstreak@10
|
173 for i = 1, 12 do
|
flickerstreak@10
|
174 setglobal("BINDING_NAME_ACTIONBUTTON"..i,label)
|
flickerstreak@10
|
175 for j = 1, 4 do
|
flickerstreak@10
|
176 setglobal("BINDING_NAME_MULTIACTIONBAR"..j.."BUTTON"..i,label)
|
flickerstreak@10
|
177 end
|
flickerstreak@10
|
178 end
|
flickerstreak@10
|
179 for i = 1, 6 do
|
flickerstreak@10
|
180 setglobal("BINDING_NAME_ACTIONPAGE"..i,label)
|
flickerstreak@10
|
181 end
|
flickerstreak@10
|
182 for i = 1, 10 do
|
flickerstreak@10
|
183 setglobal("BINDING_NAME_BONUSACTIONBUTTON"..i,label)
|
flickerstreak@17
|
184 -- setglobal("BINDING_NAME_SHAPESHIFTBUTTON"..i,label)
|
flickerstreak@10
|
185 end
|
flickerstreak@10
|
186 BINDING_HEADER_ACTIONBAR = "|cff999999"..L["Action Bar Functions Disabled"].."|r"
|
flickerstreak@10
|
187 BINDING_HEADER_MULTIACTIONBAR = "|cff999999"..L["Multi-Action Bar Functions Disabled"].."|r"
|
flickerstreak@10
|
188 BINDING_NAME_NEXTACTIONPAGE = label
|
flickerstreak@10
|
189 BINDING_NAME_PREVIOUSACTIONPAGE = label
|
flickerstreak@10
|
190 end
|
flickerstreak@10
|
191
|
flickerstreak@12
|
192 function main:SetupKeybindings()
|
flickerstreak@10
|
193 if self.db.profile.firstRunDone ~= true then
|
flickerstreak@10
|
194 self:StealKeyBindings()
|
flickerstreak@10
|
195 else
|
flickerstreak@17
|
196 self:UpgradeBindingConfig()
|
flickerstreak@17
|
197 local needsSave = false
|
flickerstreak@10
|
198 for key, binding in pairs(self.db.profile.bindings) do
|
flickerstreak@12
|
199 local target = getglobal(binding.target)
|
flickerstreak@12
|
200 if target then
|
flickerstreak@17
|
201 if ReBound:GetBinding(target,binding.button) ~= key then
|
flickerstreak@17
|
202 ReBound:SetBinding(key,target,binding.button,true)
|
flickerstreak@17
|
203 needsSave = true
|
flickerstreak@17
|
204 end
|
flickerstreak@12
|
205 end
|
flickerstreak@10
|
206 end
|
flickerstreak@17
|
207 if needsSave then
|
flickerstreak@17
|
208 ReBound:SaveBindings()
|
flickerstreak@17
|
209 end
|
flickerstreak@10
|
210 end
|
flickerstreak@10
|
211 self:RegisterEvent("REBOUND_BIND")
|
flickerstreak@10
|
212 self:RegisterEvent("REBOUND_UNBIND")
|
flickerstreak@10
|
213 end
|
flickerstreak@10
|
214
|
flickerstreak@10
|
215 function main:StealKeyBindings()
|
flickerstreak@10
|
216 -- steal the keybindings of the main action bar and assign them to rebar 1, buttons 1-12
|
flickerstreak@17
|
217 local bar = self.bars[1]
|
flickerstreak@17
|
218 if bar and bar ~= EMPTY_BAR_SLOT then
|
flickerstreak@17
|
219 for i = 1, 12 do
|
flickerstreak@17
|
220 local key = GetBindingKey("ACTIONBUTTON"..i)
|
flickerstreak@17
|
221 if key and #key > 0 then
|
flickerstreak@17
|
222 local button = bar.buttons[i]
|
flickerstreak@17
|
223 if button then
|
flickerstreak@17
|
224 ReBound:SetBinding(key, button:GetActionFrame(),nil,true)
|
flickerstreak@17
|
225 end
|
flickerstreak@17
|
226 end
|
flickerstreak@17
|
227 end
|
flickerstreak@17
|
228 local key = GetBindingKey("NEXTACTIONPAGE")
|
flickerstreak@10
|
229 if key and #key > 0 then
|
flickerstreak@17
|
230 ReBound:SetBinding(key, bar.upArrow,nil,true)
|
flickerstreak@10
|
231 end
|
flickerstreak@17
|
232 key = GetBindingKey("PREVIOUSACTIONPAGE")
|
flickerstreak@17
|
233 if key and #key > 0 then
|
flickerstreak@17
|
234 ReBound:SetBinding(key, bar.downArrow,nil,true)
|
flickerstreak@17
|
235 end
|
flickerstreak@17
|
236 ReBound:SaveBindings()
|
flickerstreak@10
|
237 end
|
flickerstreak@10
|
238 end
|
flickerstreak@10
|
239
|
flickerstreak@12
|
240 function main:REBOUND_BIND(id, key, target, button)
|
flickerstreak@17
|
241 if id == "ReAction" and key and target then
|
flickerstreak@10
|
242 self.db.profile.bindings[key] = { target = target, button = button }
|
flickerstreak@10
|
243 end
|
flickerstreak@10
|
244 end
|
flickerstreak@10
|
245
|
flickerstreak@12
|
246 function main:REBOUND_UNBIND(id, key)
|
flickerstreak@17
|
247 if id == "ReAction" and key then
|
flickerstreak@10
|
248 self.db.profile.bindings[key] = nil
|
flickerstreak@10
|
249 end
|
flickerstreak@10
|
250 end
|
flickerstreak@10
|
251
|
flickerstreak@10
|
252 function main:ToggleKeybindMode()
|
flickerstreak@10
|
253 self:SetKeybindMode(not self:GetKeybindMode())
|
flickerstreak@10
|
254 end
|
flickerstreak@10
|
255
|
flickerstreak@10
|
256 function main:GetKeybindMode()
|
flickerstreak@10
|
257 return self.keybindMode
|
flickerstreak@10
|
258 end
|
flickerstreak@10
|
259
|
flickerstreak@10
|
260 function main:SetKeybindMode(enabled)
|
flickerstreak@17
|
261 if InCombatLockdown() then
|
flickerstreak@17
|
262 UIErrorsFrame:AddMessage(ERROR_NOT_IN_COMBAT)
|
flickerstreak@17
|
263 else
|
flickerstreak@10
|
264 self.keybindMode = enabled
|
flickerstreak@10
|
265 for _, bar in pairs(self.bars) do
|
flickerstreak@17
|
266 if bar and bar ~= EMPTY_BAR_SLOT then
|
flickerstreak@17
|
267 for __, button in pairs(bar.buttons) do
|
flickerstreak@17
|
268 if button then
|
flickerstreak@17
|
269 button:TempShow(enabled)
|
flickerstreak@17
|
270 end
|
flickerstreak@10
|
271 end
|
flickerstreak@10
|
272 end
|
flickerstreak@10
|
273 end
|
flickerstreak@10
|
274 if enabled then
|
flickerstreak@17
|
275 ReBound:ShowRegisteredFrames()
|
flickerstreak@10
|
276 ReActionKeybindDialog:Show()
|
flickerstreak@10
|
277 else
|
flickerstreak@17
|
278 ReBound:HideRegisteredFrames()
|
flickerstreak@10
|
279 if ReActionKeybindDialog:IsShown() then
|
flickerstreak@10
|
280 ReActionKeybindDialog:Hide()
|
flickerstreak@10
|
281 end
|
flickerstreak@10
|
282 end
|
flickerstreak@10
|
283 end
|
flickerstreak@10
|
284 end
|
flickerstreak@10
|
285
|
flickerstreak@17
|
286 function main:HideKeybindDialog( frame )
|
flickerstreak@17
|
287 self:SetKeybindMode(false)
|
flickerstreak@17
|
288 if frame.save then
|
flickerstreak@17
|
289 ReBound:SaveBindings()
|
flickerstreak@17
|
290 else
|
flickerstreak@17
|
291 ReBound:RevertBindings()
|
flickerstreak@17
|
292 end
|
flickerstreak@17
|
293 frame.save = false
|
flickerstreak@17
|
294 end
|
flickerstreak@10
|
295
|
flickerstreak@10
|
296
|
flickerstreak@10
|
297 ----------------------------
|
flickerstreak@10
|
298 -- Bar lock/unlock functions
|
flickerstreak@10
|
299 ----------------------------
|
flickerstreak@10
|
300 function main:CombatLockdown()
|
flickerstreak@10
|
301 if not self:IsLocked() then
|
flickerstreak@10
|
302 self:Lock()
|
flickerstreak@10
|
303 UIErrorsFrame:AddMessage(L["ReAction bars locked when in combat"])
|
flickerstreak@10
|
304 end
|
flickerstreak@10
|
305 ReActionKeybindDialog:Hide()
|
flickerstreak@10
|
306 end
|
flickerstreak@10
|
307
|
flickerstreak@7
|
308 function main:SetLocked( lock )
|
flickerstreak@2
|
309 if lock ~= self.locked then
|
flickerstreak@2
|
310 if not lock and InCombatLockdown() then
|
flickerstreak@10
|
311 UIErrorsFrame:AddMessage(ERROR_NOT_IN_COMBAT)
|
flickerstreak@2
|
312 else
|
flickerstreak@2
|
313 self.locked = lock and true or false -- force data integrity
|
flickerstreak@2
|
314 for _, bar in pairs(self.bars) do
|
flickerstreak@7
|
315 if bar ~= EMPTY_BAR_SLOT then
|
flickerstreak@7
|
316 if self.locked then
|
flickerstreak@7
|
317 bar:HideControls()
|
flickerstreak@7
|
318 -- close any dewdrop menu owned by the bar
|
flickerstreak@7
|
319 if bar:GetControlFrame() == dewdrop:GetOpenedParent() then
|
flickerstreak@7
|
320 dewdrop:Close()
|
flickerstreak@7
|
321 end
|
flickerstreak@7
|
322 else
|
flickerstreak@7
|
323 bar:ShowControls()
|
flickerstreak@7
|
324 end
|
flickerstreak@7
|
325 end
|
flickerstreak@2
|
326 end
|
flickerstreak@2
|
327 end
|
flickerstreak@1
|
328 end
|
flickerstreak@1
|
329 end
|
flickerstreak@1
|
330
|
flickerstreak@7
|
331 function main:IsLocked()
|
flickerstreak@1
|
332 return self.locked
|
flickerstreak@1
|
333 end
|
flickerstreak@1
|
334
|
flickerstreak@7
|
335 function main:Lock()
|
flickerstreak@1
|
336 self:SetLocked(true)
|
flickerstreak@1
|
337 end
|
flickerstreak@1
|
338
|
flickerstreak@7
|
339 function main:Unlock()
|
flickerstreak@1
|
340 self:SetLocked(false)
|
flickerstreak@1
|
341 end
|
flickerstreak@1
|
342
|
flickerstreak@7
|
343 function main:ToggleLocked()
|
flickerstreak@17
|
344 self:SetLocked( not(self.locked) )
|
flickerstreak@1
|
345 end
|
flickerstreak@1
|
346
|
flickerstreak@1
|
347
|
flickerstreak@1
|
348
|
flickerstreak@10
|
349 --------------------------------------------------------
|
flickerstreak@10
|
350 -- Functions to hide the default Blizzard main bar parts
|
flickerstreak@10
|
351 --------------------------------------------------------
|
flickerstreak@7
|
352 function main:HideArt()
|
flickerstreak@1
|
353 if self.db.profile.hideArt then
|
flickerstreak@17
|
354 -- the pet bar is a child of MainMenuBar, but can't be hidden because it will
|
flickerstreak@17
|
355 -- break automatic pet bar show/hide. Need to reparent it.
|
flickerstreak@7
|
356 PetActionBarFrame:SetParent(UIParent)
|
flickerstreak@17
|
357
|
flickerstreak@7
|
358 -- these two are the pet bar background
|
flickerstreak@7
|
359 -- unfortunately UIParent_ManageFramePositions() shows and hides these too
|
flickerstreak@7
|
360 -- so they get reparented to MainMenuBar
|
flickerstreak@7
|
361 SlidingActionBarTexture0:SetParent(MainMenuBar)
|
flickerstreak@7
|
362 SlidingActionBarTexture1:SetParent(MainMenuBar)
|
flickerstreak@17
|
363
|
flickerstreak@17
|
364 MainMenuBar:Hide() -- this also hides the bags, xp bar, lag meter, and micro menu buttons.
|
flickerstreak@1
|
365 else
|
flickerstreak@7
|
366 SlidingActionBarTexture0:SetParent(PetActionBarFrame)
|
flickerstreak@7
|
367 SlidingActionBarTexture1:SetParent(PetActionBarFrame)
|
flickerstreak@17
|
368 PetActionBarFrame:SetParent(MainMenuBar)
|
flickerstreak@1
|
369 MainMenuBar:Show()
|
flickerstreak@1
|
370 end
|
flickerstreak@1
|
371 end
|
flickerstreak@1
|
372
|
flickerstreak@7
|
373 function main:IsArtHidden()
|
flickerstreak@1
|
374 return self.db.profile.hideArt
|
flickerstreak@1
|
375 end
|
flickerstreak@1
|
376
|
flickerstreak@7
|
377 function main:SetHideArt( hide )
|
flickerstreak@2
|
378 if InCombatLockdown() then
|
flickerstreak@2
|
379 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT)
|
flickerstreak@2
|
380 else
|
flickerstreak@2
|
381 self.db.profile.hideArt = hide and true or false -- force data integrity
|
flickerstreak@2
|
382 self:HideArt()
|
flickerstreak@2
|
383 end
|
flickerstreak@1
|
384 end
|
flickerstreak@1
|
385
|
flickerstreak@7
|
386 function main:ToggleHideArt()
|
flickerstreak@1
|
387 self:SetHideArt( not self:IsArtHidden() )
|
flickerstreak@1
|
388 end
|
flickerstreak@1
|
389
|
flickerstreak@1
|
390 -- Hide default Blizzard bars
|
flickerstreak@1
|
391 local blizzDefaultBars = {
|
flickerstreak@1
|
392 ActionButton1,
|
flickerstreak@1
|
393 ActionButton2,
|
flickerstreak@1
|
394 ActionButton3,
|
flickerstreak@1
|
395 ActionButton4,
|
flickerstreak@1
|
396 ActionButton5,
|
flickerstreak@1
|
397 ActionButton6,
|
flickerstreak@1
|
398 ActionButton7,
|
flickerstreak@1
|
399 ActionButton8,
|
flickerstreak@1
|
400 ActionButton9,
|
flickerstreak@1
|
401 ActionButton10,
|
flickerstreak@1
|
402 ActionButton11,
|
flickerstreak@1
|
403 ActionButton12,
|
flickerstreak@7
|
404 PetActionButton1,
|
flickerstreak@7
|
405 PetActionButton2,
|
flickerstreak@7
|
406 PetActionButton3,
|
flickerstreak@7
|
407 PetActionButton4,
|
flickerstreak@7
|
408 PetActionButton5,
|
flickerstreak@7
|
409 PetActionButton6,
|
flickerstreak@7
|
410 PetActionButton7,
|
flickerstreak@7
|
411 PetActionButton8,
|
flickerstreak@7
|
412 PetActionButton9,
|
flickerstreak@7
|
413 PetActionButton10,
|
flickerstreak@7
|
414 -- NOT the PetActionBarFrame, though - we need that to auto-hide/show our pet action bars
|
flickerstreak@7
|
415 MainMenuBarPageNumber,
|
flickerstreak@7
|
416 ActionBarUpButton,
|
flickerstreak@7
|
417 ActionBarDownButton,
|
flickerstreak@1
|
418 BonusActionBarFrame,
|
flickerstreak@7
|
419 ShapeshiftBarFrame,
|
flickerstreak@1
|
420 MultiBarLeft,
|
flickerstreak@1
|
421 MultiBarRight,
|
flickerstreak@1
|
422 MultiBarBottomLeft,
|
flickerstreak@7
|
423 MultiBarBottomRight,
|
flickerstreak@1
|
424 }
|
flickerstreak@1
|
425
|
flickerstreak@7
|
426 local function disableUIOptions()
|
flickerstreak@7
|
427 -- disable the buttons to hide/show the blizzard multiaction bars
|
flickerstreak@7
|
428 -- see UIOptionsFrame.lua and .xml
|
flickerstreak@7
|
429 -- This is called every time the options panel is shown, after it is set up
|
flickerstreak@7
|
430 for _, idx in pairs( { 33, 34, 35, 36, 37, 40 } ) do
|
flickerstreak@7
|
431 local f = getglobal("UIOptionsFrameCheckButton"..idx)
|
flickerstreak@7
|
432 f.disabled = true
|
flickerstreak@7
|
433 OptionsFrame_DisableCheckBox(f)
|
flickerstreak@7
|
434 f:SetChecked(false)
|
flickerstreak@7
|
435 end
|
flickerstreak@7
|
436 end
|
flickerstreak@1
|
437
|
flickerstreak@7
|
438 function main:HideDefaultBars()
|
flickerstreak@7
|
439 for _, f in pairs(blizzDefaultBars) do
|
flickerstreak@7
|
440 f:Hide()
|
flickerstreak@7
|
441 f:ClearAllPoints()
|
flickerstreak@7
|
442 f:SetParent(ReAction.recycler)
|
flickerstreak@7
|
443 f:SetPoint("TOPLEFT")
|
flickerstreak@7
|
444 end
|
flickerstreak@7
|
445
|
flickerstreak@7
|
446 MainMenuBar:SetFrameStrata("LOW") -- otherwise it appears on top of bars, if it isn't hidden
|
flickerstreak@7
|
447 hooksecurefunc("UIOptionsFrame_Load",disableUIOptions)
|
flickerstreak@7
|
448 end
|
flickerstreak@7
|
449
|
flickerstreak@7
|
450
|
flickerstreak@10
|
451
|
flickerstreak@10
|
452
|
flickerstreak@10
|
453 ---------------------------------------
|
flickerstreak@10
|
454 -- Bar setup and manipulation functions
|
flickerstreak@10
|
455 ---------------------------------------
|
flickerstreak@7
|
456 -- Reset bars to blizzard defaults
|
flickerstreak@7
|
457 function main:ResetBars()
|
flickerstreak@2
|
458 if InCombatLockdown() then
|
flickerstreak@2
|
459 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT)
|
flickerstreak@2
|
460 else
|
flickerstreak@7
|
461 self.db.profile.bars = tcopy(ReAction_DefaultBlizzardBars)
|
flickerstreak@17
|
462 self:OnProfileEnable() -- treat it like a profile switch
|
flickerstreak@2
|
463 end
|
flickerstreak@1
|
464 end
|
flickerstreak@1
|
465
|
flickerstreak@7
|
466 function main:DestroyAllBars()
|
flickerstreak@7
|
467 -- destroy any existing bars
|
flickerstreak@7
|
468 for id = 1, table.maxn(self.bars) do
|
flickerstreak@7
|
469 self:DestroyBar(id)
|
flickerstreak@7
|
470 end
|
flickerstreak@7
|
471 end
|
flickerstreak@7
|
472
|
flickerstreak@7
|
473 function main:SetupBars()
|
flickerstreak@1
|
474 -- set up the bars from the profile
|
flickerstreak@2
|
475 -- note the use of table.maxn rather than # or ipairs:
|
flickerstreak@2
|
476 -- our array of bars can in fact contain holes
|
flickerstreak@2
|
477 for id = 1, table.maxn(self.db.profile.bars) do
|
flickerstreak@2
|
478 local config = self.db.profile.bars[id]
|
flickerstreak@2
|
479 if config then
|
flickerstreak@17
|
480 self.bars[id] = self:CreateBar(config, id)
|
flickerstreak@2
|
481 end
|
flickerstreak@1
|
482 end
|
flickerstreak@1
|
483
|
flickerstreak@1
|
484 -- anchor the bars, have to do this in a second pass because
|
flickerstreak@1
|
485 -- they might be anchored to each other in a non-ordered way
|
flickerstreak@2
|
486 for _, bar in pairs(self.bars) do
|
flickerstreak@7
|
487 if bar ~= EMPTY_BAR_SLOT then
|
flickerstreak@7
|
488 bar:ApplyAnchor()
|
flickerstreak@2
|
489 end
|
flickerstreak@2
|
490 end
|
flickerstreak@1
|
491 end
|
flickerstreak@1
|
492
|
flickerstreak@7
|
493 function main:CreateBar( config, id )
|
flickerstreak@17
|
494 local buttonType = config.btnConfig and config.btnConfig.type and getglobal(config.btnConfig.type)
|
flickerstreak@17
|
495 local subtype = buttonType and buttonType:GetButtonType(config.btnConfig.subtype)
|
flickerstreak@17
|
496
|
flickerstreak@17
|
497 if not subtype then
|
flickerstreak@17
|
498 self:Print(L["Tried to create a button of unknown type"])
|
flickerstreak@17
|
499 return
|
flickerstreak@17
|
500 end
|
flickerstreak@17
|
501
|
flickerstreak@7
|
502 local bar = ReBar:new(config, id)
|
flickerstreak@1
|
503
|
flickerstreak@17
|
504 -- initialize dewdrop menu
|
flickerstreak@17
|
505 dewdrop:Register(bar:GetControlFrame(),
|
flickerstreak@17
|
506 'children',
|
flickerstreak@17
|
507 function()
|
flickerstreak@17
|
508 dewdrop:FeedAceOptionsTable(ReActionGlobalMenuOptions)
|
flickerstreak@17
|
509 dewdrop:FeedAceOptionsTable(GenerateReActionBarOptions(bar,self))
|
flickerstreak@17
|
510 dewdrop:FeedAceOptionsTable(subtype:GenerateOptionsTable(config.btnConfig, function() return bar:GetButtonList() end))
|
flickerstreak@17
|
511 end,
|
flickerstreak@17
|
512 'cursorX', true,
|
flickerstreak@17
|
513 'cursorY', true
|
flickerstreak@17
|
514 )
|
flickerstreak@7
|
515
|
flickerstreak@17
|
516 -- register page up/down buttons with ReBound for keybinding
|
flickerstreak@17
|
517 ReBound:Register(bar.upArrow)
|
flickerstreak@17
|
518 ReBound:Register(bar.downArrow)
|
flickerstreak@7
|
519
|
flickerstreak@17
|
520 if not self.locked then
|
flickerstreak@17
|
521 bar:ShowControls()
|
flickerstreak@17
|
522 end
|
flickerstreak@7
|
523
|
flickerstreak@17
|
524 return bar
|
flickerstreak@7
|
525 end
|
flickerstreak@7
|
526
|
flickerstreak@7
|
527 function main:DestroyBar( id )
|
flickerstreak@7
|
528 local bar = self.bars[id]
|
flickerstreak@7
|
529 if bar and bar ~= EMPTY_BAR_SLOT then
|
flickerstreak@7
|
530 local cf = bar:GetControlFrame()
|
flickerstreak@7
|
531 if cf == dewdrop:GetOpenedParent() then
|
flickerstreak@7
|
532 dewdrop:Close()
|
flickerstreak@7
|
533 dewdrop:Unregister(cf)
|
flickerstreak@7
|
534 end
|
flickerstreak@7
|
535 bar:Destroy()
|
flickerstreak@7
|
536 -- we can't do tremove because each bar ID is encoded into the
|
flickerstreak@7
|
537 -- frame names as they're created. Need a blank entry in the table.
|
flickerstreak@7
|
538 -- The nice thing is that table.insert in NewBar() will automatically
|
flickerstreak@7
|
539 -- find the lowest numbered nil slot.
|
flickerstreak@7
|
540 self.bars[id] = EMPTY_BAR_SLOT
|
flickerstreak@7
|
541 end
|
flickerstreak@7
|
542 end
|
flickerstreak@7
|
543
|
flickerstreak@10
|
544 --
|
flickerstreak@10
|
545 -- this function is a wrapper for CreateBar() which looks up the bar type
|
flickerstreak@10
|
546 -- and constructs a new configuration object of the right type.
|
flickerstreak@7
|
547 function main:NewBar( type )
|
flickerstreak@7
|
548 if InCombatLockdown() then
|
flickerstreak@7
|
549 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT)
|
flickerstreak@17
|
550 return
|
flickerstreak@17
|
551 end
|
flickerstreak@17
|
552
|
flickerstreak@17
|
553 local t = ReAction:GetButtonType(type)
|
flickerstreak@17
|
554 if t then
|
flickerstreak@17
|
555 local c = tcopy(ReAction_DefaultBarConfig["ReAction"][type])
|
flickerstreak@17
|
556 local id = nil
|
flickerstreak@17
|
557 for i = 1, table.maxn(self.bars) + 1 do -- there may be holes, so #self.bars won't work
|
flickerstreak@17
|
558 if self.bars[i] == nil or self.bars[i] == EMPTY_BAR_SLOT then
|
flickerstreak@17
|
559 id = i
|
flickerstreak@17
|
560 break
|
flickerstreak@7
|
561 end
|
flickerstreak@7
|
562 end
|
flickerstreak@17
|
563 self.bars[id] = self:CreateBar(c, id)
|
flickerstreak@17
|
564 self.db.profile.bars[id] = c
|
flickerstreak@17
|
565 self.bars[id]:ApplyAnchor()
|
flickerstreak@17
|
566 self:Unlock()
|
flickerstreak@7
|
567 end
|
flickerstreak@7
|
568 end
|
flickerstreak@7
|
569
|
flickerstreak@10
|
570 --
|
flickerstreak@10
|
571 -- This function is a wrapper for DestroyBar() which does in-combat
|
flickerstreak@10
|
572 -- checking and updates the config.
|
flickerstreak@7
|
573 function main:DeleteBar(id)
|
flickerstreak@2
|
574 if InCombatLockdown() then
|
flickerstreak@2
|
575 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT)
|
flickerstreak@2
|
576 else
|
flickerstreak@2
|
577 if self.bars[id] then
|
flickerstreak@7
|
578 self:DestroyBar(id)
|
flickerstreak@2
|
579 self.db.profile.bars[id] = nil
|
flickerstreak@2
|
580 end
|
flickerstreak@1
|
581 end
|
flickerstreak@1
|
582 end
|
flickerstreak@1
|
583
|
flickerstreak@10
|
584
|
flickerstreak@10
|
585
|