

import JiaZai from "./JiaZai";
import MapConroler from "./Map";

const { ccclass, property } = cc._decorator;


@ccclass
export default class ItemGuide extends cc.Component {
    static _instance: any;
    time: number = 0;
    //需要替换的三个道具节点
    @property([cc.Node])
    itemList: cc.Node[] = [];
    @property(cc.Node)
    itemGuide: cc.Node = null;
    //道具节点的图片
    @property([cc.SpriteFrame])
    itemSpriteList: cc.SpriteFrame[] = [];
    //飞的目标节点
    @property([cc.Node])
    targetNode: cc.Node[] = [];
    onLoad() {
        if (cc.fx.GameConfig.GM_INFO.level + 1 == 8) {
            this.itemList[0].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[0];
            this.itemList[1].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[1];
            this.itemList[2].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[2];
            this.itemList[3].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[12];
        } else if (cc.fx.GameConfig.GM_INFO.level + 1 == 11) {
            this.itemList[0].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[3];
            this.itemList[1].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[4];
            this.itemList[2].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[5];
            this.itemList[3].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[12];
        } else if (cc.fx.GameConfig.GM_INFO.level + 1 == 16) {
            this.itemList[0].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[6];
            this.itemList[1].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[7];
            this.itemList[2].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[8];
            this.itemList[3].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[12];
        }
        else if (cc.fx.GameConfig.GM_INFO.winStreakFirst == true) {
            this.itemList[0].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[9];
            this.itemList[1].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[10];
            this.itemList[2].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[11];
            this.itemList[3].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[13];
        }
    }

    start() {
    }
    //关闭引导
    closeGuide() {
        this.node.children.forEach((item) => {
            item.active = false;
        })
        this.node.children[0].active = true;
        this.node.children[0].getComponent(cc.Sprite).spriteFrame = null;
        this.itemGuide.active = true;
        this.itemGuide.zIndex = 1000;
        //获取目标节点的位置并且转换到itemGuide的位置的层级
        let index = 0;
        if (cc.fx.GameConfig.GM_INFO.level + 1 == 8) {
            cc.fx.GameConfig.GM_INFO.hammerFirst = false;
            index = 0;
        } else if (cc.fx.GameConfig.GM_INFO.level + 1 == 11) {
            cc.fx.GameConfig.GM_INFO.freezeFirst = false;
            index = 1;
        } else if (cc.fx.GameConfig.GM_INFO.level + 1 == 16) {
            cc.fx.GameConfig.GM_INFO.magicAFirst = false;
            index = 2;
        }
        else if (cc.fx.GameConfig.GM_INFO.winStreakFirst == true) {
            cc.fx.GameConfig.GM_INFO.winStreakFirst = false;
            index = 0;
        }
        let pos = this.targetNode[index].convertToWorldSpaceAR(cc.Vec3.ZERO);
        pos = this.node.convertToNodeSpaceAR(pos);
        this.itemGuide.zIndex = 1000;
        //同时改变大小和位置
        if (MapConroler && MapConroler._instance) {
            MapConroler._instance.setPropNum();
        }

        // if (this.itemGuide.active == true) {

        cc.tween(this.itemGuide)
            .to(0.9, { scale: 0.3, position: pos }) // 同时执行
            .call(() => {
                if (this.node) {
                    this.node.active = false;
                }
                if (MapConroler && MapConroler._instance) {
                    MapConroler._instance.setPropNum();
                }

            })
            .start();
        // }


    }
    //显示引导
    showGuide() {
        this.node.active = true;
        this.node.children[0].active = true;
    }

    // update (dt) {}
}
