123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- 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);
- }
- }
- }
|