Quantcast
Updating optionData in LAM2 - ESOUI
Thread Tools Display Modes
08/26/21, 07:30 PM   #1
Leonardo1123
AddOn Author - Click to view addons
Join Date: Aug 2021
Posts: 19
Updating optionData in LAM2

Hey there!

My addon has a list of outfits in the LAM2 settings page. After renaming an outfit, I've noticed it doesn't update in LAM2 until you reload UI.

I tried solving it by listening to the event EVENT_OUTFIT_RENAME_RESPONSE but with no luck.

Here's my code:
Lua Code:
  1. function LeonardosWardrobeManager:Initialize()
  2.     LeonardosWardrobeManager.savedVariables = ZO_SavedVars:NewCharacterIdSettings("LeonardosWardrobeManagerVars", LeonardosWardrobeManager.variableVersion, nil, LeonardosWardrobeManager.Default, GetWorldName())
  3.  
  4.     self.inCombat = IsUnitInCombat("player")
  5.     self.inStealth = GetUnitStealthState("player")
  6.  
  7.     for i=1,GetNumUnlockedOutfits() do
  8.         self.allOutfits[i + OUTFIT_OFFSET] = GetOutfitName(0, i)
  9.     end
  10.  
  11.     LAM2:RegisterAddonPanel("LeonardosWardrobeManagerOptions", panelData)
  12.     LAM2:RegisterOptionControls("LeonardosWardrobeManagerOptions", optionsData)
  13.  
  14.     EVENT_MANAGER:RegisterForEvent(self.name, EVENT_OUTFIT_RENAME_RESPONSE, self.OnOutfitRenamed)
  15.     EVENT_MANAGER:RegisterForEvent(self.name, EVENT_ZONE_UPDATE, self.OnZoneChange)
  16.     EVENT_MANAGER:RegisterForEvent(self.name, EVENT_PLAYER_COMBAT_STATE, self.OnPlayerCombatState)
  17.     EVENT_MANAGER:RegisterForEvent(self.name, EVENT_STEALTH_STATE_CHANGED, self.OnPlayerStealthState)
  18. end

Lua Code:
  1. function LeonardosWardrobeManager.OnOutfitRenamed(_, _, index) -- TODO: Still not working
  2.     LeonardosWardrobeManager.allOutfits[index + OUTFIT_OFFSET] = GetOutfitName(index + OUTFIT_OFFSET)
  3.     optionsData[3].controls[1].choices = LeonardosWardrobeManager.allOutfits
  4.     optionsData[3].controls[2].choices = LeonardosWardrobeManager.allOutfits
  5. end

Lua Code:
  1. optionsData = {
  2.     [1] = {
  3.         type = "description",
  4.         title = nil,
  5.         text = "Warning: If you rename an outfit, you will need to reload the UI for those changes to take effect here",
  6.         width = "full",
  7.     },
  8.     [2] = {
  9.         type = "dropdown",
  10.         name = "Default Outfit",
  11.         tooltip = "The outfit to be worn by default",
  12.         choices = LeonardosWardrobeManager.allOutfits,
  13.         getFunc = function() return LeonardosWardrobeManager.savedVariables.defaultOutfit end,
  14.         setFunc = function(var) LeonardosWardrobeManager.SetStateOutfit("DEFAULT", var) end,
  15.     },
  16.     [3] = {
  17.         type = "submenu",
  18.         name = "Combat",
  19.         tooltip = "Options related to combat and stealth", --(optional)
  20.         controls = {
  21.             [1] = {
  22.                 type = "dropdown",
  23.                 name = "Combat Outfit",
  24.                 tooltip = "The outfit to be switched to upon entering combat",
  25.                 choices = LeonardosWardrobeManager.allOutfits,
  26.                 getFunc = function() return LeonardosWardrobeManager.savedVariables.combatOutfit end,
  27.                 setFunc = function(var) LeonardosWardrobeManager.SetStateOutfit("COMBAT", var) end,
  28.             },
  29.             [2] = {
  30.                 type = "dropdown",
  31.                 name = "Stealth Outfit",
  32.                 tooltip = "The outfit to be switched to upon entering stealth",
  33.                 choices = LeonardosWardrobeManager.allOutfits,
  34.                 getFunc = function() return LeonardosWardrobeManager.savedVariables.stealthOutfit end,
  35.                 setFunc = function(var) LeonardosWardrobeManager.SetStateOutfit("STEALTH", var) end,
  36.             },
  37.         }
  38.     }
  39. }
  Reply With Quote
