| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- 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;
- this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.Building40.getComponent('Content_Button').Name, this.Building40.getComponent('Content_Button').Price, this.Building40.getComponent('Content_Button').Synopsis);
- 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;
- this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.Building50.getComponent('Content_Button').Name, this.Building50.getComponent('Content_Button').Price, this.Building50.getComponent('Content_Button').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);
- }
- },
- });
|