UtilsPrefabs.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. window.UtilsPrefabs = {
  2. PrefabsName : [
  3. "prefab/share",
  4. "prefab/show",
  5. "prefab/login",
  6. "prefab/loading",
  7. "prefab/stock",
  8. ],
  9. sharePrefab : [
  10. "prefab/share",
  11. "prefab/sharepublic",
  12. "prefab/MoneyFlyAfterShare",
  13. ],
  14. init : function (parentNode) {
  15. this.parentNode = parentNode;
  16. return this;
  17. },
  18. getPrefabsName : function(){
  19. return this.prefabsName;
  20. },
  21. addPrefabs : function (prefabsName,parentNode,callback) {
  22. cc.loader.loadRes(prefabsName, function (err, texture) {
  23. var node = this.parentNode;
  24. if (parentNode!=null) {
  25. node = parentNode;
  26. }
  27. var prefab = cc.instantiate(texture);
  28. // this.prefabsName = prefab.name;
  29. this.removePrefabs(node,prefab.name);
  30. if (node!=null) {
  31. node.addChild(prefab);
  32. }else{
  33. return;
  34. }
  35. // this.dialogLuckView.active = false;
  36. // this.GivePrize = this.getNode("GivePrize",this.showDialogs);
  37. // //转
  38. // this.Sunshine = this.getNode("Sunshine",this.GivePrize);
  39. // //物品
  40. // this.Rewards = this.getNode("Rewards",this.GivePrize);
  41. // //关闭按钮
  42. // this.close = this.getNode("close",this.showDialogs);
  43. if (callback != null) {
  44. callback(prefab);
  45. }
  46. }.bind(this));
  47. },
  48. addPrefabsName : function (prefabsName,parentNode,name,callback) {
  49. cc.loader.loadRes(prefabsName, function (err, texture) {
  50. var node = this.parentNode;
  51. if (parentNode!=null) {
  52. node = parentNode;
  53. }
  54. var prefab = cc.instantiate(texture);
  55. let prefabsName = "";
  56. if (name != null) {
  57. prefabsName = name;
  58. }else{
  59. prefabsName = prefab.name;
  60. }
  61. // this.prefabsName = prefab.name;
  62. // this.removePrefabs(node,prefabsName);
  63. if (node!=null) {
  64. node.addChild(prefab);
  65. }else{
  66. return;
  67. }
  68. // this.dialogLuckView.active = false;
  69. // this.GivePrize = this.getNode("GivePrize",this.showDialogs);
  70. // //转
  71. // this.Sunshine = this.getNode("Sunshine",this.GivePrize);
  72. // //物品
  73. // this.Rewards = this.getNode("Rewards",this.GivePrize);
  74. // //关闭按钮
  75. // this.close = this.getNode("close",this.showDialogs);
  76. if (callback != null) {
  77. callback(prefab);
  78. }
  79. }.bind(this));
  80. },
  81. removePrefabs : function (parentNode,prefabsName,success,fail) {
  82. var node = this.parentNode;
  83. if (parentNode!=null) {
  84. node = parentNode;
  85. }
  86. if (node!=null) {
  87. if (node.getChildByName(prefabsName) != null) {
  88. node.getChildByName(prefabsName).off(cc.Node.EventType.TOUCH_END);
  89. node.getChildByName(prefabsName).destroy();
  90. if (success != null) {
  91. success();
  92. }
  93. }else{
  94. if (fail != null) {
  95. fail();
  96. }
  97. }
  98. }
  99. },
  100. setOff : function(node){
  101. node.off(cc.Node.EventType.TOUCH_END);
  102. },
  103. setOn : function(node,callback){
  104. if (node != null) {
  105. node.on(cc.Node.EventType.TOUCH_END,callback);
  106. }else{
  107. console.log("当前被放进来的node节点没有可以点击的名字 请关注此段警告");
  108. }
  109. return this;
  110. },
  111. getNode: function (name, parent) {
  112. if (parent == null) {
  113. if (this.parentNode.getChildByName(name) == null) {
  114. // console.log("在",this.parentNode,"没有找到名字为"+name+"的node");
  115. }
  116. return this.parentNode.getChildByName(name);
  117. } else {
  118. if (parent.getChildByName(name) == null) {
  119. // console.log("在",parent,"没有找到名字为"+name+"的node");
  120. }
  121. return parent.getChildByName(name);
  122. }
  123. },
  124. //开始分享
  125. /**
  126. UtilsPrefabs.startSharePrefab(function () {
  127. this.Building_t();
  128. }.bind(this),function () {
  129. this.Building_t();
  130. }.bind(this));
  131. * @param Success
  132. * @param fail
  133. */
  134. startSharePrefab : function (Success,fail,callbackNode) {
  135. var Canvas = cc.find("Canvas/UICamera");
  136. UtilsPrefabs
  137. .init(Canvas)
  138. .addPrefabs(UtilsPrefabs.sharePrefab[1],null,function (node) {
  139. if (callbackNode != null) {
  140. callbackNode(node);
  141. }
  142. // node.y = -200;
  143. // node.x = -20;
  144. var gosharebtn = UtilsPrefabs.getNode("gosharebtn",node);
  145. var img1 = UtilsPrefabs.getNode("img1",node);
  146. var NewLabel1 = UtilsPrefabs.getNode("New Label",img1);
  147. var img2 = UtilsPrefabs.getNode("img2",node);
  148. var NewLabel2 = UtilsPrefabs.getNode("New Label",img2);
  149. // NewLabel1.getComponent(cc.Label).string = 'x'+GlobalD.GameData.publicGive[0];
  150. // NewLabel2.getComponent(cc.Label).string = 'x'+GlobalD.GameData.publicGive[1];
  151. var close = UtilsPrefabs.getNode("close",node);
  152. UtilsPrefabs.setOn(close,function () {
  153. UtilsPrefabs.removePrefabs(Canvas,node.name);
  154. // if (task.taskCursor == 4) {
  155. // task.addTaskCount();
  156. // task.removeTaskNodes();
  157. // }
  158. if (fail!=null) {
  159. fail();
  160. }
  161. }.bind(this));
  162. UtilsPrefabs.setOn(gosharebtn,function () {
  163. // console.log("点击分享按钮");
  164. UtilsWX.sharebtn(function () {
  165. UtilsPrefabs.setOff(gosharebtn);
  166. GlobalD.GameData.PlusGolden(GlobalD.GameData.publicGive[0]);
  167. GlobalD.GameData.PlusDiamond(GlobalD.GameData.publicGive[1]);
  168. UtilsPrefabs
  169. .init(Canvas)
  170. .addPrefabs(UtilsPrefabs.sharePrefab[2],null,function (node) {
  171. // cc.log(node.name+"***********000");
  172. node.zIndex = 10000;
  173. var MoneyFlyAnim = node.getChildByName('MoneyAnim').getComponent(cc.Animation);
  174. MoneyFlyAnim.RemoveNode = function () {
  175. node.destroy();
  176. // cc.log('111111111',node);
  177. }
  178. });
  179. if (Success!=null) {
  180. Success();
  181. }
  182. }.bind(this));
  183. UtilsPrefabs.removePrefabs(Canvas,node.name);
  184. // if (task.taskCursor == 4) {
  185. // task.addTaskCount();
  186. // task.removeTaskNodes();
  187. // }
  188. }.bind(this))
  189. }.bind(this));
  190. },
  191. loadResSpriteFrame : function(src,callback){
  192. cc.loader.loadRes(src,cc.SpriteFrame, function (err, texture) {
  193. if (callback!=null) {
  194. callback(texture);
  195. }
  196. }.bind(this));
  197. },
  198. }