flickerstreak@1
|
1 -- ReAction.lua
|
flickerstreak@1
|
2 --
|
flickerstreak@1
|
3 -- Top-level file for the ReAction Action Bar add-on
|
flickerstreak@1
|
4 --
|
flickerstreak@1
|
5 -- ReAction is implemented in terms of the Ace 2 library: http://www.wowace.com
|
flickerstreak@1
|
6 --
|
flickerstreak@1
|
7
|
flickerstreak@1
|
8 -- key binding label constants
|
flickerstreak@2
|
9 BINDING_HEADER_REACTION = "ReAction"
|
flickerstreak@2
|
10 BINDING_NAME_REACTION_TOGGLELOCK = "Lock/Unlock ReAction Bars"
|
flickerstreak@2
|
11 BINDING_NAME_REBINDER_TOGGLEBINDINGMODE = "Toggle ReAction keybinding mode"
|
flickerstreak@1
|
12
|
flickerstreak@1
|
13 -- ReAction addon setup via Ace 2
|
flickerstreak@1
|
14 ReAction = AceLibrary("AceAddon-2.0"):new(
|
flickerstreak@1
|
15 "AceConsole-2.0",
|
flickerstreak@1
|
16 "AceEvent-2.0",
|
flickerstreak@1
|
17 "AceDB-2.0",
|
flickerstreak@1
|
18 "FuBarPlugin-2.0"
|
flickerstreak@1
|
19 )
|
flickerstreak@1
|
20
|
flickerstreak@2
|
21 local function tcopy(t)
|
flickerstreak@2
|
22 local r = { }
|
flickerstreak@2
|
23 for k, v in pairs(t) do
|
flickerstreak@2
|
24 r[k] = (type(v) == "table" and tcopy(v) or v)
|
flickerstreak@2
|
25 end
|
flickerstreak@2
|
26 return r
|
flickerstreak@2
|
27 end
|
flickerstreak@2
|
28
|
flickerstreak@1
|
29 -- FuBar plugin setup
|
flickerstreak@1
|
30 ReAction.hasIcon = false
|
flickerstreak@1
|
31 ReAction.hasNoColor = true
|
flickerstreak@2
|
32 ReAction.hideMenuTitle = true
|
flickerstreak@1
|
33 ReAction.defaultPosition = "RIGHT"
|
flickerstreak@1
|
34 ReAction.defaultMinimapPosition = 240 -- degrees
|
flickerstreak@2
|
35 ReAction.OnMenuRequest = tcopy(ReActionGlobalMenuOptions)
|
flickerstreak@1
|
36
|
flickerstreak@1
|
37 -- initial non-persistent state
|
flickerstreak@1
|
38 ReAction.locked = true
|
flickerstreak@1
|
39
|
flickerstreak@1
|
40 -- localization
|
flickerstreak@1
|
41 -- local L = AceLibrary("AceLocale-2.0"):new("ReAction")
|
flickerstreak@1
|
42
|
flickerstreak@1
|
43
|
flickerstreak@1
|
44
|
flickerstreak@1
|
45 -- Event handling
|
flickerstreak@1
|
46 function ReAction:OnInitialize()
|
flickerstreak@1
|
47 self:RegisterChatCommand( {"/reaction", "/rxn"}, ReActionConsoleOptions, "REACTION" )
|
flickerstreak@1
|
48
|
flickerstreak@1
|
49 self:RegisterDB("ReActionDB","ReActionDBPC")
|
flickerstreak@1
|
50 self:RegisterDefaults("profile", ReActionProfileDefaults)
|
flickerstreak@1
|
51 self:RegisterEvent("PLAYER_REGEN_DISABLED","CombatLockdown")
|
flickerstreak@2
|
52 self:RegisterEvent("PLAYER_ENTERING_WORLD","HideDefaultBars")
|
flickerstreak@1
|
53 end
|
flickerstreak@1
|
54
|
flickerstreak@1
|
55 function ReAction:OnEnable()
|
flickerstreak@1
|
56 if self.db.profile.firstRunDone ~= true then
|
flickerstreak@1
|
57 -- Do some "first-run" setup
|
flickerstreak@1
|
58 self.db.profile.firstRunDone = true
|
flickerstreak@1
|
59 elseif self.db.profile.disabled == true then
|
flickerstreak@1
|
60 -- print some kind of a warning
|
flickerstreak@1
|
61 end
|
flickerstreak@2
|
62 self:SetupBars()
|
flickerstreak@1
|
63 end
|
flickerstreak@1
|
64
|
flickerstreak@1
|
65 function ReAction:OnDisable()
|
flickerstreak@1
|
66 self:Lock()
|
flickerstreak@1
|
67 end
|
flickerstreak@1
|
68
|
flickerstreak@1
|
69 function ReAction:OnProfileEnable()
|
flickerstreak@1
|
70 -- handle profile switching
|
flickerstreak@2
|
71 self:Lock()
|
flickerstreak@1
|
72 self:SetupBars()
|
flickerstreak@1
|
73 end
|
flickerstreak@1
|
74
|
flickerstreak@1
|
75 function ReAction:CombatLockdown()
|
flickerstreak@1
|
76 if not self:IsLocked() then
|
flickerstreak@1
|
77 self:Lock()
|
flickerstreak@1
|
78 UIErrorsFrame:AddMessage("ReAction bars locked when in combat")
|
flickerstreak@1
|
79 end
|
flickerstreak@1
|
80 end
|
flickerstreak@1
|
81
|
flickerstreak@1
|
82
|
flickerstreak@1
|
83 -- lock/unlock ReAction
|
flickerstreak@1
|
84 function ReAction:SetLocked( lock )
|
flickerstreak@2
|
85 if lock ~= self.locked then
|
flickerstreak@2
|
86 if not lock then
|
flickerstreak@2
|
87 self:Print("Buttons disabled while unlocked")
|
flickerstreak@2
|
88 end
|
flickerstreak@2
|
89 if not lock and InCombatLockdown() then
|
flickerstreak@2
|
90 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT)
|
flickerstreak@2
|
91 else
|
flickerstreak@2
|
92 self.locked = lock and true or false -- force data integrity
|
flickerstreak@2
|
93 for _, bar in pairs(self.bars) do
|
flickerstreak@2
|
94 if self.locked then bar:HideControls() else bar:ShowControls() end
|
flickerstreak@2
|
95 end
|
flickerstreak@2
|
96 end
|
flickerstreak@1
|
97 end
|
flickerstreak@1
|
98 end
|
flickerstreak@1
|
99
|
flickerstreak@1
|
100 function ReAction:IsLocked()
|
flickerstreak@1
|
101 return self.locked
|
flickerstreak@1
|
102 end
|
flickerstreak@1
|
103
|
flickerstreak@1
|
104 function ReAction:Lock()
|
flickerstreak@1
|
105 self:SetLocked(true)
|
flickerstreak@1
|
106 end
|
flickerstreak@1
|
107
|
flickerstreak@1
|
108 function ReAction:Unlock()
|
flickerstreak@1
|
109 self:SetLocked(false)
|
flickerstreak@1
|
110 end
|
flickerstreak@1
|
111
|
flickerstreak@1
|
112 function ReAction:ToggleLocked()
|
flickerstreak@1
|
113 ReAction:SetLocked( not(self.locked) )
|
flickerstreak@1
|
114 end
|
flickerstreak@1
|
115
|
flickerstreak@1
|
116
|
flickerstreak@1
|
117
|
flickerstreak@1
|
118 -- Hide the default Blizzard main bar artwork
|
flickerstreak@1
|
119 function ReAction:HideArt()
|
flickerstreak@1
|
120 if self.db.profile.hideArt then
|
flickerstreak@1
|
121 MainMenuBar:Hide() -- this also hides the bags, xp bar, lag meter, and micro menu buttons.
|
flickerstreak@1
|
122 else
|
flickerstreak@1
|
123 MainMenuBar:Show()
|
flickerstreak@1
|
124 end
|
flickerstreak@1
|
125 end
|
flickerstreak@1
|
126
|
flickerstreak@1
|
127 function ReAction:IsArtHidden()
|
flickerstreak@1
|
128 return self.db.profile.hideArt
|
flickerstreak@1
|
129 end
|
flickerstreak@1
|
130
|
flickerstreak@1
|
131 function ReAction:SetHideArt( hide )
|
flickerstreak@2
|
132 if InCombatLockdown() then
|
flickerstreak@2
|
133 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT)
|
flickerstreak@2
|
134 else
|
flickerstreak@2
|
135 self.db.profile.hideArt = hide and true or false -- force data integrity
|
flickerstreak@2
|
136 self:HideArt()
|
flickerstreak@2
|
137 end
|
flickerstreak@1
|
138 end
|
flickerstreak@1
|
139
|
flickerstreak@1
|
140 function ReAction:ToggleHideArt()
|
flickerstreak@1
|
141 self:SetHideArt( not self:IsArtHidden() )
|
flickerstreak@1
|
142 end
|
flickerstreak@1
|
143
|
flickerstreak@1
|
144
|
flickerstreak@1
|
145
|
flickerstreak@1
|
146 -- Keybinding color coding
|
flickerstreak@1
|
147 function ReAction:SetKeyColorCoding( cc )
|
flickerstreak@1
|
148 self.db.profile.keyColorCode = cc
|
flickerstreak@1
|
149 end
|
flickerstreak@1
|
150
|
flickerstreak@1
|
151 function ReAction:IsKeyColorCodeEnabled()
|
flickerstreak@1
|
152 return self.db.profile.keyColorCode
|
flickerstreak@1
|
153 end
|
flickerstreak@1
|
154
|
flickerstreak@1
|
155 function ReAction:ToggleKeyColorCoding()
|
flickerstreak@1
|
156 self:SetKeyColorCoding(not self.db.profile.keyColorCode)
|
flickerstreak@1
|
157 end
|
flickerstreak@1
|
158
|
flickerstreak@1
|
159
|
flickerstreak@1
|
160
|
flickerstreak@1
|
161 -- Hide default Blizzard bars
|
flickerstreak@1
|
162 local blizzDefaultBars = {
|
flickerstreak@1
|
163 ActionButton1,
|
flickerstreak@1
|
164 ActionButton2,
|
flickerstreak@1
|
165 ActionButton3,
|
flickerstreak@1
|
166 ActionButton4,
|
flickerstreak@1
|
167 ActionButton5,
|
flickerstreak@1
|
168 ActionButton6,
|
flickerstreak@1
|
169 ActionButton7,
|
flickerstreak@1
|
170 ActionButton8,
|
flickerstreak@1
|
171 ActionButton9,
|
flickerstreak@1
|
172 ActionButton10,
|
flickerstreak@1
|
173 ActionButton11,
|
flickerstreak@1
|
174 ActionButton12,
|
flickerstreak@1
|
175 BonusActionBarFrame,
|
flickerstreak@1
|
176 MultiBarLeft,
|
flickerstreak@1
|
177 MultiBarRight,
|
flickerstreak@1
|
178 MultiBarBottomLeft,
|
flickerstreak@1
|
179 MultiBarBottomRight
|
flickerstreak@1
|
180 }
|
flickerstreak@1
|
181
|
flickerstreak@1
|
182 function ReAction:HideDefaultBars()
|
flickerstreak@1
|
183 for _, f in pairs(blizzDefaultBars) do
|
flickerstreak@2
|
184 f:UnregisterAllEvents()
|
flickerstreak@1
|
185 f:Hide()
|
flickerstreak@2
|
186 f:SetParent(ReActionButtonRecycler) -- I mean it!
|
flickerstreak@2
|
187 f:ClearAllPoints() -- no, I really mean it!
|
flickerstreak@1
|
188 end
|
flickerstreak@1
|
189 end
|
flickerstreak@1
|
190
|
flickerstreak@1
|
191
|
flickerstreak@1
|
192 -- Reset bars to defaults
|
flickerstreak@1
|
193 function ReAction:ResetBars()
|
flickerstreak@2
|
194 if InCombatLockdown() then
|
flickerstreak@2
|
195 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT)
|
flickerstreak@2
|
196 else
|
flickerstreak@2
|
197 self.db.profile.bars = ReActionProfileDefaults.bars
|
flickerstreak@2
|
198 self:SetupBars()
|
flickerstreak@2
|
199 end
|
flickerstreak@1
|
200 end
|
flickerstreak@1
|
201
|
flickerstreak@1
|
202
|
flickerstreak@1
|
203 -- re-sync action IDs
|
flickerstreak@1
|
204 function ReAction:ResyncActionIDs()
|
flickerstreak@1
|
205 -- TODO
|
flickerstreak@1
|
206 end
|
flickerstreak@1
|
207
|
flickerstreak@1
|
208
|
flickerstreak@1
|
209
|
flickerstreak@1
|
210 -- Bar manipulation
|
flickerstreak@1
|
211 ReAction.bars = { }
|
flickerstreak@1
|
212
|
flickerstreak@1
|
213 function ReAction:SetupBars()
|
flickerstreak@1
|
214 -- hide the default Blizzard art, if configued
|
flickerstreak@1
|
215 self:HideArt()
|
flickerstreak@1
|
216 -- hide the default Blizzard bars
|
flickerstreak@1
|
217 self:HideDefaultBars()
|
flickerstreak@1
|
218
|
flickerstreak@1
|
219 -- set up the bars from the profile
|
flickerstreak@2
|
220 -- note the use of table.maxn rather than # or ipairs:
|
flickerstreak@2
|
221 -- our array of bars can in fact contain holes
|
flickerstreak@2
|
222 for id = 1, table.maxn(self.db.profile.bars) do
|
flickerstreak@2
|
223 local config = self.db.profile.bars[id]
|
flickerstreak@2
|
224 if self.bars[id] then
|
flickerstreak@2
|
225 self.bars[id]:Destroy() -- remove old version of bar if switching profiles
|
flickerstreak@2
|
226 end
|
flickerstreak@2
|
227 if config then
|
flickerstreak@2
|
228 self.bars[id] = ReBar:new(config, id)
|
flickerstreak@2
|
229 end
|
flickerstreak@1
|
230 end
|
flickerstreak@1
|
231
|
flickerstreak@1
|
232 -- remove excess bars
|
flickerstreak@2
|
233 for id = table.maxn(self.db.profile.bars) + 1, table.maxn(self.bars) do
|
flickerstreak@2
|
234 if self.bars[id] then
|
flickerstreak@2
|
235 self.bars[id]:Destroy()
|
flickerstreak@2
|
236 self.bars[id] = nil
|
flickerstreak@2
|
237 end
|
flickerstreak@1
|
238 end
|
flickerstreak@1
|
239
|
flickerstreak@1
|
240 -- anchor the bars, have to do this in a second pass because
|
flickerstreak@1
|
241 -- they might be anchored to each other in a non-ordered way
|
flickerstreak@2
|
242 for _, bar in pairs(self.bars) do
|
flickerstreak@1
|
243 bar:ApplyAnchor()
|
flickerstreak@1
|
244 end
|
flickerstreak@1
|
245 end
|
flickerstreak@1
|
246
|
flickerstreak@1
|
247
|
flickerstreak@1
|
248 function ReAction:NewBar()
|
flickerstreak@2
|
249 if InCombatLockdown() then
|
flickerstreak@2
|
250 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT)
|
flickerstreak@2
|
251 else
|
flickerstreak@2
|
252 local c = tcopy(ReActionBarConfigDefaults)
|
flickerstreak@2
|
253 local bar = ReBar:new(c, #self.bars+1)
|
flickerstreak@2
|
254 table.insert(self.bars, bar)
|
flickerstreak@2
|
255 table.insert(self.db.profile.bars, c)
|
flickerstreak@2
|
256 if not self.locked then
|
flickerstreak@2
|
257 bar:ShowControls()
|
flickerstreak@2
|
258 end
|
flickerstreak@2
|
259 end
|
flickerstreak@1
|
260 end
|
flickerstreak@1
|
261
|
flickerstreak@1
|
262
|
flickerstreak@1
|
263 function ReAction:DeleteBar(id)
|
flickerstreak@2
|
264 if InCombatLockdown() then
|
flickerstreak@2
|
265 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT)
|
flickerstreak@2
|
266 else
|
flickerstreak@2
|
267 if self.bars[id] then
|
flickerstreak@2
|
268 -- we can't do tremove because each bar ID is encoded into the
|
flickerstreak@2
|
269 -- frame names as they're created. Need a nil entry in the table.
|
flickerstreak@2
|
270 -- The nice thing is that table.insert in NewBar() will automatically
|
flickerstreak@2
|
271 -- find the first nil slot.
|
flickerstreak@2
|
272 self.bars[id]:Destroy()
|
flickerstreak@2
|
273 self.bars[id] = nil
|
flickerstreak@2
|
274 self.db.profile.bars[id] = nil
|
flickerstreak@2
|
275 end
|
flickerstreak@1
|
276 end
|
flickerstreak@1
|
277 end
|
flickerstreak@1
|
278
|
flickerstreak@1
|
279 function ReAction:ToggleActionID()
|
flickerstreak@1
|
280 if self.showActionIDs then
|
flickerstreak@1
|
281 ReActionButton:HideAllActionIDs()
|
flickerstreak@1
|
282 else
|
flickerstreak@1
|
283 ReActionButton:ShowAllActionIDs()
|
flickerstreak@1
|
284 end
|
flickerstreak@1
|
285 self.showActionIDs = not self.showActionIDs
|
flickerstreak@1
|
286 end
|
flickerstreak@1
|
287
|
flickerstreak@1
|
288 function ReAction:IsActionIDVisible()
|
flickerstreak@1
|
289 return self.showActionIDs
|
flickerstreak@1
|
290 end
|
flickerstreak@1
|
291
|
flickerstreak@1
|
292
|
flickerstreak@1
|
293
|
flickerstreak@1
|
294 -- FuBar plugin methods
|
flickerstreak@1
|
295 local tablet = AceLibrary("Tablet-2.0")
|
flickerstreak@1
|
296
|
flickerstreak@1
|
297 function ReAction:OnTooltipUpdate()
|
flickerstreak@1
|
298 local c = tablet:AddCategory("columns", 2)
|
flickerstreak@2
|
299 c:AddLine("text", "Bar lock", "text2", self.locked and "|cffcc0000Locked|r" or "|cff00cc00Unlocked|r")
|
flickerstreak@2
|
300 c:AddLine("text", "Button lock", "text2", LOCK_ACTIONBAR == "1" and "|cffcc0000Locked|r" or "|cff00cc00Unlocked|r")
|
flickerstreak@2
|
301 c:AddLine("text", "Kebinding mode", "text2", ReBinder:IsEnabled() and "|cff33ff33On|r" or "|cffffcc00Off|r")
|
flickerstreak@2
|
302 tablet:SetHint("|cffffcc00Shift-Click|r for bar lock|n"..
|
flickerstreak@2
|
303 "|cff33ff33Alt-Click|r for keybindings|n"..
|
flickerstreak@2
|
304 "Right-click for menu")
|
flickerstreak@1
|
305 end
|
flickerstreak@1
|
306
|
flickerstreak@1
|
307 function ReAction:OnClick(button)
|
flickerstreak@1
|
308 if IsShiftKeyDown() then
|
flickerstreak@1
|
309 self:ToggleLocked()
|
flickerstreak@2
|
310 self:UpdateDisplay()
|
flickerstreak@2
|
311 elseif IsAltKeyDown() then
|
flickerstreak@2
|
312 ReBinder:ToggleEnabled()
|
flickerstreak@2
|
313 end
|
flickerstreak@1
|
314 end
|