Blizzard_BindingUI/Blizzard_BindingUI.lua

Blizzard_BindingUI/Blizzard_BindingUI.lua (8.3.7.35662; unchanged since 8.3.0.33062)
  1. KEY_BINDINGS_DISPLAYED = 21;
  2. KEY_BINDING_HEIGHT = 25;
  3. KEY_BINDING_ROW_NAME = "KeyBindingFrameKeyBinding";
  4. DEFAULT_BINDINGS = 0;
  5. ACCOUNT_BINDINGS = 1;
  6. CHARACTER_BINDINGS = 2;
  7. UIPanelWindows["KeyBindingFrame"] = { area = "center", pushable = 0, whileDead = 1 };
  8. StaticPopupDialogs["CONFIRM_DELETING_CHARACTER_SPECIFIC_BINDINGS"] = {
  9. text = CONFIRM_DELETING_CHARACTER_SPECIFIC_BINDINGS,
  10. button1 = OKAY,
  11. button2 = CANCEL,
  12. OnAccept = function(self)
  13. SaveBindings(KeyBindingFrame.which);
  14. KeyBindingFrame.outputText:SetText("");
  15. KeyBindingFrame_SetSelected(nil);
  16. HideUIPanel(KeyBindingFrame);
  17. CONFIRMED_DELETING_CHARACTER_SPECIFIC_BINDINGS = 1;
  18. end,
  19. timeout = 0,
  20. whileDead = 1,
  21. showAlert = 1,
  22. };
  23. StaticPopupDialogs["CONFIRM_LOSE_BINDING_CHANGES"] = {
  24. text = CONFIRM_LOSE_BINDING_CHANGES,
  25. button1 = OKAY,
  26. button2 = CANCEL,
  27. OnAccept = function(self)
  28. KeyBindingFrame_ChangeBindingProfile();
  29. KeyBindingFrame.bindingsChanged = nil;
  30. end,
  31. OnCancel = function(self)
  32. if ( KeyBindingFrame.characterSpecificButton:GetChecked() ) then
  33. KeyBindingFrame.characterSpecificButton:SetChecked();
  34. else
  35. KeyBindingFrame.characterSpecificButton:SetChecked(true);
  36. end
  37. end,
  38. timeout = 0,
  39. whileDead = 1,
  40. showAlert = 1,
  41. };
  42. StaticPopupDialogs["CONFIRM_RESET_TO_DEFAULT_KEYBINDINGS"] = {
  43. text = CONFIRM_RESET_KEYBINDINGS,
  44. button1 = OKAY,
  45. button2 = CANCEL,
  46. OnAccept = function(self)
  47. KeyBindingFrame_ResetBindingsToDefault();
  48. end,
  49. timeout = 0,
  50. whileDead = 1,
  51. showAlert = 1
  52. };
  53. function KeyBindingFrame_OnLoad(self)
  54. self:RegisterForClicks("AnyUp");
  55. KeyBindingFrame.scrollOffset = 0;
  56. KeyBindingFrame_SetSelected(nil);
  57. KeyBindingFrame_LoadCategories(self);
  58. KeyBindingFrame_LoadKeyBindingButtons(self);
  59. self:RegisterEvent("ADDON_LOADED");
  60. end
  61. function KeyBindingFrame_OnEvent(self, event, ...)
  62. if (event == "ADDON_LOADED") then
  63. KeyBindingFrame_LoadCategories(self);
  64. end
  65. end
  66. local defaultCategories = { BINDING_HEADER_MOVEMENT,
  67. BINDING_HEADER_CHAT,
  68. BINDING_HEADER_ACTIONBAR,
  69. BINDING_HEADER_MULTIACTIONBAR,
  70. BINDING_HEADER_TARGETING,
  71. BINDING_HEADER_INTERFACE,
  72. BINDING_HEADER_MISC,
  73. BINDING_HEADER_CAMERA,
  74. BINDING_HEADER_RAID_TARGET,
  75. BINDING_HEADER_VEHICLE,
  76. BINDING_HEADER_DEBUG,
  77. BINDING_HEADER_MOVIE_RECORDING_SECTION };
  78. function KeyBindingFrame_LoadCategories(self)
  79. local keyBindingCategories = {};
  80. local otherCategory = nil;
  81. OptionsList_ClearSelection(KeyBindingFrame.categoryList, KeyBindingFrame.categoryList.buttons);
  82. for i = 1, GetNumBindings() do
  83. local commandName, category, binding1, binding2 = GetBinding(i, self.mode);
  84. if ( not category ) then
  85. --If there is no category name for the category of this keyBinding, put this
  86. --keyBinding into the default "Other" category.
  87. category = BINDING_HEADER_OTHER;
  88. otherCategory = otherCategory or {};
  89. tinsert(otherCategory, i);
  90. else
  91. --Check for global string values for category names.
  92. category = _G[category] or category;
  93. keyBindingCategories[category] = keyBindingCategories[category] or {};
  94. tinsert(keyBindingCategories[category], i);
  95. end
  96. end
  97. local categoryButtons = self.categoryList.buttons;
  98. local nextCategory = 1;
  99. for i = 1, #defaultCategories do
  100. local categoryName = defaultCategories[i];
  101. if ( keyBindingCategories[categoryName] ~= nil ) then
  102. local element = { ["name"] = categoryName, ["category"] = keyBindingCategories[categoryName] };
  103. OptionsList_DisplayButton(categoryButtons[nextCategory], element);
  104. keyBindingCategories[categoryName] = nil;
  105. nextCategory = nextCategory + 1;
  106. end
  107. end
  108. for key, value in pairs(keyBindingCategories) do
  109. if ( nextCategory < #categoryButtons ) then
  110. local element = { ["name"] = key, ["category"] = keyBindingCategories[key] };
  111. OptionsList_DisplayButton(categoryButtons[nextCategory], element);
  112. nextCategory = nextCategory + 1;
  113. end
  114. end
  115. if ( otherCategory ) then
  116. local element = { ["name"] = BINDING_HEADER_OTHER, ["category"] = otherCategory };
  117. OptionsList_DisplayButton(categoryButtons[nextCategory], element);
  118. nextCategory = nextCategory + 1;
  119. end
  120. for i = nextCategory, #categoryButtons do
  121. OptionsList_HideButton(categoryButtons[i]);
  122. end
  123. local defaultButton = categoryButtons[1];
  124. self.cntCategory = defaultButton.element.category;
  125. OptionsList_SelectButton(defaultButton:GetParent(), defaultButton);
  126. end
  127. function KeyBindingFrame_LoadKeyBindingButtons(self)
  128. local previousRow = CreateFrame("FRAME", KEY_BINDING_ROW_NAME.."1", KeyBindingFrame, "KeyBindingFrameBindingTemplate");
  129. previousRow:SetPoint("TOP", 100, -78);
  130. previousRow.key1Button.buttonIndex = 1;
  131. previousRow.key1Button.rowIndex = 1;
  132. previousRow.key2Button.buttonIndex = 2;
  133. previousRow.key2Button.rowIndex = 1;
  134. self.keyBindingRows = { previousRow };
  135. for i = 2, KEY_BINDINGS_DISPLAYED do
  136. local newRow = CreateFrame("FRAME", KEY_BINDING_ROW_NAME..i, KeyBindingFrame, "KeyBindingFrameBindingTemplate");
  137. newRow:SetPoint("TOP", previousRow, "BOTTOM", 0, 2);
  138. newRow.key1Button.buttonIndex = 1;
  139. newRow.key1Button.rowIndex = i;
  140. newRow.key2Button.buttonIndex = 2;
  141. newRow.key2Button.rowIndex = i;
  142. self.keyBindingRows[i] = newRow;
  143. previousRow = newRow;
  144. end
  145. end
  146. function KeyBindingFrame_OnShow(self)
  147. KeyBindingFrame.mode = 1;
  148. KeyBindingFrame_Update();
  149. -- Update character button
  150. KeyBindingFrame.characterSpecificButton:SetChecked(GetCurrentBindingSet() == 2);
  151. KeyBindingFrame_UpdateHeaderText();
  152. -- Reset bindingsChanged
  153. KeyBindingFrame.bindingsChanged = nil;
  154. Disable_BagButtons();
  155. UpdateMicroButtons();
  156. end
  157. local function CreatePushToTalkBindingButton()
  158. local button;
  159. local handler = CustomBindingHandler:CreateHandler(Enum.CustomBindingType.VoicePushToTalk);
  160. handler:SetOnBindingModeActivatedCallback(function(isActive)
  161. if isActive then
  162. KeyBindingFrame.buttonPressed = button;
  163. KeyBindingFrame_SetSelected("TOGGLE_VOICE_PUSH_TO_TALK", button);
  164. KeyBindingFrame_UpdateUnbindKey();
  165. KeyBindingFrame.outputText:SetFormattedText(BIND_KEY_TO_COMMAND, GetBindingName("TOGGLE_VOICE_PUSH_TO_TALK"));
  166. end
  167. end);
  168. handler:SetOnBindingCompletedCallback(function(completedSuccessfully, keys)
  169. KeyBindingFrame_SetSelected(nil);
  170. if completedSuccessfully then
  171. KeyBindingFrame.outputText:SetText(KEY_BOUND);
  172. else
  173. KeyBindingFrame.outputText:SetText("");
  174. end
  175. if completedSuccessfully and keys then
  176. DisplayUniversalAccessDialogIfRequiredForVoiceChatKeybind(keys);
  177. end
  178. end);
  179. button = CustomBindingManager:RegisterHandlerAndCreateButton(handler, "CustomBindingButtonTemplate", KeyBindingFrame);
  180. return button;
  181. end
  182. local customKeybindings = {};
  183. local function GetOrCreateCustomKeybindingButton(customBindingType)
  184. local button = customKeybindings[customBindingType]
  185. if not button then
  186. if customBindingType == Enum.CustomBindingType.VoicePushToTalk then
  187. button = CreatePushToTalkBindingButton();
  188. end
  189. customKeybindings[customBindingType] = button;
  190. end
  191. return button;
  192. end
  193. local function HideAllCustomButtons()
  194. for customBindingType, button in pairs(customKeybindings) do
  195. button:Hide();
  196. end
  197. end
  198. local function HandleCustomKeybindingsDismissed(shouldSave)
  199. for customBindingType in pairs(customKeybindings) do
  200. CustomBindingManager:OnDismissed(customBindingType, shouldSave);
  201. end
  202. end
  203. function KeyBindingFrame_Update()
  204. local self = KeyBindingFrame;
  205. local cntCategory = self.cntCategory;
  206. local numBindings = #cntCategory;
  207. local keyOffset = FauxScrollFrame_GetOffset(KeyBindingFrameScrollFrame);
  208. if ( self.selected ) then
  209. local offsetDifference = self.scrollOffset - keyOffset;
  210. if ( offsetDifference ~= 0 ) then
  211. self.selectedRowIndex = self.selectedRowIndex + offsetDifference;
  212. if ( self.selectedRowIndex > 0 and self.selectedRowIndex <= #self.keyBindingRows ) then
  213. local button;
  214. if ( self.selectedButtonIndex == 1 ) then
  215. button = self.keyBindingRows[self.selectedRowIndex].key1Button;
  216. else
  217. button = self.keyBindingRows[self.selectedRowIndex].key2Button;
  218. end
  219. KeyBindingFrame_SetSelected(self.selected, button);
  220. else
  221. KeyBindingFrame_SetSelected(self.selected, nil);
  222. end
  223. end
  224. end
  225. HideAllCustomButtons();
  226. self.scrollOffset = keyOffset;
  227. for i=1, KEY_BINDINGS_DISPLAYED, 1 do
  228. keyOffset = keyOffset + 1;
  229. local keyBindingRow = self.keyBindingRows[i];
  230. if ( keyOffset <= numBindings ) then
  231. local keyBindingButton1 = keyBindingRow.key1Button;
  232. local keyBindingButton2 = keyBindingRow.key2Button;
  233. local keyBindingDescription = keyBindingRow.description;
  234. -- Set binding text
  235. local commandName, category, binding1, binding2 = GetBinding(cntCategory[keyOffset], self.mode);
  236. local customBindingType = C_KeyBindings.GetCustomBindingType(cntCategory[keyOffset]);
  237. local customButton = customBindingType and GetOrCreateCustomKeybindingButton(customBindingType);
  238. local headerText = keyBindingRow.header;
  239. local isHeader = strsub(commandName, 1, 6) == "HEADER";
  240. headerText:SetShown(isHeader);
  241. keyBindingButton1:SetShown(not isHeader and not customButton);
  242. keyBindingButton2:SetShown(not isHeader);
  243. keyBindingButton2:SetEnabled(not customButton);
  244. keyBindingDescription:SetShown(not isHeader);
  245. keyBindingButton1.commandName = commandName;
  246. keyBindingButton2.commandName = commandName;
  247. if ( isHeader ) then
  248. headerText:SetText(_G["BINDING_"..commandName]);
  249. else
  250. if customBindingType ~= nil then
  251. binding1, binding2 = nil, nil;
  252. end
  253. BindingButtonTemplate_SetupBindingButton(binding1, keyBindingButton1);
  254. BindingButtonTemplate_SetupBindingButton(binding2, keyBindingButton2);
  255. keyBindingDescription:SetText(GetBindingName(commandName));
  256. keyBindingRow:Show();
  257. if customButton then
  258. BindingButtonTemplate_SetupBindingButton(nil, customButton);
  259. customButton:ClearAllPoints();
  260. customButton:SetAllPoints(keyBindingButton1);
  261. customButton:Show();
  262. end
  263. end
  264. else
  265. keyBindingRow:Hide();
  266. end
  267. end
  268. -- Scroll frame stuff
  269. FauxScrollFrame_Update(KeyBindingFrameScrollFrame, numBindings, KEY_BINDINGS_DISPLAYED, KEY_BINDING_HEIGHT );
  270. -- Update Unbindkey button
  271. KeyBindingFrame_UpdateUnbindKey();
  272. end
  273. function KeyBindingFrame_OnHide(self)
  274. ShowUIPanel(GameMenuFrame);
  275. KeyBindingFrame.outputText:SetText("");
  276. PlaySound(SOUNDKIT.GS_TITLE_OPTION_EXIT);
  277. UpdateMicroButtons();
  278. end
  279. function KeyBindingFrame_UnbindKey(keyPressed, selectedAction, bindingMode)
  280. local keyBindMessage;
  281. local oldAction = GetBindingAction(keyPressed, bindingMode);
  282. if oldAction ~= "" and oldAction ~= selectedAction then
  283. local key1, key2 = GetBindingKey(oldAction, bindingMode);
  284. if (not key1 or key1 == keyPressed) and (not key2 or key2 == keyPressed) then
  285. --Notification message
  286. keyBindMessage = KEY_UNBOUND_ERROR:format(GetBindingName(oldAction))
  287. KeyBindingFrame.outputText:SetText(keyBindMessage);
  288. end
  289. end
  290. SetBinding(keyPressed, nil, bindingMode);
  291. return keyBindMessage;
  292. end
  293. local function ClearBindingsForKeys(bindingMode, ...)
  294. for i = 1, select("#", ...) do
  295. local key = select(i, ...);
  296. if key then
  297. SetBinding(key, nil, bindingMode);
  298. end
  299. end
  300. end
  301. local function RebindKeysInOrder(keyPressed, keybindButtonID, selectedAction, bindingMode, ...)
  302. local keyBindMessage;
  303. for i = 1, select("#", ...) do
  304. local currentKey = select(i, ...);
  305. local keyToBind = (i == keybindButtonID) and keyPressed or currentKey;
  306. if keyToBind then
  307. keyBindMessage = KeyBindingFrame_SetBinding(keyToBind, selectedAction, bindingMode, currentKey) or keyBindMessage;
  308. end
  309. end
  310. return keyBindMessage;
  311. end
  312. -- NOTE: preventKeybindingFrameBehavior being true indicates that all the code specific to the keybind frame shouldn't be run.
  313. -- The default behavior is to be called from the keybinding frame.
  314. -- This function returns true if it tried to bind something, and false otherwise. Its secondary return is a feedback/status message.
  315. function KeyBindingFrame_AttemptKeybind(self, keyOrButton, selectedAction, bindingMode, keybindButtonID, preventKeybindingFrameBehavior)
  316. local keyBindFeedbackMessage;
  317. local wasSomethingBound = false;
  318. if GetBindingFromClick(keyOrButton) == "SCREENSHOT" then
  319. RunBinding("SCREENSHOT");
  320. elseif selectedAction then
  321. local keyPressed = GetConvertedKeyOrButton(keyOrButton);
  322. if not IsKeyPressIgnoredForBinding(keyPressed) then
  323. keyPressed = CreateKeyChordString(keyPressed);
  324. -- Unbind the current action
  325. local key1, key2 = GetBindingKey(selectedAction, bindingMode)
  326. ClearBindingsForKeys(bindingMode, key1, key2);
  327. -- Unbind the current key and rebind current action
  328. if not preventKeybindingFrameBehavior then
  329. keyBindFeedbackMessage = KEY_BOUND;
  330. KeyBindingFrame.outputText:SetText(KEY_BOUND);
  331. end
  332. keyBindFeedbackMessage = KeyBindingFrame_UnbindKey(keyPressed, selectedAction, bindingMode) or keyBindFeedbackMessage;
  333. local rebindingMessage = RebindKeysInOrder(keyPressed, keybindButtonID, selectedAction, bindingMode, key1, key2);
  334. if not keyBindFeedbackMessage then
  335. keyBindFeedbackMessage = rebindingMessage;
  336. end
  337. if not preventKeybindingFrameBehavior then
  338. KeyBindingFrame_Update();
  339. -- Button highlighting stuff
  340. KeyBindingFrame_SetSelected(nil);
  341. KeyBindingFrame.buttonPressed:UnlockHighlight();
  342. KeyBindingFrame.bindingsChanged = 1;
  343. KeyBindingFrame_UpdateUnbindKey();
  344. end
  345. wasSomethingBound = true;
  346. end
  347. elseif (not preventKeybindingFrameBehavior) and GetBindingFromClick(keyOrButton) == "TOGGLEGAMEMENU" then
  348. KeyBindingFrame_CancelBinding(self);
  349. end
  350. return wasSomethingBound, keyBindFeedbackMessage;
  351. end
  352. function KeyBindingFrame_OnKeyDown(self, keyOrButton)
  353. return KeyBindingFrame_AttemptKeybind(self, keyOrButton, KeyBindingFrame.selected, KeyBindingFrame.mode, KeyBindingFrame.keyID);
  354. end
  355. function KeyBindingFrame_SetBinding(key, selectedAction, bindingMode, oldKey)
  356. local keyBindMessage;
  357. if not SetBinding(key, selectedAction, bindingMode) then
  358. if oldKey then
  359. SetBinding(oldKey, selectedAction, bindingMode);
  360. end
  361. --Error message
  362. keyBindMessage = KEYBINDINGFRAME_MOUSEWHEEL_ERROR;
  363. KeyBindingFrame.outputText:SetText(keyBindMessage);
  364. end
  365. return keyBindMessage;
  366. end
  367. function KeyBindingFrame_UpdateUnbindKey()
  368. if ( KeyBindingFrame.selected ) then
  369. KeyBindingFrame.unbindButton:Enable();
  370. else
  371. KeyBindingFrame.unbindButton:Disable();
  372. end
  373. end
  374. function KeyBindingFrame_UpdateHeaderText()
  375. if ( KeyBindingFrame.characterSpecificButton:GetChecked() ) then
  376. KeyBindingFrame.Header:Setup(CHARACTER_KEY_BINDINGS:format(UnitName("player")));
  377. else
  378. KeyBindingFrame.Header:Setup(KEY_BINDINGS);
  379. end
  380. end
  381. function KeyBindingFrame_ChangeBindingProfile()
  382. if ( KeyBindingFrame.characterSpecificButton:GetChecked() ) then
  383. LoadBindings(CHARACTER_BINDINGS);
  384. else
  385. LoadBindings(ACCOUNT_BINDINGS);
  386. end
  387. KeyBindingFrame_UpdateHeaderText();
  388. KeyBindingFrame.outputText:SetText("");
  389. KeyBindingFrame_SetSelected(nil);
  390. KeyBindingFrame_Update();
  391. end
  392. function KeyBindingFrame_SetSelected(value, keyBindingButton)
  393. local previousButton = KeyBindingFrame.selectedButton;
  394. KeyBindingFrame.selectedButton = nil;
  395. KeyBindingFrame.selected = value;
  396. if previousButton then
  397. BindingButtonTemplate_SetSelected(previousButton, false);
  398. if previousButton.GetCustomBindingType and previousButton:GetCustomBindingType() ~= nil then
  399. previousButton:CancelBinding();
  400. end
  401. end
  402. if keyBindingButton then
  403. BindingButtonTemplate_SetSelected(keyBindingButton, true);
  404. KeyBindingFrame.selectedButton = keyBindingButton;
  405. KeyBindingFrame.selectedButtonIndex = keyBindingButton.buttonIndex;
  406. KeyBindingFrame.selectedRowIndex = keyBindingButton.rowIndex;
  407. end
  408. end
  409. function KeyBindingFrame_OnMouseWheel(self, delta)
  410. if ( self.selected ) then
  411. if ( delta > 0 ) then
  412. KeyBindingFrame_OnKeyDown(self, "MOUSEWHEELUP");
  413. else
  414. KeyBindingFrame_OnKeyDown(self, "MOUSEWHEELDOWN");
  415. end
  416. end
  417. end
  418. function KeyBindingButton_OnClick(self, button)
  419. PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
  420. if ( KeyBindingFrame.selected ) then
  421. -- Code to be able to deselect or select another key to bind
  422. if ( button == "LeftButton" or button == "RightButton" ) then
  423. -- Deselect button if it was the pressed previously pressed
  424. if (KeyBindingFrame.buttonPressed == self) then
  425. KeyBindingFrame_SetSelected(nil);
  426. KeyBindingFrame.outputText:SetText("");
  427. else
  428. -- Select a different button
  429. KeyBindingFrame.buttonPressed = self;
  430. KeyBindingFrame_SetSelected(self.commandName, self);
  431. KeyBindingFrame.keyID = self:GetID();
  432. KeyBindingFrame.outputText:SetFormattedText(BIND_KEY_TO_COMMAND, GetBindingName(self.commandName));
  433. end
  434. KeyBindingFrame_Update();
  435. return;
  436. end
  437. KeyBindingFrame_OnKeyDown(self, button);
  438. else
  439. if (KeyBindingFrame.buttonPressed) then
  440. KeyBindingFrame.buttonPressed:UnlockHighlight();
  441. end
  442. KeyBindingFrame.buttonPressed = self;
  443. KeyBindingFrame_SetSelected(self.commandName, self);
  444. KeyBindingFrame.keyID = self:GetID();
  445. KeyBindingFrame.outputText:SetFormattedText(BIND_KEY_TO_COMMAND, GetBindingName(self.commandName));
  446. KeyBindingFrame_Update();
  447. end
  448. KeyBindingFrame_UpdateUnbindKey();
  449. end
  450. function KeybindingsCategoryListButton_OnClick(self, button)
  451. PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
  452. OptionsList_ClearSelection(KeyBindingFrame.categoryList, KeyBindingFrame.categoryList.buttons);
  453. OptionsList_SelectButton(self:GetParent(), self);
  454. KeyBindingFrame.cntCategory = self.element.category;
  455. KeyBindingFrame_SetSelected(nil);
  456. KeyBindingFrame.outputText:SetText("");
  457. KeyBindingFrameScrollFrame.ScrollBar:SetValue(0);
  458. KeyBindingFrame_Update();
  459. end
  460. function CharacterSpecificButton_OnLoad(self)
  461. self.text:SetText(HIGHLIGHT_FONT_COLOR_CODE..CHARACTER_SPECIFIC_KEYBINDINGS..FONT_COLOR_CODE_CLOSE);
  462. end
  463. function CharacterSpecificButton_OnClick(self)
  464. if (self.enabled) then
  465. PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
  466. else
  467. PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_OFF);
  468. end
  469. if ( KeyBindingFrame.bindingsChanged ) then
  470. StaticPopup_Show("CONFIRM_LOSE_BINDING_CHANGES");
  471. else
  472. KeyBindingFrame_ChangeBindingProfile();
  473. end
  474. end
  475. function CharacterSpecificButton_OnEnter(self)
  476. GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
  477. GameTooltip:SetText(CHARACTER_SPECIFIC_KEYBINDING_TOOLTIP, nil, nil, nil, nil, true);
  478. end
  479. function CharacterSpecificButton_OnHide(self)
  480. GameTooltip_Hide();
  481. end
  482. function UnbindButton_OnClick(self)
  483. PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
  484. local button = KeyBindingFrame.selectedButton;
  485. local customBindingType = button.GetCustomBindingType and button:GetCustomBindingType();
  486. if customBindingType ~= nil then
  487. CustomBindingManager:Unbind(customBindingType);
  488. BindingButtonTemplate_SetupBindingButton(nil, button);
  489. else
  490. local key1, key2 = GetBindingKey(KeyBindingFrame.selected, KeyBindingFrame.mode);
  491. if ( key1 ) then
  492. SetBinding(key1, nil, KeyBindingFrame.mode);
  493. end
  494. if ( key2 ) then
  495. SetBinding(key2, nil, KeyBindingFrame.mode);
  496. end
  497. if ( key1 and KeyBindingFrame.keyID == 1 ) then
  498. KeyBindingFrame_SetBinding(key1, nil, KeyBindingFrame.mode, key1);
  499. if ( key2 ) then
  500. KeyBindingFrame_SetBinding(key2, KeyBindingFrame.selected, KeyBindingFrame.mode, key2);
  501. end
  502. else
  503. if ( key1 ) then
  504. KeyBindingFrame_SetBinding(key1, KeyBindingFrame.selected, KeyBindingFrame.mode);
  505. end
  506. if ( key2 ) then
  507. KeyBindingFrame_SetBinding(key2, nil, KeyBindingFrame.mode, key2);
  508. end
  509. end
  510. end
  511. KeyBindingFrame_Update();
  512. -- Button highlighting stuff
  513. KeyBindingFrame_SetSelected(nil);
  514. KeyBindingFrame.buttonPressed:UnlockHighlight();
  515. KeyBindingFrame_UpdateUnbindKey();
  516. KeyBindingFrame.outputText:SetText("");
  517. end
  518. function OkayButton_OnClick(self)
  519. if ( KeyBindingFrame.characterSpecificButton:GetChecked() ) then
  520. KeyBindingFrame.which = CHARACTER_BINDINGS;
  521. else
  522. KeyBindingFrame.which = ACCOUNT_BINDINGS;
  523. if ( GetCurrentBindingSet() == CHARACTER_BINDINGS ) then
  524. if ( not CONFIRMED_DELETING_CHARACTER_SPECIFIC_BINDINGS ) then
  525. StaticPopup_Show("CONFIRM_DELETING_CHARACTER_SPECIFIC_BINDINGS");
  526. return;
  527. end
  528. end
  529. end
  530. SaveBindings(KeyBindingFrame.which);
  531. KeyBindingFrame.outputText:SetText("");
  532. KeyBindingFrame_SetSelected(nil);
  533. HideUIPanel(KeyBindingFrame);
  534. local shouldSave = true;
  535. HandleCustomKeybindingsDismissed(shouldSave);
  536. end
  537. function CancelButton_OnClick(self)
  538. KeyBindingFrame_CancelBinding(self);
  539. local shouldSave = false;
  540. HandleCustomKeybindingsDismissed(shouldSave);
  541. end
  542. function DefaultsButton_OnClick(self)
  543. StaticPopup_Show("CONFIRM_RESET_TO_DEFAULT_KEYBINDINGS");
  544. end
  545. function KeyBindingFrame_CancelBinding(self)
  546. LoadBindings(GetCurrentBindingSet());
  547. KeyBindingFrame.outputText:SetText("");
  548. KeyBindingFrame_SetSelected(nil);
  549. HideUIPanel(KeyBindingFrame);
  550. end
  551. function KeyBindingFrame_ResetBindingsToDefault()
  552. PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
  553. LoadBindings(DEFAULT_BINDINGS);
  554. KeyBindingFrame.outputText:SetText("");
  555. KeyBindingFrame_SetSelected(nil);
  556. KeyBindingFrame_Update();
  557. end