177 lines
5.6 KiB
Lua
177 lines
5.6 KiB
Lua
require("Base/BasePanel")
|
|
local FifteenDayGift = Inherit(BasePanel)
|
|
local this = FifteenDayGift
|
|
local sortingOrder = 0
|
|
local Data
|
|
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
|
local itemList = {}
|
|
local ItemViewList = {}
|
|
local frontList = {}
|
|
local backList = {}
|
|
|
|
local angle = {
|
|
[1] = Quaternion.Euler(Vector3.New(0, 0, 0)),
|
|
[2] = Quaternion.Euler(Vector3.New(0, 90, 0)),
|
|
}
|
|
|
|
--初始化组件(用于子类重写)
|
|
function FifteenDayGift:InitComponent()
|
|
self.backBtn1 = Util.GetGameObject(self.gameObject,"Content/btnBack1")
|
|
self.backBtn2 = Util.GetGameObject(self.gameObject,"Content/btnBack2")
|
|
self.backBtn3 = Util.GetGameObject(self.gameObject,"Content/btnBack3")
|
|
self.btnGet = Util.GetGameObject(self.gameObject,"Content/btnGet")
|
|
self.rewardGrid = Util.GetGameObject(self.gameObject,"Content/RewardGrid")
|
|
for i = 1, self.rewardGrid.transform.childCount do
|
|
table.insert(itemList, self.rewardGrid.transform:GetChild(i - 1))
|
|
end
|
|
end
|
|
--绑定事件(用于子类重写)
|
|
function FifteenDayGift:BindEvent()
|
|
Util.AddClick(self.backBtn1,function ()
|
|
self:ClosePanel()
|
|
end)
|
|
Util.AddClick(self.backBtn2,function ()
|
|
self:ClosePanel()
|
|
end)
|
|
Util.AddClick(self.backBtn3,function ()
|
|
self:ClosePanel()
|
|
end)
|
|
Util.AddClick(self.btnGet,function ()
|
|
if #frontList == 0 then
|
|
PopupTipPanel.ShowTip("暂无可领取的奖励~")
|
|
return
|
|
end
|
|
NetManager.GetActivityRewardRequest(-1,Data.activityId,function (drop)
|
|
for i = 1, #frontList do
|
|
local thread=coroutine.start(function()
|
|
frontList[i].transform:DORotate(Vector3.New(0, 90, 0), 0.3)
|
|
coroutine.wait(0.3)
|
|
frontList[i]:SetActive(false)
|
|
backList[i].transform:DORotate(Vector3.New(0, 0, 0), 0.3)
|
|
coroutine.wait(0.3)
|
|
UIManager.OpenPanel(UIName.RewardItemPopup, drop, 1,function()
|
|
FifteenDayGift:Refresh()
|
|
end)
|
|
end)
|
|
end
|
|
end)
|
|
|
|
end)
|
|
end
|
|
|
|
--添加事件监听(用于子类重写)
|
|
function FifteenDayGift:AddListener()
|
|
end
|
|
|
|
--移除事件监听(用于子类重写)
|
|
function FifteenDayGift:RemoveListener()
|
|
end
|
|
|
|
function FifteenDayGift:OnSortingOrderChange()
|
|
-- Util.AddParticleSortLayer(self.effect, self.sortingOrder - sortingOrder)
|
|
sortingOrder = self.sortingOrder
|
|
end
|
|
|
|
--界面打开时调用(用于子类重写)
|
|
function FifteenDayGift:OnOpen()
|
|
end
|
|
|
|
-- 打开,重新打开时回调
|
|
function FifteenDayGift:OnShow()
|
|
FifteenDayGift:Refresh()
|
|
end
|
|
|
|
function FifteenDayGift:Refresh()
|
|
Data = FifteenDayGiftManager.GetData()
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
frontList = {}
|
|
backList = {}
|
|
FifteenDayGift:SetReward()
|
|
end
|
|
|
|
function FifteenDayGift:SetReward()
|
|
if Data and #Data.rewards > 0 then
|
|
for i = 1, #itemList do
|
|
FifteenDayGift:SetSingleReward(Data.rewards[i],itemList[i],i)
|
|
end
|
|
end
|
|
end
|
|
|
|
function FifteenDayGift:SetSingleReward(sData,go,index)
|
|
local front = Util.GetGameObject(go,"front")
|
|
local name = Util.GetGameObject(go,"name"):GetComponent("Text")
|
|
local icon = Util.GetGameObject(go,"icon"):GetComponent("Image")
|
|
local num = Util.GetGameObject(go,"num"):GetComponent("Text")
|
|
local back = Util.GetGameObject(go,"back")
|
|
local curTime = GetTimeStamp()
|
|
|
|
--弄一个ItemView提供点击方法
|
|
if not ItemViewList[index] then
|
|
local view = SubUIManager.Open(SubUIConfig.ItemView,icon.transform)
|
|
ItemViewList[index] = view
|
|
end
|
|
ItemViewList[index]:OnOpen(false,sData.Reward,0,false)
|
|
ItemViewList[index].gameObject:SetActive(false)
|
|
|
|
--设置图片初始角度
|
|
front:GetComponent("RectTransform").rotation = sData.State == 0 and angle[1] or angle[2]
|
|
back:GetComponent("RectTransform").rotation = sData.State == 1 and angle[1] or angle[2]
|
|
--判断哪些可领取,插入表
|
|
if sData.Progress <= curTime and sData.State == 0 then
|
|
table.insert(frontList,front)
|
|
table.insert(backList,back)
|
|
end
|
|
--如果已领取、可领取、不可领取显示第几天;下一领取显示时间
|
|
if sData.Progress > curTime and sData.Progress - 86400 <= curTime then
|
|
local time = sData.Progress - GetTimeStamp()
|
|
name.text = TimeToFelaxible(time)
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
self.timer = Timer.New(function()
|
|
time = time - 1
|
|
if time <= 0 then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
FifteenDayGift:Refresh()
|
|
end
|
|
name.text = TimeToFelaxible(time)
|
|
end, 1, -1, true)
|
|
self.timer:Start()
|
|
else
|
|
name.text = FixableString(itemConfig[sData.Reward[1]].Name,5)
|
|
end
|
|
--设置icon 和数量
|
|
icon.sprite = SetIcon(sData.Reward[1])
|
|
num.text = string.format("X %s",sData.Reward[2])
|
|
|
|
Util.AddOnceClick(icon.gameObject,function ()
|
|
ItemViewList[index]:OnBtnCkickEvent(sData.Reward[1])
|
|
end)
|
|
end
|
|
|
|
--界面关闭时调用(用于子类重写)
|
|
function FifteenDayGift:OnClose()
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
end
|
|
|
|
--界面销毁时调用(用于子类重写)
|
|
function FifteenDayGift:OnDestroy()
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
itemList = {}
|
|
ItemViewList = {}
|
|
frontList = {}
|
|
backList = {}
|
|
end
|
|
|
|
return FifteenDayGift |