// 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 ShopItem from "../prefabs/ShopItem"; import GameM, { AUDIO_TYPE, VIDEO_TYPE } from "../manager/GameM"; import AdM from "../manager/AdM"; import UiM, { PANEL_NAME } from "../manager/UiM"; import { thirdVideoTS } from "../manager/topon/AnyThinkAdsMgr/thirdVideoTS"; import EffectNode from "./EffectNode"; import { Utils } from "../utils/Utils"; const { ccclass, property } = cc._decorator; @ccclass export default class Shop extends cc.Component { @property(cc.Node) content: cc.Node = null; @property(cc.Node) sview: cc.Node = null; @property(cc.Node) mask: cc.Node = null; @property(cc.Node) hand: cc.Node = null; itemP = null //分帧加载 addNum = 0 addMax = 64 addTotal = 64 _n = 0 _dis = 3 private disY = 0 private lastY = 0 private hasScroll = false onLoad() { this.addNum = 0 this.itemP = cc.loader.getRes('prefabs/ShopItem') } async onEnable() { this.itemP = await Utils.loadResPromise('prefabs/ShopItem') this.addNum = 0 this.addTotal = Math.max(GameM.commonData.maxCarLevel - 6, 4) if (GameM.commonData.roleData.lv >= 3 && GameM.commonData.roleData.shop == 0) { // this.mask.active = true // this.hand.active = true } else { this.hideGuide() } this.content.height = (this.addTotal + 1) * 163 this.addNum = this.addTotal this.hasScroll = false this.sview.on('touch-up', this.stopAutoScroll, this) this.sview.on('scroll-began', this.stopAutoScroll, this) // this.scheduleOnce(this.onAutoScroll, 1) this.onAutoScroll() AdM.showBanner() } onAutoScroll() { if (!this.hasScroll) { this.sview.getComponent(cc.ScrollView).scrollTo(cc.v2(this.content.height, 0), 0.6) } } stopAutoScroll() { this.hasScroll = true } hideGuide() { this.mask.active = false this.hand.active = false } onDisable() { AdM.destroyNative() this.sview.off('touch-up', this.stopAutoScroll, this) this.sview.off('scroll-began', this.stopAutoScroll, this) AdM.destroyBanner() } onScroll() { if (Math.abs(this.content.y - this.lastY) >= this.disY) { this.lastY = this.content.y this.content.children.forEach(element => { this.checkVisible(element) }); } } refreshPrice(type) { let item = this.content.getChildByName(type.toString()) if (item) { let s = item.getComponent(ShopItem) s.refreshPrice() } } start() { } onClickClose() { GameM.audioM.playEffect(AUDIO_TYPE.button) // this.node.active = false UiM.Instance.offPanel(PANEL_NAME.ShopNode, false, () => { AdM.createInter(3) }) } update(dt) { if (this.addNum >= 0) { if (this._n <= this._dis) { this._n++ } else { this._n = 0 let item: cc.Node = cc.instantiate(this.itemP) item.name = (this.addNum + 1).toString() let s = item.getComponent(ShopItem) s.init(this.addNum + 1) this.disY = item.height + 10 item.y = - item.height * 0.5 - (item.height + 10) * this.addNum this.content.addChild(item) this.checkVisible(item) // this.content.height = this.addTotal * (item.height + 10) this.addNum-- } } this.onScroll() } checkVisible(item: cc.Node) { let disy = item.y + this.content.y if (disy >= 90 + this.disY || disy <= -this.sview.height - 90 - this.disY) { item.active = false } else { item.active = true } } }