SettlementlayoutManager.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. // foo: {
  14. // // ATTRIBUTES:
  15. // default: null, // The default value will be used only when the component attaching
  16. // // to a node for the first time
  17. // type: cc.SpriteFrame, // optional, default is typeof default
  18. // serializable: true, // optional, default is true
  19. // },
  20. // bar: {
  21. // get () {
  22. // return this._bar;
  23. // },
  24. // set (value) {
  25. // this._bar = value;
  26. // }
  27. // },
  28. },
  29. // LIFE-CYCLE CALLBACKS:
  30. onLoad () {
  31. // console.log("结算页面看见");
  32. },
  33. start() {
  34. utils.isMobile(function () {
  35. Manager.Settlementlayout = this;
  36. }.bind(this));
  37. if (soundM.sound!=null) {
  38. soundM.sound.playSettlement();
  39. }
  40. let datalayout = this.datalayout = UtilsPrefabs.getNode("datalayout", this.node);
  41. //本次得分
  42. let Score = this.Score = UtilsPrefabs.getNode("Score", datalayout);
  43. //飞过什么星球
  44. let star = UtilsPrefabs.getNode("star", datalayout);
  45. //距离面板
  46. let DistanceLayout = this.DistanceLayout = UtilsPrefabs.getNode("DistanceLayout", datalayout);
  47. //距离
  48. let distance = this.distance = UtilsPrefabs.getNode("distance", DistanceLayout);
  49. //距离单位
  50. let distanceUnit = this.distanceUnit = UtilsPrefabs.getNode("distanceUnit", DistanceLayout);
  51. //准确度
  52. let Accuracy = this.Accuracy = UtilsPrefabs.getNode("Accuracy", datalayout);
  53. //速度
  54. let speed = this.speed = UtilsPrefabs.getNode("speed", datalayout);
  55. //力量
  56. let power = this.power = UtilsPrefabs.getNode("power", datalayout);
  57. //三个前后的操作
  58. let layout = this.layout = UtilsPrefabs.getNode("layout", this.node);
  59. let noData = this.noData = UtilsPrefabs.getNode("noData", this.node);
  60. //04月25日,单位改为万公里了
  61. this.StarDistnaces = [
  62. //"月球",
  63. 15210,
  64. //"火星",
  65. 22794,
  66. //"木星",
  67. 77833,
  68. //"土星",
  69. 142700,
  70. //"天王星",
  71. 287099,
  72. //"海王星",
  73. 450400,
  74. //"黑洞"
  75. 591352,
  76. //"飞出太阳系"
  77. 600000,
  78. //飞出银河系
  79. 24598080000000]
  80. //排行榜 里面的 名次 头像 名字 分数 设置
  81. for (var i = 0; i < layout.children.length; i++) {
  82. let children = layout.children[i];
  83. //第几名
  84. let Ranking = UtilsPrefabs.getNode("Ranking", children);
  85. //头像
  86. let ic = UtilsPrefabs.getNode("ic", children);
  87. //名字
  88. let name = UtilsPrefabs.getNode("name", children);
  89. //分数
  90. let Fraction = UtilsPrefabs.getNode("Fraction", children);
  91. }
  92. //再来一次
  93. let restButton = UtilsPrefabs.getNode("restButton", this.node);
  94. let Settlement_more =this.Settlement_more= UtilsPrefabs.getNode("Settlement_more", this.node);
  95. UtilsPrefabs.setOn(Settlement_more, function () {
  96. if (this.MoreButtonClick != null) {
  97. this.MoreButtonClick();
  98. }
  99. }.bind(this));
  100. UtilsPrefabs.setOn(restButton, function () {
  101. this.goMain();
  102. }.bind(this));
  103. this.initstar();
  104. this.initData();
  105. //设置前后中
  106. for (var i = 0; i < RankingListData.aroundArr.length; i++) {
  107. if (RankingListData.aroundArr[i] !=null) {
  108. if (RankingListData.UserId == RankingListData.aroundArr[i].userId) {
  109. this.checkrank(RankingListData.aroundArr, i, i - 1, i + 1);
  110. break;
  111. }
  112. }
  113. }
  114. },
  115. setNoData : function(b){
  116. this.Settlement_more.active = b;
  117. this.layout.active = b;
  118. if (!b) {
  119. this.noData.active = true;
  120. }else{
  121. this.noData.active = false;
  122. }
  123. },
  124. goMain : function(){
  125. utils.isMobile(function () {
  126. Manager.sceneType = 1;
  127. Manager.restartGame();
  128. }.bind(this));
  129. if (soundM.sound!=null) {
  130. soundM.sound.stop(soundM.sound.Settlement_ClipID);
  131. }
  132. //返回 主页面
  133. utils.toLoadScene("main")
  134. },
  135. initstar: function () {
  136. let star = UtilsPrefabs.getNode("star", this.datalayout);
  137. this.stars = [];
  138. let starlist = star;
  139. this.stars.push(UtilsPrefabs.getNode("s1", starlist));
  140. this.stars.push(UtilsPrefabs.getNode("s2", starlist));
  141. this.stars.push(UtilsPrefabs.getNode("s3", starlist));
  142. this.stars.push(UtilsPrefabs.getNode("s4", starlist));
  143. this.stars.push(UtilsPrefabs.getNode("s5", starlist));
  144. this.stars.push(UtilsPrefabs.getNode("s6", starlist));
  145. this.stars.push(UtilsPrefabs.getNode("s7", starlist));
  146. this.stars.push(UtilsPrefabs.getNode("s8", starlist));
  147. this.stars.push(UtilsPrefabs.getNode("s99", starlist));
  148. this.stars.push(UtilsPrefabs.getNode("s100", starlist));
  149. this.setStar(UserInfo.PlayerGameData.currtag);
  150. },
  151. checkrank: function (listdata, x, y, z) {
  152. let playerx = UtilsPrefabs.getNode("playerx", this.layout);
  153. let playery = UtilsPrefabs.getNode("playery", this.layout);
  154. let playerz = UtilsPrefabs.getNode("playerz", this.layout);
  155. // console.log("我就想看看前中后数组是啥 listdata "+ JSON.stringify(listdata));
  156. // console.log("我就想看看前中后数组是啥 x "+ JSON.stringify(x));
  157. // console.log("我就想看看前中后数组是啥 y "+ JSON.stringify(y));
  158. // console.log("我就想看看前中后数组是啥 z "+ JSON.stringify(z));
  159. // console.log("我就想看看前中后数组是啥 listdata[x] "+ listdata[x]);
  160. // console.log("我就想看看前中后数组是啥 listdata[y] "+ listdata[y]);
  161. // console.log("我就想看看前中后数组是啥 listdata[z] "+ listdata[z]);
  162. if (listdata[x] != null) {
  163. this.getRankListNode(playerx,listdata[x]);
  164. RankingListData.myRank = listdata[x];
  165. if (RankingListData.myRank.rank == 0) {
  166. this.setNoData(false);
  167. }else{
  168. this.setNoData(true);
  169. }
  170. }
  171. if (listdata[y] != null) {
  172. this.getRankListNode(playery,listdata[y]);
  173. }
  174. if (listdata[z] != null) {
  175. this.getRankListNode(playerz,listdata[z]);
  176. }
  177. },
  178. getRankListNode: function (node,listdata) {
  179. node.active = true;
  180. let Ranking = UtilsPrefabs.getNode("Ranking", node);
  181. let ic = UtilsPrefabs.getNode("ic", node);
  182. let name = UtilsPrefabs.getNode("name", node);
  183. let Fraction = UtilsPrefabs.getNode("Fraction", node);
  184. Ranking.active = true;
  185. name.active = true;
  186. Fraction.active = true;
  187. Ranking.getComponent(cc.Label).string = "第"+listdata.rank+"名";
  188. name.getComponent(cc.Label).string = listdata.nickName;
  189. Fraction.getComponent(cc.Label).string = listdata.score;
  190. utils.loadHttpSpriteFrame(listdata.portraits, ic.getComponent(cc.Sprite));
  191. },
  192. setStar: function (currtag) {
  193. if (currtag == 99 || currtag == 100) {
  194. if (currtag == 99) {
  195. this.stars[8].active = true;
  196. } else if (currtag == 100) {
  197. this.stars[9].active = true;
  198. }
  199. } else {
  200. this.stars[currtag].active = true;
  201. }
  202. },
  203. setmoreButtonClickListeniner: function (MoreButtonClick) {
  204. this.MoreButtonClick = MoreButtonClick;
  205. },
  206. MoreButtonClick: function () {
  207. },
  208. initData: function () {
  209. utils.getShareData(function (data) {
  210. this.Score.getComponent(cc.Label).string = data.power
  211. this.power.getComponent(cc.Label).string = data.everypowers_average
  212. this.speed.getComponent(cc.Label).string = data.speend_average
  213. this.Accuracy.getComponent(cc.Label).string = data.types_average + "%"
  214. console.log("系数", data.power * UserInfo.PlayerGameData.coefficient);
  215. // this.distance.getComponent(cc.Label).string = parseInt(data.power * UserInfo.PlayerGameData.coefficient) + ""
  216. this.SetDistance(UserInfo.PlayerGameData.currtag,data.power);
  217. }.bind(this));
  218. // this.playername.getComponent(cc.Label).string = UserInfo.Player.name
  219. },
  220. SetDistance: function (currtag,power) {
  221. var distance = 0;
  222. var distanceUnit ="万公里";
  223. var a = 0;
  224. //普通星球
  225. if (currtag>=0 && currtag<=6) {
  226. distance = this.StarDistnaces[currtag];
  227. }
  228. //太阳系
  229. else if (currtag == 99) {
  230. distance = this.StarDistnaces[7];
  231. }
  232. //银河系
  233. else if (currtag == 100) {
  234. distance = this.StarDistnaces[8];
  235. }
  236. a = power/10000;
  237. a = Math.floor(a * 100) / 100;//保留两位小数点
  238. distance = distance+a;
  239. // distance = 24598080000000
  240. this.distance.getComponent(cc.Label).string = distance.toString();
  241. this.distanceUnit.getComponent(cc.Label).string = distanceUnit;
  242. },
  243. // update (dt) {},
  244. });