08/27/21, 02:08 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 3,753
This forum here is about asking questions to addons, not lua example code etc.
"The place to ask general questions about developing AddOns."

Moved to the correct forum
"The place to ask specific questions relating to Lua/XML coding."

Last edited by Baertram : 08/27/21 at 02:11 AM.
  Reply With Quote
08/27/21, 02:10 AM   #3
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 3,753
There are other threads/posts about this already. Please use the forum search before posting new threads. Searching for LibAddonMenu or LAM would have provided them easily.

But basically you need to use the "reference" tag of the lam options to give it a name you can reference to.
And then use <referenceVariableOfDropdownBox>:UpdateChoices(listOfChoices, choicesValues, choicesTooltips)
choicesValues and choicesTooltips are optional. But I'd at least always provide choices and choicesValues so that the getfunc and setFunc uses the choicesValues easily, instead of having to check all entries in choices to match the string of your getFunc/setFunc parameter!

Searching for LAM or UpdateChoices (you could not know the later until now I assume :-)) will give you example forum threads, e.g.
https://www.esoui.com/forums/showthr...=UpdateChoices

I've added it to the Wiki as well now:
https://wiki.esoui.com/LibAddonMenu:...wn_box_entries

Last edited by Baertram : 08/27/21 at 02:49 AM.
  Reply With Quote
08/27/21, 12:46 PM   #4
Leonardo1123
AddOn Author - Click to view addons
Join Date: Aug 2021
Posts: 19
Hey there! Sorry for not searching, definitely will in the future! So I feel like I'm super close but there's something basic I'm not understanding. Here's my attempt to implement what you suggested:

LAM
Lua Code:
  1. optionsData = {
  2.     [1] = {
  3.         type = "description",
  4.         title = nil,
  5.         text = "Warning: If you rename an outfit, you will need to reload the UI for those changes to take effect here",
  6.         width = "full",
  7.     },
  8.     [2] = {
  9.         type = "dropdown",
  10.         name = "Default Outfit",
  11.         tooltip = "The outfit to be worn by default",
  12.         choices = LeonardosWardrobeManager.allOutfits,
  13.         getFunc = function() return LeonardosWardrobeManager.savedVariables.defaultOutfit end,
  14.         setFunc = function(var) LeonardosWardrobeManager.SetStateOutfit("DEFAULT", var) end,
  15.         reference = "LeonardosWardrobeManager_Default_Dropdown"
  16.     },
  17.     [3] = {
  18.         type = "submenu",
  19.         name = "Combat",
  20.         tooltip = "Options related to combat and stealth", --(optional)
  21.         controls = {
  22.             [1] = {
  23.                 type = "dropdown",
  24.                 name = "Combat Outfit",
  25.                 tooltip = "The outfit to be switched to upon entering combat",
  26.                 choices = LeonardosWardrobeManager.allOutfits,
  27.                 getFunc = function() return LeonardosWardrobeManager.savedVariables.combatOutfit end,
  28.                 setFunc = function(var) LeonardosWardrobeManager.SetStateOutfit("COMBAT", var) end,
  29.                 reference = "LeonardosWardrobeManager_Combat_Dropdown"
  30.             },
  31.             [2] = {
  32.                 type = "dropdown",
  33.                 name = "Stealth Outfit",
  34.                 tooltip = "The outfit to be switched to upon entering stealth",
  35.                 choices = LeonardosWardrobeManager.allOutfits,
  36.                 getFunc = function() return LeonardosWardrobeManager.savedVariables.stealthOutfit end,
  37.                 setFunc = function(var) LeonardosWardrobeManager.SetStateOutfit("STEALTH", var) end,
  38.                 reference = "LeonardosWardrobeManager_Stealth_Dropdown"
  39.             },
  40.         }
  41.     }
  42. }

