mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-26 18:26:23 +00:00
提交聊天
This commit is contained in:
@@ -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{
|
||||
|
@@ -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> {
|
||||
|
9
JisolGameCocos/assets/script/consts/GAction.ts
Normal file
9
JisolGameCocos/assets/script/consts/GAction.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export enum GAction {
|
||||
|
||||
TOKEN_EXPIRED = 1001, //Token过期
|
||||
|
||||
//聊天
|
||||
CHAT_MESSAGE = 2001, //发送聊天消息
|
||||
CHAT_RECEIVE_MESSAGE = 2002, //接受聊天消息
|
||||
|
||||
}
|
@@ -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": {}
|
@@ -1,6 +0,0 @@
|
||||
export enum GAction {
|
||||
|
||||
TOKEN_EXPIRED = 1001, //Token过期
|
||||
NOT_CREATE_PLAYER_INFO = 2001, //没有玩家信息 - 前往引导页面
|
||||
|
||||
}
|
9
JisolGameCocos/assets/script/consts/GActionType.ts
Normal file
9
JisolGameCocos/assets/script/consts/GActionType.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export interface GUIChatMessage{
|
||||
message:string;
|
||||
}
|
||||
|
||||
export enum GActionType {
|
||||
|
||||
GUIChatMessage = "GUIChatMessage",//聊天信息
|
||||
|
||||
}
|
9
JisolGameCocos/assets/script/consts/GActionType.ts.meta
Normal file
9
JisolGameCocos/assets/script/consts/GActionType.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d3e60765-b4ca-4c63-9dd8-20befd658457",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
3
JisolGameCocos/assets/script/consts/HttpCode.ts
Normal file
3
JisolGameCocos/assets/script/consts/HttpCode.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export enum GAction {
|
||||
|
||||
}
|
9
JisolGameCocos/assets/script/consts/HttpCode.ts.meta
Normal file
9
JisolGameCocos/assets/script/consts/HttpCode.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "772c2168-9685-4567-92b0-93cb00b8d679",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
46
JisolGameCocos/assets/script/data/ChatData.ts
Normal file
46
JisolGameCocos/assets/script/data/ChatData.ts
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
9
JisolGameCocos/assets/script/data/ChatData.ts.meta
Normal file
9
JisolGameCocos/assets/script/data/ChatData.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "37e2c6bd-5072-431f-a9c4-ec7fda53b41f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
9
JisolGameCocos/assets/script/manager.meta
Normal file
9
JisolGameCocos/assets/script/manager.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "2c2f02a8-a17c-4c79-81c6-df08eff53759",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
@@ -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{
|
||||
|
@@ -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": {}
|
@@ -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();
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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} 加入游戏`
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
//打开聊天页面
|
||||
|
@@ -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')
|
||||
|
Reference in New Issue
Block a user