ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   Dynamic Menu with LibAddonMenu (https://www.esoui.com/forums/showthread.php?t=8883)

MethosFrost 12/09/19 10:34 PM

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. :confused:


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

Baertram 12/10/19 01:41 AM

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.

sirinsidiator 12/10/19 03:06 AM

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.

votan 12/10/19 03:06 AM

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.

MethosFrost 12/10/19 06:24 PM

Quote:

Originally Posted by votan (Post 39842)
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.


All times are GMT -6. The time now is 05:17 AM.

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