import { Prefab } from 'cc'; import { instantiate } from 'cc'; import { _decorator, Component, Node, Animation } from 'cc'; import { DeviceUtil } from 'db://oops-framework/core/utils/DeviceUtil'; import VMParent from 'db://oops-framework/libs/model-view/VMParent'; import { start } from 'repl'; import { smc } from '../../common/SingletonModuleComp'; import { LoadBricsItem } from '../LoadBricsItem'; import { UIID } from '../../common/config/GameUIConfig'; import { oops } from 'db://oops-framework/core/Oops'; const { ccclass, property } = _decorator; interface LevelInfo { level: number; eventType: string; withdraw: boolean; position?: number; //位置 isFirstNotWithdraw?: boolean; //是否第一个没提现 } @ccclass('WelfareTwo') export class WelfareTwo extends VMParent { data: any = { itemList: [], cur_num: 1, total_num: 12, wealCount: 0 } @property(Node) private progressNode: Node = null!; @property(Node) private showNode1: Node = null!; //福利一 @property(Node) private showNode2: Node = null!; //自动提现进度 @property(Prefab) itemPrefab: Prefab = null!; @property(Node) itemList: Node = null!; start() { //三秒后进自动提现进度条 this.showNode1.active = false; this.showNode2.active = false; this.showWelfareTwo(); this.updateData(); } showWelfareTwo() { this.showNode1.active = true; // this.scheduleOnce(() => { this.showNode1.active = false; this.showLoadBar(); }, 3) } //展示进度条界面 showLoadBar() { this.showNode2.active = true; const animation = this.showNode2.getComponent(Animation); if (animation) { animation.play(); } //3秒后关闭 this.scheduleOnce(() => { oops.gui.open(UIID.UnlockFunction); oops.gui.remove(UIID.WelfareTwo); //解锁新功能 }, 3) } //更新数据 updateData() { if (DeviceUtil.isAndroid && DeviceUtil.isNative) { if (smc.game.GameModel.loadbarInfo.levelProgress) { this.data.itemList = smc.game.GameModel.loadbarInfo.levelProgress.levelInfoList //进度 this.data.cur_num = smc.account.AccountModel.curLevel; this.data.total_num = this.data.itemList[this.data.itemList.length - 1].level; const itemInfoList = this.processLevelInfo(this.data.itemList); this.itemList.destroyAllChildren(); itemInfoList.forEach((item, index) => { const loadLevelItem = instantiate(this.itemPrefab) this.itemList.addChild(loadLevelItem); if (item.position) { loadLevelItem.setPosition(item.position, 0); //设置数据 const script = loadLevelItem.getComponent(LoadBricsItem); if (script) { script.updateData(item); } } }) } } } processLevelInfo(levelInfoList: LevelInfo[], totalLength: number = 602): LevelInfo[] { if (levelInfoList.length === 0) return []; const firstLevel = levelInfoList[0].level; const lastLevel = levelInfoList[levelInfoList.length - 1].level; //单段距离 总长度/最后一个level-1 const singleLength = totalLength / (lastLevel - 1); return levelInfoList.map((item, index) => { let foundFirstNotWithdraw = false; if (index === 0) { item.position = this.progressNode.position.x; } else if (index === levelInfoList.length - 1) { item.position = this.progressNode.position.x + totalLength; } else { item.position = this.progressNode.position.x + ((item.level - firstLevel) * singleLength); } // 标记第一个未提现 if (!foundFirstNotWithdraw && item.withdraw) { item.isFirstNotWithdraw = true; foundFirstNotWithdraw = true; } else { item.isFirstNotWithdraw = false; } return item; }); } }