StarContent.js 8.7 KB

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