BuildingView.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.Building40.getComponent('Content_Button').Name, this.Building40.getComponent('Content_Button').Price, this.Building40.getComponent('Content_Button').Synopsis);
  170. this.SeedBtn.setSiblingIndex(10);
  171. this.SeedBtn.setContentSize(86,88);
  172. }
  173. //果实
  174. else if ('5' == index) {
  175. this.FruitBtn.y = -20;
  176. this.FruitBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Fruit_Sprite;
  177. this.Fruit.active = true;
  178. this.SelectedFrame.parent = this.Building50;
  179. this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.Building50.getComponent('Content_Button').Name, this.Building50.getComponent('Content_Button').Price, this.Building50.getComponent('Content_Button').Synopsis);
  180. this.FruitBtn.setSiblingIndex(10);
  181. this.FruitBtn.setContentSize(86,88);
  182. }
  183. //切换节点顺序
  184. // this.switch();
  185. },
  186. switch: function () {
  187. var children = this.container.children;
  188. var length = children.length;
  189. if (length > 1) {
  190. var src = Math.floor(Math.random() * length);
  191. var node = children[src];
  192. var dst = src === length - 1 ? 0 : src + 1;
  193. node.setSiblingIndex(dst);
  194. }
  195. },
  196. });