cc.Layout.ClassName = "Layout" function cc.Layout:saveToXmlNode(xmlNode) cc.Widget.saveToXmlNode(self , xmlNode); xmlNode.backGroundScale9Enable = self:isBackGroundImageScale9Enabled(); xmlNode.colorType = self:getBackGroundColorType(); xmlNode.bgStartColor = self:getBackGroundStartColor(); xmlNode.bgEndColor = self:getBackGroundEndColor(); xmlNode.bgColor = self:getBackGroundColor(); xmlNode.bgColorOpacity = self:getBackGroundColorOpacity(); xmlNode.bgWithChildren = self:isUpdateBackgroundWithChildren(); xmlNode.bgImage = getUITexture(self:getBackGroundImageFileName() , self:getBackgroundImageTexType()); if self:isBackGroundImageScale9Enabled() then xmlNode.capInsets = self:getBackGroundImageCapInsets(); --[[ local scale9 = tolua.cast(self:getBackgroundImage() , "cc.Scale9Sprite"); if scale9 then xmlNode.bgBorderEnabled = scale9:isBorderEnabled(); xmlNode.bgBorder = scale9:getBorder(); end --]] end xmlNode.layoutType = self:getLayoutType(); xmlNode.clipping = self:isClippingEnabled(); xmlNode.clippingType = self:getClippingType(); end function cc.Layout:loadFromXmlNode(xmlNode) cc.Widget.loadFromXmlNode(self , xmlNode); local colorType = xmlNode.colorType; self:setBackGroundColorType(colorType); if colorType ~= cc.LayoutBackGroundColorType.none then self:setBackGroundColor(xmlNode.bgStartColor,xmlNode.bgEndColor); self:setBackGroundColor(xmlNode.bgColor); self:setBackGroundColorOpacity(xmlNode.bgColorOpacity); end if xmlNode.bgWithChildren then self:setUpdateBackgroundWithChildren(xmlNode.bgWithChildren); end setUITexture(self.setBackGroundImage , self , xmlNode.bgImage); local scale9Enabled = xmlNode.backGroundScale9Enable; self:setBackGroundImageScale9Enabled(scale9Enabled); if scale9Enabled then self:setBackGroundImageCapInsets(xmlNode.capInsets); --[[ if xmlNode.bgBorderEnabled then local scale9 = tolua.cast(self:getBackgroundImage() , "cc.Scale9Sprite"); if scale9 then scale9:setBorderEnabled(true); scale9:setBorder(xmlNode.bgBorder); end end --]] end self:setLayoutType(xmlNode.layoutType); self:setClippingEnabled(xmlNode.clipping); self:setClippingType(xmlNode.clippingType); end --[[ function cc.Layout:isBorderEnabled() if self:isBackGroundImageScale9Enabled() then local scale9 = tolua.cast(self:getBackgroundImage() , "cc.Scale9Sprite"); if scale9 then return scale9:isBorderEnabled(); end end return false; end function cc.Layout:setBorderEnabled(enabled) if self:isBackGroundImageScale9Enabled() then local scale9 = tolua.cast(self:getBackgroundImage() , "cc.Scale9Sprite"); if enabled then scale9:setBorderEnabled(true); else scale9:setBorderEnabled(false); end end end function cc.Layout:getBorder() if self:isBackGroundImageScale9Enabled() then local scale9 = tolua.cast(self:getBackgroundImage() , "cc.Scale9Sprite"); return scale9:getBorder(); end return cc.margin(0,0,0,0); end function cc.Layout:setBorder(border) if self:isBackGroundImageScale9Enabled() then local scale9 = tolua.cast(self:getBackgroundImage() , "cc.Scale9Sprite"); scale9:setBorder(border); end end --]] function cc.Layout:extend(node) cc.Widget:extend(node); node:setName("Layout") end function cc.Layout:createNode() local layer = cc.Layout:create(); cc.Layout:extend(layer); return layer; end -- 设置默认值 function cc.Layout:setDefaults() self:setSize(cc.size(200,200)); self:setBackGroundColorType(cc.LayoutBackGroundColorType.solid); self:setBackGroundColor(cc.c3b(150,200,255)); self:setBackGroundColorOpacity(100); self:setBackGroundImageCapInsets(cc.rect(0,0,0,0)); end -- 重新加载这个控件的所有图片 function cc.Layout:preloadImage() self:removeBackGroundImage(); end -- 收集这个控件用到了哪些PList文件 function cc.Layout:collectPListFiles() local files = {}; collectPListFile(files , self:getBackGroundImageFileName() , self:getBackgroundImageTexType()); function getParent(node, path) local parent = node:getParent() if parent then local nameParent = parent:getName() path = nameParent.. "\\"..path return getParent(parent, path) else return path end end local nodePath = getParent(self, self:getName()); for k,v in pairs(files) do print("plist = " .. v .. ", nodePath = ".. nodePath) end return files; end