cc.Class({
    extends: cc.Component,

    properties: {
        Env: {
            default: null,
            type: cc.Node,
        },
        Labour: {
            default: null,
            type: cc.Node,
        },
        Shop: {
            default: null,
            type: cc.Node,
        },
        SpeBuilding: {
            default: null,
            type: cc.Node,
        },
        EvnBtn: {
            default: null,
            type: cc.Node,
        },
        LabourBtn: {
            default: null,
            type: cc.Node,
        },
        ShopBtn: {
            default: null,
            type: cc.Node,
        },
        SpeBuildingBtn: {
            default: null,
            type: cc.Node,
        },

        SelectedFrame: cc.Node,
        Building00: cc.Node,
        Building10: cc.Node,
        Building20: cc.Node,
        Building30: cc.Node,
        ManageUI: cc.Node,


        //四个按钮对应的sprite
        Normal_Env_Sprite: cc.SpriteFrame,
        Selecteded_Env_Sprite: cc.SpriteFrame,

        Normal_Labour_Sprite: cc.SpriteFrame,
        Selecteded_Labour_Sprite: cc.SpriteFrame,

        Normal_Shop_Sprite: cc.SpriteFrame,
        Selecteded_Shop_Sprite: cc.SpriteFrame,

        Normal_Spe_Sprite: cc.SpriteFrame,
        Selecteded_Spe_Sprite: cc.SpriteFrame,


        //需要切换节点顺序的父节点
        container: cc.Node
    },
    HiddenAll() {

        if (this.Env.active)
            this.Env.active = false;
        if (this.Labour.active)
            this.Labour.active = false;
        if (this.Shop.active)
            this.Shop.active = false;
        if (this.SpeBuilding.active)
            this.SpeBuilding.active = false;
    },
    start(){
        //默认设置第一个节点为 最上面
        this.EvnBtn.setSiblingIndex(10);
    },
    //切换建筑的面板
    onSwitchBuildingContent(event, index) {


        this.EvnBtn.setScale(1);
        this.LabourBtn.setScale(1);
        this.ShopBtn.setScale(1);
        this.SpeBuildingBtn.setScale(1);

        this.EvnBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_Env_Sprite;
        this.LabourBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_Labour_Sprite;
        this.ShopBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_Shop_Sprite;
        this.SpeBuildingBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_Spe_Sprite;

        this.EvnBtn.y = 0;
        this.LabourBtn.y = 0;
        this.ShopBtn.y = 0;
        this.SpeBuildingBtn.y = 0;

        this.HiddenAll();
        //面板设置index
        //环境
        if ('0' == index) {
            this.EvnBtn.y = -30;
            this.EvnBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Env_Sprite;
            this.Env.active = true;
            this.SelectedFrame.parent = this.Building00;
            this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.Building00.getComponent('Content_Button').Name, this.Building00.getComponent('Content_Button').Price, this.Building00.getComponent('Content_Button').Synopsis);
            
            //设置节点顺序
            this.EvnBtn.setSiblingIndex(10);

        }
        //劳动 
        else if ('1' == index) {
            this.LabourBtn.y = -30;
            this.LabourBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Labour_Sprite;
            this.Labour.active = true;
            this.SelectedFrame.parent = this.Building10;
            this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.Building10.getComponent('Content_Button').Name, this.Building10.getComponent('Content_Button').Price, this.Building10.getComponent('Content_Button').Synopsis);
       
            this.LabourBtn.setSiblingIndex(10);
        }
        //商铺
        else if ('2' == index) {
            this.ShopBtn.y = -30;
            this.ShopBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Shop_Sprite;
            this.Shop.active = true;
            this.SelectedFrame.parent = this.Building20;
            this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.Building20.getComponent('Content_Button').Name, this.Building20.getComponent('Content_Button').Price, this.Building20.getComponent('Content_Button').Synopsis);

            this.ShopBtn.setSiblingIndex(10);

        } else if ('3' == index) {
            this.SpeBuildingBtn.y = -30;
            this.SpeBuildingBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Spe_Sprite;
            this.SpeBuilding.active = true;
            this.SelectedFrame.parent = this.Building30;
            this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.Building30.getComponent('Content_Button').Name, this.Building30.getComponent('Content_Button').Price, this.Building30.getComponent('Content_Button').Synopsis);

            this.SpeBuildingBtn.setSiblingIndex(10);

        }

        //切换节点顺序
        // this.switch();
    },

    switch: function () {
        var children = this.container.children;
        var length = children.length;
        if (length > 1) {
            var src = Math.floor(Math.random() * length);
            var node = children[src];
            var dst = src === length - 1 ? 0 : src + 1;
            node.setSiblingIndex(dst);
        }
    },
});
