源战役客户端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

211 rindas
6.8 KiB

pirms 1 mēnesi
  1. --[[
  2. @describtion:
  3. @author:huangjingpei
  4. ]]
  5. SysInfoSpecialView = SysInfoSpecialView or BaseClass()
  6. local SysInfoSpecialView = SysInfoSpecialView
  7. SysInfoSpecialView.MAX_MSG_COUNT = 20
  8. SysInfoSpecialView.WIDTH = 749
  9. SysInfoSpecialView.HEIGHT = 62
  10. SysInfoSpecialView.SHOW_MAX_COUNT = 3
  11. function SysInfoSpecialView:__init()
  12. self.font_name = "sysinfo2"
  13. self.records = Array.New()
  14. self.msg_list = Array.New()
  15. self.total_time = 1
  16. self.play_step = 0.3
  17. self.last_time = 0
  18. self.state_time1 = 1
  19. self.state_time2 = 3
  20. self.fout_out_time = 0.8
  21. self.speed = 90.0 / self.state_time1
  22. self.message_wnd_list = {}
  23. self.index = 0
  24. local ui_load_finish = function()
  25. self:CreateMessageContainer()
  26. end
  27. GlobalEventSystem:Bind(CommonUIEventType.DEFAULT_UI_RES_LOADED, ui_load_finish)
  28. end
  29. function SysInfoSpecialView:__delete()
  30. if self.root_wnd then
  31. self.root_wnd:DeleteMe()
  32. self.root_wnd = nil
  33. end
  34. end
  35. --创建消息容器
  36. function SysInfoSpecialView:CreateMessageContainer()
  37. local screen_width = HandleRenderUnit:getTargetWidth()
  38. local screen_height = HandleRenderUnit:getTargetHeight()
  39. self.root_wnd = Game.UI:CreateWindowByTypeNoName(UIType.Box, "", "ControlLayer")
  40. self.root_wnd:SetVector2(WidgetProperty.Size, Game.Vector2(SysInfoSpecialView.WIDTH/1280*screen_width, SysInfoSpecialView.HEIGHT/720*screen_height))
  41. self.root_wnd:SetBool(WidgetProperty.NeedMouse, false)
  42. self.root_wnd:SetInt(WidgetProperty.Align, Align.Center)
  43. 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)
  44. for index = 0, SysInfoSpecialView.MAX_MSG_COUNT do
  45. local wnd = self:CreateLabel()
  46. self.message_wnd_list[index] = wnd
  47. end
  48. end
  49. --创建消息组件
  50. function SysInfoSpecialView:CreateLabel()
  51. local box = {}
  52. box.bg = self.root_wnd:CreateChildNoName(UIType.ImageBox, "")
  53. box.bg:SetString(ImageBoxProperty.Source, "comp:xx_special_msg_bg")
  54. box.bg:SetFloat(WidgetProperty.Alpha, 0.0)
  55. box.bg:SetBool(WidgetProperty.NeedMouse, false)
  56. box.wnd = box.bg:CreateChildNoName(UIType.Label, "Label3")
  57. box.wnd:SetVector2(WidgetProperty.Size, Game.Vector2(SysInfoSpecialView.WIDTH, 32))
  58. box.wnd:SetVectorValue(WidgetProperty.Position, 0, 14)
  59. box.wnd:SetInt(TextBoxProperty.TextAlign, bit.bor(Align.Center, Align.VCenter))
  60. box.wnd:SetInt(TextBoxProperty.FontSize, 24)
  61. box.wnd:SetBool(WidgetProperty.NeedMouse, false)
  62. return box
  63. end
  64. function SysInfoSpecialView:CreateNewItem(content)
  65. if self.index >= SysInfoSpecialView.MAX_MSG_COUNT then
  66. self.index = 0
  67. end
  68. local box = self.message_wnd_list[self.index]
  69. if box ~= nil then
  70. box.wnd:SetString(WindowProperty.Label, content)
  71. box.bg:SetFloat(WidgetProperty.Alpha, 0.0)
  72. end
  73. self.index = self.index + 1
  74. return box
  75. end
  76. function SysInfoSpecialView:CreateFoutAnim(wnd)
  77. local orign_pos_y = wnd:GetVector2(WidgetProperty.Position).y
  78. local wnd_alpha_frames = Game.KeyFrameSet()
  79. wnd_alpha_frames:AddTimeValue(0, 0)
  80. wnd_alpha_frames:AddTimeValue(self.fout_out_time, 1)
  81. local function WindowScreenCenterEnd()
  82. if wnd then
  83. wnd:SetFloat(WidgetProperty.Alpha, 0)
  84. end
  85. end
  86. local function WindowAlphaSetterCreator(anmi_val)
  87. if not wnd or wnd:IsNull() then
  88. return true
  89. end
  90. local anmi_num = anmi_val:GetAsNumeric()
  91. local value = 1 - anmi_num
  92. local pos = wnd:GetVector2(WidgetProperty.Position)
  93. local pos_y = 70 * anmi_num
  94. wnd:SetVectorValue(WidgetProperty.Position, pos.x, orign_pos_y - pos_y)
  95. wnd:SetFloat(WidgetProperty.Alpha, value)
  96. return false
  97. end
  98. Game.Animation:CreateKeyAnim(WindowAlphaSetterCreator, wnd_alpha_frames, false, true,
  99. WindowScreenCenterEnd)
  100. end
  101. function SysInfoSpecialView:Update(elapse_time)
  102. self.total_time = self.total_time + elapse_time
  103. local count = self.msg_list:GetSize()
  104. if count > 0 then
  105. if self.total_time > self.play_step then
  106. local content = self.msg_list:PopFront()
  107. if content ~= nil then
  108. self.total_time = 0.0
  109. local node = {}
  110. node.wnd = self:CreateNewItem(content)
  111. node.time = 0
  112. self.records:PushBack(node)
  113. end
  114. end
  115. end
  116. local record_length = self.records:GetSize()
  117. if record_length == 0 then
  118. return
  119. end
  120. for i = 0, record_length - 1 do
  121. local node = self.records:Get(i)
  122. local wnd = node.wnd.bg
  123. node.time = node.time + elapse_time
  124. local pos = wnd:GetVector2(WidgetProperty.Position)
  125. if node.time < self.state_time1 then
  126. local percent = node.time / self.state_time1
  127. pos.y = 90 - self.speed * node.time
  128. wnd:SetVector2(WidgetProperty.Position, pos)
  129. wnd:SetFloat(WidgetProperty.Alpha, percent)
  130. elseif node.time <= self.state_time2 then
  131. local end_y = -(record_length - 1 - i) * (SysInfoSpecialView.HEIGHT + 3)
  132. node.up_time = 0.4 + (record_length - 1 - i)*0.3
  133. local speed = end_y / node.up_time * elapse_time
  134. pos.y = pos.y + speed
  135. if pos.y <= end_y then pos.y = end_y end
  136. wnd:SetVector2(WidgetProperty.Position, pos)
  137. wnd:SetFloat(WidgetProperty.Alpha, 1)
  138. end
  139. end
  140. if record_length > 0 then
  141. local node = self.records:Get(0)
  142. if node.time > self.state_time2 then
  143. self.records:PopFront()
  144. self:CreateFoutAnim(node.wnd.bg)
  145. return
  146. end
  147. end
  148. if record_length > SysInfoSpecialView.SHOW_MAX_COUNT then
  149. local node = self.records:Get(0)
  150. if node.time and node.up_time then
  151. if node.time > node.up_time + 1 then
  152. self.records:PopFront()
  153. self:CreateFoutAnim(node.wnd.bg)
  154. return
  155. end
  156. end
  157. end
  158. end
  159. function SysInfoSpecialView:AppendMessage(content)
  160. if not self.root_wnd then
  161. return
  162. end
  163. local cur_time = TimeUtil:getClientTime()
  164. local count = self.msg_list:GetSize()
  165. if count > 0 then --判断现在显示的是否和要显示的内容一致,确定是否要显示
  166. local msg = self.msg_list:Get(count - 1)
  167. if msg ~= nil and msg == content then
  168. local diff = cur_time - self.last_time
  169. if diff < self.play_step then
  170. return
  171. end
  172. end
  173. end
  174. self.last_time = cur_time
  175. if count > SysInfoSpecialView.MAX_MSG_COUNT then
  176. self.msg_list:PopFront()
  177. end
  178. self.msg_list:PushBack(content)
  179. end