local UIChannelChatMain = require("View/ChannelChat/UIChannelChatMain")
local UIPKRoomChatView = UIViewClass(UIChannelChatMain)
local SelfChatBg = ConstAssetPathConfig.SelfChatBg
local OtherChatBg = ConstAssetPathConfig.OtherChatBg
local EMOJI_PREFIX_STR = "[%s]"
local SYSTEM_PREFIX_TAG = MDL.ChannelChat.ChannelCfgId.System
function UIPKRoomChatView:OnBaseOpened()
self.effectPlayDic = {} -- OVERRIDER
UIUtils.SetCanvasSortingOrderByMainCanvas(self.gameObject:GetComponent(typeof(UnityEngine.Canvas)), self.group_Condition, CTL.Character.UpOrder.ChannelChat)
self:InitInfo()
self:LoadChannel()
end
function UIPKRoomChatView:InitInfo()
self:RegistSystemEvent(EventID.ApplicationPause, self.SetDragToEndByApplicationPause)
self:RegistSystemEvent(EventID.UI_ChannelChat_OnDrag, self.OnDragEvent)
self:RegistSystemEvent(EventID.UI_ChannelChat_GetUnReadShow, self.GetUnReadShow)
self:RegistSystemEvent(EventID.UI_ChannelChat_IsScrollBarInTheEnd, self.IsScrollBarInTheEnd)
self:RegistSystemEvent(EventID.UI_ChannelChat_ClearInputField, self.ClearInputField)
self:RegistSystemEvent(EventID.ChannelChat_ReceiveNewMsg, self.OnNewMsg)
self:RegistSystemEvent(EventID.UI_UpdateBlack,self.OnBanBlackMsg)
self:RegistSystemEvent(EventID.UI_ChannelChat_TranslateUpdate, self.UpdateTranslationIndex)
end
function UIPKRoomChatView:LoadChannel()
self.CurrentChannelCfgID, self.channelName = CTL.CustomRoom.JoinPKRoomChatChannel()
MDL.ChannelChat.SetChannelChatIsOpen(true)
if self.CurrentChannelCfgID ~= nil then
self:IsDisplayNewMsgTips(false)
end
local chatList = MDL.ChannelChat.GetChannelChatList(self:GetChannelID())
for i, v in ipairs(chatList) do
if not MDL.ChannelChat.IsMsgFromBlack(v) then
if v.isSelf then
self.obj_ScrollPanel:AddData(v,0)
elseif v.heroId == nil or v.heroId <= 0 then
self.obj_ScrollPanel:AddData(v,2)
else
self.obj_ScrollPanel:AddData(v,1)
end
end
end
if #chatList > 0 then
self.obj_ScrollPanel:MoveEnd()
end
end
function UIPKRoomChatView:OnNewMsg(msgData, isNewMsg)
local v = msgData
if v and not MDL.ChannelChat.IsMsgFromBlack(v) and self:GetChannelID() == v.targetId then
if isNewMsg then
if v.isSelf then
self.obj_ScrollPanel:AddDynamicData(v,0)
elseif v.heroId == nil or v.heroId <= 0 then
self.obj_ScrollPanel:AddDynamicData(v,2)
else
self.obj_ScrollPanel:AddDynamicData(v,1)
end
self.obj_ScrollPanel:MoveEnd()
else
--历史记录会倒序,倒着插进来
if v.isSelf then
self.obj_ScrollPanel:InsertData(0, v, 0)
elseif v.heroId == nil or v.heroId <= 0 then
self.obj_ScrollPanel:InsertData(0, v, 2)
else
self.obj_ScrollPanel:InsertData(0, v, 1)
end
self:StopRepeatFunc(self.DelayMoveEnd)
self:StartRepeatFunc(self.DelayMoveEnd, 0.1, 1)
end
end
end
function UIPKRoomChatView:DelayMoveEnd()
self.obj_ScrollPanel:MoveEnd()
end
function UIPKRoomChatView:OnButtonClicked(comp)
if comp == self.event_Send then
--处于禁言状态
if MDL.HomeMain.GetSilenceBuff() then
CTL.Tips.AddTipsMsg(Const_IDS.IDS_OfficialPrivilege_FailInSend)
self:RefreshLoopScroll()
return
end
self:OnClickSend()
elseif comp == self.event_UnRead then
self:OnClickUnRead()
elseif comp == self.event_Face then
self:OnClickFaceBtn()
elseif comp == self.event_Condition_BackBtn then
UIUtils.SetActive(self.group_Condition.gameObject, false)
elseif comp == self.event_FriendChanel then
UIManager.OpenView(Const_UI_Lua.UIEnum.UIChannelChatMain, {LastMsgChannelId = nil})
end
end
function UIPKRoomChatView:OnClickFaceBtn()
local isActive = self.group_Condition.gameObject.activeSelf
UIUtils.SetActive(self.group_Condition.gameObject, not isActive)
self.Emoji_Condition:ReloadAll(MDL.ChannelChat.GetSortedEmojiList())
end
function UIPKRoomChatView:SendMsg(content)
--处于禁言状态
if MDL.HomeMain.GetSilenceBuff() then
CTL.Tips.AddTipsMsg(Const_IDS.IDS_OfficialPrivilege_FailInSend)
return
end
if MDL.ChannelChat.CanSendMsg() then
local msg = content
if MDL.ChannelChat.IsJoinChannel(self.CurrentChannelCfgID) and not CTL.ChannelChat.IsOutOfLength(msg, self:GetChannelID()) then
CTL.ChannelChat.SendTextMsg(msg, self:GetChannelID(), false)
end
else
CTL.Tips.AddTipsMsg(MDL.ChannelChat.GetForbiddenMsg())
end
end
function UIPKRoomChatView:OnCellInit(scrollRect, index, cellTable, data)
if scrollRect == self.Emoji_Condition then
UIUtils.SetLabel(cellTable.txt_emoji, string.format(EMOJI_PREFIX_STR, data.ID))
elseif scrollRect == self.obj_ScrollPanel then
if index == 0 then
self.topLineMsgData = data
local width, height = cellTable.cell.transform:GetSizeDelta()
self.topLineMsgOffset = height
end
local isSelf = data.isSelf
local curChannelId = nil
curChannelId = self.CurrentChannelCfgID
CTL.ChannelChat.SetMsgTitle(cellTable, self.CurrentChannelCfgID, data, isSelf, self.CurrentChannelCfgID)
-- 默认使用跨服标签
if data.heroId == nil or data.heroId <= 0 then
-- 设置频道文字空格(需要在设置text之前设置)
CTL.ChannelChat.SetChannelBgColor(SYSTEM_PREFIX_TAG, cellTable.groupBG, cellTable.txt_Channel, data.serId, not string.isNilOrEmpty(data.senderName))
cellTable.lab_Content.text = CTL.ChannelChat.GetChannelBlankSpace(SYSTEM_PREFIX_TAG, data.serId) .. data.content
if UIUtils.GetFirstLineHaveEmojiByEmojiText(cellTable.lab_Content) then
UIUtils.SetRectPosition(cellTable.groupBG, 0, -37)
else
UIUtils.SetRectPosition(cellTable.groupBG, 0, 0)
end
else
CTL.ChannelChat.SetChannelBgColor(self.CurrentChannelCfgID, cellTable.groupBG, cellTable.txt_Channel, data.serId, not string.isNilOrEmpty(data.senderName))
cellTable.lab_Content.text = CTL.ChannelChat.GetChannelBlankSpace(self.CurrentChannelCfgID, data.serId) .. data.content
if isSelf then
UIUtils.SetLabelText(cellTable.lab_Name, Const_IDS.IDS_Chat_Me)
CTL.Player.OperateGenderImage(cellTable.image_Gender, MDL.Player.GetSelfGender())
CTL.Character.SetSelfPortraitAndFrame(cellTable.UIHeroHead190, data.level)
else
UIUtils.SetLabel(cellTable.lab_Name, data.senderName)
CTL.Player.OperateGenderImage(cellTable.image_Gender, data.sex)
CTL.Character.SetPortraitAndFrame(cellTable.UIHeroHead190, data.portraitId, data.frameId, data.level)
end
local roleId = data.heroId
UTL.Item.SetHeroHeadTemplate(cellTable.UIHeroHead, roleId, UTL.Item.GetNobilityByTeamLevel(data.level, 2))
UIUtils.SetImageByAssetBundle(cellTable.group_Content, isSelf and SelfChatBg or OtherChatBg)
local trumpetType = data.trumpetType and data.trumpetType or -1
UIUtils.SetActive(cellTable.icon_Suona, trumpetType > 0)
if trumpetType > 0 then
local suonaTxt = UTL.Color.FormatTextByColor(suonaTxtColor, data.content)
cellTable.lab_Content.text = suonaTxt
if trumpetType == MDL.ChannelChat.TrumtType.Cross then
cellTable.obg_SuoNaBgState:SetState(1)
cellTable.state_IconSuoNa:SetState(1)
elseif trumpetType == MDL.ChannelChat.TrumtType.WarZone then
cellTable.obg_SuoNaBgState:SetState(3)
cellTable.state_IconSuoNa:SetState(3)
else
cellTable.obg_SuoNaBgState:SetState(2)
cellTable.state_IconSuoNa:SetState(2)
end
else
cellTable.lab_Content.text = data.content
cellTable.obg_SuoNaBgState:SetState(0)
cellTable.state_IconSuoNa:SetState(0)
end
self:SetTitleColor(data.fromId, cellTable.lab_Name)
CTL.Guild.SetGuildEmblem(cellTable.img_GuildBg, cellTable.txt_Guild, data.emblemFrame, data.emblemContent)
UIUtils.SetLabel(cellTable.lab_official, CTL.OfficialPosition.GetModelNameShow(data.officialId))
if self:ProcessVoiceChatData(data, cellTable) == false then
if not isSelf then --翻译相关
local pureText = MDL.Translate.GetPureText(data.uuid)
local translateText = MDL.Translate.GetTranslateText(data.uuid)
if not string.isNilOrEmpty(translateText) then
UIUtils.SetActive(cellTable.btn_Translate, false)
UIUtils.SetActive(cellTable.lab_Translation, true)
cellTable.lab_Translation.text = translateText
UnityEngine.UI.LayoutRebuilder.ForceRebuildLayoutImmediate(cellTable.sprite_ChatMsgBg)
else
UIUtils.SetActive(cellTable.btn_Translate, not string.isNilOrEmpty(pureText))
UIUtils.SetActive(cellTable.lab_Translation, false)
end
cellTable.anim_Translate:StopAnim(false)
cellTable.anim_Translate.transform:SetLocalEulerAngles(nil, nil, 0)
cellTable.btn_Translate:SetGray(false, true)
end
end
end
end
end
function UIPKRoomChatView:OnCellClicked(scrollRect, index, cellTable, target, data)
if scrollRect == self.Emoji_Condition then
-- 点击表情
self:OnCommonClickEmoji(data)
elseif scrollRect == self.obj_ScrollPanel then
-- 头像点击
if target.transform.name == "img_PlayerAvatarBg" then
CTL.PlayerInteract.OpenFriendInteractView(data.fromId, MDL.PlayerInteract.OccasionType.ChannelChat, {chatContent = data.content})
elseif cellTable.btn_Translate and target == cellTable.btn_Translate then
MDL.Translate.TranslateReq(data.uuid, index)
cellTable.anim_Translate:PlayAnim()
cellTable.btn_Translate:SetGray(true, false)
end
end
end
function UIPKRoomChatView:OnCommonClickEmoji(data)
local emojiShow = string.format("[%s]", UIUtils.GetLocalizedTxt(Const_IDS[data.EmojiName]))
local msg = self.obj_InputField.text
msg = msg .. emojiShow
self:SetInputTextAndMoveEnd(msg)
end
function UIPKRoomChatView:GetChannelID()
return MDL.ChannelChat.GetChannelIdByCfgID(self.CurrentChannelCfgID)
end
function UIPKRoomChatView:GetChannelBlankSpace(serId)
--频道标题字符空格补齐字符串
local cacheChannelBlankSpace = {}
if cacheChannelBlankSpace == nil or cacheChannelBlankSpace[serId] == nil then
local str = string.format("S.%d", serId)
cacheChannelBlankSpace = cacheChannelBlankSpace[MDL.ChannelChat.ChannelCfgId.WarZone] or {}
cacheChannelBlankSpace[serId] = string.format("%saaa", str)
end
if GameAppInfo.IsJapanesePackage() then
-- 日服频道翻译过长,这里空格多加一些
cacheChannelBlankSpace[serId] = "%saaaaaa"
return cacheChannelBlankSpace[serId]
else
return cacheChannelBlankSpace[serId]
end
end
return UIPKRoomChatView