Update
Lua Code:
  1. function LeonardosWardrobeManager.OnOutfitRenamed(event, response, index) -- TODO: Still not working
  2.     for i=1,GetNumUnlockedOutfits() do
  3.         LeonardosWardrobeManager.allOutfits[i + OUTFIT_OFFSET] = GetOutfitName(0, i)
  4.     end
  5.     LeonardosWardrobeManager_Default_Dropdown:UpdateChoices(LeonardosWardrobeManager.allOutfits)
  6.     LeonardosWardrobeManager_Combat_Dropdown:UpdateChoices(LeonardosWardrobeManager.allOutfits)
  7.     LeonardosWardrobeManager_Stealth_Dropdown:UpdateChoices(LeonardosWardrobeManager.allOutfits)
  8. end

Event Registers
Lua Code:
  1. ...
  2.  
  3.     LAM2:RegisterAddonPanel("LeonardosWardrobeManagerOptions", panelData)
  4.     LAM2:RegisterOptionControls("LeonardosWardrobeManagerOptions", optionsData)
  5.  
  6.     EVENT_MANAGER:RegisterForEvent(self.name, EVENT_OUTFIT_RENAME_RESPONSE, self.OnOutfitRenamed)
  7.     EVENT_MANAGER:RegisterForEvent(self.name, EVENT_PLAYER_ACTIVATED, self.OnPlayerActivated)
  8.     EVENT_MANAGER:RegisterForEvent(self.name, EVENT_PLAYER_COMBAT_STATE, self.OnPlayerCombatState)
  9.     EVENT_MANAGER:RegisterForEvent(self.name, EVENT_STEALTH_STATE_CHANGED, self.OnPlayerStealthState)
  10. end


Originally Posted by Baertram View Post
There are other threads/posts about this already. Please use the forum search before posting new threads. Searching for LibAddonMenu or LAM would have provided them easily.

But basically you need to use the "reference" tag of the lam options to give it a name you can reference to.
And then use <referenceVariableOfDropdownBox>:UpdateChoices(listOfChoices, choicesValues, choicesTooltips)
choicesValues and choicesTooltips are optional. But I'd at least always provide choices and choicesValues so that the getfunc and setFunc uses the choicesValues easily, instead of having to check all entries in choices to match the string of your getFunc/setFunc parameter!

Searching for LAM or UpdateChoices (you could not know the later until now I assume :-)) will give you example forum threads, e.g.
https://www.esoui.com/forums/showthr...=UpdateChoices

I've added it to the Wiki as well now:
https://wiki.esoui.com/LibAddonMenu:...wn_box_entries
  Reply With Quote
08/27/21, 01:24 PM   #5
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 304
I'm not 100% sure if I understand, so if I'm wrong please forgive me. The LAM menu was not designed with the intent to update or change anything. Meaning if you have a dropdown and the three names are Today, Yesterday, Tomorrow you can not add Next Week after you initialize LAM and then update the dropdown. Nor can you remove Tomorrow and replace it with Next Week.

I am currious because I see an update choices and you can't update them after you call RegisterOptionControls.
__________________
Admin for TES5Edit, occasional LOOT masterlist contributor, and Wrye Bash contributor. I also maintain special Fallout 3 and Fallout NV versions of Wrye Flash.
  Reply With Quote
08/27/21, 01:26 PM   #6
Leonardo1123
AddOn Author - Click to view addons
Join Date: Aug 2021
Posts: 19
Hmm, yes, that's exactly what I'm trying to do. So is it just an unavoidable shortcoming of my mod that after you rename an outfit you have to ReloadUI for that to take effect in LAM?

Originally Posted by Sharlikran View Post
I'm not 100% sure if I understand, so if I'm wrong please forgive me. The LAM menu was not designed with the intent to update or change anything. Meaning if you have a dropdown and the three names are Today, Yesterday, Tomorrow you can not add Next Week after you initialize LAM and then update the dropdown. Nor can you remove Tomorrow and replace it with Next Week.

