136 lines
5.6 KiB
Lua
136 lines
5.6 KiB
Lua
require("Base/BasePanel")
|
|
NoticePopup = Inherit(BasePanel)
|
|
local this = NoticePopup
|
|
local prelist={}
|
|
--初始化组件(用于子类重写)
|
|
function NoticePopup:InitComponent()
|
|
this.spLoader = SpriteLoader.New()
|
|
|
|
this.BtnBack = Util.GetGameObject(self.transform, "bg/bg/btnBack")
|
|
this.TitleText=Util.GetGameObject(self.transform,"bg/bg/title"):GetComponent("Text")
|
|
this.ContentText=Util.GetGameObject(self.transform,"bg/bg/rect/GameObject"):GetComponent("Text")
|
|
this.content=Util.GetGameObject(self.transform,"bg/bg/rect/content")
|
|
this.go=Util.GetGameObject(self.transform,"bg/bg/noticeItem")
|
|
end
|
|
|
|
--绑定事件(用于子类重写)
|
|
function NoticePopup:BindEvent()
|
|
|
|
Util.AddClick(this.BtnBack, function()
|
|
self:ClosePanel()
|
|
end)
|
|
end
|
|
|
|
--添加事件监听(用于子类重写)
|
|
function NoticePopup:AddListener()
|
|
|
|
end
|
|
|
|
--移除事件监听(用于子类重写)
|
|
function NoticePopup:RemoveListener()
|
|
|
|
|
|
end
|
|
local str
|
|
--界面打开时调用(用于子类重写)
|
|
function NoticePopup:OnOpen(...)
|
|
str=...
|
|
|
|
|
|
end
|
|
|
|
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
|
|
function NoticePopup:OnShow()
|
|
this.GetNotice(str)
|
|
ForceRebuildLayout(this.content.transform)
|
|
end
|
|
|
|
--界面关闭时调用(用于子类重写)
|
|
function NoticePopup:OnClose()
|
|
|
|
end
|
|
|
|
--界面销毁时调用(用于子类重写)
|
|
function NoticePopup:OnDestroy()
|
|
this.spLoader:Destroy()
|
|
prelist = {}
|
|
end
|
|
|
|
function this.GetNotice(str)
|
|
-- LogError(str)
|
|
RequestPanel.Hide()
|
|
if str == nil then
|
|
return
|
|
end
|
|
--Log(str)
|
|
local json = require 'cjson'
|
|
local data = json.decode(str)
|
|
|
|
-- LogError("data.parms.title:".. tostring(data.list))
|
|
-- for key, value in pairs(data.list) do
|
|
-- value.content="一群人在这里忙碌,嬉闹着搭帐篷建营地这是一个由公司同事私下组织的野营活动,当然,全都是年轻人,因为要背着帐篷等装备登山远足,年长一些的人体力不够原本大家是希望公司组织一次野营的,但公司每年都是组团旅游,有导游开大巴的那种,所以今年,很多同事干脆不跟随公司一起,反而是让几个有户外经验的同事领头自己组织,所以也有了这次登山野营。一群人在这里忙碌,嬉闹着搭帐篷建营地这是一个由公司同事私下组织的野营活动,当然,全都是年轻人,因为要背着帐篷等装备登山远足,年长一些的人体力不够原本大家是希望公司组织一次野营的,但公司每年都是组团旅游,有导游开大巴的那种,所以今年,很多同事干脆不跟随公司一起,反而是让几个有户外经验的同事领头自己组织,所以也有了这次登山野营。"
|
|
-- LogError("title:"..value.title.." content:"..value.content.." type:"..value.type)
|
|
-- end
|
|
this.TitleText.text=Language[11147]
|
|
if data.list and #data.list>0 then
|
|
this.ContentText.gameObject:SetActive(false)
|
|
table.sort(data.list, function(a, b)
|
|
return a.type < b.type
|
|
end)
|
|
for i = 1, math.max(#prelist,#data.list) do
|
|
local item=prelist[i]
|
|
if not item then
|
|
item=newObject(this.go)
|
|
item.transform:SetParent(this.content.transform)
|
|
item.transform.localScale=Vector3.one
|
|
item.transform.localPosition=Vector3.zero
|
|
prelist[i]=item
|
|
end
|
|
item.gameObject:SetActive(false)
|
|
end
|
|
for key, value in pairs(data.list) do
|
|
prelist[key]:SetActive(true)
|
|
local img=Util.GetGameObject(prelist[key],"Image/img"):GetComponent("Image")
|
|
if value.type==1 then
|
|
img.sprite=this.spLoader:LoadSprite("g_gg_zhongyao_zh")
|
|
elseif value.type==2 then
|
|
img.sprite=this.spLoader:LoadSprite("g_gg_xin_zh")
|
|
elseif value.type==3 then
|
|
img.sprite=this.spLoader:LoadSprite("g_gg_re_zh")
|
|
elseif value.type==4 then
|
|
img.gameObject:SetActive(false)
|
|
end
|
|
-- 表体
|
|
local title = Util.GetGameObject(prelist[key],"Image/title"):GetComponent("Text")
|
|
local titleStr = string.split(value.title,"|")
|
|
title.text = titleStr[GetCurLanguage()+1] or titleStr[1]
|
|
-- 内容
|
|
local content=Util.GetGameObject(prelist[key],"content"):GetComponent("Text")
|
|
local contentStr = string.split(string.gsub(value.content, "\\n", "\n"),"|")
|
|
content.text = contentStr[GetCurLanguage()+1] or contentStr[1]
|
|
|
|
local down=Util.GetGameObject(prelist[key],"Image/down")
|
|
local left=Util.GetGameObject(prelist[key],"Image/left")
|
|
local isOpen=true
|
|
down:SetActive(isOpen)
|
|
left:SetActive(not isOpen)
|
|
content.gameObject:SetActive(isOpen)
|
|
local btn=Util.GetGameObject(prelist[key],"Image")
|
|
Util.AddClick(btn,function()
|
|
isOpen=not isOpen
|
|
down:SetActive(isOpen)
|
|
left:SetActive(not isOpen)
|
|
content.gameObject:SetActive(isOpen)
|
|
end)
|
|
end
|
|
-- local titleStr = string.split(data.parms.title,"|")
|
|
-- this.TitleText.text =titleStr[GetCurLanguage()+1] or titleStr[1]
|
|
-- local contentStr = string.split(string.gsub(data.parms.content, "\\n", "\n"),"|")
|
|
-- this.ContentText.text = contentStr[GetCurLanguage()+1] or contentStr[1]
|
|
else
|
|
this.ContentText.gameObject:SetActive(true)
|
|
this.ContentText.text=Language[11148]
|
|
end
|
|
end
|
|
|
|
return NoticePopup |