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