cocos2dx lua怎么做出下拉菜单啊

cocos2dx lua怎么做出下拉菜单啊

在我写的cocos lua 类型体系下,这是一个比较简单的下拉菜单,具体参考我的贴子, <<重新设计的 lua class>>


luaClass("DropList")
:extend(cc.Menu)
:load(CViewNode)

function DropList:DropList(defaultText,textArray,callBackArray,anchorPoint,fontSize,color,disableBack)
    self.disableBack=disableBack or false
    self.anchorPoint=anchorPoint
    self.fontSize=fontSize or 20
    self.color=color 
    self.textArray=textArray
    self.callBackArray=callBackArray
    self.showHeight=0
    self.backGround=nil
    self:setAnchorPoint(anchorPoint)

    self:setText(defaultText,function()
        self:show()
    end,0,"defaultText")
end
function DropList:show()
    if not self.disableBack then
        self:setBackGround()
    end
    self:setDropTextMenu()
    self.defaultText:registerScriptTapHandler(function ()
        self:close()
    end)
end
function DropList:setText(text,callBack,index,name)
    self:createFromStyleTable({
        name=name,
        cls=cc.MenuItemLabel,
        create={createLabel(text,self.fontSize,self.color)},
        setting={
            setAnchorPoint={self:getAnchorPoint()},
            registerScriptTapHandler={callBack},
            setPosition={0,-index*(self.fontSize*1.5)}
        },
    })
end
function DropList:setDropTextMenu()
    for index,text in self.textArray:iter() do
        self:setText(text,self.callBackArray:at(index),index,"sub"..index)
    end
end
function DropList:setBackGround()
    local backSize=
    cc.size(self.defaultText:getContentSize().width
    ,(self.textArray:size())*self.fontSize*2)
    local pointArr={
        cc.p(0,0),
        cc.p(backSize.width,0),
        cc.p(backSize.width,backSize.height),
        cc.p(0,backSize.height)
    }
    local fill=cc.c4f(0,0,0,0.6)
    local dr=cc.DrawNode:create()
    dr:drawPolygon(pointArr,4,fill,2,fill)
    dr:setContentSize(backSize)
    dr:setAnchorPoint(self:getAnchorPoint())
    dr:setPosition(self:getPosition())
    dr:addTo(self:getParent(),self:getTag())
    self.backGround=dr
end
function DropList:close()
    self.defaultText:registerScriptTapHandler(function ()
        self:show()
    end)
    if self.disableBack==false then
        local back=self.backGround
        back:removeFromParent()
    end
    self.backGround=nil
    for index=1,self.textArray:size() do
        local item=self["sub"..index]
        self["sub"..index]=nil
        item:removeFromParent()
    end
end



多谢啊,大佬就是nb