StarContent.js 8.5 KB

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