local EventSystem = require('Event/EventSystem') local UIChannelChatGlobalChatDlg = UIViewClass() local NoticeAtlas = "UI_Friend" local SmallQuickMsgY = 145 local BigQuickMsgY = 350 local SmallMsgContentY = 154 local BigMsgContentY = 358 local MAX_QUICK_MSG_LENGTH = 500 function UIChannelChatGlobalChatDlg:OnOpened() --注册Update self.LastMsgChannelId = nil self:RegistSystemEvent(EventID.UI_Open_Chat_By_External, self.OnClickOpenChatByExternal) self:RegistSystemEvent(EventID.UI_ChannelChat_OnChatViewClose,self.OnChatViewClose) self:RegistSystemEvent(EventID.UI_ChannelChat_OnChatViewOpen,self.OnChatViewOpen) self:RegistSystemEvent(EventID.UI_ChannelChat_OnReceiveNewMsg,self.OnReceiveNewMsg) self:RegistSystemEvent(EventID.UI_UpdateChatRed, self.OnRefreshFriendRed) self:RegistSystemEvent(EventID.UI_UpdateBlack, self.OnUpdateBlack) self:RegistSystemEvent(EventID.UI_UpdateClimbTowerInfo, self.UpdateClimbTowerAward) self:RegistSystemEvent(EventID.UI_Auto_Tips, self.RefreshAutoTips) -- 自动寻路、跟随 self:RegistSystemEvent(CTL.RedPoint.RedPointKey.InfoReminder, self.RefreshInfoReminderRp) self:RegistSystemEvent(CTL.RedPoint.RedPointKey.Mail, self.RefreshMailRed) self:RegistSystemEvent(EventID.FunctionUnlockUpdate, self.UpdateFriendEntry) self:RegistSystemEvent(EventID.DigTreasure_StartTask, self.OnDigTreasureStart) self:RegistSystemEvent(EventID.Game_ScreenResolutionChanged, self.OnScreenResolutionChanged) self:RepositionQuickMsg(true) self.QuickMsgCellTable = nil self.QuickMsgCellTableIndex = -1 self.isOpen = true self.TextPreferredHeight = 0 UIUtils.SetActive(self.Condition_QuickMsg, false) UIUtils.SetActive(self.img_Click, false) MDL.ChannelChat.SetGlobalChatDlgIsOpen(true) self:RefreshLoopScroll() self:RefreshMailRed() self:OnRefreshFriendRed() self:InitAutoTips() self.infoReminderCanvas:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIInfoReminderTipsView)) self:RefreshInfoReminderRp(CTL.RedPoint.GetRedPointActive(CTL.RedPoint.RedPointKey.InfoReminder)) self:UpdateFriendEntry() self:InitCurVoiceChannel() if GameAppInfo.IsPCOrMacPackage() then CTL.Setting.SetPCViewScale(self.gameObject.transform) end end function UIChannelChatGlobalChatDlg:UpdateFriendEntry() --好友入口:邮件和好友至少有一个有解锁了才有入口 local hasEntry = false if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Friend) or MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Mail) then hasEntry = true end UIUtils.SetActive(self.btn_Friend, hasEntry) --观战用了该对话框,但是需要特殊隐藏下该入口 if self.context and self.context.isWatch then UIUtils.SetActive(self.btn_Msg, false) else UIUtils.SetActive(self.btn_Msg, MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.InfoReminder)) end end function UIChannelChatGlobalChatDlg:OnUpdateBlack() self:ReloadDatas(self.isSmall) end function UIChannelChatGlobalChatDlg:OnClickOpenChat() UIUtils.SetActive(self.Condition_QuickMsg, false) UIManager.OpenView(Const_UI_Lua.UIEnum.UIChannelChatMain, {LastMsgChannelId = nil}) end function UIChannelChatGlobalChatDlg:OnClickOpenChatByExternal() if UIManager.IsFocus(Const_UI_Lua.UIEnum.UIChannelChatGlobalChatDlg) then if not UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIChannelChatMain) then self:OnClickOpenChat() end end end function UIChannelChatGlobalChatDlg:RefreshLoopScroll() if self.isOpen then MDL.ChannelChat.SetMsgIteratorData() CSExt.CSFunc_ReloadAll(self.obj_ScrollPanel, MDL.ChannelChat.EnumMsgIterator) local inRegion = GameAppInfo.IsJapanesePackage() or GameAppInfo.IsOverseaPackage() if inRegion and self.obj_ScrollPanel.Count <= 0 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 UnityEngine.Canvas.ForceUpdateCanvases() self.obj_ScrollPanel:MoveEnd() self.obj_ScrollPanel:RefreshScrollHeight(self.TextPreferredHeight) UnityEngine.Canvas.ForceUpdateCanvases() end end function UIChannelChatGlobalChatDlg:OnChatViewClose() self.gameObject:SetActive(true) self.isOpen = true self.obj_ScrollPanel:ClearCells() self:RefreshLoopScroll() end function UIChannelChatGlobalChatDlg:OnChatViewOpen() self.gameObject:SetActive(false) self.isOpen = false end function UIChannelChatGlobalChatDlg:OnScreenResolutionChanged() self.obj_ScrollPanel:ClearCells() self:RefreshLoopScroll() end function UIChannelChatGlobalChatDlg: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) local scrollCellCount = self.obj_ScrollPanel.Count if scrollCellCount <= 0 then self.obj_ScrollPanel:AddData(msg, 0) else self.obj_ScrollPanel:AddDynamicData(msg, 0) end self.obj_ScrollPanel:MoveEnd() self.obj_ScrollPanel:RefreshScrollHeight(self.TextPreferredHeight) end end function UIChannelChatGlobalChatDlg:OnClosed() MDL.ChannelChat.SetGlobalChatDlgIsOpen(false) CTL.ChannelChat.CancelRecordVoice() end --以下为按钮点击事件 function UIChannelChatGlobalChatDlg:OnButtonClicked(obj) if obj == self.event_OpenChat then self:OnClickOpenChat() elseif obj == self.btn_QuickMsg then self:LoadQuickMsg() elseif obj == self.btn_ArrowDown then self:ReloadDatas(true) elseif obj == self.btn_ArrowUp then self:ReloadDatas(false) elseif obj == self.btn_Friend then CTL.Friend.OpenFriendPanel(CTL.Friend.MainIndex.Main) elseif obj == self.img_Click then self:OnDeselect(nil,nil) elseif obj == self.event_ClimbTowerGet then --挂机奖励可领取 CTL.ClimbTower.OpenMainPanel() CTL.ClimbTower.OpenEarningsInfo() elseif obj == self.btn_Msg then UIManager.OpenView(Const_UI_Lua.UIEnum.UIInfoReminderMsgView) elseif obj == self.mask_Talk then self:CloseChannelSetting() elseif obj == self.dig_btn then UIManager.OpenView(Const_UI_Lua.UIEnum.UIDigForTreasurePanel) end end function UIChannelChatGlobalChatDlg:ReloadDatas(isSmall) self.obj_ScrollPanel:ClearCells() self:RepositionQuickMsg(isSmall) self:RefreshLoopScroll() self:RefreshMailRed() if isSmall then self:InitAutoTips() else self:SetAutomaticType(false) end end function UIChannelChatGlobalChatDlg:LoadQuickMsg() --频道是否开启,现在的版本快捷频道只是发送到当前频道,后面有其他功能根据相应功能选择频道是否开启 local isOpen, unlockMsg = MDL.ChannelChat.IsChannelOpen(MDL.ChannelChat.ChannelCfgId.Current) if not isOpen then CTL.Tips.AddTipsMsg(unlockMsg) return end if self.Condition_QuickMsg.gameObject.activeSelf then UIUtils.SetActive(self.Condition_QuickMsg, false) self:InitAutoTips() return else UIUtils.SetActive(self.Condition_QuickMsg, true) self:SetAutomaticType(false) end local quickDatas = MDL.ChannelChat.GetQuickMsgData() self.QuickMsgScroll:ReloadAll(quickDatas) end function UIChannelChatGlobalChatDlg:RepositionQuickMsg(isSmall) self.isSmall = isSmall UIUtils.SetActive(self.btn_ArrowUp, isSmall) UIUtils.SetActive(self.btn_ArrowDown, not isSmall) self.Condition_QuickMsg.transform:SetAnchoredPosition(nil, isSmall and SmallQuickMsgY or BigQuickMsgY) self.group_ChatContent:SetSizeDelta(nil, isSmall and SmallMsgContentY or BigMsgContentY) self:UpdateClimbTowerAward(isSmall) UnityEngine.UI.LayoutRebuilder.ForceRebuildLayoutImmediate(self.group_Chat) end function UIChannelChatGlobalChatDlg:UpdateClimbTowerAward() if CTL.ClimbTower.ShowHomeGetAwardBtn() then UIUtils.SetActive(self.event_ClimbTowerGet, self.isSmall) CTL.HomeMain.AddMainNotice(CTL.HomeMain.NoticeType.ClimbTower) else UIUtils.SetActive(self.event_ClimbTowerGet, false) CTL.HomeMain.RemoveMainNotice(CTL.HomeMain.NoticeType.ClimbTower) end end function UIChannelChatGlobalChatDlg: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) MDL.ChannelChat.ProcessQuickMsg(tmpValue, cellTable.txt_01, MAX_QUICK_MSG_LENGTH) elseif scrollRect == self.loop_Channel then UIUtils.SetLabelText(cellTable.txt_Channel,Const_IDS[data.AudioChatName]) else local content = "" if MDL.ChannelChat.IsZhaoMuChannelByCfgId(data.ChatCfgId) or MDL.ChannelChat.IsSystemChannelByCfgId(data.ChatCfgId) then content = data.content else if not string.isNilOrEmpty(data.senderName) then if data.isVoice then content = data.senderName .. "[j]" .. data.content else content = data.senderName .. ":" .. data.content end else content = data.content end end -- 设置频道(需要优先设置,以便首行空格) -- chatCfgId 从1 开始 state从0开始所以减1 CTL.ChannelChat.SetChannelBgColor(data.ChatCfgId, cellTable.groupBG, cellTable.txt_Channel, data.serId, not string.isNilOrEmpty(data.senderName)) -- 设置频道文字空格(需要在设置text之前设置) cellTable.msg_Content.text = CTL.ChannelChat.GetChannelBlankSpace(data.ChatCfgId, data.serId, not string.isNilOrEmpty(data.senderName)) .. content self.LastMsgChannelId = data.ChannelId self.TextPreferredHeight = cellTable.msg_Content.preferredHeight -- 设置频道位置 if UIUtils.GetFirstLineHaveEmojiByEmojiText(cellTable.msg_Content) then UIUtils.SetRectPosition(cellTable.groupBG, 0, -37) else UIUtils.SetRectPosition(cellTable.groupBG, 0, 0) end end end function UIChannelChatGlobalChatDlg: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_QuickMsg, false) self:InitAutoTips() 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) UIUtils.SetActive(self.img_Click, true) 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 UIChannelChatGlobalChatDlg:Cell_OnDeselect(comp, eventData) if self.QuickMsgCellTable ~= nil then local newContent = self.QuickMsgCellTable.objQuickMsg_InputField.text if newContent == nil or #newContent <= 0 then newContent = MDL.ChannelChat.GetQuickMsgByIndex(self.QuickMsgCellTableIndex + 1) end 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) UIUtils.SetActive(self.img_Click, false) MDL.ChannelChat.ProcessQuickMsg(newContent, self.QuickMsgCellTable.txt_01, MAX_QUICK_MSG_LENGTH) self.QuickMsgCellTableIndex = -1 self.QuickMsgCellTable = nil end end function UIChannelChatGlobalChatDlg: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 UIChannelChatGlobalChatDlg:RefreshMailRed() if self.context and self.context.isWatch then UIUtils.SetActive(self.img_Mail, false) else local mailRed = CTL.RedPoint.GetRedPointActive(CTL.RedPoint.RedPointKey.Mail) if mailRed == nil then UIUtils.SetActive(self.img_Mail, false) else UIUtils.SetActive(self.img_Mail, mailRed) end end end function UIChannelChatGlobalChatDlg: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 UIChannelChatGlobalChatDlg:InitAutoTips() self:RefreshAutoTips(LuaConst.AutoType.AutoFollow) -- 先判断是否自动跟随 if not MDL.Team.IsFollowing() then -- 再判断是否自动寻路 self:RefreshAutoTips(LuaConst.AutoType.AutoFindPath) end end -- 刷新自动提示内容 function UIChannelChatGlobalChatDlg:RefreshAutoTips(autoType) if BattleDataGetter.IsInLevelWatchBattle() then self:SetAutomaticType(false) return end if autoType == LuaConst.AutoType.AutoFindPath and MDL.Team.IsFollowing() then return end self:SetAutomaticType(false) if self.isSmall then if autoType == LuaConst.AutoType.AutoFollow then -- 自动跟随 if MDL.Team.IsFollowing() then UIUtils.SetLabelText(self.txt_Automatic, Const_IDS["IDS_Automatic_Following"]) self:SetAutomaticType(true) end elseif autoType == LuaConst.AutoType.AutoFindPath then -- 自动寻路 if BattleDataGetter.GetAutoFindPathInTownState() then UIUtils.SetLabelText(self.txt_Automatic, Const_IDS["IDS_Automatic_Pathfinding"]) self:SetAutomaticType(true) end elseif autoType == LuaConst.AutoType.FollowingCart then -- 自动寻路 FollowingCart if SyncMoveManager.IsFollowingNPC(BattleDataGetter.GetCurEntity()) then UIUtils.SetLabelText(self.txt_Automatic, Const_IDS["IDS_Escort_Auto"]) self:SetAutomaticType(true) end end end end function UIChannelChatGlobalChatDlg:SetAutomaticType(active) if active then local digTreasureCount = CTL.TeamDungeon.GetDigTreasureCount() if digTreasureCount and digTreasureCount > 0 then UIUtils.SetActive(self.state_Automatic.gameObject, false) UIUtils.SetActive(self.state_Automatic_Dig.gameObject, true) if MDL.TeamDungeon.GetDigRewardCount() > 0 then self.effect_RewardHigh:PlayUIEffect() else self.effect_RewardHigh:StopUIEffect() end else UIUtils.SetActive(self.state_Automatic.gameObject, true) UIUtils.SetActive(self.state_Automatic_Dig.gameObject, false) end else UIUtils.SetActive(self.state_Automatic.gameObject, false) UIUtils.SetActive(self.state_Automatic_Dig.gameObject, false) end end function UIChannelChatGlobalChatDlg:OnDigTreasureStart() UIUtils.SetActive(self.state_Automatic.gameObject, false) UIUtils.SetActive(self.state_Automatic_Dig.gameObject, true) if MDL.TeamDungeon.GetDigRewardCount() > 0 then self.effect_RewardHigh:PlayUIEffect() else self.effect_RewardHigh:StopUIEffect() end end function UIChannelChatGlobalChatDlg:RefreshInfoReminderRp(active) self.btn_Msg:SetRedPoint(active) end function UIChannelChatGlobalChatDlg: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, true) 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_OnRecordTimeEnd, self.OnRecordTimeEnd) self:RegistSystemEvent(EventID.UI_ChannelChat_OnRecordStartResult, self.OnStartRecordVoiceResult) self:RegistSystemEvent(EventID.UI_ChannelChat_OnSelectChannelChanged, self.SetCurVoiceChannel) end function UIChannelChatGlobalChatDlg: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 UIChannelChatGlobalChatDlg:OnRecordTimeEnd() UIUtils.SetActive(self.mask_Talk, false) self.isRecordTimeEnd = true end function UIChannelChatGlobalChatDlg: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 end end function UIChannelChatGlobalChatDlg: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 UIChannelChatGlobalChatDlg: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 UIChannelChatGlobalChatDlg: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 end end function UIChannelChatGlobalChatDlg:OnPointerPress() CTL.ChannelChat.StartRecordVoice(MDL.ChannelChat.GetChannelIdByCfgID(self.curVoiceChannelCfgID), false) end function UIChannelChatGlobalChatDlg:OnStartRecordVoiceResult(result) if result == "true" then UIUtils.SetActive(self.mask_Talk, true) end end function UIChannelChatGlobalChatDlg: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 UIChannelChatGlobalChatDlg:CloseChannelSetting() self.channelSettingActive = false UIUtils.SetActive(self.group_Channel, false) UIUtils.SetActive(self.mask_Talk, false) end return UIChannelChatGlobalChatDlg