View Single Post
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