| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647 |
- // Learn TypeScript:
- // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
- // Learn Attribute:
- // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
- import GameM, { AUDIO_TYPE, VIDEO_TYPE } from "../manager/GameM";
- import DailyUpItem from "../prefabs/DailyUpItem";
- import DailyDownItem from "../prefabs/DailyDownItem";
- import UiM, { PANEL_NAME } from "../manager/UiM";
- import Main from "../Main";
- import EffectNode from "./EffectNode";
- import AdM from "../manager/AdM";
- import { thirdVideoTS } from "../manager/topon/AnyThinkAdsMgr/thirdVideoTS";
- import DailyData from "../datas/DailyData";
- import { PlayerPrefs } from "../tools/MyExtends";
- import GuideMng from "../manager/GuideMng";
- import { Utils } from "../utils/Utils";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class Daily 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)
- btnGet: cc.Node = null;
- @property(cc.Node)
- btnNo: cc.Node = null;
- @property(cc.Label)
- labDays: cc.Label = null;
- @property(cc.Node)
- iconGot: cc.Node = null;
- @property(cc.RichText)
- labCondition: cc.RichText = null;
- @property(cc.Node)
- btnLeft: cc.Node = null;
- @property(cc.Node)
- btnRight: cc.Node = null;
- @property(cc.Node)
- arrLeft: cc.Node = null;
- @property(cc.Node)
- arrRight: cc.Node = null;
- @property(cc.Animation)
- getBtnAni: cc.Animation = null
- @property(cc.Node)
- par: cc.Node = null
- @property(cc.Node)
- guideRect1: cc.Node = null;
- curSelDownItem = null
- preDownItem = null
- curSelItem = null
- curData = null
- itemP = null
- //分帧加载
- addNum = 0
- addTotal = 0
- _n = 0
- _dis = 5
- private disX = 0
- private lastX = 0
- private startX = 0
- private coolTime = false
- private hasChoose = false
- async onLoad() {
- this.addNum = 0
- this.addTotal = 0
- this.itemP = await Utils.loadResPromise('prefabs/DailyUpItem')
- // this.content.width = this.itemP.width * DailyData.Instance.dailyCfg.length + 10 * (DailyData.Instance.dailyCfg.length - 1)
- this.addTotal = DailyData.Instance.dailyCfg.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())
- let s = item.getComponent(DailyUpItem)
- if (DailyData.Instance.dailyGetArr[i] == '1') {
- s.init(DailyData.Instance.dailyCfg[i], true)
- }
- else {
- s.init(DailyData.Instance.dailyCfg[i], DailyData.Instance.dailyGetArr[this.addNum] == '1')
- if (!this.hasChoose) {
- let day = DailyData.Instance.dailyCfg[i].getDay
- if (day >= GameM.commonData.loginDays) {
- if (DailyData.Instance.dailyGetArr[i] == '0') {
- this.initSel(i, item, s)
- this.hasChoose = true
- }
- }
- }
- }
- }
- AdM.showBanner()
- AdM.destroyNative()
- this.guideRect1.active = GuideMng.Ins.CurGuideId == 16;
- //this.guideRect1.active = GameM.commonData.maxCarLevel < GameM.commonData.loginRewardOpenLevel;
- //this.guideRect1.active = PlayerPrefs.GetInt("GGuide9", 0) != 1;
- }
- onDisable() {
- this.curSelDownItem = null
- this.preDownItem = null
- this.curSelItem = null
- this.curData = null
- AdM.destroyBanner()
- }
- onScroll() {
- if (Math.abs(this.content.x - this.lastX) >= this.disX) {
- this.lastX = this.content.x
- this.content.children.forEach(element => {
- this.checkVisible(element)
- });
- }
- }
- onClickClose() {
- this.coolTime = false
- GameM.audioM.playEffect(AUDIO_TYPE.button)
- // this.node.active = false
- this.hideEff()
- }
- 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.itemP)
- item.name = this.addNum.toString()
- let s = item.getComponent(DailyUpItem)
- s.init(DailyData.Instance.dailyCfg[this.addNum], DailyData.Instance.dailyGetArr[this.addNum] == '1')
- this.disX = item.width + 10
- item.x = item.width * 0.5 + (item.width + 10) * this.addNum
- this.content.addChild(item)
- this.checkVisible(item)
- if (!this.hasChoose) {
- let day = DailyData.Instance.dailyCfg[this.addNum].getDay
- if (day >= GameM.commonData.loginDays) {
- if (DailyData.Instance.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 = DailyData.Instance.dailyCfg[index]
- this.curSelItem = item
- s.setSel(true)
- this.curSelDownItem = this.item1
- this.curSelDownItem.getComponent(DailyDownItem).init(this.curData)
- this.curSelDownItem.x = 1500
- this.curSelDownItem.active = true
- this.item2.x = 1500
- cc.tween(this.curSelDownItem).to(0.6, { x: 0 }, cc.easeInOut(1)).call(() => {
- this.coolTime = false
- }).start()
- this.freshBtns(DailyData.Instance.dailyGetArr[this.curData.index] == '1')
- this.autoScroll()
- }
- autoScroll() {
- let endX = 0
- let len = DailyData.Instance.dailyCfg.length
- if (this.curData.index == 0 || this.curData.index == 1 || this.curData.index == 2) {
- endX = 0
- if (this.curData.index == 0) {
- this.btnLeft.active = false
- this.arrLeft.active = false
- }
- else {
- this.btnLeft.active = true
- this.arrLeft.active = true
- this.btnRight.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.btnRight.active = false
- this.arrRight.active = false
- }
- else {
- this.btnLeft.active = true
- this.arrLeft.active = true
- this.btnRight.active = true
- this.arrRight.active = true
- }
- }
- else {
- endX = this.content.width * (this.curData.index + 0.5) / len
- this.btnLeft.active = true
- this.arrLeft.active = true
- this.btnRight.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 = DailyData.Instance.dailyCfg[index]
- this.onSelByData(data)
- }
- onSelByData(data) {
- if (this.curData) {
- let preTo = -1500
- 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(DailyDownItem).init(data)
- this.curSelDownItem.x = 1500
- preTo = -1500
- }
- 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(DailyDownItem).init(data)
- this.curSelDownItem.x = -1500
- preTo = 1500
- }
- this.coolTime = true
- cc.tween(this.preDownItem).to(0.6, { x: preTo }, cc.easeInOut(1)).start()
- cc.tween(this.curSelDownItem).to(0.6, { x: 0 }, cc.easeInOut(1)).call(() => {
- this.coolTime = false
- }).start()
- }
- else {
- return
- }
- if (this.curSelItem) {
- this.curSelItem.getComponent(DailyUpItem).setSel(false)
- }
- this.curData = data
- this.curSelItem = this.content.getChildByName(this.curData.index.toString())
- let s = this.curSelItem.getComponent(DailyUpItem)
- s.setSel(true)
- this.freshBtns(DailyData.Instance.dailyGetArr[this.curData.index] == '1')
- 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 = -1500
- let data
- if (state == 1) {
- if (this.curData.index >= DailyData.Instance.dailyCfg.length - 1) {
- if (slide) {
- EffectNode.instance.PlayTip('已到最后一项')
- }
- return
- }
- data = DailyData.Instance.dailyCfg[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(DailyDownItem).init(data)
- this.curSelDownItem.x = 1500
- preTo = -1500
- }
- else if (state == 2) {
- if (this.curData.index <= 0) {
- if (slide) {
- EffectNode.instance.PlayTip('已到第一项')
- }
- return
- }
- data = DailyData.Instance.dailyCfg[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(DailyDownItem).init(data)
- this.curSelDownItem.x = -1500
- preTo = 1500
- }
- this.coolTime = true
- cc.tween(this.preDownItem).to(0.6, { x: preTo }, cc.easeInOut(1)).start()
- cc.tween(this.curSelDownItem).to(0.6, { x: 0 }, cc.easeInOut(1)).call(() => {
- this.coolTime = false
- }).start()
- if (this.curSelItem) {
- this.curSelItem.getComponent(DailyUpItem).setSel(false)
- }
- this.curData = data
- this.curSelItem = this.content.getChildByName(this.curData.index.toString())
- let s = this.curSelItem.getComponent(DailyUpItem)
- s.setSel(true)
- this.freshBtns(DailyData.Instance.dailyGetArr[this.curData.index] == '1')
- 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)
- }
- }
- }
- freshBtns(hasGet) {
- if (hasGet) {
- this.iconGot.active = true
- this.btnGet.active = false
- this.btnNo.active = false
- this.labCondition.node.active = false
- }
- else {
- this.iconGot.active = false
- let canGet = false
- let conditionShow = true
- switch (this.curData.conditionType) {
- case 1:
- this.labCondition.string = `领取条件:累计登陆${this.curData.conditionLv}天<color=#FCFF04>(${GameM.commonData.loginDays}/${this.curData.conditionLv})</c>`
- canGet = GameM.commonData.loginDays >= this.curData.getDay
- conditionShow = !canGet
- break;
- case 2:
- this.labCondition.string = `领取条件:武将等级达到${this.curData.conditionLv}级<color=#FCFF04>(${GameM.commonData.maxCarLevel}/${this.curData.conditionLv})</c>`
- canGet = GameM.commonData.loginDays >= this.curData.getDay
- conditionShow = GameM.commonData.maxCarLevel < this.curData.conditionLv
- break;
- case 3:
- this.labCondition.string = `领取条件:玩家等级达到${this.curData.conditionLv}级<color=#FCFF04>(${GameM.commonData.roleData.lv}/${this.curData.conditionLv})</c>`
- canGet = GameM.commonData.loginDays >= this.curData.getDay
- conditionShow = GameM.commonData.roleData.lv < this.curData.conditionLv
- break;
- }
- this.btnGet.active = canGet
- this.btnNo.active = !canGet
- if (this.curData.getDay - GameM.commonData.loginDays == 1) {
- this.labDays.string = `明天领取`
- }
- else {
- this.labDays.string = `累计登陆${this.curData.getDay}天`
- }
- this.labCondition.node.active = true
- if (canGet) {
- if (!conditionShow) {
- this.labCondition.node.active = false
- this.getBtnAni.play()
- }
- else {
- this.getBtnAni.stop()
- this.getBtnAni.setCurrentTime(0)
- }
- }
- else {
- // this.labCondition.string = `领取条件:累计登陆${this.curData.getDay}天<color=#FCFF04>(${GameM.commonData.loginDays}/${this.curData.getDay})</c>`
- this.labCondition.string = `当前累计登陆:<color=#FCFF04>${GameM.commonData.loginDays}天</c>`
- this.getBtnAni.stop()
- this.getBtnAni.setCurrentTime(0)
- }
- }
- }
- clickGet() {
- GameM.audioM.playEffect(AUDIO_TYPE.button)
- if (DailyData.Instance.dailyGetArr[this.curData.index] == '1') {
- return
- }
- if (this.coolTime) {
- return
- }
- this.coolTime = true
- if (this.curData.conditionType == 1) {
- if (GameM.commonData.loginDays < this.curData.conditionLv) {
- cc.tween(this.labCondition.node).to(0.15, { scale: 1.3 }).to(0.15, { scale: 1 }).start()
- this.coolTime = false
- return
- }
- }
- else if (this.curData.conditionType == 2) {
- if (GameM.commonData.maxCarLevel < this.curData.conditionLv) {
- cc.tween(this.labCondition.node).to(0.15, { scale: 1.3 }).to(0.15, { scale: 1 }).start()
- this.coolTime = false
- return
- }
- }
- else if (this.curData.conditionType == 3) {
- if (GameM.commonData.roleData.lv < this.curData.conditionLv) {
- cc.tween(this.labCondition.node).to(0.15, { scale: 1.3 }).to(0.15, { scale: 1 }).start()
- this.coolTime = false
- return
- }
- }
- if (this.curData.rewardType == 2 && UiM.Instance.hallNode.getComponent(Main).getEmptySpace() == '') {
- EffectNode.instance.PlayTip("位置已满,请空出位置再领");
- this.coolTime = false
- return
- }
- if (this.curData.rewardType == 1) {
- UiM.Instance.redPackageNode.init(this.curData.rewardNum, 0, 1, null)
- UiM.Instance.redPackageNode.node.active = true
- UiM.Instance.redPackageNode.node.x = 1000
- }
- // GameM.adM.watchVideo(VIDEO_TYPE.dailyGet)
- this.onVideoEnd()
- }
- clickShowTip() {
- GameM.audioM.playEffect(AUDIO_TYPE.button)
- cc.tween(this.labCondition.node).to(0.15, { scale: 1.3 }).to(0.15, { scale: 1 }).start()
- }
- onVideoEnd() {
- switch (this.curData.rewardType) {
- case 1:
- UiM.Instance.redPackageNode.init(this.curData.rewardNum, 0, 1, null)
- UiM.Instance.openPanel(UiM.Instance.redPackageNode.node, false)
- break
- case 2:
- UiM.Instance.hallNode.getComponent(Main).getDailyCar(this.curData.rewardNum)
- break
- }
- }
- onVideoFail() {
- this.coolTime = false
- if (this.curData.rewardType == 1) {
- UiM.Instance.redPackageNode.node.active = false
- UiM.Instance.redPackageNode.node.x = 0
- }
- }
- hasOpen() {
- DailyData.Instance.updateDailyGet(this.curData.index)
- this.curSelItem.getComponent(DailyUpItem).init(DailyData.Instance.dailyCfg[this.curData.index], true)
- EffectNode.instance.PlayTip("领取成功");
- this.iconGot.active = false
- this.btnGet.active = false
- this.btnNo.active = false
- this.labCondition.node.active = false
- cc.tween(this.iconGot)
- .delay(0.5)
- .call(() => {
- this.iconGot.active = true
- this.iconGot.scale = 5
- })
- .to(0.15, { scale: 1 })
- .call(() => {
- GameM.audioM.playEffect(AUDIO_TYPE.gaizhang)
- this.node.y -= 10
- })
- .delay(0.1)
- .call(() => {
- this.node.y += 10
- })
- .delay(0.7)
- .call(() => {
- if (this.curData.index != DailyData.Instance.dailyCfg.length - 1) {
- for (var i = this.curData.index + 1; i < DailyData.Instance.dailyCfg.length; i++) {
- if (DailyData.Instance.dailyGetArr[i] != '1') {
- this.onSelByData(DailyData.Instance.dailyCfg[i])
- break
- }
- }
- }
- }).start()
- UiM.Instance.hallNode.getComponent(Main).freshDailyRed()
- }
- hideEff() {
- let main = UiM.Instance.hallNode.getComponent(Main)
- let pos1 = main.dailyBtn.node.position
- let pos2 = main.topPart.position
- let pos = cc.v2(pos1.x, pos1.y + pos2.y)
- cc.tween(this.par).to(0.2, { scale: 0, position: pos }).call(() => {
- UiM.Instance.offPanel(PANEL_NAME.DailyNode, false, () => {
- AdM.createInter(13);
- })
- // UiM.Instance.hallNode.getComponent(Main).checkOfflineAward()
- // this.par.scale = 1
- // this.par.setPosition(cc.v2(0, 0))
- }).start();
- }
- //西游
- Click_GuideRectBtn() {
- this.guideRect1.active = false;
- }
- }
|