mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交聊天
This commit is contained in:
@@ -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')
|
||||
|
@@ -1,30 +0,0 @@
|
||||
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";
|
||||
|
||||
export default class NoviceManager extends Singleton{
|
||||
|
||||
//新手引导执行
|
||||
async onStart(){
|
||||
|
||||
//获取玩家信息是否引导过
|
||||
if(!(PlayerData.getIns().data.novice)){
|
||||
//如果没有过引导则打开引导页面
|
||||
await app.layer.OpenToClose(GUI.NoviceNamingView);
|
||||
}
|
||||
|
||||
//获取玩家信息是否选择过宠物(有没有宠物)
|
||||
//如果没有宠物则弹出让玩家选择宠物
|
||||
if(PlayerPetData.getIns().getData().length == 0){
|
||||
//没有宠物则弹出选择宠物页面
|
||||
await app.layer.OpenToClose(GUI.NoviceSelectPetView);
|
||||
}
|
||||
|
||||
console.log("新手引导结束");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "8b5cc1e0-3fa2-4ee3-b93b-2da9878f9c8c",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
Reference in New Issue
Block a user