| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- import { _decorator, Component, Node, Button, find } from 'cc';
- import { BaseSingleton } from '../Core/BaseSingleton';
- import EventBus, { GameEvents } from '../Core/EventBus';
- import { Audio } from '../AudioManager/AudioManager';
- const { ccclass, property } = _decorator;
- /**
- * UIStateManager
- * 负责游戏内 UI 按钮事件分发。
- * 游戏失败/成功的UI显示逻辑已迁移到GameEnd.ts统一处理。
- */
- @ccclass('UIStateManager')
- export class UIStateManager extends BaseSingleton {
- public static _instance: UIStateManager;
- @property({ type: Node, tooltip: '游戏结束面板 (Canvas/GameEnd)' })
- public endPanel: Node = null;
- protected init() {
- // 自动查找面板
- if (!this.endPanel) {
- this.endPanel = find('Canvas/GameEnd');
- }
- // 绑定按钮事件分发
- this.bindPanelButtons();
- // 监听UI重置事件
- EventBus.getInstance().on(GameEvents.RESET_UI_STATES, this.onResetUI, this);
- }
- private bindPanelButtons() {
- this.bindButtonsInPanel(this.endPanel);
- }
- private bindButtonsInPanel(panel: Node) {
- if (!panel) return;
- const buttons = panel.getComponentsInChildren(Button);
- buttons.forEach(btn => {
- btn.node.on(Button.EventType.CLICK, () => {
- // 播放UI点击音效
- Audio.playUISound('data/弹球音效/ui play');
- EventBus.getInstance().emit(btn.node.name.toUpperCase() + '_CLICK');
- });
- });
- }
- /**
- * 处理UI重置事件
- * 游戏失败/成功的UI显示逻辑已迁移到GameEnd.ts统一处理
- */
- private onResetUI() {
- console.log('[UIStateManager] 处理UI重置事件');
- // UI重置逻辑已迁移到GameEnd.ts,这里保留空实现以维持兼容性
- }
- protected onDestroy() {
- // 清理事件监听
- const eventBus = EventBus.getInstance();
- eventBus.off(GameEvents.RESET_UI_STATES, this.onResetUI, this);
-
- super.onDestroy();
- }
- }
|