Thread Tools Display Modes
12/09/19, 10:34 PM   #1
MethosFrost
AddOn Author - Click to view addons
Join Date: Dec 2018
Posts: 5
Dynamic Menu with LibAddonMenu

Still learning so I hope the answer isn't obvious. I'm testing creating a dynamic menu using LibAddonMenu and I can get the menu to show up with no errors but I'm having an issue when it comes to the get/set. I'm unable to get them to properly read or assign the settings. I'm 90% sure that the issue is getting the "functionGet/functionSet" functions to be uniform and not have part of it be a string just not sure how to accomplish.


The functions I'm using to create the menu are:
Lua Code:
  1. local function CheckboxMenuAdd(settingName)
  2.     local set = settingName
  3.     local setting = AllCraft_Decon.deconSettings
  4. --Find a way to get this to populate properly, Answer is always nil
  5.     local functionGet =  function() return setting.set end
  6.     local functionSet = function(value) setting.set = value end
  7.  
  8.     local x = {}
  9.         x.type = "checkbox"
  10.         x.name = tostring(settingName)
  11.         x.getFunc = functionGet
  12.         x.setFunc = functionSet
  13.     return x
  14. end
  15.  
  16. function ACLoadMenu()
  17.     local t = getmetatable(AllCraft_Decon.deconSettings).__index
  18.     local setting = AllCraft_Decon.deconSettings
  19.     local menu = {type = "submenu",
  20.     name = "Table Options",
  21.     controls = {}}
  22.  
  23.     for key, value in pairs(t) do
  24.         if key ~= "version" then
  25.             if string.find( key,"Deconstruct_Set_Type_") then
  26.                 table.insert (menu.controls, CheckboxMenuAdd(key))
  27.             end
  28.         end
  29.     end
  30.     return menu
  31. end

FullCode@ https://github.com/MethosFrost/AllCraft
  Reply With Quote
12/10/19, 01:41 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
No time to review your code but what I can offer is an example (a complex though!):
You can check the FCO ItemSaver code for example, file src/FCOIS_SettingsMenu.lua
In the upper part of function BuildAddonMenu you'll find several dynamically created (via loops) settings menus submenus containing checkboxes, dropdown etc.

Hope the code helps you.
  Reply With Quote
12/10/19, 03:06 AM   #3
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,566
LibAddonMenu2 wasn't made with dynamic menus in mind, so adding controls on the fly isn't easily possible. After the panel was opened the first time and all the controls are created, LAM doesn't add any new controls. So you'd have to take care of creating them yourself and since destroying controls isn't possible in ESO, you'd have to manage removing them in a way that doesn't cause a memory leak.
All in all, not something I can recommend if it can be avoided, as it could easily break on LAM updates.
  Reply With Quote
12/10/19, 03:06 AM   #4
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
You always use the same setting called "set".
I guess you want to do:
Lua Code:
  1. setting[set]

setting.set is setting["set"]. Not setting.$set like in powershell.
  Reply With Quote
12/10/19, 06:24 PM   #5
MethosFrost
AddOn Author - Click to view addons
Join Date: Dec 2018
Posts: 5
Originally Posted by votan View Post
You always use the same setting called "set".
I guess you want to do:
Lua Code:
  1. setting[set]

setting.set is setting["set"]. Not setting.$set like in powershell.
That's exactly what I was looking for, Thanks! I was unsure how to convert that out of being a string in lua.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Dynamic Menu with LibAddonMenu

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