| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- cc.Class({
- extends: cc.Component,
- properties: {
-
- Seed: {
- default: null,
- type: cc.Node,
- },
- Exchange: {
- default: null,
- type: cc.Node,
- },
- SeedBtn: {
- default: null,
- type: cc.Node,
- },
- ExchangeBtn: {
- default: null,
- type: cc.Node,
- },
- SelectedFrame: cc.Node,
-
- //Building40: cc.Node,
- ManageUI: cc.Node,
- //四个按钮对应的sprite
- Normal_Seed_Sprite: cc.SpriteFrame,
- Selecteded_Seed_Sprite: cc.SpriteFrame,
- Normal_Exchange_Sprite: cc.SpriteFrame,
- Selecteded_Exchange_Sprite: cc.SpriteFrame,
- //需要切换节点顺序的父节点
- container: cc.Node,
- //商城的列表
- mySeedList: [],
-
- seedPrefab: cc.Prefab,
- seedSpriteFrame: {
- default: [],
- type: [cc.SpriteFrame]
- },
- seedNodeArry: {
- default: [],
- type: [cc.Node]
- }
- },
- HiddenAll() {
- if (this.Seed.active)
- this.Seed.active = false;
- if (this.Exchange.active)
- this.Exchange.active = false;
- },
- start() {
- //默认设置第一个节点为 最上面
- this.SeedBtn.setSiblingIndex(10);
-
- //获取种子和果实
- GlobalD.GameData.getMallSeed((res, vaule) => {
- this.mySeedList = vaule.data.seed;
-
- for (let i = 0; i < this.mySeedList.length; i++) {
- //没有种子数量不显示 todo 看看后续需不需要处理删除
- if (this.mySeedList[i].amount < 1) continue;
- let _seed = cc.instantiate(this.seedPrefab);
- this.seedNodeArry.push(_seed);
- _seed.parent = this.Seed;
- let _seedScript = _seed.getComponent("Content_Button");
- //设置一个生成点
- let _spawnScript = _seed.getComponent("Content_seed");
- _spawnScript.SpawnPoint = cc.find("Canvas/SpawnParent/SpawnPoint");
- _seedScript.NumLabel.string = this.mySeedList[i].amount;
- _seedScript.NameLabel.string = this.mySeedList[i].name;
- switch (this.mySeedList[i].picture) {
- case "Cabbage":
- _seedScript.bgSprite.spriteFrame = this.seedSpriteFrame[0];
- break;
- case "Potato":
- _seedScript.bgSprite.spriteFrame = this.seedSpriteFrame[1];
- break;
- case "Carrot":
- _seedScript.bgSprite.spriteFrame = this.seedSpriteFrame[2];
- break;
- case "Broccoli":
- _seedScript.bgSprite.spriteFrame = this.seedSpriteFrame[3];
- break;
- case "Tomato":
- _seedScript.bgSprite.spriteFrame = this.seedSpriteFrame[4];
- break;
- case "Squash":
- _seedScript.bgSprite.spriteFrame = this.seedSpriteFrame[5];
- break;
- case "Eggplant":
- _seedScript.bgSprite.spriteFrame = this.seedSpriteFrame[6];
- break;
- case "Pepper":
- _seedScript.bgSprite.spriteFrame = this.seedSpriteFrame[7];
- break;
- default:
- break;
- }
- }
- });
- },
- //切换建筑的面板
- onSwitchBuildingContent(event, index) {
- this.SeedBtn.setScale(1);
- this.ExchangeBtn.setScale(1);
- this.SeedBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_Seed_Sprite;
- this.ExchangeBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_Exchange_Sprite;
- this.SeedBtn.setContentSize(100, 54);
- this.ExchangeBtn.setContentSize(100, 54);
- this.SeedBtn.y = -5;
- this.ExchangeBtn.y = -5;
- this.HiddenAll();
- //面板设置index
-
- //种子
- if ('0' == index) {
- this.SeedBtn.y = -20;
- this.SeedBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Seed_Sprite;
- this.Seed.active = true;
- if(this.seedNodeArry.length!=0)
- {
- this.SelectedFrame.parent = this.seedNodeArry[0];
- }
-
- //if (this.mySeedList.length > 0) {
- // let Synopsis = "成熟期:" + this.mySeedList[0].maturity;
- // this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.mySeedList[0].name, this.mySeedList[0].priceSnb, Synopsis);
- //}
-
- this.SeedBtn.setSiblingIndex(10);
- this.SeedBtn.setContentSize(86, 88);
- }
- //兑换
- else if ('1' == index) {
- this.ExchangeBtn.y = -20;
- this.ExchangeBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Exchange_Sprite;
- this.Exchange.active = true;
- this.ExchangeBtn.setSiblingIndex(10);
- this.ExchangeBtn.setContentSize(86, 88);
- }
- },
- 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);
- }
- },
- });
|