UtilsPrefabs.js 6.4 KB

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