| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- var reGameStates = require('GameStates');
- cc.Class({
- extends: cc.Component,
- properties: {
- //名称
- buildName: {
- default: null,
- type: cc.Label,
- },
- //维护费
- runingCost: {
- default: null,
- type: cc.Label,
- },
- //库存
- inventory: {
- default: null,
- type: cc.Label,
- },
- //简介
- synopsis: {
- default: null,
- type: cc.Label,
- },
- //介绍图片
- imageSprite: {
- default: null,
- type: cc.Sprite,
- },
- //商品名称
- commodityName: {
- default: null,
- type: cc.Label,
- },
- //商品价格
- commodityPrice: {
- default: null,
- type: cc.Label,
- },
- strength: {
- default: null,
- type: cc.Label,
- },
- //列表的对象
- // CommodityItems: {
- // default: [],
- // visible: false,
- // },
- //记录当前商品的信息
- goodsArray: {
- default: null,
- visible: false,
- },
- SalesInfoBg: {
- default: null,
- type: cc.Node
- },
- ProductionInfoBg: {
- default: null,
- type: cc.Node
- },
- //需要的农作物
- materialCrops: {
- default: null,
- type: cc.Label,
- },
- //需要的木材
- materialWood: {
- default: null,
- type: cc.Label,
- },
- //需要的矿石
- materialMineral: {
- default: null,
- type: cc.Label,
- },
- //除了商店,展开otherNode时候的模板
- //名称
- otherBuildName: {
- default: null,
- type: cc.Label,
- },
- //维护费
- otherRuningCost: {
- default: null,
- type: cc.Label,
- },
- //库存
- otherInventory: {
- default: null,
- type: cc.Label,
- },
- //简介
- otherSynopsis: {
- default: null,
- type: cc.Label,
- },
- //介绍图片
- otherImageSprite: {
- default: null,
- type: cc.Sprite,
- },
- //商品名称
- otherCommodityName: {
- default: null,
- type: cc.Label,
- },
- //商品价格
- otherCommodityPrice: {
- default: null,
- type: cc.Label,
- },
- //销售或者生产力
- otherProductivity: {
- default: null,
- type: cc.Label,
- },
- },
- onSetBuildingInfoView(buildingInfo) {
- switch (buildingInfo.buildType) {
- // //特殊建筑
- // case reGameStates.BuildType.Special:
- // break;
- // //住房
- // case reGameStates.BuildType.Housing:
- // break;
- case reGameStates.BuildType.Shop:
- this.inventory.string = buildingInfo._inventory;
- this.buildName.string = buildingInfo.buildingName;
- this.runingCost.string = buildingInfo.RunningCost;
- this.synopsis.string = buildingInfo.BuildingSynopsis;
- if (buildingInfo.BuildingSprite)
- this.imageSprite.spriteFrame = buildingInfo.BuildingSprite.spriteFrame;
- else
- this.imageSprite.spriteFrame = null;
- //显示当前商品信息
- if (buildingInfo._goods) {
- this.commodityName.string = buildingInfo._goods.goodsName;
- this.commodityPrice.string = buildingInfo._goods.goodsPrice;
- //原材料
- this.materialCrops.string = buildingInfo._goods.goodsMaterial.crops;
- this.materialWood.string = buildingInfo._goods.goodsMaterial.wood;
- this.materialMineral.string = buildingInfo._goods.goodsMaterial.mineral;
- }
- this.strength.string = buildingInfo.totalConsumption;
- //保存当前的商品信息
- this.goodsArray = buildingInfo.goodsArray;
- if (this.SalesInfoBg)
- this.SalesInfoBg.active = true;
- if (this.ProductionInfoBg)
- this.ProductionInfoBg.active = false;
- break;
- //如果是农田,采木场,矿坑
- case reGameStates.BuildType.Farmland:
- case reGameStates.BuildType.TimberYard:
- case reGameStates.BuildType.MiningPit:
- this.onSetProductionInfo(buildingInfo);
- let goodsArray = buildingInfo.goodsArray;
- let length = goodsArray.length;
- if (length == 0) {
- this.otherCommodityName.string = '';
- this.otherCommodityPrice.string = '';
- } else {
- //当前销售的商品
- for (let i = 0; i < length; i++) {
- if (goodsArray[i].isItSale) {
- this.otherCommodityName.string = goodsArray[i].goodsName;
- this.otherCommodityPrice.string = goodsArray[i].goodsPrice;
- break;
- }
- }
- }
- break;
- case reGameStates.BuildType.Factory:
- //如果true,就是点击了工厂
- this.onSetProductionInfo(buildingInfo);
- if (buildingInfo._goods) {
- this.otherCommodityName.string = buildingInfo._goods.goodsName;
- this.otherCommodityPrice.string = buildingInfo._goods.goodsPrice;
- } else {
- this.otherCommodityName.string = '';
- this.otherCommodityPrice.string = '';
- }
- break;
- }
- },
- //显示销售的信息
- onSetProductionInfo(buildingInfo) {
- this.otherInventory.string = buildingInfo._inventory;
- this.otherBuildName.string = buildingInfo.buildingName;
- this.otherRuningCost.string = buildingInfo.RunningCost;
- this.otherSynopsis.string = buildingInfo.BuildingSynopsis;
- if (buildingInfo.BuildingSprite)
- this.otherImageSprite.spriteFrame = buildingInfo.BuildingSprite.spriteFrame;
- else
- this.otherImageSprite.spriteFrame = null;
- this.otherProductivity.string = buildingInfo.totalConsumption;
- if (this.SalesInfoBg)
- this.SalesInfoBg.active = false;
- if (this.ProductionInfoBg)
- this.ProductionInfoBg.active = true;
- },
- //显示商店信息
- onSetShopInfo(buildingInfo) {
- //显示对应的父节点
- this.inventory.string = buildingInfo._inventory;
- this.buildName.string = buildingInfo.buildingName;
- this.runingCost.string = buildingInfo.RunningCost;
- this.synopsis.string = buildingInfo.BuildingSynopsis;
- if (buildingInfo.BuildingSprite)
- this.imageSprite.spriteFrame = buildingInfo.BuildingSprite.spriteFrame;
- // cc.log('buildingInfo',buildingInfo);
- //显示当前商品信息
- if (buildingInfo._goods) {
- this.commodityName.string = buildingInfo._goods.goodsName;
- this.commodityPrice.string = buildingInfo._goods.goodsPrice;
- //原材料
- this.materialCrops.string = buildingInfo._goods.goodsMaterial.crops;
- this.materialWood.string = buildingInfo._goods.goodsMaterial.wood;
- this.materialMineral.string = buildingInfo._goods.goodsMaterial.mineral;
- }
- this.strength.string = buildingInfo.totalConsumption;
- //保存当前的商品信息
- this.goodsArray = buildingInfo.goodsArray;
- if (this.SalesInfoBg)
- this.SalesInfoBg.active = true;
- if (this.ProductionInfoBg)
- this.ProductionInfoBg.active = false;
- },
- //点击更换商品时候显示
- // onSetCommodityInfo() {
- // //隐藏对应的父节点
- // this.buildName.string = '商品列表';
- // this.content = this.CommodityScrollView.content;
- // this.spacing = 10;
- // this.ClearItems();
- // let length = this.goodsArray.length;
- // this.initialize(length, length);
- // },
- //生成商品列表
- // initialize: function (totalCount, spawnCount) {
- // this.content.height = totalCount * (this.CommodityTemplate.height + this.spacing) + this.spacing; // get total content height
- // for (let i = 0; i < spawnCount; ++i) { // spawn items, we only need to do this once
- // let item = cc.instantiate(this.CommodityTemplate);
- // item.active = true;
- // this.content.addChild(item);
- // item.setPosition(0, -item.height * (0.5 + i) - this.spacing * (i + 1));
- // item.getComponent('CommodityItem').updateItem(i, i, this.goodsArray[i]);
- // this.CommodityItems.push(item);
- // }
- // },
- //清空UI商品列表
- // ClearItems() {
- // let length = this.CommodityItems.length;
- // for (let i = length - 1; i >= 0; i--) { // spawn items, we only need to do this once
- // this.CommodityItems[i].destroy();
- // }
- // }
- });
|