You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
4.3 KiB

  1. cc.Layout.ClassName = "Layout"
  2. function cc.Layout:saveToXmlNode(xmlNode)
  3. cc.Widget.saveToXmlNode(self , xmlNode);
  4. xmlNode.backGroundScale9Enable = self:isBackGroundImageScale9Enabled();
  5. xmlNode.colorType = self:getBackGroundColorType();
  6. xmlNode.bgStartColor = self:getBackGroundStartColor();
  7. xmlNode.bgEndColor = self:getBackGroundEndColor();
  8. xmlNode.bgColor = self:getBackGroundColor();
  9. xmlNode.bgColorOpacity = self:getBackGroundColorOpacity();
  10. xmlNode.bgWithChildren = self:isUpdateBackgroundWithChildren();
  11. xmlNode.bgImage = getUITexture(self:getBackGroundImageFileName() , self:getBackgroundImageTexType());
  12. if self:isBackGroundImageScale9Enabled() then
  13. xmlNode.capInsets = self:getBackGroundImageCapInsets();
  14. --[[ local scale9 = tolua.cast(self:getBackgroundImage() , "cc.Scale9Sprite");
  15. if scale9 then
  16. xmlNode.bgBorderEnabled = scale9:isBorderEnabled();
  17. xmlNode.bgBorder = scale9:getBorder();
  18. end
  19. --]]
  20. end
  21. xmlNode.layoutType = self:getLayoutType();
  22. xmlNode.clipping = self:isClippingEnabled();
  23. xmlNode.clippingType = self:getClippingType();
  24. end
  25. function cc.Layout:loadFromXmlNode(xmlNode)
  26. cc.Widget.loadFromXmlNode(self , xmlNode);
  27. local colorType = xmlNode.colorType;
  28. self:setBackGroundColorType(colorType);
  29. if colorType ~= cc.LayoutBackGroundColorType.none then
  30. self:setBackGroundColor(xmlNode.bgStartColor,xmlNode.bgEndColor);
  31. self:setBackGroundColor(xmlNode.bgColor);
  32. self:setBackGroundColorOpacity(xmlNode.bgColorOpacity);
  33. end
  34. if xmlNode.bgWithChildren then
  35. self:setUpdateBackgroundWithChildren(xmlNode.bgWithChildren);
  36. end
  37. setUITexture(self.setBackGroundImage , self , xmlNode.bgImage);
  38. local scale9Enabled = xmlNode.backGroundScale9Enable;
  39. self:setBackGroundImageScale9Enabled(scale9Enabled);
  40. if scale9Enabled then
  41. self:setBackGroundImageCapInsets(xmlNode.capInsets);
  42. --[[ if xmlNode.bgBorderEnabled then
  43. local scale9 = tolua.cast(self:getBackgroundImage() , "cc.Scale9Sprite");
  44. if scale9 then
  45. scale9:setBorderEnabled(true);
  46. scale9:setBorder(xmlNode.bgBorder);
  47. end
  48. end
  49. --]]
  50. end
  51. self:setLayoutType(xmlNode.layoutType);
  52. self:setClippingEnabled(xmlNode.clipping);
  53. self:setClippingType(xmlNode.clippingType);
  54. end
  55. --[[
  56. function cc.Layout:isBorderEnabled()
  57. if self:isBackGroundImageScale9Enabled() then
  58. local scale9 = tolua.cast(self:getBackgroundImage() , "cc.Scale9Sprite");
  59. if scale9 then
  60. return scale9:isBorderEnabled();
  61. end
  62. end
  63. return false;
  64. end
  65. function cc.Layout:setBorderEnabled(enabled)
  66. if self:isBackGroundImageScale9Enabled() then
  67. local scale9 = tolua.cast(self:getBackgroundImage() , "cc.Scale9Sprite");
  68. if enabled then
  69. scale9:setBorderEnabled(true);
  70. else
  71. scale9:setBorderEnabled(false);
  72. end
  73. end
  74. end
  75. function cc.Layout:getBorder()
  76. if self:isBackGroundImageScale9Enabled() then
  77. local scale9 = tolua.cast(self:getBackgroundImage() , "cc.Scale9Sprite");
  78. return scale9:getBorder();
  79. end
  80. return cc.margin(0,0,0,0);
  81. end
  82. function cc.Layout:setBorder(border)
  83. if self:isBackGroundImageScale9Enabled() then
  84. local scale9 = tolua.cast(self:getBackgroundImage() , "cc.Scale9Sprite");
  85. scale9:setBorder(border);
  86. end
  87. end
  88. --]]
  89. function cc.Layout:extend(node)
  90. cc.Widget:extend(node);
  91. node:setName("Layout")
  92. end
  93. function cc.Layout:createNode()
  94. local layer = cc.Layout:create();
  95. cc.Layout:extend(layer);
  96. return layer;
  97. end
  98. -- 设置默认值
  99. function cc.Layout:setDefaults()
  100. self:setSize(cc.size(200,200));
  101. self:setBackGroundColorType(cc.LayoutBackGroundColorType.solid);
  102. self:setBackGroundColor(cc.c3b(150,200,255));
  103. self:setBackGroundColorOpacity(100);
  104. self:setBackGroundImageCapInsets(cc.rect(0,0,0,0));
  105. end
  106. -- 重新加载这个控件的所有图片
  107. function cc.Layout:preloadImage()
  108. self:removeBackGroundImage();
  109. end
  110. -- 收集这个控件用到了哪些PList文件
  111. function cc.Layout:collectPListFiles()
  112. local files = {};
  113. collectPListFile(files , self:getBackGroundImageFileName() , self:getBackgroundImageTexType());
  114. function getParent(node, path)
  115. local parent = node:getParent()
  116. if parent then
  117. local nameParent = parent:getName()
  118. path = nameParent.. "\\"..path
  119. return getParent(parent, path)
  120. else
  121. return path
  122. end
  123. end
  124. local nodePath = getParent(self, self:getName());
  125. for k,v in pairs(files) do
  126. print("plist = " .. v .. ", nodePath = ".. nodePath)
  127. end
  128. return files;
  129. end