import { _decorator, Node, Button } from 'cc'; import { BaseView } from '../../scripts/core/BaseView'; import { ViewManager } from '../../scripts/core/ViewManager'; const { ccclass, property } = _decorator; /** * 首页组件 * 继承 BaseView,实现页面生命周期 */ @ccclass('PageHome') export class PageHome extends BaseView { @property({ type: Node, tooltip: '开始游戏按钮' }) startGameBtn: Node | null = null; /** * 页面首次加载时调用 */ onViewLoad(): void { console.log('[PageHome] onViewLoad'); this._initButtons(); } /** * 初始化按钮事件 */ private _initButtons(): void { if (this.startGameBtn) { this.startGameBtn.on(Button.EventType.CLICK, this._onStartGameClick, this); } } /** * 开始游戏按钮点击回调 */ private _onStartGameClick(): void { console.log('[PageHome] 开始游戏按钮点击'); ViewManager.instance.open('PageLevel'); } /** * 页面每次显示时调用 */ onViewShow(): void { console.log('[PageHome] onViewShow'); } /** * 页面隐藏时调用 */ onViewHide(): void { console.log('[PageHome] onViewHide'); } /** * 页面销毁时调用 */ onViewDestroy(): void { console.log('[PageHome] onViewDestroy'); // 移除按钮事件监听 if (this.startGameBtn) { this.startGameBtn.off(Button.EventType.CLICK, this._onStartGameClick, this); } } }