BuildingView.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. let posY = -5;
  86. if ('0' == index) {
  87. this.EvnBtn.y = posY;
  88. this.EvnBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Env_Sprite;
  89. this.Env.active = true;
  90. this.SelectedFrame.parent = this.Building00;
  91. this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.Building00.getComponent('Content_Button').Name, this.Building00.getComponent('Content_Button').Price, this.Building00.getComponent('Content_Button').Synopsis);
  92. //设置节点顺序
  93. this.EvnBtn.setSiblingIndex(10);
  94. }
  95. //劳动
  96. else if ('1' == index) {
  97. this.LabourBtn.y = posY;
  98. this.LabourBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Labour_Sprite;
  99. this.Labour.active = true;
  100. this.SelectedFrame.parent = this.Building10;
  101. this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.Building10.getComponent('Content_Button').Name, this.Building10.getComponent('Content_Button').Price, this.Building10.getComponent('Content_Button').Synopsis);
  102. this.LabourBtn.setSiblingIndex(10);
  103. }
  104. //商铺
  105. else if ('2' == index) {
  106. this.ShopBtn.y = posY;
  107. this.ShopBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Shop_Sprite;
  108. this.Shop.active = true;
  109. this.SelectedFrame.parent = this.Building20;
  110. this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.Building20.getComponent('Content_Button').Name, this.Building20.getComponent('Content_Button').Price, this.Building20.getComponent('Content_Button').Synopsis);
  111. this.ShopBtn.setSiblingIndex(10);
  112. } else if ('3' == index) {
  113. this.SpeBuildingBtn.y = posY;
  114. this.SpeBuildingBtn.getComponent(cc.Sprite).spriteFrame = this.Selecteded_Spe_Sprite;
  115. this.SpeBuilding.active = true;
  116. this.SelectedFrame.parent = this.Building30;
  117. this.ManageUI.getComponent('ManageUI').onSetButtonInfo(this.Building30.getComponent('Content_Button').Name, this.Building30.getComponent('Content_Button').Price, this.Building30.getComponent('Content_Button').Synopsis);
  118. this.SpeBuildingBtn.setSiblingIndex(10);
  119. }
  120. //切换节点顺序
  121. // this.switch();
  122. },
  123. switch: function () {
  124. var children = this.container.children;
  125. var length = children.length;
  126. if (length > 1) {
  127. var src = Math.floor(Math.random() * length);
  128. var node = children[src];
  129. var dst = src === length - 1 ? 0 : src + 1;
  130. node.setSiblingIndex(dst);
  131. }
  132. },
  133. });