BattleMain.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. const ViewBase = require('ViewBase');
  2. const BoxItem = require('BoxItem')
  3. const ButtonSelect1 = require('ButtonSelect1')
  4. const BattleRoomPreviweCell = require('BattleRoomPreviweCell')
  5. const SequenCreateView = require('SequenCreateView');
  6. cc.Class({
  7. extends: ViewBase,
  8. properties: {
  9. button1: {
  10. default: null,
  11. type: ButtonSelect1,
  12. serializable: true,
  13. },
  14. button2: {
  15. default: null,
  16. type: ButtonSelect1,
  17. serializable: true,
  18. },
  19. button3: {
  20. default: null,
  21. type: ButtonSelect1,
  22. serializable: true,
  23. },
  24. buttonPrice1: {
  25. default: null,
  26. type: ButtonSelect1,
  27. serializable: true,
  28. },
  29. buttonPrice2: {
  30. default: null,
  31. type: ButtonSelect1,
  32. serializable: true,
  33. },
  34. buttonPrice3: {
  35. default: null,
  36. type: ButtonSelect1,
  37. serializable: true,
  38. },
  39. buttonPrice4: {
  40. default: null,
  41. type: ButtonSelect1,
  42. serializable: true,
  43. },
  44. scrollViewBox: {
  45. default: null,
  46. type: cc.ScrollView,
  47. serializable: true,
  48. },
  49. roomPools: {
  50. default: null,
  51. type: cc.Node,
  52. serializable: true,
  53. },
  54. roomContent: {
  55. default: null,
  56. type: cc.Layout,
  57. serializable: true,
  58. },
  59. bottomLayout: {
  60. default: null,
  61. type: cc.Layout,
  62. serializable: true,
  63. },
  64. layerLayout: {
  65. default: null,
  66. type: cc.Layout,
  67. serializable: true,
  68. },
  69. roomPreviewPrefab: {
  70. default: null,
  71. type: cc.Prefab,
  72. serializable: true,
  73. },
  74. },
  75. onLoad () {
  76. this.buttons = [
  77. this.button1,
  78. this.button2,
  79. this.button3,
  80. ];
  81. this.buttonPrices = [
  82. this.buttonPrice1,
  83. this.buttonPrice2,
  84. this.buttonPrice3,
  85. this.buttonPrice4,
  86. ];
  87. this.titleViews = [
  88. JMC.UIEnum.BattleRoomCreate,
  89. JMC.UIEnum.BattleRoomCreate,
  90. JMC.UIEnum.BattleRoomCreate,
  91. ]
  92. this.sequenCreateBoxs = new SequenCreateView().initRoot(this);
  93. this.initBoxs();
  94. this.onClickPrice(null, "0");
  95. G.PublicMgr.on(JMC.PUBLIC_MSG.ROOM_GET_INFO, JMC.PUBLIC_MSG_ORDER.BATTLE, this.updateRoom, this);
  96. G.BattleMgr.requestInfo()
  97. },
  98. initBoxs() {
  99. this.sequenCreateBoxs.addDatas(G.CfgMgr.battleBoxConfig.getConfigAll());
  100. this.sequenCreateBoxs.startCreate(JMC.UIEnum.BoxItem, this.scrollViewBox.content, function(node, index, data) {
  101. let boxItem = node.getComponent(BoxItem);
  102. boxItem.setScale(0.73);
  103. boxItem.setNameScale(1/0.73);
  104. boxItem.setName(data.name);
  105. boxItem.setPrice(G.PlayerUtils.getPrice(data.price));
  106. });
  107. },
  108. updateRoom() {
  109. let rooms = G.BattleMgr.getRoomList()
  110. for(let room of rooms)
  111. {
  112. let roomNode = this.addRoom(room);
  113. let roomCell = roomNode.getComponent(BattleRoomPreviweCell);
  114. roomCell.resetData(room);
  115. }
  116. this.roomContent.updateLayout();
  117. this.bottomLayout.updateLayout();
  118. // this.layerLayout.updateLayout();
  119. },
  120. addRoom(data) {
  121. let node = cc.instantiate(this.roomPreviewPrefab);
  122. this.roomContent.node.addChild(node);
  123. return node;
  124. },
  125. removeRoom(data) {
  126. },
  127. updatePriceSelect(index) {
  128. for (let i = 0; i < this.buttonPrices.length; i++) {
  129. const b = this.buttonPrices[i];
  130. b.setSelect(index == i)
  131. }
  132. },
  133. onClickTitle(event, customEventData) {
  134. let index = parseInt(customEventData)
  135. G.UIMgr.open(this.titleViews[index]);
  136. },
  137. onClickPrice(event, customEventData) {
  138. let index = parseInt(customEventData)
  139. this.updatePriceSelect(index)
  140. },
  141. });