StarContent.js 8.7 KB

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