StarHandbook.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. const StarApi = require('../net/StarApi');
  2. const GameModule = require('../utils/GameModule');
  3. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  4. const AlertManager = require('../utils/AlertManager');
  5. cc.Class({
  6. extends: cc.Component,
  7. properties: {
  8. content: cc.Node,
  9. //
  10. starItemPrefab: cc.Prefab,
  11. starLayout: cc.Layout,
  12. //
  13. progressBar: cc.ProgressBar,
  14. countLabel: cc.Label,
  15. percentRichText: cc.RichText,
  16. //
  17. descNode: cc.Node,
  18. //底部信息
  19. discountRichText: cc.RichText,
  20. discount50Label: cc.Label,
  21. discount30Label: cc.Label
  22. },
  23. // LIFE-CYCLE CALLBACKS:
  24. onLoad () {
  25. if (Global.winSize.height <= 1000) {
  26. this.content.height = 800;
  27. }
  28. GameEvent.on('show_star_desc', this, (starInfo) => {
  29. this.showDescView(starInfo);
  30. });
  31. this.isRecalling = false;
  32. this.showGiftBag = _.debounce((array) => {
  33. AlertManager.showStarGiftBag(array);
  34. }, 1000, true);
  35. },
  36. onDestroy() {
  37. GameModule.audioMng.playClickButton();
  38. GameEvent.off('show_star_desc', this);
  39. },
  40. start () {
  41. this.getAllStars().then((respondData) => {
  42. // console.log(respondData);
  43. this.configData(respondData);
  44. }).catch((code) => {
  45. console.log(code);
  46. });
  47. },
  48. /// 网络请求
  49. getAllStars() {
  50. return new Promise((resolve, reject) => {
  51. // 获取目标用户的建筑
  52. StarApi.getAllStars((respondData) => {
  53. resolve(respondData);
  54. }, (errCode, errMsg) => {
  55. reject(code);
  56. });
  57. })
  58. },
  59. configData(respondData) {
  60. this.respondData = respondData;
  61. if (respondData.userStars.length > 0) {
  62. var isUnlockedCount = 0;
  63. for (let i = 0; i < respondData.userStars.length; ++i) {
  64. let star = respondData.userStars[i];
  65. let item = cc.instantiate(this.starItemPrefab);
  66. item = item.getComponent('StarHandbookItem');
  67. item.configData(star);
  68. this.starLayout.node.addChild(item.node);
  69. if (star.starCount > 0) {
  70. isUnlockedCount++;
  71. }
  72. }
  73. let totalCount = respondData.userStars.length;
  74. this.countLabel.string = `${isUnlockedCount}/${totalCount} 已收集的明星`;
  75. let percent = (isUnlockedCount/totalCount * 100).toFixed(2);
  76. this.percentRichText.string = `<b><outline color=#3d2e1d width=2><color=#ff9600 >${percent}%</color></outline></b>`;
  77. this.progressBar.progress = isUnlockedCount/totalCount;
  78. }
  79. let percent = parseInt(this.respondData.starZk * 100);
  80. this.discountRichText.string = `<b><outline color=#3d2e1d width=2>${percent}%</outline></b>`;
  81. //遍历礼包折扣
  82. this.discount50Array = [];
  83. this.discount30Array = [];
  84. this.discount50 = 0;
  85. this.discount30 = 0;
  86. if (this.respondData.userShops.length > 0) {
  87. for (let i = 0; i < this.respondData.userShops.length; ++i) {
  88. let shop = this.respondData.userShops[i];
  89. if (shop.zk == 0.5) {
  90. this.discount50 += 1;
  91. this.discount50Array.push(shop);
  92. } else if (shop.zk == 0.3) {
  93. this.discount30 += 1;
  94. this.discount30Array.push(shop);
  95. }
  96. }
  97. }
  98. this.discount50Label.string = `x ${this.discount50}`;
  99. this.discount30Label.string = `x ${this.discount30}`;
  100. },
  101. closeView() {
  102. this.node.destroy();
  103. },
  104. //显示描述信息
  105. showDescView(starInfo) {
  106. GameModule.audioMng.playClickButton();
  107. this.descNode.active = true;
  108. this.descNode.getComponent('StarHandbookDesc').configData(starInfo);
  109. },
  110. closeDescView() {
  111. GameModule.audioMng.playClickButton();
  112. this.descNode.active = false;
  113. },
  114. refreshData() {
  115. for (let i = 0; i < this.respondData.userStars.length; ++i) {
  116. let star = this.respondData.userStars[i];
  117. star.starRoomCount = 0;
  118. }
  119. },
  120. recallAllStar() {
  121. if (this.respondData.userStars.length <= 0) {
  122. return;
  123. }
  124. if (this.isRecalling) { return; }
  125. this.isRecalling = true;
  126. StarApi.recallAllStar((respondData) => {
  127. this.isRecalling = false;
  128. this.refreshData();
  129. GameEvent.fire(GameNotificationKey.AllStarLeaveRoom);
  130. }, (code, msg) => {
  131. this.isRecalling = false;
  132. Global.commonAlert.showCommonErrorAlert(`收回失败 \n${msg}`);
  133. });
  134. },
  135. //tabIndex:0为5折,1为3折数据
  136. showDiscountGift(event, tabIndex) {
  137. if (this.respondData == undefined) {
  138. return;
  139. }
  140. if (tabIndex == 0) {
  141. this.showGiftBag(this.discount50Array);
  142. } else {
  143. this.showGiftBag(this.discount30Array);
  144. }
  145. },
  146. // update (dt) {},
  147. });