cocos2dx之商店源码

function shopLayer.initShopGoods(iTabelIndex)
    -- body
    print("---- Enter shopLayer.initShopGoods ----")
        --高亮选中项
    shopLayer._shopTabel[iTabelIndex]._Selected:setVisible(true)
    shopLayer._shopTabel[iTabelIndex]._Normal:setVisible(false)

    if shopLayer._shopTabel[iTabelIndex]._Panel ~= nil and shopLayer._ListView ~= nil then
        --todo
        --商店总共6项 ,这个值可以随意变化
        local panelMode = shopLayer._shopTabel[iTabelIndex]._Panel
        shopLayer._ListView:setItemModel(panelMode)
        for i = 1, 6 do 
            shopLayer._ListView:pushBackDefaultItem()
        end
        local ViewWidth  = shopLayer._ListView:getContentSize().width
        local iID = shopLayer._shopTabel[iTabelIndex]._id
        print("iID: "..iID)
        for i = 0, 5 do --lua里面ListView是从0开始的
            local iItem      = shopLayer._ListView:getItem(i)
            local btnResID   = shopLayer._ButtonRes[iID][i + 1].buy_btn
            local btn        = ccui.Button:create(btnResID)
            local itemHeight = iItem:getContentSize().height
            btn:setPosition(ViewWidth - btn:getContentSize().width / 2, itemHeight / 2)
            btn:setAnchorPoint(cc.p(0.5, 0.5))
            btn:setTouchEnabled(true)
            btn.shopType = iTabelIndex; --商店类型
            btn.id = i + 1 --商店按钮ID
            btn:addTouchEventListener(function (sender, eventType) --这里回调到每个按钮所对应的信息
                -- body
                if eventType == 2 then
                    --todo
                    local CostType = sender.shopType
                    local CostID   = sender.id
                    local iCount = shopLayer._ButtonRes[CostType][CostID].count
                    if sender.shopType == 1 then 
                        --萌币
                        cpp_SaveBudCoinCount(iCount)
                        print("shopType ____1, Button ID: "..sender.id)
                    else
                        print("shopType ____2, Button ID: "..sender.id)
                    end
                end
            end)           
            iItem:addChild(btn)
        end
    end
    print("---- Exit shopLayer.initShopGoods ----")
end

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值