| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- import GameM, { AUDIO_TYPE } from "../../manager/GameM";
- import EffectNode from "../EffectNode";
- import ClubInviteItem from "./ClubInviteItem";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class ClubInvitePageView extends cc.Component {
- @property(cc.Node)
- content: cc.Node = null;
- @property(cc.Node)
- sview: cc.Node = null;
- @property(cc.Node)
- dragArea: cc.Node = null
- @property(cc.Node)
- item1: cc.Node = null
- @property(cc.Node)
- item2: cc.Node = null
- @property(cc.Node)
- arrLeft: cc.Node = null;
- @property(cc.Node)
- arrRight: cc.Node = null;
- @property(cc.Node)
- par: cc.Node = null
- @property(cc.Prefab)
- clubInviteInfoItem: cc.Prefab = null
- curSelDownItem = null
- preDownItem = null
- curSelItem = null
- curData = null
- //分帧加载
- addNum = 0
- addTotal = 7
- _n = 0
- _dis = 5
- private disX = 0
- private lastX = 0
- private startX = 0
- private coolTime = false
- private hasChoose = false
- onLoad() {
- this.addNum = 0
- this.addTotal = GameM.ClubData.clubInviteInfo.progressRecord.length
- this.dragArea.on(cc.Node.EventType.TOUCH_START, this.onDragStart, this)
- this.dragArea.on(cc.Node.EventType.TOUCH_END, this.onDragEnd, this)
- }
- onEnable() {
- this.item1.active = false
- this.hasChoose = false
- let len = this.content.childrenCount
- for (var i = 0; i < len; i++) {
- let item: cc.Node = this.content.getChildByName(i.toString())
- }
- }
- onDisable() {
- this.curSelDownItem = null
- this.preDownItem = null
- this.curSelItem = null
- this.curData = null
- }
- onScroll() {
- if (Math.abs(this.content.x - this.lastX) >= this.disX) {
- this.lastX = this.content.x
- this.content.children.forEach(element => {
- this.checkVisible(element)
- });
- }
- }
- update(dt) {
- if (this.addNum < this.addTotal) {
- if (this._n <= this._dis) {
- this._n++
- }
- else {
- this._n = 0
- let item: cc.Node = cc.instantiate(this.clubInviteInfoItem)
- item.name = this.addNum.toString()
- let s = item.getComponent(ClubInviteItem)
- s.initItem(GameM.ClubData.clubInviteInfo.progressRecord[this.addNum],this.addNum)
- this.disX = item.width + 10
- item.x = item.width * 0.5 + (item.width + 10) * this.addNum
- this.content.addChild(item)
- this.checkVisible(item)
- // to do
- // if (!this.hasChoose) {
- // let day = GameM.commonData.dailyCfg[this.addNum].getDay
- // if (day >= GameM.commonData.loginDays) {
- // if (GameM.commonData.dailyGetArr[this.addNum] == '0') {
- // this.hasChoose = true
- // this.initSel(this.addNum, item, s)
- // }
- // }
- // }
- this.content.width = this.addTotal * (item.width + 10)
- this.addNum++
- if (this.addNum == this.addTotal && !this.hasChoose) {
- this.initSel(this.addNum - 1, item, s)
- }
- item.on(cc.Node.EventType.TOUCH_END, this.onSel, this)
- }
- }
- this.onScroll()
- }
- initSel(index, item, s) {
- this.coolTime = true
- this.curData = GameM.ClubData.clubInviteInfo.progressRecord[index]
- this.curSelItem = item
- this.curSelDownItem = this.item1
- this.curSelDownItem.x = 750
- this.curSelDownItem.active = true
- this.item2.x = 750
- cc.tween(this.curSelDownItem).to(0.3, { x: 0 }, cc.easeInOut(1)).call(() => {
- this.coolTime = false
- }).start()
- this.autoScroll()
- }
- autoScroll() {
- let endX = 0
- let len = GameM.ClubData.clubInviteInfo.progressRecord.length
- if (this.curData.index == 0 || this.curData.index == 1 || this.curData.index == 2) {
- endX = 0
- if (this.curData.index == 0) {
- this.arrLeft.active = false
- }
- else {
- this.arrLeft.active = true
- this.arrRight.active = true
- }
- }
- else if (this.curData.index == len - 1 || this.curData.index == len - 2 || this.curData.index == len - 3) {
- endX = this.content.width
- if (this.curData.index == len - 1) {
- this.arrRight.active = false
- }
- else {
- this.arrLeft.active = true
- this.arrRight.active = true
- }
- }
- else {
- endX = this.content.width * (this.curData.index + 0.5) / len
- this.arrLeft.active = true
- this.arrRight.active = true
- }
- this.sview.getComponent(cc.ScrollView).scrollTo(cc.v2(endX / this.content.width, 0), 0.6)
- }
- checkVisible(item: cc.Node) {
- let disX = item.y + this.content.y
- if (disX >= 90 + this.disX || disX <= -this.sview.width - 90 - this.disX) {
- item.active = false
- }
- else {
- item.active = true
- }
- }
- onSel(evt: cc.Event.EventTouch) {
- if (this.coolTime) {
- return
- }
- GameM.audioM.playEffect(AUDIO_TYPE.button)
- let index = Number(evt.currentTarget.name)
- let data = GameM.ClubData.clubInviteInfo.progressRecord[index]
- this.onSelByData(data)
- }
- onSelByData(data) {
- if (this.curData) {
- let preTo = -750
- if (data.index == this.curData.index) {
- return
- }
- else if (data.index > this.curData.index) {
- 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(ClubInviteItem).init(data)
- this.curSelDownItem.x = 750
- preTo = -750
- }
- else {
- 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(ClubInviteItem).initItem(data,data.index)
- this.curSelDownItem.x = -750
- preTo = 750
- }
- this.coolTime = true
- cc.tween(this.preDownItem).to(0.3, { x: preTo }, cc.easeInOut(1)).start()
- cc.tween(this.curSelDownItem).to(0.3, { x: 0 }, cc.easeInOut(1)).call(() => {
- this.coolTime = false
- }).start()
- }
- else {
- return
- }
- this.curData = data
- this.curSelItem = this.content.getChildByName(this.curData.index.toString())
- let s = this.curSelItem.getComponent(ClubInviteItem)
- this.autoScroll()
- }
- onLeft() {
- GameM.audioM.playEffect(AUDIO_TYPE.button)
- this.onSelDown(2)
- }
- onRight() {
- GameM.audioM.playEffect(AUDIO_TYPE.button)
- this.onSelDown(1)
- }
- /**
- * 滑动选择
- * @param state 1 向左 2 向右
- */
- onSelDown(state, slide = false) {
- if (this.coolTime) {
- return
- }
- if (!this.curData) {
- return
- }
- let preTo = -750
- let data
- if (state == 1) {
- if (this.curData.index >= GameM.ClubData.clubInviteInfo.progressRecord.length - 1) {
- if (slide) {
- EffectNode.instance.PlayTip('已到最后一项')
- }
- return
- }
- data = GameM.ClubData.clubInviteInfo.progressRecord[this.curData.index + 1]
- if (this.curSelDownItem == this.item1) {
- this.curSelDownItem = this.item2
- this.preDownItem = this.item1
- }
- else {
- this.curSelDownItem = this.item1
- this.preDownItem = this.item2
- }
- this.curSelDownItem.x = 750
- preTo = -750
- }
- else if (state == 2) {
- if (this.curData.index <= 0) {
- if (slide) {
- EffectNode.instance.PlayTip('已到第一项')
- }
- return
- }
- data = GameM.ClubData.clubInviteInfo.progressRecord[this.curData.index - 1]
- 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(ClubInviteItem).init(data)
- this.curSelDownItem.x = -750
- preTo = 750
- }
- this.coolTime = true
- cc.tween(this.preDownItem).to(0.3, { x: preTo }, cc.easeInOut(1)).start()
- cc.tween(this.curSelDownItem).to(0.3, { x: 0 }, cc.easeInOut(1)).call(() => {
- this.coolTime = false
- }).start()
- this.autoScroll()
- }
- onDragStart(evt) {
- 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, true)
- }
- else {
- this.onSelDown(1, true)
- }
- }
- }
- }
|