View Single Post
06-24-19, 11:28 AM   #4
DashingSplash
A Murloc Raider
Join Date: Jun 2019
Posts: 7
Originally Posted by MunkDev View Post
Awesome-code
Wow! Now that's some clean and good-looking code. Thank you for the help.

Was really surprised to see that

Lua Code:
  1. local prefix = SecureButton_GetModifierPrefix()
  2. local binding = GetBindingAction(prefix .. key)

was a thing. Although, I assume I'll get a better understanding of the API with some experience.

The only thing that had to be included in your code was to allow companion, item, and macro functionality. See modified function below. Any input on that?

Lua Code:
  1. frame:EnableKeyboard(true)
  2. frame:SetPropagateKeyboardInput(true)
  3. frame:SetScript('OnKeyDown', function(self, key, ...)  
  4.     if IsMounted() then
  5.         local prefix = SecureButton_GetModifierPrefix()
  6.         local binding = GetBindingAction(prefix .. key)
  7.         local button = actionButtons[binding]
  8.  
  9.         if button then
  10.             local action = ActionButton_CalculateAction(button)
  11.            
  12.             if HasAction(action) then
  13.                 local actionType, spellID = GetActionInfo(action)
  14.                
  15.                 if (actionType == 'spell' or actionType == 'item' or actionType == 'companion') and not protectedSkills[spellID] then
  16.                     Dismount()
  17.                 elseif actionType == "macro" then
  18.                     spellID, _ = GetMacroSpell(spellID)
  19.                     if spellID ~= nil and not protectedSkills[spellID] then
  20.                         Dismount()
  21.                     end
  22.                 end
  23.             end
  24.             return
  25.         end
  26.  
  27.         button = stanceButtons[binding]
  28.         if button and not button:GetChecked() then
  29.             Dismount()
  30.         end
  31.     end
  32. end)

The only thing I am unsure about is how

Lua Code:
  1. button = stanceButtons[binding]
  2. if button and not button:GetChecked() then
  3.       Dismount()
  4. end

works. When and how is the button state set to checked?

frame:EnableKeyboard(true) seems moot. Can set it to false (or even remove it completely) and the addon will still work. In my first version I had to set the frame to inherit from UIParent, and then show the frame for EnableKeyboard to actually work. Safe to remove it, or does it actually have some hidden function?

Last edited by DashingSplash : 06-24-19 at 11:48 AM.
  Reply With Quote