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, }, Seed: { default: null, type: cc.Node, }, Fruit: { 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, }, SeedBtn: { default: null, type: cc.Node, }, FruitBtn: { default: null, type: cc.Node, }, SelectedFrame: cc.Node, Building00: cc.Node, Building10: cc.Node, Building20: cc.Node, Building30: cc.Node, Building40: cc.Node, Building50: 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, Normal_Seed_Sprite: cc.SpriteFrame, Selecteded_Seed_Sprite: cc.SpriteFrame, Normal_Fruit_Sprite: cc.SpriteFrame, Selecteded_Fruit_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; if (this.Seed.active) this.Seed.active = false; if (this.Fruit.active) this.Fruit.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.SeedBtn.setScale(1); this.FruitBtn.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.SeedBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_Seed_Sprite; this.FruitBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_Fruit_Sprite; this.EvnBtn.setContentSize(100,54); this.LabourBtn.setContentSize(100,54); this.ShopBtn.setContentSize(100,54); this.SpeBuildingBtn.setContentSize(100,54); this.SeedBtn.setContentSize(100,54); this.FruitBtn.setContentSize(100,54); this.EvnBtn.y = -5; this.LabourBtn.y = -5; this.ShopBtn.y = -5; this.SpeBuildingBtn.y = -5; this.SeedBtn.y = -5; this.FruitBtn.y = -5; this.HiddenAll(); //面板设置index //环境 if ('0' == index) { this.EvnBtn.y = -20; 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); this.EvnBtn.setContentSize(86,88); } //劳动 else if ('1' == index) { this.LabourBtn.y = -20; 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); this.LabourBtn.setContentSize(86,88); } //商铺 else if ('2' == index) { this.ShopBtn.y = -20; 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); this.ShopBtn.setContentSize(86,88); } //特殊 else if ('3' == index) { this.SpeBuildingBtn.y = -20; 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.SpeBuildingBtn.setContentSize(86,88); } //种子 else if ('4' == index) { this.SeedBtn.y = -20; this.SeedBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Seed_Sprite; this.Seed.active = true; this.SelectedFrame.parent = this.Building40; GlobalD.GameData.getMallSeed(function(res, vaule) { let Synopsis = "成熟期:"+maturity; this.ManageUI.getComponent('ManageUI').onSetButtonInfo(vaule.data[0].name, vaule.data[0].price, Synopsis); }); // "id": 1, // "mallType": "0", // "picture": null, // "name": "白菜种子", // "maturity": 100, // "planting": 100, // "harvestQuantity": 2500, // "harvestCount": 2500, // "harvestName": "大白菜", // "price": 99, // "amount": 0, // "withered": 200, // "createTime": "2022-01-10 16:45:18", // "updateTime": "2022-01-10 16:45:26" // }, this.SeedBtn.setSiblingIndex(10); this.SeedBtn.setContentSize(86,88); } //果实 else if ('5' == index) { this.FruitBtn.y = -20; this.FruitBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Fruit_Sprite; this.Fruit.active = true; this.SelectedFrame.parent = this.Building50; // { // "id": 1, // "picture": null, // "name": "白菜", // "priceSnb": 99, // "priceCnt": 9.9, // "createTime": "2022-01-10 16:45:18", // "updateTime": "2022-01-10 16:45:26" // } GlobalD.GameData.getMallSeed(function(res, vaule) { let Price = 'Snb:'+vaule.data[0].priceSnb+' Cnt:'+vaule.data[0].priceCnt; let Synopsis = "成熟期:"+maturity; this.ManageUI.getComponent('ManageUI').onSetButtonInfo(vaule.data[0].name, Price, Synopsis); }); this.FruitBtn.setSiblingIndex(10); this.FruitBtn.setContentSize(86,88); } //切换节点顺序 // 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); } }, });