local ChannelChat_Controller = {} local private = {} local EventSystem = require('Event/EventSystem') local HttpReq = require('Http/HttpReq') local EntityHeadUIModule = require("View/Battle/BattleEntityUI/EntityUIModule/EntityHeadUIModule") local LuaFuncEntry = require("Main/LuaFuncEntry") --**********私有数据********** local lastMsgTimeDic = {} -- 上次发言时间,cd判断 local chat_pb = require("Proto/chat_pb") local RefreshRedPoint = false local RefreshLoopScroll = false local RefreshGlobalChatLoopScroll = false local RefreshAnnouncement = false local isInit = false --军团战场斥候最大数量 local GuildWarMaxScoutsCount=10; --当前斥候数量 local CurrentScoutsCount=0 --当前收听人数 local CurrentListenCount=0 --战场总人数 local TotalCountInBattle=0 --是否已经提示开麦 local HasShowMicTip=false --频道标题字符空格补齐字符串 local cacheChannelBlankSpace = {} local EMOJI_LEFT_KEY = string.byte("[") local EMOJI_RIGHT_KEY = string.byte("]") private.processMsgResult = {} private.processMsgTemp = {} local AUDIO_DURATION_MAX local VOICE_ROOT_PATH = "Voice" --语音频道收听人数,索引对应VoiceRoomIndexl local VoiceRoomListenerCount= { [1]=0, [2]=0, } --错误码枚举 ChannelChat_Controller.ErrorCode = { Success = "Success", WordNumErr = "WordNumErr", TimeIntervalErr = "TimeIntervalErr", ContentEqualLastMsg = "ContentEqualLastMsg", EmptyContent = "EmptyContent", } local TitleEnum = { Channel = 1, Country = 2, Official = 3, GuildFrame = 4, GuildLeader = 5, GuildOfficial = 6, PlayerName = 7, PlayerServer = 8, PlayerGender = 9, Trumpet = 10, } local SAME_SERVER_FORMAT = "S.%d" local DIF_SERVER_FORMAT = "S.%d" function ChannelChat_Controller.GetServerShow(channelCfgID, serId) if channelCfgID then if channelCfgID == MDL.ChannelChat.ChannelCfgId.Cross or channelCfgID == MDL.ChannelChat.ChannelCfgId.WarZone or channelCfgID == MDL.ChannelChat.ChannelCfgId.SpecifiedActivity or channelCfgID == MDL.ChannelChat.ChannelCfgId.MyCamp then local mySerId = MDL.Login.GetServerShowId() if serId == mySerId then return string.format(SAME_SERVER_FORMAT, serId) else return string.format(DIF_SERVER_FORMAT, serId) end end end return nil end function ChannelChat_Controller.GetDefaultSelectChannel(lastMsgChannelId) local defaultShowChatId = ChannelChat_Controller.GetLastSelectChannelChat() if lastMsgChannelId ~= nil then local chatCfgData = MDL.ChannelChat.GetChatCfgDataByChannelId(lastMsgChannelId) if chatCfgData ~= nil then defaultShowChatId = chatCfgData.ID end end if not MDL.ChannelChat.IsDisplayCurrentChatChannel() and defaultShowChatId == MDL.ChannelChat.ChannelCfgId.Current then defaultShowChatId = MDL.ChannelChat.ChannelCfgId.World end return defaultShowChatId end function ChannelChat_Controller.SetChannelBgColor(channelCfgID, img, channelTXT, serId, isPlayerMsg) local chatCfgData = DataSheetManager.Chat:GetDataByID(channelCfgID) UIUtils.SetImageColor(img, chatCfgData.Color) if isPlayerMsg and chatCfgData.IsServerName == 1 then channelTXT.text = string.format(DIF_SERVER_FORMAT, serId) else UIUtils.SetLabelText(channelTXT, Const_IDS[chatCfgData.Name]) end end -- 注:%saa 这种是为了首行空出一定距离,所以颜色透明度必须为0,aaa用作占位 function ChannelChat_Controller.GetChannelBlankSpace(channelCfgID, serId, isPlayerMsg) if cacheChannelBlankSpace[channelCfgID] then return cacheChannelBlankSpace[channelCfgID] else if channelCfgID == MDL.ChannelChat.ChannelCfgId.Bullet then local str = UIUtils.GetLocalizedTxt(Const_IDS["IDS_HeroMatch1v1_Channel"]) cacheChannelBlankSpace[channelCfgID] = string.format("%saa", str) else local excelChatData = DataSheetManager.Chat:GetDataByID(channelCfgID) if isPlayerMsg and excelChatData.IsServerName == 1 then if cacheChannelBlankSpace[serId] == nil then if type(serId) == "number" and serId < 10 then cacheChannelBlankSpace[serId] = string.format("%saaa", string.format(DIF_SERVER_FORMAT, serId)) else cacheChannelBlankSpace[serId] = string.format("%saa", string.format(DIF_SERVER_FORMAT, serId)) end end return cacheChannelBlankSpace[serId] else local str = UIUtils.GetLocalizedTxt(Const_IDS[excelChatData.Name]) if channelCfgID == MDL.ChannelChat.ChannelCfgId.Country and Localization.IsThailand() then cacheChannelBlankSpace[channelCfgID] = string.format("%saaa", str) else cacheChannelBlankSpace[channelCfgID] = string.format("%saa", str) end end end return cacheChannelBlankSpace[channelCfgID] end end --**********End私有数据********** --**********私有数据访问********** function ChannelChat_Controller.GetRefreshRedPoint() return RefreshRedPoint end function ChannelChat_Controller.SetRefreshRedPoint(refresh) RefreshRedPoint = refresh end function ChannelChat_Controller.GetRefreshGlobalChatLoopScroll() return RefreshGlobalChatLoopScroll end function ChannelChat_Controller.SetRefreshGlobalChatLoopScroll(refresh) RefreshGlobalChatLoopScroll = refresh end function ChannelChat_Controller.GetRefreshAnnouncement() return RefreshAnnouncement end function ChannelChat_Controller.SetRefreshAnnouncement(refresh) RefreshAnnouncement = refresh end function ChannelChat_Controller.GetRefreshLoopScroll() return RefreshLoopScroll end function ChannelChat_Controller.SetRefreshLoopScroll(refresh) RefreshLoopScroll = refresh end --**********End私有数据访问********** function ChannelChat_Controller.OnStartup() private.SetupEntryFunc(true) private.CleanVoice() AUDIO_DURATION_MAX = DataSheetManager.ConstData:GetDataByID("AudioChatDuration").IntValue EventSystem.Regist(EventID.JoinBattleTeamChatChannel, private.JoinBattleTeamChatChannel) EventSystem.Regist(EventID.UI_Team_CreateTeam, private.JoinTeamChatChannel) EventSystem.Regist(EventID.UI_Team_LeaveTeam, private.ExitTeam) EventSystem.Regist(EventID.ChannelChat_ContinueFindPath, private.ContinueFindPathOnce) EventSystem.Regist(EventID.Level_SendPositionChatLink, private.OnSendPositionChatLink) EventSystem.Regist(EventID.TeamLevelUpdate, private.CheckJoinWarZoneChannelUnlock) EventSystem.Regist(EventID.WarZone_State_Change, private.CheckJoinWarZoneChannelUnlock) EventSystem.Regist(EventID.New_Day_Refresh, private.CheckJoinGVGFightChannelUnlock) EventSystem.Regist(EventID.ApplicationPause, private.OnApplicationPause) EventSystem.Regist(EventID.ChannelChat_ReceiveNewMsg, private.OnReceiveNewMsg) private.LastSelectChannelChatIndex = 0-- 上次选中的聊天频道index private.emojiKeyMapping = {} for i,v in DataSheetManager.ChatEmoji:GetEnumerator() do local emojiContent = UIUtils.GetLocalizedTxt(Const_IDS[v.EmojiName]) private.emojiKeyMapping[emojiContent] = tostring(v.ID) end private.showCurrentChannelTimeList = {} end function private.SetupEntryFunc(isRegist) LuaFuncEntry.SetupMainEntryFunc(isRegist, LuaFuncEntry.FuncType.OnRecordFinishSuccess, private.HandleOnRecordFinishSuccess, LuaFuncEntry.FuncType.OnRecordFinishFail, private.OnRecordFinishFail, LuaFuncEntry.FuncType.OnRecordStartResult, private.HandleOnRecordStartResult ) end function ChannelChat_Controller.OnShutdown() private.SetupEntryFunc(false) end function private.HandleOnRecordFinishSuccess(...) --参数拼接: 翻译文本|路径|时长(单位是毫秒) local content, recordPath, duration = string.match(..., "^(.*)|(.*)|(.*)$", 1) private.OnRecordFinishSuccess(content, recordPath, math.floor(tonumber(duration) / 1000)) end function private.HandleOnRecordStartResult(result) private.OnRecordStartResult(result) EventSystem.Dispatch(EventID.UI_ChannelChat_OnRecordStartResult, result) end --**************************Chat通信流程,不出意外都是按照连接顺序写的********************************* --2、加入聊天频道 function ChannelChat_Controller.JoinChannel() if isInit then --这个可以判定是聊天的断线重连,直接把现有的频道都加进去 MDL.ChannelChat.JoinAllChannel() else isInit = true local serverName = MDL.Login.GetRealServerId() MDL.ChannelChat.InitChannel(serverName) if MDL.Guild.IsHasGuild() then CTL.ChannelChat.JoinGuildChatChannel(MDL.Guild.GetMyGuildInfo().guildId) end if CTL.Team.IsInTeam() then private.JoinTeamChatChannel(MDL.Team.GetMyTeamId()) end if ChannelChat_Controller.CanJoinWarZoneChannel() then MDL.ChannelChat.TryJoinWarZoneChannel() end if MDL.ChannelChat.IsDisplayCurrentChatChannel() then if not MDL.ChannelChat.IsJoinChannel(MDL.ChannelChat.ChannelCfgId.Current) then ChannelChat_Controller.CreateCurrentChannel() end end if MDL.Country.IsHasCountry() then MDL.ChannelChat.JoinCountryChannel(MDL.Country.GetMyCountryId()) end if CTL.SpecialTeam.GetIsGroupChatOpen() then CTL.SpecialTeam.TryJoinGroupChat(MDL.SpecialTeam.GetMyTeamId()) end if BattleDataGetter.IsCityWarLevel() or BattleDataGetter.IsCityWarWaitingLevel() then CTL.ChannelChat.TryCreateDynamicChannel(MDL.ChannelChat.ChannelCfgId.MyCamp) end end end function ChannelChat_Controller.CheckCanSendTrumtMsg() local trumptNum = MDL.Bag.GetItemCountInOneCell("Item_Dalaba") if trumptNum >= 1 then return true else return false end end function private.OnApplicationPause(pause) if pause then ChannelChat_Controller.StopRecordVoice() ChannelChat_Controller.TryStopPlayingVoice(false) private.TryAbortDownloadVoice() end end --错误处理 function ChannelChat_Controller.ProcessError(errorCode,leftTime) if errorCode == ChannelChat_Controller.ErrorCode.WordNumErr then CTL.Tips.AddTipsMsg(Const_IDS["IDS_LiaoTian_Longtext"]) elseif errorCode == ChannelChat_Controller.ErrorCode.ContentEqualLastMsg then CTL.Tips.AddTipsMsg(Const_IDS["IDS_LiaoTian_Textrepetition"]) elseif errorCode == ChannelChat_Controller.ErrorCode.TimeIntervalErr then CTL.Tips.AddTipsMsg(Const_IDS["IDS_LiaoTian_Speaspeed"], tostring(math.ceil(leftTime))) elseif errorCode == ChannelChat_Controller.ErrorCode.EmptyContent then CTL.Tips.AddTipsMsg(Const_IDS["IDS_LiaoTian_Empty"]) end end --返回消息合规性 function ChannelChat_Controller.CheckCanSendTextMsg(content, channelID, chatType) local msgLen = #content if msgLen == 0 then return ChannelChat_Controller.ErrorCode.EmptyContent end local chatType = chatType or chat_pb.Room if chatType == chat_pb.Personal then --私聊 return ChannelChat_Controller.ErrorCode.Success else local chatCfgData = MDL.ChannelChat.GetChatCfgDataByChannelId(channelID) local msgCDTime = chatCfgData.Cd --判断CD if msgCDTime > 0 then local nowTime = UTL.Time.GetLocalTimestamp() local lastMsgTime = lastMsgTimeDic[channelID] or 0 if lastMsgTime > 0 then local offset = nowTime - lastMsgTime if offset < msgCDTime then local leftTime = msgCDTime - offset return ChannelChat_Controller.ErrorCode.TimeIntervalErr,leftTime end end lastMsgTimeDic[channelID] = nowTime end return ChannelChat_Controller.ErrorCode.Success end end function ChannelChat_Controller.SendTextMsg(content, channelID, isHistory, chatType, colorID) content = ChannelChat_Controller.PreProcessChatContentForEmoji(content) local errorCode, leftTime = ChannelChat_Controller.CheckCanSendTextMsg(content, channelID, chatType) if errorCode == ChannelChat_Controller.ErrorCode.Success then --替换content中的超链接数据 if isHistory ~= nil and isHistory then local realContent = MDL.ChannelChat.GetInputHistoryDataByKey(content) MDL.ChannelChat.SetInputHistoryData(content, realContent) MDL.ChannelChat.SendChatMsg(channelID, realContent, chatType, nil, colorID) else local simpleContent = content local hyperlinkIndex = nil if ChannelChat_Controller.HasHyperlinkTag(content) then content,hyperlinkIndex = ChannelChat_Controller.ReplaceHyperlinkContent(content) end MDL.ChannelChat.SetInputHistoryData(simpleContent, content) MDL.ChannelChat.SendChatMsg(channelID, content, chatType, hyperlinkIndex, colorID) end EventSystem.Dispatch(EventID.UI_ChannelChat_ClearInputField) elseif errorCode == ChannelChat_Controller.ErrorCode.WordNumErr then local chatCfgData = MDL.ChannelChat.GetChatCfgDataByChannelId(channelID) local shortcutContent = UTL.String.CutStrByLength(content, chatCfgData.Limit) MDL.ChannelChat.SendChatMsg(channelID, shortcutContent, chatType, nil, colorID) EventSystem.Dispatch(EventID.UI_ChannelChat_ClearInputField) else CTL.ChannelChat.ProcessError(errorCode,leftTime) end return errorCode == ChannelChat_Controller.ErrorCode.Success end function ChannelChat_Controller.OnDrag() EventSystem.Dispatch(EventID.UI_ChannelChat_OnDrag) end ChannelChat_Controller.ChatType = { Unknow = 0, PrivateChat = 1, RoomChat = 2, } function ChannelChat_Controller.GetHistoryInfos( ) MDL.ChannelChat.GetHistoryInfos() end function private.JoinTeamChatChannel(teamId) if isInit then local chatCfgData = DataSheetManager.Chat:GetDataByID(MDL.ChannelChat.ChannelCfgId.Team) local tmpTeamChannel = chatCfgData.ChannelPrefix..teamId MDL.ChannelChat.JoinChannel(chatCfgData.ID, tmpTeamChannel) end end function private.ExitTeam() MDL.ChannelChat.ExitChannelByChannelType(MDL.ChannelChat.ChannelCfgId.Team) end function ChannelChat_Controller.ExitGuild() MDL.ChannelChat.ExitChannelByChannelType(MDL.ChannelChat.ChannelCfgId.Legion) end function ChannelChat_Controller.ExitCountry() local channelType = MDL.ChannelChat.ChannelCfgId.Country local channelId = MDL.ChannelChat.GetChannelIdByCfgID(channelType) if channelId ~= nil then MDL.ChannelChat.ExitChannel(channelType, channelId) end end function ChannelChat_Controller.JoinGuildChatChannel(guildId) if isInit then local chatCfgData = DataSheetManager.Chat:GetDataByID(MDL.ChannelChat.ChannelCfgId.Legion) local tmpGuildChannel = chatCfgData.ChannelPrefix..guildId MDL.ChannelChat.JoinChannel(chatCfgData.ID, tmpGuildChannel) end end function private.JoinBattleTeamChatChannel(roomId, isJoin) if isJoin then ChannelChat_Controller.CreateBattleCurrentChannel(roomId) else ChannelChat_Controller.ExitCurrentChannel() end end --创建当前地图频道 --分为主城当前地图、副本当前地图(单人副本,策划配置)、战斗副本(多人战斗)当前地图 --主城当前地图主城当前地图按照主城地图创建频道 --副本当前地图(单人副本,策划配置)不显示,不创建频道 --战斗副本(多人战斗)当前地图,按照战斗唯一ID创建频道 ChannelChat_Controller.CreateBattleCurrentChannel(roomId) function ChannelChat_Controller.CreateCurrentChannel() local serverId = MDL.Login.GetRealServerId() if not serverId then return end ChannelChat_Controller.ExitCurrentChannel() local levelId = BattleDataGetter.GetLevelID() if levelId <= 0 then return end if not MDL.ChannelChat.GetFirstPassLevelForNew() then return end if not MDL.ChannelChat.IsDisplayCurrentChatChannel() then return end local chatCfgData = DataSheetManager.Chat:GetDataByID(MDL.ChannelChat.ChannelCfgId.Current) local tmpCurrentChannel = chatCfgData.ChannelPrefix..serverId.."_"..levelId logging.log(LTAG.LOG,"-11111---CreateCurrentChannel---- ", tmpCurrentChannel) MDL.ChannelChat.JoinChannel(chatCfgData.ID, tmpCurrentChannel) end function ChannelChat_Controller.CreateBattleCurrentChannel(roomId) ChannelChat_Controller.ExitCurrentChannel() local chatCfgData = DataSheetManager.Chat:GetDataByID(MDL.ChannelChat.ChannelCfgId.Current) local tmpCurrentChannel = chatCfgData.ChannelPrefix..MDL.Login.GetRealServerId().."_"..roomId logging.log(LTAG.LOG,"----CreateBattleCurrentChannel---- ", tmpCurrentChannel) MDL.ChannelChat.JoinChannel(chatCfgData.ID, tmpCurrentChannel) end function ChannelChat_Controller.ExitCurrentChannel() MDL.ChannelChat.ExitChannelByChannelType(MDL.ChannelChat.ChannelCfgId.Current) end function ChannelChat_Controller.TryCreateDynamicChannel(channelCfgID) local isInChannelScene = false local channelPrefix if channelCfgID == MDL.ChannelChat.ChannelCfgId.MyCamp then if not LevelManager.IsInLevelWatchBattle() and BattleDataGetter.IsSyncTeamPVP() or UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UISyncTeamPVPSelectHeroPanel) then isInChannelScene = true channelPrefix = "SyncTeamPVP_" .. MDL.SyncTeamPVP.GetBattleChatChannel() --唯一标识,只有同阵营同房间的人才能进入 elseif BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncFourCountryChaos) or UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UISyncFourCountryWarSelectHeroPanel) then isInChannelScene = true channelPrefix = "SyncTeamPVE_" .. MDL.SyncFourCountryWar.GetBattleChatChannel() --唯一标识,只有同阵营同房间的人才能进入 elseif BattleDataGetter.IsCityWarLevel() or BattleDataGetter.IsCityWarWaitingLevel() then channelPrefix = MDL.ChangAnSiege.GetChatChannel() isInChannelScene = channelPrefix ~= nil end elseif channelCfgID == MDL.ChannelChat.ChannelCfgId.SpecifiedActivity then if BattleDataGetter.IsFightThroneTown() or BattleDataGetter.IsFightThroneLevel() then isInChannelScene = true local warZoneId = MDL.ChannelChat.GetWarZoneId() if warZoneId and warZoneId > 0 then channelPrefix = "FightThrone_" .. warZoneId else channelPrefix = "FightThrone_" .. MDL.Login.GetRealServerId() end elseif BattleDataGetter.IsDragonArteryType() then isInChannelScene = true channelPrefix = MDL.DragonArtery.GetDragonArteryChannelPrefix(true) end elseif channelCfgID == MDL.ChannelChat.ChannelCfgId.Bullet then if (BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncUnfairSolo) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.CrossHeroMatchTown)) and MDL.HeroMatch1v1.IsCurActivityInOpenTime() then isInChannelScene = true channelPrefix = "CommonBullet_" .. MDL.HeroMatch1v1.GetActivityWarZoneGroupID() elseif (BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncUnfairTeamPVP) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.CrossHeroMatchTown3V3)) and MDL.HeroMatch3v3.IsCurActivityInOpenTime() then isInChannelScene = true local warZoneId = MDL.ChannelChat.GetWarZoneId() if warZoneId and warZoneId > 0 then channelPrefix = "HeroMatch3v3_" .. warZoneId else channelPrefix = "HeroMatch3v3_" .. MDL.Login.GetRealServerId() end elseif LevelManager.IsSceneQuizTown() then isInChannelScene = true channelPrefix = "CommonBullet_" .. CTL.SceneQuiz.GetBulletChannelPrefix() elseif (BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncFairSoloTournament) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.CrossFairSoloTournamentTown) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SingleFairSoloTournamentTown)) and MDL.FairSoloTournament.IsInOpenTime() then isInChannelScene = true local warZoneId = MDL.ChannelChat.GetWarZoneId() if warZoneId and warZoneId > 0 then channelPrefix = "FairTournament_" .. warZoneId else channelPrefix = "FairTournament_" .. MDL.Login.GetRealServerId() end elseif (BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.SyncTeamFairChampionship) or BattleDataGetter.CheckCurLevelType(LuaConst.LevelType.TeamFairChampionshipTown)) and CTL.TeamFairChampionship.IsCurActivityInOpenTime() then isInChannelScene = true local warZoneId = MDL.ChannelChat.GetWarZoneId() if warZoneId and warZoneId > 0 then channelPrefix = "TeamFairChampionship_" .. warZoneId else channelPrefix = "TeamFairChampionship_" .. MDL.Login.GetRealServerId() end end end if isInChannelScene then if MDL.ChannelChat.IsJoinChannel(channelCfgID) == false then local chatCfgData = DataSheetManager.Chat:GetDataByID(channelCfgID) MDL.ChannelChat.JoinChannel(channelCfgID, chatCfgData.ChannelPrefix .. channelPrefix) --进入该玩法,打开聊天自动选中该频道 ChannelChat_Controller.SetLastSelectChannelChat(channelCfgID) end else if MDL.ChannelChat.ExitChannelByChannelType(channelCfgID) then --需要将该频道的消息清除 MDL.ChannelChat.RemoveDlgMsgChannel(channelCfgID) end end end function ChannelChat_Controller.GetSpecifiedActivitySubChannel(channelPrefix) local chatCfgData = DataSheetManager.Chat:GetDataByID(MDL.ChannelChat.ChannelCfgId.SpecifiedActivity) return chatCfgData.ChannelPrefix .. channelPrefix end --活动频道是否有子频道 function ChannelChat_Controller.IsSpecifiedActivityHasSubChannel() return BattleDataGetter.IsDragonArteryType() end function private.IsNotDisplayBullet() return LevelManager.IsSceneQuizTown() end --左侧展示聊天频道 --这些聊天频道信息是一上线就创建并加入频道了 function ChannelChat_Controller.GetShowChannelCfgData() local list = {} local chatCfgData = MDL.ChannelChat.GetChatCfgData() for i = 1, #chatCfgData do local channelId = chatCfgData[i].ID --控制频道显示/隐藏 if channelId == MDL.ChannelChat.ChannelCfgId.Current and not MDL.ChannelChat.IsDisplayCurrentChatChannel() then elseif channelId == MDL.ChannelChat.ChannelCfgId.GuildWar and not CTL.ChannelChat.IsCanShowGuildWarChannel() then elseif channelId == MDL.ChannelChat.ChannelCfgId.WarZone and not CTL.ChannelChat.IsCanShowWarZoneChannel() then elseif channelId == MDL.ChannelChat.ChannelCfgId.SpecifiedActivity and not MDL.ChannelChat.IsJoinChannel(channelId) then elseif channelId == MDL.ChannelChat.ChannelCfgId.MyCamp and not MDL.ChannelChat.IsJoinChannel(channelId) then elseif channelId == MDL.ChannelChat.ChannelCfgId.Bullet and (private.IsNotDisplayBullet() or not MDL.ChannelChat.IsJoinChannel(channelId)) then elseif channelId == MDL.ChannelChat.ChannelCfgId.PKRoom and not MDL.ChannelChat.IsJoinChannel(channelId) then elseif channelId == MDL.ChannelChat.ChannelCfgId.GVGFight and not CTL.ChannelChat.IsCanShowGVGFightChannel() then elseif channelId == MDL.ChannelChat.ChannelCfgId.PetBreedChat and not MDL.ChannelChat.IsJoinChannel(channelId) then else if channelId == MDL.ChannelChat.ChannelCfgId.ZhaoMu or channelId == MDL.ChannelChat.ChannelCfgId.System then table.insert(list, chatCfgData[i]) else if MDL.Player.GetPublicSentimentUnLock() then table.insert(list, chatCfgData[i]) end end end end return list end --判断该频道是否支持语音 function ChannelChat_Controller.IsChannelEnableAudio(channelCfgID) if MDL.ChannelChat.IsTeamChannelByCfgId(channelCfgID) then --队伍数据为空时,且没有队伍,则需要隐藏数据框,提示加入队伍 if not CTL.Team.IsInTeam() then return false end return true end if MDL.ChannelChat.IsCanChatByCfgId(channelCfgID) then return false end if MDL.ChannelChat.IsLegionChannelByCfgId(channelCfgID) then if not MDL.Guild.IsHasGuild() then return false end return true end if MDL.ChannelChat.IsWarZoneChannelByCfgId(channelCfgID) then local state = CTL.WarZone.GetTimeState() if state == CTL.WarZone.TimeState.NotStart then return false end return true end if channelCfgID == MDL.ChannelChat.ChannelCfgId.Country then if not MDL.Country.IsHasCountry() or CTL.Country.IsShutUp(channelCfgID) then return false end end return true end function ChannelChat_Controller.GetEnableVoiceChannelList(curChannelID) local list = ChannelChat_Controller.GetShowChannelCfgData() for i = #list, 1, -1 do local channelId = list[i].ID local isRemove = false --移除不能聊天的頻道 local isOpen, unlockMsg = MDL.ChannelChat.IsChannelOpen(channelId) if not isOpen then isRemove = true else if curChannelID and curChannelID == channelId then isRemove = true else local silence = MDL.HomeMain.GetSilenceBuff() if silence ~= nil and MDL.ChannelChat.IsInSilenceChannelByCfgId(channelId) then isRemove = true else if ChannelChat_Controller.IsChannelEnableAudio(channelId) == false then isRemove = true else if channelId == MDL.ChannelChat.ChannelCfgId.Country then isRemove = not MDL.Country.IsHasCountry() or CTL.Country.IsShutUp(channelId) end end end end end if isRemove then table.remove(list, i) end end return list end function ChannelChat_Controller.OnHrefClick(text) if text == "NoneChatLink" then EventSystem.Dispatch(EventID.UI_Open_Chat_By_External) else logging.log(LTAG.LOG, "----OnHrefClick----text ", text) if MDL.CustomRoom.IsInRoom() then CTL.Tips.AddTipsMsg(Const_IDS["IDS_PK_Room_Tips_14"]) return end ChannelChat_Controller.ParseHyperlink(text) if string.find( text ,"http") then UnityEngine.Application.OpenURL(text) end end end function ChannelChat_Controller.IsOutOfLengthWhenInsertContent(input, channelId) local length = UTL.String.GetStrLen(input) local chatCfgData = MDL.ChannelChat.GetChatCfgDataByChannelId(channelId) if length > chatCfgData.Limit then CTL.Tips.AddTipsMsg(Const_IDS.IDS_Chat_New_UpperLimit) return true end return false end function ChannelChat_Controller.IsOutOfLength(input, channelId) local length = UTL.String.GetStrLen(input) local chatCfgData = MDL.ChannelChat.GetChatCfgDataByChannelId(channelId) if length > chatCfgData.Limit then CTL.Tips.AddTipsMsg(Const_IDS.IDS_Chat_Limit) return true end return false end function ChannelChat_Controller.OnEnterLevel() ChannelChat_Controller.CreateCurrentChannel() ChannelChat_Controller.TryCreateDynamicChannel(MDL.ChannelChat.ChannelCfgId.MyCamp) ChannelChat_Controller.TryCreateDynamicChannel(MDL.ChannelChat.ChannelCfgId.SpecifiedActivity) ChannelChat_Controller.TryCreateDynamicChannel(MDL.ChannelChat.ChannelCfgId.Bullet) ChannelChat_Controller.DisplayTrumpet() end --切换完场景之后判断再打开喇叭 function ChannelChat_Controller.DisplayTrumpet( ) local TrumpetDatas = MDL.ChannelChat.GetTrumpetDatas() if TrumpetDatas ~= nil and #TrumpetDatas > 0 then UIManager.OpenView(Const_UI_Lua.UIEnum.UIChannelChatMarquee) end end --发送文本时检测表情包文本,转成表情包符号 function ChannelChat_Controller.PreProcessChatContentForEmoji(content) table.clearArray(private.processMsgResult) table.clearArray(private.processMsgTemp) local startMatch = false for i = 1, #content do local byte = string.byte(content, i) if startMatch then if byte == EMOJI_LEFT_KEY then --未匹配到"]"前先匹配到了"[",此时将temp的值合并到result中 table.insert(private.processMsgResult, EMOJI_LEFT_KEY) for _, temp in ipairs(private.processMsgTemp) do table.insert(private.processMsgResult, temp) end table.clearArray(private.processMsgTemp) elseif byte == EMOJI_RIGHT_KEY then --匹配到"]",取出temp中的内容判断是否是表情表的文本 table.insert(private.processMsgResult, EMOJI_LEFT_KEY) local match = private.emojiKeyMapping[string.char(table.unpack(private.processMsgTemp))] if match then --是表情包的文本,需要替换成表情包的特殊字符 for j = 1, #match do table.insert(private.processMsgResult, string.byte(match, j)) end else --匹配失败,将temp的内容合并回result for _, temp in ipairs(private.processMsgTemp) do table.insert(private.processMsgResult, temp) end end table.insert(private.processMsgResult, EMOJI_RIGHT_KEY) table.clearArray(private.processMsgTemp) startMatch = false else table.insert(private.processMsgTemp, byte) end else if byte == EMOJI_LEFT_KEY then startMatch = true else table.insert(private.processMsgResult, byte) end end end return string.char(table.unpack(private.processMsgResult)) end --******************登录聊天服务器*********************** -- --region----------------超链接相关---------------------------------- --保存连接关联的数据表 --1、网址:打开百度 = "URL|http:baidu.com" --2、坐标:[210,123] = "Loaction|300,100,1" --3、装备:[上衣] = "Equip|1233423,12313" --4、邀请:[组队] = "Team|Content" --点击时,优先将数据保存在数据中 --坐标的正则表达式 function ChannelChat_Controller.GetLocationHyperlinkPattern() return "%[[^[(]*%([-]?%d+,[-]?%d+%)[^)%]]*%]" end function ChannelChat_Controller.GetItemHyperlinkPattern() if GameAppInfo.IsJapanesePackage() or GameAppInfo.IsVietnamPackage() then return "「[^)]-」" else return "【[^)]-】" end end local templateHyperlink = "%s" ChannelChat_Controller.HyperlinkTag = { URL = 0, Location = 1, Equip = 2, TeamApply = 3, ExcelTemplate = 4, Item = 5, Player = 6, GuildApply = 7, OfficialPositionPromote = 8,--官职晋升仪式 OfficialPositionResult = 9,--官职录取结果 GuildBuilding = 10 , --军团建筑 GuildWarBattle = 11, --势力战个人信息消息 GuildWarLineUp = 12, --上阵 Achievement = 13, --成就 GoldenHeroBossShare = 14, --金将体验boss分享 RedPacket = 15, GuildAllies = 16, --势力合纵连横 Scrimmage = 17, -- 大乱斗令旗分享 HeroCountry = 18, -- 国别跳转 HeroProfession = 19, -- 职业跳转 DragonArteryResultShare = 20, --龙脉结算分享 CountryChoose = 21, --国家选择跳转 CountryNightBossRecruit = 22, -- 国战晚间boss召集寻路 SpecialTeamApply = 23, --战团邀请 PetBreedApply = 24, --宠物繁殖邀请 PetInfo = 25, --宠物查看信息 PetShare = 26, --宠物分享 SlgGvEAttackCityOrBoss = 27, --SlgGvE城池/Boss攻打 } -- ---region--------暂时保存需要发送的超链接内容----------------------- local HyperlinkContentDatas = {} function ChannelChat_Controller.AddInputContentToCache(key, value) HyperlinkContentDatas[key] = value end function ChannelChat_Controller.RemoveInputContentByKey(key) HyperlinkContentDatas[key] = nil end function ChannelChat_Controller.GetInputContent(key) if HyperlinkContentDatas[key] == nil then return "" end return HyperlinkContentDatas[key] end -- ---end region--------暂时保存需要发送的超链接内容----------------------- --判断是否有相关超链接,后面有其他连接时需要在这里添加下 function ChannelChat_Controller.HasHyperlinkTag(content) if string.find(content, ChannelChat_Controller.GetLocationHyperlinkPattern()) ~= nil then return true end if string.find(content, ChannelChat_Controller.GetItemHyperlinkPattern()) ~= nil then return true end return false end --在给服务器发送消息时,处理下替换逻辑,将显示内容换成连接内容,后面有新增时需要新添加判断逻辑 --eg: -- 显示内容:[徐州(207,349)1 Line] -- 发送给服务器内容:超链起点和终点下标 然后收到协议后 在拼接回来 --替换时,需要按照其他功能需求处理替换方式 function ChannelChat_Controller.ReplaceHyperlinkContent(content) local linkParamsArr = {}; local findIndex = 1; for matchContent in string.gmatch(content, ChannelChat_Controller.GetLocationHyperlinkPattern()) do local hyperLinkContent = ChannelChat_Controller.GetInputContent(matchContent) local utf8StartIndex, utf8EndInex, luaStartIndex, luaEndIndex = string.findutf8(content, matchContent, findIndex, true) findIndex = luaEndIndex+1; table.insert(linkParamsArr, {utf8StartIndex, utf8EndInex, hyperLinkContent}); end findIndex = 1; for matchContent in string.gmatch(content, ChannelChat_Controller.GetItemHyperlinkPattern()) do local hyperLinkContent = ChannelChat_Controller.GetInputContent(matchContent) local utf8StartIndex, utf8EndInex, luaStartIndex, luaEndIndex = string.findutf8(content, matchContent, findIndex, true) findIndex = luaEndIndex+1; table.insert(linkParamsArr, {utf8StartIndex, utf8EndInex, hyperLinkContent}); end return content, linkParamsArr; end --生成超链接内容 function ChannelChat_Controller.GetHyperlinkContent(value,key) local hasKey = CTL.ChannelChat.GetInputContent(key) if hasKey == nil or #hasKey <= 0 then return "" end local content = string.format(templateHyperlink ,value, key) ChannelChat_Controller.RemoveInputContentByKey(key) return content end local HyperLinkColorRichText = "%s" function ChannelChat_Controller.CreateHyperlinkContent(type, value, key, isHyperLinkColor) if isHyperLinkColor then key = string.format(HyperLinkColorRichText, key) end value = type.."|"..value return string.format(templateHyperlink ,value, key) end -- Emoji 图集图片名 ChannelChat_Controller.RankEmoji = { [1] = "", [2] = "[a]", [3] = "[b]", [4] = "[c]", [5] = "[d]", [6] = "[e]", [7] = "[g]", [8] = "[h]", [9] = "[i]", [10] = "[k]", [11] = "[l]", [12] = "[n]", } function ChannelChat_Controller.FormatTeamRecruitMsg(teamRecruitInfo) --队长名字 local leaderName = teamRecruitInfo.name local leaderNameText = string.FormatByIdsId(Const_IDS["IDS_Team_Zhaomu07"], leaderName) --目标名字 local teamTarget = teamRecruitInfo.target local targetText = "" if CTL.Team.IsSpecifiedTarget(teamTarget.mainTarget) then targetText = string.FormatByIdsId(Const_IDS["IDS_Team_Zhaomu01"], UIUtils.GetLocalizedTxt(CTL.Team.GetSpecifiedTargetTitle(teamTarget.mainTarget))) else if teamTarget.mainTarget == LuaConst.ActivityType.GuildEscort and teamRecruitInfo.cartRarity >= MDL.GuildEscort.AdvancedEscort then local escortData = DataSheetManager.GuildEscortData:GetDataByID(teamRecruitInfo.cartRarity) local colorStr = UTL.Color.FormatTextByColor(escortData.NameColor, UIUtils.GetLocalizedTxt(Const_IDS[escortData.NameDes])) targetText = string.FormatByIdsId(Const_IDS.IDS_Escort_TeamRecruit1, colorStr) else targetText = string.FormatByIdsId(Const_IDS["IDS_Team_Zhaomu01"], MDL.Team.GetTeamTargetName(teamTarget.mainTarget, teamTarget.subTarget)) end end --成员数量 local teamMemberNum = string.FormatByIdsId(Const_IDS["IDS_Team_Zhaomu02"], teamRecruitInfo.curCount) --队伍限制 local teamLimit = teamRecruitInfo.limit local teamLimitText = "" if teamLimit.level > 0 and teamLimit.power > 0 then local level, rank = MDL.Nobility.GetLevelAndNobility(teamLimit.level) local levelText = string.FormatByIdsId(Const_IDS["IDS_Team_Zhaomu03"], ChannelChat_Controller.RankEmoji[rank]..level) local powerText = string.FormatByIdsId(Const_IDS["IDS_Team_Zhaomu04"], teamLimit.power) teamLimitText = string.format("(%s/%s)", levelText, powerText) elseif teamLimit.level > 0 then local level, rank = MDL.Nobility.GetLevelAndNobility(teamLimit.level) local levelText = string.FormatByIdsId(Const_IDS["IDS_Team_Zhaomu03"], ChannelChat_Controller.RankEmoji[rank]..level) teamLimitText = string.format("(%s)", levelText, levelText) elseif teamLimit.power > 0 then local powerText = string.FormatByIdsId(Const_IDS["IDS_Team_Zhaomu04"], teamLimit.power) teamLimitText = string.format("(%s)", powerText, powerText) end --超链接内容 local HyperLinkText = CTL.ChannelChat.GetTeamRecruitHyperlinkContent(teamRecruitInfo.teamId, teamTarget, teamLimit) local msgContent = string.Concat(leaderNameText, targetText) .. teamMemberNum .. teamLimitText .. UIUtils.GetLocalizedTxt(Const_IDS["IDS_Team_Zhaomu05"])..HyperLinkText return msgContent end function ChannelChat_Controller.FormatDragonArteryResultShare(strArray) local acid = strArray[2] or "" local shareId = strArray[3] or "" local value = ChannelChat_Controller.HyperlinkTag.DragonArteryResultShare .. "|" .. acid .. "|" .. shareId return UIUtils.GetLocalizedTxt(Const_IDS.IDS_DragonArtey_ShareChatMsg) .. string.format(templateHyperlink, value, UIUtils.GetLocalizedTxt(Const_IDS.IDS_DragonArtey_ShareChatMsg2)) end function ChannelChat_Controller.FormatSpecialTeamApplyMsg(strArray) local leaderName = strArray[2] or "" local teamName = strArray[3] or "" local curCount = strArray[4] or "" local teamId = strArray[5] or "" local funcId = strArray[6] or "" local value = ChannelChat_Controller.HyperlinkTag.SpecialTeamApply .. "|" .. teamId .. "|" .. funcId if tonumber(funcId) == MDL.Unlock.FunctionType.TeamFairChampionship then return string.FormatByIdsId(Const_IDS.IDS_TeamFairTournament_RecruitTip, leaderName, teamName, curCount) .. string.format(templateHyperlink, value, UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeroMatch3v3_RecruitTip2)) else return string.FormatByIdsId(Const_IDS.IDS_HeroMatch3v3_RecruitTip, leaderName, teamName, curCount) .. string.format(templateHyperlink, value, UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeroMatch3v3_RecruitTip2)) end end function ChannelChat_Controller.GetPetShareContext(chatMsgData) for i,v in ipairs(chatMsgData.templateInfo.params) do if v.param.strCommonParam and #v.param.strCommonParam > 0 then if tonumber(v.param.strCommonParam[1]) == CTL.ChannelChat.HyperlinkTag.PetShare then return v.param.strCommonParam[2] end end end return nil end function ChannelChat_Controller.FormatPetShareMsg(strArray, templateParam, content) local petUniqId = strArray[2] if string.isNilOrEmpty(petUniqId) then return end local preStr = utf8.sub(content, 1, templateParam.insertBeginIndex) local endStr = utf8.sub(content,templateParam.insertEndIndex) local petConfigId = tonumber(strArray[3]) local petStage = tonumber(strArray[4]) local petConfig = DataSheetManager.PetData:GetDataByID_Stage(petConfigId, petStage) local petIDS = petConfig.PetName local acid = strArray[5] local petName if petConfig.Quality == MDL.Pet.PetQuality.God then --神宠用彩金品质色 petName = UTL.Color.FormatQualityText(string.FormatByIdsKey("IDS_Chat_item", UIUtils.GetLocalizedTxt(Const_IDS[petIDS])), 7) else petName = string.FormatByIdsKey("IDS_Chat_item", UIUtils.GetLocalizedTxt(Const_IDS[petIDS])) end local value = ChannelChat_Controller.HyperlinkTag.PetShare .. "|" .. petUniqId .. "|" .. acid return preStr .. string.format(templateHyperlink, value, petName) .. endStr end function ChannelChat_Controller.FormatPetBreedApplyMsg(strArray, content) local acid = strArray[2] or "" local msg = strArray[3] or "" if UTL.String.CheckIsIds(msg) then msg = UIUtils.GetLocalizedTxt(Const_IDS[msg]) else msg = content end local pedigree = tonumber(strArray[4]) local petId = tonumber(strArray[5]) local playerName = strArray[6] if playerName then local value = ChannelChat_Controller.HyperlinkTag.PetBreedApply .. "|" .. acid .. "|" .. pedigree .. "|" .. petId .. "|" .. playerName local petConfig = DataSheetManager.PetData:GetDataByID_Stage(petId, MDL.Pet.PetState.Basic) return string.FormatByIdsId(Const_IDS.IDS_Pet_MyPet, pedigree, UIUtils.GetLocalizedTxt(Const_IDS[petConfig.PetName])) .. "," .. msg .. string.format(templateHyperlink, value, UIUtils.GetLocalizedTxt(Const_IDS.IDS_PetReproduce15)) else local value = ChannelChat_Controller.HyperlinkTag.PetBreedApply .. "|" .. acid .. "|" .. pedigree .. "|" .. petId local petConfig = DataSheetManager.PetData:GetDataByID_Stage(petId, MDL.Pet.PetState.Basic) return string.FormatByIdsId(Const_IDS.IDS_Pet_MyPet, pedigree, UIUtils.GetLocalizedTxt(Const_IDS[petConfig.PetName])) .. "," .. msg .. string.format(templateHyperlink, value, UIUtils.GetLocalizedTxt(Const_IDS.IDS_PetReproduce14)) end end function ChannelChat_Controller.FormatSlgGvEAttackCityOrBossMsg(param) local value = ChannelChat_Controller.HyperlinkTag.SlgGvEAttackCityOrBoss .."|".. param.gveLandId local mapName = CTL.SlgGvE.GetGridQualityColorName(param.gveLandId) return string.FormatByIdsId(Const_IDS.IDS_SlgGve_Main_Hint_13, mapName) .. string.format(templateHyperlink, value, UIUtils.GetLocalizedTxt(Const_IDS.IDS_BROADCAST_TurnDescribe_1740_1740)) end function ChannelChat_Controller.FormatMapPointMsg(content, templateParam) local mapInfo = templateParam.param.mapPointInfo local frontTag = "" local preStr = utf8.sub(content,1,templateParam.insertBeginIndex) local endstr = utf8.sub(content,templateParam.insertEndIndex) local localizedPosStr = ChannelChat_Controller.FormatLocalizedComposeLocation(mapInfo) local hpstr = string.format(HyperLinkColorRichText, localizedPosStr) return preStr..frontTag..hpstr..""..endstr end -- return 聊天透传回来的本地化后的坐标地点 function ChannelChat_Controller.FormatLocalizedComposeLocation(mapInfo) local mapId = mapInfo.mapId local line = mapInfo.lineId local posX = mapInfo.pos.X local posY = mapInfo.pos.Y local levelInfoData = DataSheetManager.LevelInfoData:GetDataByLevelID(mapId) if not levelInfoData then logging.error(LTAG.ERROR, "没有根据LevelID找到相应的LevelInfoData!", mapId) return end local levelName = UIUtils.GetLocalizedTxt(Const_IDS[levelInfoData.LevelNameIDS]) return string.FormatByIdsId(Const_IDS.IDS_Chat_Line, levelName, posX, posY, line) end function ChannelChat_Controller.FormatReceiveItemMsg(content, templateParam) local itemData = DataSheetManager.ItemData:GetDataByID(templateParam.param.itemId) local frontTag = "" local preStr = utf8.sub(content, 1, templateParam.insertBeginIndex) local chatItemName = string.FormatByIdsId(Const_IDS["IDS_Chat_item"], UTL.Item.GetItemDataSpliceByType(templateParam.param.itemId).Name) -- local hpstr = utf8.sub(content,templateParam.insertBeginIndex,templateParam.insertEndIndex) local endstr = utf8.sub(content,templateParam.insertEndIndex) return preStr..frontTag..UTL.Color.FormatQualityText(chatItemName, itemData.Color)..""..endstr end function ChannelChat_Controller.FormatGuildRecruitMsg(content, param) local frontTag = "" return param.idsOrStr..content..frontTag..UIUtils.GetLocalizedTxt(Const_IDS.IDS_Guild_Hyperlink_LearnMore).."" end function ChannelChat_Controller.FormatGuildRecommend(content, param) local frontTag = "".. param.name .."" return string.FormatByIdsId(Const_IDS.IDS_GuildRecommend_ChatMsg1,frontTag) end function ChannelChat_Controller.FormatGuildBuilding(content, param) local name = UIUtils.GetLocalizedTxt(Const_IDS[DataSheetManager.GuildBuildingBase:GetDataByID(param.guildBuildingId).BuildingName]) return name.."".. UIUtils.GetLocalizedTxt(Const_IDS.IDS_HyperLink_GoBoost) .."" end function ChannelChat_Controller.FormatGuildBuildingName(param) return UIUtils.GetLocalizedTxt(Const_IDS[DataSheetManager.GuildBuildingBase:GetDataByID(param.guildBuildingId).BuildingName]) end function ChannelChat_Controller.FormatGuildBuildingGoBoost(param) return "".. UIUtils.GetLocalizedTxt(Const_IDS.IDS_HyperLink_GoBoost) .."" end function ChannelChat_Controller.FormatRedPacket(redPacketId) return string.format("%s", CTL.ChannelChat.HyperlinkTag.RedPacket, redPacketId, UIUtils.GetLocalizedTxt(Const_IDS.IDS_HongBao_Hyperlink)) end function ChannelChat_Controller.FormatScrimmage(content, posIndex, mapId, lineId) --区分是否可寻路 local canFind = true if mapId ~= BattleDataGetter.GetCurLevelID() or lineId ~= BattleDataGetter.GetBattleBranchLine() then canFind = false end local hyperlink = string.format("%s", CTL.ChannelChat.HyperlinkTag.Scrimmage, posIndex, mapId, lineId, content) if canFind then return string.FormatByIdsId(Const_IDS.IDS_FightThrone_SharedCoordinates, hyperlink) .. UIUtils.GetLocalizedTxt(Const_IDS.IDS_FightThrone_Delivery) else return string.FormatByIdsId(Const_IDS.IDS_FightThrone_SharedCoordinates, hyperlink) end end function ChannelChat_Controller.FormatItemMsg(itemId) local itemData = DataSheetManager.ItemData:GetDataByID(itemId) local chatItemName = string.FormatByIdsId(Const_IDS["IDS_Chat_item"], UTL.Item.GetItemDataSpliceByType(itemId).Name) return CTL.ChannelChat.CreateHyperlinkContent(CTL.ChannelChat.HyperlinkTag.Item, itemId, UTL.Color.FormatQualityText(chatItemName, itemData.Color), true) end local guildWarMsgIDToData = {} function ChannelChat_Controller.FormatGuildWarMsg(content, guildWarBattleInfo,extraParam) table.insert(guildWarMsgIDToData, {data = guildWarBattleInfo, name = extraParam.PlayerShowInfo.name, mainHeroId = extraParam.PlayerShowInfo.mainHeroId}) local frontTag = "" return content..frontTag..UIUtils.GetLocalizedTxt(Const_IDS.IDS_Guild_Hyperlink_LearnMore).."" end local AchievementTitleStr = "【%s】" function ChannelChat_Controller.FormatAchievementMsg(content, param) local achievementItem = MDL.Achievement.GetAchievementItemByID(param.achievementId) if not achievementItem then logging.error(LTAG.ERROR, "当前超链接分享的成就ID ", param.achievementId, "在本地数据中不存在!!!") return content end local titleName = CTL.Achievement.GetAchievementTitleAndDesc(achievementItem) local achievementTitleName = string.format(AchievementTitleStr, titleName) local hyperLinkContent = CTL.ChannelChat.CreateHyperlinkContent(CTL.ChannelChat.HyperlinkTag.Achievement, param.name .. "," .. param.achievementId, achievementTitleName, true) return string.format(UIUtils.GetLocalizedTxt(Const_IDS[param.idsOrStr]), hyperLinkContent) end --生成组队喊话招募的超链接内容‘ function ChannelChat_Controller.GetTeamRecruitHyperlinkContent(teamId, teamTarget, teamLimit) local value = ChannelChat_Controller.HyperlinkTag.TeamApply.."|"..teamId..","..teamTarget.mainTarget..","..teamTarget.subTarget..","..teamLimit.level..","..teamLimit.power local content = UIUtils.GetLocalizedTxt(Const_IDS["IDS_Team_Zhaomu06"]) local hyperContent = string.format(templateHyperlink ,value, content) return hyperContent end --- @param bossID int 晚间bossID主键 --- @param index int boss出生点位ID --- @param playerName string 玩家名 --- @param countryJobIDS string 职位IDS --- @return 生成国家晚间boss召集喊话超链接内容 function ChannelChat_Controller.FormatCountryNightBossRecruitHyperlinkContent(bossID, index, playerName, countryJobIDS) local value = ChannelChat_Controller.HyperlinkTag.CountryNightBossRecruit .. "|" .. index local content = UIUtils.GetLocalizedTxt(Const_IDS["IDS_BROADCAST_TurnDescribe_1001_1001"]) local hyperContent = string.format(templateHyperlink, value, content) local showContent = string.FormatByIdsId( Const_IDS["IDS_CountryNightBoss_CallTogetherDes"], UIUtils.GetLocalizedTxt(Const_IDS[countryJobIDS]), -- 官职 playerName, UIUtils.GetLocalizedTxt(Const_IDS[DataSheetManager.CountryNightBossPoint:GetDataByBossPoint(index).PointName]), UIUtils.GetLocalizedTxt(Const_IDS[DataSheetManager.CountryNightBoss:GetDataByID(bossID).WordBossName]), hyperContent ) return showContent end --解析链接 function ChannelChat_Controller.ParseHyperlink(content) if content == nil or #content <= 0 then return end local pairSplits = string.split(content,"|") if #pairSplits < 2 then return end local key = tonumber(pairSplits[1]) if key == ChannelChat_Controller.HyperlinkTag.URL then ChannelChat_Controller.ParseURL(pairSplits[2]) elseif key == ChannelChat_Controller.HyperlinkTag.Location then ChannelChat_Controller.ParseLocation(pairSplits[2]) elseif key == ChannelChat_Controller.HyperlinkTag.Equip then ChannelChat_Controller.ParseEquip(pairSplits[2]) elseif key == ChannelChat_Controller.HyperlinkTag.TeamApply then ChannelChat_Controller.ParseTeamApply(pairSplits[2]) elseif key == ChannelChat_Controller.HyperlinkTag.OfficialPositionResult then ChannelChat_Controller.ParseOfficialPositionResult(pairSplits[2]) elseif key == ChannelChat_Controller.HyperlinkTag.OfficialPositionPromote then ChannelChat_Controller.ParseOfficialPositionPromote(pairSplits[2]) elseif key == ChannelChat_Controller.HyperlinkTag.ExcelTemplate then ChannelChat_Controller.ParseExcelTemplate(pairSplits[2]) elseif key == ChannelChat_Controller.HyperlinkTag.Item then UTL.ItemTips.ShowCommonTipsById(tonumber(pairSplits[2])) elseif key == ChannelChat_Controller.HyperlinkTag.Player then CTL.PlayerInteract.OpenFriendInteractView(pairSplits[2]) elseif key == ChannelChat_Controller.HyperlinkTag.GuildApply then CTL.Guild.OpenAndApply(pairSplits[2]) elseif key == ChannelChat_Controller.HyperlinkTag.GuildBuilding then local values = string.split( pairSplits[2],",") CTL.Guild.BuildingSpeedUpReq(tonumber(values[1]),tonumber(values[2])) elseif key == ChannelChat_Controller.HyperlinkTag.GuildWarBattle then CTL.GuildWar.OpenBattleResView(guildWarMsgIDToData[tonumber(pairSplits[2])]) elseif key == ChannelChat_Controller.HyperlinkTag.GuildWarLineUp then CTL.GuildWar.OpenMainView() elseif key == ChannelChat_Controller.HyperlinkTag.Achievement then local params = string.split(pairSplits[2], ",") CTL.Achievement.OnShareAchievement(params[1], params[2]) elseif key == ChannelChat_Controller.HyperlinkTag.GoldenHeroBossShare then if not BattleDataGetter.IsOnlineTownLevel() then --判断是否在主城 CTL.Tips.AddTipsMsg(Const_IDS.IDS_Chat_NoTurn) return end if CTL.OperationActivity.IsOperationActivityTypeUnlock(MDL.OperationActivity.ActivityType.GoldenHero) then local HyperlinkTag = table.remove(pairSplits, 1) local activityId = tonumber(table.remove(pairSplits, 1)) local bossId = table.concat(pairSplits, "|") if CTL.GoldenHeroBoss.IsBossCanLocate(activityId, bossId) then CTL.GoldenHeroBoss.LocateShareBoss(activityId, bossId) end else CTL.Tips.AddTipsMsg(Const_IDS.IDS_GoldHeroActivity_SynergyBoss_Help_Hint4) end elseif key == ChannelChat_Controller.HyperlinkTag.RedPacket then MDL.RedPacket.ReceiveGuildRedPacketRequest(pairSplits[2]) elseif key == ChannelChat_Controller.HyperlinkTag.GuildAllies then if MDL.Guild.IsHasGuild() then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIGuildAlliesMapView) else CTL.Guild.OpenGuildMain() end elseif key == ChannelChat_Controller.HyperlinkTag.Scrimmage then --判断是否可寻路 local mapId = tonumber(pairSplits[3]) local lineId = tonumber(pairSplits[4]) if mapId ~= BattleDataGetter.GetCurLevelID() or lineId ~= BattleDataGetter.GetBattleBranchLine() then CTL.Tips.AddTipsMsg(Const_IDS.IDS_FightThrone_CannotMove1) return end LuaInputManager.CmdRunToPosByIndex(tonumber(pairSplits[2])) elseif key == ChannelChat_Controller.HyperlinkTag.DragonArteryResultShare then local acid = pairSplits[2] local shareId = pairSplits[3] MDL.DragonArtery.DragonArteryShareInfoReq(shareId, acid) elseif key == ChannelChat_Controller.HyperlinkTag.SpecialTeamApply then local funcId = tonumber(pairSplits[3]) if funcId == MDL.SpecialTeam.GetCurTeamType() then CTL.SpecialTeam.TryApplyTeam(pairSplits[2]) end elseif key == ChannelChat_Controller.HyperlinkTag.PetShare or key == ChannelChat_Controller.HyperlinkTag.PetInfo then local petUniqId = pairSplits[2] local acid = pairSplits[3] if string.isNilOrEmpty(petUniqId) == false then CTL.Pet.ViewPetShareInfo(petUniqId, acid) end elseif key == ChannelChat_Controller.HyperlinkTag.PetBreedApply then local acid = pairSplits[2] if string.isNilOrEmpty(acid) == false and acid ~= BattleDataGetter.GetAcID() then local playerName = pairSplits[5] if not playerName then return end --旧链接没这个字段,无反馈 if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Pet) == false then CTL.Tips.AddTipsMsg(Const_IDS.IDS_ERRORCODE_3013_InfoCode_FunctionLock) return end local petId = tonumber(pairSplits[4]) MDL.Pet.BreedPetInviteHandleReq(acid, petId, {playerAcid = acid, playerName = playerName, petId = petId}) else CTL.Tips.AddTipsMsg(Const_IDS["IDS_ERRORCODE_4063_InfoCode_Pet_Born36"]) end elseif key == ChannelChat_Controller.HyperlinkTag.HeroCountry then UIManager.OpenView(Const_UI_Lua.UIEnum.UIHeroFilterView, {canJump = false, targetCountry = tonumber(pairSplits[2])}) elseif key == ChannelChat_Controller.HyperlinkTag.HeroProfession then UIManager.OpenView(Const_UI_Lua.UIEnum.UIHeroFilterView, {canJump = false, targetProfession = tonumber(pairSplits[2])}) elseif key == ChannelChat_Controller.HyperlinkTag.CountryChoose then CTL.Country.ClickChooseHref() elseif key == ChannelChat_Controller.HyperlinkTag.CountryNightBossRecruit then CTL.CountryNightBoss.GoToBossPos(tonumber(pairSplits[2])) elseif key == ChannelChat_Controller.HyperlinkTag.SlgGvEAttackCityOrBoss then if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UISlgGvEMain) then local centerPointIndex = MDL.SlgGvE.GetEliteBossGridIndex(tonumber(pairSplits[2])) EventSystem.Dispatch(EventID.UI_SlgGve_SelectGridIndex, centerPointIndex) else UIManager.CloseView(Const_UI_Lua.UIEnum.UIChannelChatMain) CTL.SlgGvE.OpenSlgGvEMain(tonumber(pairSplits[2])) end end end ---解析配表模板 function ChannelChat_Controller.ParseExcelTemplate(id) -- body if not BattleDataGetter.IsOnlineTownLevel() then CTL.Tips.AddTipsMsg(Const_IDS.IDS_Chat_NoTurn) return end local data = DataSheetManager.Broadcast:GetDataByID(tonumber(id)) CTL.ItemSources.ExecuteSourceFunctionById(data.TurnUI) end --解析URL function ChannelChat_Controller.ParseURL(content) UnityEngine.Application.OpenURL(content) end -- [地图名(X,Y)Z线] function ChannelChat_Controller.ComposeLocation(levelId, posX, posY, line) local levelInfoData = DataSheetManager.LevelInfoData:GetDataByLevelID(levelId) if not levelInfoData then logging.error(LTAG.ERROR, "没有根据LevelID找到相应的LevelInfoData!", levelId) return end local levelName = UIUtils.GetLocalizedTxt(Const_IDS[levelInfoData.LevelNameIDS]) local locationTag = string.FormatByIdsId(Const_IDS.IDS_Chat_Line, levelName, posX, posY, line) ChannelChat_Controller.AddInputContentToCache(locationTag, ChannelChat_Controller.HyperlinkTag.Location.."|".. levelId ..",".. posX ..",".. posY .. "," .. line) return locationTag end function ChannelChat_Controller.ComposeScrimmage(levelId, posX, posY, line, posIndex) local levelInfoData = DataSheetManager.LevelInfoData:GetDataByLevelID(levelId) if not levelInfoData then logging.error(LTAG.ERROR, "没有根据LevelID找到相应的LevelInfoData!", levelId) return end local levelName = UIUtils.GetLocalizedTxt(Const_IDS[levelInfoData.LevelNameIDS]) local locationTag = string.FormatByIdsId(Const_IDS.IDS_Chat_Line, levelName, posX, posY, line) ChannelChat_Controller.AddInputContentToCache(locationTag, ChannelChat_Controller.HyperlinkTag.Scrimmage .."|".. levelId ..",".. posX ..",".. posY .. "," .. line .. "," .. posIndex) return locationTag end function ChannelChat_Controller.ComposeItem(itemCfgId) local itemCfgData = DataSheetManager.ItemData:GetDataByID(itemCfgId) local chatItemName = string.FormatByIdsKey("IDS_Chat_item", UTL.Item.GetItemDataSpliceByType(itemCfgId).Name) ChannelChat_Controller.AddInputContentToCache(chatItemName, ChannelChat_Controller.HyperlinkTag.Item.."|".. itemCfgId); return chatItemName; end --解析坐标 function ChannelChat_Controller.ParseLocation(content) if BattleDataGetter.IsTownLevel() == false then CTL.Tips.AddTipsMsg(Const_IDS.IDS_Chat_CantTransmitMap) return end if not MDL.Team.IsFollowing() then local feilds = string.split(content,",") local levelId = tonumber(feilds[1]) local posX = tonumber(feilds[2]) * 1000 local posY = tonumber(feilds[3]) * 1000 local line = tonumber(feilds[4]) if not ChannelChat_Controller.CanTransferByLocation(levelId, false) then return end --调用寻路接口 ChannelChat_Controller.curFindPathRecord = { levelId = levelId, posX = posX, posY = posY, line = line, } NotSyncBattleSetter.FindPathByPos(levelId,posX,posY,false, function() NotSyncBattleSetter.SendChangeSceneLineRequest(line) end ,LuaConst.ETownFindPathType.CHAT, true) else CTL.Tips.AddTipsMsg(Const_IDS["IDS_Team_FollowCanNotDoThis"]) end end function private.OnSendPositionChatLink(posIndex, posX, posY, levelId, branchLine) ChannelChat_Controller.SendFlagPos(levelId, posX, posY, posIndex, branchLine) end function private.ContinueFindPathOnce() if ChannelChat_Controller.curFindPathRecord then local line = ChannelChat_Controller.curFindPathRecord.line NotSyncBattleSetter.FindPathByPos( ChannelChat_Controller.curFindPathRecord.levelId, ChannelChat_Controller.curFindPathRecord.posX, ChannelChat_Controller.curFindPathRecord.posY, false, function() NotSyncBattleSetter.SendChangeSceneLineRequest(line) end ,LuaConst.ETownFindPathType.CHAT, true) ChannelChat_Controller.curFindPathRecord = nil end end function ChannelChat_Controller.OnStopFindPath() ChannelChat_Controller.curFindPathRecord = nil end --是否能根据坐标传送 function ChannelChat_Controller.CanTransferByLocation(levelId, canSend) local levelInfoData = DataSheetManager.LevelInfoData:GetDataByLevelID(levelId) local MapTransfer = DataSheetManager.ConstData:GetDataByID("MapTransfer").IntListValue for i=1,#MapTransfer do if levelInfoData.LevelType == MapTransfer[i] then return true end end if canSend then CTL.Tips.AddTipsMsg(Const_IDS.IDS_Chat_CantCoordinates) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_Chat_CantTransmitMap) end return false end --解析装备 function ChannelChat_Controller.ParseEquip(content) end --解析邀请 function ChannelChat_Controller.ParseTeamApply(content) local paramSplits = string.split(content,",") local teamId = paramSplits[1] local mainTarget = tonumber(paramSplits[2]) local subTarget = tonumber(paramSplits[3]) local level = tonumber(paramSplits[4]) local power = tonumber(paramSplits[5]) if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Team) then CTL.Team.SendTeamApplyRequest(teamId, {mainTarget = mainTarget, subTarget = subTarget}, {level = level, power = power}) else CTL.Tips.AddTipsMsg(Const_IDS["IDS_Team_FuctionNotOpen"]) end end --解析录取结果 function ChannelChat_Controller.ParseOfficialPositionResult(content) local paramSplits = string.split(content,",") local title = tonumber(paramSplits[1]) CTL.OfficialPosition.ShowAdmissionResult(title) end --解析晋升仪式 function ChannelChat_Controller.ParseOfficialPositionPromote(content) local paramSplits = string.split(content,",") local title = tonumber(paramSplits[1]) CTL.OfficialPosition.ShowZhaoshu(title) end -- 发送大乱斗坐标 function ChannelChat_Controller.SendFlagPos(levelId, posX, posY, posIndex, branchLine) if string.isNilOrEmpty(MDL.Guild.GetMyGuildId()) then CTL.Tips.AddTipsMsg(UIUtils.GetLocalizedTxt(Const_IDS.IDS_FightThrone_ShareLocation)) return end local content = ChannelChat_Controller.ComposeScrimmage(levelId, math.ceil(posX), math.ceil(posY), branchLine, posIndex) local channelID = MDL.ChannelChat.GetChannelIdByCfgID(MDL.ChannelChat.ChannelCfgId.Legion) if channelID ~= "Empty_Channel" then CTL.ChannelChat.SendTextMsg(content, channelID) end end -- --end region----------------超链接相关---------------------------------- --region----------------攻城略地(GVG)聊天相关---------------------------------- function ChannelChat_Controller.IsGVGFightChannel(channelID) return channelID == MDL.ChannelChat.ChannelCfgId.GVGFight end function private.CheckJoinGVGFightChannelUnlock() if isInit then MDL.ChannelChat.TryJoinGVGFightChannel() end end function ChannelChat_Controller.IsCanShowGVGFightChannel() local isUnlock = CTL.Activities.IsOpen(LuaConst.ActivityType.GVGFight) if isUnlock and CTL.GVGFight.IsExistInGVGFightMain() then return true end return false end --endregion-------------------------------------------------- --region----------------战区聊天相关---------------------------------- function ChannelChat_Controller.CanJoinWarZoneChannel() return CTL.WarZone.IsWarZoneOpen() and MDL.ChannelChat.IsChannelOpen(MDL.ChannelChat.ChannelCfgId.WarZone) end function private.CheckJoinWarZoneChannelUnlock() if isInit and ChannelChat_Controller.CanJoinWarZoneChannel() then MDL.ChannelChat.TryJoinWarZoneChannel() end end function ChannelChat_Controller.IsCanShowWarZoneChannel() if CTL.WarZone.GetTimeState() == CTL.WarZone.TimeState.NotStart then return false end return true end --endregion-------------------------------------------------- ------------------军团战场频道相关 start------------------------ function ChannelChat_Controller.IsGuildWarChannel(channelID) return channelID == MDL.ChannelChat.ChannelCfgId.GuildWar end function ChannelChat_Controller.IsCanShowGuildWarChannel() if BattleDataGetter.IsGuildWarLevel() or BattleDataGetter.IsGuildWarWaitingArea() then return true else return false end end --是否有军团战场开麦权限 function ChannelChat_Controller.IsCanOpenGuildWarVoice() local acid=PlayerInfoManager.AcID if ChannelChat_Controller.IsCanConvene() or ChannelChat_Controller.IsScouts(acid) then return true else return false end end --是否有召集权限 function ChannelChat_Controller.IsCanConvene() return MDL.GuildWar.IsBattleCommand(MDL.Guild.GetMyGuildInfo().jobTitle) end --当前的斥候数量 function ChannelChat_Controller.GetGuildWarScoutsCount() return CurrentScoutsCount end --设置斥候数量 function ChannelChat_Controller.SetGuildWarScoutsCount(count) CurrentScoutsCount=count ChannelChat_Controller.RefreshGuildWarChannelUI() ChannelChat_Controller.RefreshGuildWarChannelMemberUI() ChannelChat_Controller.RefreshGuildWarMapUI() end --刷新军团频道UI function ChannelChat_Controller.RefreshGuildWarChannelUI() EventSystem.Dispatch(EventID.UI_ChannelChat_RefreshGuildWar) end --刷新军团频道斥候UI function ChannelChat_Controller.RefreshGuildWarChannelMemberUI(isCloseMembers) if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIChannelChatMember) then EventSystem.Dispatch(EventID.UI_ChannelChat_RefreshChatMemberUI,isCloseMembers) end end --刷新军团地图UI function ChannelChat_Controller.RefreshGuildWarMapUI() EventSystem.Dispatch(EventID.UI_RefresGuildWarMapBtnsUI) end --最大的斥候数量 function ChannelChat_Controller.GetGuildWarMaxScoutsCount() return GuildWarMaxScoutsCount end --收听人数 function ChannelChat_Controller.GetGuildWarListenCount() return CurrentListenCount end --军团战场总人数 function ChannelChat_Controller.GetGuildWarTotalCount() return TotalCountInBattle end --设置收听人数 function ChannelChat_Controller.SetGuildWarListenCount(count,totalCount) CurrentListenCount=count TotalCountInBattle=totalCount ChannelChat_Controller.RefreshGuildWarChannelUI() ChannelChat_Controller.RefreshGuildWarMapUI() end --是否进入军团战场 function ChannelChat_Controller.IsEnterGuildWar() local levelType= LevelManager.GetCurLevelType() return BattleDataGetter.IsGuildWarLevelType(levelType) end --获取军团成员 function ChannelChat_Controller.GetGuildMembers() return MDL.Guild.GetGuildMemberInfo().members end --获取军团主公名字\头像ID function ChannelChat_Controller.GetGuildLeaderInfo() local name="" local sex = nil local leaderAcid = MDL.Guild.GetMyGuildInfo().leaderAcid local portraitId = -1 local frameId = -1 for i, v in ipairs(ChannelChat_Controller.GetGuildMembers()) do if v.roleInfo.acid ==leaderAcid then name = v.roleInfo.name sex = v.roleInfo.sex portraitId = v.roleInfo.PortraitId frameId = v.roleInfo.FrameId return name, sex, portraitId, frameId end end return name, sex, portraitId, frameId end --获取军团太尉名字\头像ID function ChannelChat_Controller.GetGuildJunshiElderInfo() local name="" local sex = nil local hasJunshiElder local armyCmdAcid = MDL.Guild.GetMyGuildInfo().armyCmdAcid local portraitId local frameId for i, v in ipairs(ChannelChat_Controller.GetGuildMembers()) do if v.roleInfo.acid ==armyCmdAcid then hasJunshiElder=true name=v.roleInfo.name sex = v.roleInfo.sex portraitId = v.roleInfo.PortraitId frameId = v.roleInfo.FrameId end end if hasJunshiElder then return name, sex, portraitId, frameId else return UIUtils.GetLocalizedTxt(Const_IDS.IDS_GuildApply_Label7), portraitId end end --是否为斥候 function ChannelChat_Controller.IsScouts(acid) local scoursList=MDL.GuildWar.GetScoutsList() if scoursList ~=nil then for i, v in ipairs(scoursList) do if v.headInfo.acid ==acid then return true end end else return false end end --开麦提示 function ChannelChat_Controller.SetHasShowMicTip() HasShowMicTip=true end function ChannelChat_Controller.GetHasShowMicTip() return HasShowMicTip end --收取服务器上该语音频道收听人数 function ChannelChat_Controller.SetVoiceListenCount(type,num) VoiceRoomListenerCount[type]=num end function ChannelChat_Controller.AcquireCurVoiceListenCount(roomType) local roomId = CTL.VoiceRoom.GetPreEnterVoiceRoomID(roomType) if string.isNilOrEmpty(roomId) == false then MDL.ChannelChat.AcquireVoiceRoomNum(roomType, roomId) end end --获取该语音频道人数 function ChannelChat_Controller.GetVoiceListenCount(type) return VoiceRoomListenerCount[type] end --1语音聊天中 2语音收听中 3语音发言中 4成员语音聊天中 function ChannelChat_Controller.GetVoiceRoomWarnIDS(roomType, warnType) if roomType == MDL.VoiceRoom.VoiceRoomType.Guild then if warnType == 1 then return Const_IDS.IDS_GuildVoiceChat_HavePlayer elseif warnType == 2 then return Const_IDS.IDS_GuildVoiceChat_ListenState elseif warnType == 3 then return Const_IDS.IDS_GuildVoiceChat_SpeakState else return Const_IDS.IDS_GuildVoiceChat_OtherChannelHint end elseif roomType == MDL.VoiceRoom.VoiceRoomType.DragonArtery then if warnType == 1 then return Const_IDS.IDS_DragonArtey_Talk1 elseif warnType == 2 then return Const_IDS.IDS_DragonArtey_Talk2 elseif warnType == 3 then return Const_IDS.IDS_DragonArtey_Talk3 else return Const_IDS.IDS_DragonArtey_Talk4 end end end function ChannelChat_Controller.SetLastSelectChannelChat(chatCfgId) private.LastSelectChannelChatCfgId = chatCfgId end function ChannelChat_Controller.GetLastSelectChannelChat() if private.LastSelectChannelChatCfgId and private.LastSelectChannelChatCfgId > 0 then return private.LastSelectChannelChatCfgId else return MDL.ChannelChat.ChannelCfgId.World end end ------------------势力实时语音相关 end------------------------ function ChannelChat_Controller.UseSuoNaItem() UIManager.CloseView(Const_UI_Lua.UIEnum.UIBagMain) UIManager.OpenView(Const_UI_Lua.UIEnum.UIChannelChatMain, {LastMsgChannelId = nil}) EventSystem.Dispatch(EventID.UI_ChannelChat_OpenSuoNa) end --region 语音聊天相关:语音录制与播放 function private.CleanVoice() if GameAppInfo.IsVersionGreaterThan15000() or GameAppInfo.IsChinesePackage() then if LuaExt.DirectoryCreate(VOICE_ROOT_PATH) == false then --将超过1天的语音删除 LuaExt.DirectoryDeleteObsoleteFiles(VOICE_ROOT_PATH, "*.ptt", true, UTL.Time.TotalSecondsOneDay) end end end function private.CreateVoicePath() if private.acidSymbol == nil then --acid带了冒号: 不能作为文件路径 private.acidSymbol = string.gsub(BattleDataGetter.GetAcID(), ":", "") end if UNITY_STANDALONE and not UNITY_EDITOR then return string.format("%s/%s_%s.silk", VOICE_ROOT_PATH, private.acidSymbol, UTL.Time.GetServerTimestamp()) else return string.format("%s/%s_%s.ptt", VOICE_ROOT_PATH, private.acidSymbol, UTL.Time.GetServerTimestamp()) end end function ChannelChat_Controller.StartRecordVoice(channelID, isPersonal) private.isRecordWhilePlaying = ChannelChat_Controller.TryStopPlayingVoice(false) if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIChannelChatAudio) then return end if private.isRecordStartFail then SDKUtil.CancelRecording() private.isRecordStartFail = false end local recordFilePath = private.CreateVoicePath() private.recordVoiceChannelID = channelID private.recordVoiceChatType = isPersonal and chat_pb.Personal or chat_pb.Room private.recordVoicePath = recordFilePath local recordFileFullPath = recordFilePath if LuaExt.ToUserDataFilePath then recordFileFullPath = LuaExt.ToUserDataFilePath(recordFilePath) else recordFileFullPath = UnityEngine.Application.persistentDataPath .. "/" .. recordFilePath end SDKUtil.StartRecordVoice(recordFileFullPath) end function private.OnRecordStartResult(result) if private.recordVoiceTimer then TimerUtil.Remove(private.recordVoiceTimer) private.recordVoiceTimer = nil end if result == "true" and UnityEngine.Input.anyKey then private.recordVoiceTimestamp = UTL.Time.GetServerTimestamp() private.recordVoiceTimer = TimerUtil.Interval(ChannelChat_Controller.StopRecordVoice, AUDIO_DURATION_MAX, 1) UIManager.OpenView(Const_UI_Lua.UIEnum.UIChannelChatAudio) else if UNITY_IOS then SDKUtil.CancelRecording() end private.isRecordStartFail = true private.OnStopRecordVoice() end end function ChannelChat_Controller.IsRecordingVoice() return private.recordVoiceTimer ~= nil end --超过录制时间之前结束录制 function ChannelChat_Controller.StopRecordVoice() if private.recordVoiceTimer then SDKUtil.StopRecordVoice() end private.OnStopRecordVoice() end --用户主动取消录制 function ChannelChat_Controller.CancelRecordVoice() if private.recordVoiceTimer then SDKUtil.CancelRecording() CTL.Tips.AddTipsMsg(Const_IDS["IDS_AudioChat_CancelSending3"]) end private.OnStopRecordVoice() end function private.OnStopRecordVoice() UIManager.CloseView(Const_UI_Lua.UIEnum.UIChannelChatAudio) if private.recordVoiceTimer then TimerUtil.Remove(private.recordVoiceTimer) private.recordVoiceTimer = nil end EventSystem.Dispatch(EventID.UI_ChannelChat_OnRecordTimeEnd) if private.isRecordWhilePlaying then private.isRecordWhilePlaying = false MDL.ChannelChat.TryPlayNextVoice() end end function private.OnRecordFinishFail() if private.recordVoiceTimestamp and UTL.Time.GetServerTimestamp() - private.recordVoiceTimestamp <= 1 then CTL.Tips.AddTipsMsg(Const_IDS.IDS_AudioChat_ShortTime) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_AudioChat_Unrecognized) end private.recordVoiceTimestamp = nil private.OnStopRecordVoice() end function private.OnRecordFinishSuccess(content, recordPath, duration) private.OnStopRecordVoice() --录制时长过短 if private.recordVoiceTimestamp and UTL.Time.GetServerTimestamp() - private.recordVoiceTimestamp <= 1 then if not UNITY_IOS or duration > 0.1 then CTL.Tips.AddTipsMsg(Const_IDS.IDS_AudioChat_ShortTime) end private.recordVoiceTimestamp = nil return end --录制时长超过配置时间 if duration > AUDIO_DURATION_MAX then CTL.Tips.AddTipsMsg(Const_IDS.IDS_AudioChat_Unrecognized) return end --当翻译文本为空时,不允许发送 if string.isNilOrEmpty(content) then CTL.Tips.AddTipsMsg(Const_IDS.IDS_AudioChat_Unrecognized) return end MDL.ChannelChat.SendAudioChatMsg(private.recordVoiceChannelID, content, private.recordVoiceChatType, private.recordVoicePath, duration) end function ChannelChat_Controller.PlayRecordVoice(chatData) private.playingRecordChatData = chatData local recordPath, duration, uuid = chatData.voiceRecordPath, chatData.voiceDuration, chatData.uuid --先判断本地是否有该语音文件 if LuaExt.FileExists(recordPath) == false then --需要先获取语音下载权限 MDL.ChannelChat.GameVoiceChatMsgReq(chatData.voiceChatUrl) return end ChannelChat_Controller.TryStopPlayingVoice(false) private.playingRecordVoiceTimestamp = UTL.Time.GetServerTimestamp() MDL.ChannelChat.SaveRecordVoiceRedState(uuid) local recordFileFullPath = recordPath if LuaExt.ToUserDataFilePath then recordFileFullPath = LuaExt.ToUserDataFilePath(recordPath) else recordFileFullPath = UnityEngine.Application.persistentDataPath .. "/" .. recordPath end SDKUtil.PlayRecordFile(recordFileFullPath) --延迟1秒停止 private.playVoiceTimer = TimerUtil.Interval(private.OnVoicePlayFinish, duration + 1, 1) EventSystem.Dispatch(EventID.UI_ChannelChat_StartPlayVoice) end function private.TryAbortDownloadVoice() if private.downloadVoiceHandle then HttpReq.AbortHttpDownload(private.downloadVoiceHandle) private.downloadVoiceHandle = nil end end function ChannelChat_Controller.DownloadVoice(voiceChatUrl) --请求下载语音文件 再回调到PlayRecordVoice private.TryAbortDownloadVoice() private.downloadVoiceHandle = HttpReq.StartHttpDownload(voiceChatUrl, private.playingRecordChatData.voiceRecordPath, private.OnDownloadVoiceCallback) end function private.OnDownloadVoiceCallback(isSuccess, statusCode) private.downloadVoiceHandle = nil if isSuccess then ChannelChat_Controller.PlayRecordVoice(private.playingRecordChatData) end end function ChannelChat_Controller.TryStopPlayingVoice(isContinue) if private.playVoiceTimer then SDKUtil.StopPlayFile() TimerUtil.Remove(private.playVoiceTimer) private.OnVoicePlayFinish(isContinue) return true end return false end function private.OnVoicePlayFinish(isContinue) private.playingRecordChatData = nil private.playVoiceTimer = nil private.playingRecordVoiceTimestamp = nil EventSystem.Dispatch(EventID.UI_ChannelChat_FinishPlayVoice) if isContinue == nil or isContinue == true then MDL.ChannelChat.TryPlayNextVoice() end end function ChannelChat_Controller.IsPlayingVoice() return private.playingRecordVoiceTimestamp ~= nil and private.playingRecordChatData ~= nil end function ChannelChat_Controller.GetPlayingVoicePassedTime(recordPath) if private.playingRecordVoiceTimestamp == nil then return nil end if private.playingRecordChatData and private.playingRecordChatData.voiceRecordPath == recordPath then local passTime = UTL.Time.GetServerTimestamp() - private.playingRecordVoiceTimestamp return passTime end return nil end --是否能播放语音 function ChannelChat_Controller.CanPlayVoice(chatData, isTip) if ChannelChat_Controller.IsEnableVoiceChat() == false then return false end --黑名单 if MDL.ChannelChat.IsMsgFromBlack(chatData) then return false end --url为空 if string.isNilOrEmpty(chatData.voiceChatUrl) then return false end --文本为空 if string.isNilOrEmpty(chatData.content) then return false end --有敏感字 if string.match(chatData.content,"*") then if isTip then CTL.Tips.AddTipsMsg(Const_IDS["IDS_AudioChat_Shield"]) end return false end return true end --手动点击播放语音 function ChannelChat_Controller.ManualPlayVoice(chatData) if ChannelChat_Controller.CanPlayVoice(chatData, true) == false then return end if ChannelChat_Controller.GetPlayingVoicePassedTime(chatData.voiceRecordPath) then --相同语音,停止,不再自动播放,此时清空自动播放队列 ChannelChat_Controller.TryStopPlayingVoice(false) MDL.ChannelChat.RemovePlayVoiceQueue() return end if ChannelChat_Controller.IsPlayingVoice() then --停止当前播放的语音,并将早于chatData的语音从播放队列移除 ChannelChat_Controller.TryStopPlayingVoice(false) MDL.ChannelChat.TryBreakPlayVoiceQueue(chatData.msgTime) end ChannelChat_Controller.PlayRecordVoice(chatData) end function ChannelChat_Controller.IsEnableVoiceChat() if GameAppInfo.IsMacPackage() then return false end return MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.VoiceChat) end function ChannelChat_Controller.SetMsgTitle(collection, channelId, roleInfo, isSelf, msgChannelId) local chatCfgData = nil if roleInfo.heroId == nil or roleInfo.heroId <= 0 then chatCfgData = DataSheetManager.Chat:GetDataByID(MDL.ChannelChat.ChannelCfgId.System) else chatCfgData = DataSheetManager.Chat:GetDataByID(msgChannelId) end local patternId = 1 if chatCfgData and chatCfgData.ChatPattern > 0 then patternId = chatCfgData.ChatPattern end local showTitleIds = DataSheetManager.ChatPattern:GetDataByID(patternId).PatternID if table.containValue(showTitleIds, TitleEnum.Channel) or MDL.ChannelChat.IsMixtureChannelByCfgId(channelId) then UIUtils.SetActive(collection.groupBG, true) CTL.ChannelChat.SetChannelBgColor(msgChannelId, collection.groupBG, collection.txt_Channel, roleInfo.serId, roleInfo.heroId and roleInfo.heroId > 0) else UIUtils.SetActive(collection.groupBG, false) end if roleInfo.heroId == nil or roleInfo.heroId <= 0 then return end if table.containValue(showTitleIds, TitleEnum.Country) then if roleInfo.countryId > 0 then if collection.Loc_Country.CurState == 0 then collection.group_CountryState:SetState( roleInfo.countryId - 1) end CTL.Country.SetCountryJob(collection.img_Title, collection.img_CountryBg, roleInfo.countryId, roleInfo.countryOfficial) CTL.Country.SetOverseasCountryImage(collection.Loc_Country.CurState, collection.lab_CountryTC, roleInfo.countryId, roleInfo.countryOfficial) UIUtils.SetActive(collection.img_CountryBg, true) else UIUtils.SetActive(collection.img_CountryBg, false) end else UIUtils.SetActive(collection.img_CountryBg, false) end if table.containValue(showTitleIds, TitleEnum.Official) then UIUtils.SetLabel(collection.lab_official, CTL.OfficialPosition.GetModelNameShow(roleInfo.officialId)) else collection.lab_official.text = nil end if table.containValue(showTitleIds, TitleEnum.GuildFrame) and roleInfo.emblemFrame > 0 then CTL.Guild.SetGuildEmblem(collection.img_GuildBg, collection.txt_Guild, roleInfo.emblemFrame, roleInfo.emblemContent) UIUtils.SetActive(collection.img_GuildBg, true) else UIUtils.SetActive(collection.img_GuildBg, false) end if table.containValue(showTitleIds, TitleEnum.GuildLeader) then if roleInfo.jobTitle == MDL.Guild.JobEnum.Leader then UIUtils.SetLabelText(collection.lab_Leader, Const_IDS.IDS_Ranking_GuildOwner) else collection.lab_Leader.text = nil end else collection.lab_Leader.text = nil end if table.containValue(showTitleIds, TitleEnum.GuildOfficial) then local jobData = DataSheetManager.GuildJob:GetDataByID(roleInfo.jobTitle) if jobData then UIUtils.SetLabelText(collection.lab_Leader, Const_IDS[jobData.JobName]) else collection.lab_Leader.text = nil end else collection.lab_Leader.text = nil end if table.containValue(showTitleIds, TitleEnum.PlayerName) then if isSelf then UIUtils.SetLabelText(collection.lab_Name, Const_IDS.IDS_Chat_Me) else UIUtils.SetLabel(collection.lab_Name, roleInfo.senderName) end else end if table.containValue(showTitleIds, TitleEnum.PlayerServer) then collection.lab_Server.text = string.format(DIF_SERVER_FORMAT, roleInfo.serId) else collection.lab_Server.text = nil end if table.containValue(showTitleIds, TitleEnum.PlayerGender) then if isSelf then CTL.Player.OperateGenderImage(collection.image_Gender, MDL.Player.GetSelfGender()) else CTL.Player.OperateGenderImage(collection.image_Gender, roleInfo.sex) end else UIUtils.SetActive(collection.image_Gender, false) end end local isDead = false function ChannelChat_Controller.OnSelfDead(dead) isDead = dead if isDead then UIManager.CloseView(Const_UI_Lua.UIEnum.UIChannelChatMain) end end function ChannelChat_Controller.SelfIsDead() return isDead end function private.OnReceiveNewMsg(chatData, isNewMsg) if isNewMsg and MDL.ChannelChat.IsCurrentChannelByChannelId(chatData.targetId) then if chatData.heroId and chatData.heroId > 0 then local entity = nil if chatData.isSelf then entity = BattleDataGetter.GetCurEntity() else if BattleDataGetter.IsNoBattleLevel() then entity = SyncMoveManager.GetEntityByAcid(chatData.fromId) else local playInfo = BattleDataGetter.GetPlayerInfoByAcid(chatData.fromId) if playInfo then entity = BattleDataGetter.GetPlayerActiveEntity(playInfo.playerID) end end end if entity then local renderEntity = entity.ExpEntity.RenderEntity EventSystem.Dispatch(EventID.UIBattle_Element_SetHeadUI, renderEntity, EntityHeadUIModule.HeadUIType.CurrentChannelMsg, chatData.content) private.StartShowCurrentChannelTime(renderEntity) end end end end function private.StartShowCurrentChannelTime(renderEntity) private.showCurrentChannelTimeList[renderEntity] = Time.realtimeSinceStartup + 5 if private.showCurrentChannelTimeHandle == nil then private.showCurrentChannelTimeHandle = TimerUtil.Interval(private.CheckShowCurrentChannelTime, 1, -1) end end function private.CheckShowCurrentChannelTime() local curTime = Time.realtimeSinceStartup for renderEntity, endTime in pairs(private.showCurrentChannelTimeList) do if curTime >= endTime then private.showCurrentChannelTimeList[renderEntity] = nil EventSystem.Dispatch(EventID.UIBattle_Element_RemoveHeadUI, renderEntity, EntityHeadUIModule.HeadUIType.CurrentChannelMsg) end end if next(private.showCurrentChannelTimeList) == nil then TimerUtil.Remove(private.showCurrentChannelTimeHandle) private.showCurrentChannelTimeHandle = nil end end --endregion return ChannelChat_Controller