Thread Tools Display Modes
Yesterday, 02:52 PM   #1
Amakesh
Join Date: Oct 2021
Posts: 1
Unhappy Popup with controls

I would like the
Code:
AddCustomMenuItem(
    "Change Label Color",
    function()
        local color = nil

        color = unpack(self.labelSettings.labelColor)

        COLOR_PICKER:Show(
            function(...)
                self:SetLabelColor(...)
            end,
            color
        )
    end
)
method to show me a popup with two dropdowns and one slider instead of the colorpicker. Unfortunately, no matter which way I try, I always get just a popup with title, maintext and cancel and ok buttons.
What can I do to get the aforementioned controls in the window as well?
I tried both ZO_Dialogs(see example below) and libDialog.


Code:
	ZO_Dialogs_RegisterCustomDialog("ExampleDialog", {

		setup = function(dialog)
			d("Setting up dialog controls")
	
			local parentControl = dialog.control
			local slider = CreateControlFromVirtual("$(parent)Slider", parentControl, "ZO_Slider")
	
			if slider then
				slider:SetAnchor(TOPLEFT, parentControl, TOPLEFT, 0, 20)
				slider:SetMinMax(0, 100)
				slider:SetValue(50)
				slider:SetValueStep(1)
				slider:SetHandler("OnValueChanged", function(_, value)
					d("Slider value: " .. value)
				end)
				
				dialog.slider = slider
			else
				d("Failed to create slider.")
			end
		end,

		title = {
			text = "Example Dialog",
		},
		mainText = {
			text = "Adjust the slider:",
		},
	
		buttons = {
			{
				text = "OK",
				callback = function(dialog)
					d("Confirmed with slider value: " .. dialog.slider:GetValue())
				end,
			},
			{
				text = "Cancel",
				callback = function(dialog)
					d("Dialog cancelled")
				end,
			},
		},
	})
	

SLASH_COMMANDS["/showdialog"] = function()
    ZO_Dialogs_ShowDialog("ExampleDialog")
end

Last edited by Amakesh : Yesterday at 02:56 PM.
  Reply With Quote
Today, 02:49 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 5,169
Check my addon WishList, it got some ZO_Dialog popups with custom controls in it (defined in XML though).
It's code is old and could be improved I know but hopefully it explains it to you.

You need to define the dialog first in a XML file as ZO_Dialog alone does not provide any custom dialogs with drodpowns afaik.
-> It could work with controls created in the setup function too, not sure, never tested that actually.
Try to add in your setup function:
Code:
slider:SetHidden(false)
slider:SetMouseEnabled(true)
Maybe the control was just hidden by default




Else try it vial XML code:
See file WishList/src/dialog/WishListAddItemDialog.xml

Code:
<Controls>
        <TopLevelControl name="WishListAddItemDialog" inherits="ZO_CustomDialogBase" resizeToFitDescendents="true">
....
Init the dialog in a lua function called from your code, e.g. at your EVENT_ADD_ON_LOADED
See function call in WishlistWindow.lua
WL.WishListWindowAddItemInitialize(WishListAddItemDialog)

Function is in dialogs.lua then
Code:
function WL.WishListWindowAddItemInitialize(control)
    local content   = GetControl(control, "Content")
    local acceptBtn = GetControl(control, "Accept")
    local cancelBtn = GetControl(control, "Cancel")
    local descLabel = GetControl(content, "Text")
    local labelLastAddedHistory = GetControl(content, "LastAddedHistoryLabel")
    local comboBoxBaseControlLastAddedHistory = content:GetNamedChild("LastAddedHistoryCombo")
    local comboLastAddedHistory = ZO_ComboBox_ObjectFromContainer(comboBoxBaseControlLastAddedHistory)
    local textureLastAddedHistory = content:GetNamedChild("LastAddedHistoryTexture")
    local labelItemType = GetControl(content, "ItemTypeText")
    local comboItemType = ZO_ComboBox_ObjectFromContainer(content:GetNamedChild("ItemTypeCombo")) --GetControl(content, "ItemTypeCombo")
    local labelArmorOrWeaponType = GetControl(content, "ArmorOrWeaponTypeText")
    local comboArmorOrWeaponType = ZO_ComboBox_ObjectFromContainer(content:GetNamedChild("ArmorOrWeaponTypeCombo")) --GetControl(content, "ArmorOrWeaponTypeCombo")
    local labelSlot = GetControl(content, "SlotText")
    local comboSlot = ZO_ComboBox_ObjectFromContainer(content:GetNamedChild("SlotCombo")) --GetControl(content, "SlotCombo")
    local labelTrait = GetControl(content, "TraitText")
    local comboTrait = ZO_ComboBox_ObjectFromContainer(content:GetNamedChild("TraitCombo")) --GetControl(content, "TraitCombo")
    local labelQuality = GetControl(content, "QualityText")
    local comboQuality = ZO_ComboBox_ObjectFromContainer(content:GetNamedChild("QualityCombo")) --GetControl(content, "QualityCombo")
    local labelChars = GetControl(content, "CharsText")
    local comboChars = ZO_ComboBox_ObjectFromContainer(content:GetNamedChild("CharsCombo")) --GetControl(content, "CharsCombo")

    ZO_Dialogs_RegisterCustomDialog("WISHLIST_EVENT_ADD_ITEM_DIALOG", {

...

In the setup function of the dialog define what to do how:
Code:
setup = function(dialog, data)
            --local wlWindow = (data ~= nil and data.wlWindow ~= nil and data.wlWindow == true) or false
            descLabel:SetText(WL.currentSetName)

            labelLastAddedHistory:SetText(GetString(WISHLIST_HEADER_LAST_ADDED))
            labelItemType:SetText(GetString(WISHLIST_HEADER_TYPE))
            --labelArmorOrWeaponType:SetText("Armor/Weapon Type")
            labelTrait:SetText(GetString(WISHLIST_HEADER_TRAIT))
            labelQuality:SetText(GetString(WISHLIST_HEADER_QUALITY))
            labelSlot:SetText(GetString(WISHLIST_HEADER_SLOT))
            labelChars:SetText(GetString(WISHLIST_HEADER_CHARS))

            WL.checkCharsData()
...
And then call the dialog in your lua code via ZO_Dialogs_ShowDialog (in your case from that ZO_Menu context menu) and pass in data table with variables you need etc.
It's done for my addon in a function WL.showAddItemalso in file dialogs.lua

Lua Code:
  1. function WL.showAddItem(setData, comingFromWishListWindow, doNotUpdateCurrentCharData)
  2.     comingFromWishListWindow = comingFromWishListWindow or false
  3.     doNotUpdateCurrentCharData = doNotUpdateCurrentCharData or false
  4.     WL.createWindow(false)
  5.     local clientLang = WL.clientLang or WL.fallbackSetLang
  6.     WL.currentSetId = setData.setId
  7.     WL.currentSetName = setData.names and setData.names[clientLang] or setData.setNames[clientLang]
  8.     --Character data was chosen at external addon? Or are we coming from internal WishList?
  9.     if not doNotUpdateCurrentCharData then
  10. d(">WL.showAddItem -> checkCurrentCharData")
  11.         WL.checkCurrentCharData()
  12.     end
  13.     ZO_Dialogs_ShowDialog("WISHLIST_EVENT_ADD_ITEM_DIALOG", {set=setData.setId, wlWindow=comingFromWishListWindow})
  14. end

Last edited by Baertram : Today at 03:12 AM.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Popup with controls


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