BuildingView.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. Env: {
  5. default: null,
  6. type: cc.Node,
  7. },
  8. Labour: {
  9. default: null,
  10. type: cc.Node,
  11. },
  12. Shop: {
  13. default: null,
  14. type: cc.Node,
  15. },
  16. SpeBuilding: {
  17. default: null,
  18. type: cc.Node,
  19. },
  20. Seed: {
  21. default: null,
  22. type: cc.Node,
  23. },
  24. Fruit: {
  25. default: null,
  26. type: cc.Node,
  27. },
  28. EvnBtn: {
  29. default: null,
  30. type: cc.Node,
  31. },
  32. LabourBtn: {
  33. default: null,
  34. type: cc.Node,
  35. },
  36. ShopBtn: {
  37. default: null,
  38. type: cc.Node,
  39. },
  40. SpeBuildingBtn: {
  41. default: null,
  42. type: cc.Node,
  43. },
  44. SeedBtn: {
  45. default: null,
  46. type: cc.Node,
  47. },
  48. FruitBtn: {
  49. default: null,
  50. type: cc.Node,
  51. },
  52. SelectedFrame: cc.Node,
  53. Building00: cc.Node,
  54. Building10: cc.Node,
  55. Building20: cc.Node,
  56. Building30: cc.Node,
  57. Building40: cc.Node,
  58. Building50: cc.Node,
  59. ManageUI: cc.Node,
  60. //四个按钮对应的sprite
  61. Normal_Env_Sprite: cc.SpriteFrame,
  62. Selecteded_Env_Sprite: cc.SpriteFrame,
  63. Normal_Labour_Sprite: cc.SpriteFrame,
  64. Selecteded_Labour_Sprite: cc.SpriteFrame,
  65. Normal_Shop_Sprite: cc.SpriteFrame,
  66. Selecteded_Shop_Sprite: cc.SpriteFrame,
  67. Normal_Spe_Sprite: cc.SpriteFrame,
  68. Selecteded_Spe_Sprite: cc.SpriteFrame,
  69. Normal_Seed_Sprite: cc.SpriteFrame,
  70. Selecteded_Seed_Sprite: cc.SpriteFrame,
  71. Normal_Fruit_Sprite: cc.SpriteFrame,
  72. Selecteded_Fruit_Sprite: cc.SpriteFrame,
  73. //需要切换节点顺序的父节点
  74. container: cc.Node
  75. },
  76. HiddenAll() {
  77. if (this.Env.active)
  78. this.Env.active = false;
  79. if (this.Labour.active)
  80. this.Labour.active = false;
  81. if (this.Shop.active)
  82. this.Shop.active = false;
  83. if (this.SpeBuilding.active)
  84. this.SpeBuilding.active = false;
  85. if (this.Seed.active)
  86. this.Seed.active = false;
  87. if (this.Fruit.active)
  88. this.Fruit.active = false;
  89. },
  90. start(){
  91. //默认设置第一个节点为 最上面
  92. this.EvnBtn.setSiblingIndex(10);
  93. },
  94. //切换建筑的面板
  95. onSwitchBuildingContent(event, index) {
  96. this.EvnBtn.setScale(1);
  97. this.LabourBtn.setScale(1);
  98. this.ShopBtn.setScale(1);
  99. this.SpeBuildingBtn.setScale(1);
  100. this.SeedBtn.setScale(1);
  101. this.FruitBtn.setScale(1);
  102. this.EvnBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_Env_Sprite;
  103. this.LabourBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_Labour_Sprite;
  104. this.ShopBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_Shop_Sprite;
  105. this.SpeBuildingBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_Spe_Sprite;
  106. this.SeedBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_Seed_Sprite;
  107. this.FruitBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_Fruit_Sprite;
  108. this.EvnBtn.setContentSize(100,54);
  109. this.LabourBtn.setContentSize(100,54);
  110. this.ShopBtn.setContentSize(100,54);
  111. this.SpeBuildingBtn.setContentSize(100,54);
  112. this.SeedBtn.setContentSize(100,54);
  113. this.FruitBtn.setContentSize(100,54);
  114. this.EvnBtn.y = -5;
  115. this.LabourBtn.y = -5;
  116. this.ShopBtn.y = -5;
  117. this.SpeBuildingBtn.y = -5;
  118. this.SeedBtn.y = -5;
  119. this.FruitBtn.y = -5;
  120. this.HiddenAll();
  121. //面板设置index
  122. //环境
  123. if ('0' == index) {
  124. this.EvnBtn.y = -20;
  125. this.EvnBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Env_Sprite;
  126. this.Env.active = true;
  127. this.SelectedFrame.parent = this.Building00;
  128. this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.Building00.getComponent('Content_Button').Name, this.Building00.getComponent('Content_Button').Price, this.Building00.getComponent('Content_Button').Synopsis);
  129. //设置节点顺序
  130. this.EvnBtn.setSiblingIndex(10);
  131. this.EvnBtn.setContentSize(86,88);
  132. }
  133. //劳动
  134. else if ('1' == index) {
  135. this.LabourBtn.y = -20;
  136. this.LabourBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Labour_Sprite;
  137. this.Labour.active = true;
  138. this.SelectedFrame.parent = this.Building10;
  139. this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.Building10.getComponent('Content_Button').Name, this.Building10.getComponent('Content_Button').Price, this.Building10.getComponent('Content_Button').Synopsis);
  140. this.LabourBtn.setSiblingIndex(10);
  141. this.LabourBtn.setContentSize(86,88);
  142. }
  143. //商铺
  144. else if ('2' == index) {
  145. this.ShopBtn.y = -20;
  146. this.ShopBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Shop_Sprite;
  147. this.Shop.active = true;
  148. this.SelectedFrame.parent = this.Building20;
  149. this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.Building20.getComponent('Content_Button').Name, this.Building20.getComponent('Content_Button').Price, this.Building20.getComponent('Content_Button').Synopsis);
  150. this.ShopBtn.setSiblingIndex(10);
  151. this.ShopBtn.setContentSize(86,88);
  152. }
  153. //特殊
  154. else if ('3' == index) {
  155. this.SpeBuildingBtn.y = -20;
  156. this.SpeBuildingBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Spe_Sprite;
  157. this.SpeBuilding.active = true;
  158. this.SelectedFrame.parent = this.Building30;
  159. this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.Building30.getComponent('Content_Button').Name, this.Building30.getComponent('Content_Button').Price, this.Building30.getComponent('Content_Button').Synopsis);
  160. this.SpeBuildingBtn.setSiblingIndex(10);
  161. this.SpeBuildingBtn.setContentSize(86,88);
  162. }
  163. //种子
  164. else if ('4' == index) {
  165. this.SeedBtn.y = -20;
  166. this.SeedBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Seed_Sprite;
  167. this.Seed.active = true;
  168. this.SelectedFrame.parent = this.Building40;
  169. GlobalD.GameData.getMallSeed(function(res, vaule)
  170. {
  171. let Synopsis = "成熟期:"+maturity;
  172. this.ManageUI.getComponent('ManageUI').onSetButtonInfo(vaule.data[0].name, vaule.data[0].price, Synopsis);
  173. });
  174. // "id": 1,
  175. // "mallType": "0",
  176. // "picture": null,
  177. // "name": "白菜种子",
  178. // "maturity": 100,
  179. // "planting": 100,
  180. // "harvestQuantity": 2500,
  181. // "harvestCount": 2500,
  182. // "harvestName": "大白菜",
  183. // "price": 99,
  184. // "amount": 0,
  185. // "withered": 200,
  186. // "createTime": "2022-01-10 16:45:18",
  187. // "updateTime": "2022-01-10 16:45:26"
  188. // },
  189. this.SeedBtn.setSiblingIndex(10);
  190. this.SeedBtn.setContentSize(86,88);
  191. }
  192. //果实
  193. else if ('5' == index) {
  194. this.FruitBtn.y = -20;
  195. this.FruitBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Fruit_Sprite;
  196. this.Fruit.active = true;
  197. this.SelectedFrame.parent = this.Building50;
  198. // {
  199. // "id": 1,
  200. // "picture": null,
  201. // "name": "白菜",
  202. // "priceSnb": 99,
  203. // "priceCnt": 9.9,
  204. // "createTime": "2022-01-10 16:45:18",
  205. // "updateTime": "2022-01-10 16:45:26"
  206. // }
  207. GlobalD.GameData.getMallSeed(function(res, vaule)
  208. {
  209. let Price = 'Snb:'+vaule.data[0].priceSnb+' Cnt:'+vaule.data[0].priceCnt;
  210. let Synopsis = "成熟期:"+maturity;
  211. this.ManageUI.getComponent('ManageUI').onSetButtonInfo(vaule.data[0].name, Price, Synopsis);
  212. });
  213. this.FruitBtn.setSiblingIndex(10);
  214. this.FruitBtn.setContentSize(86,88);
  215. }
  216. //切换节点顺序
  217. // this.switch();
  218. },
  219. switch: function () {
  220. var children = this.container.children;
  221. var length = children.length;
  222. if (length > 1) {
  223. var src = Math.floor(Math.random() * length);
  224. var node = children[src];
  225. var dst = src === length - 1 ? 0 : src + 1;
  226. node.setSiblingIndex(dst);
  227. }
  228. },
  229. });