1
0

skillContent.js 4.7 KB

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