MarshalSkillSwitchUI.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import { _decorator, Component, Node, Label, Prefab, instantiate } from 'cc';
  2. import { RewardVideoSystem } from '../../ad/RewardVideoSystem';
  3. import { DataSystem } from '../../core/data/DataSystem';
  4. import { Http, HttpResponseCode } from '../../core/net/Http';
  5. import { CountDown } from '../../core/ui/CountDown';
  6. import { WindowSystem } from '../../core/ui/window/WindowSystem';
  7. import { Utils } from '../../core/utils/Utils';
  8. import { ConfigData } from '../../data/ConfigData';
  9. import { FormationData } from '../../hero/formation/FormationData';
  10. import { UserHeroData } from '../../hero/UserHeroData';
  11. import { ReportThinking } from '../../ReportThinking';
  12. import { MarshalData } from '../MarshalData';
  13. import { MarshalSkillSystem } from '../MarshalSkillSystem';
  14. import { SwitchSkillItem } from './SwitchSkillItem';
  15. const { ccclass, property } = _decorator;
  16. /**
  17. * 统帅技能切换界面
  18. * @author 郑聂华
  19. */
  20. @ccclass('MarshalSkillSwitchUI')
  21. export class MarshalSkillSwitchUI extends Component {
  22. @property({ type: Label, displayName: "计时器", tooltip: "计时器" }) txtTime: Label = null;
  23. @property({ type: Node, displayName: "广告节点", tooltip: "广告节点" }) nodeAd: Node = null;
  24. @property({ type: Node, displayName: "广告按钮", tooltip: "广告按钮" }) btnAd: Node = null;
  25. @property({ type: Node, displayName: "广告按钮灰色", tooltip: "广告按钮灰色" }) btnAdNo: Node = null;
  26. @property({ type: Node, displayName: "文本剩余广告节点", tooltip: "文本剩余广告节点" }) txtAdtimesNode: Node = null;
  27. @property({ type: Label, displayName: "文本剩余广告次数", tooltip: "文本剩余广告次数" }) txtRemaindAdtimes: Label = null;
  28. @property({ type: Node, displayName: "技能内容节点", tooltip: "技能内容节点" }) contentSkill: Node = null;
  29. @property({ type: CountDown, displayName: "倒计时组件", tooltip: "倒计时组件" }) countDown: CountDown = null;
  30. @property({ type: Prefab, displayName: "技能Item预制体", tooltip: "技能Item预制体" }) skillItemPrefab: Prefab = null;
  31. //注意 MarshalData数据的创建 目前在GameInit中初始化
  32. private clearAdNum: number = 0; //剩余清除cd次数
  33. private cfg: any;
  34. private remaindTime = 0;
  35. start() {
  36. this.initMarshalSkillClearNum();
  37. this.initPanel();
  38. }
  39. /**倒计时更新方法*/
  40. public updateTxt(progress) {
  41. this.txtTime.string = "技能冷却中:" + Utils.formatCountDown(progress * 1000);
  42. }
  43. /**倒计时结束方法*/
  44. public async finishCooling() {
  45. this.remaindTime = 0;
  46. this.updateAdInfo();
  47. }
  48. /**界面初始化*/
  49. private async initPanel() {
  50. this.cfg = DataSystem.getData(ConfigData).get("serverConfig");
  51. let formationData = DataSystem.getData(FormationData);
  52. await formationData.pull(this.getComponent(Http));
  53. let marshalData = DataSystem.getData(MarshalData);
  54. await MarshalSkillSystem.updateSkillLvData(this.getComponent(Http));
  55. let date = new Date();
  56. let detlaTime = date.getTime() - marshalData.skillCoolingTime;
  57. if (detlaTime >= this.cfg.skillCD * 1000) {
  58. this.remaindTime = 0;
  59. } else {
  60. this.remaindTime = this.cfg.skillCD - detlaTime * 0.001;
  61. }
  62. this.countDown.value = this.remaindTime > 0 ? this.remaindTime : 0;
  63. this.updateAdInfo();
  64. if (!this.countDown.running && this.remaindTime) { this.countDown.value = this.remaindTime; this.countDown.play(); }
  65. let tempKeys = marshalData.marshalSkillData.lvNeedStarsMap.keys();
  66. let hero = formationData.get(5) ? DataSystem.getData(UserHeroData).get(formationData.get(5)).client : DataSystem.getData(ConfigData).get("general")[111001];
  67. for (let id of tempKeys) {
  68. if (marshalData.marshalSkillData.lvMarshalSkill.get(id) > 0) {
  69. let tempNode = instantiate(this.skillItemPrefab);
  70. tempNode.active = true;
  71. this.contentSkill.addChild(tempNode);
  72. let scr = tempNode.getComponent(SwitchSkillItem);
  73. scr.updateInfo(hero, id, marshalData.marshalSkillData.lvMarshalSkill.get(id));
  74. }
  75. }
  76. }
  77. /**跟新广告节点显示*/
  78. private updateAdInfo() {
  79. this.nodeAd.active = this.btnAd.active = this.remaindTime > 0;
  80. this.btnAdNo.active = this.clearAdNum == 0;
  81. this.txtAdtimesNode.active = this.clearAdNum > 0;
  82. this.txtRemaindAdtimes.string = this.clearAdNum > 0 ? this.clearAdNum + "次" : "今日次数已用完";
  83. this.txtTime.string = this.remaindTime > 0 ? "技能冷却中:" + Utils.formatCountDown(this.remaindTime * 1000) : "";
  84. }
  85. /**获取清除cd次数*/
  86. private initMarshalSkillClearNum() {
  87. let date = new Date();
  88. if (!localStorage.getItem("ClearCdDay") || localStorage.getItem("ClearCdDay") != date.getDate() + "") {
  89. localStorage.setItem("ClearCdDay", date.getDate() + "");
  90. localStorage.setItem("ClearCdNum", "3");
  91. }
  92. this.clearAdNum = parseInt(localStorage.getItem("ClearCdNum"));
  93. }
  94. private async onClickAdBtn() {
  95. let resultAd = await this.getComponent(Http).send("/api/ad/watchVideoAD");
  96. if (resultAd && resultAd.code == HttpResponseCode.Success) { //可以观看视频
  97. ReportThinking.ad_init('marshalskillcd_clear');
  98. let adData = await RewardVideoSystem.show();
  99. if (adData) {
  100. ReportThinking.ad_end('marshalskillcd_clear');
  101. let marshalData = DataSystem.getData(MarshalData);
  102. this.clearAdNum--;
  103. marshalData.skillCoolingTime -= this.cfg.skillCD * 1000;
  104. localStorage.setItem("MarshalCoolTime", marshalData.skillCoolingTime.toString());
  105. this.remaindTime = 0;
  106. this.updateAdInfo();
  107. localStorage.setItem("ClearCdNum", this.clearAdNum + "");
  108. this.getComponent(Http).send("/api/task/AddWatchVideoADTimes", { adData: adData.obj });
  109. } else {
  110. WindowSystem.showTips("观看视频失败");
  111. }
  112. } else {
  113. WindowSystem.showTips("观看视频失败");
  114. }
  115. }
  116. private onClickAdNoBtn() {
  117. console.log("today has no clear times");
  118. WindowSystem.showTips("今日清除次数已用完");
  119. }
  120. }