BattleMain.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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.Node,
  57. serializable: true,
  58. },
  59. roomPreviewPrefab: {
  60. default: null,
  61. type: cc.Prefab,
  62. serializable: true,
  63. },
  64. },
  65. onLoad () {
  66. this.buttons = [
  67. this.button1,
  68. this.button2,
  69. this.button3,
  70. ];
  71. this.buttonPrices = [
  72. this.buttonPrice1,
  73. this.buttonPrice2,
  74. this.buttonPrice3,
  75. this.buttonPrice4,
  76. ];
  77. this.titleViews = [
  78. JMC.UIEnum.BattleRoomCreate,
  79. JMC.UIEnum.BattleRoomCreate,
  80. JMC.UIEnum.BattleRoomCreate,
  81. ]
  82. this.sequenCreateBoxs = new SequenCreateView().initRoot(this);
  83. this.initBoxs();
  84. this.onClickPrice(null, "0");
  85. cc.game.on(JMC.PUBLIC_MSG.ROOM_GET_INFO, this.updateRoom, this);
  86. G.BattleMgr.requestInfo()
  87. },
  88. initBoxs() {
  89. this.sequenCreateBoxs.addDatas(G.CfgMgr.battleBoxConfig.getConfigAll());
  90. this.sequenCreateBoxs.startCreate(JMC.UIEnum.BoxItem, this.scrollViewBox.content, function(node, index, data) {
  91. let boxItem = node.getComponent(BoxItem);
  92. boxItem.setScale(0.73);
  93. boxItem.setNameScale(1/0.73);
  94. boxItem.setName(data.name);
  95. boxItem.setPrice(G.PlayerUtils.getPrice(data.price));
  96. });
  97. },
  98. updateRoom() {
  99. let rooms = G.BattleMgr.getRoomList()
  100. for(let room of rooms)
  101. {
  102. this.addRoom(room)
  103. }
  104. },
  105. addRoom(data) {
  106. let node = cc.instantiate(this.roomPreviewPrefab);
  107. this.roomContent.addChild(node);
  108. },
  109. removeRoom(data) {
  110. },
  111. updatePriceSelect(index) {
  112. for (let i = 0; i < this.buttonPrices.length; i++) {
  113. const b = this.buttonPrices[i];
  114. b.setSelect(index == i)
  115. }
  116. },
  117. onClickTitle(event, customEventData) {
  118. let index = parseInt(customEventData)
  119. G.UIMgr.open(this.titleViews[index]);
  120. },
  121. onClickPrice(event, customEventData) {
  122. let index = parseInt(customEventData)
  123. this.updatePriceSelect(index)
  124. },
  125. });