I am currious because I see an update choices and you can't update them after you call RegisterOptionControls.
  Reply With Quote
08/27/21, 10:10 PM   #7
Leonardo1123
AddOn Author - Click to view addons
Join Date: Aug 2021
Posts: 19
Soooooo I'm not entirely sure how I got this working, but I got it working, haha.
  Reply With Quote
08/28/21, 02:59 AM   #8
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,490
Originally Posted by Sharlikran View Post
I'm not 100% sure if I understand, so if I'm wrong please forgive me. The LAM menu was not designed with the intent to update or change anything. Meaning if you have a dropdown and the three names are Today, Yesterday, Tomorrow you can not add Next Week after you initialize LAM and then update the dropdown. Nor can you remove Tomorrow and replace it with Next Week.

I am currious because I see an update choices and you can't update them after you call RegisterOptionControls.
Not sure how you arrived from "Is it possible to add additional controls to a LAM options panel, after it has already been shown/opened once?" "nope. LAM wasn't made with dynamic menus in mind" at "LAM menu was not designed with the intent to update or change anything". xD
You can always update existing controls, including the choices in a dropdown. You just cannot add or remove controls after the menu was created.
__________________
https://www.imperialtradingcompany.eu/ - My Addons - The Vault (Early updates and experimental projects) - My patreon - My blog
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.
  Reply With Quote
08/28/21, 09:11 AM   #9
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 304
Originally Posted by sirinsidiator View Post
* LAM wasn't made with dynamic menus in mind"
* You can always update existing controls, including the choices in a dropdown.
* You just cannot add or remove controls after the menu was created.
That is what has me going around in circles.
__________________
Admin for TES5Edit, occasional LOOT masterlist contributor, and Wrye Bash contributor. I also maintain special Fallout 3 and Fallout NV versions of Wrye Flash.
  Reply With Quote
08/28/21, 09:30 AM   #10
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,490
Originally Posted by Sharlikran View Post
That is what has me going around in circles.
Ok. Guess if you ignore the context of my answer it is a bit confusing.
Let me try to restate it in a way that's harder to misunderstand.
LAM was not made with adding or removing controls in mind, so it's not possible to do that. You can however change values of existing controls in various ways which are outlined in the documentation on github.
__________________
https://www.imperialtradingcompany.eu/ - My Addons - The Vault (Early updates and experimental projects) - My patreon - My blog
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.
  Reply With Quote
08/28/21, 11:26 AM   #11
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 3,753
Looks good so far except that you definately should use the 2nd parameter "choicesValues" in the UpdateChoices function as well.

And as the Wiki tells you here: https://wiki.esoui.com/LibAddonMenu:...ntrols_created
The LAM controls are NOT created ( means they will be nil ) until you open the LAM settings menu the first time!
If you want to update them via events like EVENT_OUTFIT_RENAME_RESPONSE you need to assure the controls exist before!
You cannot assume they exist at event_add_on_loaded or event_player_activated! They do not if you have not pressed ESC -> addon settings to show the LAM settings menu, which creates the panels of the registered addons then.

