import { _decorator, Component, Node, Button, Sprite, SpriteFrame, resources } from 'cc'; const { ccclass, property } = _decorator; /** * 测谎仪管理器,负责测谎仪UI的显示和功能实现 */ @ccclass('LieDetectorManager') export class LieDetectorManager extends Component { @property({ type: Node, tooltip: '测谎仪UI面板' }) lieDetectorPanel: Node = null; @property({ type: Button, tooltip: '关闭按钮' }) closeButton: Button = null; @property({ type: Button, tooltip: '测谎按钮' }) detectButton: Button = null; @property({ type: Sprite, tooltip: '结果显示' }) resultDisplay: Sprite = null; @property({ type: SpriteFrame, tooltip: '真实结果图片' }) trueResultFrame: SpriteFrame = null; @property({ type: SpriteFrame, tooltip: '虚假结果图片' }) falseResultFrame: SpriteFrame = null; @property({ type: Node, tooltip: '提示信息Label节点' }) hintLabel: Node = null; // 当前角色是否为伪装者 private isCharacterFake: boolean = false; start() { // 初始化隐藏面板 if (this.lieDetectorPanel) { this.lieDetectorPanel.active = false; } // 隐藏结果 this.hideResult(); // 注册按钮事件 this.setupButtons(); } private setupButtons() { // 关闭按钮 if (this.closeButton) { this.closeButton.node.on(Button.EventType.CLICK, this.hideLieDetectorPanel, this); } else { console.error('测谎仪关闭按钮未设置'); } // 测谎按钮 if (this.detectButton) { this.detectButton.node.on(Button.EventType.CLICK, this.detectLie, this); } else { console.error('测谎按钮未设置'); } } /** * 设置当前角色的真实性 * @param isFake 当前角色是否是伪装者 */ public setCharacterStatus(isFake: boolean) { this.isCharacterFake = isFake; // 重置结果显示 this.hideResult(); // 显示提示信息 this.showHint(); } /** * 显示测谎仪面板 */ public showLieDetectorPanel() { if (this.lieDetectorPanel) { this.lieDetectorPanel.active = true; this.lieDetectorPanel.setSiblingIndex(999); // 确保显示在最前面 // 初始隐藏结果 this.hideResult(); // 显示提示信息 this.showHint(); } else { console.error('测谎仪面板未设置'); } } /** * 隐藏测谎仪面板 */ public hideLieDetectorPanel() { if (this.lieDetectorPanel) { this.lieDetectorPanel.active = false; } } /** * 执行测谎操作 */ private detectLie() { // 显示测谎结果 if (this.resultDisplay) { if (this.isCharacterFake) { // 显示"假"结果 this.resultDisplay.spriteFrame = this.falseResultFrame; } else { // 显示"真"结果 this.resultDisplay.spriteFrame = this.trueResultFrame; } this.resultDisplay.node.active = true; } // 隐藏提示信息 this.hideHint(); } /** * 隐藏测谎结果 */ private hideResult() { if (this.resultDisplay) { this.resultDisplay.node.active = false; } } /** * 显示提示信息 */ private showHint() { if (this.hintLabel) { this.hintLabel.active = true; } } /** * 隐藏提示信息 */ private hideHint() { if (this.hintLabel) { this.hintLabel.active = false; } } onDestroy() { // 清理按钮事件 if (this.closeButton) { this.closeButton.node.off(Button.EventType.CLICK, this.hideLieDetectorPanel, this); } if (this.detectButton) { this.detectButton.node.off(Button.EventType.CLICK, this.detectLie, this); } } }