// // MainScene.ts - 转换后的 Cocos Creator TypeScript 版本 // import { cclegacy, _decorator, Node, UITransform, Button, Toggle, Component, RichText, tween, Vec3, v3, Label, instantiate, Tween } from 'cc'; // import { IScene } from './IScene'; // import { View, Action, InjectClick, OnClick } from './Decorator'; // import MathUtil from './MathUtil'; // import NodeUtil from './NodeUtil'; // import ViewAction from './ViewAction'; // import { ViewID } from './ViewID'; // import { JiangHuController } from './JiangHuController'; // import { TopSpace } from './TopSpace'; // import { QUALITY, ITEM_TYPE, MOUDLE_UNLOCK, MOUDLE_TYPE } from './Types'; // import AudioNames from './AudioNames'; // const { ccclass, property } = _decorator; // // 面板ID枚举 // export enum PanelID { // WuGong = "WuGong", // Invest = "Invest", // Fight = "Fight", // Shop = "Shop", // Bag = "Bag" // } // @ccclass("MainScene") // @View(ViewID.MAIN) // export class MainScene extends IScene { // @property({ type: Node, tooltip: "画布节点" }) // canvas: Node | null = null; // @property({ type: Node, tooltip: "面板层" }) // panelLayer: Node | null = null; // @property({ type: Node, tooltip: "切换按钮组" }) // toggles: Node | null = null; // @property({ type: Node, tooltip: "底部UI" }) // bottom: Node | null = null; // @property({ type: Node, tooltip: "顶部UI" }) // top: Node | null = null; // @property({ type: Node, tooltip: "公告节点" }) // notice: Node | null = null; // @property({ type: Button, tooltip: "属性按钮" }) // buttonProp: Button | null = null; // // 私有属性 // private toggleTweens: { [key: string]: Tween } = {}; // private currentPanel: string | null = null; // private panels: { [key: string]: Node } = {}; // private isInitialized: boolean = false; // constructor(...args: any[]) { // super(...args); // this.toggleTweens = {}; // this.currentPanel = null; // this.panels = {}; // this.isInitialized = false; // } // /** // * 场景启动生命周期方法 // */ // start(): void { // this.onRefreshModules(); // this.onRefreshFighting(); // this.onEnterPanel({ id: PanelID.Fight }); // // 初始化切换按钮事件 // if (this.toggles) { // const toggleComponents = this.toggles.getComponentsInChildren(Toggle); // for (const toggle of toggleComponents) { // const eventHandler = new Component.EventHandler(); // eventHandler.target = this.node; // eventHandler.component = "MainScene"; // eventHandler.handler = "onToggle"; // toggle.checkEvents.push(eventHandler); // } // } // // 调整顶部空间 // if (this.top) { // const transform = this.top.getComponent(UITransform); // if (transform) { // transform.height += TopSpace.TOP_SPACE; // } // } // this.onRefreshTags(); // // 定时刷新标签 // this.schedule(() => { // this.onRefreshTags(); // }, 1); // // 加载机器人配置并设置公告 // this.setupNoticeSystem(); // this.isInitialized = true; // } // /** // * 设置公告系统 // */ // private setupNoticeSystem(): void { // app.service.config.loadJson("robot").then((robotConfig: any) => { // const robotKeys = Object.keys(robotConfig); // const levelKeys = Object.keys(app.service.config.data.level); // const lastLevelKey = levelKeys[levelKeys.length - 1]; // const bossName = app.service.config.data.enemy[app.service.config.data.level[lastLevelKey].boss].name; // const items = app.service.config.data.items; // const wugongItems: string[] = []; // const equipmentItems: string[] = []; // // 筛选高品质物品 // for (const itemId in items) { // const item = items[itemId]; // if (item.quality > QUALITY.PURPLE) { // switch (item.type) { // case ITEM_TYPE.WUGONG: // wugongItems.push(item.name); // break; // case ITEM_TYPE.GLOVE: // case ITEM_TYPE.SWORD: // case ITEM_TYPE.KNIFE: // case ITEM_TYPE.ARMOR: // equipmentItems.push(item.name); // break; // } // } // } // // 定时显示公告 // this.schedule(() => { // if (this.currentPanel !== PanelID.Bag && this.currentPanel !== PanelID.WuGong) { // const randomRobot = robotConfig[robotKeys[MathUtil.getRandomInt(robotKeys.length - 1)]]; // const nickname = randomRobot.nickname; // const richText = this.notice?.getComponentInChildren(RichText); // if (!richText) return; // const randomType = MathUtil.getRandomInt(2); // let message = ""; // switch (randomType) { // case 1: // message = `【天道机缘】 吉星高照!玩家「${nickname}」偶得旷世奇珍【${equipmentItems[MathUtil.getRandomInt(equipmentItems.length - 1)]}】!此等神器出世,武林又将掀起波澜!`; // break; // case 2: // message = `【天道机缘】 鸿运当头!玩家「${nickname}」领悟失传绝学 【${wugongItems[MathUtil.getRandomInt(wugongItems.length - 1)]}】!此秘籍乃百年前宗师所留,习得者可撼山岳!`; // break; // default: // message = `【江湖捷报】玩家「${nickname}」成功斩杀终极BOSS【${bossName}】!烈焰散尽,英雄凯旋!`; // } // richText.string = message; // this.showNotice(richText); // } // }, 30); // }).catch((error) => { // console.error("加载机器人配置失败:", error); // }); // } // /** // * 显示公告 // */ // private showNotice(richText: RichText): void { // if (!this.notice) return; // this.notice.active = true; // this.notice.setScale(0, 0); // tween(this.notice) // .to(0.2, { scale: Vec3.ONE }) // .call(() => { // if (!this.notice) return; // const noticeTransform = this.notice.getComponent(UITransform); // const richTextTransform = richText.node.getComponent(UITransform); // if (!noticeTransform || !richTextTransform) return; // const noticeWidth = noticeTransform.width; // const richTextWidth = richTextTransform.width; // richText.node.setPosition(0.5 * noticeWidth, richText.node.position.y); // tween(richText.node) // .to(8, { // position: v3(0.5 * noticeWidth - richTextWidth - 100, richText.node.position.y) // }) // .delay(1) // .call(() => { // if (this.notice) { // this.notice.active = false; // } // }) // .start(); // }) // .start(); // } // /** // * 切换按钮点击事件 // */ // @OnClick // onToggle(toggle: Toggle): void { // if (toggle.isChecked) { // // 移除指引手指 // const finger = toggle.node.getChildByName("finger"); // if (finger) { // finger.destroy(); // } // app.manager.audio.playOnce(AudioNames.CLICK); // this.onEnterPanel({ id: toggle.node.name as PanelID }); // } // } // /** // * 属性按钮点击事件 // */ // @OnClick // onButtonProp(): void { // app.manager.popup.popNode("PopupAbility"); // } // /** // * 刷新标签状态 // */ // @Action(ViewAction.REFRESH_TAGS) // onRefreshTags(): void { // const coinAmount = app.service.item.getCurrencyValue("Coin"); // const gameModel = app.service.game.model; // for (let i = 0; i < 5; i++) { // this.updateTagForModule(i as MOUDLE_TYPE, coinAmount, gameModel); // } // } // /** // * 更新特定模块的标签状态 // */ // private updateTagForModule(moduleType: MOUDLE_TYPE, coinAmount: number, gameModel: any): void { // let shouldShowTag = false; // const bag = gameModel.bag; // switch (moduleType) { // case MOUDLE_TYPE.INVEST: // const buildings = gameModel.invest.buildings; // for (const buildingId in buildings) { // shouldShowTag = true; // const building = buildings[buildingId]; // for (const material of building.materials) { // if (bag.getItemValue(material.id) < material.value) { // shouldShowTag = false; // break; // } // } // if (shouldShowTag) break; // } // break; // case MOUDLE_TYPE.SHOP: // shouldShowTag = app.service.item.checkCurrency("Coin", gameModel.shop.cost, false); // break; // case MOUDLE_TYPE.BAG: // // 检查新标签或可合并物品 // for (const item of bag.items) { // if (item.mergeable || bag.newTags[item.uuid]) { // shouldShowTag = true; // break; // } // } // if (!shouldShowTag) { // shouldShowTag = coinAmount >= bag.cost && bag.checkMaterials(bag.materials); // } // break; // case MOUDLE_TYPE.FIGHT: // shouldShowTag = gameModel.task.config && gameModel.task.complete; // break; // case MOUDLE_TYPE.WUGONG: // const wuxue = gameModel.role.wuxue; // const wugongs = gameModel.role.wugongs; // for (const wugongType in wugongs) { // for (const wugong of wugongs[wugongType]) { // if (wuxue >= wugong.levelUp_condition && coinAmount >= wugong.levelUp_exp) { // shouldShowTag = true; // break; // } // } // if (shouldShowTag) break; // } // break; // } // this.updateToggleVisual(moduleType, shouldShowTag, gameModel); // } // /** // * 更新切换按钮视觉效果 // */ // private updateToggleVisual(moduleType: MOUDLE_TYPE, showTag: boolean, gameModel: any): void { // if (!this.toggles) return; // const toggleNode = this.toggles.children[moduleType]; // if (!toggleNode) return; // if (gameModel.moduleTags[moduleType]) { // if (!this.toggleTweens[moduleType]) { // this.toggleTweens[moduleType] = NodeUtil.breathEffect(toggleNode, 1, 1.1); // } // } else { // if (this.toggleTweens[moduleType]) { // toggleNode.setScale(Vec3.ONE); // this.toggleTweens[moduleType].stop(); // delete this.toggleTweens[moduleType]; // } // } // NodeUtil.showRedTag(toggleNode, showTag); // } // /** // * 手指指引事件 // */ // @Action(ViewAction.FINGER_GUIDE) // onFingerGuide(type: string): void { // if (!this.toggles) return; // switch (type) { // case "wugong": // NodeUtil.showFinger(this.toggles.children[0], true, { ignore: true }); // break; // case "bag": // NodeUtil.showFinger(this.toggles.children[4], true, { ignore: true }); // break; // } // } // /** // * 刷新模块显示状态 // */ // @Action(ViewAction.REFRESH_MODULES) // onRefreshModules(): void { // if (!this.toggles) return; // const taskId = app.service.game.model.task.id; // if (!taskId) return; // const taskNumber = Number(taskId); // const toggleMap = { // [MOUDLE_TYPE.WUGONG]: this.toggles.children[0], // [MOUDLE_TYPE.BAG]: this.toggles.children[4], // [MOUDLE_TYPE.SHOP]: this.toggles.children[3], // [MOUDLE_TYPE.INVEST]: this.toggles.children[1] // }; // for (const moduleType in MOUDLE_UNLOCK) { // const unlockThreshold = MOUDLE_UNLOCK[moduleType as keyof typeof MOUDLE_UNLOCK]; // const toggleNode = toggleMap[moduleType as keyof typeof toggleMap]; // if (toggleNode) { // toggleNode.active = taskNumber > unlockThreshold; // } // } // } // /** // * 刷新战斗力显示 // */ // @Action(ViewAction.REFRESH_FIGHTING) // onRefreshFighting(): void { // if (!this.buttonProp) return; // const fightingLabel = this.buttonProp.node.getChildByName("Fighting"); // if (fightingLabel) { // const labelComponent = fightingLabel.getComponent(Label); // if (labelComponent) { // const fightingValue = Math.floor(app.service.game.model.role.fighting); // labelComponent.string = fightingValue.toString(); // } // } // } // /** // * 刷新战斗状态 // */ // @Action(ViewAction.REFRESH_FIGHT) // onRefreshFight(): void { // if (this.bottom) { // this.bottom.active = app.service.game.model.level.monster.fighting; // } // } // /** // * 进入面板 // */ // @Action(ViewAction.ENTER_PANEL) // onEnterPanel(params: { id: PanelID }): void { // if (this.panels[params.id]) { // // 显示已存在的面板 // this.panels[params.id].active = true; // } else { // // 加载新面板 // this.loadPanel(params.id); // } // } // /** // * 加载面板 // */ // private async loadPanel(panelId: PanelID): Promise { // try { // app.loading = true; // const prefab = await app.service.res.getPrefab(`Panel${panelId}`); // // 退出当前面板 // if (this.currentPanel) { // this.onExitPanel({ id: this.currentPanel }); // } // const panelInstance = instantiate(prefab); // this.panels[panelId] = panelInstance; // if (this.canvas) { // panelInstance.parent = this.canvas; // // 设置层级 // if (this.panelLayer) { // const panelLayerIndex = this.panelLayer.getSiblingIndex(); // panelInstance.setSiblingIndex(panelLayerIndex); // } // } // this.currentPanel = panelId; // app.loading = false; // // 特殊处理:进入背包或武学面板时隐藏公告 // if (panelId === PanelID.Bag || panelId === PanelID.WuGong) { // if (this.notice) { // this.notice.active = false; // Tween.stopAllByTarget(this.notice); // } // } // } catch (error) { // console.error(`加载面板 ${panelId} 失败:`, error); // app.manager.toast.show("页面加载失败,请稍后重试~"); // app.loading = false; // } // } // /** // * 退出面板 // */ // @Action(ViewAction.EXIT_PANEL) // onExitPanel(params: { id: string }): void { // if (this.panels[params.id]) { // this.panels[params.id].destroy(); // delete this.panels[params.id]; // } // } // /** // * 获取当前面板ID // */ // getCurrentPanel(): string | null { // return this.currentPanel; // } // /** // * 检查是否已初始化 // */ // isSceneInitialized(): boolean { // return this.isInitialized; // } // /** // * 清理资源 // */ // onDestroy(): void { // // 停止所有缓动动画 // for (const tweenId in this.toggleTweens) { // this.toggleTweens[tweenId].stop(); // } // this.toggleTweens = {}; // // 清理所有面板 // for (const panelId in this.panels) { // this.panels[panelId].destroy(); // } // this.panels = {}; // // 取消所有调度 // this.unscheduleAllCallbacks(); // super.onDestroy(); // } // } // export default MainScene;