ChapterBtn.ts 1.42 KB
import { DummyLabel, DummyNode } from "../../common/CCDummyObjects";
import { GameModelManager } from "../model/GameModelManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class ChapterBtn extends cc.Component {

    @property(cc.Label)
    private label = DummyLabel;
    @property(cc.Node)
    private pointSpr = DummyNode;

    private _pid: number = -1;

    setData(chapterId: number, chapterName: number, pid: number) {
        this._pid = pid;
        this.label.string = chapterId.toString() + "." + GameModelManager.getI18LanguageTxt(chapterName);
    }

    onItemClick() {
        console.log("onItemClick pid = ", this._pid);
        GameModelManager.RollBackToPlot.emit(this._pid);
        let sprites = this.node.parent.getComponentsInChildren(cc.Sprite);
        for (let i = 0; i < sprites.length; i++) {
            sprites[i].node.active = false;
        }
        this.pointSpr.active = true;
        cc.tween(this.pointSpr)
            .repeatForever(cc.tween()
                .to(0.5, { scale: 1.15, x: -25 }, { easing: 'sineInOut' })
                .to(0.5, { scale: 1, x: -30 }, { easing: 'sineInOut' }))
            .start();
        let labels = this.node.parent.getComponentsInChildren(cc.Label);
        for (let i = 0; i < labels.length; i++) {
            labels[i].node.color = cc.color(255, 255, 255, 255);
        }
        this.label.node.color = cc.color(255, 238, 149, 255);
    }

}