UtilsPrefabs.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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,this.prefabsName);
  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. removePrefabs : function (parentNode,prefabsName,success,fail) {
  49. var node = this.parentNode;
  50. if (parentNode!=null) {
  51. node = parentNode;
  52. }
  53. if (node!=null) {
  54. if (node.getChildByName(prefabsName) != null) {
  55. node.getChildByName(prefabsName).off(cc.Node.EventType.TOUCH_END);
  56. node.getChildByName(prefabsName).destroy();
  57. if (success != null) {
  58. success();
  59. }
  60. }else{
  61. if (fail != null) {
  62. fail();
  63. }
  64. }
  65. }
  66. },
  67. setOff : function(node){
  68. node.off(cc.Node.EventType.TOUCH_END);
  69. },
  70. setOn : function(node,callback){
  71. if (node != null) {
  72. node.on(cc.Node.EventType.TOUCH_END,callback);
  73. }else{
  74. console.log("当前被放进来的node节点没有可以点击的名字 请关注此段警告");
  75. }
  76. return this;
  77. },
  78. getNode: function (name, parent) {
  79. if (parent == null) {
  80. if (this.parentNode.getChildByName(name) == null) {
  81. // console.log("在",this.parentNode,"没有找到名字为"+name+"的node");
  82. }
  83. return this.parentNode.getChildByName(name);
  84. } else {
  85. if (parent.getChildByName(name) == null) {
  86. // console.log("在",parent,"没有找到名字为"+name+"的node");
  87. }
  88. return parent.getChildByName(name);
  89. }
  90. },
  91. //开始分享
  92. /**
  93. UtilsPrefabs.startSharePrefab(function () {
  94. this.Building_t();
  95. }.bind(this),function () {
  96. this.Building_t();
  97. }.bind(this));
  98. * @param Success
  99. * @param fail
  100. */
  101. startSharePrefab : function (Success,fail,callbackNode) {
  102. var Canvas = cc.find("Canvas/UICamera");
  103. UtilsPrefabs
  104. .init(Canvas)
  105. .addPrefabs(UtilsPrefabs.sharePrefab[1],null,function (node) {
  106. if (callbackNode != null) {
  107. callbackNode(node);
  108. }
  109. // node.y = -200;
  110. // node.x = -20;
  111. var gosharebtn = UtilsPrefabs.getNode("gosharebtn",node);
  112. // var img1 = UtilsPrefabs.getNode("img1",node);
  113. // var NewLabel1 = UtilsPrefabs.getNode("New Label",img1);
  114. // var img2 = UtilsPrefabs.getNode("img2",node);
  115. // var NewLabel2 = UtilsPrefabs.getNode("New Label",img2);
  116. // NewLabel1.getComponent(cc.Label).string = 'x'+GlobalD.GameData.publicGive[0];
  117. // NewLabel2.getComponent(cc.Label).string = 'x'+GlobalD.GameData.publicGive[1];
  118. var close = UtilsPrefabs.getNode("close",node);
  119. UtilsPrefabs.setOn(close,function () {
  120. UtilsPrefabs.removePrefabs(Canvas,node.name);
  121. if (fail!=null) {
  122. fail();
  123. }
  124. }.bind(this));
  125. UtilsPrefabs.setOn(gosharebtn,function () {
  126. // console.log("点击分享按钮");
  127. UtilsWX.sharebtn(function () {
  128. UtilsPrefabs.setOff(gosharebtn);
  129. GlobalD.GameData.PlusGolden(GlobalD.GameData.publicGive[0]);
  130. GlobalD.GameData.PlusDiamond(GlobalD.GameData.publicGive[1]);
  131. UtilsPrefabs
  132. .init(Canvas)
  133. .addPrefabs(UtilsPrefabs.sharePrefab[2],null,function (node) {
  134. // cc.log(node.name+"***********000");
  135. node.zIndex = 10000;
  136. var MoneyFlyAnim = node.getChildByName('MoneyAnim').getComponent(cc.Animation);
  137. MoneyFlyAnim.RemoveNode = function () {
  138. node.destroy();
  139. // cc.log('111111111',node);
  140. }
  141. });
  142. if (Success!=null) {
  143. Success();
  144. }
  145. }.bind(this));
  146. UtilsPrefabs.removePrefabs(Canvas,node.name);
  147. }.bind(this))
  148. }.bind(this));
  149. },
  150. loadResSpriteFrame : function(src,callback){
  151. cc.loader.loadRes(src,cc.SpriteFrame, function (err, texture) {
  152. if (callback!=null) {
  153. callback(texture);
  154. }
  155. }.bind(this));
  156. },
  157. }