| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- /** 投资界面 */
- 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;
- }
- }
|