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: 4,959
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: 4,959
@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: 4,959
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
03/31/15, 04:11 PM   #7
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Oh yeah, my bad. I guess by the time I got done looking at it I forgot you said all of that.

EDIT: Oh yeah, and the reason the buttons stop working when you turn on SetKeyboardEnabled(true) is because if, for example, the chat edit box (to enter chat) had focus & its keyboardEnabled...if it did not block keybind buttons you would start walking & opening all kinds of windows as you typed and those dialog buttons are not keyboardEnabled controls they are called/fired from keybinds.

Here you go:

Lua Code:
  1. local DIALOG_PRIMARY
  2. local DIALOG_NEGATIVE
  3.  
  4.  
  5. local function FCOGuildBankQuickSelect_Player_Activated(...)
  6. ...
  7.      -- Grabs the key for the binding string name (e, alt, whatever)
  8.     DIALOG_PRIMARY = ZO_Keybindings_GetBindingStringFromAction("DIALOG_PRIMARY")
  9.     DIALOG_NEGATIVE = ZO_Keybindings_GetBindingStringFromAction("DIALOG_NEGATIVE")
  10. ...
  11. end
  12.  
  13.  
  14. local function FCOGuildBankQuickSelect_HandleKeyboardEvents(self, key, hide)
  15. ...
  16.     -- Convert keycode to actual key so we can compare it to our primary/negative keys
  17.     elseif GetKeyName(key) == DIALOG_PRIMARY then
  18.         ZO_Dialogs_ButtonKeybindPressed("DIALOG_PRIMARY")
  19.     elseif GetKeyName(key) == DIALOG_NEGATIVE then
  20.         ZO_Dialogs_ButtonKeybindPressed("DIALOG_NEGATIVE")
  21.     end
  22.     return false
  23. end

One thing you may (or may not) have thought of (I didn't look at any of the other code) (although unlikely) do you have to worry about if they have changed those primary/negative keybinds to a keypress you are using to switch guilds (KEY_1, KEY_NUMPAD1, exc..)?

PS: I like the easy way of switching guild banks...How about adding scrollWheel support to just scroll the mouse wheel to switch guilds.

Last edited by circonian : 03/31/15 at 04:23 PM.
  Reply With Quote
03/31/15, 04:37 PM   #8
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,959
Thanks again. Your method is exactly how I managed to solve it some hours ago ;-)
Oh and I don't think anyone uses the keys 1 to 5 for the keybinds of accept&decline as they are pre-designed to be used for the character's skills. if anyone is using them he/she should report it and I'll start to think about at this time hehe

I was thinking about the scroll wheel too but did not find out how to hook the scroll wheel on that dialog until now. Did not put much effort in it yet, maybe I'll add it in the future.
  Reply With Quote
03/31/15, 04:46 PM   #9
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
EDIT: bah, I deleted it. Lets try that again:
You could move the primary/negative key checks to the top, then that way they will get tested first. That way if someone has KEY_NUMPAD1 bound as their primary it would still work and they could still use KEY_1 to change guilds.

Lua Code:
  1. local function FCOGuildBankQuickSelect_HandleKeyboardEvents(self, key, hide)
  2.     -- Convert keycode to actual key so we can compare it to our primary/negative keys
  3.     if GetKeyName(key) == DIALOG_PRIMARY then
  4.         ZO_Dialogs_ButtonKeybindPressed("DIALOG_PRIMARY")
  5.     elseif GetKeyName(key) == DIALOG_NEGATIVE then
  6.         ZO_Dialogs_ButtonKeybindPressed("DIALOG_NEGATIVE")
  7.     end
  8. ...
  9. end

Last edited by circonian : 03/31/15 at 05:40 PM.
  Reply With Quote
04/01/15, 09:24 AM   #10
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,959
Good idea, I'll change this in the next version.
I'm currntly investigating the mouse scrolling but I'm not sure until now how to hook it at the dialog.
Maybe I need to start to listen to all mouse scroll events when then guild select dialog appears (prehook OnShow and set variable to "dialog is active") and then unhook / change variable again if the dialog gets closed.

Ok I got it to work and implemented + released it. You can select your guild by help of the mouse wheel too.

Last edited by Baertram : 04/01/15 at 10:59 AM.
  Reply With Quote
04/02/15, 11:38 AM   #11
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,959
I got a new problem now. The addon is working so far. Mouse wheel and keyboard keys 1 to 5 will switch the combobox at the guild bank selection popup to the according guild.

