163 lines
5.3 KiB
Lua
163 lines
5.3 KiB
Lua
local CommonActPage = {}
|
|
local rechargeNum = 0
|
|
function CommonActPage:New(gameObject)
|
|
local b = {}
|
|
b.gameObject = gameObject
|
|
b.transform = gameObject.transform
|
|
setmetatable(b, { __index = CommonActPage })
|
|
return b
|
|
end
|
|
|
|
|
|
--添加事件监听(用于子类重写)
|
|
function CommonActPage:AddListener()
|
|
|
|
end
|
|
|
|
--移除事件监听(用于子类重写)
|
|
function CommonActPage:RemoveListener()
|
|
|
|
end
|
|
|
|
|
|
function CommonActPage:InitComponent()
|
|
self.bg = Util.GetGameObject(self.gameObject, "Bg/banner"):GetComponent("Image")
|
|
self.scrollItem = Util.GetGameObject(self.gameObject, "scrollItem")
|
|
self.time = Util.GetGameObject(self.gameObject, "time")
|
|
self.timeText = Util.GetGameObject(self.time, "timeText"):GetComponent("Text")
|
|
self.btnHelp = Util.GetGameObject(self.gameObject, "btnHelp")
|
|
self.helpPosition = self.btnHelp:GetComponent("RectTransform").localPosition
|
|
self.itemPre = Util.GetGameObject(self.gameObject, "ItemPre")
|
|
|
|
|
|
-- 设置循环滚动,万一内容不停地加
|
|
local rootHight = self.scrollItem.transform.rect.height
|
|
local width = self.scrollItem.transform.rect.width
|
|
self.scrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.scrollItem.transform,
|
|
self.itemPre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 0))
|
|
self.scrollView.moveTween.MomentumAmount = 1
|
|
self.scrollView.moveTween.Strength = 2
|
|
self.sortingOrder = 0
|
|
|
|
self.ItemList = {}
|
|
end
|
|
|
|
function CommonActPage:BindEvent()
|
|
Util.AddClick(self.btnHelp,function()
|
|
UIManager.OpenPanel(UIName.HelpPopup,self.actConfig.HelpId,self.helpPosition.x,self.helpPosition.y)
|
|
end)
|
|
end
|
|
|
|
--界面打开时调用(用于子类重写)
|
|
function CommonActPage:OnOpen(_activityConfig,_index,parent)
|
|
self.actConfig = _activityConfig
|
|
self.pageIndex = _index
|
|
self.parent = parent
|
|
self.gameObject.name = "CommonActPage"..self.actConfig.Id
|
|
PlayerPrefs.SetInt(PlayerManager.uid.."CommonActPage"..self.actConfig.ActiveType,1)
|
|
end
|
|
|
|
-- 打开,重新打开时回调
|
|
function CommonActPage:OnShow(_sortingOrder)
|
|
self.gameObject:SetActive(true)
|
|
self.sortingOrder = _sortingOrder or self.sortingOrder
|
|
self.actId = self.actConfig.ActId
|
|
self.actType = self.actConfig.ActiveType
|
|
if self.actConfig.IfBack == 1 then
|
|
if self.actConfig.ActiveType > 0 then
|
|
local id = ActivityGiftManager.IsActivityTypeOpen(self.actConfig.ActiveType)
|
|
if id and id > 0 then
|
|
self.actId = id
|
|
local config = ConfigManager.TryGetConfigDataByThreeKey(ConfigName.ActivityGroups,"PageType",self.actConfig.PageType,"ActiveType",self.actConfig.ActiveType,"ActId",id)
|
|
if config then
|
|
self.actConfig = config
|
|
end
|
|
else
|
|
LogRed("活动类型:"..tostring(self.actConfig.ActiveType).."的活动未开启")
|
|
end
|
|
end
|
|
end
|
|
if self.actConfig.Icon[3] and self.actConfig.Icon[3] ~= "" then
|
|
self.bg.sprite = Util.LoadSprite(self.actConfig.Icon[3])
|
|
end
|
|
|
|
--拿取数据
|
|
self:RefreshData(true,true,true)
|
|
end
|
|
--刷新数据
|
|
function CommonActPage:RefreshData(isUpdata,isTop,isAni)
|
|
self.ActData = CommonActPageManager.GetData(self.actConfig.ActiveType)
|
|
if self.actConfig.RpType > 0 then
|
|
CheckRedPointStatus(self.actConfig.RpType)
|
|
end
|
|
self:RefreshActData(isTop,isAni)
|
|
self:RefreshTime()
|
|
end
|
|
--刷新活动数据
|
|
function CommonActPage:RefreshActData(isTop,isAni)
|
|
self.scrollView:ForeachItemGO(function(index, go)
|
|
go.gameObject:SetActive(false)
|
|
end)
|
|
self.scrollView:SetData(self.ActData.rewards, function (index, item)
|
|
self:ShowSingleData(item, self.ActData.rewards[index],index)
|
|
end,not isTop,not isAni)
|
|
end
|
|
|
|
function CommonActPage:ShowSingleData(item,sdata,index)
|
|
if not self.ItemList then
|
|
self.ItemList = {}
|
|
end
|
|
if not self.ItemList[item] then
|
|
local subConfig = SubUIConfig[self.actConfig.UIName[2]]
|
|
self.ItemList[item] = SubUIManager.Open(subConfig,item.transform)
|
|
end
|
|
if not sdata then
|
|
item.gameObject:SetActive(false)
|
|
return
|
|
end
|
|
item.gameObject:SetActive(true)
|
|
self.ItemList[item]:SetData(sdata,self,self.sortingOrder,self.ActData,self.actConfig)
|
|
end
|
|
|
|
function CommonActPage:RefreshTime()
|
|
if self.actConfig.ShowTime == 0 then
|
|
self.time:SetActive(false)
|
|
return
|
|
end
|
|
if self.localTimer then
|
|
self.localTimer:Stop()
|
|
self.localTimer = nil
|
|
end
|
|
self.time:SetActive(true)
|
|
local freshTime = self.ActData.endTime - GetTimeStamp()
|
|
self.timeText.text = Language[10023]..TimeToFelaxible(freshTime)
|
|
self.localTimer = Timer.New(function ()
|
|
freshTime = freshTime - 1
|
|
self.timeText.text = Language[10023]..TimeToFelaxible(freshTime)
|
|
if freshTime <= 0 then
|
|
self.parent:ClosePanel()
|
|
end
|
|
end, 1, -1, true)
|
|
self.localTimer:Start()
|
|
end
|
|
|
|
function CommonActPage:OnClose()
|
|
self.gameObject:SetActive(false)
|
|
end
|
|
|
|
function CommonActPage:OnDestroy()
|
|
if self.localTimer then
|
|
self.localTimer:Stop()
|
|
self.localTimer = nil
|
|
end
|
|
for k,v in pairs(self.ItemList) do
|
|
SubUIManager.Close(v)
|
|
end
|
|
self.ItemList = {}
|
|
if self.scrollView then
|
|
SubUIManager.Close(self.scrollView)
|
|
end
|
|
self.scrollView=nil
|
|
end
|
|
|
|
return CommonActPage |