cocos2dx之商店源码

发表于2015-12-13
评论0 1k浏览
  1. function shopLayer.initShopGoods(iTabelIndex)  
  2.     -- body  
  3.     print("---- Enter shopLayer.initShopGoods ----")  
  4.         --高亮选中项  
  5.     shopLayer._shopTabel[iTabelIndex]._Selected:setVisible(true)  
  6.     shopLayer._shopTabel[iTabelIndex]._Normal:setVisible(false)  
  7.   
  8.     if shopLayer._shopTabel[iTabelIndex]._Panel ~= nil and shopLayer._ListView ~= nil then  
  9.         --todo  
  10.         --商店总共6项 ,这个值可以随意变化  
  11.         local panelMode = shopLayer._shopTabel[iTabelIndex]._Panel  
  12.         shopLayer._ListView:setItemModel(panelMode)  
  13.         for i = 1, 6 do   
  14.             shopLayer._ListView:pushBackDefaultItem()  
  15.         end  
  16.         local ViewWidth  = shopLayer._ListView:getContentSize().width  
  17.         local iID = shopLayer._shopTabel[iTabelIndex]._id  
  18.         print("iID: "..iID)  
  19.         for i = 0, 5 do --lua里面ListView是从0开始的  
  20.             local iItem      = shopLayer._ListView:getItem(i)  
  21.             local btnResID   = shopLayer._ButtonRes[iID][i + 1].buy_btn  
  22.             local btn        = ccui.Button:create(btnResID)  
  23.             local itemHeight = iItem:getContentSize().height  
  24.             btn:setPosition(ViewWidth - btn:getContentSize().width / 2, itemHeight / 2)  
  25.             btn:setAnchorPoint(cc.p(0.5, 0.5))  
  26.             btn:setTouchEnabled(true)  
  27.             btn.shopType = iTabelIndex; --商店类型  
  28.             btn.id = i + 1 --商店按钮ID  
  29.             btn:addTouchEventListener(function (sender, eventType) --这里回调到每个按钮所对应的信息  
  30.                 -- body  
  31.                 if eventType == 2 then  
  32.                     --todo  
  33.                     local CostType = sender.shopType  
  34.                     local CostID   = sender.id  
  35.                     local iCount = shopLayer._ButtonRes[CostType][CostID].count  
  36.                     if sender.shopType == 1 then   
  37.                         --萌币  
  38.                         cpp_SaveBudCoinCount(iCount)  
  39.                         print("shopType ____1, Button ID: "..sender.id)  
  40.                     else  
  41.                         print("shopType ____2, Button ID: "..sender.id)  
  42.                     end  
  43.                 end  
  44.             end)             
  45.             iItem:addChild(btn)  
  46.         end  
  47.     end  
  48.     print("---- Exit shopLayer.initShopGoods ----")  
  49. end  

如社区发表内容存在侵权行为,您可以点击这里查看侵权投诉指引

0个评论