miduo_client/Assets/ManagedResources/~Lua/Modules/Recharge/MainRechargePanel.lua

214 lines
6.7 KiB
Lua

require("Base/BasePanel")
local MainShopPanel = Inherit(BasePanel)
local this = MainShopPanel
local oldAccumRecharge = 0
-- Tab管理器
local TabBox = require("Modules/Common/TabBox")
local _PageInfo = {}
local _PageInfoCanRecharge={
[1] = { -- 充值
default = "r_shop_chongzhi_01_zh", lock = "r_shop_chongzhi_01_zh", select = "r_shop_chongzhi_02_zh",
rpType = RedPointType.Shop_Page_Recharge,
},
[2] = { -- 充值
default = "l_mrlb_icon2_zh", lock = "l_mrlb_icon2_zh", select = "l_mrlb_icon1_zh",
rpType = RedPointType.DailyGift,
params = {DirectBuyType.DAILY_GIFT}, -- 每日礼包
},
[3] = { -- 充值
default = "t_tqsc_icon2_zh", lock = "t_tqsc_icon2_zh", select = "t_tqsc_icon1_zh",
-- rpType = RedPointType.Shop_Page_Recharge,
params = {DirectBuyType.FINDTREASURE_GIFT},-- 特权礼包
},
[4] = { -- 成长礼包
default = "c_czlb_icon2_zh", lock = "c_czlb_icon2_zh", select = "c_czlb_icon1_zh",
rpType = RedPointType.GrowthPackage,
params = {SHOP_TYPE.VIP_GIFT},-- 成长礼包
},
}
local _PageInfoCantRecharge={
[1] = { -- 充值
default = "t_tqsc_icon2_zh", lock = "t_tqsc_icon2_zh", select = "t_tqsc_icon1_zh",
params = {DirectBuyType.FINDTREASURE_GIFT},-- 特权礼包
},
}
local GiftView = require("Modules/Recharge/View/GiftView")
local RechargeView = require("Modules/Recharge/View/RechargeView")
this._MainShopPageList = {}
this._MainShopTypeList = {}
--初始化组件(用于子类重写)
function MainShopPanel:InitComponent()
this.spLoader = SpriteLoader.New()
this.tabbox = Util.GetGameObject(self.gameObject, "tabbox")
this.btnBack = Util.GetGameObject(self.gameObject, "rightUp/btnBack")
this.content = Util.GetGameObject(self.gameObject, "content")
this.bg = {}
this.bg[1] = Util.GetGameObject(self.gameObject, "bg1")
this.bg[2] = Util.GetGameObject(self.gameObject, "bg2")
this.bg[3] = Util.GetGameObject(self.gameObject, "bg3")
local giftView = GiftView.new(self, Util.GetGameObject(self.transform, "content/page_1"))
if not RECHARGEABLE then--(是否开启充值)
_PageInfo = _PageInfoCantRecharge
self.PageList = {
[1] = giftView,
}
else
_PageInfo = _PageInfoCanRecharge
self.PageList = {
[1] = RechargeView.new(self, Util.GetGameObject(self.transform, "content/ShopView")),
[2] = giftView,
[3] = giftView,
[4] = giftView,
}
end
-- 上部货币显示
this.UpView = SubUIManager.Open(SubUIConfig.UpView, self.transform, { showType = UpViewOpenType.ShowLeft})
end
--绑定事件(用于子类重写)
function MainShopPanel:BindEvent()
-- 初始化Tab管理器
this.PageTabCtrl = TabBox.New()
this.PageTabCtrl:SetTabAdapter(this.PageTabAdapter)
this.PageTabCtrl:SetTabIsLockCheck(this.PageTabIsLockCheck)
this.PageTabCtrl:SetChangeTabCallBack(this.OnPageTabChange)
-- 关闭界面打开主城
Util.AddClick(this.btnBack, function()
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
this:ClosePanel()
end)
end
--添加事件监听(用于子类重写)
function MainShopPanel:AddListener()
end
--移除事件监听(用于子类重写)
function MainShopPanel:RemoveListener()
end
--界面打开时调用(用于子类重写)
function MainShopPanel:OnOpen(chooseIndex)
-- 音效
SoundManager.PlayMusic(SoundConfig.BGM_Shop)
-- 初始化tab数据
this.PageTabCtrl:Init(this.tabbox, _PageInfo)
this._CurPageIndex = 1
if chooseIndex and _PageInfo[chooseIndex] then
this._CurPageIndex = chooseIndex
end
end
-- 打开,重新打开时回调
function MainShopPanel:OnShow()
if this._CurPageIndex then
this.PageTabCtrl:ChangeTab(this._CurPageIndex)
end
end
-- 层级变化时,子界面层级刷新
function MainShopPanel:OnSortingOrderChange()
if this._CurPageIndex then
this.PageList[this._CurPageIndex]:OnSortingOrderChange(self.sortingOrder)
end
end
----==========================一级页签相关===========================================
-- tab按钮自定义显示设置
function this.PageTabAdapter(tab, index, status)
local img = Util.GetGameObject(tab, "img"):GetComponent("Image")
local lock = Util.GetGameObject(tab, "lock")
local redpot = Util.GetGameObject(tab, "redpot")
img.sprite = this.spLoader:LoadSprite(_PageInfo[index][status])
img:SetNativeSize()
local islock = status == "lock"
-- Util.SetGray(img.gameObject, islock)
lock:SetActive(islock)
tab:SetActive(not islock)
-- 判断是否需要检测红点
redpot:SetActive(false)
if not islock then
this.ClearPageRedpot(index)
this.BindPageRedpot(index, redpot)
end
end
-- tab可用性检测
function this.PageTabIsLockCheck(index)
if index == 2 then
if not OperatingManager.HasGoodsByShowType(14) then
return true
end
-- elseif index == 4 then
-- if not OperatingManager.HasGoodsByShowType(4) then
-- return true
-- end
end
return false
end
-- tab改变事件
function this.OnPageTabChange(index, lastIndex)
this._CurPageIndex = index
for i = 1, #this.PageList do
this.PageList[i]:OnHide()
this.PageList[i].gameObject:SetActive(false)
end
this.PageList[index]:OnShow(this.sortingOrder, _PageInfo[index].params and unpack(_PageInfo[index].params) or nil)
this.PageList[index].gameObject:SetActive(true)
end
-- 绑定数据
local _PageBindData = {}
local _TabBindData = {}
function this.BindPageRedpot(page, redpot)
local rpType = _PageInfo[page].rpType
if not rpType then return end
BindRedPointObject(rpType, redpot)
_PageBindData[rpType] = redpot
end
function this.ClearPageRedpot(page)
-- 清除红点绑定
if page then -- 清除某个
local rpType = _PageInfo[page].rpType
if not rpType then return end
ClearRedPointObject(rpType, _PageBindData[rpType])
_PageBindData[rpType] = nil
else -- 全部清除
for rpt, redpot in pairs(_PageBindData) do
ClearRedPointObject(rpt, redpot)
end
_PageBindData = {}
end
end
--界面关闭时调用(用于子类重写)
function MainShopPanel:OnClose()
if this._CurPageIndex then
this.PageList[this._CurPageIndex]:OnHide()
this.PageList[this._CurPageIndex].gameObject:SetActive(false)
end
end
--界面销毁时调用(用于子类重写)
function MainShopPanel:OnDestroy()
for _, page in ipairs(this.PageList) do
page:OnDestroy()
this.spLoader:Destroy()
end
SubUIManager.Close(this.UpView)
-- 清除红点
this.ClearPageRedpot()
end
return MainShopPanel