ProductReward.ts 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { VideoAdType } from "../../data/GameData";
  2. const { ccclass, property } = cc._decorator;
  3. @ccclass
  4. export default class ProductReward extends cc.Component {
  5. @property({ type: cc.Label, displayName: "文本" })
  6. lbl_times: cc.Label = null;
  7. @property({ type: cc.Label, displayName: '任务次数' })
  8. lbl_taskTimes: cc.Label = null;
  9. @property({ type: cc.Label, displayName: '进度文本' })
  10. lbl_progress: cc.Label = null;
  11. @property({ type: cc.Sprite, displayName: '进度条' })
  12. sp_taskProgress: cc.Sprite = null;
  13. @property({ type: cc.Node, displayName: '完成节点' })
  14. node_complete: cc.Node = null;
  15. @property({ type: cc.Node, displayName: '未完成节点' })
  16. node_Uncomplete: cc.Node = null;
  17. onEnable() {
  18. this.scheduleOnce(() => {
  19. mk.guide.open(4);
  20. }, 0.5)
  21. this.lbl_times.string = `生产次数x${gData.gameData.configs.ServerConfig.ProductionAd}`;
  22. gData.gameData.init_productTask = false;
  23. if (gData.gameData.playerProp.userFarmTaskInfo) {
  24. let com = gData.gameData.playerProp.userFarmTaskInfo.completeCount;
  25. let count = gData.gameData.playerProp.userFarmTaskInfo.taskCount;
  26. if (count > com) {
  27. this.lbl_taskTimes.string = (count - com).toString();
  28. this.node_Uncomplete.active = true;
  29. this.node_complete.active = false;
  30. } else {
  31. this.node_Uncomplete.active = false;
  32. this.node_complete.active = true;
  33. }
  34. this.lbl_progress.string = `${com}/${count}`;
  35. this.sp_taskProgress.fillRange = com / count;
  36. }
  37. }
  38. update(dt) {
  39. if (gData.gameData.init_productTask) {
  40. if (gData.gameData.playerProp.userFarmTaskInfo) {
  41. let com = gData.gameData.playerProp.userFarmTaskInfo.completeCount;
  42. let count = gData.gameData.playerProp.userFarmTaskInfo.taskCount;
  43. if (count > com) {
  44. this.lbl_taskTimes.string = (count - com).toString();
  45. this.node_Uncomplete.active = true;
  46. this.node_complete.active = false;
  47. } else {
  48. this.node_Uncomplete.active = false;
  49. this.node_complete.active = true;
  50. }
  51. this.lbl_progress.string = `${com}/${count}`;
  52. this.sp_taskProgress.fillRange = com / count;
  53. }
  54. gData.gameData.init_productTask = false;
  55. }
  56. }
  57. private clickVideoBtn() {
  58. mk.audio.playEffect("button");
  59. mk.ui.closePanel(this.node.name);
  60. mk.ad.videoAdType = VideoAdType.video_init_16;
  61. mk.ad.watchAd((success: boolean) => {
  62. if (success) {
  63. gData.adData.watchVideo(null);
  64. let rewardData = [{ rewardType: 4, rewardNum: parseInt(gData.gameData.configs.ServerConfig.ProductionAd) }];
  65. gData.reward.data = rewardData;
  66. gData.reward.callback = this.addTimes;
  67. mk.ui.openPanel('module/reward/reward');
  68. }
  69. })
  70. }
  71. addTimes() {
  72. gData.gameData.changeLeftTimes(parseInt(gData.gameData.configs.ServerConfig.ProductionAd));
  73. }
  74. private clickCloseBtn() {
  75. mk.audio.playEffect("closeButton");
  76. mk.ui.closePanel(this.node.name);
  77. }
  78. }