/** 投资界面 */ import GameM, { AUDIO_TYPE } from "../manager/GameM"; import InvestItem from "../prefabs/InvestItem"; import AdM from "../manager/AdM"; import UiM, { PANEL_NAME } from "../manager/UiM"; import InvestData from "../datas/InvestData"; import GuideMng from "../manager/GuideMng"; import { Utils } from "../utils/Utils"; const { ccclass, property } = cc._decorator; @ccclass export default class Invest extends cc.Component { @property(cc.Node) content: cc.Node = null @property(cc.Label) labTimes: cc.Label = null @property(cc.Label) labCard: cc.Label = null @property(cc.Node) qipaoNode: cc.Node = null @property(cc.Node) guideRect: cc.Node = null; investData = null itemP = null //分帧加载 addNum = 0 addMax = 0 addTotal = 0 _n = 0 _dis = 2 onLoad() { } onEnable() { AdM.showBanner() this.guideRect.active = false // = GuideMng.Ins.CurGuideId == 5; } /** 刷新是否看视频 */ freshInvestItem() { let item let s for (var i = 0; i < this.content.children.length; i++) { item = this.content.getChildByName((i + 1).toString()) s = item.getComponent(InvestItem) s.freshVideoState() } } /** 刷新显示加速卡还是视频 */ freshInvestSpeedType() { let item let s for (var i = 0; i < this.content.children.length; i++) { item = this.content.getChildByName((i + 1).toString()) s = item.getComponent(InvestItem) s.freshSpeedType() } } onDisable() { AdM.destroyNative() AdM.destroyBanner() } start() { InvestData.Instance.getInvestInfo() } async init(first = true) { this.investData = InvestData.Instance.investData let item: cc.Node let s: InvestItem if (first) { this.content.removeAllChildren() this.itemP = await Utils.loadResPromise('prefabs/InvestItem') this.addNum = 0 this.addTotal = this.investData.length //探索 投资引导 this.scheduleOnce(() => { GuideMng.Ins.CheckInvestGuide5(); }, 0.7) } else { for (var i = 0; i < this.content.childrenCount; i++) { item = this.content.getChildByName((i + 1).toString()) s = item.getComponent(InvestItem) let index = s.data.index s.init(this.getDataByIndex(this.investData, index)) } } this.updateTimes() } update() { if (this.addNum < this.addTotal) { if (this._n <= this._dis) { this._n++ } else { this._n = 0 let item: cc.Node = cc.instantiate(this.itemP) let s = item.getComponent(InvestItem) item.name = this.investData[this.addNum].index.toString() s.init(this.investData[this.addNum]) this.content.addChild(item) this.addNum++ } } } getDataByIndex(data, index) { for (let entry of data) { if (index == entry.index) { return entry } } } onGetGold(index) { let item = this.content.getChildByName(index.toString()) let s = item.getComponent(InvestItem) s.getGold() } updateTimes() { let leftCount = InvestData.Instance.SurplusTimes if (leftCount < 0) { leftCount = 0 } this.labTimes.string = leftCount + "" this.labCard.string = GameM.commonData.roleData.speedCard + "" } clickClose() { GameM.audioM.playEffect(AUDIO_TYPE.button) UiM.Instance.offPanel(PANEL_NAME.InvestNode, false, () => { AdM.createInter(5) }) } clickIconShowTip() { this.qipaoNode.active = true this.scheduleOnce(() => { if (cc.isValid(this.qipaoNode)) { this.qipaoNode.active = false } }, 2) } Click_GuideRectBtn() { this.guideRect.active = false; } }