源战役客户端
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.

101 line
2.6 KiB

  1. --屏幕中间漂浮的电视文字
  2. TV = TV or BaseClass(BaseView)
  3. function TV:__init()
  4. self.base_file = "chat"
  5. self.layout_file = "tv"
  6. self.layer_name = "Top"
  7. self.model = ChatModel:getInstance()
  8. self.visible = false
  9. self.load_callback = function ()
  10. self:LoadSuccess()
  11. end
  12. self.open_callback = function ()
  13. self:SetVisible(false)
  14. self:InitEvent()
  15. end
  16. self.destroy_callback = function ()
  17. self:Remove()
  18. end
  19. self.width = 860
  20. end
  21. function TV:Remove()
  22. end
  23. function TV:SetVisible(bool)
  24. self.gameObject:SetActive(bool)
  25. self.visible = bool
  26. end
  27. function TV:LoadSuccess()
  28. self.transform.localPosition = Vector3(0,ScreenHeight / 2 - 150, 0)
  29. self.bg_img = self:GetChild("bg"):GetComponent("Image")
  30. self.bg_img.alpha = 0.8
  31. self.text = self:GetChild("Text")
  32. end
  33. function TV:InitEvent()
  34. local onCheck = function()
  35. if self.visible or self.model.tv_state == false then
  36. return
  37. end
  38. local list = self.model:GetTVList()
  39. local client_time = TimeUtil:getClientTime()
  40. local ser_time = TimeUtil:getServerTime()
  41. local ind = 1
  42. for _,obj in pairs(list) do
  43. if obj.times ~= 0 and obj.count <= 0 or ser_time > obj.endTime then
  44. table.remove(list,ind)
  45. ind = ind - 1
  46. elseif obj.startTime < ser_time and client_time - obj.interval_time > obj.interval then
  47. obj.interval_time = client_time
  48. if obj.type == 0 then --发滚屏
  49. self:SetVisible(true)
  50. self:addContent(obj)
  51. elseif obj.type == 1 then --发聊天
  52. GlobalEventSystem:Fire(EventName.SHOW_GONGGAO,obj)
  53. else --都发
  54. GlobalEventSystem:Fire(EventName.SHOW_GONGGAO,obj)
  55. self:SetVisible(true)
  56. self:addContent(obj)
  57. end
  58. end
  59. ind = ind + 1
  60. end
  61. end
  62. self.check_timerId = GlobalTimerQuest:AddPeriodQuest(onCheck, 2, -1)
  63. local onMove = function()
  64. if self.visible then
  65. local pos_x = self.text.localPosition.x
  66. if pos_x <= -(self.width / 2 + self.textWidth)then
  67. self:SetVisible(false)
  68. return
  69. end
  70. self.text.localPosition = Vector3(pos_x - 5 ,0,0)
  71. end
  72. end
  73. self.move_timerId = GlobalTimerQuest:AddPeriodQuest(onMove, 0.05, -1)
  74. end
  75. function TV:addContent(obj)
  76. local content = nil
  77. if obj.link ~= nil and #obj.link > 0 then
  78. content = "<font color='#fffc00'>"..
  79. "<a href='event:"..
  80. obj.link[1]..
  81. "'>"..
  82. obj.content..
  83. "</a></font>"
  84. else
  85. content = "<font color='#fffc00'>"..obj.content.."</font>"
  86. end
  87. if obj.count and obj.count > 0 then
  88. obj.count = obj.count - 1
  89. end
  90. self.text:GetComponent("Text").text = obj.content
  91. self.text.localPosition = Vector3(self.width / 2 ,0,0)
  92. self.textWidth = self.text:GetComponent("Text").preferredWidth
  93. self.text.sizeDelta = Vector2(self.textWidth,35)
  94. end