KLMessageNoticePanel.lua 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. ---@class KLMessageNoticePanel:UIKmlLuaPanelBase
  2. ---@field view KLMessageNoticePanelView
  3. local KLMessageNoticePanel = class(UIKmlLuaPanelBase)
  4. local this =KLMessageNoticePanel
  5. local maxLdMessageCount = 6
  6. function this:AsyncLoadUI()
  7. end
  8. ---创建时调用一次
  9. function this:Init()
  10. self.ldMessageList = {}
  11. ---@type Queue
  12. self.ldItemQueue = SL.Queue:New()
  13. for i = 1,maxLdMessageCount do
  14. local control = self.view["item_ld" .. i]
  15. GUI:setAlpha(control,0)
  16. self.ldItemQueue:PushLast({control=control})
  17. end
  18. --self.ldMessageTimer = SL:Schedule(self.ldMessageTimer,0,0.2,-1,self.LDTick,self)
  19. -- 盒子服务端过来的信息无法走表,策划要求写死配置(跑马灯)
  20. self.BoxHorse = { id = -1, description = "", name = "", messageType = { 1 }, receiver = 3, textColor = "255", rollSpeed = 10000, text = "", subType = "系统", condition = { { 1, 1 } }, backgroundColor = "0", transparencyB = 40, transparencyT = 0, textSize = 20, offsetX = 0, offsetY = 0, rollCount = 0, releaseEffect = {}, ShowDuration = 0, order = 0 }
  21. -- 盒子服务端过来的信息无法走表,策划要求写死配置(聊天框)
  22. self.BoxChat = { id = -2, description = "", name = "", messageType = { 7 }, receiver = 3, textColor = "255", rollSpeed = 10000, text = "", subType = "系统", condition = { { 1, 1 } }, backgroundColor = "0", transparencyB = 40, transparencyT = 0, textSize = 20, offsetX = 0, offsetY = 0, rollCount = 0, releaseEffect = {}, ShowDuration = 0, order = 0 }
  23. end
  24. ---注册UI事件和服务器消息
  25. function this:RegistEvents()
  26. SL:RegisterLUAEvent(LUA_EVENT_LEFT_OPEN_MESSAGE, self.HandleMDMessage, self)
  27. end
  28. ---界面显示时调用一次
  29. function this:Show()
  30. end
  31. ---创建或者刷新界面数据时调用
  32. function this:Refresh()
  33. end
  34. function this:Hide()
  35. end
  36. function this:Close()
  37. while not self.ldItemQueue:IsEmpty() do
  38. local item = self.ldItemQueue:PopFirst()
  39. if item.fadeTimer then
  40. GUI:DOKill(item.fadeTimer)
  41. end
  42. SL:UnSchedule(item.showTimer)
  43. end
  44. self:ClearMDMessageTimer()
  45. end
  46. ---@param message ChatProto.TextNoticeRes
  47. ---@param tbl cfg_string_column
  48. function this:HandleLDMessage(message, tbl)
  49. ---@type cfg_string_column
  50. if not tbl and message then
  51. if message.id == -1 then
  52. tbl = self.BoxHorse
  53. elseif message.id == -2 then
  54. tbl = self.BoxChat
  55. else
  56. tbl = SL:GetConfig("cfg_string",message.id)
  57. end
  58. end
  59. if tbl.condition and tbl.condition[1][1] == 1 then
  60. local level = SL:GetMetaValue(EMetaVarGetKey.LEVEL)
  61. if level < tbl.condition[1][2] then
  62. return false
  63. end
  64. end
  65. if tbl.messageType[1] == 8 then
  66. local showText = self:GetMessageText(message,tbl)
  67. --logError(showText)
  68. table.insert(self.ldMessageList,{text = showText,showDuration = tbl.ShowDuration,hideFlag=false})
  69. if #self.ldMessageList > maxLdMessageCount then
  70. table.remove(self.ldMessageList,1)
  71. end
  72. --GUI:OSAScrollView_RefreshList(self.view.osa_ld_message,#self.ldMessageList)
  73. self:RefreshLDMessage()
  74. return true
  75. end
  76. return false
  77. end
  78. ---@param message ChatProto.TextNoticeRes
  79. ---@param tbl cfg_string_column
  80. function this:GetMessageText(message,tbl)
  81. -- contentFromServer标志位; false:表示客户端直接读取配置 true:表示从服务器获取内容
  82. local textString = message and message.contentFromServer and message.content or tbl.text
  83. if message and not table.isNullOrEmpty(message.params) then
  84. textString = string.format(textString, table.unpack(message.params))
  85. end
  86. if string.contains(textString, "<Text") then
  87. textString = Misc.TransSpecialText(textString)
  88. end
  89. ---@type cfg_color_column
  90. local colorTbl = SL:GetConfig("cfg_color",tonumber(tbl.textColor))
  91. local txt = string.format("<color=%s>%s</color>", colorTbl.color, textString)
  92. return txt
  93. end
  94. function this:RefreshLDMessage()
  95. local count = #self.ldMessageList
  96. for i = 1,count do
  97. local msg = self.ldMessageList[i]
  98. local item = self.ldItemQueue:PopFirst()
  99. if item.fadeTimer then
  100. GUI:DOKill(item.fadeTimer)
  101. item.fadeTimer = nil
  102. end
  103. SL:UnSchedule(item.showTimer)
  104. local control = item.control
  105. ---@type UnityEngine.RectTransform
  106. local rect = GUI:GetRectTransform(control)
  107. rect:SetAsLastSibling()
  108. GUI:setAlpha(control,1)
  109. local text = GUI:GetChildById(control,"text_message")
  110. GUI:Text_setString(text,msg.text)
  111. item.showTimer = SL:ScheduleOnce(msg.showDuration/1000,self.PlayLdMessageHideAnim,self,item)
  112. self.ldItemQueue:PushLast(item)
  113. end
  114. table.clear(self.ldMessageList)
  115. end
  116. function this:PlayLdMessageHideAnim(item)
  117. item.fadeTimer = GUI:DOAlphaCanvasGroup(item.control,0,1)
  118. end
  119. ---中间底部泡点信息
  120. function this:HandleMDMessage(_, data)
  121. self:ClearMDMessageTimer()
  122. local msgControl = self.view.text_mid_message
  123. GUI:setAlpha(msgControl,1)
  124. GUI:Text_setString(msgControl,data.text)
  125. GUI:Text_setFontName(msgControl,data.fontName or "BubblePoint")
  126. self.mdMessageShowTimer = SL:ScheduleOnce(data.showTime,self.PlayMDMessageHideAnim,self)
  127. end
  128. function this:ClearMDMessageTimer()
  129. if self.mdMessageShowTimer then
  130. SL:UnSchedule(self.mdMessageShowTimer)
  131. self.mdMessageShowTimer = nil
  132. end
  133. GUI:setAlpha(self.view.text_mid_message,0)
  134. if self.mdMessageHideTimer then
  135. GUI:DOKill(self.mdMessageHideTimer)
  136. self.mdMessageHideTimer = nil
  137. end
  138. end
  139. function this:PlayMDMessageHideAnim()
  140. self.mdMessageHideTimer = GUI:DOAlphaCanvasGroup(self.view.text_mid_message,0,0.5)
  141. end
  142. return this