miduo_client/Assets/ManagedResources/~Lua/Modules/ContinuePackage/ContinuePackagePanel.lua

259 lines
10 KiB
Lua
Raw Normal View History

2021-12-02 14:03:38 +08:00
require("Base/BasePanel")
2021-12-02 16:27:24 +08:00
local ContinuePackagePanel = Inherit(BasePanel)
2021-12-02 14:03:38 +08:00
local rechargeConfig = ConfigManager.GetConfig(ConfigName.RechargeCommodityConfig)
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local artResourcesConfig = ConfigManager.GetConfig(ConfigName.ArtResourcesConfig)
local BTNS = {
[1] = {bg1 = "b_baibao_andi",bg2 = "b_baibao_liangdi",text1 = "b_baibao_liangouhaoli-a",text2 = "b_baibao_liangouhaoli",title = "b_baibao_liangouhaoli-b"},
[2] = {bg1 = "b_baibao_andi",bg2 = "b_baibao_liangdi",text1 = "b_baibao_meiritehui-a",text2 = "b_baibao_meiritehui",title = "b_baibao_meiritehui-b"},
[3] = {bg1 = "b_baibao_andi",bg2 = "b_baibao_liangdi",text1 = "b_baibao_chaozhitehui-a",text2 = "b_baibao_chaozhitehui",title = "b_baibao_chaozhitehui-b"},
}
2021-12-06 11:23:31 +08:00
local btnType = {
LianGou = 1,
Meiri = 2,
ChaoZhi = 3,
}
2021-12-02 14:03:38 +08:00
2021-12-02 16:27:24 +08:00
function ContinuePackagePanel:InitComponent()
2021-12-02 14:03:38 +08:00
self.spLoader = SpriteLoader.New()
self.scrollItem = Util.GetGameObject(self.gameObject, "Bg/scroll")
self.itemPre = Util.GetGameObject(self.gameObject, "Bg/scroll/ItemPre")
self.backArena = Util.GetGameObject(self.gameObject, "backArena")
self.itemPre:SetActive(false)
self.leftTime = Util.GetGameObject(self.gameObject, "Bg/time/leftTime"):GetComponent("Text")
self.title = Util.GetGameObject(self.gameObject, "Bg/NameBg/Image"):GetComponent("Image")
self.btnList = {}
for i = 1, 3 do
self.btnList[i] = Util.GetGameObject(self.gameObject, "Bg/btns/btn"..i)
end
local rootHight = self.scrollItem.transform.rect.height
local width = self.scrollItem.transform.rect.width
self.scrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.scrollItem.transform,
2021-12-06 16:59:10 +08:00
self.itemPre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, -5))
2021-12-02 14:03:38 +08:00
self.scrollView.moveTween.MomentumAmount = 1
self.scrollView.moveTween.Strength = 2
self.scrollView.elastic = false
self.itemViewList = {}
self.sortingOrder = 0
2021-12-06 11:23:31 +08:00
self.curPage = btnType.LianGou
2021-12-02 14:03:38 +08:00
end
--绑定事件(用于子类重写)
2021-12-02 16:27:24 +08:00
function ContinuePackagePanel:BindEvent()
2021-12-02 14:03:38 +08:00
for i = 1, self.backArena.transform.childCount do
Util.AddOnceClick(self.backArena.transform:GetChild(i-1).gameObject, function()
self:ClosePanel()
end)
end
for j = 1, 3 do
Util.AddOnceClick(self.btnList[j], function()
if self.curPage ~= j then
self.curPage = j
2021-12-02 16:27:24 +08:00
ContinuePackagePanel:Refresh(true,true)
2021-12-02 14:03:38 +08:00
end
end)
end
end
--添加事件监听(用于子类重写)
2021-12-02 16:27:24 +08:00
function ContinuePackagePanel:AddListener()
2021-12-02 14:03:38 +08:00
Game.GlobalEvent:AddEvent(GameEvent.Activity.OnActivityProgressStateChange,self.Refresh,self)
end
--移除事件监听(用于子类重写)
2021-12-02 16:27:24 +08:00
function ContinuePackagePanel:RemoveListener()
2021-12-02 14:03:38 +08:00
Game.GlobalEvent:RemoveEvent(GameEvent.Activity.OnActivityProgressStateChange,self.Refresh,self)
end
2021-12-02 16:27:24 +08:00
function ContinuePackagePanel:OnSortingOrderChange()
2021-12-02 14:03:38 +08:00
end
local fun
--界面打开时调用(用于子类重写)
2021-12-02 16:27:24 +08:00
function ContinuePackagePanel:OnOpen(_linkActId, _fun)
2021-12-02 14:03:38 +08:00
self.linkActId = _linkActId
self.fun = _fun
end
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
2021-12-02 16:27:24 +08:00
function ContinuePackagePanel:OnShow()
self.curPage = 1
2021-12-02 16:27:24 +08:00
ContinuePackagePanel:Refresh(true,true)
2021-12-02 14:03:38 +08:00
end
2021-12-02 16:27:24 +08:00
function ContinuePackagePanel:Refresh(isTop,isAni)
self.actData = CommonActPageManager.GetData(ActivityTypeDef.ContinuePackage,self.linkActId)
2021-12-02 14:03:38 +08:00
self:SetBtns()
self:SetRewardShow(isTop,isAni)
self:SetTime()
end
2021-12-02 16:27:24 +08:00
function ContinuePackagePanel:SetBtns()
2021-12-02 14:03:38 +08:00
self.title.sprite = self.spLoader:LoadSprite(BTNS[self.curPage].title)
for i = 1, 3 do
2021-12-02 16:27:24 +08:00
if not self.actData.rewards[i] or #self.actData.rewards[i] <= 0 then
2021-12-02 14:03:38 +08:00
self.btnList[i]:SetActive(false)
else
self.btnList[i]:SetActive(true)
if self.curPage == i then
Util.GetGameObject(self.btnList[i],"Image"):GetComponent("Image").sprite = self.spLoader:LoadSprite(BTNS[i].text2)
self.btnList[i]:GetComponent("Image").sprite = self.spLoader:LoadSprite(BTNS[i].bg2)
else
Util.GetGameObject(self.btnList[i],"Image"):GetComponent("Image").sprite = self.spLoader:LoadSprite(BTNS[i].text1)
self.btnList[i]:GetComponent("Image").sprite = self.spLoader:LoadSprite(BTNS[i].bg1)
end
end
end
end
2021-12-02 16:27:24 +08:00
function ContinuePackagePanel:SetRewardShow(isTop,isAni)
2021-12-02 14:03:38 +08:00
-- 显示
self.scrollView:SetData(self.actData.rewards[self.curPage], function (index, item)
if self.actData.rewards[self.curPage][index].otherData.Type == self.curPage then
self:ShowSingleHero(item, self.actData.rewards[self.curPage][index],index)
end
end,not isTop,not isAni)
end
2021-12-02 16:27:24 +08:00
function ContinuePackagePanel:ShowSingleHero(go,data,index)
2021-12-02 14:03:38 +08:00
local grid = Util.GetGameObject(go, "Grid")
local btnGet = Util.GetGameObject(go, "btnGet")
local btnText = Util.GetGameObject(go, "btnGet/Text"):GetComponent("Text")
local btnImg = Util.GetGameObject(go, "btnGet"):GetComponent("Image")
local buyDayImg = Util.GetGameObject(go, "bugDay")
local buyDayText = Util.GetGameObject(buyDayImg, "Text"):GetComponent("Text")
local obj = Util.GetGameObject(btnGet, "Obj")
local icon = Util.GetGameObject(obj, "icon"):GetComponent("Image")
local cost = Util.GetGameObject(obj, "cost"):GetComponent("Text")
2021-12-02 17:13:33 +08:00
local canBuyTime = Util.GetGameObject(go, "times"):GetComponent("Text")
2021-12-02 14:03:38 +08:00
if not self.itemViewList[go] then
self.itemViewList[go] = {}
end
for k,v in ipairs(self.itemViewList[go]) do
v.gameObject:SetActive(false)
end
for i = 1, #data.otherData.Reward do
local rewardData = data.otherData.Reward[i]
if not self.itemViewList[go][i] then
self.itemViewList[go][i] = SubUIManager.Open(SubUIConfig.ItemView, grid.transform)
end
2023-01-17 10:45:21 +08:00
self.itemViewList[go][i]:OnOpen(false, rewardData, 0.8,false,false,false,self.sortingOrder)
2021-12-02 14:03:38 +08:00
self.itemViewList[go][i].gameObject:SetActive(true)
end
2021-12-02 17:13:33 +08:00
-- LogBlue("Id:"..tostring(data.missionId).." state:"..tostring(data.state).." progress:"..tostring(data.progress))
2021-12-02 14:03:38 +08:00
Util.SetGray(btnGet,false)
buyDayImg:SetActive(false)
btnText.gameObject:SetActive(false)
obj:SetActive(false)
2021-12-02 17:13:33 +08:00
canBuyTime.text = string.format( "剩余:%s次",data.progress)
2021-12-06 11:23:31 +08:00
canBuyTime.gameObject:SetActive(self.curPage ~= btnType.LianGou)--第一页连购好礼不显示剩余次数
2021-12-02 17:13:33 +08:00
btnImg.sprite = self.spLoader:LoadSprite("s_slbz_anniu")
2021-12-02 14:03:38 +08:00
if data.otherData.GoodType == 1 then--直购
btnText.gameObject:SetActive(true)
btnText.text = string.format("%s 元",data.otherData.Price)
2021-12-02 16:27:24 +08:00
if data.state == 8 then
2021-12-02 14:03:38 +08:00
btnImg.sprite = self.spLoader:LoadSprite("s_slbz_1anniuhuise")
btnText.text = Language[10514]
2021-12-02 17:13:33 +08:00
canBuyTime.text = ""
2021-12-02 16:27:24 +08:00
elseif data.state == 3 then
2021-12-02 14:03:38 +08:00
Util.SetGray(btnGet,true)
2021-12-02 16:27:24 +08:00
elseif data.state == 2 then
2021-12-02 14:03:38 +08:00
Util.SetGray(btnGet,true)
buyDayImg:SetActive(true)
buyDayText.text = string.format("%s日后可购",data.otherData.canBuyDay)
end
elseif data.otherData.GoodType == 2 then--商品
obj:SetActive(true)
icon.sprite = self.spLoader:LoadSprite(GetSpriteNameByItemId(data.otherData.Price[1]))
cost.text = data.otherData.Price[2]
2021-12-02 16:27:24 +08:00
if data.state == 8 then
2021-12-02 14:03:38 +08:00
obj:SetActive(false)
btnText.gameObject:SetActive(true)
btnImg.sprite = self.spLoader:LoadSprite("s_slbz_1anniuhuise")
btnText.text = Language[10514]
2021-12-02 17:13:33 +08:00
canBuyTime.text = ""
2021-12-02 16:27:24 +08:00
elseif data.state == 3 then
2021-12-02 14:03:38 +08:00
Util.SetGray(btnGet,true)
2021-12-02 16:27:24 +08:00
elseif data.state == 2 then
2021-12-02 14:03:38 +08:00
Util.SetGray(btnGet,true)
buyDayImg:SetActive(true)
buyDayText.text = string.format("%s日后可购",data.otherData.canBuyDay)
end
end
Util.AddOnceClick(btnGet,function ()
2021-12-02 16:27:24 +08:00
if data.state == 1 then
2021-12-02 17:13:33 +08:00
if data.otherData.GoodType == 1 then--直购
PayManager.Pay(data.otherData.GoodId, function(id)
FirstRechargeManager.RefreshAccumRechargeValue(data.otherData.GoodId)
OperatingManager.SetHadBuyGoodsId({data.otherData.GoodId})
-- OperatingManager.RemoveItemInfoByType(GoodsTypeDef.DirectPurchaseGift, data.otherData.GoodId)
2021-12-02 17:13:33 +08:00
self:Refresh(false,false)
end)
elseif data.otherData.GoodType == 2 then--商品
NetManager.ContinueBuyItemRequest(data.otherData.GoodId,function (drop)
UIManager.OpenPanel(UIName.RewardItemPopup,drop,1,function()
self:Refresh(false,false)
end)
end)
end
2021-12-02 16:27:24 +08:00
elseif data.state == 3 then
2021-12-02 14:03:38 +08:00
PopupTipPanel.ShowTip("请先购买上一礼包,即可解锁此礼包")
2021-12-02 16:27:24 +08:00
elseif data.state == 2 then
2021-12-02 14:03:38 +08:00
PopupTipPanel.ShowTip("礼包尚未开启,请耐心等待")
end
end)
end
2021-12-02 16:27:24 +08:00
function ContinuePackagePanel:SetTime()
2021-12-02 14:03:38 +08:00
if self.timer then
self.timer:Stop()
self.timer = nil
end
local time = self.actData.endTime - GetTimeStamp()
2021-12-06 11:38:52 +08:00
local leftTime = time - 86280
if self.curPage == btnType.Meiri and leftTime > 0 then--如果是每日特惠显示每日倒计时
2021-12-06 11:23:31 +08:00
time = CalculateSecondsNowTo_N_OClock(24)
end
2021-12-06 11:38:52 +08:00
--每日特惠处理
2021-12-02 14:03:38 +08:00
self.leftTime.text = Language[10512]..TimeToFelaxible(time)
2021-12-06 11:38:52 +08:00
if self.curPage == btnType.Meiri then
self.leftTime.text = Language[10023]..TimeToFelaxible(time)
end
2021-12-02 14:03:38 +08:00
self.timer = Timer.New(function ()
if time <= 0 then
2021-12-06 11:38:52 +08:00
if self.curPage == btnType.Meiri and leftTime > 0 then
2021-12-06 11:23:31 +08:00
self:Refresh(false,false)
return
end
2021-12-02 14:03:38 +08:00
self:ClosePanel()
end
self.leftTime.text = Language[10512]..TimeToFelaxible(time)
2021-12-06 11:30:46 +08:00
if self.curPage == btnType.Meiri then
self.leftTime.text = Language[10023]..TimeToFelaxible(time)
end
2021-12-02 14:03:38 +08:00
time = time -1
end, 1, -1, true)
self.timer:Start()
end
2021-12-02 16:27:24 +08:00
function ContinuePackagePanel:OnClose()
2021-12-02 14:03:38 +08:00
if self.timer then
self.timer:Stop()
self.timer = nil
end
self.sortingOrder = 0
if self.fun then
self.fun()
self.fun = nil
end
end
--界面销毁时调用(用于子类重写)
2021-12-02 16:27:24 +08:00
function ContinuePackagePanel:OnDestroy()
2021-12-02 14:03:38 +08:00
self.spLoader:Destroy()
self.itemViewList = {}
end
2021-12-02 16:27:24 +08:00
return ContinuePackagePanel