StoreView.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. Seed: {
  5. default: null,
  6. type: cc.Node,
  7. },
  8. Exchange: {
  9. default: null,
  10. type: cc.Node,
  11. },
  12. SeedBtn: {
  13. default: null,
  14. type: cc.Node,
  15. },
  16. ExchangeBtn: {
  17. default: null,
  18. type: cc.Node,
  19. },
  20. SelectedFrame: cc.Node,
  21. //Building40: cc.Node,
  22. ManageUI: cc.Node,
  23. //四个按钮对应的sprite
  24. Normal_Seed_Sprite: cc.SpriteFrame,
  25. Selecteded_Seed_Sprite: cc.SpriteFrame,
  26. Normal_Exchange_Sprite: cc.SpriteFrame,
  27. Selecteded_Exchange_Sprite: cc.SpriteFrame,
  28. //需要切换节点顺序的父节点
  29. container: cc.Node,
  30. //商城的列表
  31. mySeedList: [],
  32. seedPrefab: cc.Prefab,
  33. seedSpriteFrame: {
  34. default: [],
  35. type: [cc.SpriteFrame]
  36. }
  37. },
  38. HiddenAll() {
  39. if (this.Seed.active)
  40. this.Seed.active = false;
  41. if (this.Exchange.active)
  42. this.Exchange.active = false;
  43. },
  44. start() {
  45. this.seedNodeArry = [];
  46. //默认设置第一个节点为 最上面
  47. this.SeedBtn.setSiblingIndex(10);
  48. //获取种子和果实
  49. GlobalD.GameData.getMallSeed((res, vaule) => {
  50. this.mySeedList = vaule.data.seed;
  51. //this.myFruitList = vaule.data.fruit;
  52. //console.log(this.mySeedList, this.myFruitList);
  53. for (let i = 0; i < this.mySeedList.length; i++) {
  54. //没有种子数量不显示 todo 看看后续需不需要处理删除
  55. if (this.mySeedList[i].amount < 1) continue;
  56. let _seed = cc.instantiate(this.seedPrefab);
  57. this.seedNodeArry.push(_seed);
  58. _seed.parent = this.Seed;
  59. let _seedScript = _seed.getComponent("Content_Button");
  60. //设置一个生成点
  61. let _spawnScript = _seed.getComponent("Content_seed");
  62. _spawnScript.SpawnPoint = cc.find("Canvas/SpawnParent/SpawnPoint");
  63. _seedScript.NumLabel.string = this.mySeedList[i].amount;
  64. _seedScript.NameLabel.string = this.mySeedList[i].name;
  65. switch (this.mySeedList[i].picture) {
  66. case "Cabbage":
  67. _seedScript.bgSprite.spriteFrame = this.seedSpriteFrame[0];
  68. break;
  69. case "Potato":
  70. _seedScript.bgSprite.spriteFrame = this.seedSpriteFrame[1];
  71. break;
  72. case "Carrot":
  73. _seedScript.bgSprite.spriteFrame = this.seedSpriteFrame[2];
  74. break;
  75. case "Broccoli":
  76. _seedScript.bgSprite.spriteFrame = this.seedSpriteFrame[3];
  77. break;
  78. case "Tomato":
  79. _seedScript.bgSprite.spriteFrame = this.seedSpriteFrame[4];
  80. break;
  81. case "Squash":
  82. _seedScript.bgSprite.spriteFrame = this.seedSpriteFrame[5];
  83. break;
  84. case "Eggplant":
  85. _seedScript.bgSprite.spriteFrame = this.seedSpriteFrame[6];
  86. break;
  87. case "Pepper":
  88. _seedScript.bgSprite.spriteFrame = this.seedSpriteFrame[7];
  89. break;
  90. default:
  91. break;
  92. }
  93. }
  94. });
  95. },
  96. //切换建筑的面板
  97. onSwitchBuildingContent(event, index) {
  98. this.SeedBtn.setScale(1);
  99. this.ExchangeBtn.setScale(1);
  100. this.SeedBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_Seed_Sprite;
  101. this.ExchangeBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_Fruit_Sprite;
  102. this.SeedBtn.setContentSize(100, 54);
  103. this.ExchangeBtn.setContentSize(100, 54);
  104. this.SeedBtn.y = -5;
  105. this.ExchangeBtn.y = -5;
  106. this.HiddenAll();
  107. //面板设置index
  108. //种子
  109. if ('1' == index) {
  110. this.SeedBtn.y = -20;
  111. this.SeedBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Seed_Sprite;
  112. this.Seed.active = true;
  113. this.SelectedFrame.parent = this.seedNodeArry[0];
  114. if (this.mySeedList.length > 0) {
  115. let Synopsis = "成熟期:" + this.mySeedList[0].maturity;
  116. this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.mySeedList[0].name, this.mySeedList[0].priceSnb, Synopsis);
  117. }
  118. this.SeedBtn.setSiblingIndex(10);
  119. this.SeedBtn.setContentSize(86, 88);
  120. // {
  121. // "id": 1,
  122. // "mallType": "0",
  123. // "picture": null,
  124. // "name": "白菜种子",
  125. // "maturity": 100,
  126. // "planting": 100,
  127. // "harvestQuantity": 2500,
  128. // "harvestCount": 2500,
  129. // "harvestName": "大白菜",
  130. // "price": 99,
  131. // "amount": 0,
  132. // "withered": 200,
  133. // "createTime": "2022-01-10 16:45:18",
  134. // "updateTime": "2022-01-10 16:45:26"
  135. // },
  136. }
  137. //兑换
  138. else if ('2' == index) {
  139. this.FruitBtn.y = -20;
  140. this.FruitBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Fruit_Sprite;
  141. this.Fruit.active = true;
  142. this.ExchangeBtn.setSiblingIndex(10);
  143. this.ExchangeBtn.setContentSize(86, 88);
  144. }
  145. },
  146. switch: function () {
  147. var children = this.container.children;
  148. var length = children.length;
  149. if (length > 1) {
  150. var src = Math.floor(Math.random() * length);
  151. var node = children[src];
  152. var dst = src === length - 1 ? 0 : src + 1;
  153. node.setSiblingIndex(dst);
  154. }
  155. },
  156. });