96 lines
2.4 KiB
TypeScript
96 lines
2.4 KiB
TypeScript
import { _decorator, Component, EditBox, Node,Label } from "cc";
|
|
import { DemoManager } from "./DemoManager";
|
|
import { ChatGPTService } from "./ChatGPTService";
|
|
import {characters} from "db://assets/Scripts/test/cfg/characters";
|
|
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 "db://assets/Scripts/test/ChatContentsLayout";
|
|
import {ViewManager} from "db://assets/Scripts/Main/Manager/ViewManager";
|
|
import GameRootUI from "db://assets/Scripts/Main/Common/GameRootUI";
|
|
import {ImagePopup} from "db://assets/Scripts/test/ImagePopup";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass("ChatPanel")
|
|
export class ChatPanel extends li_BaseView {
|
|
manager: DemoManager = null;
|
|
|
|
@property(EditBox)
|
|
editBox: EditBox = null;
|
|
|
|
@property(Label)
|
|
girlName: Label = null;
|
|
|
|
@property(ChatContentsLayout)
|
|
layout: ChatContentsLayout = null;
|
|
|
|
@property(ImagePopup)
|
|
popUpImage: ImagePopup = null;
|
|
|
|
id:number
|
|
|
|
onLoadCT()
|
|
{
|
|
this.register();
|
|
}
|
|
register()
|
|
{
|
|
Utils.addInnerEL(InnerMsgCode.Chat_DialogRefresh,this,this.onDialogUpdate);
|
|
}
|
|
refresh(id:number) {
|
|
this.id = id;
|
|
const data = characters[id-1];
|
|
this.girlName.string = data.name;
|
|
}
|
|
onDialogUpdate()
|
|
{
|
|
this.layout.UpdateDialog(DemoManager.getInstance().getDialogs())
|
|
}
|
|
protected onEnable(): void {
|
|
if (!this.manager) this.manager = DemoManager.getInstance();
|
|
|
|
GameRootUI.I.hideDefaultView();
|
|
}
|
|
|
|
public async OnClickSend() {
|
|
const str = this.editBox.string;
|
|
if (!str || str == "") return;
|
|
console.log("post:" + str);
|
|
|
|
this.editBox.string = "";
|
|
|
|
DemoManager.getInstance().updateDialog(true, str,true);
|
|
|
|
let ret = await ChatGPTService.getInstance().Post({
|
|
model: "Deepseek-reasoner",
|
|
messages: [{ role: "user", content: str }],
|
|
temperature: 0.8,
|
|
id: ChatGPTService.getInstance().GetId(),
|
|
});
|
|
console.log(ret);
|
|
|
|
const rep = ret.choices[0].message.content;
|
|
if (rep == null) {
|
|
console.warn("rep null");
|
|
}
|
|
if (this.manager) {
|
|
this.manager.updateDialog(false, rep);
|
|
}
|
|
console.log("ret:" + rep);
|
|
|
|
//测试
|
|
this.popUpImage.refresh("Image/1/blur_naked_1");
|
|
}
|
|
|
|
|
|
|
|
|
|
returnBtn()
|
|
{
|
|
this.onClose();
|
|
GameRootUI.I.showDefaultView();
|
|
|
|
//ViewManager.I.openBundlesView("GirlListPanel");
|
|
}
|
|
}
|