| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import { _decorator, Component, Label, Node, Sprite } from 'cc';
- import { rootMgr } from '../../scene/RootMgr';
- import { Player } from '../../data/player/Player';
- const { ccclass, property } = _decorator;
- @ccclass('LifeView')
- export class LifeView extends Component {
- @property(Label)
- timeLabel: Label
- @property(Label)
- lifeLabel: Label
- @property(Sprite)
- overIcon: Sprite
- protected onEnable(): void {
- let life = rootMgr.dataControl.getCompent(Player).getLifeControl()
- if (life) {
- life.evt.on('valueChange', this.reFlashView, this)
- }
- this.reFlashView(life.value)
- }
- protected onDisable(): void {
- let life = rootMgr.dataControl.getCompent(Player).getLifeControl()
- if (life) {
- life.evt.off('valueChange', this.reFlashView, this)
- }
- }
- reFlashView(v: number) {
- this.lifeLabel.string = v + ""
- }
- update() {
- let life = rootMgr.dataControl.getCompent(Player).getLifeControl()
- if (!life) {
- this.timeLabel.node.active = false
- this.overIcon.node.active = true
- return
- }
- this.timeLabel.node.active = !life.isMax()
- this.overIcon.node.active = life.isMax()
- let now = chsdk.date.now()
- life.addLastTime(now)
- let last = life.needAddTime
- this.timeLabel.string = chsdk.date.ms_format(last - now, "$M:$S")
- }
- }
|