Thread Tools Display Modes
05/25/14, 09:09 PM   #1
Vuelhering
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 169
LibAddonmenu question

How do I hook into the "[X] Defaults" keystroke at the bottom of the menu? It looks like it's difficult to remove that button, although looks like you can add others.

I want to be able to set the defaults, and not sure how to do that.
  Reply With Quote
05/25/14, 09:17 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
LAM doesn't support the defaults button. The script run by that button when it is clicked is more than just "here's a default value! ".

Unfortunately, that Defaults button has been a PITA to hide/remove/disable the keybind/etc. LAM-2.0 will have defaults support.
  Reply With Quote
05/25/14, 09:27 PM   #3
Vuelhering
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 169
I don't mind not hiding it... just curious if there's a known way to hook into it so I can call my own routines. (Doesn't have to be through LAM, I don't mind hooking into the base UI.)

Finally got the tooltip thing handled although I haven't been able to figure out how to read it.

The defaults button was one of those things left that's bugging me, though.

Thanks!

Last edited by Vuelhering : 05/25/14 at 09:40 PM.
  Reply With Quote
05/26/14, 06:17 AM   #4
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by Vuelhering View Post
I don't mind not hiding it... just curious if there's a known way to hook into it so I can call my own routines. (Doesn't have to be through LAM, I don't mind hooking into the base UI.)

Finally got the tooltip thing handled although I haven't been able to figure out how to read it.

The defaults button was one of those things left that's bugging me, though.

Thanks!
Check X4D Chat addon code, it seem that Wilson0x4d found a way how to do it.

Lua Code:
  1. ZO_PreHook("ZO_OptionsWindow_ChangePanels", function(panel)
  2.     if (panel == yourPanelId) then
  3.         ZO_OptionsWindowResetToDefaultButton:SetCallback(function()
  4.             --your code here
  5.         end)
  6.     end
  7. end)
  Reply With Quote
05/26/14, 01:07 PM   #5
Vuelhering
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 169
Excellent! *tents fingers*
  Reply With Quote
05/27/14, 12:08 AM   #6
lyravega
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 93
Below, I'll paste a code block that might help you. I'll add comments to show what I am doing, and why in that block.

Lua Code:
  1. local function QB_SettingsMenu()
  2. --this is my function that sets up the settings menu
  3.     local LAM = LibStub:GetLibrary( "LibAddonMenu-1.0" )
  4.    
  5.     local QB_SettingsPanelID = LAM:CreateControlPanel( "QB_Config", "|cFFD700Quest Buddy|r" )
  6.     --here I define the panel ID
  7.    
  8.     local defaultText = ZO_OptionsWindowResetToDefaultButtonNameLabel:GetText()
  9.     local applyText = ZO_OptionsWindowApplyButtonNameLabel:GetText()
  10.     --these two locals are necessary if you are going to change the default texts
  11.  
  12.     ZO_PreHook("ZO_OptionsWindow_ChangePanels", function(panel)    
  13.         if (panel == QB_SettingsPanelID) then
  14.             ZO_OptionsWindowResetToDefaultButton:SetHidden(false)
  15.             --I'd like to use this apply button as well
  16.             ZO_OptionsWindowResetToDefaultButton:SetKeybindEnabled(false)
  17.             --this has no effect for some reason, need to look a bit more for this
  18.             ZO_OptionsWindowResetToDefaultButtonKeyLabel:SetHidden(true)
  19.             --since above has no effect, we hide the button here
  20.             ZO_OptionsWindowResetToDefaultButtonNameLabel:SetText("Reset to Defaults")
  21.             --we change text with this if we so desire
  22.            
  23.             --same stuff goes for the apply button as well which you can see below
  24.             ZO_OptionsWindowApplyButton:SetHidden(false)
  25.             ZO_OptionsWindowApplyButton:SetKeybindEnabled(false)
  26.             ZO_OptionsWindowApplyButtonKeyLabel:SetHidden(true)
  27.             ZO_OptionsWindowApplyButtonNameLabel:SetText("Apply Changes")
  28.        
  29.             --below is the callback function for apply button
  30.             --which is merely a ReloadUI for my add-on
  31.             ZO_OptionsWindowApplyButton:SetCallback(function()
  32.                 ReloadUI()
  33.             end)
  34.            
  35.             --below is the function for the defaults button
  36.             --which resets everything to the default values
  37.             ZO_OptionsWindowResetToDefaultButton:SetCallback(function()
  38.                 for variable, value in next, QB_defaults do
  39.                     QB_vars[variable] = value
  40.                 end
  41.                 ReloadUI()
  42.             end)
  43.        
  44.         --the ELSE below is IMPORTANT if you are changing the texts and/or hiding the keybind icons
  45.         --what this part does is just reverting everything back to "vanilla"
  46.         else
  47.             ZO_OptionsWindowResetToDefaultButton:SetKeybindEnabled(true)
  48.             ZO_OptionsWindowResetToDefaultButtonKeyLabel:SetHidden(false)
  49.             ZO_OptionsWindowResetToDefaultButtonNameLabel:SetText(defaultText)
  50.             --defaultText is used here, which was stored prior to the change
  51.            
  52.             ZO_OptionsWindowApplyButton:SetKeybindEnabled(true)
  53.             ZO_OptionsWindowApplyButtonKeyLabel:SetHidden(false)
  54.             ZO_OptionsWindowApplyButtonNameLabel:SetText(applyText)
  55.         end
  56.     end)
  57.    
  58.         local QB_Main = LAM:AddHeader(QB_SettingsPanelID, "QB_Description", "")
  59.         --we need to define a variable name for a header, preferably for the first one
  60.         --because LAM hides these reset buttons while setting up headers, for some reason
  61.         --and then sets handlers, which hides the buttons
  62.        
  63.         QB_Main:SetHandler("OnShow", function() return end)
  64.         QB_Main:SetHandler("OnHide", function() return end)
  65.         --these two above are necessary, we are basically overriding what LAM is doing here
  66.         --if you don't do this, the reset button will stay hidden
  67.  
  68. ... --rest of the menu stuff goes here

