2020-08-25 15:46:38 +08:00
|
|
|
|
local ChatTipView = {}
|
2020-05-09 13:31:21 +08:00
|
|
|
|
|
|
|
|
|
local SYS_MSG_TYPE = {
|
2021-03-02 16:53:12 +08:00
|
|
|
|
[0] = {name = Language[10350]},
|
|
|
|
|
[1] = {name = Language[10351]},
|
2021-03-11 17:06:08 +08:00
|
|
|
|
[2] = {name = Language[10352]},
|
|
|
|
|
[9] = {name = Language[10352]}
|
2020-05-09 13:31:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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()
|
2021-04-21 13:12:04 +08:00
|
|
|
|
self.spLoader = SpriteLoader.New()
|
2020-05-09 13:31:21 +08:00
|
|
|
|
self.btn = Util.GetGameObject(self.transform, "button")
|
|
|
|
|
self.content = Util.GetGameObject(self.transform, "content"):GetComponent("Text")
|
|
|
|
|
self.redpot = Util.GetGameObject(self.transform, "icon/redpot")
|
2021-05-21 14:47:04 +08:00
|
|
|
|
self.redPackage = Util.GetGameObject(self.transform, "Image")
|
2020-05-09 13:31:21 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--绑定事件(用于子类重写)
|
|
|
|
|
function ChatTipView:BindEvent()
|
|
|
|
|
Util.AddClick(self.btn, function()
|
2021-07-30 14:07:08 +08:00
|
|
|
|
local jumpType = 1
|
|
|
|
|
if self._ViewType == VIEW_TYPE.GUILD then
|
|
|
|
|
jumpType = 2
|
2020-05-09 13:31:21 +08:00
|
|
|
|
end
|
2021-07-30 14:07:08 +08:00
|
|
|
|
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)
|
2020-05-09 13:31:21 +08:00
|
|
|
|
end)
|
2021-05-21 14:47:04 +08:00
|
|
|
|
Util.AddClick(self.redPackage,function()
|
|
|
|
|
UIManager.OpenPanel(UIName.RedPacketPanel,3)
|
|
|
|
|
Game.GlobalEvent:DispatchEvent(GameEvent.GuildRedPacket.AuoGetRedPackage)
|
|
|
|
|
end)
|
2020-05-09 13:31:21 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--添加事件监听(用于子类重写)
|
|
|
|
|
function ChatTipView:AddListener()
|
|
|
|
|
Game.GlobalEvent:AddEvent(GameEvent.Chat.OnMainChatChanged, self.RefreshChatShow, self)
|
2021-05-21 14:47:04 +08:00
|
|
|
|
Game.GlobalEvent:AddEvent(GameEvent.Chat.OnRedPackageNumChanged, self.CheckRedPackageShow, self)
|
2020-05-09 13:31:21 +08:00
|
|
|
|
BindRedPointObject(RedPointType.Chat, self.redpot)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--移除事件监听(用于子类重写)
|
|
|
|
|
function ChatTipView:RemoveListener()
|
|
|
|
|
Game.GlobalEvent:RemoveEvent(GameEvent.Chat.OnMainChatChanged, self.RefreshChatShow, self)
|
2021-05-21 14:47:04 +08:00
|
|
|
|
Game.GlobalEvent:RemoveEvent(GameEvent.Chat.OnRedPackageNumChanged, self.CheckRedPackageShow, self)
|
2020-05-09 13:31:21 +08:00
|
|
|
|
ClearRedPointObject(RedPointType.Chat, self.redpot)
|
|
|
|
|
end
|
|
|
|
|
|
2021-05-21 14:47:04 +08:00
|
|
|
|
function ChatTipView:CheckRedPackageShow()
|
2021-05-26 16:03:28 +08:00
|
|
|
|
if MyGuildManager.PackageNum>0 and self.redPackage.gameObject then
|
2021-05-21 14:47:04 +08:00
|
|
|
|
self.redPackage.gameObject:SetActive(true)
|
2021-05-26 16:03:28 +08:00
|
|
|
|
LogError("///////////")
|
|
|
|
|
--self.freeBtnAnim.enabled=true
|
2021-05-21 14:47:04 +08:00
|
|
|
|
else
|
|
|
|
|
self.redPackage.gameObject:SetActive(false)
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-05-09 13:31:21 +08:00
|
|
|
|
--界面打开时调用(用于子类重写)
|
|
|
|
|
function ChatTipView:OnOpen(viewType)
|
|
|
|
|
self._ViewType = viewType or VIEW_TYPE.MAIN
|
2021-05-21 14:47:04 +08:00
|
|
|
|
if MyGuildManager.PackageNum>0 then
|
|
|
|
|
self.redPackage.gameObject:SetActive(true)
|
|
|
|
|
else
|
|
|
|
|
self.redPackage.gameObject:SetActive(false)
|
|
|
|
|
end
|
2020-05-09 13:31:21 +08:00
|
|
|
|
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
|
2021-03-02 16:53:12 +08:00
|
|
|
|
content = string.format(Language[12018], data.msg)
|
2020-05-09 13:31:21 +08:00
|
|
|
|
end
|
|
|
|
|
elseif msg.channel == CHAT_CHANNEL.GLOBAL then
|
|
|
|
|
local chat = ChatManager.AnalysisGlobalChat(msg.chat.msg)
|
2021-03-02 16:53:12 +08:00
|
|
|
|
content = string.format(Language[12019], msg.chat.senderName, chat.content)
|
2020-05-09 13:31:21 +08:00
|
|
|
|
elseif msg.channel == CHAT_CHANNEL.FAMILY then
|
|
|
|
|
local chat = ChatManager.AnalysisGlobalChat(msg.chat.msg)
|
2021-03-02 16:53:12 +08:00
|
|
|
|
content = string.format(Language[12020], msg.chat.senderName, chat.content)
|
2021-07-28 17:42:58 +08:00
|
|
|
|
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)
|
2020-05-09 13:31:21 +08:00
|
|
|
|
end
|
2021-07-30 14:07:08 +08:00
|
|
|
|
self.channel = msg.channel
|
2020-05-09 13:31:21 +08:00
|
|
|
|
end
|
|
|
|
|
self.content.text = content
|
2021-07-30 14:07:08 +08:00
|
|
|
|
|
2020-05-09 13:31:21 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 开始聊天数据刷新
|
|
|
|
|
function ChatTipView:StartCheck()
|
|
|
|
|
ChatManager.StartChatDataUpdate()
|
|
|
|
|
end
|
|
|
|
|
-- 停止聊天数据刷新
|
|
|
|
|
function ChatTipView:StopCheck()
|
|
|
|
|
ChatManager.StopChatDataUpdate()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--界面关闭时调用(用于子类重写)
|
|
|
|
|
function ChatTipView:OnClose()
|
2021-04-21 13:12:04 +08:00
|
|
|
|
self.spLoader:Destroy()
|
2020-05-09 13:31:21 +08:00
|
|
|
|
end
|
|
|
|
|
|
2020-06-23 18:36:24 +08:00
|
|
|
|
return ChatTipView
|