WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   How to open addon interface options? (https://www.wowinterface.com/forums/showthread.php?t=57172)

MinguasBeef 05-27-19 01:40 AM

How to open addon interface options?
 
Edit: Shortly after making this post I found the answer. For anyone searching for the same thing, you just need to call
Code:

InterfaceOptionsFrame_OpenToCategory("ADDON NAME")
I made a panel and some options in the interface addon menu for my addon.

I can hit escape and access the addons menu from there, but I wanted to add a slash command to open up the menu automatically.

I've done this a long time ago and I forgot how I accomplished this. How would I open up the interface addon window and select a specific panel with LUA?

jeruku 05-27-19 10:03 AM

Quick note, there has been a long standing bug(?) that prevents that code from always opening to the addon. The work around I use is first calling InterfaceOptionsFrame_Show before opening the category.

Lua Code:
  1. InterfaceOptionsFrame_Show()
  2. InterfaceOptionsFrame_OpenToCategory("ADDON NAME")

Seerah 05-30-19 12:37 PM

Or you can just open to the category twice.

This usually happens if your addon is not visible in the scrollframe list on the left.

bsmorgan 10-07-21 08:32 AM

Quote:

Originally Posted by Seerah (Post 332263)
This usually happens if your addon is not visible in the scrollframe list on the left.

In Burning Crusade Classic, my addon isn't visible in the scrollframe list the first time I call:

Lua Code:
  1. InterfaceOptionsFrame_OpenToCategory("Skillet")
unless I open the panel and manually scroll to the page my addon is listed on. Other than changing my addon name to "ASkillet", is there anyway to force the scroll to happen, i.e.

Lua Code:
  1. InterfaceOptionsFrame_ScrollToCategory("Skillet")

Dridzt 10-07-21 10:30 AM

Other idea.

Lua Code:
  1. local function ScrollToCategory(panelName)
  2.   local idx
  3.   for i,cat in ipairs(INTERFACEOPTIONS_ADDONCATEGORIES) do
  4.     if not cat.hidden then
  5.       idx=(idx or 0) + 1
  6.       if cat.name == panelName then
  7.         break
  8.       end
  9.     end
  10.   end
  11.   local numbuttons = #(InterfaceOptionsFrameAddOns.buttons)
  12.   if idx and numbuttons and idx > numbuttons then
  13.     local btnHeight = InterfaceOptionsFrameAddOns.buttons[1]:GetHeight()
  14.     InterfaceOptionsFrameAddOnsListScrollBar:SetValue((idx-numbuttons)*btnHeight)
  15.   end
  16. end

Then using as
Code:

ScrollToCategory("Skillet")
.
It might need to be called on next frame after the first InterfaceOptionsFrame_OpenToCategory("Skillet")

I'm sure someone will come up with a more elegant solution.

bsmorgan 10-09-21 07:35 AM

It works!

Lua Code:
  1. function Skillet:ShowOptions()
  2.     InterfaceOptionsFrame_Show()
  3.     ScrollToCategory("Skillet")
  4.     InterfaceOptionsFrame_OpenToCategory("Skillet")
  5. end

Thank you!

Dridzt 10-09-21 07:42 AM

Quote:

Originally Posted by bsmorgan (Post 339935)
It works!

Lua Code:
  1. function Skillet:ShowOptions()
  2.     InterfaceOptionsFrame_Show()
  3.     ScrollToCategory("Skillet")
  4.     InterfaceOptionsFrame_OpenToCategory("Skillet")
  5. end

Thank you!

If you want it to "always work" and not have to complicate the method you could add a
Code:

InterfaceOptionsFrameAddOnsListScrollBar:SetValue(0)
to reset the addon list to the top as it retains the last selection for the session.

That would make it more generic so it works for addons towards the top of the list when the last addon selected was a the bottom (list is already scrolled down from a previous user action)

bsmorgan 10-09-21 08:25 AM

I modified it a little bit. Since Skillet has 3 sub-categories and as written, it always puts the main category at the bottom. I added an offset value so that once expanded, Skillet and its sub-categories were always on the screen.

Lua Code:
  1. local function ScrollToCategory(panelName,offset)
  2.     local idx = 0
  3.     InterfaceOptionsFrameAddOnsListScrollBar:SetValue(0)
  4.     for i,cat in ipairs(INTERFACEOPTIONS_ADDONCATEGORIES) do
  5.         if not cat.hidden then
  6.             idx = idx + 1
  7.             if cat.name == panelName then
  8.                 break
  9.             end
  10.         end
  11.     end
  12.     local numbuttons = #(InterfaceOptionsFrameAddOns.buttons)
  13.     if idx and numbuttons and idx > numbuttons then
  14.         local btnHeight = InterfaceOptionsFrameAddOns.buttons[1]:GetHeight()
  15.         InterfaceOptionsFrameAddOnsListScrollBar:SetValue((offset+idx-numbuttons)*btnHeight)
  16.     end
  17. end

I guess the code should worry about setting a value that exceeds the maximum.


All times are GMT -6. The time now is 11:03 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI