源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

155 lines
3.7 KiB

SysInfoMiniView = SysInfoMiniView or BaseClass()
local SysInfoMiniView = SysInfoMiniView
SysInfoMiniView.MAX_MSG_COUNT = 5
function SysInfoMiniView:__init()
self.msg_list = Array.New()
self.total_time = 1
self.play_step = 0.5--这个数字较大时,TryPopMessage函数时冷却时间不足会中断提示,但没有清除信息表,会有问题,虽然每次切场景会有校正
self.last_time = 0
self.message_wnd_list = {}
self.index = 0
self.can_show = true
self.prefab_asset = nil
self:LoadAsset()
end
function SysInfoMiniView:LoadAsset()
local function call_back(objs)
self.prefab_asset = objs[0]
self:CreateMessageContainer()
if self.need_to_refresh then
self:TryPopMessage()
self.need_to_refresh = false
end
end
lua_resM:loadPrefab(self,"message","miniMessage", call_back)
local event = function ()
self.msg_list:Clear()
end
self.scene_id = GlobalEventSystem:Bind(SceneEventType.OPEN_SCENE_LOAD_VIEW,event)
local func = function ()
self.msg_list:Clear()
end
self.account_change_id = GlobalEventSystem:Bind(EventName.CHANGE_ACCOUNT,func)
self.role_change_id = GlobalEventSystem:Bind(EventName.CHANGE_ROLE,func)
end
function SysInfoMiniView:__delete()
for k,v in pairs(self.message_wnd_list) do
v:DeleteMe()
end
self.message_wnd_list = {}
if self.account_change_id then
GlobalEventSystem:UnBind(self.account_change_id)
self.account_change_id = nil
end
if self.role_change_id then
GlobalEventSystem:UnBind(self.role_change_id)
self.role_change_id = nil
end
if self.scene_id then
GlobalEventSystem:UnBind(self.scene_id)
self.scene_id = nil
end
end
function SysInfoMiniView:CreateMessageContainer()
if self.prefab_asset then
local item = nil
for index = 0, SysInfoMiniView.MAX_MSG_COUNT do
item = MessageItem.New(panelMgr:GetParent("Top"),self.prefab_asset,nil,function()
self:TryPopMessage()
end)
self.message_wnd_list[index] = item
end
end
end
function SysInfoMiniView:TryPopMessage()
local size = Array.GetSize(self.msg_list)
if size <= 0 then
return
end
local content = Array.Get(self.msg_list,0)
if content then
for k,v in pairs(self.message_wnd_list) do
if v.state == 2 then
v:CreateFoutAnim()
break
end
end
local cur_time = TimeUtil:getClientTime()
if cur_time - self.last_time >= self.play_step then
self.last_time = cur_time
if self.index > SysInfoMiniView.MAX_MSG_COUNT then
self.index = 0
end
local item = self.message_wnd_list[self.index]
if item.state == 0 then
item:CreateFinAnim(content)
self.msg_list:PopFront()
self.index = self.index + 1
elseif item.state ~= 3 then
item:CreateFoutAnim()
end
end
end
end
function SysInfoMiniView:AppendMessage(content)
if not self.prefab_asset then
return
end
-- local item = self.message_wnd_list[self.index - 1 < 0 and 0 or self.index - 1]
-- if item.content == content then
-- item:CreateFinAnim(content)
-- self.msg_list:PopFront()
-- self.last_time = TimeUtil:getClientTime()
-- return
-- end
local count = self.msg_list:GetSize()
local cur_time = TimeUtil:getClientTime()
if count > 0 then
local msg = self.msg_list:Get(count - 1)
if msg ~= nil and msg == content then
local diff = cur_time - self.last_time
if diff < self.play_step then
return
end
end
end
if count > SysInfoMiniView.MAX_MSG_COUNT then
self.msg_list:PopFront()
end
self.msg_list:PushBack(content)
self:TryPopMessage()
end
function SysInfoMiniView:SetHide(bool)
self.can_show = false
if TableSize(self.message_wnd_list) > 0 then
for i = 0, SysInfoMiniView.MAX_MSG_COUNT do
self.message_wnd_list[i].gameObject:SetActive(not bool)
end
end
end