The mousewheel is working directly after the 1st time you open the guild bank selector popup.
But the keyboard keys 1 to 5 won#t work at this time?
You'll have to close the dialog and reopen it again. After this the keys are working too.

Currently I hooked the OnShow method of the dialog, prehooked the OnKeyUp function of the dialog and enabled the keyboard then. But it seems that the dialog won't register the OnKeyUp handler's PreHook until you "reload" the dialog (by closing and opening it again)?

Any ideas how to fix this?

Here is the current source code:
Lua Code:
  1. ------------------------------------------------------------------
  2. --FCOGuildBankQuickSelect.lua
  3. --Author: Baertram
  4. --v0.0.2b
  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.2b' -- version shown in the settings panel
  29. addonVars.addonSavedVariablesName    = "FCOGuildBankQuickSelect_Settings"
  30. addonVars.gAddonLoaded               = false
  31. addonVars.hookedGuildSelectDialog    = false
  32. addonVars.currentSelectedGuildNumber = -1
  33.  
  34. --Original/Backup avriables
  35. local origVars = {}
  36. --origVars.GuildBankSelectorOnKeyDown         = nil
  37. origVars.GuildBankSelectorOnKeyUp           = nil
  38. origVars.GuildBankSelectorOnMouseWheelMU    = nil
  39. origVars.GuildBankSelectorOnMouseWheelG     = nil
  40.  
  41. --Control names of ZO* standard controls etc.
  42. local GUILDBANK_SELECT_POPUP                = ZO_SelectGuildBankDialog
  43. local GUILDBANK_SELECT_POPUP_GUILD          = ZO_SelectGuildBankDialogGuild
  44. local GUILDBANK_SELECT_POPUP_GUILD_COMBOBOX = GUILDBANK_SELECT_POPUP_GUILD.m_comboBox
  45. local GUILDBANK_SELECT_POPUP_ACCEPT         = ZO_SelectGuildBankDialogAccept
  46. local GUILDBANK_SELECT_POPUP_ABORT          = ZO_SelectGuildBankDialogCancel
  47. local GUILDBANK_SELECT_POPUP_MODAL_UNDERLAY = ZO_SelectGuildBankDialogModalUnderlay
  48.  
  49. --===================== FUNCTIONS ==============================================
  50.  
  51. --Get the current selected item's index
  52. local function FCOGuildBankQuickSelect_GetCurrentSelectedIndex(comboBoxCtrl)
  53. d("blubb")
  54.     --Check the combobox if the last item is possible in there, otherwise select "All"
  55.     local comboboxItems = comboBoxCtrl.m_sortedItems
  56.     local currentItem   = comboBoxCtrl.m_selectedItemText:GetText()
  57.     if currentItem == nil then return -1 end
  58.     local foundIndex = -1
  59.     if comboboxItems ~= nil then
  60.         for idx, itemTable in pairs(comboboxItems) do
  61.             if itemTable.name == currentItem then
  62.                 --item was found, abort here
  63.                 foundIndex = idx
  64.                 break
  65.             end
  66.         end
  67.     end
  68.     return foundIndex
  69. end
  70.  
  71. --Select the next entry in the guild selection combobox
  72. local function FCOGuildBankQuickSelect_SelectGuildEntry(upDown, newIndex)
  73.     local maxIndex = #GUILDBANK_SELECT_POPUP_GUILD_COMBOBOX.m_sortedItems
  74.     if maxIndex == 0 or maxIndex == nil then return end
  75.     newIndex = newIndex or -1
  76.     if newIndex ~= nil and newIndex ~= -1 and newIndex >= 1 and newIndex <= maxIndex then
  77.         --Set the given new index
  78.         if GUILDBANK_SELECT_POPUP_GUILD_COMBOBOX then
  79.             GUILDBANK_SELECT_POPUP_GUILD_COMBOBOX:SelectItemByIndex(newIndex)
  80.         end
  81.     else
  82.         if upDown == nil then return end
  83.         --Get the next index by help of the upDown variable coming from the mouse wheel capture
  84.         --Get the current selected item index first
  85.         local currentIndex = addonVars.currentSelectedGuildNumber
  86.         if currentIndex == -1 then
  87.             currentIndex = FCOGuildBankQuickSelect_GetCurrentSelectedIndex(GUILDBANK_SELECT_POPUP_GUILD_COMBOBOX)
  88.         end
  89.         if currentIndex == nil or currentIndex == -1 or currentIndex < 1 or currentIndex > maxIndex then return end
  90.         --Scrolled up?
  91.         local newIndexToUse = -1
  92.         if upDown then
  93.             newIndexToUse = currentIndex - 1
  94.         else
  95.         --Scrolled down?
  96.             newIndexToUse = currentIndex + 1
  97.         end
  98.         --Did we scroll to the first index and below, then use maximum index
  99.         if newIndexToUse < 1 then
  100.             newIndexToUse = maxIndex
  101.         end
  102.         --Did we scroll to the last index and above, then use minimum index
  103.         if newIndexToUse > maxIndex then
  104.             newIndexToUse = 1
  105.         end
  106.         if newIndexToUse ~= -1 then
  107.             GUILDBANK_SELECT_POPUP_GUILD_COMBOBOX:SelectItemByIndex(newIndexToUse)
  108.             addonVars.currentSelectedGuildNumber = newIndexToUse
  109.         end
  110.     end
  111. end
  112.  
  113. --Get the information about the pressed key and map it to a keybind
  114. local function FCOGuildBankQuickSelect_GetKeybindByPressedKey(key)
  115.     local actionNameAccept = "DIALOG_PRIMARY"
  116.     local actionNameDecline = "DIALOG_NEGATIVE"
  117.  
  118.     --KEYBIND_TEXT_OPTIONS_ABBREVIATED_NAME = 1
  119.     --KEYBIND_TEXT_OPTIONS_FULL_NAME = 2
  120.     --KEYBIND_TEXT_OPTIONS_FULL_NAME_SEPARATE_MODS = 3
  121.     local textOptions = KEYBIND_TEXT_OPTIONS_ABBREVIATED_NAME
  122.     --KEYBIND_TEXTURE_OPTIONS_NONE = 1
  123.     --KEYBIND_TEXTURE_OPTIONS_EMBED_MARKUP = 2
  124.     local textureOptions = KEYBIND_TEXTURE_OPTIONS_NONE
  125.     local bindingIndexAccept = 1  --1 or 2, primary or secondary binding
  126.     local bindingIndexDecline = 1  --1 or 2, primary or secondary binding
  127.     local bindingStringAccept = ZO_Keybindings_GetBindingStringFromAction(actionNameAccept, textOptions, textureOptions, bindingIndexAccept)
  128.     local bindingStringDecline = ZO_Keybindings_GetBindingStringFromAction(actionNameDecline, textOptions, textureOptions, bindingIndexDecline)
  129.  
  130. --d("bindingStringAccept: " .. tostring(bindingStringAccept))
  131. --d("bindingStringDecline: " .. tostring(bindingStringDecline))
  132. --d("Key: " .. tostring(key) .. "(".. GetKeyName(key) .. ")")
  133.     if GetKeyName(key) == bindingStringAccept then
  134.         return 1
  135.     elseif GetKeyName(key) == bindingStringDecline then
  136.         return 2
  137.     else
  138.         return -1
  139.     end
  140. end
  141.  
  142. -- set handlers for the mouse wheel
  143. local function FCOGuildBankQuickSelect_HandleMouseWheelEvents(doRegister)
  144.     doRegister = doRegister or false
  145.     if doRegister then
  146.         GUILDBANK_SELECT_POPUP_MODAL_UNDERLAY:SetMouseEnabled(true)
  147.         GUILDBANK_SELECT_POPUP_MODAL_UNDERLAY:SetHandler("OnMouseWheel", function(self, delta, ctrl, alt, shift)
  148.             if delta < 0 then
  149.                 -- Mouse wheel down
  150.                 FCOGuildBankQuickSelect_SelectGuildEntry(false, nil)
  151.             else
  152.                 -- Mouse wheel up
  153.                 FCOGuildBankQuickSelect_SelectGuildEntry(true, nil)
  154.             end
  155.         end)
  156.         GUILDBANK_SELECT_POPUP_GUILD:SetMouseEnabled(true)
  157.         GUILDBANK_SELECT_POPUP_GUILD:SetHandler("OnMouseWheel", function(self, delta, ctrl, alt, shift)
  158.             if delta < 0 then
  159.                 -- Mouse wheel down
  160.                 FCOGuildBankQuickSelect_SelectGuildEntry(false, nil)
  161.             else
  162.                 -- Mouse wheel up
  163.                 FCOGuildBankQuickSelect_SelectGuildEntry(true, nil)
  164.             end
  165.         end)
  166.     else
  167.         if origVars.GuildBankSelectorOnMouseWheelMU and origVars.GuildBankSelectorOnMouseWheelMU ~= nil then
  168.             --Use original handler for the mousewheel again
  169.             GUILDBANK_SELECT_POPUP_MODAL_UNDERLAY:SetHandler("OnMouseWheel", function(self, delta, ctrl, alt, shift)
  170.                 origVars.GuildBankSelectorOnMouseWheelMU(self, delta, ctrl, alt, shift)
  171.             end)
  172.         end
  173.         if origVars.GuildBankSelectorOnMouseWheelG and origVars.GuildBankSelectorOnMouseWheelG ~= nil then
  174.             GUILDBANK_SELECT_POPUP_GUILD:SetHandler("OnMouseWheel", function(self, delta, ctrl, alt, shift)
  175.                 origVars.GuildBankSelectorOnMouseWheelG(self, delta, ctrl, alt, shift)
  176.             end)
  177.         end
  178.     end
  179. end
  180.  
  181. -- set handlers for keyboard events:
  182. local function FCOGuildBankQuickSelect_HandleKeyboardEvents(self, key, ctrl, alt, shift, command)
  183.     --Check if the keybinding for accept or decline (or key ESCAPE) were pressed
  184.     local pressedKeyMappedToKeybindKey = -1
  185.     if key ~= KEY_ESCAPE then
  186.         pressedKeyMappedToKeybindKey = FCOGuildBankQuickSelect_GetKeybindByPressedKey(key)
  187.     end
  188.     if key == KEY_ESCAPE or pressedKeyMappedToKeybindKey ~= -1 then
  189.         if pressedKeyMappedToKeybindKey == 1 then
  190.             if GUILDBANK_SELECT_POPUP_ACCEPT.clickSound ~= nil then
  191.                 PlaySound(GUILDBANK_SELECT_POPUP_ACCEPT.clickSound)
  192.             else
  193.                 PlaySound(SOUNDS.DIALOG_ACCEPT)
  194.             end
  195.             GUILDBANK_SELECT_POPUP_ACCEPT:callback()
  196.         elseif key == KEY_ESCAPE or pressedKeyMappedToKeybindKey == 2 then
  197.             if GUILDBANK_SELECT_POPUP_ABORT.clickSound ~= nil then
  198.                 PlaySound(GUILDBANK_SELECT_POPUP_ABORT.clickSound)
  199.             else
  200.                 PlaySound(SOUNDS.DIALOG_DECLINE)
  201.             end
  202.             GUILDBANK_SELECT_POPUP_ABORT:callback()
  203.         end
  204.     else
  205.         --Check for the pressed key 1 to 5 or numpad 1 to 5 and change the guild accordingly
  206.         if key == KEY_1 or key == KEY_NUMPAD1 then
  207.             FCOGuildBankQuickSelect_SelectGuildEntry(nil, 1)
  208.         elseif key == KEY_2 or key == KEY_NUMPAD2 then
  209.             FCOGuildBankQuickSelect_SelectGuildEntry(nil, 2)
  210.         elseif key == KEY_3 or key == KEY_NUMPAD3 then
  211.             FCOGuildBankQuickSelect_SelectGuildEntry(nil, 3)
  212.         elseif key == KEY_4 or key == KEY_NUMPAD4 then
  213.             FCOGuildBankQuickSelect_SelectGuildEntry(nil, 4)
  214.         elseif key == KEY_5 or key == KEY_NUMPAD5 then
  215.             FCOGuildBankQuickSelect_SelectGuildEntry(nil, 5)
  216.         end
  217.     end
  218.     return false
  219. end
  220.  
  221. --
  222. local function FCOGuildBankQuickSelect_ChangeTweaks(doRegister)
  223.     if doRegister then
  224.         if GUILDBANK_SELECT_POPUP ~= nil then
  225.             --Register the OnKeyUp function for the guild bank select dialog
  226.             ZO_PreHookHandler(GUILDBANK_SELECT_POPUP, 'OnKeyUp', function(self, key, ctrl, alt, shift, command) FCOGuildBankQuickSelect_HandleKeyboardEvents(self, key, ctrl, alt, shift, command) end)
  227.             --GUILDBANK_SELECT_POPUP:SetHandler("OnKeyUp", function(self, key, ctrl, alt, shift, command) FCOGuildBankQuickSelect_HandleKeyboardEvents(self, key, ctrl, alt, shift, command) end)
  228.             FCOGuildBankQuickSelect_HandleMouseWheelEvents(true)
  229.             GUILDBANK_SELECT_POPUP:SetKeyboardEnabled(true)
  230.             addonVars.hookedGuildSelectDialog = true
  231.         end
  232.     else
  233.     if GUILDBANK_SELECT_POPUP ~= nil then
  234.         --Unregister OnKeyUp callback
  235.         if origVars.GuildBankSelectorOnKeyUp and origVars.GuildBankSelectorOnKeyUp ~= nil then
  236.             GUILDBANK_SELECT_POPUP:SetHandler("OnKeyUp", function(self, key, ctrl, alt, shift, command) origVars.GuildBankSelectorOnKeyUp(self, key, ctrl, alt, shift, command) end)
  237.         end
  238.         FCOGuildBankQuickSelect_HandleMouseWheelEvents(false)
  239.         GUILDBANK_SELECT_POPUP:SetKeyboardEnabled(false)
  240.         addonVars.hookedGuildSelectDialog = false
  241.         end
  242.     end
  243. end
  244.  
  245. --un/register guild bank selection popup tweaks
  246. local function registerGuildBankSelectionTweaks(doRegister, doOverride)
  247.     doOverride = doOverride or false
  248.     --If no guilds are given the functions make no sense here, so abort everything
  249.     local maxIndex = -1
  250.     if not doOverride then
  251.         if GUILDBANK_SELECT_POPUP_GUILD_COMBOBOX ~= nil then
  252.             maxIndex = #GUILDBANK_SELECT_POPUP_GUILD_COMBOBOX.m_sortedItems
  253.         end
  254.         if maxIndex == nil or maxIndex < 1 then
  255.             --Unregister existing tweaks now
  256.             FCOGuildBankQuickSelect_ChangeTweaks(false)
  257.             --Abort here as no guilds are enabled
  258.             return false
  259.         end
  260.     end
  261.     --Enable or disable the tweaks now
  262.     FCOGuildBankQuickSelect_ChangeTweaks(doRegister)
  263. end
  264.  
  265. --==============================================================================
  266. --==================== START EVENT CALLBACK FUNCTIONS===========================
  267. --==============================================================================
  268.  
  269. --[[
  270. --Event function if guild bank is opened
  271. local function FCOGuildBankQuickSelect_Open_Guild_Bank()
  272.     if not addonVars.hookedGuildSelectDialog then
  273.         registerGuildBankSelectionTweaks(true, false)
  274.     end
  275. end
  276. ]]
  277.  
  278. --Event function if guild bank is closed
  279. local function FCOGuildBankQuickSelect_Close_Guild_Bank()
  280.     if addonVars.hookedGuildSelectDialog then
  281.         registerGuildBankSelectionTweaks(false, false)
  282.     end
  283. end
  284.  
  285. --PreHook the OnShow callback function of the guildbank select dialog
  286. local function FCOGuildBankQuickSelect_PreHookGuildSelectDialogOnShow(self)
  287.     --Reset the variable for the currently selected guild index
  288.     addonVars.currentSelectedGuildNumber = -1
  289.     if not addonVars.hookedGuildSelectDialog then
  290.         registerGuildBankSelectionTweaks(true, false)
  291.     end
  292. end
  293.  
  294. -- Fires each time after addons were loaded and player is ready to move (after each zone change too)
  295. local function FCOGuildBankQuickSelect_Player_Activated(...)
  296.     --Prevent this event to be fired again and again upon each zone change
  297.     EVENT_MANAGER:UnregisterForEvent(addonVars.gAddonName, EVENT_PLAYER_ACTIVATED)
  298.  
  299.     --Backup the original handlers
  300.     --origVars.GuildBankSelectorOnKeyDown      = GUILDBANK_SELECT_POPUP:GetHandler("OnKeyDown")
  301.     origVars.GuildBankSelectorOnKeyUp        = GUILDBANK_SELECT_POPUP:GetHandler("OnKeyUp")
  302.     origVars.GuildBankSelectorOnMouseWheelMU = GUILDBANK_SELECT_POPUP_MODAL_UNDERLAY:GetHandler("OnMouseWheel")
  303.     origVars.GuildBankSelectorOnMouseWheelG  = GUILDBANK_SELECT_POPUP_GUILD:GetHandler("OnMouseWheel")
  304.  
  305.     --PreHook the OnShow handler for the guild bank select dialog
  306.     ZO_PreHookHandler(GUILDBANK_SELECT_POPUP, 'OnShow', function(self) FCOGuildBankQuickSelect_PreHookGuildSelectDialogOnShow(self) end)
  307.  
  308.     --Set addon loaded = false
  309.     addonVars.gAddonLoaded = false
  310. end
  311.  
  312. --==============================================================================
  313. --===== HOOKS BEGIN ============================================================
  314. --==============================================================================
  315. --Create the hooks & pre-hooks
  316. local function CreateHooks()
  317. --nothing here atm
  318. end
  319.  
  320. --Addon loads up
  321. local function FCOGuildBankQuickSelect_Loaded(eventCode, addOnName)
  322.     --Is this addon found?
  323.     if(addOnName ~= addonVars.gAddonName) then
  324.         return
  325.     end
  326.     --Unregister this event again so it isn't fired again after this addon has beend reckognized
  327.     EVENT_MANAGER:UnregisterForEvent(addonVars.gAddonName, EVENT_ADD_ON_LOADED)
  328.  
  329.     --Register for Guild Bank opened & closed
  330.     --EVENT_MANAGER:RegisterForEvent(addonVars.gAddonName, EVENT_OPEN_GUILD_BANK, FCOGuildBankQuickSelect_Open_Guild_Bank)
  331.     EVENT_MANAGER:RegisterForEvent(addonVars.gAddonName, EVENT_CLOSE_GUILD_BANK, FCOGuildBankQuickSelect_Close_Guild_Bank)
  332.  
  333.     addonVars.gAddonLoaded = true
  334. end
  335.  
  336. -- Register the event "addon loaded" for this addon
  337. local function FCOGuildBankQuickSelect_Initialized()
  338.     EVENT_MANAGER:RegisterForEvent(addonVars.gAddonName, EVENT_ADD_ON_LOADED, FCOGuildBankQuickSelect_Loaded)
  339.     --Register for the zone change/player ready event
  340.     EVENT_MANAGER:RegisterForEvent(addonVars.gAddonName, EVENT_PLAYER_ACTIVATED, FCOGuildBankQuickSelect_Player_Activated)
  341. end
  342.  
  343.  
  344. --------------------------------------------------------------------------------
  345. --- Call the start function for this addon to register events etc.
  346. --------------------------------------------------------------------------------
  347. FCOGuildBankQuickSelect_Initialized()

