Mercurial > wow > reaction
comparison main.lua @ 10:f3a7bfebc283
Version 0.33
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Tue, 20 Mar 2007 21:37:38 +0000 |
parents | c05fd3e18b4f |
children | 2735edcf9ab7 |
comparison
equal
deleted
inserted
replaced
9:650f75d08952 | 10:f3a7bfebc283 |
---|---|
7 | 7 |
8 -- Ace Library local object initialization | 8 -- Ace Library local object initialization |
9 local L = AceLibrary("AceLocale-2.2"):new("ReAction") | 9 local L = AceLibrary("AceLocale-2.2"):new("ReAction") |
10 local dewdrop = AceLibrary("Dewdrop-2.0") | 10 local dewdrop = AceLibrary("Dewdrop-2.0") |
11 local tablet = AceLibrary("Tablet-2.0") | 11 local tablet = AceLibrary("Tablet-2.0") |
12 local ReBound = AceLibrary("ReBound-1.0") | |
12 | 13 |
13 -- private functions | 14 -- private functions |
14 local function tcopy(t) | 15 local function tcopy(t) |
15 local r = { } | 16 local r = { } |
16 for k, v in pairs(t) do | 17 for k, v in pairs(t) do |
23 local EMPTY_BAR_SLOT = -1 | 24 local EMPTY_BAR_SLOT = -1 |
24 | 25 |
25 -- key binding label constants | 26 -- key binding label constants |
26 BINDING_HEADER_REACTION = L["ReAction"] | 27 BINDING_HEADER_REACTION = L["ReAction"] |
27 BINDING_NAME_REACTION_TOGGLELOCK = L["Toggle ReAction Bar Lock"] | 28 BINDING_NAME_REACTION_TOGGLELOCK = L["Toggle ReAction Bar Lock"] |
28 BINDING_NAME_REBOUND_TOGGLEBINDINGMODE = L["Toggle ReBound Keybinding Mode"] | 29 BINDING_NAME_REACTION_TOGGLEKEYBIND = L["ReAction Keybinding Mode"] |
29 | 30 |
30 | 31 -- UI panel strings |
31 -- main object | 32 REACTION_KEYBIND_TITLE = L["ReAction Keybinding"] |
33 REACTION_KEYBIND_SUBTITLE = L["Click Buttons to Set Keybindings"] | |
34 REACTION_KEYBIND_DONE = L["Save"] | |
35 REACTION_KEYBIND_REVERT = L["Revert"] | |
36 | |
37 | |
38 | |
39 ------------------------------ | |
40 -- AceAddon setup | |
41 ------------------------------ | |
32 local main = AceLibrary("AceAddon-2.0"):new( | 42 local main = AceLibrary("AceAddon-2.0"):new( |
33 "AceConsole-2.0", | 43 "AceConsole-2.0", |
34 "AceEvent-2.0", | 44 "AceEvent-2.0", |
35 "AceDB-2.0", | 45 "AceDB-2.0", |
36 "FuBarPlugin-2.0" | 46 "FuBarPlugin-2.0" |
37 ) | 47 ) |
38 | 48 |
39 -- initial non-persistent state | 49 function main:OnInitialize() |
40 main.locked = true | 50 self:RegisterChatCommand( {L["/reaction"], L["/rxn"]}, ReActionConsoleOptions, "REACTION" ) |
41 | 51 self:RegisterDB("ReActionDB","ReActionDBPC") |
42 -- set a global variable for Bindings.xml | 52 self:RegisterDefaults("profile", ReAction_DefaultProfile) |
43 ReActionAddOn = main | 53 self:RegisterEvent("PLAYER_REGEN_DISABLED","CombatLockdown") |
44 | 54 self:RegisterEvent("PLAYER_ENTERING_WORLD","HideDefaultBars") |
45 | 55 self:DisableDefaultKeybindings() |
56 | |
57 -- initial non-persistent state | |
58 self.locked = true | |
59 self.bars = { } | |
60 end | |
61 | |
62 -- OnEnable is called at startup (startup = true, oldConfig = nil), | |
63 -- and when the profile is changed (startup = false, oldConfig ~= nil ) | |
64 function main:OnEnable( startup, oldConfig ) | |
65 if self.db.profile.firstRunDone ~= true then | |
66 self.db.profile.bars = tcopy(ReAction_DefaultBlizzardBars) | |
67 end | |
68 self:DestroyAllBars() | |
69 self:SetupBars() | |
70 self:UpgradeProfile() | |
71 self:SetupKeybindings( oldConfig and oldConfig.bindings ) | |
72 if self.db.profile.firstRunDone ~= true then | |
73 self:Unlock() | |
74 end | |
75 self.db.profile.firstRunDone = true | |
76 end | |
77 | |
78 function main:OnDisable() | |
79 self:Lock() | |
80 end | |
81 | |
82 -- OnProfileEnable() is only called when switching profiles, NOT for the initial profile at load time. | |
83 function main:OnProfileEnable( oldName, oldData ) | |
84 self:OnEnable(false, oldData) | |
85 end | |
86 | |
87 function main:UpgradeProfile() | |
88 if self.db.profile.firstRunDone ~= true and #self.db.profile.bindings == 0 then | |
89 for _, bar in pairs(self.bars) do | |
90 for _, button in pairs(bar.buttons) do | |
91 local key = ReBound:GetBinding(button:GetActionFrame(),"LeftButton") | |
92 if key and #key > 0 and not self.db.profile.bindings[key] then | |
93 self:REBOUND_BIND(key,button:GetActionFrame():GetName(),"LeftButton") | |
94 end | |
95 end | |
96 end | |
97 end | |
98 end | |
99 | |
100 | |
101 | |
102 | |
103 -------------------------------------------- | |
46 -- FuBar plugin setup | 104 -- FuBar plugin setup |
47 -- Even if FuBar isn't installed, this gives us a nice minimap-button interface. | 105 -- Even if FuBar isn't installed, the plugin |
106 -- provides a nice minimap-button interface. | |
107 --------------------------------------------- | |
48 main.hasIcon = "Interface\\Icons\\INV_Qiraj_JewelEncased" | 108 main.hasIcon = "Interface\\Icons\\INV_Qiraj_JewelEncased" |
49 main.hasNoColor = true | 109 main.hasNoColor = true |
50 main.hideMenuTitle = true | 110 main.hideMenuTitle = true |
51 main.defaultPosition = "LEFT" | 111 main.defaultPosition = "LEFT" |
52 main.defaultMinimapPosition = 240 -- degrees | 112 main.defaultMinimapPosition = 240 -- degrees |
55 | 115 |
56 -- set the handler for the global bar menu options | 116 -- set the handler for the global bar menu options |
57 -- have to do this after tcopy() above, otherwise it will try to copy the handler object (bad idea) | 117 -- have to do this after tcopy() above, otherwise it will try to copy the handler object (bad idea) |
58 ReActionGlobalMenuOptions.handler = main | 118 ReActionGlobalMenuOptions.handler = main |
59 | 119 |
60 | |
61 | |
62 | |
63 -- Event handling | |
64 function main:OnInitialize() | |
65 self:RegisterChatCommand( {L["/reaction"], L["/rxn"]}, ReActionConsoleOptions, "REACTION" ) | |
66 self:RegisterDB("ReActionDB","ReActionDBPC") | |
67 self:RegisterDefaults("profile", ReAction_DefaultProfile) | |
68 self:RegisterEvent("PLAYER_REGEN_DISABLED","CombatLockdown") | |
69 self:RegisterEvent("PLAYER_ENTERING_WORLD","HideDefaultBars") | |
70 self:RegisterEvent("EVENT_REBOUND_KEYBINDING_MODE") | |
71 end | |
72 | |
73 function main:OnEnable() | |
74 -- this gets called at startup and when the profile is changed | |
75 if self.db.profile.firstRunDone ~= true then | |
76 -- Do some "first-run" setup | |
77 self:StealKeyBindings() | |
78 self.db.profile.firstRunDone = true | |
79 self.db.profile.bars = tcopy(ReAction_DefaultBlizzardBars) | |
80 end | |
81 self:DestroyAllBars() | |
82 self:SetupBars() | |
83 end | |
84 | |
85 function main:OnDisable() | |
86 self:Lock() | |
87 end | |
88 | |
89 function main:OnProfileEnable() | |
90 -- for profile switching | |
91 self:OnEnable() | |
92 end | |
93 | |
94 function main:CombatLockdown() | |
95 if not self:IsLocked() then | |
96 self:Lock() | |
97 ReBound:Disable() | |
98 UIErrorsFrame:AddMessage(L["ReAction bars locked when in combat"]) | |
99 end | |
100 end | |
101 | |
102 function main:EVENT_REBOUND_KEYBINDING_MODE(enabled) | |
103 for _, bar in pairs(self.bars) do | |
104 for __, button in pairs(bar.buttons) do | |
105 if button and button ~= EMPTY_BAR_SLOT then | |
106 button:TempShow(enabled) | |
107 end | |
108 end | |
109 end | |
110 end | |
111 | |
112 | |
113 -- FuBar plugin methods | |
114 function main:OnTooltipUpdate() | 120 function main:OnTooltipUpdate() |
115 local c = tablet:AddCategory("columns", 2) | 121 local c = tablet:AddCategory("columns", 2) |
116 c:AddLine("text", L["Bar lock"], "text2", self.locked and ("|cffff0000"..L["Locked"].."|r") or ("|cffffcc00"..L["Unlocked"].."|r")) | 122 c:AddLine("text", L["Bar lock"], "text2", self.locked and ("|cffff0000"..L["Locked"].."|r") or ("|cffffcc00"..L["Unlocked"].."|r")) |
117 c:AddLine("text", L["Button lock"], "text2", LOCK_ACTIONBAR == "1" and ("|cffcc0000"..L["Locked"].."|r") or ("|cff00cc00"..L["Unlocked"].."|r")) | 123 c:AddLine("text", L["Button lock"], "text2", LOCK_ACTIONBAR == "1" and ("|cffcc0000"..L["Locked"].."|r") or ("|cff00cc00"..L["Unlocked"].."|r")) |
118 c:AddLine("text", L["Kebinding mode"], "text2", ReBound:IsEnabled() and ("|cff33ff33"..L["On"].."|r") or ("|cffffcc00"..L["Off"].."|r")) | 124 c:AddLine("text", L["Kebinding mode"], "text2", self:GetKeybindMode() and ("|cff33ff33"..L["On"].."|r") or ("|cffffcc00"..L["Off"].."|r")) |
119 tablet:SetHint(L["|cffffcc00Shift-Click for bar lock|n|cff33ff33Alt-Click|r for keybindings|nRight-click for menu"]) | 125 tablet:SetHint(L["|cffffcc00Shift-Click for bar lock|n|cff33ff33Alt-Click|r for keybindings|nRight-click for menu"]) |
120 end | 126 end |
121 | 127 |
122 function main:OnClick(button) | 128 function main:OnClick(button) |
123 if IsShiftKeyDown() then | 129 if IsShiftKeyDown() then |
124 self:ToggleLocked() | 130 self:ToggleLocked() |
125 self:UpdateDisplay() | 131 self:UpdateDisplay() |
126 elseif IsAltKeyDown() then | 132 elseif IsAltKeyDown() then |
127 ReBound:ToggleEnabled() | 133 self:ToggleKeybindMode() |
128 self:UpdateDisplay() | 134 self:UpdateDisplay() |
129 end | 135 end |
130 end | 136 end |
131 | 137 |
132 | 138 |
133 -- lock/unlock bars | 139 |
140 | |
141 ------------------------------ | |
142 -- Key binding functions | |
143 ------------------------------ | |
144 function main:DisableDefaultKeybindings() | |
145 -- change the labels on all actionbar keybindings in the default | |
146 -- interface. | |
147 local label = "|cff999999("..L["Use ReAction"]..")|r" | |
148 for i = 1, 12 do | |
149 setglobal("BINDING_NAME_ACTIONBUTTON"..i,label) | |
150 for j = 1, 4 do | |
151 setglobal("BINDING_NAME_MULTIACTIONBAR"..j.."BUTTON"..i,label) | |
152 end | |
153 end | |
154 for i = 1, 6 do | |
155 setglobal("BINDING_NAME_ACTIONPAGE"..i,label) | |
156 end | |
157 for i = 1, 10 do | |
158 setglobal("BINDING_NAME_BONUSACTIONBUTTON"..i,label) | |
159 setglobal("BINDING_NAME_SHAPESHIFTBUTTON"..i,label) | |
160 end | |
161 BINDING_HEADER_ACTIONBAR = "|cff999999"..L["Action Bar Functions Disabled"].."|r" | |
162 BINDING_HEADER_MULTIACTIONBAR = "|cff999999"..L["Multi-Action Bar Functions Disabled"].."|r" | |
163 BINDING_NAME_NEXTACTIONPAGE = label | |
164 BINDING_NAME_PREVIOUSACTIONPAGE = label | |
165 end | |
166 | |
167 function main:SetupKeybindings( previous ) | |
168 if previous then | |
169 self:UnregisterEvent("REBOUND_BIND") | |
170 self:UnregisterEvent("REBOUND_UNBIND") | |
171 for key, binding in pairs(previous) do | |
172 ReBound:ClearBinding(key, getglobal(binding.target), binding.button, true) | |
173 end | |
174 end | |
175 if self.db.profile.firstRunDone ~= true then | |
176 self:StealKeyBindings() | |
177 else | |
178 for key, binding in pairs(self.db.profile.bindings) do | |
179 ReBound:SetBinding(key, getglobal(binding.target), binding.button) | |
180 end | |
181 end | |
182 SaveBindings(GetCurrentBindingSet()) | |
183 self:RegisterEvent("REBOUND_BIND") | |
184 self:RegisterEvent("REBOUND_UNBIND") | |
185 end | |
186 | |
187 function main:StealKeyBindings() | |
188 -- steal the keybindings of the main action bar and assign them to rebar 1, buttons 1-12 | |
189 for i = 1, 12 do | |
190 local key = GetBindingKey("ACTIONBUTTON"..i) | |
191 if key and #key > 0 then | |
192 ReBound:ClearBinding(key,nil,nil,true) -- suppress notification printouts | |
193 ReBound:SetBinding(key, self.bars[1].buttons[i]:GetActionFrame(), "LeftButton") | |
194 end | |
195 end | |
196 SaveBindings(GetCurrentBindingSet()) | |
197 end | |
198 | |
199 function main:REBOUND_BIND(key, target, button) | |
200 if key and target then | |
201 self.db.profile.bindings[key] = { target = target, button = button } | |
202 end | |
203 end | |
204 | |
205 function main:REBOUND_UNBIND(key) | |
206 if key then | |
207 self.db.profile.bindings[key] = nil | |
208 end | |
209 end | |
210 | |
211 function main:ToggleKeybindMode() | |
212 self:SetKeybindMode(not self:GetKeybindMode()) | |
213 end | |
214 | |
215 function main:GetKeybindMode() | |
216 return self.keybindMode | |
217 end | |
218 | |
219 function main:SetKeybindMode(enabled) | |
220 if not InCombatLockdown() then | |
221 self.keybindMode = enabled | |
222 for _, bar in pairs(self.bars) do | |
223 for __, button in pairs(bar.buttons) do | |
224 if button and button ~= EMPTY_BAR_SLOT then | |
225 button:TempShow(enabled) | |
226 end | |
227 end | |
228 end | |
229 if enabled then | |
230 ReBound:ShowAll() | |
231 ReActionKeybindDialog:Show() | |
232 else | |
233 ReBound:HideAll() | |
234 if ReActionKeybindDialog:IsShown() then | |
235 ReActionKeybindDialog:Hide() | |
236 end | |
237 end | |
238 else | |
239 UIErrorsFrame:AddMessage(ERROR_NOT_IN_COMBAT) | |
240 end | |
241 end | |
242 | |
243 | |
244 | |
245 | |
246 ---------------------------- | |
247 -- Bar lock/unlock functions | |
248 ---------------------------- | |
249 function main:CombatLockdown() | |
250 if not self:IsLocked() then | |
251 self:Lock() | |
252 UIErrorsFrame:AddMessage(L["ReAction bars locked when in combat"]) | |
253 end | |
254 ReActionKeybindDialog:Hide() | |
255 end | |
256 | |
134 function main:SetLocked( lock ) | 257 function main:SetLocked( lock ) |
135 if lock ~= self.locked then | 258 if lock ~= self.locked then |
136 if not lock and InCombatLockdown() then | 259 if not lock and InCombatLockdown() then |
137 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT) | 260 UIErrorsFrame:AddMessage(ERROR_NOT_IN_COMBAT) |
138 else | 261 else |
139 self.locked = lock and true or false -- force data integrity | 262 self.locked = lock and true or false -- force data integrity |
140 for _, bar in pairs(self.bars) do | 263 for _, bar in pairs(self.bars) do |
141 if bar ~= EMPTY_BAR_SLOT then | 264 if bar ~= EMPTY_BAR_SLOT then |
142 if self.locked then | 265 if self.locked then |
170 main:SetLocked( not(self.locked) ) | 293 main:SetLocked( not(self.locked) ) |
171 end | 294 end |
172 | 295 |
173 | 296 |
174 | 297 |
175 -- Hide the default Blizzard main bar artwork | 298 -------------------------------------------------------- |
299 -- Functions to hide the default Blizzard main bar parts | |
300 -------------------------------------------------------- | |
176 function main:HideArt() | 301 function main:HideArt() |
177 if self.db.profile.hideArt then | 302 if self.db.profile.hideArt then |
178 -- the pet bar is a child of MainMenuBar, and can't be hidden. Need to reparent it | 303 -- the pet bar is a child of MainMenuBar, and can't be hidden. Need to reparent it |
179 PetActionBarFrame:SetParent(UIParent) | 304 PetActionBarFrame:SetParent(UIParent) |
180 MainMenuBar:Hide() -- this also hides the bags, xp bar, lag meter, and micro menu buttons. | 305 MainMenuBar:Hide() -- this also hides the bags, xp bar, lag meter, and micro menu buttons. |
204 end | 329 end |
205 | 330 |
206 function main:ToggleHideArt() | 331 function main:ToggleHideArt() |
207 self:SetHideArt( not self:IsArtHidden() ) | 332 self:SetHideArt( not self:IsArtHidden() ) |
208 end | 333 end |
209 | |
210 | |
211 | 334 |
212 -- Hide default Blizzard bars | 335 -- Hide default Blizzard bars |
213 local blizzDefaultBars = { | 336 local blizzDefaultBars = { |
214 ActionButton1, | 337 ActionButton1, |
215 ActionButton2, | 338 ActionButton2, |
243 MultiBarRight, | 366 MultiBarRight, |
244 MultiBarBottomLeft, | 367 MultiBarBottomLeft, |
245 MultiBarBottomRight, | 368 MultiBarBottomRight, |
246 } | 369 } |
247 | 370 |
248 function main:StealKeyBindings() | |
249 -- steal the keybindings of the main action bar and assign them to rebar 1, buttons 1-12 | |
250 for i = 1, 12 do | |
251 -- TODO: when we convert to override bindings | |
252 end | |
253 end | |
254 | |
255 local function disableUIOptions() | 371 local function disableUIOptions() |
256 -- disable the buttons to hide/show the blizzard multiaction bars | 372 -- disable the buttons to hide/show the blizzard multiaction bars |
257 -- see UIOptionsFrame.lua and .xml | 373 -- see UIOptionsFrame.lua and .xml |
258 -- This is called every time the options panel is shown, after it is set up | 374 -- This is called every time the options panel is shown, after it is set up |
259 for _, idx in pairs( { 33, 34, 35, 36, 37, 40 } ) do | 375 for _, idx in pairs( { 33, 34, 35, 36, 37, 40 } ) do |
275 MainMenuBar:SetFrameStrata("LOW") -- otherwise it appears on top of bars, if it isn't hidden | 391 MainMenuBar:SetFrameStrata("LOW") -- otherwise it appears on top of bars, if it isn't hidden |
276 hooksecurefunc("UIOptionsFrame_Load",disableUIOptions) | 392 hooksecurefunc("UIOptionsFrame_Load",disableUIOptions) |
277 end | 393 end |
278 | 394 |
279 | 395 |
396 | |
397 | |
398 --------------------------------------- | |
399 -- Bar setup and manipulation functions | |
400 --------------------------------------- | |
280 -- Reset bars to blizzard defaults | 401 -- Reset bars to blizzard defaults |
281 function main:ResetBars() | 402 function main:ResetBars() |
282 if InCombatLockdown() then | 403 if InCombatLockdown() then |
283 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT) | 404 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT) |
284 else | 405 else |
286 self.db.profile.bars = tcopy(ReAction_DefaultBlizzardBars) | 407 self.db.profile.bars = tcopy(ReAction_DefaultBlizzardBars) |
287 self:SetupBars() | 408 self:SetupBars() |
288 end | 409 end |
289 end | 410 end |
290 | 411 |
291 | |
292 -- re-sync action IDs | |
293 function main:ResyncActionIDs() | |
294 -- TODO | |
295 end | |
296 | |
297 | |
298 | |
299 -- Bar manipulation | |
300 main.bars = { } | |
301 | |
302 function main:DestroyAllBars() | 412 function main:DestroyAllBars() |
303 -- destroy any existing bars | 413 -- destroy any existing bars |
304 for id = 1, table.maxn(self.bars) do | 414 for id = 1, table.maxn(self.bars) do |
305 self:DestroyBar(id) | 415 self:DestroyBar(id) |
306 end | 416 end |
307 end | 417 end |
308 | |
309 | 418 |
310 function main:SetupBars() | 419 function main:SetupBars() |
311 -- hide the default Blizzard art, if configued | 420 -- hide the default Blizzard art, if configued |
312 self:HideArt() | 421 self:HideArt() |
313 | 422 |
386 -- find the lowest numbered nil slot. | 495 -- find the lowest numbered nil slot. |
387 self.bars[id] = EMPTY_BAR_SLOT | 496 self.bars[id] = EMPTY_BAR_SLOT |
388 end | 497 end |
389 end | 498 end |
390 | 499 |
500 -- | |
501 -- this function is a wrapper for CreateBar() which looks up the bar type | |
502 -- and constructs a new configuration object of the right type. | |
391 function main:NewBar( type ) | 503 function main:NewBar( type ) |
392 if InCombatLockdown() then | 504 if InCombatLockdown() then |
393 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT) | 505 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT) |
394 else | 506 else |
395 local t = ReAction:GetButtonType(type) | 507 local t = ReAction:GetButtonType(type) |
407 self:Unlock() | 519 self:Unlock() |
408 end | 520 end |
409 end | 521 end |
410 end | 522 end |
411 | 523 |
412 | 524 -- |
525 -- This function is a wrapper for DestroyBar() which does in-combat | |
526 -- checking and updates the config. | |
413 function main:DeleteBar(id) | 527 function main:DeleteBar(id) |
414 if InCombatLockdown() then | 528 if InCombatLockdown() then |
415 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT) | 529 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT) |
416 else | 530 else |
417 if self.bars[id] then | 531 if self.bars[id] then |
419 self.db.profile.bars[id] = nil | 533 self.db.profile.bars[id] = nil |
420 end | 534 end |
421 end | 535 end |
422 end | 536 end |
423 | 537 |
538 | |
539 | |
540 | |
541 ----------------- | |
542 -- General utility | |
543 ----------------- | |
424 function main:ToggleIds() | 544 function main:ToggleIds() |
425 if self.showIds then | 545 if self.showIds then |
426 ReAction:HideAllIds() | 546 ReAction:HideAllIds() |
427 else | 547 else |
428 ReAction:ShowAllIds() | 548 ReAction:ShowAllIds() |
432 | 552 |
433 function main:AreIdsVisible() | 553 function main:AreIdsVisible() |
434 return self.showIds | 554 return self.showIds |
435 end | 555 end |
436 | 556 |
437 | 557 -- set a global variable for Bindings.xml |
438 | 558 ReActionAddOn = main |
559 | |
560 |