StoreView.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. seedNodeArry: {
  38. default: [],
  39. type: [cc.Node]
  40. }
  41. },
  42. HiddenAll() {
  43. if (this.Seed.active)
  44. this.Seed.active = false;
  45. if (this.Exchange.active)
  46. this.Exchange.active = false;
  47. },
  48. start() {
  49. //默认设置第一个节点为 最上面
  50. this.SeedBtn.setSiblingIndex(10);
  51. //获取种子和果实
  52. GlobalD.GameData.getMallSeed((res, vaule) => {
  53. this.mySeedList = vaule.data.seed;
  54. for (let i = 0; i < this.mySeedList.length; i++) {
  55. //没有种子数量不显示 todo 看看后续需不需要处理删除
  56. if (this.mySeedList[i].amount < 1) continue;
  57. let _seed = cc.instantiate(this.seedPrefab);
  58. this.seedNodeArry.push(_seed);
  59. _seed.parent = this.Seed;
  60. let _seedScript = _seed.getComponent("Content_Button");
  61. //设置一个生成点
  62. let _spawnScript = _seed.getComponent("Content_seed");
  63. _spawnScript.SpawnPoint = cc.find("Canvas/SpawnParent/SpawnPoint");
  64. _seedScript.NumLabel.string = this.mySeedList[i].amount;
  65. _seedScript.NameLabel.string = this.mySeedList[i].name;
  66. switch (this.mySeedList[i].picture) {
  67. case "Cabbage":
  68. _seedScript.bgSprite.spriteFrame = this.seedSpriteFrame[0];
  69. break;
  70. case "Potato":
  71. _seedScript.bgSprite.spriteFrame = this.seedSpriteFrame[1];
  72. break;
  73. case "Carrot":
  74. _seedScript.bgSprite.spriteFrame = this.seedSpriteFrame[2];
  75. break;
  76. case "Broccoli":
  77. _seedScript.bgSprite.spriteFrame = this.seedSpriteFrame[3];
  78. break;
  79. case "Tomato":
  80. _seedScript.bgSprite.spriteFrame = this.seedSpriteFrame[4];
  81. break;
  82. case "Squash":
  83. _seedScript.bgSprite.spriteFrame = this.seedSpriteFrame[5];
  84. break;
  85. case "Eggplant":
  86. _seedScript.bgSprite.spriteFrame = this.seedSpriteFrame[6];
  87. break;
  88. case "Pepper":
  89. _seedScript.bgSprite.spriteFrame = this.seedSpriteFrame[7];
  90. break;
  91. default:
  92. break;
  93. }
  94. }
  95. });
  96. },
  97. //切换建筑的面板
  98. onSwitchBuildingContent(event, index) {
  99. this.SeedBtn.setScale(1);
  100. this.ExchangeBtn.setScale(1);
  101. this.SeedBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_Seed_Sprite;
  102. this.ExchangeBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_Exchange_Sprite;
  103. this.SeedBtn.setContentSize(100, 54);
  104. this.ExchangeBtn.setContentSize(100, 54);
  105. this.SeedBtn.y = -5;
  106. this.ExchangeBtn.y = -5;
  107. this.HiddenAll();
  108. //面板设置index
  109. //种子
  110. if ('0' == index) {
  111. this.SeedBtn.y = -20;
  112. this.SeedBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Seed_Sprite;
  113. this.Seed.active = true;
  114. if(this.seedNodeArry.length!=0)
  115. {
  116. this.SelectedFrame.parent = this.seedNodeArry[0];
  117. }
  118. //if (this.mySeedList.length > 0) {
  119. // let Synopsis = "成熟期:" + this.mySeedList[0].maturity;
  120. // this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.mySeedList[0].name, this.mySeedList[0].priceSnb, Synopsis);
  121. //}
  122. this.SeedBtn.setSiblingIndex(10);
  123. this.SeedBtn.setContentSize(86, 88);
  124. }
  125. //兑换
  126. else if ('1' == index) {
  127. this.ExchangeBtn.y = -20;
  128. this.ExchangeBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Exchange_Sprite;
  129. this.Exchange.active = true;
  130. this.ExchangeBtn.setSiblingIndex(10);
  131. this.ExchangeBtn.setContentSize(86, 88);
  132. }
  133. },
  134. switch: function () {
  135. var children = this.container.children;
  136. var length = children.length;
  137. if (length > 1) {
  138. var src = Math.floor(Math.random() * length);
  139. var node = children[src];
  140. var dst = src === length - 1 ? 0 : src + 1;
  141. node.setSiblingIndex(dst);
  142. }
  143. },
  144. });