Result:


For vanilla menus, the texts will be reverted back, as well as the hidden keybind buttons. For other menus created with LAM, they will keep their hidden stuff. As I've said above, keybinds cannot be disabled for some reason (try pressing "Apply" key or "Defaults" key while navigating a LAM menu); only their icons are disabled, not their functions, I'm sure Seerah will find the reason soon enough with 2.0 or something

If anyone know how to change a keybinding via API, then changing that keybinding temporarily or unbinding would help (run "/script d(ZO_Keybindings_GetBindingStringFromAction("OPTIONS_APPLY_CHANGES"))" this is the problem). Also this code above has one problem; when you open your add-on menu, it will also override vanilla stuff, so lets say you changed defaults button and now it simply just runs a d() function, after looking at your menu then vanilla menus and clicking defaults button will also run that function.

Off-topic, for some reason LAM tries to show/hide the reset buttons under "AddHeader". It has handlers for OnShow and OnHide, but they do not work as intended I believe. I'll contact Seerah about these, but for now this is more or less how you can modify the vanilla buttons for your options menu that is created with LAM.

Last edited by lyravega : 05/27/14 at 01:01 AM.
  Reply With Quote
05/27/14, 01:57 PM   #7
Aicam
Join Date: Apr 2014
Posts: 16
Do something like the following and you will notice that the callback of the button has nothing to do with the action triggered with the keybind.
Lua Code:
  1. ZO_OptionsWindowResetToDefaultButton:SetCallback( function() d( "Hello World" ) end )
The only option i see is to hook into ZO_Dialogs_ShowDialog( name, ... ).
I just don't think this is a really good idea unless you know all possible dialog names.
  Reply With Quote
05/28/14, 08:08 PM   #8
Vuelhering
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 169
Originally Posted by lyravega View Post
Below, I'll paste a code block that might help you. I'll add comments to show what I am doing, and why in that block.
lyravega, thanks for the code; I'll check that out!

Originally Posted by Aicam View Post
the callback of the button has nothing to do with the action triggered with the keybind. [...] The only option i see is to hook into ZO_Dialogs_ShowDialog( name, ... ).
I just don't think this is a really good idea unless you know all possible dialog names.
You could simply hook into it and ignore anything that isn't one of your dialogs.
  Reply With Quote
05/29/14, 05:43 AM   #9
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by Aicam View Post
Do something like the following and you will notice that the callback of the button has nothing to do with the action triggered with the keybind.
Lua Code:
  1. ZO_OptionsWindowResetToDefaultButton:SetCallback( function() d( "Hello World" ) end )
The only option i see is to hook into ZO_Dialogs_ShowDialog( name, ... ).
I just don't think this is a really good idea unless you know all possible dialog names.
It's true that code I have posted before did not store original callback, so it won't work the way we want. lyravega's code does not cause issues just because he calls ReloadUI() from the callback.

So I was digging around and I found that dialog displayed from the callback is "OPTIONS_RESET_TO_DEFAULTS" and from this dialog is called function ZO_OptionsWindow_LoadDefaults(). So maybe hook this function?

Lua Code:
  1. ZO_PreHook("ZO_OptionsWindow_LoadDefaults",
  2.    function(control)
  3.       if ZO_OptionsWindow.currentPanel == yourPanelId then
  4.          --your code
  5.          return true --true means that ZO_PreHook will not call original function
  6.       end
  7.       return false
  8.    end)
  Reply With Quote
05/29/14, 06:11 AM   #10
lyravega
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 93
Originally Posted by Garkin View Post
It's true that code I have posted before did not store original callback, so it won't work the way we want. lyravega's code does not cause issues just because he calls ReloadUI() from the callback.

So I was digging around and I found that dialog displayed from the callback is "OPTIONS_RESET_TO_DEFAULTS" and from this dialog is called function ZO_OptionsWindow_LoadDefaults(). So maybe hook this function?

Lua Code:
  1. ZO_PreHook("ZO_OptionsWindow_LoadDefaults",
  2.    function(control)
  3.       if ZO_OptionsWindow.currentPanel == yourPanelId then
  4.          --your code
  5.          return true --true means that ZO_PreHook will not call original function
  6.       end
  7.       return false
  8.    end)
How did you find the function from a dialogue :s Looks interesting, will try some stuff out
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » LibAddonmenu question

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