This commit is contained in:
DESKTOP-5RP3AKU\Jisol
2024-01-05 02:15:38 +08:00
parent 0556449f0a
commit c0cfcf98fc
14 changed files with 1004 additions and 67 deletions

View File

@@ -28,14 +28,14 @@ import AppAction from "./AppAction";
import { Asset } from "cc";
import { Component } from "cc";
// let APIPath = `http://localhost:8080`
// let WsPath = `ws://localhost:8080/websocket`
let APIPath = `http://localhost:8080`
let WsPath = `ws://localhost:8080/websocket`
// let APIPath = `http://192.168.1.23:8080`
// let WsPath = `ws://192.168.1.23:8080/websocket`
// let APIPath = `http://192.168.0.115:8080`
// let WsPath = `ws://192.168.0.115:8080/websocket`
let APIPath = `https://api.pet.jisol.cn`
let WsPath = `wss://api.pet.jisol.cn/websocket`
// let APIPath = `https://api.pet.jisol.cn`
// let WsPath = `wss://api.pet.jisol.cn/websocket`
//重写UI
class JNGLayer extends JNLayer{

View File

@@ -1,11 +1,16 @@
export interface GUIChatMessage{
message:string;
}
export interface GUIChatMessageDTO{
message:GUIChatMessage;
playerName:string;
playerId:number;
}
export enum GActionType {
GUIChatMessage = "GUIChatMessage",//聊天信息
GUIChatMessage = "GUIChatMessage",//聊天信息发送
GUIChatMessageDTO = "GUIChatMessageDTO",//聊天信息接受
/*************** 游戏模式 : 无尽模式(OnHook) **************/
GOnHookPet = "GOnHookPet", //野怪

View File

@@ -1,7 +1,7 @@
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 { GActionType, GUIChatMessage, GUIChatMessageDTO } from "../consts/GActionType";
import BaseData from "./BaseData";
//聊天数据
@@ -10,18 +10,18 @@ export default class ChatData extends BaseData{
static Event = "ChatData_Event_Message";
//世界消息列表
datas:string[] = [];
datas:GUIChatMessageDTO[] = [];
onInit() {
//监听聊天消息
app.socket.on(GAction.CHAT_RECEIVE_MESSAGE,this.onChatReceiveMessage,this,GActionType.GUIChatMessage);
app.socket.on(GAction.CHAT_RECEIVE_MESSAGE,this.onChatReceiveMessage,this,GActionType.GUIChatMessageDTO);
}
//接受聊天消息
onChatReceiveMessage(info:GUIChatMessage){
onChatReceiveMessage(info:GUIChatMessageDTO){
console.log(`ChatData - onChatReceiveMessage`,info.message);
this.datas.push(info.message);
this.datas.push(info);
app.event.emit(ChatData.Event,info);
}

View File

@@ -5,7 +5,7 @@ import { instantiate } from 'cc';
import { Label } from 'cc';
import { EditBox } from 'cc';
import { GUI } from '../../UIConfig';
import { GUIChatMessage } from '../../../consts/GActionType';
import { GUIChatMessage, GUIChatMessageDTO } from '../../../consts/GActionType';
import { Widget } from 'cc';
import JScrollExceedHide from '../../../../../extensions/ngame/assets/ngame/util/components/JScrollExceedHide';
import { JNGLayerBase } from '../../../components/JNComponent';
@@ -46,9 +46,7 @@ export class MainChatView extends JNGLayerBase {
let messages = ChatData.getIns().datas;
messages.forEach(message => {
let node = instantiate(this.chatPrefab);
node.getComponent(Label).string = message;
this.content.addChild(node);
this.onMessage(message);
})
}
@@ -68,11 +66,12 @@ export class MainChatView extends JNGLayerBase {
}
//接受到消息
onMessage(info:GUIChatMessage){
onMessage(info:GUIChatMessageDTO){
//插入数据
let node = instantiate(this.chatPrefab);
node.getComponent(Label).string = info.message;
node.getComponent(Label).string = `${info.playerName} : ${info.message.message}`;
this.content.addChild(node);
this.scheduleOnce(() => {
this.getComponentInChildren(JScrollExceedHide).onUpdate();

View File

@@ -31,7 +31,7 @@ export class MainView extends JNGLayerBase {
//发送消息
ChatData.getIns().onSend({
message:`${PlayerData.getIns().data.playerId} 加入游戏`
message:`加入游戏`
});
this.onUpdateView();