local ChatTipView = {} local SYS_MSG_TYPE = { [0] = {name = Language[10350]}, [1] = {name = Language[10351]}, [2] = {name = Language[10352]}, [9] = {name = Language[10352]} } local VIEW_TYPE = { MAIN = 1, GUILD = 2, } function ChatTipView:New(gameObject) local b = {} b.gameObject = gameObject b.transform = gameObject.transform setmetatable(b, { __index = ChatTipView }) return b end --初始化组件(用于子类重写) function ChatTipView:InitComponent() self.spLoader = SpriteLoader.New() self.btn = Util.GetGameObject(self.transform, "button") self.content = Util.GetGameObject(self.transform, "content"):GetComponent("Text") self.redpot = Util.GetGameObject(self.transform, "icon/redpot") self.redPackage = Util.GetGameObject(self.transform, "Image") end --绑定事件(用于子类重写) function ChatTipView:BindEvent() Util.AddClick(self.btn, function() local jumpType = 1 if self._ViewType == VIEW_TYPE.GUILD then jumpType = 2 end local tabIndex = 3 if not self.channel then tabIndex = 3 elseif self.channel == CHAT_CHANNEL.SYSTEM then tabIndex = 5 elseif self.channel == CHAT_CHANNEL.FAMILY then tabIndex = 2 elseif self.channel == CHAT_CHANNEL.GLOBAL then tabIndex = 3 elseif self.channel == CHAT_CHANNEL.JUMP_SERVER then tabIndex = 4 end UIManager.OpenPanel(UIName.ChatPanel, tabIndex, jumpType) end) Util.AddClick(self.redPackage,function() UIManager.OpenPanel(UIName.RedPacketPanel,3) Game.GlobalEvent:DispatchEvent(GameEvent.GuildRedPacket.AuoGetRedPackage) end) end --添加事件监听(用于子类重写) function ChatTipView:AddListener() Game.GlobalEvent:AddEvent(GameEvent.Chat.OnMainChatChanged, self.RefreshChatShow, self) Game.GlobalEvent:AddEvent(GameEvent.Chat.OnRedPackageNumChanged, self.CheckRedPackageShow, self) BindRedPointObject(RedPointType.Chat, self.redpot) end --移除事件监听(用于子类重写) function ChatTipView:RemoveListener() Game.GlobalEvent:RemoveEvent(GameEvent.Chat.OnMainChatChanged, self.RefreshChatShow, self) Game.GlobalEvent:RemoveEvent(GameEvent.Chat.OnRedPackageNumChanged, self.CheckRedPackageShow, self) ClearRedPointObject(RedPointType.Chat, self.redpot) end function ChatTipView:CheckRedPackageShow() if MyGuildManager.PackageNum>0 and self.redPackage.gameObject then self.redPackage.gameObject:SetActive(true) LogError("///////////") --self.freeBtnAnim.enabled=true else self.redPackage.gameObject:SetActive(false) end end --界面打开时调用(用于子类重写) function ChatTipView:OnOpen(viewType) self._ViewType = viewType or VIEW_TYPE.MAIN if MyGuildManager.PackageNum>0 then self.redPackage.gameObject:SetActive(true) else self.redPackage.gameObject:SetActive(false) end self:RefreshChatShow() end -- 刷新聊天显示 function ChatTipView:RefreshChatShow() local msg = ChatManager.GetMainPanelShowMsg() local content = "" local data = {} if msg then if msg.channel == CHAT_CHANNEL.SYSTEM then data = msg.chat local sTypeInfo = SYS_MSG_TYPE[data.messageType] if sTypeInfo then content = string.format("[%s]:%s", sTypeInfo.name, data.msg) else content = string.format(Language[12018], data.msg) end elseif msg.channel == CHAT_CHANNEL.GLOBAL then local chat = ChatManager.AnalysisGlobalChat(msg.chat.msg) content = string.format(Language[12019], msg.chat.senderName, chat.content) elseif msg.channel == CHAT_CHANNEL.FAMILY then local chat = ChatManager.AnalysisGlobalChat(msg.chat.msg) content = string.format(Language[12020], msg.chat.senderName, chat.content) elseif msg.channel == CHAT_CHANNEL.JUMP_SERVER then local chat = ChatManager.AnalysisGlobalChat(msg.chat.msg) content = string.format("[跨服]%s:%s", msg.chat.senderName, chat.content) end self.channel = msg.channel end self.content.text = content end -- 开始聊天数据刷新 function ChatTipView:StartCheck() ChatManager.StartChatDataUpdate() end -- 停止聊天数据刷新 function ChatTipView:StopCheck() ChatManager.StopChatDataUpdate() end --界面关闭时调用(用于子类重写) function ChatTipView:OnClose() self.spLoader:Destroy() end return ChatTipView