1
0

StarContent.js 7.1 KB

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