View Single Post
04/08/14, 04:47 PM   #27
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
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:
  1. local wm = WINDOW_MANAGER  --just an upvalue
  2. local choices = {"apple", "banana", "cherry"}  --this is the table of choices to go in the dropdown
  3.  
  4. local myFrame = wm:CreateTopLevelWindow("myFrameForXrystal")  --this can be whatever toplevel frame you need it to be to anchor the dropdown stuff to
  5.     myFrame:SetAnchor(CENTER)
  6.     myFrame:SetDimensions(200, 50)
  7. local dropdownContainer = wm:CreateControlFromVirtual("myFrameForXrystalDropdown", myFrame, "ZO_StatsDropdownRow")  --create your dropdown container using the template above
  8.     dropdownContainer:SetAnchor(TOPLEFT)  --anchor this container however you need to
  9.     dropdownContainer:GetNamedChild("Dropdown"):SetWidth(200)  --change your dimensions if different from the template's (607, 30)
  10. local selected = dropdownContainer.name  --the template put the label in our container's table, you don't need this line unless you want it
  11. 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
  12.     dropdown:SetSelectedItem("cherry")  --set your initial dropdown selection - usually taken from the saved variables
  13.  
  14. local function OnItemSelect(_, choiceText, choice)  --this is the callback function for when an item gets selected in the dropdown
  15.     d(choiceText, choice)
  16. end
  17.  
  18. for i=1,#choices do  --loop through your table to add the selections to the dropdown
  19.     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...
  20.     dropdown:AddItem(entry)  --again, entry is just a table with the above args stored in it
  21. end


If everything works right, we can put it on the wiki.

Last edited by Seerah : 04/08/14 at 07:54 PM.
  Reply With Quote