在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
function UIBagController:initItemView( ) -- 获取面板 self.panelCenter = tolua.cast(UIHelper:seekWidgetByName(self.owner, "Panel_Center"), "Layout"); -- 获取面板下的子节点,多级子节点也可以获取到 local imageViewGrid1 = tolua.cast(UIHelper:seekWidgetByName(self.panelCenter, "ImageView_Grid1"), "ImageView"); local x, y = imageViewGrid1:getPosition(); local h, w = imageViewGrid1:getSize().width, imageViewGrid1:getSize().height; local gridX, gridY = x , y -- 获取父节点,也就是相应的面板 self.parentLayout = imageViewGrid1:getParent(); self.defaultTexture = imageViewGrid1:getTexture() imageViewGrid1:setVisible(true); imageViewGrid1:setTouchEnabled(false); local imageViewItemTmp = tolua.cast(UIHelper:seekWidgetByName(imageViewGrid1, "ImageView_Item"), "ImageView"); imageViewItemTmp:setVisible(false) local oLine = 1 print("\n\n========背包个数==========" .. ItemM:getAmount()); for i = 2, ItemM:getAmount() do -- 字符串处理函数 local gridName = string.format("ImageView_Grid%d", i); local imageViewGrid = tolua.cast(UIHelper:seekWidgetByName(self.panelCenter, gridName), "ImageView"); if imageViewGrid == nil then local imageViewGridTmp = imageViewGrid1:clone(); table.insert(self.itemArr, imageViewGridTmp); if (i-1)%self.numPerLine == 0 then gridY = y - (i-1)/self.numPerLine * self.gridYInterval oLine = oLine + 1 end gridX = x + (i-1)%self.numPerLine * self.gridXInterval imageViewGridTmp:setName(string.format("ImageView_Grid%d", i)); local labelItemNameTmp = tolua.cast(UIHelper:seekWidgetByName(imageViewGridTmp, "Label_ItemName"), "Label"); labelItemNameTmp:setText(" "); self:setLabelFont(labelItemNameTmp) local labelItenNum = tolua.cast(UIHelper:seekWidgetByName(imageViewGridTmp, "Label_ItenNum"), "Label"); labelItenNum:setText(" "); self:setLabelFont(labelItenNum) imageViewItemTmp = tolua.cast(UIHelper:seekWidgetByName(imageViewGridTmp, "ImageView_Item"), "ImageView"); imageViewItemTmp:setVisible(false); imageViewGridTmp:setVisible(true); -- 将克隆出来的节点添加进去 self.parentLayout:addChild(imageViewGridTmp); imageViewGridTmp:setPosition(ccp(gridX, gridY)); imageViewGridTmp:setTouchEnabled(true); else table.insert(self.itemArr, imageViewGrid); end end -- 获取按钮控件 后面的Button要看引擎中类是怎么定义的 local btnArrange = tolua.cast(UIHelper:seekWidgetByName(self.owner, "btnArrange"), "Button"); -- 给控件绑定事件,这里不一定只有按钮才可以,其他控件也可以 btnArrange:addTouchEventListener(function ( uiwidget, eventType ) -- 判断触摸类型 if eventType == TOUCH_EVENT_ENDED then self:ClearGoods(); self:initItemView(); self:showData(); UISystemTips:SystemTips("bag_arrange"); end; end); end
|
请发表评论