update
This commit is contained in:
+1021
-157
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,54 @@
|
||||
import { _decorator, Component, instantiate, Node, Vec3 } from "cc";
|
||||
import { DemoManager } from "./DemoManager";
|
||||
import { DialogBubble } from "./DialogBubble";
|
||||
import { Dialog } from "./DemoData";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
const BUTTOM_Y = -346.354;
|
||||
|
||||
@ccclass("ChatContentsLayout")
|
||||
export class ChatContentsLayout extends Component {
|
||||
@property(DemoManager)
|
||||
manager: DemoManager = null;
|
||||
|
||||
@property(DialogBubble)
|
||||
lBubble: DialogBubble = null;
|
||||
@property(DialogBubble)
|
||||
rBubble: DialogBubble = null;
|
||||
|
||||
bubbles: DialogBubble[] = [];
|
||||
|
||||
protected start(): void {
|
||||
this.lBubble.node.active = false;
|
||||
this.rBubble.node.active = false;
|
||||
this.manager.layoutout = this;
|
||||
}
|
||||
|
||||
UpdateDialog(dialogs: Dialog[]) {
|
||||
//if (!this.bubbles) this.bubbles = [];
|
||||
for (let i = this.bubbles.length - 1; i >= 0; i--) {
|
||||
if (this.bubbles[i].node) {
|
||||
this.bubbles[i].node.destroy();
|
||||
}
|
||||
}
|
||||
this.bubbles = [];
|
||||
let initPosY: number = BUTTOM_Y;
|
||||
for (let i = dialogs.length - 1; i >= 0; i--) {
|
||||
const dialog = dialogs[i]; //倒序
|
||||
|
||||
let newBubbleNode = dialog.isPlayer
|
||||
? instantiate(this.rBubble.node)
|
||||
: instantiate(this.lBubble.node);
|
||||
let newBubble = newBubbleNode.getComponent(DialogBubble);
|
||||
|
||||
newBubbleNode.setParent(this.node);
|
||||
newBubble.node.active = true;
|
||||
let pos = newBubble.node.position;
|
||||
newBubble.node.position = new Vec3(pos.x, initPosY, pos.z);
|
||||
|
||||
let offset = newBubble.updateBubbleContent(dialog.content);
|
||||
initPosY += offset + 40;
|
||||
this.bubbles.push(newBubble);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "3f083bb1-33cb-4e87-93a9-7c120f3aa0e6",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -1,13 +1,15 @@
|
||||
import { _decorator, Component, EditBox, Label, Node } from "cc";
|
||||
import { l10n } from "db://localization-editor/l10n";
|
||||
import { DemoManager } from "./DemoManager";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("ChatGPTService")
|
||||
export class ChatGPTService extends Component {
|
||||
@property(DemoManager)
|
||||
manager: DemoManager = null;
|
||||
|
||||
@property(EditBox)
|
||||
editBox: EditBox = null;
|
||||
@property(Label)
|
||||
reply: Label = null;
|
||||
|
||||
private apiurl: string = "https://cloud.fastgpt.cn/api/v1/chat/completions";
|
||||
private apikey: string =
|
||||
@@ -36,25 +38,35 @@ export class ChatGPTService extends Component {
|
||||
}
|
||||
|
||||
protected async start(): Promise<void> {
|
||||
console.log(l10n.t("hello"));
|
||||
l10n.changeLanguage("zh-Hans-CN");
|
||||
console.log(l10n.t("hello"));
|
||||
l10n.changeLanguage("en");
|
||||
console.log(l10n.t("hello"));
|
||||
// console.log(l10n.t("hello"));
|
||||
// l10n.changeLanguage("zh-Hans-CN");
|
||||
// console.log(l10n.t("hello"));
|
||||
// l10n.changeLanguage("en");
|
||||
// console.log(l10n.t("hello"));
|
||||
}
|
||||
|
||||
public async OnClickSend() {
|
||||
const str = this.editBox.string;
|
||||
if (!str || str == "") return;
|
||||
console.log("post:" + str);
|
||||
|
||||
if (this.manager) {
|
||||
this.manager.updateDialog(true, str);
|
||||
}
|
||||
|
||||
let ret = await this.Post({
|
||||
model: "llama3.1:8b",
|
||||
messages: [{ role: "user", content: str }],
|
||||
temperature: 0.0,
|
||||
temperature: 0.8,
|
||||
});
|
||||
|
||||
const rep = ret.choices[0].message.content;
|
||||
this.reply.string = rep;
|
||||
if (rep == null) {
|
||||
console.warn("rep null");
|
||||
}
|
||||
if (this.manager) {
|
||||
this.manager.updateDialog(false, rep);
|
||||
}
|
||||
console.log("ret:" + rep);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
export interface Dialog {
|
||||
isPlayer: boolean;
|
||||
content: string;
|
||||
}
|
||||
|
||||
export class DemoData {
|
||||
public Dialogs: Dialog[] = [];
|
||||
|
||||
public cleanDialog() {
|
||||
this.Dialogs = [];
|
||||
}
|
||||
|
||||
public pushDialog(isPlayer: boolean, str: string) {
|
||||
if (!this.Dialogs) this.Dialogs = [];
|
||||
this.Dialogs.push({ isPlayer: isPlayer, content: str });
|
||||
}
|
||||
|
||||
public GetDialogs() {
|
||||
return this.Dialogs;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "830fbab3-0034-468c-9c91-754a8c7e4088",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { _decorator, Component, Node } from "cc";
|
||||
import { DemoData, Dialog } from "./DemoData";
|
||||
import { ChatContentsLayout } from "./ChatContentsLayout";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("DemoManager")
|
||||
export class DemoManager extends Component {
|
||||
demoData: DemoData;
|
||||
|
||||
public layoutout: ChatContentsLayout;
|
||||
|
||||
start() {
|
||||
this.demoData = new DemoData();
|
||||
}
|
||||
|
||||
public updateDialog(isPlayer: boolean, str: string) {
|
||||
this.demoData.pushDialog(isPlayer, str);
|
||||
console.log("update dialog");
|
||||
this.layoutout.UpdateDialog(this.getDialogs());
|
||||
}
|
||||
|
||||
public getDialogs() {
|
||||
return this.demoData.GetDialogs();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "1bbb6645-1868-4b46-932a-c29fbb9ff0fc",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { _decorator, Component, Label, Node, Size, UITransform } from "cc";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass("DialogBubble")
|
||||
export class DialogBubble extends Component {
|
||||
@property(UITransform)
|
||||
bg: UITransform = null;
|
||||
@property(Label)
|
||||
content: Label = null;
|
||||
@property(UITransform)
|
||||
contentT: UITransform = null;
|
||||
|
||||
updateBubbleContent(str: string) {
|
||||
this.content.string = str;
|
||||
this.content.updateRenderData();
|
||||
|
||||
this.bg.setContentSize(
|
||||
new Size(this.contentT.contentSize.x + 5, this.contentT.contentSize.y + 5)
|
||||
);
|
||||
|
||||
return this.bg.contentSize.y / 2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "174d858d-dd04-4283-bc20-3daeff93c518",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "eb853b2f-d932-485d-b928-8de811c83ae8",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"ver": "1.0.1",
|
||||
"importer": "text",
|
||||
"imported": true,
|
||||
"uuid": "0751a71b-f7fc-4905-af59-24965a4e0921",
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"__version__": "3.0.5",
|
||||
"__version__": "3.0.7",
|
||||
"game": {
|
||||
"name": "未知游戏",
|
||||
"name": "UNKNOW GAME",
|
||||
"app_id": "UNKNOW",
|
||||
"c_id": "0"
|
||||
},
|
||||
|
||||
@@ -4,19 +4,19 @@
|
||||
"customSplash": {
|
||||
"id": "customSplash",
|
||||
"label": "customSplash",
|
||||
"enable": true,
|
||||
"enable": false,
|
||||
"customSplash": {
|
||||
"complete": true,
|
||||
"form": "https://creator-api.cocos.com/api/form/show?sid=05d2919f40e0134fd62411d578aed4d8"
|
||||
"complete": false,
|
||||
"form": "https://creator-api.cocos.com/api/form/show?"
|
||||
}
|
||||
},
|
||||
"removeSplash": {
|
||||
"id": "removeSplash",
|
||||
"label": "removeSplash",
|
||||
"enable": true,
|
||||
"enable": false,
|
||||
"removeSplash": {
|
||||
"complete": true,
|
||||
"form": "https://creator-api.cocos.com/api/form/show?sid=05d2919f40e0134fd62411d578aed4d8"
|
||||
"complete": false,
|
||||
"form": "https://creator-api.cocos.com/api/form/show?"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user