0

我终于解决了从桌子上制作魔兽世界下拉菜单的问题。

现在我需要它能够嵌套到用户提供的最深处。我该怎么做?

这是我目前使用的功能:

    local info = UIDropDownMenu_CreateInfo()

    if level == 1 then
        for a,b in pairs(menuList) do
            info.text = b[1]
            info.hasArrow = b[2]

            UIDropDownMenu_AddButton(info, level)
        end
    elseif level == 2 then

        for a,b in pairs(menuList[UIDROPDOWNMENU_MENU_VALUE][3]) do
            info.text = b
            info.func = OnClick

            UIDropDownMenu_AddButton(info, level)
        end
    end

这是使用的表格示例:

testMenuList = {Greetings = {"Greetings", true, {"hi", "hello", "good day"}}, Farewells = {"Farewells", true, {"bye", "goodbye", "later"}}}

它目前最多可以设置 2 个级别。第一个和子菜单。

谁能帮我吗?

4

1 回答 1

0

这是解决方案:

function IOLib_CreateDropDown(parent, name, title, width, anchor, posX, posY, menuList, OnClick)
    local dropDown = CreateFrame("Button", name, parent, "UIDropDownMenuTemplate")
    --_G[name].list = menuList
    dropDown.list = menuList
    -- dropDown.Func = OnClick
    dropDown:ClearAllPoints()
    dropDown:SetPoint(anchor, posY, posX)

    local function initialize(self, level)
        local info = UIDropDownMenu_CreateInfo()

        if level ~= nil then
            info = UIDropDownMenu_CreateInfo()
            info.text = title
            info.isTitle = true
            UIDropDownMenu_AddButton(info, level)

            if level == 1 then

                for a,b in pairs(menuList) do
                    info = UIDropDownMenu_CreateInfo()
                    info.text = b[1]
                    info.hasArrow = b[2]
                    info.func = OnClick
                    if info.hasArrow then _menuLists[b[1]] = b[3] end
                    UIDropDownMenu_AddButton(info, level)
                end

            elseif level > 1 then
                --print(#_menuLists[UIDROPDOWNMENU_MENU_VALUE][2])
                --for x=1, #_menuLists[UIDROPDOWNMENU_MENU_VALUE] do
                for a,b in pairs(_menuLists[UIDROPDOWNMENU_MENU_VALUE]) do
                    info = UIDropDownMenu_CreateInfo()
                    info.text = b[1]
                    info.hasArrow = b[2]
                    if info.hasArrow then _menuLists[b[1]] = b[3] end
                    info.func = OnClick
                    UIDropDownMenu_AddButton(info, level)
                end
            end


        end
    end

    UIDropDownMenu_Initialize(dropDown, initialize)
    UIDropDownMenu_SetWidth(dropDown, width) -- Use in place of dropDown:SetWidth
    UIDropDownMenu_SetButtonWidth(dropDown, width + 24)
    UIDropDownMenu_SetSelectedID(dropDown, 1)
    UIDropDownMenu_JustifyText(dropDown, "LEFT")

    return dropDown
end

这是与此函数一起使用的表的示例:

testMenuList = {{"Greetings", true, {{"Hi", true, {{"H", true, {{"Amazing", false, nil}}},{"i", false, nil}}},
                                     {"Hello", false, nil}}},
                {"Farewells", true, {{"Bye", false, nil},
                                     {"Goodbye", false, nil}}},
                {"Test", false, nil}}
于 2014-06-11T00:42:54.007 回答