So make sure to check if the controls exist via ~= nil before trying to update them and ALWAYS pass in choices = LeonardosWardrobeManager.allOutfits (and like I said before also choicesValues = a table with the key = same as in LeonardosWardrobeManager.allOutfits but the value = the key again (a unique number). So that your setFunc and getFunc can use the key value instead of the name of the outfit to update your savedvariables! Names change! So use a unique key number instead via choicesValues parameter.

Originally Posted by Leonardo1123 View Post
Hey there! Sorry for not searching, definitely will in the future! So I feel like I'm super close but there's something basic I'm not understanding. Here's my attempt to implement what you suggested:

LAM
Lua Code:
  1. optionsData = {
  2.     [1] = {
  3.         type = "description",
  4.         title = nil,
  5.         text = "Warning: If you rename an outfit, you will need to reload the UI for those changes to take effect here",
  6.         width = "full",
  7.     },
  8.     [2] = {
  9.         type = "dropdown",
  10.         name = "Default Outfit",
  11.         tooltip = "The outfit to be worn by default",
  12.         choices = LeonardosWardrobeManager.allOutfits,
  13.         getFunc = function() return LeonardosWardrobeManager.savedVariables.defaultOutfit end,
  14.         setFunc = function(var) LeonardosWardrobeManager.SetStateOutfit("DEFAULT", var) end,
  15.         reference = "LeonardosWardrobeManager_Default_Dropdown"
  16.     },
  17.     [3] = {
  18.         type = "submenu",
  19.         name = "Combat",
  20.         tooltip = "Options related to combat and stealth", --(optional)
  21.         controls = {
  22.             [1] = {
  23.                 type = "dropdown",
  24.                 name = "Combat Outfit",
  25.                 tooltip = "The outfit to be switched to upon entering combat",
  26.                 choices = LeonardosWardrobeManager.allOutfits,
  27.                 getFunc = function() return LeonardosWardrobeManager.savedVariables.combatOutfit end,
  28.                 setFunc = function(var) LeonardosWardrobeManager.SetStateOutfit("COMBAT", var) end,
  29.                 reference = "LeonardosWardrobeManager_Combat_Dropdown"
  30.             },
  31.             [2] = {
  32.                 type = "dropdown",
  33.                 name = "Stealth Outfit",
  34.                 tooltip = "The outfit to be switched to upon entering stealth",
  35.                 choices = LeonardosWardrobeManager.allOutfits,
  36.                 getFunc = function() return LeonardosWardrobeManager.savedVariables.stealthOutfit end,
  37.                 setFunc = function(var) LeonardosWardrobeManager.SetStateOutfit("STEALTH", var) end,
  38.                 reference = "LeonardosWardrobeManager_Stealth_Dropdown"
  39.             },
  40.         }
  41.     }
  42. }

Update
Lua Code:
  1. function LeonardosWardrobeManager.OnOutfitRenamed(event, response, index) -- TODO: Still not working
  2.     for i=1,GetNumUnlockedOutfits() do
  3.         LeonardosWardrobeManager.allOutfits[i + OUTFIT_OFFSET] = GetOutfitName(0, i)
  4.     end
  5.     LeonardosWardrobeManager_Default_Dropdown:UpdateChoices(LeonardosWardrobeManager.allOutfits)
  6.     LeonardosWardrobeManager_Combat_Dropdown:UpdateChoices(LeonardosWardrobeManager.allOutfits)
  7.     LeonardosWardrobeManager_Stealth_Dropdown:UpdateChoices(LeonardosWardrobeManager.allOutfits)
  8. end

Event Registers
Lua Code:
  1. ...
  2.  
  3.     LAM2:RegisterAddonPanel("LeonardosWardrobeManagerOptions", panelData)
  4.     LAM2:RegisterOptionControls("LeonardosWardrobeManagerOptions", optionsData)
  5.  
  6.     EVENT_MANAGER:RegisterForEvent(self.name, EVENT_OUTFIT_RENAME_RESPONSE, self.OnOutfitRenamed)
  7.     EVENT_MANAGER:RegisterForEvent(self.name, EVENT_PLAYER_ACTIVATED, self.OnPlayerActivated)
  8.     EVENT_MANAGER:RegisterForEvent(self.name, EVENT_PLAYER_COMBAT_STATE, self.OnPlayerCombatState)
  9.     EVENT_MANAGER:RegisterForEvent(self.name, EVENT_STEALTH_STATE_CHANGED, self.OnPlayerStealthState)
  10. end
  Reply With Quote
08/28/21, 07:57 PM   #12
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 304
Originally Posted by sirinsidiator View Post
Ok. Guess if you ignore the context of my answer it is a bit confusing.
Not trying to do that sir. ^_^
Originally Posted by sirinsidiator View Post
Let me try to restate it in a way that's harder to misunderstand.
I will experiment with it so I understand better.
__________________
Admin for TES5Edit, occasional LOOT masterlist contributor, and Wrye Bash contributor. I also maintain special Fallout 3 and Fallout NV versions of Wrye Flash.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Updating optionData in LAM2

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