| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- import { _decorator, Tween, tween, UIOpacity, Node, Vec3, easing } from 'cc';
- import { UIView } from './UIView';
- import { UICloseReason } from './UILayer';
- import { waitForSeconds } from '@scripts/utils/Helper';
- const { ccclass, property } = _decorator;
- const TWEEM_TIMES = 0.3;
- @ccclass('UIPopup')
- export class UIPopup extends UIView {
- @property(UIOpacity)
- popupMask: UIOpacity;
- @property(Node)
- popupRoot: Node;
- private maskTween: Tween;
- private rootTween: Tween;
- internalCreate(): Promise<void> {
- if (this.popupMask) this.popupMask.opacity = 0;
- if (this.popupRoot) this.popupRoot.scale = Vec3.ZERO;
- return super.internalCreate();
- }
- async internalOpen(params: unknown): Promise<void> {
- this.openAnimation();
- await super.internalOpen(params);
- }
- protected openAnimation(): void | Promise<void> {
- if (this.popupMask) {
- this.stopTween(this.maskTween);
- this.popupMask.opacity = 0;
- this.maskTween = tween(this.popupMask)
- .to(TWEEM_TIMES * 0.6, { opacity: 255 })
- .start();
- }
- if (this.popupRoot) {
- this.stopTween(this.rootTween);
- this.popupRoot.scale = Vec3.ZERO;
- this.rootTween = tween(this.popupRoot)
- .to(TWEEM_TIMES, { scale: Vec3.ONE }, { easing: 'backOut' })
- .start();
- }
- }
- protected async onClose(_reason: UICloseReason) {
- if (!this.popupMask && !this.popupRoot) return;
- this.stopTween(this.maskTween);
- this.stopTween(this.rootTween);
- if (this.popupMask) {
- this.maskTween = tween(this.popupMask)
- .to(TWEEM_TIMES, { opacity: 0 })
- .start();
- }
- if (this.popupRoot) {
- this.rootTween = tween(this.popupRoot)
- .to(TWEEM_TIMES, { scale: Vec3.ZERO })
- .start();
- }
- await waitForSeconds(TWEEM_TIMES);
- }
- private stopTween(tweener: Tween) {
- if (tweener) tweener.stop();
- }
- }
|