|
|
- --屏幕中间漂浮的电视文字
- TV = TV or BaseClass(BaseView)
- function TV:__init()
- self.base_file = "chat"
- self.layout_file = "tv"
- self.layer_name = "Top"
- self.model = ChatModel:getInstance()
- self.visible = false
- self.load_callback = function ()
- self:LoadSuccess()
- end
- self.open_callback = function ()
- self:SetVisible(false)
- self:InitEvent()
- end
- self.destroy_callback = function ()
- self:Remove()
- end
- self.width = 860
- end
- function TV:Remove()
-
- end
-
- function TV:SetVisible(bool)
- self.gameObject:SetActive(bool)
- self.visible = bool
- end
-
- function TV:LoadSuccess()
- self.transform.localPosition = Vector3(0,ScreenHeight / 2 - 150, 0)
- self.bg_img = self:GetChild("bg"):GetComponent("Image")
- self.bg_img.alpha = 0.8
- self.text = self:GetChild("Text")
- end
-
- function TV:InitEvent()
- local onCheck = function()
- if self.visible or self.model.tv_state == false then
- return
- end
- local list = self.model:GetTVList()
- local client_time = TimeUtil:getClientTime()
- local ser_time = TimeUtil:getServerTime()
- local ind = 1
- for _,obj in pairs(list) do
- if obj.times ~= 0 and obj.count <= 0 or ser_time > obj.endTime then
- table.remove(list,ind)
- ind = ind - 1
- elseif obj.startTime < ser_time and client_time - obj.interval_time > obj.interval then
- obj.interval_time = client_time
- if obj.type == 0 then --发滚屏
- self:SetVisible(true)
- self:addContent(obj)
- elseif obj.type == 1 then --发聊天
- GlobalEventSystem:Fire(EventName.SHOW_GONGGAO,obj)
- else --都发
- GlobalEventSystem:Fire(EventName.SHOW_GONGGAO,obj)
- self:SetVisible(true)
- self:addContent(obj)
- end
- end
- ind = ind + 1
- end
- end
- self.check_timerId = GlobalTimerQuest:AddPeriodQuest(onCheck, 2, -1)
- local onMove = function()
- if self.visible then
- local pos_x = self.text.localPosition.x
- if pos_x <= -(self.width / 2 + self.textWidth)then
- self:SetVisible(false)
- return
- end
- self.text.localPosition = Vector3(pos_x - 5 ,0,0)
- end
-
- end
- self.move_timerId = GlobalTimerQuest:AddPeriodQuest(onMove, 0.05, -1)
- end
-
- function TV:addContent(obj)
- local content = nil
- if obj.link ~= nil and #obj.link > 0 then
- content = "<font color='#fffc00'>"..
- "<a href='event:"..
- obj.link[1]..
- "'>"..
- obj.content..
- "</a></font>"
- else
- content = "<font color='#fffc00'>"..obj.content.."</font>"
- end
- if obj.count and obj.count > 0 then
- obj.count = obj.count - 1
- end
- self.text:GetComponent("Text").text = obj.content
- self.text.localPosition = Vector3(self.width / 2 ,0,0)
- self.textWidth = self.text:GetComponent("Text").preferredWidth
- self.text.sizeDelta = Vector2(self.textWidth,35)
- end
-
|