skillContent.js 5.4 KB

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