--[[ @describtion:特殊飘字视图层 @author:huangjingpei ]] SysInfoSpecialView = SysInfoSpecialView or BaseClass() local SysInfoSpecialView = SysInfoSpecialView SysInfoSpecialView.MAX_MSG_COUNT = 20 SysInfoSpecialView.WIDTH = 749 SysInfoSpecialView.HEIGHT = 62 SysInfoSpecialView.SHOW_MAX_COUNT = 3 function SysInfoSpecialView:__init() self.font_name = "sysinfo2" self.records = Array.New() self.msg_list = Array.New() self.total_time = 1 self.play_step = 0.3 self.last_time = 0 self.state_time1 = 1 self.state_time2 = 3 self.fout_out_time = 0.8 self.speed = 90.0 / self.state_time1 self.message_wnd_list = {} self.index = 0 local ui_load_finish = function() self:CreateMessageContainer() end GlobalEventSystem:Bind(CommonUIEventType.DEFAULT_UI_RES_LOADED, ui_load_finish) end function SysInfoSpecialView:__delete() if self.root_wnd then self.root_wnd:DeleteMe() self.root_wnd = nil end end --创建消息容器 function SysInfoSpecialView:CreateMessageContainer() local screen_width = HandleRenderUnit:getTargetWidth() local screen_height = HandleRenderUnit:getTargetHeight() self.root_wnd = Game.UI:CreateWindowByTypeNoName(UIType.Box, "", "ControlLayer") self.root_wnd:SetVector2(WidgetProperty.Size, Game.Vector2(SysInfoSpecialView.WIDTH/1280*screen_width, SysInfoSpecialView.HEIGHT/720*screen_height)) self.root_wnd:SetBool(WidgetProperty.NeedMouse, false) self.root_wnd:SetInt(WidgetProperty.Align, Align.Center) self.root_wnd:SetVectorValue(WidgetProperty.Position, (screen_width - SysInfoSpecialView.WIDTH/1280*screen_width)/2, (screen_height - SysInfoSpecialView.HEIGHT/720*screen_height)/2 - 35/720*screen_height) for index = 0, SysInfoSpecialView.MAX_MSG_COUNT do local wnd = self:CreateLabel() self.message_wnd_list[index] = wnd end end --创建消息组件 function SysInfoSpecialView:CreateLabel() local box = {} box.bg = self.root_wnd:CreateChildNoName(UIType.ImageBox, "") box.bg:SetString(ImageBoxProperty.Source, "comp:xx_special_msg_bg") box.bg:SetFloat(WidgetProperty.Alpha, 0.0) box.bg:SetBool(WidgetProperty.NeedMouse, false) box.wnd = box.bg:CreateChildNoName(UIType.Label, "Label3") box.wnd:SetVector2(WidgetProperty.Size, Game.Vector2(SysInfoSpecialView.WIDTH, 32)) box.wnd:SetVectorValue(WidgetProperty.Position, 0, 14) box.wnd:SetInt(TextBoxProperty.TextAlign, bit.bor(Align.Center, Align.VCenter)) box.wnd:SetInt(TextBoxProperty.FontSize, 24) box.wnd:SetBool(WidgetProperty.NeedMouse, false) return box end function SysInfoSpecialView:CreateNewItem(content) if self.index >= SysInfoSpecialView.MAX_MSG_COUNT then self.index = 0 end local box = self.message_wnd_list[self.index] if box ~= nil then box.wnd:SetString(WindowProperty.Label, content) box.bg:SetFloat(WidgetProperty.Alpha, 0.0) end self.index = self.index + 1 return box end function SysInfoSpecialView:CreateFoutAnim(wnd) local orign_pos_y = wnd:GetVector2(WidgetProperty.Position).y local wnd_alpha_frames = Game.KeyFrameSet() wnd_alpha_frames:AddTimeValue(0, 0) wnd_alpha_frames:AddTimeValue(self.fout_out_time, 1) local function WindowScreenCenterEnd() if wnd then wnd:SetFloat(WidgetProperty.Alpha, 0) end end local function WindowAlphaSetterCreator(anmi_val) if not wnd or wnd:IsNull() then return true end local anmi_num = anmi_val:GetAsNumeric() local value = 1 - anmi_num local pos = wnd:GetVector2(WidgetProperty.Position) local pos_y = 70 * anmi_num wnd:SetVectorValue(WidgetProperty.Position, pos.x, orign_pos_y - pos_y) wnd:SetFloat(WidgetProperty.Alpha, value) return false end Game.Animation:CreateKeyAnim(WindowAlphaSetterCreator, wnd_alpha_frames, false, true, WindowScreenCenterEnd) end function SysInfoSpecialView:Update(elapse_time) self.total_time = self.total_time + elapse_time local count = self.msg_list:GetSize() if count > 0 then if self.total_time > self.play_step then local content = self.msg_list:PopFront() if content ~= nil then self.total_time = 0.0 local node = {} node.wnd = self:CreateNewItem(content) node.time = 0 self.records:PushBack(node) end end end local record_length = self.records:GetSize() if record_length == 0 then return end for i = 0, record_length - 1 do local node = self.records:Get(i) local wnd = node.wnd.bg node.time = node.time + elapse_time local pos = wnd:GetVector2(WidgetProperty.Position) if node.time < self.state_time1 then local percent = node.time / self.state_time1 pos.y = 90 - self.speed * node.time wnd:SetVector2(WidgetProperty.Position, pos) wnd:SetFloat(WidgetProperty.Alpha, percent) elseif node.time <= self.state_time2 then local end_y = -(record_length - 1 - i) * (SysInfoSpecialView.HEIGHT + 3) node.up_time = 0.4 + (record_length - 1 - i)*0.3 local speed = end_y / node.up_time * elapse_time pos.y = pos.y + speed if pos.y <= end_y then pos.y = end_y end wnd:SetVector2(WidgetProperty.Position, pos) wnd:SetFloat(WidgetProperty.Alpha, 1) end end if record_length > 0 then local node = self.records:Get(0) if node.time > self.state_time2 then self.records:PopFront() self:CreateFoutAnim(node.wnd.bg) return end end if record_length > SysInfoSpecialView.SHOW_MAX_COUNT then local node = self.records:Get(0) if node.time and node.up_time then if node.time > node.up_time + 1 then self.records:PopFront() self:CreateFoutAnim(node.wnd.bg) return end end end end function SysInfoSpecialView:AppendMessage(content) if not self.root_wnd then return end local cur_time = TimeUtil:getClientTime() local count = self.msg_list:GetSize() 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 self.last_time = cur_time if count > SysInfoSpecialView.MAX_MSG_COUNT then self.msg_list:PopFront() end self.msg_list:PushBack(content) end