fix chatmodel

This commit is contained in:
2025-09-10 16:43:46 +08:00
parent e4ee688dc8
commit 07bd9923fc
8 changed files with 244 additions and 503 deletions
+45 -82
View File
@@ -25,6 +25,8 @@ import LanguageUtils from "../../../Main/Common/LanguageUtils";
import { UITransitionHelper } from "../../utils/UITransitionHelper";
import { VideoEmotion, purchase } from "../../../schema/schema";
import { PayToTalkSubpanel } from "./PayToTalkSubpanel";
import { DataId, DataManager } from "../../data/DataManager";
import { GirlData } from "../../data/GirlData";
const { ccclass, property } = _decorator;
@ccclass("ChatPanel")
@@ -53,6 +55,7 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
@property(ImagePopup)
popUpImage: ImagePopup = null;
categoryId: string;
id: number;
private _nodeTab: any = {};
@@ -76,7 +79,7 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
const isRoleSwitch = this.id && this.id !== newRoleId;
this.id = newRoleId;
this.categoryId = data.categoryId;
// 如果标记了需要滑入动画,则执行动画
if (withAnimation && this.node && this.node.isValid) {
// 延迟一帧执行动画,确保节点已正确加载到场景中
@@ -91,18 +94,21 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
// 初始化或切换ChatController
if (this.id && this.id > 0) {
if (isRoleSwitch && this.chatController.hasRoleData(this.id)) {
if (
isRoleSwitch &&
this.chatController.hasRoleData(this.categoryId, this.id)
) {
// 如果是角色切换且有缓存数据,使用switchRole
console.log(
`ChatPanel: Switching from role ${this.chatController.getCurrentRoleId()} to role ${
this.id
}`
);
this.chatController.switchRole(this.id);
this.chatController.switchRole(this.categoryId, this.id);
} else {
// 首次初始化或没有缓存数据,使用initialize
console.log(`ChatPanel: Initializing role ${this.id}`);
this.chatController.initialize(this.id);
this.chatController.initialize(this.categoryId, this.id);
}
}
}
@@ -111,7 +117,7 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
Utils.parseNode(this.node, this._nodeTab);
this.register();
this.refresh(this.id);
this.refresh();
this.payToTalkPanel.node.active = false;
// Add video loaded event callback
if (this.girlVideo) {
@@ -176,18 +182,19 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
this.chatController = null;
}
}
refresh(id: number) {
this.id = id;
refresh() {
//this.id = id;
// 通过ChatController获取角色数据
const roleData = this.chatController.getRoleData();
if (!roleData || !roleData.basic) return;
//const roleData = this.chatController.getRoleData();
//if (!roleData || !roleData.basic) return;
const data = roleData.basic;
const dataDetail = roleData.detail;
//const data = roleData.basic;
//const dataDetail = roleData.detail;
const girlData = DataManager.I.getDataById<GirlData>(DataId.Girl);
this.nameKey = data.nameKey;
this.girlName.string = LanguageUtils.getText(data.nameKey);
this.nameKey = girlData.getGrilName(this.categoryId, this.id);
this.girlName.string = LanguageUtils.getText(this.nameKey);
// ResManager.I.changeBundleSpriteFrame(
// this.girlImg,
// data.avatarPath,
@@ -204,45 +211,30 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
// 通过ChatController获取商业视频数据
const chatModel = this.chatController.getChatModel();
const commercialVideos = chatModel.getCommercialVideos();
this.commercialVideos = commercialVideos;
if (commercialVideos.length > 0) {
// Load initial video based on current emotion
if (this.girlVideo) {
// Get current emotion from ChatController
const currentEmotion = this.chatController.getCurrentEmotion();
console.log(
`Loaded ${commercialVideos.length} videos for role ${this.id}`
`Current emotion for role ${this.id}: ${VideoEmotion[currentEmotion]}`
);
// Load initial video based on current emotion
if (this.girlVideo) {
// Get current emotion from ChatController
const currentEmotion = this.chatController.getCurrentEmotion();
// Get appropriate video from ChatModel
const initialVideo =
chatModel.getVideoByEmotion(currentEmotion) ||
chatModel.getDefaultVideo();
if (initialVideo) {
console.log(
`Current emotion for role ${this.id}: ${VideoEmotion[currentEmotion]}`
`Loading initial video: ${initialVideo} (emotion: ${VideoEmotion[initialVideo]})`
);
// Get appropriate video from ChatModel
const initialVideo =
chatModel.getVideoByEmotion(currentEmotion) ||
chatModel.getDefaultVideo();
if (initialVideo) {
console.log(
`Loading initial video: ${initialVideo.path} (emotion: ${
VideoEmotion[initialVideo.emotion]
})`
);
// Set current emotion to the loaded video's emotion
this.currentEmotion = initialVideo.emotion;
ResManager.I.changeBundleVideo(
this.girlVideo,
initialVideo.path,
"Girls"
);
// Also immediately try to adjust scale (in case already loaded)
this.adjustVideoScale();
}
// Set current emotion to the loaded video's emotion
this.currentEmotion = this.chatController.getCurrentEmotion();
ResManager.I.changeBundleVideo(this.girlVideo, initialVideo, "Girls");
// Also immediately try to adjust scale (in case already loaded)
this.adjustVideoScale();
}
} else {
this.commercialVideos = [];
@@ -302,12 +294,6 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
}
// Get video data from ChatModel through ChatController
const chatModel = this.chatController.getChatModel();
const commercialVideos = chatModel.getCommercialVideos();
if (commercialVideos.length === 0) {
console.warn("Cannot switch video: no commercialVideos data");
return;
}
// Check if emotion has changed
if (this.currentEmotion === emotion) {
@@ -322,9 +308,9 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
if (matchingVideo) {
console.log(
`Switching to video for emotion ${VideoEmotion[emotion]}: ${
matchingVideo.path
} (from ${
`Switching to video for emotion ${
VideoEmotion[emotion]
}: ${matchingVideo} (from ${
this.currentEmotion !== null
? VideoEmotion[this.currentEmotion]
: "null"
@@ -332,11 +318,7 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
);
// Load the new video
ResManager.I.changeBundleVideo(
this.girlVideo,
matchingVideo.path,
"Girls"
);
ResManager.I.changeBundleVideo(this.girlVideo, matchingVideo, "Girls");
// Update current emotion state
this.currentEmotion = emotion;
@@ -353,20 +335,17 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
const fallbackVideo = chatModel.getDefaultVideo();
if (fallbackVideo) {
console.log(
`Loading fallback video: ${fallbackVideo.path} (emotion: ${
VideoEmotion[fallbackVideo.emotion]
})`
`Loading fallback video: ${fallbackVideo} (emotion: ${VideoEmotion[fallbackVideo]})`
);
ResManager.I.changeBundleVideo(
this.girlVideo,
fallbackVideo.path,
fallbackVideo,
"Chat18x"
);
// Update current emotion state to the fallback video's emotion
this.currentEmotion = fallbackVideo.emotion;
this.currentEmotion = this.chatController.getCurrentEmotion();
this.adjustVideoScale();
this.setVideoEnable(true);
}
@@ -452,7 +431,7 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
}
onChatLimitReached(): void {
this.payToTalkPanel.show();
this.payToTalkPanel.show(this.categoryId,this.id);
}
/**
* 情绪状态更新回调 (实现IChatPanelCallback接口)
@@ -502,22 +481,6 @@ export class ChatPanel extends li_BaseView implements IChatPanelCallback {
ViewManager.I.openBundlesView("RecordPanel", this.id);
}
/**
* 获取当前聊天状态信息(用于调试)
*/
public getChatStatus(): any {
if (!this.chatController) {
return { error: "ChatController not initialized" };
}
return {
currentPanelRoleId: this.id,
controllerStats: this.chatController.getDialogStats(),
modelSummary: this.chatController.getModelSummary(),
allRolesStats: this.chatController.getAllRolesStats(),
};
}
/**
* 手动清除指定角色的数据(调试用)
* @param roleId 角色ID,不传则清除当前角色
@@ -241,7 +241,11 @@ export class GirlDetailPanel extends li_BaseView {
OnClickChatBtn() {
// 使用带过渡动画的导航方法
NavigationManager.Instance.navigateToChatWithTransition(this.id, this);
NavigationManager.Instance.navigateToChatWithTransition(
this.category.toString(),
this.id,
this
);
// 注意:不在这里直接调用onClose,而是在动画完成后由NavigationManager调用
}
@@ -29,7 +29,7 @@ export class PayToTalkSubpanel extends Component {
this.base = this.getComponent(UIOpacity);
}
show() {
show(categoryId: string, girlId: number) {
this.node.active = true;
this.base.opacity = 0;
tween(this.base).to(0.3, { opacity: 255 }).start();
@@ -53,7 +53,7 @@ export class PayToTalkSubpanel extends Component {
onClick_BuyTime() {
//购买次数
ChatController.Instance.resetChatCount();
//ChatController.Instance.resetChatCount();
this.hide();
}