miduo_client/Assets/ManagedResources/~Lua/View/ChatTipView.lua

98 lines
2.9 KiB
Lua
Raw Normal View History

2020-08-06 17:52:32 +08:00
local ChatTipView = {}
2020-05-09 13:31:21 +08:00
local SYS_MSG_TYPE = {
2020-06-23 18:36:24 +08:00
[0] = {name = Language[10384]},
[1] = {name = Language[10385]},
[2] = {name = Language[10386]}
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()
self.btn = Util.GetGameObject(self.transform, "button")
self.content = Util.GetGameObject(self.transform, "content"):GetComponent("Text")
self.redpot = Util.GetGameObject(self.transform, "icon/redpot")
end
--绑定事件(用于子类重写)
function ChatTipView:BindEvent()
Util.AddClick(self.btn, function()
if self._ViewType == VIEW_TYPE.MAIN then
UIManager.OpenPanel(UIName.ChatPanel)
elseif self._ViewType == VIEW_TYPE.GUILD then
UIManager.OpenPanel(UIName.ChatPanel, 2, 2)
end
end)
end
--添加事件监听(用于子类重写)
function ChatTipView:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.Chat.OnMainChatChanged, self.RefreshChatShow, self)
BindRedPointObject(RedPointType.Chat, self.redpot)
end
--移除事件监听(用于子类重写)
function ChatTipView:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.Chat.OnMainChatChanged, self.RefreshChatShow, self)
ClearRedPointObject(RedPointType.Chat, self.redpot)
end
--界面打开时调用(用于子类重写)
function ChatTipView:OnOpen(viewType)
self._ViewType = viewType or VIEW_TYPE.MAIN
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
2020-06-23 18:36:24 +08:00
content = string.format(Language[12071], 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)
2020-06-23 18:36:24 +08:00
content = string.format(Language[12072], 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)
2020-06-23 18:36:24 +08:00
content = string.format(Language[12073], msg.chat.senderName, chat.content)
2020-05-09 13:31:21 +08:00
end
end
self.content.text = content
end
-- 开始聊天数据刷新
function ChatTipView:StartCheck()
ChatManager.StartChatDataUpdate()
end
-- 停止聊天数据刷新
function ChatTipView:StopCheck()
ChatManager.StopChatDataUpdate()
end
--界面关闭时调用(用于子类重写)
function ChatTipView:OnClose()
end
2020-06-23 18:36:24 +08:00
return ChatTipView