Thread Tools Display Modes
02/13/21, 11:52 PM   #1
ShadowMau
AddOn Author - Click to view addons
Join Date: Oct 2018
Posts: 23
LibAddonMenu update optionsData

I have a situation where I want to do may not be possible. I want to be able to dynamically update the optionsData. I have looked at the wiki at https://github.com/sirinsidiator/ESO-LibAddonMenu/wiki but I can't see what I am looking for. Maybe I am looking in the wrong spot. Any help would be appreciated. Here is what I am trying to accomplish.

Say I have a dropdown list with the following values: Blue, Green, Red, Yellow. When the person selects a color, that color is no longer available. So if the person selects Red, then the new dropdown values should be Blue, Green, Yellow. Red is no longer available because it has already been "used."

I am not asking about the functions that are processing the choice, I am asking how to I tell LAM that there is an updated optionsData table to use? Am I asking the impossible?

I did find a similar post https://www.esoui.com/forums/showthr...t=LibAddonMenu. I kinda understand, but my little brain could not figure out exactly what all that meant. Is there somewhere that has a nice simple working example I can learn from?
  Reply With Quote
02/13/21, 11:58 PM   #2
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 626
The dropdown uses a table for the values. A table can be altered but that would mean manipulating the table used. I'm not sure that is impossible but probably not what is intended.

https://github.com/sirinsidiator/ESO.../wiki/Controls
  Reply With Quote
02/14/21, 12:04 AM   #3
ShadowMau
AddOn Author - Click to view addons
Join Date: Oct 2018
Posts: 23
Originally Posted by Sharlikran View Post
The dropdown uses a table for the values. A table can be altered but that would mean manipulating the table used. I'm not sure that is impossible but probably not what is intended.

https://github.com/sirinsidiator/ESO.../wiki/Controls
I can easily change the table data (ie table.insert or table.remove) to create a new optionsData table, but since the optionsData table has already been passed to LAM at the time it was created, now do I tell LAM there is now a new optionsData table to use?
  Reply With Quote
02/14/21, 12:24 AM   #4
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 626
Granted I'm not going in game and doing this to test but unless LAM can't use the new table once you initialize it then I don't see why LAM wouldn't use the modified table.

Code:
function ManipulateTable()
  <<you have to put your own code here>>
  return TableOfValues
end

local panelData = {
  <<snip>>
  registerForRefresh  = true,
}

local optionsData = {
  [1]  = {
    choices = yourManipulatedTable()
    choicesValues = yourManipulatedTable()
    setFunc = function(value)
      YourColor = value
      ManipulateTable()
    end,
  },
  [2]  = {
    choices = yourManipulatedTable()
    choicesValues = yourManipulatedTable()
    setFunc = function(value)
      YourOtherColor = value
      ManipulateTable()
    end,
  },
}

Last edited by Sharlikran : 02/14/21 at 10:20 AM.
  Reply With Quote
02/14/21, 12:52 AM   #5
ShadowMau
AddOn Author - Click to view addons
Join Date: Oct 2018
Posts: 23
When I first call LAM:RegisterOptionControls(panelName, optionsData), it will create the menu properly, with all the colors listed, but when I change the options in the dropdown table and try calling LAM:RegisterOptionControls(panelName, optionsData) a second time, it still uses the old table, not my new one.
  Reply With Quote
02/14/21, 01:07 AM   #6
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 626
I don't see why you would have to call RegisterOptionControls() more than once. If what I am suggesting doesn't work then you will have to wait for the author to respond. (He is in another time zone)
  Reply With Quote
02/14/21, 01:17 AM   #7
ShadowMau
AddOn Author - Click to view addons
Join Date: Oct 2018
Posts: 23
Found this thread, so it looks like it is not possible to do what I want. https://www.esoui.com/forums/showthr...t=LibAddonMenu

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
02/14/21, 06:31 AM   #8
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,566
That answer in that other thread was regarding adding and removing new controls to the menu. As long as you just want to update the existing controls, that's supported.
You simply have to tell LAM that you have changed something in the data table, otherwise it wouldn't know that the dropdown choices are now different:
Lua Code:
  1. -- make sure you can access the dropdown via a variable name:
  2. local optionsData = {
  3.  --snip--
  4.     reference = "myDropdown"
  5.   },
  6. }
  7.  
  8. -- either change the optionsData table
  9. optionsData[1].choices = newChoices
  10. myDropdown:UpdateChoices()
  11.  
  12. -- or set values independently of what is stored in the optionsData. That way you can go back to the original values later
  13. myDropdown:UpdateChoices(newChoices)
  Reply With Quote
02/14/21, 06:48 AM   #9
andy.s
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 40
Lua Code:
  1. local function choices()
  2.     return {math.random(100), math.random(100)}
  3. end
  4.  
  5. {
  6.     type = "dropdown",
  7.     -- name, getFunc, etc...
  8.     setFunc = function(value)
  9.         MyAddonDropdown:UpdateChoices(choices(), choices())
  10.     end,
  11.     choices = choices(),
  12.     choicesValues = choices(),
  13.     reference = "MyAddonDropdown",
  14. },

This code randomizes MyAddonDropdown items every time you select something.
  Reply With Quote
02/14/21, 10:17 AM   #10
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 626
Sirinsidiator just gave an example of what could be used.

Last edited by Sharlikran : 02/14/21 at 02:09 PM.
  Reply With Quote
02/14/21, 12:24 PM   #11
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
@ShadowMau
If you want to work with 2 lists where 1 contains entries, and if you select some they will be moved to the other 2nd list (of chosen entries), have a look at
LibShifterBox.

It is not added to LAM directly but you can easily use LibAddonMenu's customControl type (the SetpFunction callback) to add a LibShifterBox to your addon settings panel.

Last edited by Baertram : 02/14/21 at 04:29 PM.
  Reply With Quote
02/14/21, 02:11 PM   #12
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 626
Baertram he wants to use a dropdown that is dynamically rebuilt depending on which choices have been used. He doesn't want people to choose the same option twice.
  Reply With Quote
02/14/21, 02:20 PM   #13
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
Originally Posted by Sharlikran View Post
Baertram he wants to use a dropdown that is dynamically rebuilt depending on which choices have been used. He doesn't want people to choose the same option twice.
Yes and this is what LibShifterBox also provides, just not as a combobox with dropdown but 2 lists where you "move" entries from left (All entries) to right (chosen entries). You are also able to react on a move and rebuild the list entries if you need to, but if you just want to assure there is nothing selected twice, this is a perfect control for that purpose.

I'm only pointing to the possibilities there, whatever will be chosen to be used in the end is up to ShadowMau.
  Reply With Quote
02/14/21, 03:14 PM   #14
ShadowMau
AddOn Author - Click to view addons
Join Date: Oct 2018
Posts: 23
Thank You

Thank you all for your ideas and suggestions. Between @sirinsidiator telling me about :UpdateChoices, and the example from @andy.s I learned what I needed to make what I wanted to do work.

Also thank you to @Baertram, you have been very helpful. This was just a proof of concept example so your LibShifterBox does not apply to what I am trying to do with my actual application. I will, however, be downloading LibShifterBox and taking a look at it so I can learn more.
  Reply With Quote
03/15/21, 11:15 AM   #15
ShadowMau
AddOn Author - Click to view addons
Join Date: Oct 2018
Posts: 23
For those who are interested, what I learned was ultimately used in LinkPetToMount. I then turned around an used the same idea for FavoritePet and FavoriteMount. For both FavoritePet and FavoriteMount, I could also have used the LibShifterBox.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » LibAddonMenu update optionsData

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