UtilsPrefabs.js 6.4 KB

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