skillContent.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. const SkillApi = require('../net/SkillApi');
  2. const DWTool = require("../utils/DWTool");
  3. const GameModule = require("../utils/GameModule");
  4. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  5. var Promise = require('../lib/es6-promise').Promise;
  6. const TapTapTool = require("../utils/TapTapTool");
  7. cc.Class({
  8. extends: cc.Component,
  9. properties: {
  10. content: cc.Node,
  11. topSkillItems:{
  12. tooltip: '技能顶部的四个实时技能',
  13. default: [],
  14. type: [cc.Node]
  15. },
  16. skillScrollView: cc.Node,
  17. mask: cc.Node,
  18. skillMask: cc.Prefab,
  19. },
  20. // LIFE-CYCLE CALLBACKS:
  21. onLoad () {
  22. this.node.height = GameGlobal.winSize.height;
  23. if (GameGlobal.winSize.height <= 1000) {
  24. this.content.height = 800;
  25. }
  26. this.setUpNotification();
  27. this.skillScrollView.active = false;
  28. this.handelGuide();
  29. // if (GameGlobal.isCheck) {
  30. // this.topSkillItems[3].active = false;
  31. // }
  32. },
  33. start () {
  34. this.loadData();
  35. },
  36. onDestroy() {
  37. GameEvent.off("skillAlert_done", this);
  38. GameEvent.off('skill_1_unlocked', this);
  39. GameEvent.off('Fire_state17', this);
  40. GameEvent.off('skill3_use_begain',this);
  41. GameEvent.off(GameNotificationKey.GameShowNotificationKey, this);
  42. },
  43. loadData() {
  44. this._isLoadData = true;
  45. this.getAllSkills().then((respondData) => {
  46. console.log(respondData);
  47. /// 防止重新加载数据
  48. if (this._respondData !== undefined) {
  49. return;
  50. }
  51. this._respondData = respondData;
  52. this._isloadData = true;
  53. /// 初始化这个scrollView
  54. GameGlobal.rcdSkillLevel = respondData.skills2[2].skillLevel;
  55. this.skillScrollView.getComponent('SkillScrollView').init(respondData);
  56. this.skillScrollView.active = true;
  57. this.initTopSkillItem(respondData.skills1);
  58. this.schedule(this.timeAction, 1);
  59. }).catch(({code, msg}) => {
  60. this._isloadData = false;
  61. console.log(code, msg);
  62. });
  63. },
  64. //// 初始化通知相关
  65. setUpNotification() {
  66. /// 点击tabbar导致skill隐藏的通知
  67. GameEvent.on("skillAlert_done", this, () => {
  68. this.hidden();
  69. });
  70. ///通过 最后一个新手引导
  71. GameModule.homeGuide.on('Fire_state17', (event) => {
  72. this.hidden();
  73. GameEvent.fire(GameNotificationKey.TabbarClickCat);
  74. }, this);
  75. this.mask.on(cc.Node.EventType.TOUCH_END, (event) => {
  76. this.hidden();
  77. GameEvent.fire(GameNotificationKey.TabbarClickCat);
  78. }, this);
  79. GameEvent.on('skill3_use_begain', this, this.handelSkill1Unlocked);
  80. GameEvent.on(GameNotificationKey.GameShowNotificationKey, this, this.updateTopSkillData);
  81. },
  82. updateTopSkillData() {
  83. this.getAllSkills().then((respondData) => {
  84. console.log(respondData);
  85. /// 初始化这个scrollView
  86. this.initTopSkillItem(respondData.skills1);
  87. let arr = respondData.skills1.concat(respondData.skills2);
  88. //// 说明第一个技能是重新进来的
  89. arr[0].isShow = true;
  90. /// 说明第二个技能是重新进来刷新的
  91. arr[2].isShow = true;
  92. GameModule.skill.skills = arr;
  93. GameModule.skill.getAllSkillInfo();
  94. }).catch(({code, msg}) => {
  95. console.log(code, msg);
  96. });
  97. },
  98. /// 解锁第一个技能的时候需要的动画效果
  99. handelSkill1Unlocked() {
  100. let SkillMask = cc.instantiate(this.skillMask).getComponent('SkillMask');
  101. SkillMask.show();
  102. },
  103. /// 显示 单例显示
  104. show() {
  105. this.node.setPosition(0, 0);
  106. this.skillScrollView.getComponent('SkillScrollView').updateUI();
  107. let scrollView = this.skillScrollView.getComponent(cc.ScrollView);
  108. scrollView.vertical = true;
  109. this.handelGuide();
  110. //// 如果网络请求没有请求下来数据
  111. if (this._isloadData === false) {
  112. this.loadData();
  113. }
  114. },
  115. ///直接隐藏
  116. hidden() {
  117. this.node.setPosition(10000, -100000);
  118. GameModule.homeGuide.getComponent('HomeGuide').changeGuideTask1315(false);
  119. },
  120. //// 点击之后隐藏
  121. hidenAction() {
  122. GameModule.audioMng.playClickButton();
  123. this.hidden();
  124. GameEvent.fire(GameNotificationKey.TabbarClickCat);
  125. },
  126. /// 处理新手引导的显示
  127. handelGuide() {
  128. let homeGuide = GameModule.homeGuide.getComponent('HomeGuide');
  129. for (let i = 12; i <= 17; ++ i) {
  130. let state = 'state' + i;
  131. if (!homeGuide.isPassGuideState(state)) {
  132. homeGuide.handleState(state);
  133. if (i === 13 || i === 15) {
  134. homeGuide.changeGuideTask1315(true);
  135. }
  136. let scrollView = this.skillScrollView.getComponent(cc.ScrollView);
  137. scrollView.vertical = false;
  138. break;
  139. }
  140. }
  141. },
  142. /// 初始化顶部的四个实时技能
  143. initTopSkillItem(timeSkill) {
  144. var isAllLocked = true;
  145. for(let i = 0; i < 3; ++i) {
  146. let skillItemScript = this.topSkillItems[i].getComponent('SkillTopItem');
  147. let timeSkillData = timeSkill[i];
  148. if (timeSkillData.isHave == 1) {
  149. isAllLocked = false;
  150. }
  151. skillItemScript.init(timeSkillData);
  152. }
  153. let upDateItemScript = this.topSkillItems[3].getComponent('SkillTopItem');
  154. upDateItemScript.initUpdateSkill(isAllLocked);
  155. },
  156. timeAction() {
  157. for(let i = 0; i < 4; ++i) {
  158. let skillItemScript = this.topSkillItems[i].getComponent('SkillTopItem');
  159. skillItemScript.updateTime();
  160. }
  161. },
  162. /// 网络请求
  163. getAllSkills() {
  164. return new Promise((resolve, reject) => {
  165. // 获取目标用户的建筑
  166. SkillApi.getAllSkills((respondData) => {
  167. resolve(respondData);
  168. }, (code, msg) => {
  169. reject({code, msg});
  170. });
  171. })
  172. },
  173. // update (dt) {},
  174. });