Last edited by Baertram : 04/02/15 at 11:41 AM.
  Reply With Quote
04/02/15, 04:27 PM   #12
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
I glanced at the code, don't have much time have to leave for work soon...but will look at it later when I get home.
I only glanced at it and didn't have time to look for the thing you actually asked about....but I can say a couple of things I noticed so far:
I did not test any of this and didn't have much time to look at the code, so I might have overlooked something or made a type-o.

Lua Code:
  1. registerGuildBankSelectionTweaks
This entire function seems desgined to determine if there is more than one guild in the popup guild selector drop down box and if so to enable your addons selection tweaks. Correct?

Couldn't this replace that entire function?
Lua Code:
  1. GetNumGuilds()
The number of guilds that they are in, will be the number of guilds in that pop-up box right?

This might also make your life easier. I see a lot of manipulation with the combo box & other things to mess with getting/setting the selected guild. You don't need to do any of that, I believe this will allow you to eliminate a LOT of code...you can use:
Lua Code:
  1. GetSelectedGuildBankId()
  2. SelectGuildBank(guildId)

Again I only glanced at it, but I think those few things could take place of several functions it looks like. Here are a coupld of examples:
Lua Code:
  1. -- Instead of all of the code in: registerGuildBankSelectionTweaks
  2. -- Notice this code does so little it may (or may not i didn't look where its called from) not even be necessary:
  3. -- also note:
  4. -- I used < 2, because if there is only 1 guild to select from, theres no need to scroll or select anything
  5. -- The 1 & ONLY guild your in will already be selected and there is no other guild to select so there is
  6. -- no need for your code to be running
  7. -- I left out the doOverride, because I didn't see it get called anywhere with doOverride == true
  8. -- and I didn't have enough time to look at it further.
  9. local function registerGuildBankSelectionTweaks(doRegister)
  10.    if GetNumGuilds() < 2 then
  11.        FCOGuildBankQuickSelect_ChangeTweaks(false)
  12.    return false
  13.    end
  14.  
  15.    --Enable or disable the tweaks now
  16.    FCOGuildBankQuickSelect_ChangeTweaks(true)
  17. end

I see a lot of code dealing with the last index of the combo box. I'm guessing that allows the user to scroll from the last guild in the list to the first. You could probably get rid of that function entirely...and replace it with something like this:
Lua Code:
  1. -- I would just pass the scroll wheels delta directly to this function (or just get rid of it entirely).
  2. -- Note: For keypresses you can just call SelectGuildBank(guildId) inside of  FCOGuildBankQuickSelect_HandleKeyboardEvents
  3. --    Where the guildId's are the order they appear in, the same numbers your grabbing anyhow: 1, 2, 3, 4
  4. -- GetSelectedGuildBankId() gives us the currently selected guild bank id. They are numberd 1 to GetNumGuilds()
  5. -- GetSelectedGuildBankId-1 changes the table indices to start at 0 (to match the modulus results)
  6. -- The delta, can just be added to that selected guild id
  7. -- the % is the modulus symbol:   a % b, divides a by b and then gives us the remainder.
  8. -- It would handle scrolling from the end of the list to the beginning of the list, and vice-versa, for you.
  9. -- the +1 on the end switches it back to base 1, giving us a range from 1 to numGuilds
  10. local function FCOGuildBankQuickSelect_SelectGuildEntry(delta)
  11.     local numGuilds = GetNumGuilds()
  12.     local newIndex = (GetSelectedGuildBankId() - 1  + delta) % numGuilds + 1
  13.  
  14.     SelectGuildBank(newIndex)
  15. end

Last edited by circonian : 04/02/15 at 04:31 PM.
  Reply With Quote
04/02/15, 05:04 PM   #13
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,959
Thx for the info about GetNumGuilds() and the other functions.

One question:
SelectGuildBank(guild id)

Will this change the guild bank directly or do I have to accept the selected guild before it changes it?
  Reply With Quote
04/02/15, 09:04 PM   #14
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Originally Posted by Baertram View Post
Thx for the info about GetNumGuilds() and the other functions.

One question:
SelectGuildBank(guild id)

Will this change the guild bank directly or do I have to accept the selected guild before it changes it?
EDIT: My bad I thought i tested this earlier.....SelectGuildBank(..) does apparently automatically change the guild bank. I just tried it again & it does.

Also I don't think you need these. They return nil, so I don't think they have those handlers by default, so I don't think theres anything to restore later.
Lua Code:
  1. origVars.GuildBankSelectorOnKeyUp        = GUILDBANK_SELECT_POPUP:GetHandler("OnKeyUp")
  2. origVars.GuildBankSelectorOnMouseWheelG  = GUILDBANK_SELECT_POPUP_GUILD:GetHandler("OnMouseWheel")

Last edited by circonian : 04/02/15 at 09:54 PM.
  Reply With Quote
04/02/15, 11:02 PM   #15
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Originally Posted by Baertram View Post
Thx for the info about GetNumGuilds() and the other functions.

One question:
SelectGuildBank(guild id)

Will this change the guild bank directly or do I have to accept the selected guild before it changes it?
When I got home and had a better chance to look at everything I decided that these:
Lua Code:
  1. GetSelectedGuildBankId()
  2. SelectGuildBank(guildId)
Are not the best solution. I sent you a PM about it.
  Reply With Quote
04/04/15, 04:44 PM   #16
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,959
I've just added them so they will be compatible in the future with other addons playing around with these functions. But as I replace them with mine they shouldn't be necessary I guess, you are right

Originally Posted by circonian View Post
EDIT: My bad I thought i tested this earlier.....SelectGuildBank(..) does apparently automatically change the guild bank. I just tried it again & it does.

Also I don't think you need these. They return nil, so I don't think they have those handlers by default, so I don't think theres anything to restore later.
Lua Code:
  1. origVars.GuildBankSelectorOnKeyUp        = GUILDBANK_SELECT_POPUP:GetHandler("OnKeyUp")
  2. origVars.GuildBankSelectorOnMouseWheelG  = GUILDBANK_SELECT_POPUP_GUILD:GetHandler("OnMouseWheel")
  Reply With Quote

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

Thread Tools
Display Modes

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