var reGameStates = require('GameStates');

cc.Class({
    extends: cc.Component,

    properties: {
        Name: {
            default: '种子',
            tooltip: '种子名字，这里和Content_button差不多。主要用于种子',
        },
        SeedPrefab: {
            default: null,
            type: cc.Prefab,
        },
        SpawnPoint: {
            default: null,
            type: cc.Node,
        },
        seedType: {
            default: reGameStates.SeedType.Normal,
            type: cc.Enum(reGameStates.SeedType),
            serializable: true,
        },
        goodsSeedInfo:{
            default: null,
            tooltip: '设定一个背包种子信息',
        },
        seedSpriteFrame:{
            default:null,
            type:cc.SpriteFrame,
            tooltip:"当前生出工具的提示"
        },
        fruitSpriteFrame:{
            default:null,
            type:cc.SpriteFrame,
            tooltip:"当前生出工具的提示"
        },
        myIndex:-1
    },
   start()
   {
       this.StoreViewScp = this.node.parent.parent.parent.parent.parent.getComponent("StoreView");
      // console.log('11111111111=',this.StoreViewScp);
   },
    onCreateSeed() {
        let seedTemp = cc.instantiate(this.SeedPrefab);
        // console.log(seedTemp);
        //获取对应的信息，设置不同的种子
        let _ManageSeedNode = seedTemp.getComponent("ManageSeedNode");
        _ManageSeedNode.seedName = this.Name;
        _ManageSeedNode.seedType = this.seedType;
        _ManageSeedNode.goodsSeedInfo = this.goodsSeedInfo;
        _ManageSeedNode.seedSprite.spriteFrame = this.seedSpriteFrame;
        _ManageSeedNode.fruitSpriteFrame = this.fruitSpriteFrame;

        _ManageSeedNode.upTarget = this.node;

        let tempPos = this.SpawnPoint.convertToNodeSpace(GlobalD.game.MainCamera.node);
        let CanvasPos = GlobalD.game.Canvas.position;

        seedTemp.setPosition(tempPos.x + CanvasPos.x, tempPos.y + CanvasPos.y);
        seedTemp.parent = this.SpawnPoint;
        //收起菜单
        GlobalD.game._ManageUIScript.onButtonEvent_Building_Close();
    },
    onPayCNTPopView()
    {
        this.StoreViewScp.onPayCNTPopView(this.myIndex);
    },
    onPaySNBPopView()
    {
        this.StoreViewScp.onPaySNBPopView(this.myIndex);
    }
});
