Blizzard_BindingUI/Blizzard_BindingUI.lua

Blizzard_BindingUI/Blizzard_BindingUI.lua (9.0.2.37474; unchanged since 9.0.2.36665)
  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() KeyBindingFrame:CharacterSpecificPopupAccept() end,
  13. timeout = 0,
  14. whileDead = 1,
  15. showAlert = 1,
  16. };
  17. StaticPopupDialogs["CONFIRM_LOSE_BINDING_CHANGES_CHARACTER_SPECIFIC"] = {
  18. text = CONFIRM_LOSE_BINDING_CHANGES_CHARACTER_SPECIFIC,
  19. button1 = OKAY,
  20. button2 = CANCEL,
  21. OnAccept = function() KeyBindingFrame:LoseBindingsPopupAccept() end,
  22. OnCancel = KeybindsFrames_LoseBindingsPopupCancel,
  23. timeout = 0,
  24. whileDead = 1,
  25. showAlert = 1,
  26. };
  27. StaticPopupDialogs["CONFIRM_RESET_TO_DEFAULT_KEYBINDINGS"] = {
  28. text = CONFIRM_RESET_KEYBINDINGS,
  29. button1 = OKAY,
  30. button2 = CANCEL,
  31. OnAccept = function() KeyBindingFrame:ResetBindingsPopupAccept() end,
  32. timeout = 0,
  33. whileDead = 1,
  34. showAlert = 1,
  35. };
  36. StaticPopupDialogs["CONFIRM_RESET_TO_PREVIOUS_KEYBINDINGS"] = {
  37. text = CONFIRM_RESET_TO_PREVIOUS_KEYBINDINGS,
  38. button1 = OKAY,
  39. button2 = CANCEL,
  40. OnAccept = function() LoadBindings(GetCurrentBindingSet()) end,
  41. timeout = 0,
  42. whileDead = 1,
  43. showAlert = 1,
  44. };
  45. local function KeybindFrames_SetOutputText(...)
  46. KeyBindingFrame.outputText:SetFormattedText(...);
  47. QuickKeybindFrame.outputText:SetFormattedText(...);
  48. end
  49. local function KeybindFrames_ClearOutputText()
  50. KeyBindingFrame.outputText:SetText("");
  51. QuickKeybindFrame.outputText:SetText("");
  52. end
  53. local function KeybindsFrames_LoseBindingsPopupCancel()
  54. local newChecked = not KeyBindingFrame.characterSpecificButton:GetChecked();
  55. KeyBindingFrame.characterSpecificButton:SetChecked(newChecked);
  56. QuickKeybindFrame.characterSpecificButton:SetChecked(newChecked);
  57. end
  58. KeyBindingFrameMixin = {};
  59. function KeyBindingFrameMixin:OnLoad()
  60. self:RegisterForClicks("AnyUp");
  61. self.scrollOffset = 0;
  62. self:SetSelected(nil);
  63. self:LoadCategories();
  64. self:LoadKeyBindingButtons();
  65. self:RegisterEvent("ADDON_LOADED");
  66. end
  67. function KeyBindingFrameMixin:OnEvent(event, ...)
  68. if (event == "ADDON_LOADED") then
  69. self:LoadCategories();
  70. end
  71. end
  72. local defaultCategories = { BINDING_HEADER_MOVEMENT,
  73. BINDING_HEADER_CHAT,
  74. BINDING_HEADER_ACTIONBAR,
  75. BINDING_HEADER_MULTIACTIONBAR,
  76. BINDING_HEADER_TARGETING,
  77. BINDING_HEADER_INTERFACE,
  78. BINDING_HEADER_MISC,
  79. BINDING_HEADER_CAMERA,
  80. BINDING_HEADER_RAID_TARGET,
  81. BINDING_HEADER_VEHICLE,
  82. BINDING_HEADER_DEBUG,
  83. BINDING_HEADER_MOVIE_RECORDING_SECTION };
  84. function KeyBindingFrameMixin:LoadCategories()
  85. local keyBindingCategories = {};
  86. local otherCategory = nil;
  87. OptionsList_ClearSelection(self.categoryList, self.categoryList.buttons);
  88. for i = 1, GetNumBindings() do
  89. local commandName, category, binding1, binding2 = GetBinding(i, self.mode);
  90. if ( not category ) then
  91. --If there is no category name for the category of this keyBinding, put this
  92. --keyBinding into the default "Other" category.
  93. category = BINDING_HEADER_OTHER;
  94. otherCategory = otherCategory or {};
  95. tinsert(otherCategory, i);
  96. else
  97. --Check for global string values for category names.
  98. category = _G[category] or category;
  99. keyBindingCategories[category] = keyBindingCategories[category] or {};
  100. tinsert(keyBindingCategories[category], i);
  101. end
  102. end
  103. local categoryButtons = self.categoryList.buttons;
  104. local nextCategory = 1;
  105. for i = 1, #defaultCategories do
  106. local categoryName = defaultCategories[i];
  107. if ( keyBindingCategories[categoryName] ~= nil ) then
  108. local element = { ["name"] = categoryName, ["category"] = keyBindingCategories[categoryName] };
  109. OptionsList_DisplayButton(categoryButtons[nextCategory], element);
  110. keyBindingCategories[categoryName] = nil;
  111. nextCategory = nextCategory + 1;
  112. end
  113. end
  114. for key, value in pairs(keyBindingCategories) do
  115. if ( nextCategory < #categoryButtons ) then
  116. local element = { ["name"] = key, ["category"] = keyBindingCategories[key] };
  117. OptionsList_DisplayButton(categoryButtons[nextCategory], element);
  118. nextCategory = nextCategory + 1;
  119. end
  120. end
  121. if ( otherCategory ) then
  122. local element = { ["name"] = BINDING_HEADER_OTHER, ["category"] = otherCategory };
  123. OptionsList_DisplayButton(categoryButtons[nextCategory], element);
  124. nextCategory = nextCategory + 1;
  125. end
  126. for i = nextCategory, #categoryButtons do
  127. OptionsList_HideButton(categoryButtons[i]);
  128. end
  129. local defaultButton = categoryButtons[1];
  130. self.cntCategory = defaultButton.element.category;
  131. OptionsList_SelectButton(defaultButton:GetParent(), defaultButton);
  132. end
  133. function KeyBindingFrameMixin:LoadKeyBindingButtons()
  134. local previousRow = CreateFrame("FRAME", KEY_BINDING_ROW_NAME.."1", self, "KeyBindingFrameBindingTemplate");
  135. previousRow:InitializeButtons(1);
  136. previousRow:SetPoint("TOP", 100, -78);
  137. self.keyBindingRows = { previousRow };
  138. for i = 2, KEY_BINDINGS_DISPLAYED do
  139. local newRow = CreateFrame("FRAME", KEY_BINDING_ROW_NAME..i, self, "KeyBindingFrameBindingTemplate");
  140. newRow:InitializeButtons(i);
  141. newRow:SetPoint("TOP", previousRow, "BOTTOM", 0, 2);
  142. self.keyBindingRows[i] = newRow;
  143. previousRow = newRow;
  144. end
  145. end
  146. function KeyBindingFrameMixin:OnShow()
  147. self.mode = 1;
  148. self:Update();
  149. -- Update character button
  150. self.characterSpecificButton:SetChecked(GetCurrentBindingSet() == 2);
  151. self:UpdateHeaderText();
  152. -- Reset bindingsChanged
  153. self.bindingsChanged = nil;
  154. self.inQuickKeybind = false;
  155. Disable_BagButtons();
  156. UpdateMicroButtons();
  157. end
  158. local function CreatePushToTalkBindingButton()
  159. local button;
  160. local handler = CustomBindingHandler:CreateHandler(Enum.CustomBindingType.VoicePushToTalk);
  161. handler:SetOnBindingModeActivatedCallback(function(isActive)
  162. if isActive then
  163. KeyBindingFrame.buttonPressed = button;
  164. KeyBindingFrame:SetSelected("TOGGLE_VOICE_PUSH_TO_TALK", button);
  165. KeyBindingFrame:UpdateUnbindKey();
  166. KeybindFrames_SetOutputText(BIND_KEY_TO_COMMAND, GetBindingName("TOGGLE_VOICE_PUSH_TO_TALK"));
  167. end
  168. end);
  169. handler:SetOnBindingCompletedCallback(function(completedSuccessfully, keys)
  170. KeyBindingFrame:SetSelected(nil);
  171. if completedSuccessfully then
  172. KeybindFrames_SetOutputText(KEY_BOUND);
  173. else
  174. KeybindFrames_ClearOutputText();
  175. end
  176. if completedSuccessfully and keys then
  177. DisplayUniversalAccessDialogIfRequiredForVoiceChatKeybind(keys);
  178. end
  179. end);
  180. button = CustomBindingManager:RegisterHandlerAndCreateButton(handler, "CustomBindingButtonTemplate", KeyBindingFrame);
  181. return button;
  182. end
  183. local customKeybindings = {};
  184. local function GetOrCreateCustomKeybindingButton(customBindingType)
  185. local button = customKeybindings[customBindingType]
  186. if not button then
  187. if customBindingType == Enum.CustomBindingType.VoicePushToTalk then
  188. button = CreatePushToTalkBindingButton();
  189. end
  190. customKeybindings[customBindingType] = button;
  191. end
  192. return button;
  193. end
  194. local function HideAllCustomButtons()
  195. for customBindingType, button in pairs(customKeybindings) do
  196. button:Hide();
  197. end
  198. end
  199. local function HandleCustomKeybindingsDismissed(shouldSave)
  200. for customBindingType in pairs(customKeybindings) do
  201. CustomBindingManager:OnDismissed(customBindingType, shouldSave);
  202. end
  203. end
  204. function KeyBindingFrameMixin:Update()
  205. local numBindings = #self.cntCategory;
  206. local keyOffset = FauxScrollFrame_GetOffset(self.scrollFrame);
  207. if ( self.selected ) then
  208. local offsetDifference = self.scrollOffset - keyOffset;
  209. if ( offsetDifference ~= 0 ) then
  210. self.selectedRowIndex = self.selectedRowIndex + offsetDifference;
  211. if ( self.selectedRowIndex > 0 and self.selectedRowIndex <= #self.keyBindingRows ) then
  212. local button;
  213. if ( self.selectedButtonIndex == 1 ) then
  214. button = self.keyBindingRows[self.selectedRowIndex].key1Button;
  215. else
  216. button = self.keyBindingRows[self.selectedRowIndex].key2Button;
  217. end
  218. self:SetSelected(self.selected, button);
  219. else
  220. self:SetSelected(self.selected, nil);
  221. end
  222. end
  223. end
  224. HideAllCustomButtons();
  225. self.scrollOffset = keyOffset;
  226. for i=1, KEY_BINDINGS_DISPLAYED, 1 do
  227. keyOffset = keyOffset + 1;
  228. local keyBindingRow = self.keyBindingRows[i];
  229. if ( keyOffset <= numBindings ) then
  230. keyBindingRow:Update(keyOffset);
  231. else
  232. keyBindingRow:Hide();
  233. end
  234. end
  235. -- Scroll frame stuff
  236. FauxScrollFrame_Update(self.scrollFrame, numBindings, KEY_BINDINGS_DISPLAYED, KEY_BINDING_HEIGHT);
  237. -- Update Unbindkey button
  238. self:UpdateUnbindKey();
  239. end
  240. function KeyBindingFrameMixin:OnHide()
  241. if ( not self.inQuickKeybind ) then
  242. ShowUIPanel(GameMenuFrame);
  243. PlaySound(SOUNDKIT.GS_TITLE_OPTION_EXIT);
  244. UpdateMicroButtons();
  245. end
  246. KeybindFrames_ClearOutputText();
  247. self:SetSelected(nil);
  248. end
  249. function KeyBindingFrameMixin:UnbindKey(keyPressed, selectedAction, bindingMode)
  250. local keyBindMessage;
  251. local oldAction = GetBindingAction(keyPressed, bindingMode);
  252. if oldAction ~= "" and oldAction ~= selectedAction then
  253. local key1, key2 = GetBindingKey(oldAction, bindingMode);
  254. if ( key1 == keyPressed and key2 ) then
  255. keyBindMessage = PRIMARY_KEY_UNBOUND_ERROR:format(GetBindingName(oldAction));
  256. KeybindFrames_SetOutputText(keyBindMessage);
  257. elseif (not key1 or key1 == keyPressed) and (not key2 or key2 == keyPressed) then
  258. keyBindMessage = KEY_UNBOUND_ERROR:format(GetBindingName(oldAction));
  259. KeybindFrames_SetOutputText(keyBindMessage);
  260. end
  261. end
  262. SetBinding(keyPressed, nil, bindingMode);
  263. return keyBindMessage;
  264. end
  265. local function ClearBindingsForKeys(bindingMode, ...)
  266. for i = 1, select("#", ...) do
  267. local key = select(i, ...);
  268. if key then
  269. SetBinding(key, nil, bindingMode);
  270. end
  271. end
  272. end
  273. local function RebindKeysInOrder(keyPressed, keybindButtonID, selectedAction, bindingMode, ...)
  274. local keyBindMessage;
  275. for i = 1, select("#", ...) do
  276. local currentKey = select(i, ...);
  277. local keyToBind = (i == keybindButtonID) and keyPressed or currentKey;
  278. if keyToBind then
  279. keyBindMessage = KeyBindingFrame:SetBinding(keyToBind, selectedAction, bindingMode, currentKey) or keyBindMessage;
  280. end
  281. end
  282. return keyBindMessage;
  283. end
  284. -- NOTE: preventKeybindingFrameBehavior being true indicates that all the code specific to the keybind frame shouldn't be run.
  285. -- The default behavior is to be called from the keybinding frame.
  286. -- This function returns true if it tried to bind something, and false otherwise. Its secondary return is a feedback/status message.
  287. function KeyBindingFrameMixin:AttemptKeybind(keyOrButton, selectedAction, bindingMode, keybindButtonID, preventKeybindingFrameBehavior)
  288. local keyBindFeedbackMessage;
  289. local wasSomethingBound = false;
  290. if GetBindingFromClick(keyOrButton) == "SCREENSHOT" then
  291. RunBinding("SCREENSHOT");
  292. elseif selectedAction then
  293. local keyPressed = GetConvertedKeyOrButton(keyOrButton);
  294. if not IsKeyPressIgnoredForBinding(keyPressed) then
  295. keyPressed = CreateKeyChordStringUsingMetaKeyState(keyPressed);
  296. -- Unbind the current action
  297. local key1, key2 = GetBindingKey(selectedAction, bindingMode);
  298. ClearBindingsForKeys(bindingMode, key1, key2);
  299. -- Unbind the current key and rebind current action
  300. if not preventKeybindingFrameBehavior then
  301. keyBindFeedbackMessage = KEY_BOUND;
  302. KeybindFrames_SetOutputText(KEY_BOUND);
  303. end
  304. keyBindFeedbackMessage = self:UnbindKey(keyPressed, selectedAction, bindingMode) or keyBindFeedbackMessage;
  305. local rebindingMessage = RebindKeysInOrder(keyPressed, keybindButtonID, selectedAction, bindingMode, key1, key2);
  306. if not keyBindFeedbackMessage then
  307. keyBindFeedbackMessage = rebindingMessage;
  308. end
  309. if not preventKeybindingFrameBehavior then
  310. self:Update();
  311. -- Button highlighting stuff
  312. self:SetSelected(nil);
  313. if ( self.buttonPressed ) then
  314. self.buttonPressed:UnlockHighlight();
  315. end
  316. self.bindingsChanged = 1;
  317. self:UpdateUnbindKey();
  318. end
  319. wasSomethingBound = true;
  320. end
  321. elseif (not preventKeybindingFrameBehavior) and GetBindingFromClick(keyOrButton) == "TOGGLEGAMEMENU" then
  322. self:CancelBinding();
  323. end
  324. return wasSomethingBound, keyBindFeedbackMessage;
  325. end
  326. function KeyBindingFrameMixin:OnKeyDown(keyOrButton)
  327. return self:AttemptKeybind(keyOrButton, self.selected, self.mode, self.keyID);
  328. end
  329. function KeyBindingFrameMixin:SetBinding(key, selectedAction, bindingMode, oldKey)
  330. local keyBindMessage;
  331. if not SetBinding(key, selectedAction, bindingMode) then
  332. if oldKey then
  333. SetBinding(oldKey, selectedAction, bindingMode);
  334. end
  335. keyBindMessage = KEYBINDINGFRAME_MOUSEWHEEL_ERROR;
  336. KeybindFrames_SetOutputText(keyBindMessage);
  337. end
  338. return keyBindMessage;
  339. end
  340. function KeyBindingFrameMixin:UpdateUnbindKey()
  341. local enabled = self.selected and true or false;
  342. self.unbindButton:SetEnabled(enabled);
  343. end
  344. function KeyBindingFrameMixin:UpdateHeaderText()
  345. if ( self.characterSpecificButton:GetChecked() ) then
  346. self.Header:Setup(CHARACTER_KEY_BINDINGS:format(UnitName("player")));
  347. else
  348. self.Header:Setup(KEY_BINDINGS);
  349. end
  350. end
  351. function KeyBindingFrameMixin:ChangeBindingProfile()
  352. if ( self.characterSpecificButton:GetChecked() ) then
  353. LoadBindings(CHARACTER_BINDINGS);
  354. else
  355. LoadBindings(ACCOUNT_BINDINGS);
  356. end
  357. self:UpdateHeaderText();
  358. KeybindFrames_ClearOutputText();
  359. self:SetSelected(nil);
  360. self:Update();
  361. end
  362. function KeyBindingFrameMixin:SetSelected(value, keyBindingButton)
  363. local previousButton = self.selectedButton;
  364. self.selectedButton = nil;
  365. self.selected = value;
  366. if previousButton then
  367. BindingButtonTemplate_SetSelected(previousButton, false);
  368. if previousButton.GetCustomBindingType and previousButton:GetCustomBindingType() ~= nil then
  369. previousButton:CancelBinding();
  370. end
  371. end
  372. if keyBindingButton then
  373. BindingButtonTemplate_SetSelected(keyBindingButton, true);
  374. self.selectedButton = keyBindingButton;
  375. self.selectedButtonIndex = keyBindingButton.buttonIndex;
  376. self.selectedRowIndex = keyBindingButton.rowIndex;
  377. end
  378. end
  379. function KeyBindingFrameMixin:OnMouseWheel(delta)
  380. if ( self.selected ) then
  381. if ( delta > 0 ) then
  382. self:OnKeyDown("MOUSEWHEELUP");
  383. else
  384. self:OnKeyDown("MOUSEWHEELDOWN");
  385. end
  386. end
  387. end
  388. function KeyBindingFrameMixin:CancelBinding()
  389. LoadBindings(GetCurrentBindingSet());
  390. KeybindFrames_ClearOutputText();
  391. self:SetSelected(nil);
  392. HideUIPanel(self);
  393. end
  394. function KeyBindingFrameMixin:ResetBindingsToDefault()
  395. PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
  396. LoadBindings(DEFAULT_BINDINGS);
  397. KeybindFrames_ClearOutputText();
  398. self:SetSelected(nil);
  399. self:Update();
  400. end
  401. function KeyBindingFrameMixin:CharacterSpecificPopupAccept()
  402. SaveBindings(ACCOUNT_BINDINGS);
  403. KeybindFrames_ClearOutputText();
  404. self:SetSelected(nil);
  405. HideUIPanel(self);
  406. CONFIRMED_DELETING_CHARACTER_SPECIFIC_BINDINGS = 1;
  407. end
  408. function KeyBindingFrameMixin:LoseBindingsPopupAccept()
  409. self:ChangeBindingProfile();
  410. self.bindingsChanged = nil;
  411. end
  412. function KeyBindingFrameMixin:ResetBindingsPopupAccept()
  413. self:ResetBindingsToDefault();
  414. end
  415. function KeyBindingFrameMixin:EnterQuickKeybind()
  416. self.inQuickKeybind = true;
  417. HideUIPanel(self);
  418. ShowUIPanel(QuickKeybindFrame);
  419. end
  420. KeyBindingButtonMixin = {};
  421. function KeyBindingButtonMixin:OnClick(button, down)
  422. local keybindsFrame = self:GetParent():GetParent();
  423. PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
  424. if ( keybindsFrame.selected ) then
  425. -- Code to be able to deselect or select another key to bind
  426. if ( button == "LeftButton" or button == "RightButton" ) then
  427. -- Deselect button if it was the pressed previously pressed
  428. if (keybindsFrame.buttonPressed == self) then
  429. keybindsFrame:SetSelected(nil);
  430. KeybindFrames_ClearOutputText();
  431. else
  432. -- Select a different button
  433. keybindsFrame.buttonPressed = self;
  434. keybindsFrame:SetSelected(self.commandName, self);
  435. keybindsFrame.keyID = self:GetID();
  436. KeybindFrames_SetOutputText(BIND_KEY_TO_COMMAND, GetBindingName(self.commandName));
  437. end
  438. keybindsFrame:Update();
  439. return;
  440. end
  441. keybindsFrame:OnKeyDown(button);
  442. else
  443. if (keybindsFrame.buttonPressed) then
  444. keybindsFrame.buttonPressed:UnlockHighlight();
  445. end
  446. keybindsFrame.buttonPressed = self;
  447. keybindsFrame:SetSelected(self.commandName, self);
  448. keybindsFrame.keyID = self:GetID();
  449. KeybindFrames_SetOutputText(BIND_KEY_TO_COMMAND, GetBindingName(self.commandName));
  450. keybindsFrame:Update();
  451. end
  452. keybindsFrame:UpdateUnbindKey();
  453. end
  454. function KeyBindingButtonMixin:OnLoad()
  455. self:RegisterForClicks("AnyUp");
  456. end
  457. KeybindingsCategoryListButtonMixin = {};
  458. function KeybindingsCategoryListButtonMixin:OnClick(button, down)
  459. local keybindsFrame = self:GetParent():GetParent();
  460. PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
  461. OptionsList_ClearSelection(keybindsFrame.categoryList, keybindsFrame.categoryList.buttons);
  462. OptionsList_SelectButton(self:GetParent(), self);
  463. keybindsFrame.cntCategory = self.element.category;
  464. keybindsFrame:SetSelected(nil);
  465. KeybindFrames_ClearOutputText();
  466. keybindsFrame.scrollFrame.ScrollBar:SetValue(0);
  467. keybindsFrame:Update();
  468. end
  469. KeybindingsCharacterSpecificButtonMixin = {};
  470. function KeybindingsCharacterSpecificButtonMixin:OnLoad()
  471. self.text:SetText(HIGHLIGHT_FONT_COLOR_CODE..CHARACTER_SPECIFIC_KEYBINDINGS..FONT_COLOR_CODE_CLOSE);
  472. end
  473. function KeybindingsCharacterSpecificButtonMixin:OnClick(button, down)
  474. if (self.enabled) then
  475. PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
  476. else
  477. PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_OFF);
  478. end
  479. if ( KeyBindingFrame.bindingsChanged ) then
  480. StaticPopup_Show("CONFIRM_LOSE_BINDING_CHANGES_CHARACTER_SPECIFIC");
  481. else
  482. KeyBindingFrame:ChangeBindingProfile();
  483. end
  484. end
  485. function KeybindingsCharacterSpecificButtonMixin:OnEnter()
  486. GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
  487. GameTooltip:SetText(CHARACTER_SPECIFIC_KEYBINDING_TOOLTIP, nil, nil, nil, nil, true);
  488. end
  489. function KeybindingsCharacterSpecificButtonMixin:OnHide()
  490. GameTooltip_Hide();
  491. end
  492. KeybindingsUnbindButtonMixin = {};
  493. function KeybindingsUnbindButtonMixin:OnClick()
  494. PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
  495. local keybindsFrame = self:GetParent();
  496. local button = keybindsFrame.selectedButton;
  497. local customBindingType = button.GetCustomBindingType and button:GetCustomBindingType();
  498. if customBindingType ~= nil then
  499. CustomBindingManager:Unbind(customBindingType);
  500. BindingButtonTemplate_SetupBindingButton(nil, button);
  501. else
  502. local key1, key2 = GetBindingKey(keybindsFrame.selected, keybindsFrame.mode);
  503. if ( key1 ) then
  504. SetBinding(key1, nil, keybindsFrame.mode);
  505. end
  506. if ( key2 ) then
  507. SetBinding(key2, nil, keybindsFrame.mode);
  508. end
  509. if ( key1 and keybindsFrame.keyID == 1 ) then
  510. keybindsFrame:SetBinding(key1, nil, keybindsFrame.mode, key1);
  511. if ( key2 ) then
  512. keybindsFrame:SetBinding(key2, keybindsFrame.selected, keybindsFrame.mode, key2);
  513. end
  514. else
  515. if ( key1 ) then
  516. keybindsFrame:SetBinding(key1, keybindsFrame.selected, keybindsFrame.mode);
  517. end
  518. if ( key2 ) then
  519. keybindsFrame:SetBinding(key2, nil, keybindsFrame.mode, key2);
  520. end
  521. end
  522. end
  523. keybindsFrame:Update();
  524. -- Button highlighting stuff
  525. keybindsFrame:SetSelected(nil);
  526. keybindsFrame.buttonPressed:UnlockHighlight();
  527. keybindsFrame:UpdateUnbindKey();
  528. KeybindFrames_ClearOutputText();
  529. end
  530. KeybindingsOkayButtonMixin = {};
  531. function KeybindingsOkayButtonMixin:OnClick()
  532. local parentFrame = self:GetParent();
  533. local keyBindingMode;
  534. if ( parentFrame.characterSpecificButton:GetChecked() ) then
  535. keyBindingMode = CHARACTER_BINDINGS;
  536. else
  537. keyBindingMode = ACCOUNT_BINDINGS;
  538. if ( GetCurrentBindingSet() == CHARACTER_BINDINGS ) then
  539. if ( not CONFIRMED_DELETING_CHARACTER_SPECIFIC_BINDINGS ) then
  540. StaticPopup_Show("CONFIRM_DELETING_CHARACTER_SPECIFIC_BINDINGS");
  541. return;
  542. end
  543. end
  544. end
  545. SaveBindings(keyBindingMode);
  546. KeybindFrames_ClearOutputText();
  547. parentFrame:SetSelected(nil);
  548. HideUIPanel(parentFrame);
  549. local shouldSave = true;
  550. HandleCustomKeybindingsDismissed(shouldSave);
  551. end
  552. KeybindingsCancelButtonMixin = {};
  553. function KeybindingsCancelButtonMixin:OnClick()
  554. local parentFrame = self:GetParent();
  555. parentFrame:CancelBinding();
  556. local shouldSave = false;
  557. HandleCustomKeybindingsDismissed(shouldSave);
  558. end
  559. KeybindingsDefaultsButtonMixin = {};
  560. function KeybindingsDefaultsButtonMixin:OnClick()
  561. StaticPopup_Show("CONFIRM_RESET_TO_DEFAULT_KEYBINDINGS");
  562. end
  563. KeyBindingFrameBindingTemplateMixin = {};
  564. function KeyBindingFrameBindingTemplateMixin:Update(keyOffset)
  565. local keybindsFrame = self:GetParent();
  566. local cntCategory = keybindsFrame.cntCategory;
  567. -- Set binding text
  568. local commandName, category, binding1, binding2 = GetBinding(cntCategory[keyOffset], self.mode);
  569. local customBindingType = C_KeyBindings.GetCustomBindingType(cntCategory[keyOffset]);
  570. local customButton = customBindingType and GetOrCreateCustomKeybindingButton(customBindingType);
  571. local isHeader = strsub(commandName, 1, 6) == "HEADER";
  572. self.header:SetShown(isHeader);
  573. self.key1Button:SetShown(not isHeader and not customButton);
  574. self.key2Button:SetShown(not isHeader);
  575. self.key2Button:SetEnabled(not customButton);
  576. self.description:SetShown(not isHeader);
  577. self.key1Button.commandName = commandName;
  578. self.key2Button.commandName = commandName;
  579. if ( isHeader ) then
  580. self.header:SetText(_G["BINDING_"..commandName]);
  581. else
  582. if customBindingType ~= nil then
  583. binding1, binding2 = nil, nil;
  584. end
  585. BindingButtonTemplate_SetupBindingButton(binding1, self.key1Button);
  586. BindingButtonTemplate_SetupBindingButton(binding2, self.key2Button);
  587. self.description:SetText(GetBindingName(commandName));
  588. self:Show();
  589. if customButton then
  590. BindingButtonTemplate_SetupBindingButton(nil, customButton);
  591. customButton:ClearAllPoints();
  592. customButton:SetAllPoints(self.key1Button);
  593. customButton:Show();
  594. end
  595. end
  596. end
  597. function KeyBindingFrameBindingTemplateMixin:InitializeButtons(rowIndex)
  598. self.key1Button.buttonIndex = 1;
  599. self.key1Button.rowIndex = rowIndex;
  600. self.key2Button.buttonIndex = 2;
  601. self.key2Button.rowIndex = rowIndex;
  602. end
  603. KeyBindingFrameScrollFrameMixin = {};
  604. function KeyBindingFrameScrollFrameMixin:OnVerticalScroll(offset)
  605. local keybindsFrame = self:GetParent();
  606. FauxScrollFrame_OnVerticalScroll(self, offset, KEY_BINDING_HEIGHT, GenerateClosure(keybindsFrame.Update, keybindsFrame));
  607. end
  608. function KeyBindingFrameScrollFrameMixin:OnMouseWheel(delta)
  609. local keybindsFrame = self:GetParent();
  610. if ( not keybindsFrame.selected ) then
  611. ScrollFrameTemplate_OnMouseWheel(self, delta);
  612. else
  613. keybindsFrame:OnMouseWheel(delta);
  614. end
  615. end
  616. QuickKeybindButtonMixin = {};
  617. function QuickKeybindButtonMixin:OnClick(button, down)
  618. local keybindFrame = self:GetParent();
  619. keybindFrame.keyID = 1;
  620. keybindFrame:EnterQuickKeybind();
  621. end
  622. QuickKeybindFrameMixin = {};
  623. function QuickKeybindFrameMixin:OnShow()
  624. EventRegistry:TriggerEvent("QuickKeybindFrame.QuickKeybindModeEnabled");
  625. self.characterSpecificButton:SetChecked(KeyBindingFrame.characterSpecificButton:GetChecked());
  626. self.mouseOverButton = nil;
  627. Enable_BagButtons();
  628. ActionButtonUtil.ShowAllActionButtonGrids();
  629. ActionButtonUtil.ShowAllQuickKeybindButtonHighlights();
  630. local showQuickKeybindEffects = true;
  631. MainMenuBar:SetQuickKeybindModeEffectsShown(showQuickKeybindEffects);
  632. MultiActionBar_SetAllQuickKeybindModeEffectsShown(showQuickKeybindEffects);
  633. self.phantomExtraActionButton.QuickKeybindHighlightTexture:Show();
  634. end
  635. function QuickKeybindFrameMixin:OnHide()
  636. EventRegistry:TriggerEvent("QuickKeybindFrame.QuickKeybindModeDisabled");
  637. KeybindFrames_ClearOutputText();
  638. if ( not GameMenuFrame:IsShown() ) then
  639. ShowUIPanel(KeyBindingFrame);
  640. end
  641. Disable_BagButtons();
  642. ActionButtonUtil.HideAllActionButtonGrids();
  643. ActionButtonUtil.HideAllQuickKeybindButtonHighlights();
  644. local showQuickKeybindEffects = false;
  645. MainMenuBar:SetQuickKeybindModeEffectsShown(showQuickKeybindEffects);
  646. MultiActionBar_SetAllQuickKeybindModeEffectsShown(showQuickKeybindEffects);
  647. end
  648. function QuickKeybindFrameMixin:CancelBinding()
  649. LoadBindings(GetCurrentBindingSet());
  650. KeybindFrames_ClearOutputText();
  651. KeyBindingFrame:SetSelected(nil);
  652. HideUIPanel(self);
  653. end
  654. function QuickKeybindFrameMixin:SetSelected(value, button)
  655. KeyBindingFrame:SetSelected(value);
  656. self.mouseOverButton = button;
  657. end
  658. function QuickKeybindFrameMixin:OnKeyDown(keyOrButton)
  659. local selected = KeyBindingFrame.selected;
  660. local mode = KeyBindingFrame.mode;
  661. local gmkey1, gmkey2 = GetBindingKey("TOGGLEGAMEMENU", mode);
  662. if ( (keyOrButton == gmkey1 or keyOrButton == gmkey1) and not selected ) then
  663. ShowUIPanel(GameMenuFrame);
  664. self:CancelBinding();
  665. elseif ( keyOrButton == "ESCAPE" and selected ) then
  666. local key1, key2 = GetBindingKey(selected, mode);
  667. if ( key1 ) then
  668. KeyBindingFrame:SetBinding(key1, nil, mode, key1);
  669. end
  670. if ( key2 ) then
  671. KeyBindingFrame:SetBinding(key2, selected, mode, key2);
  672. end
  673. KeybindFrames_ClearOutputText();
  674. else
  675. KeyBindingFrame:OnKeyDown(keyOrButton);
  676. -- Reselect hovered button
  677. KeyBindingFrame:SetSelected(selected);
  678. end
  679. if ( self.mouseOverButton ) then
  680. self.mouseOverButton:QuickKeybindButtonSetTooltip();
  681. end
  682. end
  683. function QuickKeybindFrameMixin:OnMouseWheel(delta)
  684. local selected = KeyBindingFrame.selected;
  685. KeyBindingFrame:OnMouseWheel(delta);
  686. if ( self.mouseOverButton ) then
  687. self.mouseOverButton:QuickKeybindButtonSetTooltip();
  688. end
  689. -- Reselect hovered button
  690. KeyBindingFrame:SetSelected(selected);
  691. end
  692. QuickKeybindResetAllButtonMixin = {};
  693. function QuickKeybindResetAllButtonMixin:OnClick()
  694. StaticPopup_Show("CONFIRM_RESET_TO_PREVIOUS_KEYBINDINGS");
  695. end
  696. PhantomExtraActionButtonMixin = {};
  697. function PhantomExtraActionButtonMixin:OnLoad()
  698. self:RegisterEvent("UPDATE_BINDINGS");
  699. self:UpdateHotkeyText();
  700. end
  701. function PhantomExtraActionButtonMixin:OnUpdate(elapsed)
  702. local bottom = ExtraActionButton1:GetBottom() or 150;
  703. self:SetPoint("BOTTOM", UIParent, "BOTTOM", 0, bottom)
  704. end
  705. function PhantomExtraActionButtonMixin:OnEvent(event, ...)
  706. if ( event == "UPDATE_BINDINGS" ) then
  707. self:UpdateHotkeyText();
  708. end
  709. end
  710. function PhantomExtraActionButtonMixin:UpdateHotkeyText()
  711. local key = GetBindingKey(self.commandName);
  712. local bindingText = GetBindingText(key, 1);
  713. self.HotKey:SetText(bindingText);
  714. end