StarHandbook.js 5.2 KB

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