| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- 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';
- import { ServerHandler } from '../../common/manager/ServerHandler';
- import { GameEvent } from '../../common/config/GameEvent';
- 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();
- oops.message.dispatchEvent(GameEvent.updateGameState, "paused");
- }
- 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);
- this.updateState();
- 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;
- });
- }
- updateState() {
- ServerHandler.inst.updatePopupState({
- level: smc.account.AccountModel.curLevel,
- type: smc.game.GameModel.popupType
- })
- }
- }
|