View Single Post
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: 4,979
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