import GameModel from "../../ts/core/GameModel"; import VIPUtil from "../../ts/game/role/VIPUtil"; import SKUIUtil from "../../ts/gear_2.3.4/util/SKUIUtil"; import MsgAlert from "../../ts/game/msg/MsgAlert"; import RoleMenuAlert from "../../ts/RoleMenuAlert" let GoodsMgr = require('../../game/GoodsMgr'); let CPubFunction = require('../../game/PubFunction'); let zhufuyu = '大哥大嫂新年好! '; cc.Class({ extends: cc.Component, properties: { chatItemOther: cc.Prefab, chatItemSelf: cc.Prefab, contentNode: cc.Node, editbox: cc.EditBox, bgNode: cc.Node, progressNode: cc.Node, joinBangNode: cc.Node, lingdangNode: cc.Node, inputNode: cc.Node, preBang: cc.Prefab, emojiContent: cc.Node, emojiAtlas: cc.SpriteAtlas, joinTeamBg: cc.SpriteFrame, fontRes: cc.Font, GmUI: cc.Prefab, btnGmButton: cc.Prefab, autoPlayToggle: cc.Toggle, voiceBtn: cc.Node, chatView: cc.Node, }, onLoad() { // this.node.on(cc.Node.EventType.TOUCH_START, this.touchBegan.bind(this)); this.teamItemList = []; this.campItemList = []; this.worldItemList = []; this.sysItemList = []; this.meItemList = []; this.maxItems = 50; this.curItemList = this.worldItemList; this.curChatScale = 0; this.chatItemNodes = []; this.bgOpacity = 255; this.isTransparent = false; this.opacityProgress = this.progressNode.getComponent(cc.ProgressBar); this.autoPlayToggle.isChecked = GameModel.autoWorldVoice == 1; this.name = 'ChatPanel'; this.vecGmBtn = []; this.mSendStr = ""; this.mSendIds = []; }, start() { this.mSendIds = []; let mainUILogic = cc.find('Canvas/MainUI').getComponent('MainUI'); if (mainUILogic) { this.voiceBtn.on(cc.Node.EventType.TOUCH_START, mainUILogic.onWorldVoiceRecord.bind(this)); this.voiceBtn.on(cc.Node.EventType.TOUCH_CANCEL, mainUILogic.onWorldVoiceRecord.bind(this)); this.voiceBtn.on(cc.Node.EventType.TOUCH_END, mainUILogic.onWorldVoiceRecord.bind(this)); } this.chatView.getComponent("ChatView").setCallback(this.onInputCallback.bind(this)); }, onBiaoqingItemClicked(e, d) { this.editbox.string += `[${d}]`; }, onEditBoxEnded() { }, onEditBoxChang() { // if(this.editbox.string.length < 15){ // this.editbox.textLabel.horizontalAlign = cc.Label.HorizontalAlign.LEFT; // }else{ // this.editbox.textLabel.horizontalAlign = cc.Label.HorizontalAlign.RIGHT; // } }, onInputCallback(data) { if (!this.checkInput()) { return; } this.mType = data.type; if (data.type == 0) { // 表情 // this.mSendStr += ("#"+data.index) this.mSendStr += ("[" + data.index + "]") this.editbox.string += `#${data.index}`; } else { // 道具 let link = '[' + data.name + '@' + data.id + '@' + data.type + ']' this.mSendStr += link; this.editbox.string += `[${data.name}]`; // let info = {}; // info.id = data.id+'@123'; // info.name = data.name; // info.poss = []; this.mSendIds.push(link); } this.onEditBoxChang(); }, checkInput() { if (this.mSendIds.length >= 5) { MsgAlert.addMsg("最多發送5個鏈接"); return false; } return true; }, hideEmoji() { if (this.isEmojiShow) { this.isEmojiShow = false; this.node.stopAllActions(); this.node.runAction(cc.moveTo(0.1, cc.v2(this.node.x, 0))); } }, editingDidBegan(e, d) { this.hideEmoji(); }, loadListInfo(list) { for (const info of list) { if (info.scale == 0) { this.worldItemList.push(info); } else if (info.scale == 1) { this.teamItemList.push(info); } else if (info.scale == 2) { this.campItemList.push(info); } else if (info.scale == 3) { this.sysItemList.push(info); } // else if (info.scale == 7) { // this.meItemList.push(info); // } } this.showListInfo(); }, addListInfo(info) { // cc.log(info); // 0世界,1隊伍,2幫派,3系統,5系統撤回,6快訊 if (info.scale == 0) { this.worldItemList.push(info); } else if (info.scale == 1) { this.teamItemList.push(info); } else if (info.scale == 2) { this.campItemList.push(info); } else if (info.scale == 3) { this.sysItemList.push(info); } // else if (info.scale == 7) { // this.meItemList.push(info); // } if (info.scale == 5) { for (let i = 0; i < this.worldItemList.length; i++) { const chatinfo = this.worldItemList[i]; if (chatinfo.roleid == info.roleid) { chatinfo.msg = zhufuyu; } } for (let i = 0; i < this.campItemList.length; i++) { const chatinfo = this.campItemList[i]; if (chatinfo.roleid == info.roleid) { chatinfo.msg = zhufuyu; } } for (let i = 0; i < this.teamItemList.length; i++) { const chatinfo = this.teamItemList[i]; if (chatinfo.roleid == info.roleid) { chatinfo.msg = zhufuyu; } } this.fixChatItemNode(info.roleid); return; } if (this.curChatScale == info.scale) { this.addChatItem(info); } if (this.curItemList.length > this.maxItems) { this.delFirstChatItem(); } if (this.worldItemList.length > this.maxItems) { this.worldItemList.shift(); } if (this.teamItemList.length > this.maxItems) { this.teamItemList.shift(); } if (this.campItemList.length > this.maxItems) { this.campItemList.shift(); } if (this.sysItemList.length > this.maxItems) { this.sysItemList.shift(); } if (this.meItemList.length > this.maxItems) { this.meItemList.shift(); } }, tipNo() { MsgAlert.addMsg("暫未開放") }, showListInfo() { this.inputNode.active = true; this.joinBangNode.active = false; this.lingdangNode.active = false; this.contentNode.destroyAllChildren(); this.chatItemNodes = []; this.contentNode.height = this.contentNode.parent.height; // for (const info of this.curItemList) { // this.addChatItem(info); // } if (this.curItemList.length > 0) { // 是否反向添加 var reverse = this.curItemList.length > 6 ? true : false if (reverse) { // 反向 let index = this.curItemList.length - 1; this.schedule(() => { this.addChatItem(this.curItemList[index], reverse, index == 0); index--; }, 0.01, this.curItemList.length); } else { let index = 0; this.schedule(() => { this.addChatItem(this.curItemList[index], reverse); index++; }, 0.01, this.curItemList.length); } } }, delFirstChatItem() { let delItem = this.chatItemNodes.shift(); if (delItem) { this.contentNode.height -= delItem.height; for (const item of this.chatItemNodes) { item.y += delItem.height; } delItem.destroy(); } }, addChatItem(info, reverse = false, first = false) { if (info == null) { return; } let chatItem = null; let vipLevel = VIPUtil.getVipLevel(info.chargesum); if (this.curChatScale == 3) { chatItem = new cc.Node(); chatItem.parent = this.contentNode; let richText = chatItem.addComponent('CustomRichText'); richText.maxWidth = this.contentNode.width - 6; richText.fontSize = 18; richText.font = this.fontRes; richText.lineHeight = 20; richText.type = 1; richText.vipLevel = vipLevel; richText.rolename = info.name; richText.scale = info.scale; richText.emojiAtlas = this.emojiAtlas; richText.string = info.msg; chatItem.x = -this.contentNode.width / 2 + 3; chatItem.color = cc.color(200, 0, 0, 255); } else { if (info.roleid == GameModel.player.roleid) { chatItem = cc.instantiate(this.chatItemSelf); } else { chatItem = cc.instantiate(this.chatItemOther); cc.find('HeadSprite', chatItem).getComponent(cc.Button).clickEvents.push(CPubFunction .CreateEventHandler(this.node, "ChatPanel", "OnClickSpeaker", info)); } chatItem.parent = this.contentNode; chatItem.getComponent('ChatItem').loadInfo(info); chatItem.x = 0; chatItem.roleid = info.roleid; chatItem.voiceid = info.voice; } //聊天記錄從上面添加 if (!reverse) { // 正向 chatItem.y = 0; if (this.chatItemNodes.length > 0) { let preItem = this.chatItemNodes[this.chatItemNodes.length - 1]; chatItem.y = preItem.y - preItem.height; } if (chatItem.y - chatItem.height < -this.contentNode.height) { this.contentNode.height = chatItem.height - chatItem.y; } this.chatItemNodes.push(chatItem); if (this.contentNode.y > this.contentNode.height - this.contentNode.parent.height - chatItem .height - 20) { this.contentNode.y = this.contentNode.height - this.contentNode.parent.height; } } else { // 反向 if (this.chatItemNodes[0]) { // 不是倒數第一個 chatItem.y = this.chatItemNodes[0].y + chatItem.height; } else { // 是倒數第一個 chatItem.y = -this.contentNode.height + chatItem.height; } this.chatItemNodes.unshift(chatItem); if (this.contentNode.y > this.contentNode.height - this.contentNode.parent.height - chatItem .height - 20) { this.contentNode.y = this.contentNode.height - this.contentNode.parent.height; } if (first) { // console.log(this.chatItemNodes) if (this.chatItemNodes[0].y != 0) { var offY = this.chatItemNodes[0].y - 0 for (const item of this.chatItemNodes) { item.y -= offY; } this.contentNode.height = -this.chatItemNodes[this.chatItemNodes.length - 1].y + this .chatItemNodes[this.chatItemNodes.length - 1].height; this.contentNode.height = this.contentNode.height < this.contentNode.parent.height ? this .contentNode.parent.height : this.contentNode.height; if (this.contentNode.height > this.contentNode.parent.height) { this.contentNode.y = this.contentNode.height - this.contentNode.parent.height; } } } } /** * 聊天記錄從下面開始顯示,不要刪 */ // let blankHeight = this.contentNode.height; // if (this.chatItemNodes[0]) { // blankHeight = -this.chatItemNodes[0].y; // } // if (chatItem.height > blankHeight) { // this.contentNode.height += chatItem.height - blankHeight; // for (const item of this.chatItemNodes) { // item.y += blankHeight; // } // } // else { // for (const item of this.chatItemNodes) { // item.y += chatItem.height; // } // } // chatItem.y = -this.contentNode.height + chatItem.height // this.chatItemNodes.push(chatItem); // if (this.contentNode.y > this.contentNode.height - this.contentNode.parent.height - chatItem.height - 20) { // this.contentNode.y = this.contentNode.height - this.contentNode.parent.height; // } }, fixChatItemNode(roleid) { for (const chatitem of this.chatItemNodes) { if (chatitem.roleid == roleid) { chatitem.getComponent('ChatItem').setMsg(zhufuyu); } } }, OnClickSpeaker(e, info) { //console.log(info) RoleMenuAlert.show(info, true) return; SKUIUtil.destroyList(this.vecGmBtn); let goGmUI = CPubFunction.CreateSubNode(this.node, { nX: 0, nY: 0 }, this.GmUI, 'GmUI'); let goContent = cc.find('ScrollView/view/content', goGmUI); cc.find('btnClose', goGmUI).getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler( this.node, "ChatPanel", 'CloseGmUI', info)); cc.find('nodPlayerInfo/picPlayerAvater', goGmUI).getComponent(cc.Sprite).spriteFrame = GameModel .getRoleHead(info.resid); cc.find('nodPlayerInfo/labID', goGmUI).getComponent(cc.Label).string = info.roleid; cc.find('nodPlayerInfo/labName', goGmUI).getComponent(cc.Label).string = info.name; let menu = [{ name: '加入隊伍', fun: 'ApplyJoint' }, { name: '邀請入隊', fun: 'InviteTeam' }, { name: '添加好友', fun: 'AddFriend' }, { name: '禁言', fun: 'ShutUp' }, { name: '封號', fun: 'KickOff' }, { name: '封IP', fun: 'FreezeIP' }, { name: '封設備', fun: 'FreezeMAC' }]; let myPlayer = GameModel.player; for (let key in menu) { if (myPlayer.gmlevel < 1 && menu[key].name == '禁言') continue; if (myPlayer.gmlevel < 1 && menu[key].name == '封號') continue; if (myPlayer.gmlevel < 15 && menu[key].name == '封IP') continue; if (myPlayer.gmlevel < 30 && menu[key].name == '封設備') continue; // 自已有隊,對方有隊不能加入隊伍 if (myPlayer.teamid != 0 && info.teamid == 0 && menu[key].name == '加入隊伍') { continue; } if ((myPlayer.teamid == 0 && info.teamid != 0) && menu[key].name == '邀請入隊') { continue; } let btnGmButton = CPubFunction.CreateSubNode(goContent, { nX: 0, nY: 0 - this.vecGmBtn.length * 55 }, this.btnGmButton, 'btnGmButton'); cc.find('Label', btnGmButton).getComponent(cc.Label).string = menu[key].name; btnGmButton.getComponent(cc.Button).clickEvents.push(CPubFunction.CreateEventHandler(this.node, "ChatPanel", menu[key].fun, info)); this.vecGmBtn.push(btnGmButton); } goContent.height = Math.max(goContent.height, this.vecGmBtn.length * 60 + 10); }, //zfy 請求 紅包列表 onworldBtnClick() { // //打開UI GameModel.send('c2s_world_reward_list'); this.hideEmoji(); }, CloseGmUI(e, d) { CPubFunction.FindAndDeleteNode(this.node, 'GmUI'); }, ShutUp(e, info) { GameModel.send('c2s_player_shutup', { nRoleID: info.roleid }); this.CloseGmUI(0, 0); }, KickOff(e, info) { GameModel.send('c2s_kick_off', { nRoleID: info.roleid }); this.CloseGmUI(0, 0); }, FreezeIP(e, info) { GameModel.send('c2s_freeze_ip', { nRoleID: info.roleid }); this.CloseGmUI(0, 0); }, FreezeMAC(e, info) { GameModel.send('c2s_freeze_mac', { nRoleID: info.roleid }); this.CloseGmUI(0, 0); }, ApplyJoint(e, info) { GameModel.send('c2s_requst_team', { roleid: GameModel.player.roleid, teamid: info.teamid }); this.CloseGmUI(0, 0); }, InviteTeam(e, info) { GameModel.send('c2s_team_invite', { toroleid: info.roleid, }); this.CloseGmUI(0, 0); }, AddFriend(e, info) { GameModel.send('c2s_add_friend', { roleid: info.roleid }); this.CloseGmUI(0, 0); }, onToggleClicked(e, param) { this.contentNode.parent.height = 500; this.autoPlayToggle.node.active = false; if (param == 'team') { this.curChatScale = 1; this.curItemList = this.teamItemList; this.showListInfo(); } else if (param == 'world') { this.curChatScale = 0; this.curItemList = this.worldItemList; this.showListInfo(); this.autoPlayToggle.node.active = true; this.lingdangNode.active = true; } else if (param == 'camp') { this.curChatScale = 2; this.curItemList = this.campItemList; this.showListInfo(); if (GameModel.player.bangid == 0) { this.joinBangNode.active = true; this.inputNode.active = false; return; } } else if (param == 'system') { this.curChatScale = 3; this.curItemList = this.sysItemList; this.contentNode.parent.height = 560; this.showListInfo(); this.inputNode.active = false; } // else if (param == 'self') { // this.curChatScale = 7; // this.curItemList = this.meItemList; // this.contentNode.parent.height = 560; // this.showListInfo(); // this.inputNode.active = false; // } else { this.curChatScale = -1; this.curItemList = []; this.showListInfo(); this.inputNode.active = false; } }, onButtonClick(event, param) { if (param == 'close') { this.node.destroy(); } else if (param == 'emoji') { if (!this.isEmojiShow) { this.isEmojiShow = true; this.node.stopAllActions(); this.node.runAction(cc.moveTo(0.1, cc.v2(this.node.x, 250))); } } else if (param == 'send') { if (this.editbox.string.length == 0) { return; } let str = this.editbox.string; // if (str.substr(0, 1) == ':') { // if (str.substr(1, 1) == '+') { // GoodsMgr.addItem(str.substr(2)); // } else { // GoodsMgr.subItem(str.substr(2)); // } // } this.hideEmoji(); let msg = this.editbox.string; if (msg[0] == '/') { let str = msg.substr(1, msg.length); let command = str.split(','); GameModel.send('gm_command', { commands: command }); this.node.destroy(); return; } // let flitlist = GameDefine.limitWordList; // for (let i = 0; i < flitlist.length; i++) { // const fword = flitlist[i]; // if (msg.indexOf(fword) != -1) { // msg = msg.replace(new RegExp(fword, 'g'), '*'); // } // } let msgstr = this.editbox.string; let patt1 = /\[[^(@)]*?\]/; let pos1 = msgstr.search(patt1); while (pos1 != -1) { let matchstr = msgstr.match(patt1); msgstr = msgstr.replace(matchstr[0], this.mSendIds.shift()); pos1 = msgstr.search(patt1); } // cc.log(msgstr); let patt = /(? 0) { bang.getComponent('BangPanel').showBangLayer(); } else { bang.getComponent('BangPanel').showAddlayer(); } this.node.destroy(); } }, update() { if (this.isTransparent && this.bgNode.opacity > 155) { this.bgNode.opacity -= 5; if (this.bgNode.opacity <= 155) { this.bgNode.opacity = 155; cc.find('handleNode/handle', this.progressNode).active = true; } this.opacityProgress.progress = (255 - this.bgNode.opacity) / 100; cc.find('handleNode', this.progressNode).y = 3 + 0.9 * this.progressNode.height * this .opacityProgress.progress; } else if (!this.isTransparent && this.bgNode.opacity < 255) { this.bgNode.opacity += 5; if (this.bgNode.opacity >= 255) { this.bgNode.opacity = 255; } this.opacityProgress.progress = (255 - this.bgNode.opacity) / 100; cc.find('handleNode', this.progressNode).y = 3 + 0.9 * this.progressNode.height * this .opacityProgress.progress; } }, touchBegan(event) { // this.hideEmoji(); }, onAutoPlayWorldToggle(e, d) { GameModel.autoWorldVoice = this.autoPlayToggle.isChecked ? 1 : 0; cc.sys.localStorage.setItem('auto_play_world', GameModel.autoWorldVoice); }, changeVoicePlayedId(id) { for (const chatitem of this.chatItemNodes) { if (chatitem.voiceid == id) { chatitem.getComponent('ChatItem').playVoiceAct(); break; } } } });