import MoreGameData from "../datas/MoreGameData"; import GameM, { AUDIO_TYPE } from "../manager/GameM"; import UiM, { PANEL_NAME } from "../manager/UiM"; import MoreGamePicItem from "../prefabs/MoreGamePicItem"; import MoreNormalGameItem from "../prefabs/MoreNormalGameItem"; import PointItem from "../prefabs/PointItem"; import CashRecordNode from "./CashRecordNode"; const { ccclass, property } = cc._decorator; @ccclass export default class MoreGameNode extends cc.Component { @property(cc.ScrollView) normalSv: cc.ScrollView = null; @property(cc.Prefab) moreGameNormalNode: cc.Prefab = null @property(cc.Node) dragArea: cc.Node = null @property(cc.Node) item1: cc.Node = null @property(cc.Node) item2: cc.Node = null @property(cc.Prefab) pointPrefab: cc.Prefab = null @property(cc.Node) pointLy: cc.Node = null @property(cc.Node) centerNode: cc.Node = null @property(cc.Node) btnLeft: cc.Node = null @property(cc.Node) btnRight: cc.Node = null private startX = 0 private coolTime = false private curSelDownItem = null private preDownItem = null private curIndex = 0 private normalDatas = null private bannerDatas = null public hasClick = false private curSelPoint = null start() { this.node.setContentSize(cc.winSize) this.normalSv.content.destroyAllChildren() if (MoreGameData.Instance.moreGameList == null || MoreGameData.Instance.moreGameList == undefined) { MoreGameData.Instance.sendRecommendList() } else { this.initView() } let addY = (cc.winSize.height - 1334) this.normalSv.node.height += addY this.normalSv.node.getChildByName('view').height += addY this.dragArea.on(cc.Node.EventType.TOUCH_START, this.onDragStart, this) this.dragArea.on(cc.Node.EventType.TOUCH_END, this.onDragEnd, this) } onDisable() { this.dragArea.off(cc.Node.EventType.TOUCH_START, this.onDragStart, this) this.dragArea.off(cc.Node.EventType.TOUCH_END, this.onDragEnd, this) } clickBack() { GameM.audioM.playEffect(AUDIO_TYPE.button) UiM.Instance.offPanel(PANEL_NAME.moreGameNode) } initView() { this.centerNode.parent = this.node this.normalSv.content.destroyAllChildren() if (MoreGameData.Instance.moreGameList == null || MoreGameData.Instance.moreGameList == undefined) { return } this.setBannerInfo() this.setNormalInfo() } setBannerInfo() { this.bannerDatas = MoreGameData.Instance.moreGameList.banner if (this.bannerDatas && this.bannerDatas.length > 0) { for (var i = 0; i < this.bannerDatas.length; i++) { let point = cc.instantiate(this.pointPrefab) point.name = i.toString() this.pointLy.addChild(point) } } } setNormalInfo() { this.normalDatas = MoreGameData.Instance.moreGameList.normal if (this.normalDatas && this.normalDatas.length > 0) { for (var i = 0; i < this.normalDatas.length; i++) { let node = cc.instantiate(this.moreGameNormalNode) node.name = i.toString() node.getComponent(MoreNormalGameItem).setInfo(this.normalDatas[i]) node.parent = this.normalSv.content if (i == 1) { if (this.bannerDatas && this.bannerDatas.length > 0) { this.centerNode.parent = this.normalSv.content this.centerNode.x = 25 this.onOpenBigPicNode(0) } } } } } clickCashRecord() { UiM.Instance.offPanel(PANEL_NAME.moreGameNode) UiM.Instance.onPanel(PANEL_NAME.CashRecordNode, true, () => { if (cc.isValid(UiM.Instance.cashRecordNode)) { UiM.Instance.cashRecordNode.getComponent(CashRecordNode).initType() } }) } clickGotoCash() { GameM.audioM.playEffect(AUDIO_TYPE.button) UiM.Instance.offPanel(PANEL_NAME.moreGameNode) UiM.Instance.onPanel(PANEL_NAME.CashNode) } /** ---------------- bigpicNode */ onOpenBigPicNode(index) { this.curIndex = index let data = this.bannerDatas[this.curIndex] this.curSelDownItem = this.item1 this.curSelDownItem.getComponent(MoreGamePicItem).init(data) this.curSelDownItem.x = 0 this.curSelDownItem.active = true this.item2.x = 750 this.curSelPoint = this.pointLy.getChildByName(this.curIndex.toString()) this.curSelPoint.getComponent(PointItem).setSel(true) this.hasClick = false if (this.bannerDatas.length > 1) { this.schedule(() => { if (!this.hasClick) { this.onSelDown(1) } }, 3, cc.macro.REPEAT_FOREVER, 7) } else { this.btnLeft.active = false this.btnRight.active = false } } onLeft() { GameM.audioM.playEffect(AUDIO_TYPE.button) this.hasClick = true this.onSelDown(2) } onRight() { GameM.audioM.playEffect(AUDIO_TYPE.button) this.hasClick = true this.onSelDown(1) } /** * 滑动选择 * @param state 1 向左 2 向右 */ onSelDown(state) { if (this.coolTime) { return } let preTo = -750 let data if (state == 1) { if (this.curIndex + 1 > this.bannerDatas.length - 1) { this.curIndex = 0 } else { this.curIndex++ } data = this.bannerDatas[this.curIndex] if (this.curSelDownItem == this.item1) { this.curSelDownItem = this.item2 this.preDownItem = this.item1 } else { this.curSelDownItem = this.item1 this.preDownItem = this.item2 } this.curSelDownItem.getComponent(MoreGamePicItem).init(data) this.curSelDownItem.x = 750 preTo = -750 } else if (state == 2) { if (this.curIndex - 1 < 0) { this.curIndex = this.bannerDatas.length - 1 } else { this.curIndex-- } data = this.bannerDatas[this.curIndex] if (this.curSelDownItem == this.item1) { this.curSelDownItem = this.item2 this.preDownItem = this.item1 } else { this.curSelDownItem = this.item1 this.preDownItem = this.item2 } this.curSelDownItem.getComponent(MoreGamePicItem).init(data) this.curSelDownItem.x = -750 preTo = 750 } this.coolTime = true cc.tween(this.preDownItem).to(0.4, { x: preTo }, cc.easeInOut(1)).start() cc.tween(this.curSelDownItem).to(0.4, { x: 0 }, cc.easeInOut(1)).call(() => { this.onSelPoint() this.coolTime = false }).start() } onDragStart(evt) { this.hasClick = true this.startX = evt.touch._point.x } onDragEnd(evt) { let end = evt.touch._point.x - this.startX if (Math.abs(end) > 20) { if (end > 0) { this.onSelDown(2) } else { this.onSelDown(1) } } } onSelPoint() { if (this.curSelPoint) { this.curSelPoint.getComponent(PointItem).setSel(false) } this.curSelPoint = this.pointLy.getChildByName(this.curIndex.toString()) this.curSelPoint.getComponent(PointItem).setSel(true) } // clickCloseBigPicNode() { // GameM.audioM.playEffect(AUDIO_TYPE.button) // this.curSelPoint.getComponent(PointItem).setSel(false) // this.unscheduleAllCallbacks() // } }