StarContent.js 9.0 KB

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