Thread Tools Display Modes
07/23/14, 04:09 AM   #1
Migoda
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 18
LAM-2.0 control creation

Hey all,

i have two addons running that still use LAM-1.0 and it does not look that they will get an update to version 2 in the near future. So i tried updating them on my own, but got stuck at some point.

I read the guides provided for LAM-2.0 but with my little coding experience in LUA i could not figure out how to create controls dynamically. One of the addons creates some editboxes using a for loop and LAM:AddEditBox. How would i do that in LAM-2.0? I have just used LAM2:RegisterOptionControls and that static options table so far.

Thanks in advance!
  Reply With Quote
07/23/14, 04:34 AM   #2
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
You can build the options table incrementally with table.insert. Here's is how I create 5 checkboxes for guilds in a loop, with uninteresting parts stripped off. Hope it helps
Lua Code:
  1. local function mkoptGuildCheckbox(guildIndex)
  2.     return {
  3.         type = "checkbox",
  4.         name = GetGuildName(GetGuildId(guildIndex)),
  5.         getFunc = function() ... end,
  6.         setFunc = function(value) ... end,
  7.         disabled = function()
  8.             local guildId = GetGuildId(guildIndex)
  9.             return not guildId or guildId == 0
  10.         end,
  11.     }
  12. end
  13.  
  14. local function iniOptionControls()
  15.     local optionsData = {}
  16.     for guildIndex = 1, MAX_GUILDS do
  17.         table.insert(optionsData, mkoptGuildCheckbox(guildIndex))
  18.     end
  19.     LAM:RegisterOptionControls(MYSETTINGSNAME, optionsData)
  20. end
  Reply With Quote
07/23/14, 01:26 PM   #3
zgrssd
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 280
Originally Posted by Migoda View Post
Hey all,

i have two addons running that still use LAM-1.0 and it does not look that they will get an update to version 2 in the near future. So i tried updating them on my own, but got stuck at some point.

I read the guides provided for LAM-2.0 but with my little coding experience in LUA i could not figure out how to create controls dynamically. One of the addons creates some editboxes using a for loop and LAM:AddEditBox. How would i do that in LAM-2.0? I have just used LAM2:RegisterOptionControls and that static options table so far.

Thanks in advance!
The easiest way to go from LAM 1 to LAM 2 is this interface Library:
http://www.esoui.com/downloads/info5...Interface.html

It takes your LAM 1.0 commands, the LAM 2.0 files and makes a proper LAM 2 style menu out of it.
Asuming you are not doing anything special with those elements it should work just fine.
  Reply With Quote
07/23/14, 07:40 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
Or this...
Lua Code:
  1. local controlTemplate = {
  2.         type = "checkbox",
  3.         name = GetGuildName(GetGuildId(guildIndex)),
  4.         getFunc = function() ... end,
  5.         setFunc = function(value) ... end,
  6.         disabled = function()
  7.             local guildId = GetGuildId(guildIndex)
  8.             return not guildId or guildId == 0
  9.         end,
  10.     }
  11.  
  12. local addonOptions = {
  13.         [1] = controlTemplate,
  14.         [2] = controlTemplate
  15. }
  Reply With Quote
07/24/14, 03:29 AM   #5
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Originally Posted by Seerah View Post
Or this...
Lua Code:
  1. local controlTemplate = {
  2.         type = "checkbox",
  3.         name = GetGuildName(GetGuildId(guildIndex)),
  4.         getFunc = function() ... end,
  5.         setFunc = function(value) ... end,
  6.         disabled = function()
  7.             local guildId = GetGuildId(guildIndex)
  8.             return not guildId or guildId == 0
  9.         end,
  10.     }
  11.  
  12. local addonOptions = {
  13.         [1] = controlTemplate,
  14.         [2] = controlTemplate
  15. }
This alone won't work. You'd need to set addonOptions[i].name and addonOptions[i].disabled in a loop anyway, otherwise the name would be just empty string, and disabled() would always return true. My mkoptGuildCheckbox() constructor returns a table with .name filled, and more importantly, creates a closure containing guildIndex, so that all functions (getFunc, setFunc, disabled) have guildIndex of the guild they shall work with.
  Reply With Quote
07/24/14, 03:10 PM   #6
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
Right. I was just showing what is possible to the OP.
  Reply With Quote
07/25/14, 01:49 AM   #7
Migoda
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 18
Thanks for your responses and the examples, i appreciate them .

Got a little problem with LAM:RegisterAddonPanel yesterday, producing an Failed to create control (Duplicate Name) error. Any idea what i am doing wrong? The name i used is definitely unique.
  Reply With Quote
07/25/14, 03:09 AM   #8
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by Migoda View Post
Thanks for your responses and the examples, i appreciate them .

Got a little problem with LAM:RegisterAddonPanel yesterday, producing an Failed to create control (Duplicate Name) error. Any idea what i am doing wrong? The name i used is definitely unique.
This UI error is shown if some addon registers panels before library is updated. Make sure that you don't register settings panel sooner then in EVENT_ADD_ON_LOADED handler.

By the way this issue is fixed in r13: http://www.esoui.com/portal.php?id=5...wbug&bugid=966

Last edited by Garkin : 07/25/14 at 03:14 AM.
  Reply With Quote

ESOUI » AddOns » AddOn Help/Support » LAM-2.0 control creation


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