Files
JJBB/Assets/Project/Script/LuaScripts/UI/Lua/UINotice/UISpecialNotice.txt
2024-08-23 15:49:34 +08:00

219 lines
5.9 KiB
Plaintext

require "BaseClass"
require "Words"
require "SpecialNoticeMgr"
local msgList = {}
local usedMsgList = {}
local inTime = 2 -- 出去运动时间
local outTime = 2 -- 进入运动时间
local stayTime = 3 -- 界面停留时间
local moveInY = -45
local moveoutY = 45
local startStay = false
local startStayTime
local getMsgInterval = 2
local getMsgStartTime = 0
local showDuration = outTime + stayTime
UISpecialNotice = UISpecialNotice or BaseClass()
function UISpecialNotice.Awake()
-- 组件初始化
-- local ui1 = textItem1:GetComponent("Text")
textItem1:SetActive(false)
for i = 1,5 do
local go = CS.LuaUIBehaviour.InstantiateSubItem(textItem1,ViewPanel)
local uiGo = go.transform:Find("LabelNotice1")
local ui = uiGo:GetComponent("Text")
go:SetActive(false)
table.insert(usedMsgList,{go = go,ui = ui})
end
textItem1:SetActive(false)
end
function UISpecialNotice.Start()
end
function UISpecialNotice.Update()
-- 消息处理
local msgDataList = SpecialNoticeMgr.GetInstance():GetMsgList()
if #msgDataList > 0 then
-- 取消息的间隔时间是2秒
local curTime = CS.UnityEngine.Time.time
if curTime - getMsgStartTime > getMsgInterval then
-- print("get usedMsgList ------------".."msgNum:"..tostring(#usedMsgList))
if #usedMsgList > 0 then
local msg = SpecialNoticeMgr.GetInstance():PopMsg()
if msg then
-- print("get msg ------------"..msg.."msgNum:"..tostring(#msgDataList))
local ret = UISpecialNotice.ShowMsg(msg)
getMsgStartTime = curTime
return
end
end
end
end
-- 消息进入
-- 消息出去
for i,v in ipairs(msgList) do
local item = v
if item.state == "out" then
local nowTime = CS.UnityEngine.Time.time
if nowTime - item.outTime >= 2 then
-- print("-------------set SetActive false---------------")
v.go:SetActive(false)
table.insert(usedMsgList,v)
table.remove(msgList,i)
break
end
end
end
if startStay then
local nowTime = CS.UnityEngine.Time.time
if nowTime - startStayTime > showDuration then
UISpecialNotice.Show(false)
startStay = false
end
end
end
function UISpecialNotice.Show(bShow)
rootUI:SetActive(bShow)
-- 如果是隐藏了,清空
if not bShow then
for i,v in ipairs(msgList) do
local item = v
v.go:SetActive(false)
table.insert(usedMsgList,v)
table.remove(msgList,i)
end
end
end
function UISpecialNotice.ShowMsg(msg)
local strMsg = msg or "test data have"
-- body
if usedMsgList[1] then
-- 移除列表中的项目
for i,v in ipairs(msgList) do
local item = v
local textUI = item.ui
-- textUI.text = strMsg
-- item.go:SetActive(true)
item.go.transform.localPosition = {x = 0, y = 0,z = 0}
local transform = item.go.transform
local worldPos = transform.parent.localToWorldMatrix:MultiplyPoint(CS.UnityEngine.Vector3(0,moveoutY,0))
item.outTime = CS.UnityEngine.Time.time
item.state = "out"
CS.iTween.MoveTo(item.go,worldPos,2)
end
local item = table.remove(usedMsgList)
item.state = "in"
local textUI = item.ui
local chatTxt = item.go:GetComponent("ChatInfoLogItem")
-- msg = "金光四散,{0}打开了{1},获得了{2}个<color=#ffffff>[#2,101010,101010,1,1,1,0]</color>[#2,101010,101010,1,1,1,0],简直太厉害了!"
-- msg = "玩家<color=#0096ff>{0}</color>领取了<color=#f2341b>每日充值</color>的奖励,强大的奖励让他战力不断地爬升!<color=#f2341b>[#19,6,121,Line_f2341b]</color>"
-- local newStr = UISpecialNotice.ParseLink(msg,textUI)
-- textUI.text = newStr
local chatHistoryItem = CS.Games.ChatHistory.ChatHistoryItem()
chatHistoryItem.EChannel = CS.GC_CHAT.CHATTYPE.CHAT_TYPE_NORMAL
chatHistoryItem.ChatInfo = msg
item.go:SetActive(true)
item.go.transform.localPosition = {x = 0, y = moveInY,z = 0}
table.insert(msgList,item)
local transform = item.go.transform
local worldPos = transform.parent.localToWorldMatrix:MultiplyPoint(CS.UnityEngine.Vector3(0,0,0))
CS.iTween.MoveTo(item.go,worldPos,2)
startStayTime = CS.UnityEngine.Time.time
startStay = true
UISpecialNotice.Show(true)
chatTxt:SetChatLog(chatHistoryItem)
-- 傻逼方式去掉下划线
-- local tempStr = textUI.text
-- chatTxt:ClearChat()
-- textUI.text = tempStr
end
end
-- function UISpecialNotice.ParseLink(linkStr,uiText)
-- -- body
-- local linkItemList = {}
-- local parseStr = linkStr
-- local s1,e1 = string.find(linkStr,'%[%#')
-- if s1 then
-- parseStr = ""
-- parseStr = parseStr..tostring(string.sub(linkStr,1,s1 - 1))
-- end
-- local text = uiText
-- local chatHistoryItem = CS.Games.ChatHistory.ChatHistoryItem()
-- while(s1)
-- do
-- local s2,e2 = string.find(linkStr,'%]',e1)
-- if s2 then
-- local linkItemStr = string.sub(linkStr,s1, s2 -1)
-- print("link item str"..tostring(linkItemStr))
-- local linkItem = CS.ChatLinkBase.CreateChatLinkBySendStr(text,chatHistoryItem,linkItemStr)
-- table.insert(linkItemList,linkItem)
-- -- 拼接link字符串
-- if linkItem then
-- -- print("linkItem"..tostring(linkItem))
-- -- print("linkItem input"..tostring(linkItem.StrInput))
-- -- print("linkItem show"..tostring(linkItem.StrShow))
-- parseStr = parseStr..linkItem.StrShow
-- end
-- end
-- s1,e1 = string.find(linkStr,'%[%#',s2)
-- if s1 and s2 then
-- parseStr = parseStr..string.sub(linkStr,s2 + 1,s1 -1)
-- else
-- parseStr = parseStr..string.sub(linkStr,s2 + 1)
-- end
-- end
-- -- print("--printParse item:"..parseStr)
-- return parseStr
-- end
function UISpecialNotice.OnNotice(msg)
-- body
UISpecialNotice.Show(true)
local msgStr = "test"..tostring(CS.UnityEngine.Time.time)
msgStr = msg
local noticeStr = CS.GCGame.Table.StrDictionary.GetServerDictionaryFormatString(msgStr)
-- print("--------------------------------AddMsg"..noticeStr)
SpecialNoticeMgr.GetInstance():AddMsg(noticeStr)
end