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.

115 lines
2.8 KiB

  1. cc.LoadingBar.ClassName = "LoadingBar"
  2. function cc.LoadingBar:saveToXmlNode(xmlNode)
  3. cc.Widget.saveToXmlNode(self , xmlNode);
  4. xmlNode.Texture = getUITexture(self:getTextureFile() , self:getRenderBarTexType());
  5. xmlNode.Scale9Enabled = self:isScale9Enabled();
  6. if xmlNode.Scale9Enabled then
  7. xmlNode.CapInsets = self:getCapInsets();
  8. end
  9. xmlNode.Direction = self:getDirection();
  10. xmlNode.Percent = self:getPercent();
  11. end
  12. function cc.LoadingBar:loadFromXmlNode(xmlNode)
  13. cc.Widget.loadFromXmlNode(self , xmlNode);
  14. setUITexture(self.loadTexture , self , xmlNode.Texture);
  15. self:setScale9Enabled(xmlNode.Scale9Enabled);
  16. if self:isScale9Enabled() then
  17. self:setCapInsets(xmlNode.CapInsets);
  18. end
  19. self:setDirection(xmlNode.Direction);
  20. self:setPercent(xmlNode.Percent);
  21. end
  22. function cc.LoadingBar:extend(node)
  23. cc.Widget:extend(node);
  24. node:setName("LoadingBar")
  25. end
  26. -- 把进度条以动画形式设置到percent值, isSineOut是否由快至慢
  27. function cc.LoadingBar:animPercent(targetPercent, duration, isSineOut, aniEndFunc)
  28. if not tolua.isnull(self.AnimPercentAction) then
  29. self:stopAction(self.AnimPercentAction);
  30. end
  31. local function actionEnd()
  32. if aniEndFunc then
  33. aniEndFunc()
  34. end
  35. end
  36. self.AnimPercentAction = nil;
  37. if isSineOut then
  38. if targetPercent ~= self:getPercent() then
  39. local action = cc.EaseSineOut:create(cc.UIPercentTo:create(duration , targetPercent));
  40. self.AnimPercentAction = action;
  41. self:runActions(action, actionEnd);
  42. else
  43. actionEnd()
  44. end
  45. else
  46. if targetPercent ~= self:getPercent() then
  47. local action = cc.UIPercentTo:create(duration , targetPercent);
  48. self.AnimPercentAction = action;
  49. self:runActions(action, actionEnd);
  50. else
  51. actionEnd()
  52. end
  53. end
  54. end
  55. function cc.LoadingBar:createNode()
  56. local layer = cc.LoadingBar:create();
  57. cc.LoadingBar:extend(layer);
  58. return layer;
  59. end
  60. -- 设置默认值
  61. function cc.LoadingBar:setDefaults()
  62. self:loadTexture("res/default/loadingbar.png");
  63. self:setCapInsets(cc.rect(0,0,0,0));
  64. self:setPercent(100);
  65. end
  66. -- 重新加载这个控件的所有图片
  67. function cc.LoadingBar:postloadImage()
  68. local isScale9 = self:isScale9Enabled();
  69. self:setScale9Enabled(not isScale9);
  70. self:setScale9Enabled(isScale9);
  71. end
  72. -- 收集这个控件用到了哪些PList文件
  73. function cc.LoadingBar:collectPListFiles()
  74. local files = {};
  75. collectPListFile(files , self:getTextureFile() , self:getRenderBarTexType());
  76. function getParent(node, path)
  77. local parent = node:getParent()
  78. if parent then
  79. local nameParent = parent:getName()
  80. path = nameParent.. "\\"..path
  81. return getParent(parent, path)
  82. else
  83. return path
  84. end
  85. end
  86. local nodePath = getParent(self, self:getName());
  87. for k,v in pairs(files) do
  88. print("plist = " .. v .. ", nodePath = ".. nodePath)
  89. end
  90. return files;
  91. end