LikeLevelSubviewImpl.ts 1.61 KB
import { DummyLabel, DummyNode, DummySprite } from "../../../../common/CCDummyObjects";
import { CCPureSubview } from "../../../../common/classbase/CCViewBase";
import { RegSubview } from "../../PresenterCCViewFactory";
import { LikeLevelProps, LikeLevelView, LikeLevelViewType } from "../type/LikeLevelSubview";

const { ccclass, property } = cc._decorator;

@ccclass
@RegSubview(LikeLevelViewType)
export class LikeLevelSubviewImpl extends CCPureSubview<LikeLevelProps> implements LikeLevelView {
    //#region editor bindings
    @property(cc.Sprite)
    private bar = DummySprite;
    @property(cc.Label)
    private label = DummyLabel;

    @property(cc.Node)
    private graceNode = DummyNode;

    likevalue: cc.Label = DummyLabel;
    //#endregion

    onLoad() {
        super.onLoad();
        this.likevalue = this.node.getChildByName("likevalue").getComponent(cc.Label);
        this.bindProp("level", v => {
            this.label.string = v + "";
        });
        this.bindProp("percent", v => {
            this.bar.fillRange = v;
        });
        this.bindProp("visible", this.node, "active");

        this.bindProp("like", (value) => {
            if (value === "") {
                this.likevalue.node.active = false;
            } else {
                this.likevalue.node.active = true;
                this.likevalue.string = value;
            }

        });

    }

    onEnable() {
        cc.tween(this.graceNode)
            .repeatForever(cc.tween()
                .to(0.8, { scale: 1.15 }, { easing: 'sineInOut' })
                .to(0.8, { scale: 1 }, { easing: 'sineInOut' }))
            .start();
    }

}