|
@@ -1,10 +1,8 @@
|
|
import { _decorator, Component, Node, Button, Sprite, SpriteFrame, resources } from 'cc';
|
|
import { _decorator, Component, Node, Button, Sprite, SpriteFrame, resources } from 'cc';
|
|
-import { GameFlowManager } from './GameFlowManager';
|
|
|
|
-import { DataManager } from './DataManager';
|
|
|
|
const { ccclass, property } = _decorator;
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 测谎仪管理器,控制测谎仪UI的显示和隐藏,并处理测谎功能
|
|
|
|
|
|
+ * 测谎仪管理器,负责测谎仪UI的显示和功能实现
|
|
*/
|
|
*/
|
|
@ccclass('LieDetectorManager')
|
|
@ccclass('LieDetectorManager')
|
|
export class LieDetectorManager extends Component {
|
|
export class LieDetectorManager extends Component {
|
|
@@ -12,7 +10,7 @@ export class LieDetectorManager extends Component {
|
|
type: Node,
|
|
type: Node,
|
|
tooltip: '测谎仪UI面板'
|
|
tooltip: '测谎仪UI面板'
|
|
})
|
|
})
|
|
- detectorPanel: Node = null;
|
|
|
|
|
|
+ lieDetectorPanel: Node = null;
|
|
|
|
|
|
@property({
|
|
@property({
|
|
type: Button,
|
|
type: Button,
|
|
@@ -22,229 +20,159 @@ export class LieDetectorManager extends Component {
|
|
|
|
|
|
@property({
|
|
@property({
|
|
type: Button,
|
|
type: Button,
|
|
- tooltip: '测谎按钮(红色按钮)'
|
|
|
|
|
|
+ tooltip: '测谎按钮'
|
|
})
|
|
})
|
|
- testButton: Button = null;
|
|
|
|
|
|
+ detectButton: Button = null;
|
|
|
|
|
|
@property({
|
|
@property({
|
|
type: Sprite,
|
|
type: Sprite,
|
|
- tooltip: '结果显示图片'
|
|
|
|
|
|
+ tooltip: '结果显示'
|
|
})
|
|
})
|
|
resultDisplay: Sprite = null;
|
|
resultDisplay: Sprite = null;
|
|
|
|
|
|
- @property({
|
|
|
|
- type: GameFlowManager,
|
|
|
|
- tooltip: '游戏流程管理器引用'
|
|
|
|
- })
|
|
|
|
- gameFlowManager: GameFlowManager = null;
|
|
|
|
-
|
|
|
|
- @property({
|
|
|
|
- type: DataManager,
|
|
|
|
- tooltip: '数据管理器引用'
|
|
|
|
- })
|
|
|
|
- dataManager: DataManager = null;
|
|
|
|
-
|
|
|
|
@property({
|
|
@property({
|
|
type: SpriteFrame,
|
|
type: SpriteFrame,
|
|
- tooltip: '真人结果图片'
|
|
|
|
|
|
+ tooltip: '真实结果图片'
|
|
})
|
|
})
|
|
- trueResultImage: SpriteFrame = null;
|
|
|
|
|
|
+ trueResultFrame: SpriteFrame = null;
|
|
|
|
|
|
@property({
|
|
@property({
|
|
type: SpriteFrame,
|
|
type: SpriteFrame,
|
|
- tooltip: '伪人结果图片'
|
|
|
|
- })
|
|
|
|
- fakeResultImage: SpriteFrame = null;
|
|
|
|
-
|
|
|
|
- // 添加默认资源路径属性
|
|
|
|
- @property({
|
|
|
|
- tooltip: '真人结果图片资源路径(可选)',
|
|
|
|
|
|
+ tooltip: '虚假结果图片'
|
|
})
|
|
})
|
|
- trueResultPath: string = 'ui/liedetector/true_result';
|
|
|
|
|
|
+ falseResultFrame: SpriteFrame = null;
|
|
|
|
|
|
@property({
|
|
@property({
|
|
- tooltip: '伪人结果图片资源路径(可选)',
|
|
|
|
|
|
+ type: Node,
|
|
|
|
+ tooltip: '提示信息Label节点'
|
|
})
|
|
})
|
|
- fakeResultPath: string = 'ui/liedetector/false_result';
|
|
|
|
|
|
+ hintLabel: Node = null;
|
|
|
|
|
|
- private imagesLoaded: boolean = false;
|
|
|
|
|
|
+ // 当前角色是否为伪装者
|
|
|
|
+ private isCharacterFake: boolean = false;
|
|
|
|
|
|
start() {
|
|
start() {
|
|
- // 初始化隐藏测谎仪面板
|
|
|
|
- if (this.detectorPanel) {
|
|
|
|
- this.detectorPanel.active = false;
|
|
|
|
|
|
+ // 初始化隐藏面板
|
|
|
|
+ if (this.lieDetectorPanel) {
|
|
|
|
+ this.lieDetectorPanel.active = false;
|
|
}
|
|
}
|
|
|
|
|
|
- // 隐藏结果显示
|
|
|
|
- if (this.resultDisplay) {
|
|
|
|
- this.resultDisplay.node.active = false;
|
|
|
|
- }
|
|
|
|
|
|
+ // 隐藏结果
|
|
|
|
+ this.hideResult();
|
|
|
|
|
|
- // 注册按钮点击事件
|
|
|
|
|
|
+ // 注册按钮事件
|
|
this.setupButtons();
|
|
this.setupButtons();
|
|
-
|
|
|
|
- // 预加载结果图片
|
|
|
|
- this.preloadResultImages();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 预加载结果图片
|
|
|
|
- */
|
|
|
|
- private preloadResultImages() {
|
|
|
|
- // 如果已经直接设置了SpriteFrame,则不需要加载
|
|
|
|
- if (this.trueResultImage && this.fakeResultImage) {
|
|
|
|
- this.imagesLoaded = true;
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- let loadedCount = 0;
|
|
|
|
- const totalToLoad = 2;
|
|
|
|
-
|
|
|
|
- // 加载真人结果图片
|
|
|
|
- if (!this.trueResultImage && this.trueResultPath) {
|
|
|
|
- resources.load(this.trueResultPath, SpriteFrame, (err, spriteFrame) => {
|
|
|
|
- if (err) {
|
|
|
|
- console.error(`加载真人结果图片失败: ${this.trueResultPath}`, err);
|
|
|
|
- } else {
|
|
|
|
- console.log(`加载真人结果图片成功: ${this.trueResultPath}`);
|
|
|
|
- this.trueResultImage = spriteFrame;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- loadedCount++;
|
|
|
|
- if (loadedCount >= totalToLoad) {
|
|
|
|
- this.imagesLoaded = true;
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- } else {
|
|
|
|
- loadedCount++;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 加载伪人结果图片
|
|
|
|
- if (!this.fakeResultImage && this.fakeResultPath) {
|
|
|
|
- resources.load(this.fakeResultPath, SpriteFrame, (err, spriteFrame) => {
|
|
|
|
- if (err) {
|
|
|
|
- console.error(`加载伪人结果图片失败: ${this.fakeResultPath}`, err);
|
|
|
|
- } else {
|
|
|
|
- console.log(`加载伪人结果图片成功: ${this.fakeResultPath}`);
|
|
|
|
- this.fakeResultImage = spriteFrame;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- loadedCount++;
|
|
|
|
- if (loadedCount >= totalToLoad) {
|
|
|
|
- this.imagesLoaded = true;
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- } else {
|
|
|
|
- loadedCount++;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 设置按钮事件
|
|
|
|
- */
|
|
|
|
private setupButtons() {
|
|
private setupButtons() {
|
|
- // 设置关闭按钮
|
|
|
|
|
|
+ // 关闭按钮
|
|
if (this.closeButton) {
|
|
if (this.closeButton) {
|
|
- this.closeButton.node.off('click');
|
|
|
|
- this.closeButton.node.on('click', () => {
|
|
|
|
- console.log('测谎仪关闭按钮被点击');
|
|
|
|
- this.hideDetectorPanel();
|
|
|
|
- }, this);
|
|
|
|
|
|
+ this.closeButton.node.on(Button.EventType.CLICK, this.hideLieDetectorPanel, this);
|
|
} else {
|
|
} else {
|
|
console.error('测谎仪关闭按钮未设置');
|
|
console.error('测谎仪关闭按钮未设置');
|
|
}
|
|
}
|
|
|
|
|
|
- // 设置测谎按钮
|
|
|
|
- if (this.testButton) {
|
|
|
|
- this.testButton.node.off('click');
|
|
|
|
- this.testButton.node.on('click', () => {
|
|
|
|
- console.log('测谎按钮被点击');
|
|
|
|
- this.performLieTest();
|
|
|
|
- }, this);
|
|
|
|
|
|
+ // 测谎按钮
|
|
|
|
+ if (this.detectButton) {
|
|
|
|
+ this.detectButton.node.on(Button.EventType.CLICK, this.detectLie, this);
|
|
} else {
|
|
} else {
|
|
console.error('测谎按钮未设置');
|
|
console.error('测谎按钮未设置');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 设置当前角色的真实性
|
|
|
|
+ * @param isFake 当前角色是否是伪装者
|
|
|
|
+ */
|
|
|
|
+ public setCharacterStatus(isFake: boolean) {
|
|
|
|
+ this.isCharacterFake = isFake;
|
|
|
|
+ // 重置结果显示
|
|
|
|
+ this.hideResult();
|
|
|
|
+ // 显示提示信息
|
|
|
|
+ this.showHint();
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 显示测谎仪面板
|
|
* 显示测谎仪面板
|
|
*/
|
|
*/
|
|
- public showDetectorPanel() {
|
|
|
|
- if (this.detectorPanel) {
|
|
|
|
- this.detectorPanel.active = true;
|
|
|
|
-
|
|
|
|
- // 确保面板在最前面
|
|
|
|
- this.detectorPanel.setSiblingIndex(999);
|
|
|
|
-
|
|
|
|
- // 隐藏结果显示,重置状态
|
|
|
|
- if (this.resultDisplay) {
|
|
|
|
- this.resultDisplay.node.active = false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 如果图片还没加载完成,再次尝试加载
|
|
|
|
- if (!this.imagesLoaded) {
|
|
|
|
- this.preloadResultImages();
|
|
|
|
- }
|
|
|
|
|
|
+ public showLieDetectorPanel() {
|
|
|
|
+ if (this.lieDetectorPanel) {
|
|
|
|
+ this.lieDetectorPanel.active = true;
|
|
|
|
+ this.lieDetectorPanel.setSiblingIndex(999); // 确保显示在最前面
|
|
|
|
+ // 初始隐藏结果
|
|
|
|
+ this.hideResult();
|
|
|
|
+ // 显示提示信息
|
|
|
|
+ this.showHint();
|
|
} else {
|
|
} else {
|
|
console.error('测谎仪面板未设置');
|
|
console.error('测谎仪面板未设置');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 执行测谎检测
|
|
|
|
|
|
+ * 隐藏测谎仪面板
|
|
*/
|
|
*/
|
|
- private performLieTest() {
|
|
|
|
- if (!this.gameFlowManager || !this.dataManager || !this.resultDisplay) {
|
|
|
|
- console.error('游戏流程管理器、数据管理器或结果显示未设置');
|
|
|
|
- return;
|
|
|
|
|
|
+ public hideLieDetectorPanel() {
|
|
|
|
+ if (this.lieDetectorPanel) {
|
|
|
|
+ this.lieDetectorPanel.active = false;
|
|
}
|
|
}
|
|
-
|
|
|
|
- // 获取当前NPC数据
|
|
|
|
- const currentNpc = this.gameFlowManager.getCurrentNpcData();
|
|
|
|
-
|
|
|
|
- if (!currentNpc) {
|
|
|
|
- console.error('无法获取当前NPC数据');
|
|
|
|
- return;
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 执行测谎操作
|
|
|
|
+ */
|
|
|
|
+ private detectLie() {
|
|
|
|
+ // 显示测谎结果
|
|
|
|
+ if (this.resultDisplay) {
|
|
|
|
+ if (this.isCharacterFake) {
|
|
|
|
+ // 显示"假"结果
|
|
|
|
+ this.resultDisplay.spriteFrame = this.falseResultFrame;
|
|
|
|
+ } else {
|
|
|
|
+ // 显示"真"结果
|
|
|
|
+ this.resultDisplay.spriteFrame = this.trueResultFrame;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.resultDisplay.node.active = true;
|
|
}
|
|
}
|
|
|
|
|
|
- // 判断是否为真人
|
|
|
|
- const isRealHuman = currentNpc.type === 'real';
|
|
|
|
-
|
|
|
|
- console.log(`测谎结果: 角色${currentNpc.characterId} 是${isRealHuman ? '真人' : '伪人'}`);
|
|
|
|
-
|
|
|
|
- // 确保有结果图片可用
|
|
|
|
- if (isRealHuman && !this.trueResultImage) {
|
|
|
|
- console.error('真人结果图片未设置');
|
|
|
|
- return;
|
|
|
|
|
|
+ // 隐藏提示信息
|
|
|
|
+ this.hideHint();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 隐藏测谎结果
|
|
|
|
+ */
|
|
|
|
+ private hideResult() {
|
|
|
|
+ if (this.resultDisplay) {
|
|
|
|
+ this.resultDisplay.node.active = false;
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (!isRealHuman && !this.fakeResultImage) {
|
|
|
|
- console.error('伪人结果图片未设置');
|
|
|
|
- return;
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 显示提示信息
|
|
|
|
+ */
|
|
|
|
+ private showHint() {
|
|
|
|
+ if (this.hintLabel) {
|
|
|
|
+ this.hintLabel.active = true;
|
|
}
|
|
}
|
|
-
|
|
|
|
- // 显示对应结果图片
|
|
|
|
- this.resultDisplay.spriteFrame = isRealHuman ? this.trueResultImage : this.fakeResultImage;
|
|
|
|
- this.resultDisplay.node.active = true;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 隐藏测谎仪面板
|
|
|
|
|
|
+ * 隐藏提示信息
|
|
*/
|
|
*/
|
|
- public hideDetectorPanel() {
|
|
|
|
- if (this.detectorPanel) {
|
|
|
|
- this.detectorPanel.active = false;
|
|
|
|
|
|
+ private hideHint() {
|
|
|
|
+ if (this.hintLabel) {
|
|
|
|
+ this.hintLabel.active = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
onDestroy() {
|
|
onDestroy() {
|
|
- // 移除按钮事件监听
|
|
|
|
|
|
+ // 清理按钮事件
|
|
if (this.closeButton) {
|
|
if (this.closeButton) {
|
|
- this.closeButton.node.off('click');
|
|
|
|
|
|
+ this.closeButton.node.off(Button.EventType.CLICK, this.hideLieDetectorPanel, this);
|
|
}
|
|
}
|
|
|
|
|
|
- if (this.testButton) {
|
|
|
|
- this.testButton.node.off('click');
|
|
|
|
|
|
+ if (this.detectButton) {
|
|
|
|
+ this.detectButton.node.off(Button.EventType.CLICK, this.detectLie, this);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|