提交聊天

This commit is contained in:
PC-20230316NUNE\Administrator
2023-11-14 18:52:25 +08:00
parent 5a43eb197b
commit 93ae85e88b
33 changed files with 2047 additions and 4757 deletions

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "5592da29-bb83-47c5-9d95-27f5c71ae7b6",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,146 @@
[
{
"__type__": "cc.Prefab",
"_name": "MainChatItem",
"_objFlags": 0,
"__editorExtras__": {},
"_native": "",
"data": {
"__id__": 1
},
"optimizationPolicy": 0,
"persistent": false
},
{
"__type__": "cc.Node",
"_name": "MainChatItem",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": null,
"_children": [],
"_active": true,
"_components": [
{
"__id__": 2
},
{
"__id__": 4
}
],
"_prefab": {
"__id__": 6
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 1512.0000000000005,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 3
},
"_contentSize": {
"__type__": "cc.Size",
"width": 335.53125,
"height": 50.4
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "3251Mcv39NZJJvhmqkWsTm"
},
{
"__type__": "cc.Label",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 5
},
"_customMaterial": null,
"_srcBlendFactor": 2,
"_dstBlendFactor": 4,
"_color": {
"__type__": "cc.Color",
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_string": "ScrollView content01",
"_horizontalAlign": 0,
"_verticalAlign": 1,
"_actualFontSize": 36,
"_fontSize": 36,
"_fontFamily": "Arial",
"_lineHeight": 40,
"_overflow": 0,
"_enableWrapText": true,
"_font": null,
"_isSystemFontUsed": true,
"_spacingX": 0,
"_isItalic": false,
"_isBold": false,
"_isUnderline": false,
"_underlineHeight": 2,
"_cacheMode": 0,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "7ahEvd3z5N4ruHsPPLIdmV"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "b4aPDEneNHC4OYnY3k7ypP",
"targetOverrides": null
}
]

View File

@@ -0,0 +1,13 @@
{
"ver": "1.1.49",
"importer": "prefab",
"imported": true,
"uuid": "da561b68-57fb-462b-b799-da2ba6658534",
"files": [
".json"
],
"subMetas": {},
"userData": {
"syncNodeName": "MainChatItem"
}
}

View File

@@ -20,15 +20,15 @@ import { SpriteFrame } from "cc";
import Loading from "../../extensions/ngame/assets/ngame/util/Loading";
import { Tables } from "../resources/config/data/schema";
import { JsonAsset } from "cc";
import { GAction } from "./consts/GActionEnum";
import { GAction } from "./consts/GAction";
import { StorageData, StorageEnum } from "./consts/GData";
import { JAPI, JAPIConfig } from "../../extensions/ngame/assets/ngame/util/JAPI";
import { AppData } from "./AppData";
// let APIPath = `http://localhost:8080`
// let WsPath = `ws://localhost:8080/websocket`
let APIPath = `https://api.pet.jisol.cn`
let WsPath = `wss://api.pet.jisol.cn/websocket`
let APIPath = `http://localhost:8080`
let WsPath = `ws://localhost:8080/websocket`
// let APIPath = `https://api.pet.jisol.cn`
// let WsPath = `wss://api.pet.jisol.cn/websocket`
//重写UI
class JNGLayer extends JNLayer{

View File

@@ -1,6 +1,7 @@
import SystemBase from "../../extensions/ngame/assets/ngame/system/SystemBase";
import { app } from "./App";
import BaseData from "./data/BaseData";
import ChatData from "./data/ChatData";
import PlayerData from "./data/PlayerData";
import PlayerPetData from "./data/PlayerPetData";
@@ -12,6 +13,7 @@ export class AppData extends SystemBase{
loadings:BaseData[] = [
PlayerData.getIns(), //玩家信息
PlayerPetData.getIns(), //玩家宠物信息
ChatData.getIns(), //聊天
];
async onInit(): Promise<any> {

View File

@@ -0,0 +1,9 @@
export enum GAction {
TOKEN_EXPIRED = 1001, //Token过期
//聊天
CHAT_MESSAGE = 2001, //发送聊天消息
CHAT_RECEIVE_MESSAGE = 2002, //接受聊天消息
}

View File

@@ -2,7 +2,7 @@
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "ed7dee3c-9396-4f08-bd29-deb690ca6cf8",
"uuid": "a70276f1-e218-427c-ba96-791133341363",
"files": [],
"subMetas": {},
"userData": {}

View File

@@ -1,6 +0,0 @@
export enum GAction {
TOKEN_EXPIRED = 1001, //Token过期
NOT_CREATE_PLAYER_INFO = 2001, //没有玩家信息 - 前往引导页面
}

View File

@@ -0,0 +1,9 @@
export interface GUIChatMessage{
message:string;
}
export enum GActionType {
GUIChatMessage = "GUIChatMessage",//聊天信息
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "d3e60765-b4ca-4c63-9dd8-20befd658457",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,3 @@
export enum GAction {
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "772c2168-9685-4567-92b0-93cb00b8d679",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,46 @@
import Singleton from "../../../extensions/ngame/assets/ngame/util/Singleton";
import { app } from "../App";
import { GAction } from "../consts/GAction";
import { GActionType, GUIChatMessage } from "../consts/GActionType";
import BaseData from "./BaseData";
//聊天数据
export default class ChatData extends BaseData{
//世界消息列表
datas:string[] = [];
//接受消息事件
receives:Function[] = [];
onInit() {
//监听聊天消息
app.socket.on(GAction.CHAT_RECEIVE_MESSAGE,this.onChatReceiveMessage,this,GActionType.GUIChatMessage);
}
//接受聊天消息
onChatReceiveMessage(info:GUIChatMessage){
console.log(`ChatData - onChatReceiveMessage`,info.message);
this.datas.push(info.message);
this.receives.forEach(fun => fun(info))
}
//发送消息
onSend(message:GUIChatMessage){
app.socket.Send(GAction.CHAT_MESSAGE,message,GActionType.GUIChatMessage);
}
//监听接受消息
on(receive:Function){
this.receives.push(receive);
}
//取消
off(receive:Function){
let index = this.receives.indexOf(receive);
if(index != -1)
this.receives.splice(index,1);
}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "37e2c6bd-5072-431f-a9c4-ec7fda53b41f",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "2c2f02a8-a17c-4c79-81c6-df08eff53759",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,8 +1,8 @@
import Singleton from "../../../../extensions/ngame/assets/ngame/util/Singleton";
import { app } from "../../App";
import PlayerData from "../../data/PlayerData";
import PlayerPetData from "../../data/PlayerPetData";
import { GUI } from "../UIConfig";
import Singleton from "../../../extensions/ngame/assets/ngame/util/Singleton";
import { app } from "../App";
import PlayerData from "../data/PlayerData";
import PlayerPetData from "../data/PlayerPetData";
import { GUI } from "../ui/UIConfig";
export default class NoviceManager extends Singleton{

View File

@@ -2,7 +2,7 @@
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "8b5cc1e0-3fa2-4ee3-b93b-2da9878f9c8c",
"uuid": "ef14d8c5-9f53-4f42-baeb-1c663be5f283",
"files": [],
"subMetas": {},
"userData": {}

View File

@@ -1,9 +1,83 @@
import { _decorator, Component, Node } from 'cc';
import { JNGLayerBase } from '../../../App';
import { app, JNGLayerBase } from '../../../App';
import { Prefab } from 'cc';
import ChatData from '../../../data/ChatData';
import { instantiate } from 'cc';
import { Label } from 'cc';
import { EditBox } from 'cc';
import { GUI } from '../../UIConfig';
import { GUIChatMessage } from '../../../consts/GActionType';
import { Widget } from 'cc';
import JScrollExceedHide from '../../../../../extensions/ngame/assets/ngame/util/components/JScrollExceedHide';
const { ccclass, property } = _decorator;
@ccclass('MainChatView')
export class MainChatView extends JNGLayerBase {
@property(Node)
content:Node; //聊天内容
@property(Prefab)
chatPrefab:Prefab; //聊天预制体
@property(EditBox)
inputMessage:EditBox; //聊天输入框
onJNLoad(data?: any): void {
super.onJNLoad(data);
this.onInitUpdate();
//监听消息
ChatData.getIns().on(this.onMessage.bind(this));
}
onJNClose(): void {
super.onJNClose();
ChatData.getIns().off(this.onMessage.bind(this));
}
//初始化聊天显示
onInitUpdate(){
this.content.destroyAllChildren();
let messages = ChatData.getIns().datas;
messages.forEach(message => {
let node = instantiate(this.chatPrefab);
node.getComponent(Label).string = message;
this.content.addChild(node);
})
}
//发送消息
onClickSendMessage(){
if(!this.inputMessage.string){
app.layer.Open(GUI.Tips,{text:"请输入内容"})
return;
}
ChatData.getIns().onSend({
message:this.inputMessage.string
});
}
//接受到消息
onMessage(info:GUIChatMessage){
//插入数据
let node = instantiate(this.chatPrefab);
node.getComponent(Label).string = info.message;
this.content.addChild(node);
this.scheduleOnce(() => {
this.getComponentInChildren(JScrollExceedHide).onUpdate();
})
}
}

View File

@@ -1,6 +1,8 @@
import { _decorator, Component, Label, Node } from 'cc';
import { app, JNGLayerBase } from '../../App';
import { GUI } from '../UIConfig';
import ChatData from '../../data/ChatData';
import PlayerData from '../../data/PlayerData';
const { ccclass, property } = _decorator;
@ccclass('MainView')
@@ -8,6 +10,12 @@ export class MainView extends JNGLayerBase {
onJNLoad(data?: any): void {
//发送消息
ChatData.getIns().onSend({
message:`${PlayerData.getIns().data.playerId} 加入游戏`
});
}
//打开聊天页面

View File

@@ -3,9 +3,7 @@ import { _decorator } from "cc";
import { JNGLayerBase, app } from "../../App";
import { Label } from "cc";
import { GUI } from "../UIConfig";
import { API } from "../../consts/API";
import { GAction } from "../../consts/GActionEnum";
import NoviceManager from "../Novice/NoviceManager";
import NoviceManager from "../../manager/NoviceManager";
const { ccclass, property } = _decorator;
@ccclass('LoadingView')