vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | |
2 | -- Old mappings now deprecated. Left here to support addons already using them, |
||
3 | -- but these will be removed in the future, so update to the new format. |
||
4 | MYBINDINGS_CATEGORY_BARS = "bars" |
||
5 | MYBINDINGS_CATEGORY_CHAT = "chat" |
||
6 | MYBINDINGS_CATEGORY_CLASS = "class" |
||
7 | MYBINDINGS_CATEGORY_COMBAT = "combat" |
||
8 | MYBINDINGS_CATEGORY_COMPILATIONS = "compilations" |
||
9 | MYBINDINGS_CATEGORY_INTERFACE = "interface" |
||
10 | MYBINDINGS_CATEGORY_INVENTORY = "inventory" |
||
11 | MYBINDINGS_CATEGORY_MAP = "map" |
||
12 | MYBINDINGS_CATEGORY_OTHERS = "others" |
||
13 | MYBINDINGS_CATEGORY_PROFESSIONS = "professions" |
||
14 | MYBINDINGS_CATEGORY_QUESTS = "quests" |
||
15 | MYBINDINGS_CATEGORY_RAID = "raid" |
||
16 | |||
17 | -- Key binding to open up the myBindings window. |
||
18 | BINDING_HEADER_MYBINDINGS = MYBINDINGS_NAME |
||
19 | BINDING_CATEGORY_MYBINDINGS = "interface" |
||
20 | BINDING_NAME_MYBINDINGS_OPEN = MYBINDINGS_KEYBIND_OPEN |
||
21 | |||
22 | |||
23 | --[[-------------------------------------------------------------------------- |
||
24 | Class Definition |
||
25 | -----------------------------------------------------------------------------]] |
||
26 | |||
27 | myBindings = AceAddonClass:new({ |
||
28 | name = MYBINDINGS_NAME, |
||
29 | description = MYBINDINGS_DESCRIPTION, |
||
30 | category = BINDING_CATEGORY_MYBINDINGS, |
||
31 | optionsFrame = "myBindingsOptionsFrame", |
||
32 | version = "1.3", |
||
33 | releaseDate = "10-11-2005", |
||
34 | author = "Turan", |
||
35 | email = "turan@wowace.com", |
||
36 | website = "http://www.wowace.com", |
||
37 | aceCompatible = "100", |
||
38 | db = AceDbClass:new("myBindingsDB"), |
||
39 | cmd = AceChatCmdClass:new(MYBINDINGS_COMMANDS, MYBINDINGS_CMD_OPTIONS), |
||
40 | |||
41 | maxMenuLines = 18, |
||
42 | maxMenuLineHeight = 22, |
||
43 | maxBindingLines = 17, |
||
44 | maxBindingLineHeight = 25, |
||
45 | |||
46 | categoriesSort = { |
||
47 | MYBINDINGS_CATEGORY_GAME, |
||
48 | ACE_CATEGORY_BARS, |
||
49 | ACE_CATEGORY_CHAT, |
||
50 | ACE_CATEGORY_CLASS, |
||
51 | ACE_CATEGORY_COMBAT, |
||
52 | ACE_CATEGORY_COMPILATIONS, |
||
53 | ACE_CATEGORY_INTERFACE, |
||
54 | ACE_CATEGORY_INVENTORY, |
||
55 | ACE_CATEGORY_MAP, |
||
56 | ACE_CATEGORY_OTHERS, |
||
57 | ACE_CATEGORY_PROFESSIONS, |
||
58 | ACE_CATEGORY_QUESTS, |
||
59 | ACE_CATEGORY_RAID |
||
60 | }, |
||
61 | gameBindings = {}, |
||
62 | currentMenuSelection = nil, |
||
63 | confirmKeyBind = nil |
||
64 | }) |
||
65 | myBindings:RegisterForLoad() |
||
66 | |||
67 | function myBindings:Initialize() |
||
68 | if( myBindings_LoadCategories ) then myBindings_LoadCategories() end |
||
69 | |||
70 | self.Msg = function(...) self.cmd:result(format(unpack(arg))) end |
||
71 | self.Error = function(...) self.cmd:result(ACEG_LABEL_ERROR, " ", format(unpack(arg))) end |
||
72 | |||
73 | self.savedKeyBindingFrame = KeyBindingFrame |
||
74 | self.frame = myBindingsOptionsFrame |
||
75 | self.currentProfile = self.profilePath[2] |
||
76 | end |
||
77 | |||
78 | -- Data Management |
||
79 | |||
80 | function myBindings:GetBind(val) |
||
81 | if( not val ) then |
||
82 | return self.db:get(self.profilePath, "bindings") |
||
83 | else |
||
84 | return self.db:get({self.profilePath, "bindings"}, val) |
||
85 | end |
||
86 | end |
||
87 | function myBindings:SetBind(var, val) |
||
88 | self.db:set({self.profilePath, "bindings"}, var, val) |
||
89 | end |
||
90 | function myBindings:ClearBinds() |
||
91 | self.db:set(self.profilePath, "bindings") |
||
92 | end |
||
93 | |||
94 | function myBindings:GetCat(var) |
||
95 | return self.db:get({"categories"}, var) |
||
96 | end |
||
97 | function myBindings:SetCat(var, val) |
||
98 | self.db:set({"categories"}, var, val) |
||
99 | end |
||
100 | |||
101 | -- |
||
102 | |||
103 | function myBindings:Enable() |
||
104 | -- Override the existing key bindings dialog so that myBindingsOptionsFrame will |
||
105 | -- get called just like any other UIPanel frame. |
||
106 | KeyBindingFrame = myBindingsOptionsFrame |
||
107 | GameMenuButtonKeybindings:Hide() |
||
108 | myBindingsGameMenuButton:Show() |
||
109 | |||
110 | self:RegisterEvent("ACE_PROFILE_LOADED") |
||
111 | |||
112 | self:SetGameBindings() |
||
113 | self:ParseBindings() |
||
114 | self:LoadBindings(GetCurrentBindingSet()) |
||
115 | self:UpdateLoadedLabel() |
||
116 | |||
117 | UIPanelWindows[self.optionsFrame] = {area = "center", pushable = 0} |
||
118 | self.frame.selected = nil |
||
119 | end |
||
120 | |||
121 | function myBindings:Disable() |
||
122 | KeyBindingFrame = self.savedKeyBindingFrame |
||
123 | GameMenuButtonKeybindings:Show() |
||
124 | myBindingsGameMenuButton:Hide() |
||
125 | end |
||
126 | |||
127 | function myBindings:ACE_PROFILE_LOADED() |
||
128 | if( self.profilePath[2] == self.currentProfile ) then return end |
||
129 | self.currentProfile = self.profilePath[2] |
||
130 | self:LoadBindings(GetCurrentBindingSet()) |
||
131 | self:UpdateLoadedLabel() |
||
132 | end |
||
133 | |||
134 | |||
135 | --[[-------------------------------------------------------------------------- |
||
136 | Initialize Bindings List |
||
137 | -----------------------------------------------------------------------------]] |
||
138 | |||
139 | function myBindings:SetGameBindings() |
||
140 | -- This is just a reference list to check later which bindings are part of the |
||
141 | -- standard game controls. |
||
142 | self.gameBindings[BINDING_HEADER_ACTIONBAR] = 1 |
||
143 | self.gameBindings[BINDING_HEADER_CAMERA] = 1 |
||
144 | self.gameBindings[BINDING_HEADER_CHAT] = 1 |
||
145 | self.gameBindings[BINDING_HEADER_INTERFACE] = 1 |
||
146 | self.gameBindings[BINDING_HEADER_MISC] = 1 |
||
147 | self.gameBindings[BINDING_HEADER_MOVEMENT] = 1 |
||
148 | self.gameBindings[BINDING_HEADER_TARGETING] = 1 |
||
149 | self.gameBindings[BINDING_HEADER_MULTIACTIONBAR] = 1 |
||
150 | self.gameBindings[BINDING_HEADER_BLANK] = 1 |
||
151 | self.gameBindings[BINDING_HEADER_BLANK2] = 1 |
||
152 | self.gameBindings[BINDING_HEADER_BLANK3] = 1 |
||
153 | end |
||
154 | |||
155 | function myBindings:ParseBindings() |
||
156 | local categories = {} |
||
157 | local commandName, binding1, binding2, header, addOnCat |
||
158 | |||
159 | self.menuHeaders = {} |
||
160 | self.bindingIndexes = {} |
||
161 | self.expandedCategories = {} |
||
162 | |||
163 | for index = 1, GetNumBindings(), 1 do |
||
164 | commandName, binding1, binding2 = GetBinding(index) |
||
165 | |||
166 | if( strsub(commandName, 1, 6) == "HEADER" ) then |
||
167 | header = getglobal("BINDING_"..commandName) |
||
168 | if( (header or "") == "" ) then header = strsub(commandName, 8) end |
||
169 | |||
170 | self.bindingIndexes[header] = {} |
||
171 | |||
172 | -- Add to appropriate category |
||
173 | if( self.gameBindings[header] ) then |
||
174 | if( not categories[MYBINDINGS_CATEGORY_GAME] ) then |
||
175 | categories[MYBINDINGS_CATEGORY_GAME] = {} |
||
176 | end |
||
177 | table.insert(categories[MYBINDINGS_CATEGORY_GAME], header) |
||
178 | else |
||
179 | addOnCat = getglobal( |
||
180 | "ACE_CATEGORY_".. |
||
181 | strupper( |
||
182 | self:GetCat(strsub(commandName, 8)) or |
||
183 | getglobal("BINDING_CATEGORY_"..strsub(commandName, 8)) or |
||
184 | "others" |
||
185 | ) |
||
186 | ) or ACE_CATEGORY_OTHERS |
||
187 | if( not categories[addOnCat] ) then categories[addOnCat] = {} end |
||
188 | table.insert(categories[addOnCat], header) |
||
189 | end |
||
190 | elseif( header ) then |
||
191 | -- Need to save the index so it can be used later to reference this command |
||
192 | -- in the API's bindings list. |
||
193 | table.insert(self.bindingIndexes[header], index) |
||
194 | end |
||
195 | end |
||
196 | |||
197 | -- Now place all the sorted categories and headers into one list for easy |
||
198 | -- display later on. |
||
199 | for index, category in self.categoriesSort do |
||
200 | if( categories[category] ) then |
||
201 | table.sort(categories[category]) |
||
202 | table.insert(self.menuHeaders, {text=category, isCategory=TRUE}) |
||
203 | for i, header in categories[category] do |
||
204 | table.insert(self.menuHeaders, {text=header, category=category}) |
||
205 | end |
||
206 | end |
||
207 | end |
||
208 | end |
||
209 | |||
210 | |||
211 | --[[-------------------------------------------------------------------------- |
||
212 | Dialog Handling Methods |
||
213 | -----------------------------------------------------------------------------]] |
||
214 | |||
215 | function myBindings:HeadingsUpdate() |
||
216 | local numHeaders = table.getn(self.menuHeaders) |
||
217 | local offset = FauxScrollFrame_GetOffset(myBindingsOptionsHeadingsScrollFrame) |
||
218 | local hdrinx = 0 |
||
219 | local visible = 0 |
||
220 | local line = 0 |
||
221 | local header, menuItem, button |
||
222 | |||
223 | -- In case we were waiting for a key bind confirmation, cancel it. |
||
224 | self:CancelKeyBind() |
||
225 | |||
226 | -- Browse the lines |
||
227 | while ( line < self.maxMenuLines ) do |
||
228 | if( ((offset + line) <= numHeaders) and (hdrinx < numHeaders) ) then |
||
229 | hdrinx = hdrinx + 1 |
||
230 | header = self.menuHeaders[hdrinx] |
||
231 | |||
232 | if( header.isCategory ) then |
||
233 | visible = visible + 1 |
||
234 | if( visible > offset ) then |
||
235 | line = line + 1 |
||
236 | getglobal("myBindingsOptionsBindCategory"..line.."NormalText"):SetText(header.text) |
||
237 | -- getglobal("myBindingsOptionsBindCategory"..line.."HighlightText"):SetText(header.text) |
||
238 | getglobal("myBindingsOptionsBindCategory"..line):Show() |
||
239 | getglobal("myBindingsOptionsBindHeader"..line):Hide() |
||
240 | end |
||
241 | elseif( self.expandedCategories[header.category] ) then |
||
242 | visible = visible + 1 |
||
243 | if( visible > offset ) then |
||
244 | line = line + 1 |
||
245 | menuItem = getglobal("myBindingsOptionsBindHeader"..line) |
||
246 | button = getglobal("myBindingsOptionsBindHeader"..line.."Button") |
||
247 | |||
248 | getglobal("myBindingsOptionsBindHeader"..line.."ButtonNormalText"):SetText(header.text) |
||
249 | -- getglobal("myBindingsOptionsBindHeader"..line.."ButtonHighlightText"):SetText(header.text) |
||
250 | getglobal("myBindingsOptionsBindCategory"..line):Hide() |
||
251 | menuItem:Show() |
||
252 | |||
253 | if( self.currentMenuSelection == header.text ) then |
||
254 | myBindingsOptionsFrameBindingsTitle:SetText(header.text) |
||
255 | menuItem:SetBackdropBorderColor(.9, .9, 0) |
||
256 | menuItem:SetBackdropColor(1.0, 1.0, 0.5) |
||
257 | button:LockHighlight() |
||
258 | else |
||
259 | menuItem:SetBackdropBorderColor(0.4, 0.4, 0.4) |
||
260 | menuItem:SetBackdropColor(0.15, 0.15, 0.15) |
||
261 | button:UnlockHighlight() |
||
262 | end |
||
263 | |||
264 | self.frame.highlightID = self.frame:GetParent():GetID() |
||
265 | end |
||
266 | end |
||
267 | else |
||
268 | line = line + 1 |
||
269 | getglobal("myBindingsOptionsBindCategory"..line):Hide() |
||
270 | getglobal("myBindingsOptionsBindHeader"..line):Hide() |
||
271 | end |
||
272 | end |
||
273 | |||
274 | FauxScrollFrame_Update(myBindingsOptionsHeadingsScrollFrame, |
||
275 | self:GetMenuNumVisible(), |
||
276 | self.maxMenuLines, |
||
277 | self.maxMenuLineHeight |
||
278 | ) |
||
279 | end |
||
280 | |||
281 | function myBindings:ExpandCollapseHeadings(val) |
||
282 | for index, header in self.menuHeaders do |
||
283 | if( header.isCategory ) then |
||
284 | self.expandedCategories[header.text] = val |
||
285 | end |
||
286 | end |
||
287 | end |
||
288 | |||
289 | function myBindings:GetMenuNumVisible() |
||
290 | local numVisible = 0 |
||
291 | |||
292 | for index = 1, table.getn(self.menuHeaders), 1 do |
||
293 | if( self.menuHeaders[index].isCategory ) then |
||
294 | numVisible = numVisible + 1 |
||
295 | elseif( self.expandedCategories[self.menuHeaders[index].category] ) then |
||
296 | numVisible = numVisible + 1 |
||
297 | end |
||
298 | end |
||
299 | |||
300 | return numVisible |
||
301 | end |
||
302 | |||
303 | function myBindings:CategoryOnClick(text) |
||
304 | self.expandedCategories[text] = (not self.expandedCategories[text]) |
||
305 | self:HeadingsUpdate() |
||
306 | end |
||
307 | |||
308 | function myBindings:HeaderOnClick() |
||
309 | self.currentMenuSelection = this:GetText() |
||
310 | self:HeadingsUpdate() |
||
311 | self:BindingsUpdate() |
||
312 | end |
||
313 | |||
314 | |||
315 | --[[-------------------------------------------------------------------------- |
||
316 | Bindings ScrollFrame Methods |
||
317 | -----------------------------------------------------------------------------]] |
||
318 | |||
319 | -- Copied from Blizzard's UI as a temporary fix for game patch 1800. Since the |
||
320 | -- default key binding frame is no longer loaded at start, this function is |
||
321 | -- not available if the default key bind frame is never opened, which it probably |
||
322 | -- never is if someone is using myBindings. 10/11/2005 |
||
323 | function KeyBindingFrame_GetLocalizedName(name, prefix) |
||
324 | if ( not name ) then |
||
325 | return ""; |
||
326 | end |
||
327 | local tempName = name; |
||
328 | local i = strfind(name, "-"); |
||
329 | local dashIndex = nil; |
||
330 | while ( i ) do |
||
331 | if ( not dashIndex ) then |
||
332 | dashIndex = i; |
||
333 | else |
||
334 | dashIndex = dashIndex + i; |
||
335 | end |
||
336 | tempName = strsub(tempName, i + 1); |
||
337 | i = strfind(tempName, "-"); |
||
338 | end |
||
339 | |||
340 | local modKeys = ''; |
||
341 | if ( not dashIndex ) then |
||
342 | dashIndex = 0; |
||
343 | else |
||
344 | modKeys = strsub(name, 1, dashIndex); |
||
345 | if ( GetLocale() == "deDE") then |
||
346 | modKeys = gsub(modKeys, "CTRL", "STRG"); |
||
347 | end |
||
348 | end |
||
349 | |||
350 | local variablePrefix = prefix; |
||
351 | if ( not variablePrefix ) then |
||
352 | variablePrefix = ""; |
||
353 | end |
||
354 | local localizedName = nil; |
||
355 | if ( IsMacClient() ) then |
||
356 | -- see if there is a mac specific name for the key |
||
357 | localizedName = getglobal(variablePrefix..tempName.."_MAC"); |
||
358 | end |
||
359 | if ( not localizedName ) then |
||
360 | localizedName = getglobal(variablePrefix..tempName); |
||
361 | end |
||
362 | if ( not localizedName ) then |
||
363 | localizedName = tempName; |
||
364 | end |
||
365 | return modKeys..localizedName; |
||
366 | end |
||
367 | |||
368 | function myBindings:BindingsUpdate() |
||
369 | local header = self.currentMenuSelection |
||
370 | local indexes = self.bindingIndexes[header] |
||
371 | local scrollOffset = FauxScrollFrame_GetOffset(myBindingsOptionsBindingsScrollFrame) |
||
372 | local bindLine, commandName, numCommands, keyOffset |
||
373 | local keyBindingButton1, keyBindingButton1NormalTexture, keyBindingButton1PushedTexture, |
||
374 | keyBindingButton2, keyBindingButton2NormalTexture, keyBindingButton2PushedTexture, |
||
375 | keyBindingDescription |
||
376 | |||
377 | -- In case we were waiting for a key bind confirmation, cancel it. |
||
378 | if( not myBindingsOptionsBindingsScrollFrame.buttonPressed ) then |
||
379 | self:CancelKeyBind() |
||
380 | end |
||
381 | |||
382 | if( indexes ) then |
||
383 | numCommands = table.getn(indexes) |
||
384 | else |
||
385 | numCommands = 0 |
||
386 | end |
||
387 | |||
388 | -- Browse the lines |
||
389 | for line = 1, self.maxBindingLines, 1 do |
||
390 | keyOffset = scrollOffset + line |
||
391 | keyBindingButton1 = getglobal("myBindingsOptionsBindingLine"..line.."Key1Button") |
||
392 | keyBindingButton2 = getglobal("myBindingsOptionsBindingLine"..line.."Key2Button") |
||
393 | |||
394 | if( keyOffset <= numCommands ) then |
||
395 | bindLine = getglobal("myBindingsOptionsBindingLine"..line) |
||
396 | commandName, binding1, binding2 = GetBinding(self.bindingIndexes[header][keyOffset]) |
||
397 | |||
398 | keyBindingButton1NormalTexture = getglobal("myBindingsOptionsBindingLine"..line.."Key1ButtonNormalTexture") |
||
399 | keyBindingButton1PushedTexture = getglobal("myBindingsOptionsBindingLine"..line.."Key1ButtonPushedTexture") |
||
400 | keyBindingButton2NormalTexture = getglobal("myBindingsOptionsBindingLine"..line.."Key2ButtonNormalTexture") |
||
401 | keyBindingButton2PushedTexture = getglobal("myBindingsOptionsBindingLine"..line.."Key2ButtonPushedTexture") |
||
402 | keyBindingLabel = getglobal("myBindingsOptionsBindingLine"..line.."Label") |
||
403 | |||
404 | keyBindingLabel:SetText(KeyBindingFrame_GetLocalizedName(commandName, "BINDING_NAME_")) |
||
405 | |||
406 | if( binding1 ) then |
||
407 | keyBindingButton1:SetText( |
||
408 | KeyBindingFrame_GetLocalizedName(binding1, "KEY_") |
||
409 | ) |
||
410 | keyBindingButton1:SetAlpha(1) |
||
411 | else |
||
412 | keyBindingButton1:SetText(NORMAL_FONT_COLOR_CODE..NOT_BOUND..FONT_COLOR_CODE_CLOSE) |
||
413 | keyBindingButton1:SetAlpha(0.8) |
||
414 | end |
||
415 | |||
416 | if( binding2 ) then |
||
417 | keyBindingButton2:SetText( |
||
418 | KeyBindingFrame_GetLocalizedName(binding2, "KEY_") |
||
419 | ) |
||
420 | keyBindingButton2:SetAlpha(1) |
||
421 | else |
||
422 | keyBindingButton2:SetText(NORMAL_FONT_COLOR_CODE..NOT_BOUND..FONT_COLOR_CODE_CLOSE) |
||
423 | keyBindingButton2:SetAlpha(0.8) |
||
424 | end |
||
425 | |||
426 | if( myBindingsOptionsBindingsScrollFrame.selected == commandName ) then |
||
427 | if( myBindingsOptionsBindingsScrollFrame.keyID == 1 ) then |
||
428 | keyBindingButton1:LockHighlight() |
||
429 | keyBindingButton2:UnlockHighlight() |
||
430 | else |
||
431 | keyBindingButton2:LockHighlight() |
||
432 | keyBindingButton1:UnlockHighlight() |
||
433 | end |
||
434 | else |
||
435 | keyBindingButton1:UnlockHighlight() |
||
436 | keyBindingButton2:UnlockHighlight() |
||
437 | end |
||
438 | |||
439 | keyBindingButton1.commandName = commandName |
||
440 | keyBindingButton2.commandName = commandName |
||
441 | |||
442 | bindLine:Show() |
||
443 | else |
||
444 | keyBindingButton1.commandName = nil |
||
445 | keyBindingButton2.commandName = nil |
||
446 | getglobal("myBindingsOptionsBindingLine"..line):Hide() |
||
447 | end |
||
448 | end |
||
449 | |||
450 | FauxScrollFrame_Update(myBindingsOptionsBindingsScrollFrame, |
||
451 | numCommands, |
||
452 | self.maxBindingLines, |
||
453 | self.maxBindingLineHeight |
||
454 | ) |
||
455 | end |
||
456 | |||
457 | function myBindings:DeselectButton() |
||
458 | myBindingsOptionsFrameOutputText:SetText("") |
||
459 | myBindingsOptionsBindingsScrollFrame.selected = nil |
||
460 | myBindingsOptionsBindingsScrollFrame.buttonPressed = nil |
||
461 | myBindingsOptionsBindingsScrollFrame.keyID = nil |
||
462 | self:BindingsUpdate() |
||
463 | end |
||
464 | |||
465 | function myBindings:BindingOnClick(button) |
||
466 | if( myBindingsOptionsBindingsScrollFrame.buttonPressed == this ) then |
||
467 | -- Code to be able to deselect or select another key to bind |
||
468 | if( button == "LeftButton" or button == "RightButton" ) then |
||
469 | -- Deselect button if it was the pressed previously pressed |
||
470 | self:DeselectButton() |
||
471 | else |
||
472 | self:OnKeyDown(button) |
||
473 | end |
||
474 | else |
||
475 | myBindingsOptionsFrameUnbindButton:Enable() |
||
476 | myBindingsOptionsBindingsScrollFrame.selected = this.commandName |
||
477 | myBindingsOptionsBindingsScrollFrame.buttonPressed = this |
||
478 | myBindingsOptionsBindingsScrollFrame.keyID = this:GetID() |
||
479 | myBindingsOptionsFrameOutputText:SetText( |
||
480 | format(BIND_KEY_TO_COMMAND, |
||
481 | KeyBindingFrame_GetLocalizedName(this.commandName, "BINDING_NAME_") |
||
482 | ) |
||
483 | ) |
||
484 | self:BindingsUpdate() |
||
485 | end |
||
486 | end |
||
487 | |||
488 | function myBindings:OnKeyDown(button) |
||
489 | if( arg1 == "PRINTSCREEN" ) then |
||
490 | Screenshot() |
||
491 | return |
||
492 | end |
||
493 | |||
494 | -- Convert the mouse button names |
||
495 | if( button == "LeftButton" ) then |
||
496 | button = "BUTTON1" |
||
497 | elseif( button == "RightButton" ) then |
||
498 | button = "BUTTON2" |
||
499 | elseif( button == "MiddleButton" ) then |
||
500 | button = "BUTTON3" |
||
501 | elseif( button == "Button4" ) then |
||
502 | button = "BUTTON4" |
||
503 | elseif( button == "Button5" ) then |
||
504 | button = "BUTTON5" |
||
505 | end |
||
506 | |||
507 | if( myBindingsOptionsBindingsScrollFrame.selected ) then |
||
508 | local keyPressed = arg1 |
||
509 | |||
510 | if( button ) then |
||
511 | if( button == "BUTTON1" or button == "BUTTON2" ) then |
||
512 | return |
||
513 | end |
||
514 | keyPressed = button |
||
515 | else |
||
516 | keyPressed = arg1 |
||
517 | end |
||
518 | |||
519 | if( keyPressed == "UNKNOWN" ) then |
||
520 | return |
||
521 | end |
||
522 | if( keyPressed == "SHIFT" or keyPressed == "CTRL" or keyPressed == "ALT") then |
||
523 | return |
||
524 | end |
||
525 | if( IsShiftKeyDown() ) then |
||
526 | keyPressed = "SHIFT-"..keyPressed |
||
527 | end |
||
528 | if( IsControlKeyDown() ) then |
||
529 | keyPressed = "CTRL-"..keyPressed |
||
530 | end |
||
531 | if( IsAltKeyDown() ) then |
||
532 | keyPressed = "ALT-"..keyPressed |
||
533 | end |
||
534 | |||
535 | local oldAction = GetBindingAction(keyPressed) |
||
536 | if( (oldAction ~= "") and (oldAction ~= myBindingsOptionsBindingsScrollFrame.selected) ) then |
||
537 | local key1, key2 = GetBindingKey(oldAction) |
||
538 | if( (not key1 or key1 == keyPressed) and ((not key2) or (key2 == keyPressed)) ) then |
||
539 | --Error message |
||
540 | myBindingsOptionsFrameOutputText:SetText( |
||
541 | format(MYBINDINGS_BOUND_ERROR, |
||
542 | keyPressed, |
||
543 | KeyBindingFrame_GetLocalizedName(oldAction, "BINDING_NAME_") |
||
544 | ) |
||
545 | ) |
||
546 | self.confirmKeyBind = TRUE |
||
547 | end |
||
548 | end |
||
549 | |||
550 | if( self.confirmKeyBind ) then |
||
551 | myBindingsOptionsFrameConfirmBindButton:Show() |
||
552 | myBindingsOptionsFrameConfirmBindButton.keyPressed = keyPressed |
||
553 | myBindingsOptionsFrameCancelBindButton:Show() |
||
554 | else |
||
555 | self:BindKey(keyPressed) |
||
556 | end |
||
557 | else |
||
558 | if( arg1 == "ESCAPE" ) then |
||
559 | LoadBindings(GetCurrentBindingSet()) |
||
560 | myBindingsOptionsFrameOutputText:SetText("") |
||
561 | myBindingsOptionsBindingsScrollFrame.selected = nil |
||
562 | HideUIPanel(this) |
||
563 | end |
||
564 | end |
||
565 | end |
||
566 | |||
567 | function myBindings:BindKey(keyPressed) |
||
568 | local key1, key2 = GetBindingKey(myBindingsOptionsBindingsScrollFrame.selected) |
||
569 | |||
570 | if( key1 ) then SetBinding(key1); end |
||
571 | if( key2 ) then SetBinding(key2); end |
||
572 | |||
573 | if( myBindingsOptionsBindingsScrollFrame.keyID == 1 ) then |
||
574 | self:SetBinding(keyPressed, myBindingsOptionsBindingsScrollFrame.selected, key1) |
||
575 | if( key2 ) then |
||
576 | SetBinding(key2, myBindingsOptionsBindingsScrollFrame.selected) |
||
577 | end |
||
578 | else |
||
579 | if( key1 ) then |
||
580 | self:SetBinding(key1, myBindingsOptionsBindingsScrollFrame.selected) |
||
581 | end |
||
582 | self:SetBinding(keyPressed, myBindingsOptionsBindingsScrollFrame.selected, key2) |
||
583 | end |
||
584 | |||
585 | myBindingsOptionsBindingsScrollFrame.selected = nil |
||
586 | myBindingsOptionsBindingsScrollFrame.buttonPressed = nil |
||
587 | self:BindingsUpdate() |
||
588 | myBindingsOptionsFrameOutputText:SetText(KEY_BOUND) |
||
589 | end |
||
590 | |||
591 | function myBindings:SetBinding(key, selectedBinding, oldKey) |
||
592 | if( SetBinding(key, selectedBinding) ) then |
||
593 | return |
||
594 | else |
||
595 | if( oldKey ) then |
||
596 | SetBinding(oldKey, selectedBinding) |
||
597 | end |
||
598 | --Error message |
||
599 | myBindingsOptionsFrameOutputText:SetText( |
||
600 | "Can't bind mousewheel to actions with up and down states" |
||
601 | ) |
||
602 | end |
||
603 | end |
||
604 | |||
605 | function myBindings:ConfirmKeyBind() |
||
606 | self:BindKey(this.keyPressed) |
||
607 | end |
||
608 | |||
609 | function myBindings:CancelKeyBind() |
||
610 | self.confirmKeyBind = FALSE |
||
611 | |||
612 | -- Button highlighting stuff |
||
613 | myBindingsOptionsBindingsScrollFrame.selected = nil |
||
614 | if( myBindingsOptionsBindingsScrollFrame.buttonPressed ) then |
||
615 | myBindingsOptionsBindingsScrollFrame.buttonPressed:UnlockHighlight() |
||
616 | myBindingsOptionsBindingsScrollFrame.buttonPressed = nil |
||
617 | end |
||
618 | |||
619 | myBindingsOptionsFrameConfirmBindButton:Hide() |
||
620 | myBindingsOptionsFrameConfirmBindButton.keyPressed = nil |
||
621 | myBindingsOptionsFrameCancelBindButton:Hide() |
||
622 | myBindingsOptionsFrameUnbindButton:Disable() |
||
623 | myBindingsOptionsFrameOutputText:SetText("") |
||
624 | end |
||
625 | |||
626 | function myBindings:UnbindKey() |
||
627 | if( not myBindingsOptionsBindingsScrollFrame.selected ) then return end |
||
628 | |||
629 | local key1, key2 = GetBindingKey(myBindingsOptionsBindingsScrollFrame.selected) |
||
630 | |||
631 | if( myBindingsOptionsBindingsScrollFrame.keyID == 1 ) then |
||
632 | if( key1 ) then SetBinding(key1) end |
||
633 | if( key2 ) then |
||
634 | SetBinding(key2, myBindingsOptionsBindingsScrollFrame.selected) |
||
635 | end |
||
636 | elseif( key2 ) then SetBinding(key2) |
||
637 | end |
||
638 | |||
639 | self:CancelKeyBind() |
||
640 | self:BindingsUpdate() |
||
641 | end |
||
642 | |||
643 | |||
644 | --[[-------------------------------------------------------------------------- |
||
645 | Binding Methods |
||
646 | -----------------------------------------------------------------------------]] |
||
647 | |||
648 | function myBindings:LoadGameDefaultBindings() |
||
649 | LoadBindings(DEFAULT_BINDINGS) |
||
650 | self:BindingsUpdate() |
||
651 | end |
||
652 | |||
653 | function myBindings:LoadBindings() |
||
654 | -- If there's no binding set in the current profile, don't do anything or this |
||
655 | -- will wipe out all settings, leaving mouse-control of the game only. |
||
656 | if( not self:GetBind() ) then return end |
||
657 | |||
658 | local commandName, binding1, binding2, command |
||
659 | |||
660 | for index = 1, GetNumBindings(), 1 do |
||
661 | commandName, binding1, binding2 = GetBinding(index) |
||
662 | |||
663 | -- I don't know why, but if the bindings aren't first erased, then attempting |
||
664 | -- to overwrite the values from the stored values will wipe out all the second |
||
665 | -- key bindings. They need clearing anyway in case the stored binding set |
||
666 | -- doesn't have values, meaning these bindings should be empty. |
||
667 | if( binding1 ) then SetBinding(binding1) end |
||
668 | if( binding2 ) then SetBinding(binding2) end |
||
669 | |||
670 | command = self:GetBind(commandName) |
||
671 | if( command ) then |
||
672 | if( command.bind1 ) then SetBinding(command.bind1, commandName, binding1) end |
||
673 | if( command.bind2 ) then SetBinding(command.bind2, commandName, binding2) end |
||
674 | end |
||
675 | end |
||
676 | |||
677 | SaveBindings(GetCurrentBindingSet()) |
||
678 | self:BindingsUpdate() |
||
679 | end |
||
680 | |||
681 | function myBindings:SaveBindings() |
||
682 | -- Save the bindings in the system first. |
||
683 | SaveBindings(GetCurrentBindingSet()) |
||
684 | |||
685 | local commandName, binding1, binding2 |
||
686 | |||
687 | -- Empty the stored bindings first. |
||
688 | self:ClearBinds() |
||
689 | |||
690 | for index = 1, GetNumBindings(), 1 do |
||
691 | commandName, binding1, binding2 = GetBinding(index) |
||
692 | local key1, key2 = GetBindingKey(commandName) |
||
693 | -- Don't save empty bindings |
||
694 | if( binding1 or binding2 ) then |
||
695 | self:SetBind(commandName, {bind1 = binding1, bind2 = binding2}) |
||
696 | end |
||
697 | end |
||
698 | |||
699 | self:CloseInterface() |
||
700 | end |
||
701 | |||
702 | |||
703 | --[[-------------------------------------------------------------------------- |
||
704 | Display Methods |
||
705 | -----------------------------------------------------------------------------]] |
||
706 | |||
707 | function myBindings:UpdateLoadedLabel() |
||
708 | myBindingsOptionsFrameBindingsLoadedLabel:SetText( |
||
709 | format(MYBINDINGS_LABEL_BINDINGS_LOADED, self.profilePath[2]) |
||
710 | ) |
||
711 | end |
||
712 | |||
713 | function myBindings:OpenInterface() |
||
714 | if( self.disabled ) then return; end |
||
715 | |||
716 | if( not self.frame:IsVisible() ) then |
||
717 | ShowUIPanel(self.frame) |
||
718 | self.dontOpenGameMenu = TRUE |
||
719 | self:HeadingsUpdate() |
||
720 | self:BindingsUpdate() |
||
721 | end |
||
722 | end |
||
723 | |||
724 | function myBindings:CloseInterface() |
||
725 | myBindingsOptionsBindingsScrollFrame.selected = nil |
||
726 | HideUIPanel(self.frame) |
||
727 | end |
||
728 | |||
729 | function myBindings:OnShow() |
||
730 | self:HeadingsUpdate() |
||
731 | self:BindingsUpdate() |
||
732 | end |
||
733 | |||
734 | function myBindings:OnHide() |
||
735 | self:CancelKeyBind() |
||
736 | |||
737 | -- Check if it's currently showing an options frame or the myAddOns options frame. |
||
738 | if( (not MYADDONS_ACTIVE_OPTIONSFRAME) and |
||
739 | (not self.dontOpenGameMenu) and |
||
740 | ( (not myAddOnsFrame) or (not myAddOnsFrame:IsVisible())) ) then |
||
741 | ShowUIPanel(GameMenuFrame) |
||
742 | -- Check if the options frame was opened by myAddOns |
||
743 | elseif( MYADDONS_ACTIVE_OPTIONSFRAME == this ) then |
||
744 | ShowUIPanel(myAddOnsFrame) |
||
745 | end |
||
746 | |||
747 | self.dontOpenGameMenu = FALSE |
||
748 | end |
||
749 | |||
750 | --[[-------------------------------------------------------------------------- |
||
751 | Chat Handlers |
||
752 | -----------------------------------------------------------------------------]] |
||
753 | |||
754 | function myBindings:SetCategory(opt) |
||
755 | local header, cat = unpack(ace.ParseWords(opt)) |
||
756 | |||
757 | if( (not header) or (not cat) ) then |
||
758 | self.Error(MYBINDINGS_TEXT_INVALID_ENTRY) |
||
759 | return |
||
760 | elseif( not getglobal("ACE_CATEGORY_"..strupper(cat)) ) then |
||
761 | self.Error(MYBINDINGS_TEXT_CAT_INVALID, cat) |
||
762 | return |
||
763 | end |
||
764 | |||
765 | local try, valid = getglobal("BINDING_HEADER_"..header) |
||
766 | if( try ) then |
||
767 | valid = header |
||
768 | else |
||
769 | try = getglobal("BINDING_HEADER_"..strlower(header)) |
||
770 | if( try ) then |
||
771 | valid = strlower(header) |
||
772 | else |
||
773 | try = getglobal("BINDING_HEADER_"..strupper(header)) |
||
774 | if( try ) then |
||
775 | valid = strupper(header) |
||
776 | else |
||
777 | self.Error(MYBINDINGS_TEXT_HDR_INVALID, header) |
||
778 | return |
||
779 | end |
||
780 | end |
||
781 | end |
||
782 | |||
783 | self:SetCat(valid, cat) |
||
784 | self:ParseBindings() |
||
785 | self.Msg(MYBINDINGS_TEXT_CAT_SET, valid, getglobal("ACE_CATEGORY_"..strupper(cat))) |
||
786 | end |
||
787 | |||
788 | function myBindings:SetBindOpt(opt) |
||
789 | local oldaction = nil |
||
790 | local key, action = unpack(ace.ParseWords(opt)) |
||
791 | key = string.upper(key) |
||
792 | -- Attempt to clear the binding. If this is an invalid key, it'll fail. |
||
793 | oldaction = GetBindingAction( key ) |
||
794 | if not SetBinding(key, nil) then |
||
795 | if not SetBinding(key, oldaction) then |
||
796 | self.cmd:msg( "Error - " .. key .. " is not a valid key!" ) |
||
797 | end |
||
798 | elseif action then |
||
799 | if SetBinding(key, action) then |
||
800 | self.cmd:msg( "Key " .. key .. " successfully bound to action " .. action .. ".") |
||
801 | else |
||
802 | self.cmd:msg( "Action " .. action .. " is not valid!" ) |
||
803 | SetBinding(key, oldaction) |
||
804 | end |
||
805 | else |
||
806 | self.cmd:msg( "Key " .. key .. " cleared." ) |
||
807 | end |
||
808 | end |