CheckpointLeaveViewComp.ts 3.2 KB

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