BattleRoomCreate.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. const SequenCreateView = require('SequenCreateView');
  2. const ButtonSelect1 = require('ButtonSelect1')
  3. const ButtonSelect3 = require('ButtonSelect3')
  4. const ViewBase = require('ViewBase');
  5. const BattleRoomCreateCell = require('BattleRoomCreateCell')
  6. const BattleRoomSelectCell = require('BattleRoomSelectCell')
  7. cc.Class({
  8. extends: ViewBase,
  9. properties: {
  10. buttonPlayerNum1: {
  11. default: null,
  12. type: ButtonSelect1,
  13. serializable: true,
  14. },
  15. buttonPlayerNum2: {
  16. default: null,
  17. type: ButtonSelect1,
  18. serializable: true,
  19. },
  20. buttonType1: {
  21. default: null,
  22. type: ButtonSelect3,
  23. serializable: true,
  24. },
  25. buttonType2: {
  26. default: null,
  27. type: ButtonSelect3,
  28. serializable: true,
  29. },
  30. buttonType3: {
  31. default: null,
  32. type: ButtonSelect3,
  33. serializable: true,
  34. },
  35. buttonRoomNum1: {
  36. default: null,
  37. type: ButtonSelect3,
  38. serializable: true,
  39. },
  40. buttonRoomNum2: {
  41. default: null,
  42. type: ButtonSelect3,
  43. serializable: true,
  44. },
  45. buttonRoomNum3: {
  46. default: null,
  47. type: ButtonSelect3,
  48. serializable: true,
  49. },
  50. buttonRoomNum4: {
  51. default: null,
  52. type: ButtonSelect3,
  53. serializable: true,
  54. },
  55. buttonRoomNum5: {
  56. default: null,
  57. type: ButtonSelect3,
  58. serializable: true,
  59. },
  60. scrollViewBox: {
  61. default: null,
  62. type: cc.ScrollView,
  63. serializable: true,
  64. },
  65. scrollViewBoxSelect: {
  66. default: null,
  67. type: cc.ScrollView,
  68. serializable: true,
  69. },
  70. textNumPrice: {
  71. default: null,
  72. type: cc.Label,
  73. serializable: true,
  74. },
  75. },
  76. onLoad () {
  77. this.buttonPlayerNums = [
  78. this.buttonPlayerNum1,
  79. this.buttonPlayerNum2,
  80. ];
  81. this.buttonTypes = [
  82. this.buttonType1,
  83. this.buttonType2,
  84. this.buttonType3,
  85. ];
  86. this.buttonRoomNums = [
  87. this.buttonRoomNum1,
  88. this.buttonRoomNum2,
  89. this.buttonRoomNum3,
  90. this.buttonRoomNum4,
  91. this.buttonRoomNum5,
  92. ];
  93. this.playerNumType = 0
  94. this.itemType = 0
  95. this.roomNumType = 0
  96. this.selectMaxNum = 6
  97. this.selectDatas = []
  98. this.selectDataNums = {}
  99. this.sequenCreateBoxs = new SequenCreateView().initRoot(this);
  100. this.sequenCreateItems = new SequenCreateView().initRoot(this);
  101. this.onClickPlayerNum(null, "0");
  102. this.onClickType(null, "0");
  103. this.onClickRoomNum(null, "0");
  104. },
  105. refreshBoxs() {
  106. let self = this;
  107. this.sequenCreateBoxs.addDatas(G.CfgMgr.battleBoxConfig.getByMultipleKey(this.itemType + 1));
  108. this.sequenCreateBoxs.startCreate(JMC.UIEnum.BattleRoomCreateCell, this.scrollViewBox.content, function(node, index, data) {
  109. let selectNum = self.selectDataNums[data.boxId] != undefined ? self.selectDataNums[data.boxId] : 0
  110. let boxItem = node.getComponent(BattleRoomCreateCell);
  111. boxItem.setIndex(index)
  112. boxItem.setData(data)
  113. boxItem.setCb(self.onClickBox.bind(self))
  114. boxItem.setPrice(G.PlayerUtils.getPrice(data.price));
  115. boxItem.setSelectNum(selectNum);
  116. });
  117. },
  118. refreshItems() {
  119. let self = this;
  120. this.sequenCreateItems.addDatas(this.selectDatas);
  121. this.sequenCreateItems.startCreate(JMC.UIEnum.BattleRoomSelectCell, this.scrollViewBoxSelect.content, function(node, index, data) {
  122. let boxItem = node.getComponent(BattleRoomSelectCell);
  123. boxItem.setIndex(index)
  124. boxItem.setData(data)
  125. boxItem.setSelect(false)
  126. boxItem.setCb(self.onClickItem.bind(self))
  127. });
  128. },
  129. onClickPlayerNum(event, customEventData) {
  130. let index = parseInt(customEventData)
  131. this.playerNumType = index
  132. this.updatePlayerNumSelect(index);
  133. },
  134. onClickType(event, customEventData) {
  135. let index = parseInt(customEventData)
  136. this.itemType = index
  137. this.updateTypeSelect(index);
  138. this.refreshBoxs();
  139. },
  140. onClickRoomNum(event, customEventData) {
  141. let index = parseInt(customEventData)
  142. this.roomNumType = index
  143. this.updateRoomNumSelect(index);
  144. },
  145. onClickCreate(event, customEventData) {
  146. if (this.selectDatas.length == 0) {
  147. return;
  148. }
  149. let boxIds = []
  150. for (let d of this.selectDatas) {
  151. boxIds.push(d.boxId)
  152. }
  153. G.BattleMgr.requestRoomCreate(2, boxIds)
  154. },
  155. onClickBox(index, data) {
  156. this.selectDatas.push(data)
  157. this.updateSelectDataNums();
  158. this.updateBoxSelect();
  159. this.refreshItems();
  160. this.updateSelectNumAndPrice();
  161. },
  162. onClickItem(index, data) {
  163. this.selectDatas.splice(index, 1);
  164. this.updateSelectDataNums();
  165. this.updateBoxSelect();
  166. this.refreshItems();
  167. this.updateSelectNumAndPrice();
  168. },
  169. updateSelectDataNums() {
  170. this.selectDataNums = {}
  171. for (let d of this.selectDatas) {
  172. if (this.selectDataNums[d.boxId] == undefined) {
  173. this.selectDataNums[d.boxId] = 1;
  174. } else {
  175. this.selectDataNums[d.boxId] += 1;
  176. }
  177. }
  178. },
  179. updateBoxSelect() {
  180. let cells = this.sequenCreateBoxs.getCells();
  181. for (let c of cells) {
  182. let boxItem = c.getComponent(BattleRoomCreateCell);
  183. let bxd = boxItem.getData();
  184. boxItem.setSelectNum(this.selectDataNums[bxd.boxId]);
  185. }
  186. },
  187. updatePlayerNumSelect(index) {
  188. for (let i = 0; i < this.buttonPlayerNums.length; i++) {
  189. const b = this.buttonPlayerNums[i];
  190. b.setSelect(index == i)
  191. }
  192. },
  193. updateTypeSelect(index) {
  194. for (let i = 0; i < this.buttonTypes.length; i++) {
  195. const b = this.buttonTypes[i];
  196. b.setSelect(index == i)
  197. }
  198. },
  199. updateRoomNumSelect(index) {
  200. for (let i = 0; i < this.buttonRoomNums.length; i++) {
  201. const b = this.buttonRoomNums[i];
  202. b.setSelect(index == i)
  203. }
  204. },
  205. updateSelectNumAndPrice() {
  206. let price = 0;
  207. for (let d of this.selectDatas) {
  208. price += d.price
  209. }
  210. this.textNumPrice.string = cc.js.formatStr('已选择:%d/%d 价值:', this.selectDatas.length, this.selectMaxNum, G.PlayerUtils.getPrice(price));
  211. },
  212. });