BattleRoom.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. const ViewBase = require('ViewBase');
  2. const BattleRoomCreateCell = require('BattleRoomCreateCell')
  3. const BattleRoomSelectCell = require('BattleRoomSelectCell')
  4. const BattleRoomPlayer = require('BattleRoomPlayer')
  5. const ButtonSelect1 = require('ButtonSelect1')
  6. const ButtonSelect3 = require('ButtonSelect3')
  7. const SequenCreateView = require('SequenCreateView');
  8. cc.Class({
  9. extends: ViewBase,
  10. properties: {
  11. playerCell1: {
  12. default: null,
  13. type: BattleRoomPlayer,
  14. serializable: true,
  15. },
  16. playerCell2: {
  17. default: null,
  18. type: BattleRoomPlayer,
  19. serializable: true,
  20. },
  21. playerCell3: {
  22. default: null,
  23. type: BattleRoomPlayer,
  24. serializable: true,
  25. },
  26. playerLayout: {
  27. default: null,
  28. type: cc.Layout,
  29. serializable: true,
  30. },
  31. scrollViewBoxSelect: {
  32. default: null,
  33. type: cc.ScrollView,
  34. serializable: true,
  35. },
  36. textWatchNum: {
  37. default: null,
  38. type: cc.Label,
  39. serializable: true,
  40. },
  41. },
  42. onLoad () {
  43. this.playerCells = [
  44. this.playerCell1,
  45. this.playerCell2,
  46. this.playerCell3,
  47. ]
  48. this.roundTime = 5000;
  49. this.battleMgr = G.BattleMgr;
  50. let roomData = this.battleMgr.getMyRoom();
  51. let nowTime = G.TimeUtils.getCurrentTime();
  52. let battleTime = roomData.createTime
  53. this.curRound = (nowTime - battleTime);
  54. this.boxsPrice = this.getBoxsPrice();
  55. this.sequenCreateBoxs = new SequenCreateView().initRoot(this);
  56. this.refreshPlayers();
  57. this.refreshBoxs();
  58. },
  59. refreshPlayers() {
  60. let roomData = this.battleMgr.getMyRoom();
  61. for (let i = 0; i < this.playerCells.length; i++) {
  62. const player = roomData.playerList.length > i ? roomData.playerList[i] : null;
  63. const isShow = i < roomData.playCount;
  64. playerCell = this.playerCells[i];
  65. playerCell.setPrice(this.boxsPrice);
  66. playerCell.resetData(player);
  67. playerCell.setActive(isShow);
  68. }
  69. this.playerLayout.updateLayout();
  70. },
  71. refreshBoxs() {
  72. let self = this;
  73. this.sequenCreateBoxs.addDatas(G.BattleMgr.getMyRoom().battleBoxList);
  74. this.sequenCreateBoxs.startCreate(JMC.UIEnum.BattleRoomSelectCell, this.scrollViewBoxSelect.content, function(node, index, data) {
  75. let boxItem = node.getComponent(BattleRoomSelectCell);
  76. boxItem.setIndex(index);
  77. boxItem.setData(data);
  78. boxItem.setButtonSubShow(false)
  79. });
  80. },
  81. updateBoxSelect() {
  82. let cells = this.sequenCreateBoxs.getCells();
  83. for (let c of cells) {
  84. let boxItem = c.getComponent(BattleRoomCreateCell);
  85. let bxd = boxItem.getData();
  86. boxItem.setSelectNum(this.selectDataNums[bxd.boxId]);
  87. }
  88. },
  89. updateTypeSelect(index) {
  90. for (let i = 0; i < this.buttonTypes.length; i++) {
  91. const b = this.buttonTypes[i];
  92. b.setSelect(index == i)
  93. }
  94. },
  95. getBoxsPrice() {
  96. let roomData = this.battleMgr.getMyRoom();
  97. let price = 0;
  98. for (let b of roomData.battleBoxList) {
  99. let cfg = G.CfgMgr.battleBoxConfig.getByMainKey(b);
  100. price += cfg.price;
  101. }
  102. return price;
  103. },
  104. });