BuildingView.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. EvnBtn: {
  21. default: null,
  22. type: cc.Node,
  23. },
  24. LabourBtn: {
  25. default: null,
  26. type: cc.Node,
  27. },
  28. ShopBtn: {
  29. default: null,
  30. type: cc.Node,
  31. },
  32. SpeBuildingBtn: {
  33. default: null,
  34. type: cc.Node,
  35. },
  36. SelectedFrame: cc.Node,
  37. Building00: cc.Node,
  38. Building10: cc.Node,
  39. Building20: cc.Node,
  40. Building30: cc.Node,
  41. ManageUI: cc.Node,
  42. //四个按钮对应的sprite
  43. Normal_Env_Sprite: cc.SpriteFrame,
  44. Selecteded_Env_Sprite: cc.SpriteFrame,
  45. Normal_Labour_Sprite: cc.SpriteFrame,
  46. Selecteded_Labour_Sprite: cc.SpriteFrame,
  47. Normal_Shop_Sprite: cc.SpriteFrame,
  48. Selecteded_Shop_Sprite: cc.SpriteFrame,
  49. Normal_Spe_Sprite: cc.SpriteFrame,
  50. Selecteded_Spe_Sprite: cc.SpriteFrame,
  51. //需要切换节点顺序的父节点
  52. container: cc.Node
  53. },
  54. HiddenAll() {
  55. if (this.Env.active)
  56. this.Env.active = false;
  57. if (this.Labour.active)
  58. this.Labour.active = false;
  59. if (this.Shop.active)
  60. this.Shop.active = false;
  61. if (this.SpeBuilding.active)
  62. this.SpeBuilding.active = false;
  63. },
  64. start(){
  65. //默认设置第一个节点为 最上面
  66. this.EvnBtn.setSiblingIndex(10);
  67. },
  68. //切换建筑的面板
  69. onSwitchBuildingContent(event, index) {
  70. this.EvnBtn.setScale(1);
  71. this.LabourBtn.setScale(1);
  72. this.ShopBtn.setScale(1);
  73. this.SpeBuildingBtn.setScale(1);
  74. this.EvnBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_Env_Sprite;
  75. this.LabourBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_Labour_Sprite;
  76. this.ShopBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_Shop_Sprite;
  77. this.SpeBuildingBtn.getComponent(cc.Sprite).spriteFrame = this.Normal_Spe_Sprite;
  78. this.EvnBtn.y = 0;
  79. this.LabourBtn.y = 0;
  80. this.ShopBtn.y = 0;
  81. this.SpeBuildingBtn.y = 0;
  82. this.HiddenAll();
  83. //面板设置index
  84. //环境
  85. if ('0' == index) {
  86. this.EvnBtn.y = -30;
  87. this.EvnBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Env_Sprite;
  88. this.Env.active = true;
  89. this.SelectedFrame.parent = this.Building00;
  90. this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.Building00.getComponent('Content_Button').Name, this.Building00.getComponent('Content_Button').Price, this.Building00.getComponent('Content_Button').Synopsis);
  91. //设置节点顺序
  92. this.EvnBtn.setSiblingIndex(10);
  93. }
  94. //劳动
  95. else if ('1' == index) {
  96. this.LabourBtn.y = -30;
  97. this.LabourBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Labour_Sprite;
  98. this.Labour.active = true;
  99. this.SelectedFrame.parent = this.Building10;
  100. this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.Building10.getComponent('Content_Button').Name, this.Building10.getComponent('Content_Button').Price, this.Building10.getComponent('Content_Button').Synopsis);
  101. this.LabourBtn.setSiblingIndex(10);
  102. }
  103. //商铺
  104. else if ('2' == index) {
  105. this.ShopBtn.y = -30;
  106. this.ShopBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Shop_Sprite;
  107. this.Shop.active = true;
  108. this.SelectedFrame.parent = this.Building20;
  109. this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.Building20.getComponent('Content_Button').Name, this.Building20.getComponent('Content_Button').Price, this.Building20.getComponent('Content_Button').Synopsis);
  110. this.ShopBtn.setSiblingIndex(10);
  111. } else if ('3' == index) {
  112. this.SpeBuildingBtn.y = -30;
  113. this.SpeBuildingBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Spe_Sprite;
  114. this.SpeBuilding.active = true;
  115. this.SelectedFrame.parent = this.Building30;
  116. this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.Building30.getComponent('Content_Button').Name, this.Building30.getComponent('Content_Button').Price, this.Building30.getComponent('Content_Button').Synopsis);
  117. this.SpeBuildingBtn.setSiblingIndex(10);
  118. }
  119. //切换节点顺序
  120. // this.switch();
  121. },
  122. switch: function () {
  123. var children = this.container.children;
  124. var length = children.length;
  125. if (length > 1) {
  126. var src = Math.floor(Math.random() * length);
  127. var node = children[src];
  128. var dst = src === length - 1 ? 0 : src + 1;
  129. node.setSiblingIndex(dst);
  130. }
  131. },
  132. });