132 lines
3.4 KiB
TypeScript
132 lines
3.4 KiB
TypeScript
import {
|
|
_decorator,
|
|
Component,
|
|
EditBox,
|
|
Node,
|
|
Label,
|
|
Sprite,
|
|
UITransform,
|
|
} from "cc";
|
|
// 首先加载 polyfills 以确保兼容性
|
|
import "../../utils/polyfills";
|
|
import { DialogManager } from "../../manager/DialogManager";
|
|
import { ChatAIService } from "../../core/ChatAIService";
|
|
import li_BaseView from "db://assets/Scripts/Main/Common/li_BaseView";
|
|
import Utils from "db://assets/Scripts/Main/Common/Utils";
|
|
import { InnerMsgCode } from "db://assets/Scripts/Main/Config/InnerMsgCode";
|
|
import { ChatContentsLayout } from "../components/ChatContentsLayout";
|
|
import { ViewManager } from "db://assets/Scripts/Main/Manager/ViewManager";
|
|
import GameRootUI from "db://assets/Scripts/Main/Common/GameRootUI";
|
|
import { ImagePopup } from "../components/ImagePopup";
|
|
|
|
import ResManager from "db://assets/Scripts/Main/Manager/ResManager";
|
|
import { VideoRoleType } from "db://assets/Scripts/Main/Common/GlobalValue";
|
|
import ConfigManager from "../../manager/ConfigManager";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass("ChatPanel")
|
|
export class ChatPanel extends li_BaseView {
|
|
manager: DialogManager = null;
|
|
|
|
@property(EditBox)
|
|
editBox: EditBox = null;
|
|
|
|
@property(Label)
|
|
girlName: Label = null;
|
|
|
|
@property(Sprite)
|
|
girlImg: Sprite = null;
|
|
|
|
@property(ChatContentsLayout)
|
|
layout: ChatContentsLayout = null;
|
|
|
|
@property(ImagePopup)
|
|
popUpImage: ImagePopup = null;
|
|
|
|
id: number;
|
|
private _nodeTab: any = {};
|
|
|
|
openUIDataCT(data) {
|
|
this.id = data;
|
|
// 设置当前聊天的角色ID
|
|
ChatAIService.Instance.setCurrentRole(this.id);
|
|
}
|
|
|
|
onLoadCT() {
|
|
Utils.parseNode(this.node, this._nodeTab);
|
|
|
|
this.register();
|
|
this.refresh(this.id);
|
|
}
|
|
register() {
|
|
Utils.addInnerEL(
|
|
InnerMsgCode.Chat_DialogRefresh,
|
|
this,
|
|
this.onDialogUpdate
|
|
);
|
|
}
|
|
refresh(id: number) {
|
|
this.id = id;
|
|
const data = ConfigManager.tables.TbGirls.get(this.id);
|
|
const dataDetail = ConfigManager.tables.TbGirlsDetail.get(this.id);
|
|
if (!data) return;
|
|
this.girlName.string = data.name;
|
|
ResManager.I.changeBundleSpriteFrame(
|
|
this.girlImg,
|
|
data.avatarPath,
|
|
"Chat18x",
|
|
() => {
|
|
let sizeTran = this.girlImg.node.parent.getComponent(UITransform);
|
|
Utils.adjustBgPixelRatioToSize(
|
|
sizeTran.contentSize,
|
|
this.girlImg.node,
|
|
2
|
|
);
|
|
}
|
|
);
|
|
let uiTransform: UITransform =
|
|
this._nodeTab.BgFrame.getComponent(UITransform);
|
|
|
|
Utils.sendInnerMsg(InnerMsgCode.SimplePlayVide, {
|
|
path: dataDetail.pics[0],
|
|
size: uiTransform.contentSize,
|
|
});
|
|
}
|
|
onDialogUpdate() {
|
|
this.layout.UpdateDialog(DialogManager.getInstance().getDialogs());
|
|
}
|
|
protected onEnable(): void {
|
|
if (!this.manager) this.manager = DialogManager.getInstance();
|
|
|
|
GameRootUI.I.hideDefaultView();
|
|
}
|
|
|
|
public async OnClickSend() {
|
|
const str = this.editBox.string;
|
|
if (!str || str == "") return;
|
|
console.log("post:" + str);
|
|
|
|
this.editBox.string = "";
|
|
|
|
DialogManager.getInstance().updateDialog(true, str, true);
|
|
|
|
// 使用新的sendMessage方法,传入角色ID
|
|
const ret = await ChatAIService.Instance.sendMessage(this.id, str);
|
|
|
|
if (this.manager) {
|
|
this.manager.updateDialog(false, ret);
|
|
}
|
|
console.log("ret:" + ret);
|
|
|
|
//测试
|
|
//this.popUpImage.refresh("Image/1/blur_naked_1");
|
|
}
|
|
|
|
returnBtn() {
|
|
this.onClose();
|
|
GameRootUI.I.showDefaultView();
|
|
|
|
//ViewManager.I.openBundlesView("GirlListPanel");
|
|
}
|
|
}
|