Thread Tools Display Modes
03/30/15, 04:50 PM   #1
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 5,002
PreHooking Dialog's OnKeyUp -> Primary + Abort keybinding do not work anymore

Hey there,

I just tested somethign with a dialog and if I PreHook the OnKeyUp handler for the dialog + set dialog:SetKeyboardEnabled(true) (which is needed so the OnkeyUp method will be recognized at all) the standard keybindings of this dialog won#t work anymore :-(

Any idea to achieve both:
1. Get listener on handler OnKeyUp and execute my own function
2. Get standrd keybindings to work for the accept and abort buttons of this dialog

My idea was:
-Get the keycodes for the primary and abort dialog keys (any function to read this from the settings to get the keycodes in the desired keycode style, e.g. KEY_E for the "e" button?)
-Implement the OnKeyUp function to react on these two keycodes (accept and abort) as well

Only problem is:
If I tried to just execute the "callback" function of the accpet button by my source code I'll get an error because of another addon (Stacked). This is because Stacked already copied the original handler of this dialog's accept button and has implemented an own one. I can't see why the error is thrown but it does

Here is my source code so far:

Lua Code:
  1. ------------------------------------------------------------------
  2. --FCOGuildBankQuickSelect.lua
  3. --Author: Baertram
  4. --v0.0.1
  5. --[[
  6. Quickly select the guild bank by numbers 1-5 (at an opened guild bank selection)
  7. ]]
  8. ------------------------------------------------------------------
  9. --Array for all the variables
  10. local locVars = {}
  11.  
  12. --Uncolored "FCOIS" pre chat text for the chat output
  13. locVars.preChatText = "FCOGuildBankQuickSelect"
  14. --Green colored "FCOIS" pre text for the chat output
  15. locVars.preChatTextGreen = "|c22DD22"..locVars.preChatText.."|r "
  16. --Red colored "FCOIS" pre text for the chat output
  17. locVars.preChatTextRed = "|cDD2222"..locVars.preChatText.."|r "
  18. --Blue colored "FCOIS" pre text for the chat output
  19. locVars.preChatTextBlue = "|c2222DD"..locVars.preChatText.."|r "
  20.  
  21. --Addon variables
  22. local addonVars = {}
  23. addonVars.gAddonName                = "FCOGuildBankQuickSelect"
  24. addonVars.addonNameMenu             = "FCO GuildBankQuickSelect"
  25. addonVars.addonNameMenuDisplay      = "|c00FF00FCO |cFFFF00GuildBankQuickSelect|r"
  26. addonVars.addonAuthor               = '|cFFFF00Baertram|r'
  27. addonVars.addonVersion              = 0.01 -- Changing this will reset SavedVariables!
  28. addonVars.addonVersionOptions       = '0.0.1' -- version shown in the settings panel
  29. addonVars.addonSavedVariablesName   = "FCOGuildBankQuickSelect_Settings"
  30. addonVars.gAddonLoaded              = false
  31.  
  32. --Original/Backup avriables
  33. local origVars = {}
  34. origVars.GuildBankSelectorOnKeyDown = nil
  35. origVars.GuildBankSelectorOnKeyUp   = nil
  36.  
  37. --Control names of ZO* standard controls etc.
  38. local GUILDBANK_SELECT_POPUP                = ZO_SelectGuildBankDialog
  39. --local GUILDBANK_SELECT_POPUP_UNDERLAY     = ZO_SelectGuildBankDialogModalUnderlay
  40. local GUILDBANK_SELECT_POPUP_GUILD          = ZO_SelectGuildBankDialogGuild
  41. local GUILDBANK_SELECT_POPUP_GUILD_COMBOBOX = GUILDBANK_SELECT_POPUP_GUILD.m_comboBox
  42. local GUILDBANK_SELECT_POPUP_ACCEPT         = ZO_SelectGuildBankDialogAccept
  43. local GUILDBANK_SELECT_POPUP_ABORT          = ZO_SelectGuildBankDialogCancel
  44.  
  45. --===================== FUNCTIONS ==============================================
  46.  
  47. -- set handlers for keyboard events:
  48. local function FCOGuildBankQuickSelect_HandleKeyboardEvents(self, key, hide)
  49.     if key == KEY_1 or key == KEY_NUMPAD1 then
  50.         if GUILDBANK_SELECT_POPUP_GUILD_COMBOBOX then
  51.             GUILDBANK_SELECT_POPUP_GUILD_COMBOBOX:SelectItemByIndex(1)
  52.         end
  53.     elseif key == KEY_2 or key == KEY_NUMPAD2 then
  54.         if GUILDBANK_SELECT_POPUP_GUILD_COMBOBOX then
  55.             GUILDBANK_SELECT_POPUP_GUILD_COMBOBOX:SelectItemByIndex(2)
  56.         end
  57.     elseif key == KEY_3 or key == KEY_NUMPAD3 then
  58.         if GUILDBANK_SELECT_POPUP_GUILD_COMBOBOX then
  59.             GUILDBANK_SELECT_POPUP_GUILD_COMBOBOX:SelectItemByIndex(3)
  60.         end
  61.     elseif key == KEY_4 or key == KEY_NUMPAD4 then
  62.         if GUILDBANK_SELECT_POPUP_GUILD_COMBOBOX then
  63.             GUILDBANK_SELECT_POPUP_GUILD_COMBOBOX:SelectItemByIndex(4)
  64.         end
  65.     elseif key == KEY_5 or key == KEY_NUMPAD5 then
  66.         if GUILDBANK_SELECT_POPUP_GUILD_COMBOBOX then
  67.             GUILDBANK_SELECT_POPUP_GUILD_COMBOBOX:SelectItemByIndex(5)
  68.         end
  69.     end
  70.     return false
  71. end
  72.  
  73. --un/register guild bank selection popup tweaks
  74. local function registerGuildBankSelectionTweaks(doRegister)
  75.     if doRegister then
  76.         GUILDBANK_SELECT_POPUP:SetKeyboardEnabled(true)
  77.         --Register the OnKeyPressed function for the guild bank select dialog
  78.         ZO_PreHookHandler(GUILDBANK_SELECT_POPUP, 'OnKeyUp', function(self, key, ctrl, alt, shift, command) FCOGuildBankQuickSelect_HandleKeyboardEvents(self, key, true) end)
  79.     else
  80.         --Unregister
  81.         GUILDBANK_SELECT_POPUP_GUILD:SetHandler("OnKeyUp", function(self, key, ctrl, alt, shift, command) origVars.GuildBankSelectorOnKeyUp(self, key, true) end)
  82.     end
  83. end
  84.  
  85. --==============================================================================
  86. --==================== START EVENT CALLBACK FUNCTIONS===========================
  87. --==============================================================================
  88.  
  89. --Event function if guild bank is opened
  90. local function FCOGuildBankQuickSelect_Open_Guild_Bank()
  91.     registerGuildBankSelectionTweaks(true)
  92. end
  93.  
  94. --Event function if guild bank is closed
  95. local function FCOGuildBankQuickSelect_Close_Guild_Bank()
  96.     registerGuildBankSelectionTweaks(false)
  97. end
  98.  
  99. -- Fires each time after addons were loaded and player is ready to move (after each zone change too)
  100. local function FCOGuildBankQuickSelect_Player_Activated(...)
  101.     --Prevent this event to be fired again and again upon each zone change
  102.     EVENT_MANAGER:UnregisterForEvent(addonVars.gAddonName, EVENT_PLAYER_ACTIVATED)
  103.  
  104.     --Backup the original handler
  105.     origVars.GuildBankSelectorOnKeyDown = GUILDBANK_SELECT_POPUP:GetHandler("OnKeyDown")
  106.     origVars.GuildBankSelectorOnKeyUp   = GUILDBANK_SELECT_POPUP:GetHandler("OnKeyUp")
  107.  
  108.     --Set addon loaded = false
  109.     addonVars.gAddonLoaded = false
  110. end
  111.  
  112. --==============================================================================
  113. --===== HOOKS BEGIN ============================================================
  114. --==============================================================================
  115. --Create the hooks & pre-hooks
  116. local function CreateHooks()
  117. --nothing here atm
  118. end
  119.  
  120. --Addon loads up
  121. local function FCOGuildBankQuickSelect_Loaded(eventCode, addOnName)
  122.     --Is this addon found?
  123.     if(addOnName ~= addonVars.gAddonName) then
  124.         return
  125.     end
  126.     --Unregister this event again so it isn't fired again after this addon has beend reckognized
  127.     EVENT_MANAGER:UnregisterForEvent(addonVars.gAddonName, EVENT_ADD_ON_LOADED)
  128.  
  129.     addonVars.gAddonLoaded = true
  130. end
  131.  
  132. -- Register the event "addon loaded" for this addon
  133. local function FCOGuildBankQuickSelect_Initialized()
  134.     EVENT_MANAGER:RegisterForEvent(addonVars.gAddonName, EVENT_ADD_ON_LOADED, FCOGuildBankQuickSelect_Loaded)
  135.     --Register for the zone change/player ready event
  136.     EVENT_MANAGER:RegisterForEvent(addonVars.gAddonName, EVENT_PLAYER_ACTIVATED, FCOGuildBankQuickSelect_Player_Activated)
  137.     --Register for Guild Bank opened & closed
  138.     EVENT_MANAGER:RegisterForEvent(addonVars.gAddonName, EVENT_OPEN_GUILD_BANK, FCOGuildBankQuickSelect_Open_Guild_Bank)
  139.     EVENT_MANAGER:RegisterForEvent(addonVars.gAddonName, EVENT_CLOSE_GUILD_BANK, FCOGuildBankQuickSelect_Close_Guild_Bank)
  140. end
  141.  
  142.  
  143. --------------------------------------------------------------------------------
  144. --- Call the start function for this addon to register events etc.
  145. --------------------------------------------------------------------------------
  146. FCOGuildBankQuickSelect_Initialized()

