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