StarContent.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. content: cc.Node,
  11. scrollView: cc.Node,
  12. mask: cc.Node,
  13. getStarMask: cc.Prefab,
  14. /// 图鉴
  15. albumNode: cc.Node,
  16. },
  17. // LIFE-CYCLE CALLBACKS:
  18. onLoad () {
  19. this.node.height = Global.winSize.height;
  20. if (Global.winSize.height <= 1000) {
  21. this.content.height = 800;
  22. }
  23. this.scrollView.active = false;
  24. this._isShowGetStar = false;
  25. this.setUpNotification();
  26. this.handelGuide();
  27. this._isTimeAction = false;
  28. if (Global.isCheck) {
  29. this.albumNode.active = false;
  30. }
  31. },
  32. start () {
  33. this.loadData();
  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. GameEvent.off(GameNotificationKey.RefreshSignArtistList, this);
  40. this.mask.off(cc.Node.EventType.TOUCH_END, this);
  41. },
  42. loadData() {
  43. this._isloadData = true;
  44. this.getSignStars().then((respondData) => {
  45. /// 防止重新加载数据
  46. if (this._respondData !== undefined) {
  47. return;
  48. }
  49. this._isloadData = true;
  50. this._respondData = respondData;
  51. this.scrollView.active = true;
  52. this.scrollView.getComponent('StarScrollView').init(respondData);
  53. }).catch(({code, msg}) => {
  54. this._isloadData = false;
  55. cc.log(code, msg);
  56. });
  57. },
  58. setUpNotification() {
  59. this.mask.on(cc.Node.EventType.TOUCH_END, (event) => {
  60. this.hidden();
  61. GameEvent.fire(GameNotificationKey.TabbarClickCat);
  62. }, this);
  63. GameEvent.on("starAlert_done", this, () => {
  64. if (this.node != null) {
  65. this.hidden();
  66. }
  67. });
  68. GameEvent.on('Star_Buy_success_Alert', this, ((starId, starName) => {
  69. this.showGetStar(starId, starName);
  70. }));
  71. GameEvent.on(GameNotificationKey.RefreshSignArtistList, this, () => {
  72. this.node.destroy();
  73. Global.starContent = null;
  74. });
  75. },
  76. hidden() {
  77. // GameModule.audioMng.playClickButton();
  78. // this.node.destroy();
  79. this.node.active = false;
  80. let guide = GameModule.homeGuide.getComponent('HomeGuide');
  81. if (guide.curState == 'state29') {
  82. guide.hideArrow();
  83. }
  84. },
  85. hiddenAction() {
  86. GameModule.audioMng.playClickButton();
  87. this.hidden();
  88. GameEvent.fire(GameNotificationKey.TabbarClickCat);
  89. },
  90. show() {
  91. this.node.active = true;
  92. GameEvent.fire('StarItem_updateUI');
  93. //// 如果网络请求没有请求下来数据
  94. if (this._isloadData === false) {
  95. this.loadData();
  96. }
  97. this.handelGuide();
  98. },
  99. handelGuide() {
  100. let homeGuide = GameModule.homeGuide.getComponent('HomeGuide');
  101. this._showGuide = false;
  102. if (!homeGuide.isPassGuideState('state29')) {
  103. homeGuide.handleState('state29');
  104. //显示箭头
  105. var offsetY = 0;
  106. if (cc.view.getVisibleSize().height >= 1624) {
  107. offsetY = -140;
  108. } else if (cc.view.getVisibleSize().height >= 1500) {
  109. offsetY = -80;
  110. }
  111. homeGuide.showArrow(offsetY);
  112. this._showGuide = true;
  113. let scrollView = this.scrollView.getComponent(cc.ScrollView);
  114. scrollView.vertical = false;
  115. } else {
  116. GameEvent.off('commAlert_BuyStar_hidden', this);
  117. let scrollView = this.scrollView.getComponent(cc.ScrollView);
  118. scrollView.vertical = true;
  119. }
  120. },
  121. /// 网络请求
  122. getSignStars() {
  123. return new Promise((resolve, reject) => {
  124. StarApi.getSignStars((respondData) => {
  125. resolve(respondData);
  126. }, (code, msg) => {
  127. reject({code, msg});
  128. });
  129. })
  130. },
  131. timeAction() {
  132. if (this._isShowDone == false) {
  133. this.starSkeletonCompletion();
  134. }
  135. },
  136. //// 购买明星骨骼动画完成之后
  137. starSkeletonCompletion() {
  138. this._isShowDone = true;
  139. let homeGuide = GameModule.homeGuide.getComponent('HomeGuide');
  140. if (this.alertMask.getStarSkeleton != null) {
  141. this.alertMask.getStarSkeleton.setAnimation(0, 'run', false);
  142. }
  143. this.alertMask.node.active = false;
  144. this._isShowGetStar = false;
  145. GameModule.audioMng.playBgm();
  146. this.alertMask.getStarAudio.pause();
  147. let imageId = 50000 + this._starId;
  148. // let path = `./textures/star_handbook/${imageId}`;
  149. 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>`;
  150. DWTool.loadResPrefab("./prefabs/common/commonAlert")
  151. .then((result) => {
  152. let alert = cc.instantiate(result);
  153. cc.find('Canvas').addChild(alert);
  154. alert.getComponent('commAlert').initBuyStar(imageId, desc, `${this._starName}`);
  155. if (this._showGuide) {
  156. GameEvent.on('commAlert_BuyStar_hidden',this, () => {
  157. homeGuide.updateGuideState()
  158. homeGuide.handlePass('state29');
  159. homeGuide.handleState('state31');
  160. homeGuide.node.emit(`Fire_state29`);
  161. GameEvent.fire(GameNotificationKey.TabbarClickCat);
  162. });
  163. }
  164. });
  165. },
  166. showGetStar(starId, starName) {
  167. this._starName = starName;
  168. this._starId = starId;
  169. this._isShowDone = false;
  170. if (this._isTimeAction) {
  171. this.unschedule(this.timeAction, this);
  172. }
  173. this._isTimeAction = true;
  174. this.scheduleOnce(this.timeAction, 6);
  175. let homeGuide = GameModule.homeGuide.getComponent('HomeGuide');
  176. homeGuide.hideArrow();
  177. GameModule.audioMng.stopBgm();
  178. if (this.alertMask == undefined) {
  179. let maskNode = cc.instantiate(this.getStarMask);
  180. this.alertMask = maskNode.getComponent('StarMask');
  181. cc.find('Canvas').addChild(this.alertMask.node);
  182. } else {
  183. this.alertMask.node.active = true;
  184. }
  185. this.alertMask.getStarSkeleton.setCompleteListener(() => {
  186. this._isTimeAction = false;
  187. this.unschedule(this.timeAction, this);
  188. if (this._isShowDone === false) {
  189. this.starSkeletonCompletion();
  190. }
  191. });
  192. this._timeCount = 0;
  193. this._isChangeColor = false;
  194. this._isShowGetStar = true;
  195. this.alertMask.starSkeleton.node.color = cc.color(0, 0, 0, 255);
  196. // 根据明星id来加载不同骨骼
  197. this.alertMask.getStarSkeleton.node.active = false;
  198. ArtistManager.loadStarSpine(starId)
  199. .then((skeletonData) => {
  200. this.alertMask.starSkeleton.skeletonData = skeletonData;
  201. var sd = skeletonData.getRuntimeData(true);
  202. if (sd) {
  203. /**
  204. * item: Animation {name: "stand1", timelines: Array(113), duration: 2}
  205. */
  206. let walkAnimation = sd.animations.filter(item => item.name.indexOf('walk2') != -1).map(animation => animation.name) || [];
  207. if (walkAnimation.length === 0) {
  208. this.walkAnimation = sd.animations.filter(item => item.name.indexOf('stand') != -1).map(animation => animation.name) || [];
  209. } else {
  210. this.walkAnimation = walkAnimation;
  211. }
  212. }
  213. this.alertMask.starSkeleton.setAnimation(0, this.walkAnimation[0], true);
  214. this.alertMask.getStarSkeleton.node.active = true;
  215. }).catch((err) => {
  216. console.log(err);
  217. });
  218. this.alertMask.getStarAudio.play();
  219. },
  220. update (dt) {
  221. if (this._isShowGetStar) {
  222. this._timeCount += dt;
  223. if (this._timeCount > 1.2 && this._isChangeColor == false) {
  224. this.alertMask.starSkeleton.node.color = cc.color(255, 255, 255, 255);
  225. GameEvent.fire(GameNotificationKey.PlaySuccessAnimation, true);
  226. this._isChangeColor = true;
  227. }
  228. }
  229. },
  230. //显示明星图鉴
  231. handleStarHandbook: _.debounce((event) => {
  232. AlertManager.showStarHandbookAlert();
  233. }, 1000, true),
  234. });