DateCountViewImpl.ts 2.95 KB
import { DateCountViewType, DateCountViewProps, DateCountView } from "../type/DateCountView";
import { CCPureView } from "../../../../common/classbase/CCViewBase";
import { RegView } from "../../PresenterCCViewFactory";
import { DummyNode, DummyRichText, DummySprite } from "../../../../common/CCDummyObjects";
import { ResUtils } from "simba-cc-resutils";
import { GameModelManager } from "../../../model/GameModelManager";

const { ccclass, property } = cc._decorator;
@ccclass
@RegView(DateCountViewType, "prefab/ui/DateCountView")
export class DateCountViewImpl extends CCPureView<DateCountViewProps> implements DateCountView {

    @property(cc.Sprite)
    progressTipSpr: cc.Sprite = DummySprite;

    @property(cc.Sprite)
    preNumberSpr: cc.Sprite = DummySprite;

    @property(cc.Sprite)
    curNumberSpr: cc.Sprite = DummySprite;

    @property(cc.Sprite)
    skinSpr: cc.Sprite = DummySprite;

    @property(cc.Node)
    numberNode: cc.Node = DummyNode;

    @property(cc.RichText)
    skinNameLabel: cc.RichText = DummyRichText;

    @property(cc.Node)
    kaNode: cc.Node = DummyNode;

    private _resumPosY: number = -120;
    private _moveTmpPosY: number = -10;
    private _actLifeCycle: number = 2;
    private _rotationStep: number = -60;

    onLoad() {
        this.bindProp("skinSprPath", async (value) => {
            if (value && "" !== value.trim() && !value.endsWith("/")) {
                this.skinSpr.spriteFrame = await ResUtils.loadRes(value, cc.SpriteFrame);
            }
        });
        this.bindProp("progressTipSprPath", async (value) => {
            if (value && "" !== value.trim() && !value.endsWith("/")) {
                this.progressTipSpr.spriteFrame = await ResUtils.loadRes(value, cc.SpriteFrame);
            }
        });
        this.bindProp("preNumberSprPath", async (value) => {
            if (value && "" !== value.trim() && !value.endsWith("/")) {
                this.preNumberSpr.spriteFrame = await ResUtils.loadRes(value, cc.SpriteFrame);
            }
        });
        this.bindProp("curNumberSprPath", async (value) => {
            if (value && "" !== value.trim() && !value.endsWith("/")) {
                this.curNumberSpr.spriteFrame = await ResUtils.loadRes(value, cc.SpriteFrame);
            }
        });
        this.bindProp("skinName", async (value) => {
            this.skinNameLabel.string = value;
        });
    }

    onEnable() {
        this.kaNodeAnim();
    }

    runMoveAction = () => {
        this.numberNode.y = this._resumPosY;
        cc.tween(this.numberNode).to(this._actLifeCycle, { y: this._moveTmpPosY }, { easing: 'backInOut' }).start();
    }

    resumeMoveAction = () => {
        this.numberNode.y = this._resumPosY;
    }

    kaNodeAnim() {
        cc.tween(this.kaNode).by(this._actLifeCycle, { angle: this._rotationStep }).repeatForever().start()
    }

    closeAction() {
        if (this._props.canClose) {
            this.close();
            // GameModelManager.checkAutoPopView();
        }
    }
}