comparison ReAction.lua @ 2:8e0ff8ae4c08

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