123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- const SequenCreateView = require('SequenCreateView');
- const ButtonSelect1 = require('ButtonSelect1')
- const ButtonSelect3 = require('ButtonSelect3')
- const ViewBase = require('ViewBase');
- const BattleRoomCreateCell = require('BattleRoomCreateCell')
- const BattleRoomSelectCell = require('BattleRoomSelectCell')
- cc.Class({
- extends: ViewBase,
- properties: {
- buttonPlayerNum1: {
- default: null,
- type: ButtonSelect1,
- serializable: true,
- },
- buttonPlayerNum2: {
- default: null,
- type: ButtonSelect1,
- serializable: true,
- },
- buttonType1: {
- default: null,
- type: ButtonSelect3,
- serializable: true,
- },
- buttonType2: {
- default: null,
- type: ButtonSelect3,
- serializable: true,
- },
- buttonType3: {
- default: null,
- type: ButtonSelect3,
- serializable: true,
- },
- buttonRoomNum1: {
- default: null,
- type: ButtonSelect3,
- serializable: true,
- },
- buttonRoomNum2: {
- default: null,
- type: ButtonSelect3,
- serializable: true,
- },
- buttonRoomNum3: {
- default: null,
- type: ButtonSelect3,
- serializable: true,
- },
- buttonRoomNum4: {
- default: null,
- type: ButtonSelect3,
- serializable: true,
- },
- buttonRoomNum5: {
- default: null,
- type: ButtonSelect3,
- serializable: true,
- },
- scrollViewBox: {
- default: null,
- type: cc.ScrollView,
- serializable: true,
- },
- scrollViewBoxSelect: {
- default: null,
- type: cc.ScrollView,
- serializable: true,
- },
- textNumPrice: {
- default: null,
- type: cc.Label,
- serializable: true,
- },
- },
- onLoad () {
- this.buttonPlayerNums = [
- this.buttonPlayerNum1,
- this.buttonPlayerNum2,
- ];
- this.buttonTypes = [
- this.buttonType1,
- this.buttonType2,
- this.buttonType3,
- ];
- this.buttonRoomNums = [
- this.buttonRoomNum1,
- this.buttonRoomNum2,
- this.buttonRoomNum3,
- this.buttonRoomNum4,
- this.buttonRoomNum5,
- ];
- this.playerNumType = 0
- this.itemType = 0
- this.roomNumType = 0
- this.selectMaxNum = 6
- this.selectDatas = []
- this.selectDataNums = {}
- this.sequenCreateBoxs = new SequenCreateView().initRoot(this);
- this.sequenCreateItems = new SequenCreateView().initRoot(this);
- this.onClickPlayerNum(null, "0");
- this.onClickType(null, "0");
- this.onClickRoomNum(null, "0");
- },
- refreshBoxs() {
- let self = this;
- this.sequenCreateBoxs.addDatas(G.CfgMgr.battleBoxConfig.getByMultipleKey(this.itemType + 1));
- this.sequenCreateBoxs.startCreate(JMC.UIEnum.BattleRoomCreateCell, this.scrollViewBox.content, function(node, index, data) {
- let selectNum = self.selectDataNums[data.boxId] != undefined ? self.selectDataNums[data.boxId] : 0
- let boxItem = node.getComponent(BattleRoomCreateCell);
- boxItem.setIndex(index)
- boxItem.setData(data)
- boxItem.setCb(self.onClickBox.bind(self))
- boxItem.setPrice(G.PlayerUtils.getPrice(data.price));
- boxItem.setSelectNum(selectNum);
- });
- },
-
- refreshItems() {
- let self = this;
- this.sequenCreateItems.addDatas(this.selectDatas);
- this.sequenCreateItems.startCreate(JMC.UIEnum.BattleRoomSelectCell, this.scrollViewBoxSelect.content, function(node, index, data) {
- let boxItem = node.getComponent(BattleRoomSelectCell);
- boxItem.setIndex(index)
- boxItem.setData(data)
- boxItem.setSelect(false)
- boxItem.setCb(self.onClickItem.bind(self))
- });
- },
- onClickPlayerNum(event, customEventData) {
- let index = parseInt(customEventData)
- this.playerNumType = index
- this.updatePlayerNumSelect(index);
- },
- onClickType(event, customEventData) {
- let index = parseInt(customEventData)
- this.itemType = index
- this.updateTypeSelect(index);
- this.refreshBoxs();
- },
- onClickRoomNum(event, customEventData) {
- let index = parseInt(customEventData)
- this.roomNumType = index
- this.updateRoomNumSelect(index);
- },
- onClickCreate(event, customEventData) {
- if (this.selectDatas.length == 0) {
- return;
- }
- let boxIds = []
- for (let d of this.selectDatas) {
- boxIds.push(d.boxId)
- }
- G.BattleMgr.requestRoomCreate(2, boxIds)
- },
- onClickBox(index, data) {
- this.selectDatas.push(data)
- this.updateSelectDataNums();
- this.updateBoxSelect();
- this.refreshItems();
- this.updateSelectNumAndPrice();
- },
- onClickItem(index, data) {
- this.selectDatas.splice(index, 1);
- this.updateSelectDataNums();
- this.updateBoxSelect();
- this.refreshItems();
- this.updateSelectNumAndPrice();
- },
- updateSelectDataNums() {
- this.selectDataNums = {}
- for (let d of this.selectDatas) {
- if (this.selectDataNums[d.boxId] == undefined) {
- this.selectDataNums[d.boxId] = 1;
- } else {
- this.selectDataNums[d.boxId] += 1;
- }
- }
- },
- updateBoxSelect() {
- let cells = this.sequenCreateBoxs.getCells();
- for (let c of cells) {
- let boxItem = c.getComponent(BattleRoomCreateCell);
- let bxd = boxItem.getData();
- boxItem.setSelectNum(this.selectDataNums[bxd.boxId]);
- }
- },
- updatePlayerNumSelect(index) {
- for (let i = 0; i < this.buttonPlayerNums.length; i++) {
- const b = this.buttonPlayerNums[i];
- b.setSelect(index == i)
- }
- },
- updateTypeSelect(index) {
- for (let i = 0; i < this.buttonTypes.length; i++) {
- const b = this.buttonTypes[i];
- b.setSelect(index == i)
- }
- },
- updateRoomNumSelect(index) {
- for (let i = 0; i < this.buttonRoomNums.length; i++) {
- const b = this.buttonRoomNums[i];
- b.setSelect(index == i)
- }
- },
- updateSelectNumAndPrice() {
- let price = 0;
- for (let d of this.selectDatas) {
- price += d.price
- }
- this.textNumPrice.string = cc.js.formatStr('已选择:%d/%d 价值:', this.selectDatas.length, this.selectMaxNum, G.PlayerUtils.getPrice(price));
- },
- });
|