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.
198 lines
7.3 KiB
198 lines
7.3 KiB
1 week ago
|
|
||
|
import User from "../../FrameWork/User/User";
|
||
|
import Common5 from "../../Platform/th/Common5";
|
||
|
import GameBase from "../SCommon/GameBase";
|
||
|
import PrefabManage, { GameType } from "../PrefabManager/PrefabManage";
|
||
|
import ChatDialog from "./ChatDialog";
|
||
|
import ChatManager from "./ChatManager";
|
||
|
import JuQingManager from "./JuQingManager";
|
||
|
import EventMgr from "../../FrameWork/Event/EventMgr";
|
||
|
import { ryw_Event } from "../../FrameWork/Event/EventEnum";
|
||
|
import TaskManager, { MainTaskIdEnum } from "./TaskManager";
|
||
|
import NewGuideScript from "../NewGuide/NewGuideScript";
|
||
|
const { ccclass, property } = cc._decorator;
|
||
|
|
||
|
@ccclass
|
||
|
export default class ChatList extends GameBase {
|
||
|
//聊天列表
|
||
|
@property(cc.Node)
|
||
|
chatListNode: cc.Node = null
|
||
|
@property(cc.Node)
|
||
|
chatListContent: cc.Node = null
|
||
|
@property(cc.Node)
|
||
|
listItem: cc.Node = null
|
||
|
|
||
|
curDay = 0//当天
|
||
|
curChatTag = ''
|
||
|
isOne = true
|
||
|
|
||
|
onLoad() {
|
||
|
super.onLoad()
|
||
|
console.log('isHaveNewMessage=========================', ChatManager.isHaveNewMessage());
|
||
|
}
|
||
|
|
||
|
protected start(): void {
|
||
|
EventMgr.onEvent_custom(ryw_Event.ExitBtnEvent, () => {
|
||
|
|
||
|
if (cc.isValid(this.node, true)) {
|
||
|
console.log('initListInfo++++++++++++刷新')
|
||
|
|
||
|
this.initListInfo()
|
||
|
}
|
||
|
|
||
|
}, this)
|
||
|
}
|
||
|
|
||
|
|
||
|
onDestroy(): void {
|
||
|
super.onDestroy()
|
||
|
EventMgr.emitEvent_custom(ryw_Event.CloseChatList);
|
||
|
}
|
||
|
initView(chatTag) {
|
||
|
this.curChatTag = chatTag
|
||
|
this.curDay = User.getDay()
|
||
|
this.initListInfo()
|
||
|
}
|
||
|
//初始化聊天列表(第几天)
|
||
|
initListInfo() {
|
||
|
console.log("当前是第" + this.curDay + "天--")
|
||
|
this.chatListContent.removeAllChildren()
|
||
|
let allJuQingChatConfig: any = Common5.allJuQingChatConfig
|
||
|
//console.log('allJuQingChatConfig', allJuQingChatConfig);
|
||
|
|
||
|
|
||
|
let tempNameTab = []
|
||
|
let tempChilds = []
|
||
|
for (let name in allJuQingChatConfig) {
|
||
|
//日记本和对话不显示在微信聊天中
|
||
|
let personConfig = JuQingManager.getPersonJsonByJsonName(name)
|
||
|
if (personConfig.type == 'RJB' || personConfig.type == 'DH') {
|
||
|
continue
|
||
|
}
|
||
|
|
||
|
let personJson = ChatManager.getPersonConfig(name)
|
||
|
let recordData = ChatManager.getChatRecordDataByJson(name)
|
||
|
|
||
|
//console.log(recordData,'recordData+++++++++++++===')
|
||
|
if (recordData && recordData.length > 0) {
|
||
|
//duihuaArray.push[]
|
||
|
let childItem = cc.instantiate(this.listItem)
|
||
|
let nameStr = ChatManager.getNameByJson(name)
|
||
|
childItem.getChildByName("nameStr").getComponent(cc.Label).string = nameStr
|
||
|
tempNameTab.push(nameStr)
|
||
|
let chatPerson = ChatManager.getConfigByJsonName(name)
|
||
|
// Common5.getSpriteFrameFromBundle("allRes",chatPerson.imgPath,childItem.getChildByName("avatar").getComponent(cc.Sprite));
|
||
|
Common5.getSpriteFrameFromBundle("GameRes", "JuQingChat/texture/人物头像/" + chatPerson.imgPath, childItem.getChildByName("avatar").getComponent(cc.Sprite));
|
||
|
let itemInfo = this.getListItemStr(name, personJson, recordData, childItem.getChildByName("flag"))
|
||
|
let contentStr = itemInfo.contentDesc
|
||
|
let indexStr = itemInfo.indexStr
|
||
|
if (contentStr.length > 12) {
|
||
|
contentStr = contentStr.substr(0, 12) + "..."
|
||
|
}
|
||
|
childItem.getChildByName("contentStr").getComponent(cc.Label).string = contentStr
|
||
|
childItem.attr({ jsonName: name, playInfo: allJuQingChatConfig[name], indexStr: indexStr })
|
||
|
childItem.active = true
|
||
|
let isFinish = true
|
||
|
for (let rei = 0; rei < recordData.length; rei++) {
|
||
|
let data_ = recordData[rei]
|
||
|
if (data_.isFinish == false) {
|
||
|
isFinish = false
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
childItem['isFinish'] = isFinish
|
||
|
tempChilds[tempChilds.length] = childItem
|
||
|
//this.chatListContent.addChild(childItem)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//聊天置顶
|
||
|
if (tempChilds.length > 0) {
|
||
|
let idexz = 0
|
||
|
for (let i = 0; i < tempChilds.length; i++) {
|
||
|
|
||
|
if (!tempChilds[i]['isFinish']) {
|
||
|
idexz++
|
||
|
tempChilds[i].zIndex = idexz
|
||
|
this.chatListContent.addChild(tempChilds[i])
|
||
|
}
|
||
|
}
|
||
|
|
||
|
for (let i = 0; i < tempChilds.length; i++) {
|
||
|
if (tempChilds[i]['isFinish']) {
|
||
|
idexz++
|
||
|
tempChilds[i].zIndex = idexz
|
||
|
this.chatListContent.addChild(tempChilds[i])
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
if (Common5.isOpenChatPeople != '') {
|
||
|
let people = Common5.isOpenChatPeople;
|
||
|
let event = {
|
||
|
target: {
|
||
|
jsonName: people
|
||
|
}
|
||
|
}
|
||
|
Common5.isOpenChatPeople = ''
|
||
|
this.onItemListClick(event)
|
||
|
}
|
||
|
|
||
|
let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
|
||
|
let mainId = mainTaskInfo.Id
|
||
|
if (mainId == MainTaskIdEnum.MainTask_203 && this.isOne) {
|
||
|
let node = this.node.getChildByName("guide")
|
||
|
this.guideView([node]);
|
||
|
this.isOne = false
|
||
|
}
|
||
|
}
|
||
|
|
||
|
guideView(nodeArray) {
|
||
|
PrefabManage.loadPrefabByType(GameType.GuideMskNode, this.node, (prefab) => {
|
||
|
let guideNodeArray = nodeArray
|
||
|
let firstNode = guideNodeArray.shift()
|
||
|
prefab.getComponent(NewGuideScript).setBindNode(firstNode, guideNodeArray)
|
||
|
})
|
||
|
}
|
||
|
|
||
|
//点击进入聊天
|
||
|
onItemListClick(event) {
|
||
|
PrefabManage.loadPrefabByType(GameType.ChatDialog, cc.director.getScene().getChildByName("Canvas").getChildByName('prefabLayer2'), (prefabNode) => {
|
||
|
prefabNode.getComponent(ChatDialog).enterDialog(event.target.jsonName, null, () => {
|
||
|
this.initListInfo()
|
||
|
})
|
||
|
})
|
||
|
}
|
||
|
|
||
|
//显示列表的显示内容
|
||
|
getListItemStr(jsonName, personJson, recordData, flagNode) {
|
||
|
let indexStr = ''
|
||
|
//优先显示未完成对话的第一条
|
||
|
for (let i = 0; i < recordData.length; i++) {
|
||
|
if (!recordData[i].isFinish) {
|
||
|
indexStr = recordData[i].indexStr
|
||
|
for (let j = 0; j < personJson.length; j++) {
|
||
|
if (personJson[j].indexStr == indexStr) {
|
||
|
flagNode.active = true
|
||
|
return { contentDesc: personJson[j].contentDesc, indexStr: indexStr }
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
//显示已聊天的最后一条
|
||
|
indexStr = recordData[recordData.length - 1].indexStr
|
||
|
for (let k = personJson.length - 1; k >= 0; k--) {
|
||
|
if (personJson[k].indexStr == indexStr) {
|
||
|
flagNode.active = false
|
||
|
return { contentDesc: personJson[k].contentDesc, indexStr: indexStr }
|
||
|
}
|
||
|
}
|
||
|
|
||
|
PrefabManage.showTextTips('这里没获取到内容?' + jsonName)
|
||
|
flagNode.active = false
|
||
|
return { contentDesc: "", indexStr: "" }
|
||
|
}
|
||
|
}
|