buildingInfoView.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. var reGameStates = require('GameStates');
  2. cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. //名称
  6. buildName: {
  7. default: null,
  8. type: cc.Label,
  9. },
  10. //维护费
  11. runingCost: {
  12. default: null,
  13. type: cc.Label,
  14. },
  15. //库存
  16. inventory: {
  17. default: null,
  18. type: cc.Label,
  19. },
  20. //简介
  21. synopsis: {
  22. default: null,
  23. type: cc.Label,
  24. },
  25. //介绍图片
  26. imageSprite: {
  27. default: null,
  28. type: cc.Sprite,
  29. },
  30. //商品名称
  31. commodityName: {
  32. default: null,
  33. type: cc.Label,
  34. },
  35. //商品价格
  36. commodityPrice: {
  37. default: null,
  38. type: cc.Label,
  39. },
  40. strength: {
  41. default: null,
  42. type: cc.Label,
  43. },
  44. //列表的对象
  45. // CommodityItems: {
  46. // default: [],
  47. // visible: false,
  48. // },
  49. //记录当前商品的信息
  50. goodsArray: {
  51. default: null,
  52. visible: false,
  53. },
  54. SalesInfoBg: {
  55. default: null,
  56. type: cc.Node
  57. },
  58. ProductionInfoBg: {
  59. default: null,
  60. type: cc.Node
  61. },
  62. //需要的农作物
  63. materialCrops: {
  64. default: null,
  65. type: cc.Label,
  66. },
  67. //需要的木材
  68. materialWood: {
  69. default: null,
  70. type: cc.Label,
  71. },
  72. //需要的矿石
  73. materialMineral: {
  74. default: null,
  75. type: cc.Label,
  76. },
  77. //除了商店,展开otherNode时候的模板
  78. //名称
  79. otherBuildName: {
  80. default: null,
  81. type: cc.Label,
  82. },
  83. //维护费
  84. otherRuningCost: {
  85. default: null,
  86. type: cc.Label,
  87. },
  88. //库存
  89. otherInventory: {
  90. default: null,
  91. type: cc.Label,
  92. },
  93. //简介
  94. otherSynopsis: {
  95. default: null,
  96. type: cc.Label,
  97. },
  98. //介绍图片
  99. otherImageSprite: {
  100. default: null,
  101. type: cc.Sprite,
  102. },
  103. //商品名称
  104. otherCommodityName: {
  105. default: null,
  106. type: cc.Label,
  107. },
  108. //商品价格
  109. otherCommodityPrice: {
  110. default: null,
  111. type: cc.Label,
  112. },
  113. //销售或者生产力
  114. otherProductivity: {
  115. default: null,
  116. type: cc.Label,
  117. },
  118. },
  119. onSetBuildingInfoView(buildingInfo) {
  120. switch (buildingInfo.buildType) {
  121. // //特殊建筑
  122. // case reGameStates.BuildType.Special:
  123. // break;
  124. // //住房
  125. // case reGameStates.BuildType.Housing:
  126. // break;
  127. case reGameStates.BuildType.Shop:
  128. this.inventory.string = buildingInfo._inventory;
  129. this.buildName.string = buildingInfo.buildingName;
  130. this.runingCost.string = buildingInfo.RunningCost;
  131. this.synopsis.string = buildingInfo.BuildingSynopsis;
  132. if (buildingInfo.BuildingSprite)
  133. this.imageSprite.spriteFrame = buildingInfo.BuildingSprite.spriteFrame;
  134. else
  135. this.imageSprite.spriteFrame = null;
  136. //显示当前商品信息
  137. if (buildingInfo._goods) {
  138. this.commodityName.string = buildingInfo._goods.goodsName;
  139. this.commodityPrice.string = buildingInfo._goods.goodsPrice;
  140. //原材料
  141. this.materialCrops.string = buildingInfo._goods.goodsMaterial.crops;
  142. this.materialWood.string = buildingInfo._goods.goodsMaterial.wood;
  143. this.materialMineral.string = buildingInfo._goods.goodsMaterial.mineral;
  144. }
  145. this.strength.string = buildingInfo.totalConsumption;
  146. //保存当前的商品信息
  147. this.goodsArray = buildingInfo.goodsArray;
  148. if (this.SalesInfoBg)
  149. this.SalesInfoBg.active = true;
  150. if (this.ProductionInfoBg)
  151. this.ProductionInfoBg.active = false;
  152. break;
  153. //如果是农田,采木场,矿坑
  154. case reGameStates.BuildType.Farmland:
  155. case reGameStates.BuildType.TimberYard:
  156. case reGameStates.BuildType.MiningPit:
  157. this.onSetProductionInfo(buildingInfo);
  158. let goodsArray = buildingInfo.goodsArray;
  159. let length = goodsArray.length;
  160. if (length == 0) {
  161. this.otherCommodityName.string = '';
  162. this.otherCommodityPrice.string = '';
  163. } else {
  164. //当前销售的商品
  165. for (let i = 0; i < length; i++) {
  166. if (goodsArray[i].isItSale) {
  167. this.otherCommodityName.string = goodsArray[i].goodsName;
  168. this.otherCommodityPrice.string = goodsArray[i].goodsPrice;
  169. break;
  170. }
  171. }
  172. }
  173. break;
  174. case reGameStates.BuildType.Factory:
  175. //如果true,就是点击了工厂
  176. this.onSetProductionInfo(buildingInfo);
  177. if (buildingInfo._goods) {
  178. this.otherCommodityName.string = buildingInfo._goods.goodsName;
  179. this.otherCommodityPrice.string = buildingInfo._goods.goodsPrice;
  180. } else {
  181. this.otherCommodityName.string = '';
  182. this.otherCommodityPrice.string = '';
  183. }
  184. break;
  185. }
  186. },
  187. //显示销售的信息
  188. onSetProductionInfo(buildingInfo) {
  189. this.otherInventory.string = buildingInfo._inventory;
  190. this.otherBuildName.string = buildingInfo.buildingName;
  191. this.otherRuningCost.string = buildingInfo.RunningCost;
  192. this.otherSynopsis.string = buildingInfo.BuildingSynopsis;
  193. if (buildingInfo.BuildingSprite)
  194. this.otherImageSprite.spriteFrame = buildingInfo.BuildingSprite.spriteFrame;
  195. else
  196. this.otherImageSprite.spriteFrame = null;
  197. this.otherProductivity.string = buildingInfo.totalConsumption;
  198. if (this.SalesInfoBg)
  199. this.SalesInfoBg.active = false;
  200. if (this.ProductionInfoBg)
  201. this.ProductionInfoBg.active = true;
  202. },
  203. //显示商店信息
  204. onSetShopInfo(buildingInfo) {
  205. //显示对应的父节点
  206. this.inventory.string = buildingInfo._inventory;
  207. this.buildName.string = buildingInfo.buildingName;
  208. this.runingCost.string = buildingInfo.RunningCost;
  209. this.synopsis.string = buildingInfo.BuildingSynopsis;
  210. if (buildingInfo.BuildingSprite)
  211. this.imageSprite.spriteFrame = buildingInfo.BuildingSprite.spriteFrame;
  212. // cc.log('buildingInfo',buildingInfo);
  213. //显示当前商品信息
  214. if (buildingInfo._goods) {
  215. this.commodityName.string = buildingInfo._goods.goodsName;
  216. this.commodityPrice.string = buildingInfo._goods.goodsPrice;
  217. //原材料
  218. this.materialCrops.string = buildingInfo._goods.goodsMaterial.crops;
  219. this.materialWood.string = buildingInfo._goods.goodsMaterial.wood;
  220. this.materialMineral.string = buildingInfo._goods.goodsMaterial.mineral;
  221. }
  222. this.strength.string = buildingInfo.totalConsumption;
  223. //保存当前的商品信息
  224. this.goodsArray = buildingInfo.goodsArray;
  225. if (this.SalesInfoBg)
  226. this.SalesInfoBg.active = true;
  227. if (this.ProductionInfoBg)
  228. this.ProductionInfoBg.active = false;
  229. },
  230. //点击更换商品时候显示
  231. // onSetCommodityInfo() {
  232. // //隐藏对应的父节点
  233. // this.buildName.string = '商品列表';
  234. // this.content = this.CommodityScrollView.content;
  235. // this.spacing = 10;
  236. // this.ClearItems();
  237. // let length = this.goodsArray.length;
  238. // this.initialize(length, length);
  239. // },
  240. //生成商品列表
  241. // initialize: function (totalCount, spawnCount) {
  242. // this.content.height = totalCount * (this.CommodityTemplate.height + this.spacing) + this.spacing; // get total content height
  243. // for (let i = 0; i < spawnCount; ++i) { // spawn items, we only need to do this once
  244. // let item = cc.instantiate(this.CommodityTemplate);
  245. // item.active = true;
  246. // this.content.addChild(item);
  247. // item.setPosition(0, -item.height * (0.5 + i) - this.spacing * (i + 1));
  248. // item.getComponent('CommodityItem').updateItem(i, i, this.goodsArray[i]);
  249. // this.CommodityItems.push(item);
  250. // }
  251. // },
  252. //清空UI商品列表
  253. // ClearItems() {
  254. // let length = this.CommodityItems.length;
  255. // for (let i = length - 1; i >= 0; i--) { // spawn items, we only need to do this once
  256. // this.CommodityItems[i].destroy();
  257. // }
  258. // }
  259. });