CheckpointLeaveViewComp.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { EventTouch, Node, Toggle, Tween, Vec3, _decorator, easing, tween } from "cc";
  2. import { oops } from "../../../../../extensions/oops-plugin-framework/assets/core/Oops";
  3. import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
  4. import { CCComp } from "../../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
  5. import { UIID } from "../../common/config/GameUIConfig";
  6. import { SingletonModuleComp } from "../../common/SingletonModuleComp";
  7. import { AdManager } from "../../../platform/ad/AdManager";
  8. import { FullVehicleOperationComp } from "../bll/FullVehicleOperation";
  9. import { DataSdk, REPORT_EVENT } from "../../common/utils/datasdk";
  10. const { ccclass, property } = _decorator;
  11. /** 角色信息界面 */
  12. @ccclass('CheckpointLeaveViewComp')
  13. @ecs.register('CheckpointLeaveView', false)
  14. export class CheckpointLeaveViewComp extends CCComp {
  15. private btnClose
  16. private btnGiveup
  17. private btnGet
  18. onAdded(args: any) {
  19. console.log(args);
  20. }
  21. onLoad() {
  22. this.btnClose = this.node.getChildByPath("BG/btn_close")
  23. this.btnGiveup = this.node.getChildByPath("BG/btn_giveup")
  24. this.btnGet = this.node.getChildByPath("BG/btn_get")
  25. this.btnClose.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
  26. this.btnGiveup.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
  27. this.btnGet.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
  28. const window = this.node.getChildByName("BG")
  29. window.setScale(new Vec3(0, 0, 1));
  30. // 使用Tween来实现动画效果
  31. Tween.stopAllByTarget(window); // 停止该节点上的所有其他Tween
  32. tween(window)
  33. // .delay(0.1)
  34. .to(0.3, { scale: new Vec3(0.5, 0.5, 1) }, { easing: easing.backOut }) // 缩放动画
  35. .start(); // 开始动画
  36. }
  37. private onTouchEnd(event: EventTouch) {
  38. switch (event.target.name) {
  39. case "btn_close":
  40. oops.gui.remove(UIID.VehicleLeave);
  41. break;
  42. case "btn_giveup":
  43. oops.gui.remove(UIID.VehicleLeave);
  44. break;
  45. case "btn_get":
  46. const checkpoint = ecs.getSingleton(SingletonModuleComp).account.checkpoint
  47. if (checkpoint.CheckpointModelBase.vm.leaveCount >= 3) {
  48. oops.gui.toast('该关卡使用次数已满')
  49. oops.gui.remove(UIID.VehicleLeave);
  50. return
  51. }
  52. // ecs.getSingleton(SingletonModuleComp).account.checkpoint.add(FullVehicleOperationComp)
  53. // ecs.getSingleton(SingletonModuleComp).account.checkpoint.CheckpointModelBase.vm.leaveCount += 1
  54. DataSdk.reportEvent(REPORT_EVENT.START_LEAVE_AD,ecs.getSingleton(SingletonModuleComp)?.account?.AccountModel?.lv)
  55. AdManager.getInstance().showRewardVideoAd(() => {
  56. console.log('成功看完广告')
  57. ecs.getSingleton(SingletonModuleComp).account.checkpoint.add(FullVehicleOperationComp)
  58. ecs.getSingleton(SingletonModuleComp).account.checkpoint.CheckpointModelBase.vm.leaveCount += 1
  59. oops.gui.remove(UIID.VehicleLeave);
  60. DataSdk.reportEvent(REPORT_EVENT.END_LEAVE_AD,ecs.getSingleton(SingletonModuleComp)?.account?.AccountModel?.lv)
  61. })
  62. break;
  63. }
  64. event.propagationStopped = true;
  65. }
  66. reset() {
  67. this.node.destroy();
  68. }
  69. }