源战役客户端
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

154 linhas
3.7 KiB

  1. SysInfoMiniView = SysInfoMiniView or BaseClass()
  2. local SysInfoMiniView = SysInfoMiniView
  3. SysInfoMiniView.MAX_MSG_COUNT = 5
  4. function SysInfoMiniView:__init()
  5. self.msg_list = Array.New()
  6. self.total_time = 1
  7. self.play_step = 0.5--这个数字较大时,TryPopMessage函数时冷却时间不足会中断提示,但没有清除信息表,会有问题,虽然每次切场景会有校正
  8. self.last_time = 0
  9. self.message_wnd_list = {}
  10. self.index = 0
  11. self.can_show = true
  12. self.prefab_asset = nil
  13. self:LoadAsset()
  14. end
  15. function SysInfoMiniView:LoadAsset()
  16. local function call_back(objs)
  17. self.prefab_asset = objs[0]
  18. self:CreateMessageContainer()
  19. if self.need_to_refresh then
  20. self:TryPopMessage()
  21. self.need_to_refresh = false
  22. end
  23. end
  24. lua_resM:loadPrefab(self,"message","miniMessage", call_back)
  25. local event = function ()
  26. self.msg_list:Clear()
  27. end
  28. self.scene_id = GlobalEventSystem:Bind(SceneEventType.OPEN_SCENE_LOAD_VIEW,event)
  29. local func = function ()
  30. self.msg_list:Clear()
  31. end
  32. self.account_change_id = GlobalEventSystem:Bind(EventName.CHANGE_ACCOUNT,func)
  33. self.role_change_id = GlobalEventSystem:Bind(EventName.CHANGE_ROLE,func)
  34. end
  35. function SysInfoMiniView:__delete()
  36. for k,v in pairs(self.message_wnd_list) do
  37. v:DeleteMe()
  38. end
  39. self.message_wnd_list = {}
  40. if self.account_change_id then
  41. GlobalEventSystem:UnBind(self.account_change_id)
  42. self.account_change_id = nil
  43. end
  44. if self.role_change_id then
  45. GlobalEventSystem:UnBind(self.role_change_id)
  46. self.role_change_id = nil
  47. end
  48. if self.scene_id then
  49. GlobalEventSystem:UnBind(self.scene_id)
  50. self.scene_id = nil
  51. end
  52. end
  53. function SysInfoMiniView:CreateMessageContainer()
  54. if self.prefab_asset then
  55. local item = nil
  56. for index = 0, SysInfoMiniView.MAX_MSG_COUNT do
  57. item = MessageItem.New(panelMgr:GetParent("Top"),self.prefab_asset,nil,function()
  58. self:TryPopMessage()
  59. end)
  60. self.message_wnd_list[index] = item
  61. end
  62. end
  63. end
  64. function SysInfoMiniView:TryPopMessage()
  65. local size = Array.GetSize(self.msg_list)
  66. if size <= 0 then
  67. return
  68. end
  69. local content = Array.Get(self.msg_list,0)
  70. if content then
  71. for k,v in pairs(self.message_wnd_list) do
  72. if v.state == 2 then
  73. v:CreateFoutAnim()
  74. break
  75. end
  76. end
  77. local cur_time = TimeUtil:getClientTime()
  78. if cur_time - self.last_time >= self.play_step then
  79. self.last_time = cur_time
  80. if self.index > SysInfoMiniView.MAX_MSG_COUNT then
  81. self.index = 0
  82. end
  83. local item = self.message_wnd_list[self.index]
  84. if item.state == 0 then
  85. item:CreateFinAnim(content)
  86. self.msg_list:PopFront()
  87. self.index = self.index + 1
  88. elseif item.state ~= 3 then
  89. item:CreateFoutAnim()
  90. end
  91. end
  92. end
  93. end
  94. function SysInfoMiniView:AppendMessage(content)
  95. if not self.prefab_asset then
  96. return
  97. end
  98. -- local item = self.message_wnd_list[self.index - 1 < 0 and 0 or self.index - 1]
  99. -- if item.content == content then
  100. -- item:CreateFinAnim(content)
  101. -- self.msg_list:PopFront()
  102. -- self.last_time = TimeUtil:getClientTime()
  103. -- return
  104. -- end
  105. local count = self.msg_list:GetSize()
  106. local cur_time = TimeUtil:getClientTime()
  107. if count > 0 then
  108. local msg = self.msg_list:Get(count - 1)
  109. if msg ~= nil and msg == content then
  110. local diff = cur_time - self.last_time
  111. if diff < self.play_step then
  112. return
  113. end
  114. end
  115. end
  116. if count > SysInfoMiniView.MAX_MSG_COUNT then
  117. self.msg_list:PopFront()
  118. end
  119. self.msg_list:PushBack(content)
  120. self:TryPopMessage()
  121. end
  122. function SysInfoMiniView:SetHide(bool)
  123. self.can_show = false
  124. if TableSize(self.message_wnd_list) > 0 then
  125. for i = 0, SysInfoMiniView.MAX_MSG_COUNT do
  126. self.message_wnd_list[i].gameObject:SetActive(not bool)
  127. end
  128. end
  129. end