You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
212 lines
7.6 KiB
212 lines
7.6 KiB
import Common5 from "../../Platform/th/Common5";
|
|
import User from "../../FrameWork/User/User";
|
|
import PrefabManage, { GameType } from "../PrefabManager/PrefabManage";
|
|
import ChatDialog from "./ChatDialog";
|
|
import { ryw_Event } from "../../FrameWork/Event/EventEnum";
|
|
import EventMgr from "../../FrameWork/Event/EventMgr";
|
|
const {ccclass, property} = cc._decorator;
|
|
|
|
@ccclass
|
|
export default class ChatManager{
|
|
|
|
//获取名字对应的json名
|
|
public static getJsonByName(personName){
|
|
for(var i=0;i<Common5.chatPersonConfig.length;i++){
|
|
if(Common5.chatPersonConfig[i].chatPersonName == personName){
|
|
return Common5.chatPersonConfig[i].jsonName
|
|
}
|
|
}
|
|
}
|
|
//获取json对应的名字
|
|
public static getNameByJson(jsonName){
|
|
for(var i=0;i<Common5.chatPersonConfig.length;i++){
|
|
if(Common5.chatPersonConfig[i].jsonName == jsonName){
|
|
return Common5.chatPersonConfig[i].chatPersonName
|
|
}
|
|
}
|
|
}
|
|
//获取json配置
|
|
public static getConfigByJsonName(jsonName){
|
|
// console.log('Common5.chatPersonConfig==',Common5.chatPersonConfig)
|
|
for(var i=0;i<Common5.chatPersonConfig.length;i++){
|
|
if(Common5.chatPersonConfig[i].jsonName == jsonName){
|
|
return Common5.chatPersonConfig[i]
|
|
}
|
|
}
|
|
}
|
|
//判断聊天类型typeStr是否包含聊天索引eventIndex
|
|
public static isChatTypeIncludeEventIndex(typeStr,eventIndex){
|
|
let allEventIndexTab = []
|
|
for(let i=0;i<Common5.chatPersonConfig.length;i++){
|
|
if(Common5.chatPersonConfig[i].type == typeStr){
|
|
let tab = Common5.chatPersonConfig[i].eventIndexStr
|
|
if(tab){
|
|
for(let j=0;j<tab.length;j++){
|
|
allEventIndexTab.push(tab[j])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if(eventIndex != '' && allEventIndexTab.indexOf(eventIndex) > -1 ){
|
|
return true
|
|
}else{
|
|
return false
|
|
}
|
|
}
|
|
public static refreshChatConfigByTimeLine(curDay){
|
|
//遍历所有配置
|
|
// let chatPeriodTab = User.getChatPeriodTab()
|
|
let chatPersonConfig = Common5.chatPersonConfig
|
|
|
|
//console.log(chatPersonConfig,'chatPersonConfig')
|
|
for(var i=0;i<chatPersonConfig.length;i++){
|
|
//找到属于时间线触发的json
|
|
let dayIndexStr = chatPersonConfig[i].dayIndexStr
|
|
if(dayIndexStr && dayIndexStr.length > 0){
|
|
// //可以出现的天数
|
|
// if(!chatPersonConfig[i].hasOwnProperty('showDay')){
|
|
// continue;
|
|
// }
|
|
// let showDay = chatPersonConfig[i].showDay
|
|
|
|
|
|
for(var j=0;j<dayIndexStr.length;j++){
|
|
let day = Number(dayIndexStr[j].slice(4))
|
|
//当前天数达到最早出现的天数,加载进入配置表
|
|
if(curDay >= day ){
|
|
// this.reloadChatPersonConfig(chatPersonConfig[i].jsonName)
|
|
this.setSingleChatStatus(chatPersonConfig[i].type,chatPersonConfig[i].jsonName,dayIndexStr[j],false)
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
//设置单个聊天的状态(生成到内存中)
|
|
public static setSingleChatStatus(type,jsonName,indexStr,bFinish){
|
|
//先判断类型
|
|
if(!this.isChatTypeIncludeEventIndex(type,indexStr)){
|
|
return
|
|
}
|
|
if(!User.checkIsIncludeIndexStr(jsonName,indexStr)){
|
|
this.setChatRecordData(jsonName,indexStr,bFinish)
|
|
console.log('Event_HasNewMsg11')
|
|
EventMgr.emitEvent_custom(ryw_Event.Event_HasNewMsg,true);
|
|
}
|
|
}
|
|
public static setChatRecordData(jsonName,indexStr,bFinish){
|
|
User.setChatRecordData(jsonName,indexStr,bFinish)
|
|
}
|
|
//获取特定聊天人的json
|
|
public static getPersonConfig(jsonName){
|
|
return Common5.allJuQingChatConfig[jsonName]
|
|
}
|
|
//获取chatPerson
|
|
public static getChatPerson(jsonName){
|
|
|
|
}
|
|
|
|
public static getChatMsgByIndex(chatConfig, index){
|
|
for(let i=0;i<chatConfig.length;i++){
|
|
if(chatConfig[i].id == index){
|
|
return chatConfig[i];
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static isHaveNewMessage(){
|
|
let rlt = false;
|
|
|
|
// let allRecord = User.getChatData()
|
|
// let chatPeriodTab = User.getChatPeriodTab()
|
|
|
|
|
|
// let curDay = User.getDay()
|
|
// let allJuQingChatConfig = Common5.allJuQingChatConfig
|
|
// for(var name in allJuQingChatConfig){
|
|
|
|
// let saveDay = 0
|
|
// let personJson = ChatManager.getPersonConfig(name)
|
|
// let chatPerson = ChatManager.getConfigByJsonName(name)
|
|
// let curPersonRecord = allRecord[name]
|
|
// let finishDayLength = 0
|
|
// if(curPersonRecord && curPersonRecord["finishDay"]){
|
|
// saveDay = curPersonRecord["finishDay"]
|
|
// finishDayLength = curPersonRecord["finishIndex"].length
|
|
// }
|
|
// if(chatPerson.triggerType == "time"){
|
|
// //显示未聊天的第一条
|
|
// if(!chatPerson.hasOwnProperty('showDay')){
|
|
// continue;
|
|
// }
|
|
// for(var i=0;i<chatPerson.showDay.length;i++){
|
|
// if(curDay >= (chatPerson.showDay[i]+chatPeriodTab.curDay)){
|
|
// if((chatPerson.showDay[i]+chatPeriodTab.curDay) > saveDay){
|
|
// let firstChatId = 0
|
|
// for(var j=0;j<personJson.length;j++){
|
|
// if(personJson[j].dayIndex == (chatPerson.showDay[i])){
|
|
// firstChatId = personJson[j].id
|
|
// //flagNode.active = true
|
|
// return true;
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// }else if(chatPerson.triggerType == "event"){
|
|
// if(!chatPerson.hasOwnProperty('showDay')){
|
|
// continue;
|
|
// }
|
|
// if(finishDayLength <=0){
|
|
// // finishDayLength = curPersonRecord["finishIndex"].length
|
|
// //flagNode.active = true
|
|
// //显示未聊天的第一条
|
|
// return true;
|
|
// }
|
|
|
|
// }
|
|
// }
|
|
|
|
return rlt;
|
|
}
|
|
//事件聊天直接打开聊天内容
|
|
public static eventOpenChatContent(type,jsonName,indexStr){
|
|
// if(indexStr == ''){
|
|
// PrefabManage.showTextTips('未传入聊天id==')
|
|
// return
|
|
// }
|
|
this.setSingleChatStatus(type,jsonName,indexStr,false)
|
|
// console.log("事件加载聊天json成功==",jsonName,indexStr)
|
|
PrefabManage.loadPrefabByType(GameType.ChatDialog,cc.director.getScene().getChildByName("Canvas").getChildByName('prefabLayer2'),(prefabNode)=>{
|
|
prefabNode.getComponent(ChatDialog).enterDialog(jsonName,indexStr,()=>{
|
|
console.log("关闭聊天的回调")
|
|
})
|
|
})
|
|
|
|
// }
|
|
// ChatManager.reloadChatPersonConfig(jsonName,loadFinishCallFunc)
|
|
}
|
|
|
|
public static getAllChatRecordData(){
|
|
return User.getAllChatRecordData()
|
|
}
|
|
public static getChatRecordDataByJson(jsonName){
|
|
let recordData = this.getAllChatRecordData()
|
|
return recordData[jsonName]
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|