sk-client/Assets/ManagedResources/~Lua/Modules/Login/NoticePopup.lua

100 lines
3.2 KiB
Lua
Raw Normal View History

2024-07-03 18:38:10 +08:00
require("Base/BasePanel")
NoticePopup = Inherit(BasePanel)
local this = NoticePopup
local LoginRoot_Url = VersionManager:GetVersionInfo("serverUrl")
--初始化组件(用于子类重写)
function NoticePopup:InitComponent()
this.mask = Util.GetGameObject(this.gameObject, "mask")
this.btnBack = Util.GetGameObject(this.gameObject, "btnBack")
this.pre = Util.GetGameObject(this.gameObject, "pre")
this.rect1 = Util.GetGameObject(this.gameObject, "rect")
this.grid = Util.GetGameObject(this.gameObject, "rect/content")
this.rect2 = Util.GetGameObject(this.gameObject, "details")
this.details = Util.GetGameObject(this.gameObject, "details/content"):GetComponent("Text")
this.btnDetailsBack = Util.GetGameObject(this.gameObject, "btnDetailsBack")
end
--绑定事件(用于子类重写)
function NoticePopup:BindEvent()
Util.AddClick(this.mask, function()
self:ClosePanel()
end)
Util.AddClick(this.btnBack, function()
self:ClosePanel()
end)
Util.AddClick(this.btnDetailsBack, function()
this.rect2:SetActive(false)
this.rect1:SetActive(true)
this.btnDetailsBack:SetActive(false)
end)
end
--添加事件监听(用于子类重写)
function NoticePopup:AddListener()
end
--移除事件监听(用于子类重写)
function NoticePopup:RemoveListener()
end
--界面打开时调用(用于子类重写)
function NoticePopup:OnOpen(...)
this.GetNotice()
end
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
function NoticePopup:OnShow()
end
--界面关闭时调用(用于子类重写)
function NoticePopup:OnClose()
end
--界面销毁时调用(用于子类重写)
function NoticePopup:OnDestroy()
end
function this.GetNotice()
local timeStamp = Time.realtimeSinceStartup
local timeSign = Util.MD5Encrypt(string.format("%s%s", timeStamp, LoginManager.sign))
RequestPanel.Show(GetLanguageStrById(11128))
networkMgr:SendGetHttp(LoginRoot_Url.."tk/getNotice?timestamp="..timeStamp.."&sign="..timeSign, function (str)
2024-07-03 18:38:10 +08:00
RequestPanel.Hide()
if str == nil then
return
end
local json = require 'cjson'
local data = json.decode(str)
if data.parms then
-- this.TitleText.text = data.parms.title
-- this.ContentText.text = string.gsub(data.parms.content, "\\n", "\n")
this.SetNotice(data.parms.notice_list)
else
-- this.TitleText.text = GetLanguageStrById(11129)
-- this.ContentText.text = GetLanguageStrById(11130)
end
end, nil, nil, nil)
end
local notice = {}
function this.SetNotice(list)
for i = 1, #notice do
notice[i]:SetActive(false)
end
for i = 1, #list do
if not notice[i] then
notice[i] = newObjToParent(this.pre, this.grid)
end
notice[i]:SetActive(true)
Util.GetGameObject(notice[i], "Text"):GetComponent("Text").text = list[i].title
Util.AddOnceClick(notice[i], function ()
this.rect1:SetActive(false)
this.rect2:SetActive(true)
this.btnDetailsBack:SetActive(true)
this.details.text = string.gsub(list[i].content, "\\n", "\n")
end)
end
end
return NoticePopup