local EventSystem = require('Event/EventSystem') local UIBattleChatDlg = UIViewClass() local START_SHOW_TIME = 1 local SCROLLING_SPEED = DataSheetManager.ConstData:GetDataByID("BroadCastSpeedHigh").IntValue --运行速度 -- context = { -- onlyChat = false, -- 是否仅仅显示聊天(隐藏好友、语音等功能) -- } function UIBattleChatDlg:OnOpened(context) UIUtils.SetEmojiTextEmojiRatio(self.MarqueeMassage, 1.2) self.QuickMsgCellTable = nil self.QuickMsgCellTableIndex = -1 --注册Update self:RegistSystemEvent(EventID.UI_ChannelChat_OnChatViewClose,self.OnChatViewClose) self:RegistSystemEvent(EventID.UI_ChannelChat_OnReceiveNewMsg,self.OnReceiveNewMsg) self:RegistSystemEvent(EventID.UI_UpdateBlack, self.RefreshChatView) self:RegistSystemEvent(EventID.UI_UpdateChatRed, self.OnRefreshFriendRed) self:RegistSystemEvent(EventID.FunctionUnlockUpdate, self.UpdateInfoReminderEntry) self:RegistSystemEvent(EventID.UI_Open_Chat_By_External, self.OnClickOpenChatByExternal) self:RegistSystemEvent(EventID.UIBattle_OnDeadChatDlgViewTop, self.OnDeadChatViewTop) self:RegistSystemEvent(EventID.UIBattle_OnFriendBaseClose, self.OnFriendBaseClose) self.isOpen = true UIUtils.SetActive(self.Condition_Msg, false) UIUtils.SetActive(self.img_Channel, false) MDL.ChannelChat.SetGlobalChatDlgIsOpen(true) self:InitChatMarquee() self:RefreshChatView() UIUtils.SetActive(self.btn_QuickMsg, MDL.ChannelChat.IsDisplayCurrentChatChannel()) local isFriendUnlock = MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Friend) if isFriendUnlock then UIUtils.SetActive(self.btn_Friend, not self:OnlyShowChat()) else --有isFriendUnlock 为nil的情况 UIUtils.SetActive(self.btn_Friend, false) end self:OnRefreshFriendRed() -- 战斗内 聊天界面的快捷短语按钮隐藏 UIUtils.SetActive(self.btn_QuickMsg, false) local isHideReminder = self.context and self.context.isHideReminder or false if not self:OnlyShowChat() and isHideReminder == false then self.infoReminderCanvas:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIInfoReminderTipsView)) end self:UpdateInfoReminderEntry() self:InitCurVoiceChannel() self:InitEmojiChat() end function UIBattleChatDlg:InitEmojiChat() local curLevelType = BattleDataGetter.GetCurLevelType() local curLevelInfo = DataSheetManager.LevelFeatureData:GetDataByLevelFeatureID(curLevelType) if curLevelInfo.ShowShortcutTalkBtn then self.msgContextList = {} for i, v in ipairs(self.group_Emoji) do self:RegistTriggerEvent(v.img_Drag, UIEventTriggerType.Drag) UIUtils.SetActive(v.Img_Selected, false) UIUtils.SetActive(v.img_Drag, true) local data = DataSheetManager.ShortcutTalk:GetDataByID(i) UIUtils.SetLabelText(v.txt_Emoji, Const_IDS[data.ShortcutTalkName]) local emojiText = string.format("[%s]", data.Emoji) v.img_EmojiTxt.text = emojiText self.msgContextList[i] = UIUtils.GetLocalizedTxt(Const_IDS[data.ShortcutTalkDes]) .. emojiText end UIUtils.SetActive(self.group_ChatEmoji, false) self:RegistTriggerEvent(self.btn_Chat, UIEventTriggerType.PointerUp) self:RegistTriggerEvent(self.btn_Chat, UIEventTriggerType.PointerDown) self:RegistTriggerEvent(self.btn_Chat, UIEventTriggerType.Drag) self:RegistTriggerEvent(self.btn_Chat, UIEventTriggerType.EndDrag) UIUtils.SetActive(self.btn_Chat, true) else UIUtils.SetActive(self.btn_Chat, false) UIUtils.SetActive(self.group_ChatEmoji, false) end end function UIBattleChatDlg:OnDrag(comp, eventData) local isDrag = false for i, v in ipairs(self.group_Emoji) do if v.img_Drag.gameObject == eventData.pointerEnter.gameObject then UIUtils.SetActive(v.Img_Selected, true) isDrag = true self.curSelectEmoji = i else UIUtils.SetActive(v.Img_Selected, false) end end if not isDrag then self.curSelectEmoji = nil end end function UIBattleChatDlg:OnEndDrag(comp, eventData) if self.curSelectEmoji then self:SendEmojiChat(self.curSelectEmoji) end end function UIBattleChatDlg:SendEmojiChat(index) self:SendMsg(self.msgContextList[self.curSelectEmoji]) end function UIBattleChatDlg:InitChatMarquee() --展示框宽度 self.bgLength = self.group_Txt:GetSizeDelta() self.Y = self.MarqueeMassage.transform.anchoredPosition.y self.timeCount = 0 end function UIBattleChatDlg:OnClickOpenChatByExternal() if UIManager.IsFocus(Const_UI_Lua.UIEnum.UIBattleChatDlg) or CTL.ChannelChat.SelfIsDead() then if not UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIChannelChatMain) then self:OnClickOpenChat() end end end function UIBattleChatDlg:OnClosed() CTL.ChannelChat.CancelRecordVoice() end function UIBattleChatDlg:OnRefreshFriendRed() local num = MDL.Friend.GetUnreadMsgNumByType(MDL.Friend.ListType.Recent) + CTL.SpecialTeam.GetSumGroupChatRedCount() + CTL.SpecialTeam.GetNoticeGroupChatRed() if num > 0 then UIUtils.SetActive(self.img_NumBg, true) self.txt_MessageNum.text = num else UIUtils.SetActive(self.img_NumBg, false) end end function UIBattleChatDlg:UpdateInfoReminderEntry() UIUtils.SetActive(self.btn_Msg, MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.InfoReminder)) end function UIBattleChatDlg:OnClickOpenChat() self.gameObject:SetActive(false) self.isOpen = false UIUtils.SetActive(self.Condition_Msg, false) EventSystem.Dispatch(EventID.UI_Auto_Fight, false) -- 通知显隐自动战斗提示 UIManager.OpenView(Const_UI_Lua.UIEnum.UIChannelChatMain, {LastMsgChannelId = nil}) end function UIBattleChatDlg:RefreshChatView() local msgList = MDL.ChannelChat.GetDlgMsgList() if msgList and #msgList > 0 then for i = #msgList, 1, -1 do if not MDL.ChannelChat.IsMsgFromBlack(msgList[i]) then self.msgData = msgList[i] break end end end if self.lab_Empty then local inRegion = GameAppInfo.IsJapanesePackage() or GameAppInfo.IsOverseaPackage() if inRegion and not self.msgData then UIUtils.SetActive(self.lab_Empty, true) UIUtils.SetLabelText(self.lab_Empty, Const_IDS["IDS_Chat_Blank"]) else UIUtils.SetActive(self.lab_Empty, false) end end self:RefreshChatMarquee() end function UIBattleChatDlg:OnChatViewClose() self.gameObject:SetActive(true) self.isOpen = true self:RefreshChatView() EventSystem.Dispatch(EventID.UI_Auto_Fight, true) -- 通知显隐自动战斗提示 end function UIBattleChatDlg:OnReceiveNewMsg(msg) if MDL.ChannelChat.IsCurrentChannelByChannelId(msg.ChannelId) then if not MDL.ChannelChat.IsDisplayCurrentChatChannel() then return end end --黑名单屏蔽 if MDL.ChannelChat.IsMsgFromBlack(msg) then return end if self.isOpen then UIUtils.SetActive(self.lab_Empty, false) self.msgData = msg self:RefreshChatMarquee() end end function UIBattleChatDlg:RefreshChatMarquee() if not self.msgData then return end local content if MDL.ChannelChat.IsZhaoMuChannelByCfgId(self.msgData.ChatCfgId) or MDL.ChannelChat.IsSystemChannelByCfgId(self.msgData.ChatCfgId) then content = self.msgData.content else if not string.isNilOrEmpty(self.msgData.senderName) then if self.msgData.isVoice then content = self.msgData.senderName .. "[j]" .. self.msgData.content else content = self.msgData.senderName .. ":" .. self.msgData.content end else content = self.msgData.content end end self.MarqueeMassage.text = content UIUtils.SetActive(self.img_Channel, true) CTL.ChannelChat.SetChannelBgColor(self.msgData.ChatCfgId, self.img_Channel, self.txt, self.msgData.serId, not string.isNilOrEmpty(self.msgData.senderName)) self:ResetChatMarquee() self:StopRepeatFunc(self.OnUpdateFun) -- 如果大于长度开始循环运动 if self.MarqueeMassage.preferredWidth > self.bgLength then self.EndPosX = self.bgLength - self.MarqueeMassage.preferredWidth self.moveSecond = math.abs(self.EndPosX) / SCROLLING_SPEED self:StartRepeatFunc(self.OnUpdateFun, 1) end end function UIBattleChatDlg:OnUpdateFun() self.timeCount = self.timeCount + 1 if self.timeCount >= START_SHOW_TIME and not self.moveAnim then self.moveAnim = self:MoveToPos(self.MarqueeMassage.transform, self.EndPosX, self.Y, self.moveSecond, true) end if self.timeCount >= self.moveSecond + START_SHOW_TIME then self:ResetChatMarquee() end end function UIBattleChatDlg:ResetChatMarquee() self.MarqueeMassage.transform:SetAnchoredPosition(0, self.Y) self.timeCount = 0 if self.moveAnim then self:StopUIAnimation(self.moveAnim, true) self.moveAnim = nil end end function UIBattleChatDlg:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.QuickMsgScroll then cellTable.objQuickMsg_InputField.characterLimit = DataSheetManager.ConstData:GetDataByID("ChatConvenientLimit").IntValue local tmpValue = MDL.ChannelChat.GetQuickMsgByIndex(index + 1) cellTable.txt_01.text = tmpValue if cellTable.txt_01.preferredWidth >= 500 then local length = string.len(tmpValue) while (length > 0) do length = length - 1 local subValue = string.sub(tmpValue, 1, length) cellTable.txt_01.text = subValue if cellTable.txt_01.preferredWidth <= 490 then cellTable.txt_01.text = cellTable.txt_01.text .. "..." return end end end elseif scrollRect == self.loop_Channel then UIUtils.SetLabelText(cellTable.txt_Channel,Const_IDS[data.AudioChatName]) end end --以下为按钮点击事件 function UIBattleChatDlg:OnButtonClicked(obj) if(obj==self.event_OpenChat) then self:OnClickOpenChat() elseif obj == self.btn_QuickMsg then self:LoadQuickMsg() elseif obj == self.btn_Friend then CTL.Friend.OpenFriendPanel(CTL.Friend.MainIndex.Main) self:OnClickOpenFriend() elseif obj == self.mask_Talk then self:CloseChannelSetting() end end function UIBattleChatDlg:LoadQuickMsg() --频道是否开启,现在的版本快捷频道只是发送到当前频道,后面有其他功能根据相应功能选择频道是否开启 local isOpen, unlockMsg = MDL.ChannelChat.IsChannelOpen(MDL.ChannelChat.ChannelCfgId.Current) if not isOpen then CTL.Tips.AddTipsMsg(unlockMsg) return end if self.Condition_Msg.gameObject.activeSelf then UIUtils.SetActive(self.Condition_Msg, false) return else UIUtils.SetActive(self.Condition_Msg, true) end local quickDatas = MDL.ChannelChat.GetQuickMsgData() self.QuickMsgScroll:ReloadAll(quickDatas) end function UIBattleChatDlg:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.QuickMsgScroll then if self.QuickMsgCellTable ~= nil and self.QuickMsgCellTable ~= cellTable then self:OnDeselect(nil, nil) end if target.transform.name == "event_01" then UIUtils.SetActive(self.Condition_Msg, false) self:SendMsg(MDL.ChannelChat.GetQuickMsgByIndex(index + 1)) elseif target.transform.name == "btn_Change01" then if self.QuickMsgCellTable == cellTable then self:OnDeselect(nil, nil) return end self.QuickMsgCellTableIndex = index self.QuickMsgCellTable = cellTable UIUtils.SetActive(self.QuickMsgCellTable.event_Mask, true) UIUtils.SetActive(cellTable.objQuickMsg_InputField, true) cellTable.objQuickMsg_InputField.text = MDL.ChannelChat.GetQuickMsgByIndex(index + 1) cellTable.objQuickMsg_InputField:ActivateInputField() self:RegistTriggerEvent(self.QuickMsgCellTable.objQuickMsg_InputField, UIEventTriggerType.Deselect) UIUtils.SetActive(cellTable.event_01, false) elseif target.transform.name == "event_Mask" then self:OnDeselect(nil, nil) end elseif scrollRect == self.loop_Channel then self:SetCurVoiceChannel(data.ID) self:CloseChannelSetting() else self:OnClickOpenChat() end end function UIBattleChatDlg:OnDeselect(comp, eventData) if self.QuickMsgCellTable ~= nil then local newContent = self.QuickMsgCellTable.objQuickMsg_InputField.text self.QuickMsgCellTable.txt_01.text = newContent UIUtils.SetActive(self.QuickMsgCellTable.objQuickMsg_InputField, false) self:UnregistTriggerEvent(self.QuickMsgCellTable.objQuickMsg_InputField) UIUtils.SetActive(self.QuickMsgCellTable.event_01, true) UIUtils.SetActive(self.QuickMsgCellTable.event_Mask, false) MDL.ChannelChat.SaveQuickMsg(self.QuickMsgCellTableIndex + 1, newContent) local tmpValue = newContent self.QuickMsgCellTable.txt_01.text = tmpValue if self.QuickMsgCellTable.txt_01.preferredWidth >= 500 then local length = string.len(tmpValue) while (length > 0) do length = length - 1 local subValue = string.sub(tmpValue, 1, length) self.QuickMsgCellTable.txt_01.text = subValue if self.QuickMsgCellTable.txt_01.preferredWidth <= 490 then self.QuickMsgCellTable.txt_01.text = self.QuickMsgCellTable.txt_01.text .. "..." self.QuickMsgCellTableIndex = -1 self.QuickMsgCellTable = nil return end end else self.QuickMsgCellTableIndex = -1 self.QuickMsgCellTable = nil end end end function UIBattleChatDlg:SendMsg(content) if MDL.ChannelChat.CanSendMsg() then local msg = content local CurChannelID = MDL.ChannelChat.GetChannelIdByCfgID(MDL.ChannelChat.ChannelCfgId.Current) if not CTL.ChannelChat.IsOutOfLength(msg, CurChannelID) then CTL.ChannelChat.SendTextMsg(msg, CurChannelID) end else CTL.Tips.AddTipsMsg(MDL.ChannelChat.GetForbiddenMsg()) end end function UIBattleChatDlg:RefreshInviteButtonRedPoint(isAdd) local length = #MDL.Team.GetInviteList() length = isAdd and length or length - 1 return length > 0 end function UIBattleChatDlg:RefreshApplyButtonRedPoint(isAdd) local length = #MDL.Team.GetApplyTeamList() length = isAdd and length or length - 1 return length > 0 end function UIBattleChatDlg:OnClickTeamBubble() if CTL.Team.IsSelfLeader() then UIManager.OpenView(Const_UI_Lua.UIEnum.UITeamApplyPanel) else UIManager.OpenView(Const_UI_Lua.UIEnum.UITeamInvitedPanel) end end function UIBattleChatDlg:InitCurVoiceChannel() self.channelSettingActive = false UIUtils.SetActive(self.mask_Talk, false) local voiceChannelList = CTL.ChannelChat.GetEnableVoiceChannelList() if #voiceChannelList > 0 and CTL.ChannelChat.IsEnableVoiceChat() then UIUtils.SetActive(self.btn_Mic, not self:OnlyShowChat()) local curVoiceChannelCfgID = MDL.ChannelChat.GetCurAudioChannelCfgId() or CTL.ChannelChat.GetDefaultSelectChannel() --当前频道可能是默认频道,不一定解锁,需要判断是否允许语音 local isAllow = false for _, v in ipairs(voiceChannelList) do if v.ID == curVoiceChannelCfgID then isAllow = true break end end if isAllow == false then curVoiceChannelCfgID = voiceChannelList[1].ID end self:SetCurVoiceChannel(curVoiceChannelCfgID) else UIUtils.SetActive(self.btn_Mic, false) end self:RegistTriggerEvent(self.btn_Mic, UIEventTriggerType.PointerExit) self:RegistTriggerEvent(self.btn_Mic, UIEventTriggerType.PointerDown) self:RegistTriggerEvent(self.btn_Mic, UIEventTriggerType.PointerUp) self:RegistTriggerEvent(self.btn_Mic, UIEventTriggerType.PointerEnter) self:RegistSystemEvent(EventID.UI_ChannelChat_OnRecordStartResult, self.OnStartRecordVoiceResult) self:RegistSystemEvent(EventID.UI_ChannelChat_OnRecordTimeEnd, self.OnRecordTimeEnd) self:RegistSystemEvent(EventID.UI_ChannelChat_OnSelectChannelChanged, self.SetCurVoiceChannel) end function UIBattleChatDlg:SetCurVoiceChannel(channelCfgID) if MDL.ChannelChat.IsChannelOpen(channelCfgID) == false then return end if CTL.ChannelChat.IsChannelEnableAudio(channelCfgID) == false then return end self.curVoiceChannelCfgID = channelCfgID local channelCfgData = DataSheetManager.Chat:GetDataByID(channelCfgID) UIUtils.SetLabelText(self.txt_Channel,Const_IDS[channelCfgData.AudioChatName]) MDL.ChannelChat.SetCurAudioChannelCfgId(channelCfgID) end function UIBattleChatDlg:OnRecordTimeEnd() UIUtils.SetActive(self.mask_Talk, false) self.isRecordTimeEnd = true end function UIBattleChatDlg:OnPointerDown(comp, eventData) if comp == self.btn_Mic then --按住时间小于1s,弹出设置scroll;大于1s,录制声音 self:StartRepeatFunc(self.OnPointerPress, 0.5, 1) self.pressTimestamp = UTL.Time.GetServerTimestamp() self.isRecordTimeEnd = false elseif comp == self.btn_Chat then UIUtils.SetActive(self.group_ChatEmoji, true) for i, v in ipairs(self.group_Emoji) do UIUtils.SetActive(v.Img_Selected, false) end end end function UIBattleChatDlg:OnPointerExit(comp, eventData) if comp == self.btn_Mic then self.isExitAudioPointer = true if self.isRecordTimeEnd == false then EventSystem.Dispatch(EventID.UI_ChannelChat_OnExitPress) end end end function UIBattleChatDlg:OnPointerEnter(comp, eventData) if comp == self.btn_Mic then self.isExitAudioPointer = false if self.isRecordTimeEnd == false then EventSystem.Dispatch(EventID.UI_ChannelChat_OnEnterPress) end end end function UIBattleChatDlg:OnPointerUp(comp, eventData) if comp == self.btn_Mic then self:StopRepeatFunc(self.OnPointerPress) if UTL.Time.GetServerTimestamp() - self.pressTimestamp < 0.5 then if self.channelSettingActive == false then self:OpenChannelSetting() CTL.Sound.PlayGameSound("UI_expand") else self:CloseChannelSetting() CTL.Sound.PlayGameSound("UI_fold") end else UIUtils.SetActive(self.mask_Talk, false) if self.isRecordTimeEnd == false then if self.isExitAudioPointer then CTL.ChannelChat.CancelRecordVoice() else CTL.ChannelChat.StopRecordVoice() end end end elseif comp == self.btn_Chat then UIUtils.SetActive(self.group_ChatEmoji, false) end end function UIBattleChatDlg:OnPointerPress() CTL.ChannelChat.StartRecordVoice(MDL.ChannelChat.GetChannelIdByCfgID(self.curVoiceChannelCfgID), false) end function UIBattleChatDlg:OnStartRecordVoiceResult(result) if result == "true" then UIUtils.SetActive(self.mask_Talk, true) end end function UIBattleChatDlg:OpenChannelSetting() local channelList = CTL.ChannelChat.GetEnableVoiceChannelList(self.curVoiceChannelCfgID) if #channelList <= 0 then return end self.channelSettingActive = true UIUtils.SetActive(self.group_Channel, true) UIUtils.SetActive(self.mask_Talk, true) self.loop_Channel:ReloadAll(channelList) end function UIBattleChatDlg:CloseChannelSetting() self.channelSettingActive = false UIUtils.SetActive(self.group_Channel, false) UIUtils.SetActive(self.mask_Talk, false) end function UIBattleChatDlg:OnDeadChatViewTop(isDead) self:SetSortingLayer(isDead, "UITopmost", 0) self.changeSortingLayer = isDead end function UIBattleChatDlg:OnClickOpenFriend() if self.changeSortingLayer then self.gameObject:SetActive(false) self.isOpen = false UIUtils.SetActive(self.Condition_Msg, false) end end function UIBattleChatDlg:OnFriendBaseClose() if self.isOpen == false then self.gameObject:SetActive(true) self.isOpen = true UIUtils.SetActive(self.Condition_Msg, true) end end function UIBattleChatDlg:OnlyShowChat() return self.context and self.context.onlyChat end return UIBattleChatDlg