StarContent.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. const StarApi = require('../net/StarApi');
  2. const AlertManager = require('../utils/AlertManager');
  3. const ArtistManager = require('../utils/ArtistManager');
  4. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  5. const DWTool = require('../utils/DWTool');
  6. const GameModule = require("../utils/GameModule");
  7. cc.Class({
  8. extends: cc.Component,
  9. properties: {
  10. scrollView: cc.Node,
  11. mask: cc.Node,
  12. getStarMask: cc.Prefab,
  13. /// 图鉴
  14. albumNode: cc.Node,
  15. },
  16. // LIFE-CYCLE CALLBACKS:
  17. onLoad () {
  18. this.node.height = cc.view.getVisibleSize().height;
  19. this.scrollView.active = false;
  20. this._isShowGetStar = false;
  21. this.setUpNotification();
  22. this.handelGuide();
  23. if (Global.isCheck) {
  24. this.albumNode.active = false;
  25. }
  26. },
  27. start () {
  28. this.getSignStars().then((respondData) => {
  29. this.scrollView.active = true;
  30. this.scrollView.getComponent('StarScrollView').init(respondData);
  31. }).catch(({code, msg}) => {
  32. cc.log(code, msg);
  33. });
  34. },
  35. onDestroy() {
  36. GameEvent.off("starAlert_done", this);
  37. GameEvent.off('Star_Buy_success_Alert', this);
  38. GameEvent.off('commAlert_BuyStar_hidden', this);
  39. this.mask.off(cc.Node.EventType.TOUCH_END, this);
  40. },
  41. setUpNotification() {
  42. this.mask.on(cc.Node.EventType.TOUCH_END, (event) => {
  43. this.hidden();
  44. GameEvent.fire(GameNotificationKey.TabbarClickCat);
  45. }, this);
  46. GameEvent.on("starAlert_done", this, () => {
  47. if (this.node != null) {
  48. this.hidden();
  49. }
  50. });
  51. GameEvent.on('Star_Buy_success_Alert', this, ((starId, starName) => {
  52. this.showGetStar(starId, starName);
  53. }));
  54. },
  55. hidden() {
  56. // GameModule.audioMng.playClickButton();
  57. // this.node.destroy();
  58. this.node.active = false;
  59. let guide = GameModule.homeGuide.getComponent('HomeGuide');
  60. if (guide.curState == 'state29') {
  61. guide.hideArrow();
  62. }
  63. },
  64. hiddenAction() {
  65. GameModule.audioMng.playClickButton();
  66. this.hidden();
  67. GameEvent.fire(GameNotificationKey.TabbarClickCat);
  68. },
  69. show() {
  70. this.node.active = true;
  71. GameEvent.fire('StarItem_updateUI');
  72. this.handelGuide();
  73. },
  74. handelGuide() {
  75. let homeGuide = GameModule.homeGuide.getComponent('HomeGuide');
  76. this._showGuide = false;
  77. if (!homeGuide.isPassGuideState('state29')) {
  78. homeGuide.handleState('state29');
  79. //显示箭头
  80. var offsetY = 0;
  81. if (cc.view.getVisibleSize().height >= 1624) {
  82. offsetY = -140;
  83. } else if (cc.view.getVisibleSize().height >= 1500) {
  84. offsetY = -80;
  85. }
  86. homeGuide.showArrow(offsetY);
  87. this._showGuide = true;
  88. let scrollView = this.scrollView.getComponent(cc.ScrollView);
  89. scrollView.vertical = false;
  90. } else {
  91. GameEvent.off('commAlert_BuyStar_hidden', this);
  92. let scrollView = this.scrollView.getComponent(cc.ScrollView);
  93. scrollView.vertical = true;
  94. }
  95. },
  96. /// 网络请求
  97. getSignStars() {
  98. return new Promise((resolve, reject) => {
  99. StarApi.getSignStars((respondData) => {
  100. resolve(respondData);
  101. }, (code, msg) => {
  102. reject({code, msg});
  103. });
  104. })
  105. },
  106. showGetStar(starId, starName) {
  107. let homeGuide = GameModule.homeGuide.getComponent('HomeGuide');
  108. homeGuide.hideArrow();
  109. GameModule.audioMng.stopBgm();
  110. if (this.alertMask == undefined) {
  111. let maskNode = cc.instantiate(this.getStarMask);
  112. this.alertMask = maskNode.getComponent('StarMask');
  113. cc.find('Canvas').addChild(this.alertMask.node);
  114. } else {
  115. this.alertMask.node.active = true;
  116. }
  117. this.alertMask.getStarSkeleton.setCompleteListener(() => {
  118. this.alertMask.getStarSkeleton.setAnimation(0, 'run', false);
  119. this.alertMask.node.active = false;
  120. this._isShowGetStar = false;
  121. GameModule.audioMng.playBgm();
  122. this.alertMask.getStarAudio.pause();
  123. let imageId = 50000 + starId;
  124. // let path = `./textures/star_handbook/${imageId}`;
  125. let desc = `<color=#fe4e00>签约奖励</c><br/><br/><img src='skill_click_coin'/><color=#540904>每次点击产出金币提升200%</c><br/><img src='userInfo_rate_coin'/><color=#540904>所有房间产出金币提升200%</c>`;
  126. DWTool.loadResPrefab("./prefabs/common/commonAlert")
  127. .then((result) => {
  128. let alert = cc.instantiate(result);
  129. cc.find('Canvas').addChild(alert);
  130. alert.getComponent('commAlert').initBuyStar(imageId, desc, `${starName}`);
  131. if (this._showGuide) {
  132. GameEvent.on('commAlert_BuyStar_hidden',this, () => {
  133. homeGuide.updateGuideState()
  134. homeGuide.handlePass('state29');
  135. homeGuide.handleState('state31');
  136. homeGuide.node.emit(`Fire_state29`);
  137. GameEvent.fire(GameNotificationKey.TabbarClickCat);
  138. });
  139. }
  140. });
  141. });
  142. this._timeCount = 0;
  143. this._isChangeColor = false;
  144. this._isShowGetStar = true;
  145. this.alertMask.starSkeleton.node.color = cc.color(0, 0, 0, 255);
  146. // 根据明星id来加载不同骨骼
  147. this.alertMask.getStarSkeleton.node.active = false
  148. ArtistManager.loadStar(starId)
  149. .then((skeletonData) => {
  150. this.alertMask.starSkeleton.skeletonData = skeletonData;
  151. var sd = skeletonData.getRuntimeData(true);
  152. if (sd) {
  153. /**
  154. * item: Animation {name: "stand1", timelines: Array(113), duration: 2}
  155. */
  156. if (starId == 10 || starId == 19) {
  157. this.walkAnimation = sd.animations.filter(item => item.name.indexOf('walk2') != -1).map(animation => animation.name) || [];
  158. } else {
  159. this.walkAnimation = sd.animations.filter(item => item.name.indexOf('stand') != -1).map(animation => animation.name) || [];
  160. }
  161. }
  162. this.alertMask.starSkeleton.setAnimation(0, this.walkAnimation[0], true);
  163. this.alertMask.getStarSkeleton.node.active = true;
  164. }).catch((err) => {
  165. console.log(err);
  166. });
  167. this.alertMask.getStarAudio.play();
  168. },
  169. update (dt) {
  170. if (this._isShowGetStar) {
  171. this._timeCount += dt;
  172. if (this._timeCount > 1.2) {
  173. this.alertMask.starSkeleton.node.color = cc.color(255, 255, 255, 255);
  174. GameEvent.fire(GameNotificationKey.PlaySuccessAnimation, true);
  175. this._isChangeColor = true;
  176. }
  177. }
  178. },
  179. //显示明星图鉴
  180. handleStarHandbook: _.debounce((event) => {
  181. AlertManager.showStarHandbookAlert();
  182. }, 1000, true),
  183. });