| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 | import { _decorator, Component, Label, Node, Sprite } from 'cc';import { ModulerBase } from '../../GameFrameWork/ModulerBase';import { GameInfo } from '../../../GameInfo';import { resMgr } from '../../../Frames/ResourcesMgr';import { messageMgr } from '../../../Frames/MessageMgr';import { RoleData } from '../../../DataItem/ItemData';import { dataMgr } from '../../../Frames/DataManager';import { PopupUIDataConfig } from './Data/PopupUIDataConfig';const { ccclass, property } = _decorator;@ccclass('Bottom')export class Bottom extends ModulerBase {    private _oreSpeed: Node = null;    private _characterSlot: Node = null;    // 每多少秒生成多少个矿石    private _speed: number = 0;    // 初始矿石数量    oreCount: number = 100;    // 记录时间间隔    private _elapsedTime: number = 0;    private _roleDts: RoleData[] = null;    protected onLoad(): void {        this._roleDts = dataMgr.getAllDataByName("RoleCardData");        this._oreSpeed = this.node.getChildByPath("OreSpeed/_oreSpeed");        this._characterSlot = this.node.getChildByName("CharacterSlot");    }    onStart() {        this.initData();        this.getLabel("_lvNumber").string = String(GameInfo.Instance.getCurlv());        this.getLabel("_oreGrade").string = `等级:${GameInfo.Instance.getOreGrade()}`;        this.getLabel("_ownNumber").string = String(GameInfo.Instance.getOwnDiamondNum());        this.getLabel("_needNumber").string = String(GameInfo.Instance.getNeedDiamondNum());        this.getSprite("_skillImg").spriteFrame = resMgr.getSpriteFrame(GameInfo.Instance.getSkill());        this._updateLabel();        this._speed = GameInfo.Instance.getOreSpeed();        this._setRoleImg();        this.closeLock();        //注册消息        messageMgr.addEvent("addOreCount", this.onEnemyDeath, this)    }    initData(){        this.getLabel("_lvNumber").string = String(GameInfo.Instance.getCurlv());        this.getLabel("_ownNumber").string = String(GameInfo.Instance.getOwnDiamondNum());        this.getLabel("_ownNumber").string = String(GameInfo.Instance.getOwnDiamondNum());        this.oreCount = 100;    }    protected update(dt: number): void {        //累加时间        this._elapsedTime += dt;        //每秒更新        if (this._elapsedTime >= 1) {            //增加矿石数量            this.oreCount += this._speed / 60;            //向下取整            this.oreCount = Math.ceil(this.oreCount);            this._updateLabel();            //重置时间间隔            this._elapsedTime = 0;        }    }    private _setRoleImg() {        for (let i = 0; i < GameInfo.Instance.getRoleImgNames().length; i++) {            const role: Node = this._characterSlot.children[i];            const lock: Node = role.getChildByName("Lock");            if(lock.active){                lock.active = false;            }            //设置角色图片            const sprite: Node = role.getChildByName("Sprite");            const imgName: string = GameInfo.Instance.getRoleImgNames()[i];            sprite.getComponent(Sprite).spriteFrame = resMgr.getSpriteFrame(imgName);            //设置消耗量            for (const roleDt of this._roleDts) {                if (roleDt.imgName === imgName) {                    const count: Node = role.getChildByName("Count");                    if (count.active) {                        count.getComponent(Label).string = String(roleDt.consume);                    } else {                        count.active = true;                        count.getComponent(Label).string = String(roleDt.consume);                    }                }            }        }    }    onEnemyDeath() {        this.oreCount += 30;        this._updateLabel();    }    onReduce(count: number) {        if (this.oreCount <= 0) {            this.oreCount = 0;        } else {            this.oreCount -= count;        }        this._updateLabel();    }    private closeLock(){        const ownCardSlot: number = PopupUIDataConfig.Instance.getAvailableCardSlot();        for (const cardSlot of this._characterSlot.children) {            if(cardSlot.getChildByName("Lock").active){                if(cardSlot.getSiblingIndex() < ownCardSlot){                    cardSlot.getChildByName("Lock").active = false;                }            }        }    }    private _updateLabel() {        if (this._oreSpeed) {            this.getLabel("_oreSpeed").string = String(this.oreCount);        }    }}
 |