View Single Post
09-19-19, 11:12 AM   #3
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Originally Posted by erispope View Post
Not great at wow UI but you are creating one info and reusing it - could that be a problem?

Secondly, perhaps rewrite the inner function to a reusable one instead of recreating it all the time (use self.value +1 instead of i)?
info is just a function reference, so it only needs to be made once. The inner function is just a shortcut to iterate through the SLFG_DungeonList creating their respective info. It's basically the equivalent of writing:

Lua Code:
  1. function SLFG_Dungeon_Menu_Init(self)
  2.     local level = level or 1
  3.     local info = UIDropdownMenu_CreateInfo()
  4.    
  5.     info.text = SLFG_DungeonList[1]
  6.     info.value = 0
  7.     info.func = SLFG_DungeonMenuClick
  8.     info.owner = self
  9.     info.check = nil
  10.     info.icon = nil
  11.     UIDropDownMenu_AddButton(info, level) -- creates menu button with current insert
  12.    
  13.     -- this begins reassigning the data next table data
  14.     -- it functions the same as if you did x = 1, immediately followed by x =2
  15.     info.text = SLFG_DungeonList[2]
  16.     info.value = 1
  17.     info.func = SLFG_DungeonMenuClick
  18.     info.owner = self
  19.     info.check = nil
  20.     info.icon = nil
  21.     UIDropDownMenu_AddButton(info, level) -- creates menu button with new info
  22.  
  23.     -- repeat 26 more times for each DungeonList entry
  24. end
  25.    
  26. function SLFG_DungeonMenuClick(self)
  27.     UIDropDownMenu_SetSelectedValue(self.owner, self.value) -- button checkmark itself and updates the dropdown text shown
  28.     if self.value == 0 then
  29.         SLFG_Settings.dungeon = string.match(SLFG_DungeonList[1], "%((%w+)%)")
  30.             print(SLFG_DungeonList[1].. " has been set.")
  31.             SLFG_UpdateMsg()
  32.     elseif self.value == 1 then
  33.             SLFG_Settings.dungeon = string.match(SLFG_DungeonList[2], "%((%w+)%)")
  34.             print(SLFG_DungeonList[2].. " has been set.")
  35.             SLFG_UpdateMsg()
  36.     elseif self.value == 2 then
  37.         -- repeat 26 more times again
  38.     end
  39. end

I have a second dropdown box that is written out the long way, and it does the exact same thing. I compare the functions side by side with the ones I wrote in CFM and from what I've seen they're identical. Yet CFM dropdowns work fine and these don't.

Last edited by Sythalin : 09-19-19 at 11:16 AM.
  Reply With Quote