Mercurial > wow > reaction
comparison main.lua @ 12:2735edcf9ab7
Version 0.34
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Wed, 21 Mar 2007 00:13:27 +0000 |
parents | f3a7bfebc283 |
children | 639282f3a0e0 |
comparison
equal
deleted
inserted
replaced
11:88df7235ad8b | 12:2735edcf9ab7 |
---|---|
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 local ReBound = AceLibrary("ReBound-1.0"):new("REACTION") |
13 | 13 |
14 -- private functions | 14 -- private functions |
15 local function tcopy(t) | 15 local function tcopy(t) |
16 local r = { } | 16 local r = { } |
17 for k, v in pairs(t) do | 17 for k, v in pairs(t) do |
52 self:RegisterDefaults("profile", ReAction_DefaultProfile) | 52 self:RegisterDefaults("profile", ReAction_DefaultProfile) |
53 self:RegisterEvent("PLAYER_REGEN_DISABLED","CombatLockdown") | 53 self:RegisterEvent("PLAYER_REGEN_DISABLED","CombatLockdown") |
54 self:RegisterEvent("PLAYER_ENTERING_WORLD","HideDefaultBars") | 54 self:RegisterEvent("PLAYER_ENTERING_WORLD","HideDefaultBars") |
55 self:DisableDefaultKeybindings() | 55 self:DisableDefaultKeybindings() |
56 | 56 |
57 -- create update function for keybinding frame | |
58 ReActionKeybindDialog:SetScript("OnHide", function(frame) | |
59 main:SetKeybindMode(false) | |
60 if frame.save then | |
61 ReBound:SaveBindings() | |
62 else | |
63 ReBound:RevertBindings() | |
64 end | |
65 frame.save = false | |
66 end ) | |
67 | |
57 -- initial non-persistent state | 68 -- initial non-persistent state |
58 self.locked = true | 69 self.locked = true |
59 self.bars = { } | 70 self.bars = { } |
60 end | 71 end |
61 | 72 |
62 -- OnEnable is called at startup (startup = true, oldConfig = nil), | 73 -- OnEnable is called at startup and when the profile is changed (via OnProfileEnable) |
63 -- and when the profile is changed (startup = false, oldConfig ~= nil ) | 74 function main:OnEnable( ) |
64 function main:OnEnable( startup, oldConfig ) | |
65 if self.db.profile.firstRunDone ~= true then | 75 if self.db.profile.firstRunDone ~= true then |
66 self.db.profile.bars = tcopy(ReAction_DefaultBlizzardBars) | 76 self.db.profile.bars = tcopy(ReAction_DefaultBlizzardBars) |
67 end | 77 end |
68 self:DestroyAllBars() | 78 self:DestroyAllBars() |
69 self:SetupBars() | 79 self:SetupBars() |
70 self:UpgradeProfile() | 80 self:UpgradeProfile() |
71 self:SetupKeybindings( oldConfig and oldConfig.bindings ) | 81 self:SetupKeybindings() |
72 if self.db.profile.firstRunDone ~= true then | 82 if self.db.profile.firstRunDone ~= true then |
73 self:Unlock() | 83 self:Unlock() |
74 end | 84 end |
75 self.db.profile.firstRunDone = true | 85 self.db.profile.firstRunDone = true |
76 end | 86 end |
79 self:Lock() | 89 self:Lock() |
80 end | 90 end |
81 | 91 |
82 -- OnProfileEnable() is only called when switching profiles, NOT for the initial profile at load time. | 92 -- OnProfileEnable() is only called when switching profiles, NOT for the initial profile at load time. |
83 function main:OnProfileEnable( oldName, oldData ) | 93 function main:OnProfileEnable( oldName, oldData ) |
84 self:OnEnable(false, oldData) | 94 self:UnregisterEvent("REBOUND_BIND") |
95 self:UnregisterEvent("REBOUND_UNBIND") | |
96 ReBound:ClearRegisteredBindings() | |
97 self:OnEnable() | |
85 end | 98 end |
86 | 99 |
87 function main:UpgradeProfile() | 100 function main:UpgradeProfile() |
88 if self.db.profile.firstRunDone ~= true and #self.db.profile.bindings == 0 then | 101 if self.db.profile.firstRunDone ~= true and #self.db.profile.bindings == 0 then |
89 for _, bar in pairs(self.bars) do | 102 for _, bar in pairs(self.bars) do |
162 BINDING_HEADER_MULTIACTIONBAR = "|cff999999"..L["Multi-Action Bar Functions Disabled"].."|r" | 175 BINDING_HEADER_MULTIACTIONBAR = "|cff999999"..L["Multi-Action Bar Functions Disabled"].."|r" |
163 BINDING_NAME_NEXTACTIONPAGE = label | 176 BINDING_NAME_NEXTACTIONPAGE = label |
164 BINDING_NAME_PREVIOUSACTIONPAGE = label | 177 BINDING_NAME_PREVIOUSACTIONPAGE = label |
165 end | 178 end |
166 | 179 |
167 function main:SetupKeybindings( previous ) | 180 function main:SetupKeybindings() |
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 | 181 if self.db.profile.firstRunDone ~= true then |
176 self:StealKeyBindings() | 182 self:StealKeyBindings() |
177 else | 183 else |
178 for key, binding in pairs(self.db.profile.bindings) do | 184 for key, binding in pairs(self.db.profile.bindings) do |
179 ReBound:SetBinding(key, getglobal(binding.target), binding.button) | 185 local target = getglobal(binding.target) |
180 end | 186 if target then |
181 end | 187 ReBound:SetBinding(key, target, binding.button) |
182 SaveBindings(GetCurrentBindingSet()) | 188 end |
189 end | |
190 end | |
191 ReBound:SaveBindings() | |
183 self:RegisterEvent("REBOUND_BIND") | 192 self:RegisterEvent("REBOUND_BIND") |
184 self:RegisterEvent("REBOUND_UNBIND") | 193 self:RegisterEvent("REBOUND_UNBIND") |
185 end | 194 end |
186 | 195 |
187 function main:StealKeyBindings() | 196 function main:StealKeyBindings() |
191 if key and #key > 0 then | 200 if key and #key > 0 then |
192 ReBound:ClearBinding(key,nil,nil,true) -- suppress notification printouts | 201 ReBound:ClearBinding(key,nil,nil,true) -- suppress notification printouts |
193 ReBound:SetBinding(key, self.bars[1].buttons[i]:GetActionFrame(), "LeftButton") | 202 ReBound:SetBinding(key, self.bars[1].buttons[i]:GetActionFrame(), "LeftButton") |
194 end | 203 end |
195 end | 204 end |
196 SaveBindings(GetCurrentBindingSet()) | 205 ReBound:SaveBindings() |
197 end | 206 end |
198 | 207 |
199 function main:REBOUND_BIND(key, target, button) | 208 function main:REBOUND_BIND(id, key, target, button) |
200 if key and target then | 209 if id == "REACTION" and key and target then |
201 self.db.profile.bindings[key] = { target = target, button = button } | 210 self.db.profile.bindings[key] = { target = target, button = button } |
202 end | 211 end |
203 end | 212 end |
204 | 213 |
205 function main:REBOUND_UNBIND(key) | 214 function main:REBOUND_UNBIND(id, key) |
206 if key then | 215 if id == "REACTION" and key then |
207 self.db.profile.bindings[key] = nil | 216 self.db.profile.bindings[key] = nil |
208 end | 217 end |
209 end | 218 end |
210 | 219 |
211 function main:ToggleKeybindMode() | 220 function main:ToggleKeybindMode() |
225 button:TempShow(enabled) | 234 button:TempShow(enabled) |
226 end | 235 end |
227 end | 236 end |
228 end | 237 end |
229 if enabled then | 238 if enabled then |
230 ReBound:ShowAll() | 239 ReBound:ShowFrames() |
231 ReActionKeybindDialog:Show() | 240 ReActionKeybindDialog:Show() |
232 else | 241 else |
233 ReBound:HideAll() | 242 ReBound:HideFrames() |
234 if ReActionKeybindDialog:IsShown() then | 243 if ReActionKeybindDialog:IsShown() then |
235 ReActionKeybindDialog:Hide() | 244 ReActionKeybindDialog:Hide() |
236 end | 245 end |
237 end | 246 end |
238 else | 247 else |
466 dewdrop:Open(cf) | 475 dewdrop:Open(cf) |
467 end | 476 end |
468 end | 477 end |
469 ) | 478 ) |
470 | 479 |
480 -- register page up/down buttons with ReBound for keybinding | |
481 ReBound:Register(bar.upArrow) | |
482 ReBound:Register(bar.downArrow) | |
483 | |
471 if not self.locked then | 484 if not self.locked then |
472 bar:ShowControls() | 485 bar:ShowControls() |
473 end | 486 end |
474 return bar | 487 return bar |
475 else | 488 else |