BattleRoomPreviweCell.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. const BattleRoomPlayerIcon = require("BattleRoomPlayerIcon")
  2. const BattleRoomSelectCell = require("BattleRoomSelectCell")
  3. const ViewBase = require("ViewBase")
  4. const SequenCreateView = require('SequenCreateView');
  5. cc.Class({
  6. extends: ViewBase,
  7. properties: {
  8. imageBg: {
  9. default: null,
  10. type: cc.Sprite,
  11. serializable: true,
  12. },
  13. textStatus: {
  14. default: null,
  15. type: cc.Label,
  16. serializable: true,
  17. },
  18. textPreviewNum: {
  19. default: null,
  20. type: cc.Label,
  21. serializable: true,
  22. },
  23. textRoundNum: {
  24. default: null,
  25. type: cc.Label,
  26. serializable: true,
  27. },
  28. textGold: {
  29. default: null,
  30. type: cc.Label,
  31. serializable: true,
  32. },
  33. buttonWatch: {
  34. default: null,
  35. type: cc.Button,
  36. serializable: true,
  37. },
  38. buttonFight: {
  39. default: null,
  40. type: cc.Button,
  41. serializable: true,
  42. },
  43. goldLayout: {
  44. default: null,
  45. type: cc.Node,
  46. serializable: true,
  47. },
  48. playerTop: {
  49. default: null,
  50. type: cc.Node,
  51. serializable: true,
  52. },
  53. playerBottom: {
  54. default: null,
  55. type: cc.Node,
  56. serializable: true,
  57. },
  58. player1: {
  59. default: null,
  60. type: BattleRoomPlayerIcon,
  61. serializable: true,
  62. },
  63. player2: {
  64. default: null,
  65. type: BattleRoomPlayerIcon,
  66. serializable: true,
  67. },
  68. player3: {
  69. default: null,
  70. type: BattleRoomPlayerIcon,
  71. serializable: true,
  72. },
  73. scrollViewBox: {
  74. default: null,
  75. type: cc.ScrollView,
  76. serializable: true,
  77. },
  78. },
  79. onLoad () {
  80. this.players = [
  81. this.player1,
  82. this.player2,
  83. this.player3,
  84. ];
  85. this.sequenCreateBoxs = new SequenCreateView().initRoot(this);
  86. },
  87. setButtonSubShow(b) {
  88. this.buttonSub.node.active = b;
  89. },
  90. resetData(data) {
  91. this.data = data;
  92. this.refreshView();
  93. },
  94. refreshView() {
  95. if (this.data == null) {
  96. return;
  97. }
  98. this.textStatus.string = this.data.status == 0 ? "等待中" : (this.data.status == 1 ? "进行中" : "结束");
  99. this.textGold.string = G.PlayerUtils.getPrice(this.getBoxsPrice());
  100. this.textPreviewNum.string = this.data.playCount + "人观看";
  101. this.textRoundNum.string = this.data.battleBoxList.length + "回合";
  102. this.playerTop.active = this.data.playerList.length >= 3;
  103. for (let i = 0; i < 3; i++) {
  104. let playerIcon = this.players[i];
  105. let playerData = this.data.playerList.length > i ? this.data.playerList[i] : null;
  106. playerIcon.resetData(playerData);
  107. }
  108. this.refreshBoxs();
  109. },
  110. refreshBoxs() {
  111. let self = this;
  112. this.sequenCreateBoxs.addDatas(this.data.battleBoxList);
  113. this.sequenCreateBoxs.startCreate(JMC.UIEnum.BattleRoomSelectCell, this.scrollViewBox.content, function(node, index, data) {
  114. let boxItem = node.getComponent(BattleRoomSelectCell);
  115. boxItem.setIndex(index);
  116. boxItem.setData(data);
  117. boxItem.setButtonSubShow(false)
  118. });
  119. },
  120. getBoxsPrice() {
  121. let price = 0;
  122. for (let b of this.data.battleBoxList) {
  123. let cfg = G.CfgMgr.battleBoxConfig.getByMainKey(b);
  124. price += cfg.price;
  125. }
  126. return price;
  127. },
  128. onClickCell() {
  129. if (this.onClickCb) {
  130. this.onClickCb(this.index, this.data)
  131. }
  132. },
  133. });