Unity and Cocos stay as parallel schemes; apps/minigame ships the Godot 4.7 WeChat pack for DevTools. Co-authored-by: Cursor <cursoragent@cursor.com>
68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
import { _decorator, Component, Label, ProgressBar } from 'cc'
|
|
import { getBus } from '../core/EventBus'
|
|
import type { PlayerStats } from '../core/types'
|
|
|
|
const { ccclass, property } = _decorator
|
|
|
|
/** Thin HUD binder — no game rules. */
|
|
@ccclass('HudView')
|
|
export class HudView extends Component {
|
|
@property(Label)
|
|
titleLabel: Label | null = null
|
|
|
|
@property(Label)
|
|
hintLabel: Label | null = null
|
|
|
|
@property(Label)
|
|
timeLabel: Label | null = null
|
|
|
|
@property(Label)
|
|
cashLabel: Label | null = null
|
|
|
|
@property(Label)
|
|
interactLabel: Label | null = null
|
|
|
|
@property(ProgressBar)
|
|
energyBar: ProgressBar | null = null
|
|
|
|
onEnable() {
|
|
getBus().on('stats:changed', this.onStats, this)
|
|
getBus().on('hud:hint', this.onHint, this)
|
|
getBus().on('time:tick', this.onTime, this)
|
|
getBus().on('interact:done', this.onInteractDone, this)
|
|
}
|
|
|
|
onDisable() {
|
|
getBus().off('stats:changed', this.onStats, this)
|
|
getBus().off('hud:hint', this.onHint, this)
|
|
getBus().off('time:tick', this.onTime, this)
|
|
getBus().off('interact:done', this.onInteractDone, this)
|
|
}
|
|
|
|
private onStats = (s: PlayerStats) => {
|
|
if (this.cashLabel) this.cashLabel.string = `¥${s.cash}`
|
|
if (this.energyBar) {
|
|
this.energyBar.progress = s.maxEnergy > 0 ? s.energy / s.maxEnergy : 0
|
|
}
|
|
if (this.titleLabel) {
|
|
this.titleLabel.string = `数字游民 · Day ${s.day}`
|
|
}
|
|
}
|
|
|
|
private onHint = (e: { text: string; interactable: boolean }) => {
|
|
if (this.hintLabel) this.hintLabel.string = e.text
|
|
if (this.interactLabel) {
|
|
this.interactLabel.node.active = e.interactable
|
|
this.interactLabel.string = '互动 · E / 点按右侧'
|
|
}
|
|
}
|
|
|
|
private onTime = (e: { label: string }) => {
|
|
if (this.timeLabel) this.timeLabel.string = e.label
|
|
}
|
|
|
|
private onInteractDone = (e: { message: string }) => {
|
|
if (this.hintLabel) this.hintLabel.string = e.message
|
|
}
|
|
}
|