Last edited by Baertram : 04/02/15 at 11:41 AM.
  Reply With Quote
03/30/15, 09:12 PM   #2
Sasky
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 231
Can you register the callback elsewhere or can only one control capture keybinds?

If they all register, use the OnKeyUp event for a different control (either one in scene or add your own to the scene).
  Reply With Quote
03/30/15, 10:36 PM   #3
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
There may be a way to avoid the problem entirely, but this would be a simple fix.

Just handle those keys that aren't working yourself:
Lua Code:
  1. local function FCOGuildBankQuickSelect_HandleKeyboardEvents(self, key, hide)
  2. ...
  3. elseif key == KEY_E then
  4.     ZO_SelectGuildBankDialogAccept:callback()
  5. elseif key == KEY_ALT then
  6.     ZO_SelectGuildBankDialogCancel:callback()
  7. end

Last edited by circonian : 03/30/15 at 10:39 PM.
  Reply With Quote
03/31/15, 01:47 AM   #4
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 5,002
@Circonian Thx. I tried this already (as I've written above) but not everyone is using KEY_E and KEY_ALT as the keybindings for accept or cancel.
Am I able to get the assigned keybindings somehow to react ont eh correct keys? Maybe someone changed it to KEY_G and KEY_CTRL.

And as I said too the addon "stacked" raises an error if I try to call the callback function of the accept button. I'm not sure WHY it does this. It seems to copy the original callback to a backup function, exchange the callback function then with an own one, call the original function and then it's code to refresh some keybindings (so it's a Post-hook).
Maybe I can pre-Hook the callback function of the accept button to avoid the error.

@Sasky
Good idea, I'll see if I can register the keybindings to the scene and then check if the dialog is shown. But I hope it won't disable keybinds of the keybind strip for all teh scene elements this way ^^
  Reply With Quote
03/31/15, 07:24 AM   #5
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Originally Posted by Baertram View Post
Am I able to get the assigned keybindings somehow to react ont eh correct keys? Maybe someone changed it to KEY_G and KEY_CTRL.
http://esodata.uesp.net/100010/src/c...ls.lua.html#30

However, I think it'd be better if you got it to work without replacing existing bindings.
  Reply With Quote
03/31/15, 08:31 AM   #6
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 5,002
Thx merlight.

I'd love to get this to work but I don't know how? Everytime I enable the SetKeyboardEnabled(true) function the keybindings seem to get disabled :-(
And without this keyboard enabled function I'm not able to react on the keys :-(

Maybe I can get it to work by using the scene somehow.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » PreHooking Dialog's OnKeyUp -> Primary + Abort keybinding do not work anymore


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off