Tada!!!
Didn't have to make one from scratch, I found a nice and easy template in the UI files. (Sorry guys, we still don't have permission to upload them.
)
From the character sheet, the dropdown that you can select a title in uses this template...
Code:
<Control name="ZO_StatsDropdownRow" virtual="true">
<Dimensions x="607" y="30" />
<OnInitialized>
self.name = self:GetNamedChild("Name")
self.dropdown = ZO_ComboBox_ObjectFromContainer(self:GetNamedChild("Dropdown"))
</OnInitialized>
<Controls>
<Label name="$(parent)Name" inherits="ZO_StatsRowName"/>
<Control name="$(parent)Dropdown" inherits="ZO_ComboBox">
<Dimensions x="300"/>
<Anchor point="RIGHT"/>
</Control>
</Controls>
</Control>
To just Lua, using the pre-existing template shown above:
Lua Code:
local wm = WINDOW_MANAGER --just an upvalue
local choices = {"apple", "banana", "cherry"} --this is the table of choices to go in the dropdown
local myFrame = wm:CreateTopLevelWindow("myFrameForXrystal") --this can be whatever toplevel frame you need it to be to anchor the dropdown stuff to
myFrame:SetAnchor(CENTER)
myFrame:SetDimensions(200, 50)
local dropdownContainer = wm:CreateControlFromVirtual("myFrameForXrystalDropdown", myFrame, "ZO_StatsDropdownRow") --create your dropdown container using the template above
dropdownContainer:SetAnchor(TOPLEFT) --anchor this container however you need to
dropdownContainer:GetNamedChild("Dropdown"):SetWidth(200) --change your dimensions if different from the template's (607, 30)
local selected = dropdownContainer.name --the template put the label in our container's table, you don't need this line unless you want it
local dropdown = dropdownContainer.dropdown --the template put our actual dropdown object into our container's table. Here's a local reference so we don't have to keep doing a table look-up
dropdown:SetSelectedItem("cherry") --set your initial dropdown selection - usually taken from the saved variables
local function OnItemSelect(_, choiceText, choice) --this is the callback function for when an item gets selected in the dropdown
d(choiceText, choice)
end
for i=1,#choices do --loop through your table to add the selections to the dropdown
local entry = dropdown:CreateItemEntry(choices[i], OnItemSelect) --this really just creates a table with {name = choices[i], callback = OnItemSelect} - you may be able to skip this step and just pass the correctly formatted table into the below function...
dropdown:AddItem(entry) --again, entry is just a table with the above args stored in it
end
If everything works right, we can put it on the wiki.