Thread Tools Display Modes
05/19/15, 02:39 PM   #1
hushpuppy247
Join Date: May 2015
Posts: 2
Multiple ComboBoxes using the same entries/info

I'm new to the world of addons and LUA/XML, and am looking for some insight regarding comboboxes. I want to use multiple comboboxes with the same entries, but I'm a bit confused as to how I should proceed. I can setup, display, and populate a combobox using (essentially) the code found in this thread: http://www.esoui.com/forums/showpost...6&postcount=27. However, I don't think I want to repopulate a new combobox with the same info 8 times over (doesn't seem like good practice?).

I'm currently using XML to create a "base" combobox, then populating it via LUA code.

XML:

Code:
<Control name="myDropdown" inherits="ZO_ComboBox" virtual="true">
        <OnInitialized>
		ZO_ComboBox:New(self)
	</OnInitialized>
</Control>
LUA:

Code:
  local headArmorType = CreateControlFromVirtual("headArmorDropdown", MyWindow, "myDropdown")
  headArmorType:SetDimensions(150, 30)
  headArmorType:SetAnchor(TOPLEFT, MyWindow, TOPLEFT, 60, 120)
  local choices = {"Light", "Medium", "Heavy"}
  local dropdown = ZO_ComboBox_ObjectFromContainer(headArmorDropdown)
  dropdown:SetSelectedItem("Armor Type")
  dropdown:SetSortsItems(false)
  local function OnItemSelect(_, choiceText, choice)
	 headArmorType = choiceText --I set the choice to a string variable in order to put it in a mail message
  end	
  for i=1,#choices do
		local entry = dropdown:CreateItemEntry(choices[i], OnItemSelect)
		dropdown:AddItem(entry)
  end
Would I want to create and populate a combobox with those entries (light, medium, heavy) in XML, then create instances of them in LUA? If that's the case, how would I build the table of choices in XML? (Or would I want to create a global variable or function in the LUA script, then reference/call it in the XML file in 'OnInitialized')?
  Reply With Quote
05/20/15, 10:18 PM   #2
Sasky
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 231
One option for if you want a label with each combobox would be to use LibAddonMenu's dropdown control. It's fairly compact in the creation and would just need setting the anchor and dimension afterwords.

I don't think there's a way around registering the items for each dropdown. However, it would still be fairly clean if you did a general function for the create then called that for each of the dropdowns you create.
  Reply With Quote
05/21/15, 09:27 AM   #3
Argusus
AddOn Author - Click to view addons
Join Date: Sep 2014
Posts: 120
I would make it work first using most reusable method like a common function and xml as you mentioned..

Premature optimization is the root of all evil :-)
  Reply With Quote
05/21/15, 02:42 PM   #4
hushpuppy247
Join Date: May 2015
Posts: 2
Thanks for the replies! So what I did was create a function in the lua file that builds/propagates the combobox (using the original code posted), then called it in XML under 'OnInitialized'. I then create the combobox in lua and set its anchor and dimensions. Works exactly as intended.

I did run into a problem with setting the choice text for each separate combobox (in the original code, I have the string set in the callback function 'OnItemSelect'). I ditched that method and instead wrote a function that sets the global strings to the ComboBox items/choices. This is then called after the user clicks a button ('aArmorType' is the string variable, 'aArmor' is the name of the combobox):

Code:
function myAddon:GetChoices()

	aArmorType = aArmorSelectedItemText:GetText()
	bArmorType = bArmorSelectedItemText:GetText()
	 --etc..
	
end
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Multiple ComboBoxes using the same entries/info


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