View Single Post
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