202 lines
6.4 KiB
Lua
202 lines
6.4 KiB
Lua
|
||
|
||
|
||
|
||
require("Base/BasePanel")
|
||
local MainShopPanel = Inherit(BasePanel)
|
||
local this = MainShopPanel
|
||
local oldAccumRecharge = 0
|
||
-- Tab管理器
|
||
local TabBox = require("Modules/Common/TabBox")
|
||
local _PageInfo = {
|
||
-- [1] = { -- 充值
|
||
-- default = "r_shop_chongzhi_01", lock = "r_shop_chongzhi_01", select = "r_shop_chongzhi_02",
|
||
-- rpType = RedPointType.Shop_Page_Recharge,
|
||
-- },
|
||
-- [2] = { -- 充值
|
||
-- default = "l_mrlb_icon2", lock = "l_mrlb_icon2", select = "l_mrlb_icon1",
|
||
-- rpType = RedPointType.DailyGift,
|
||
-- params = {DirectBuyType.DAILY_GIFT}, -- 每日礼包
|
||
-- },
|
||
-- [3] = { -- 充值
|
||
-- default = "t_tqsc_icon2", lock = "t_tqsc_icon2", select = "t_tqsc_icon1",
|
||
-- -- rpType = RedPointType.Shop_Page_Recharge,
|
||
-- params = {DirectBuyType.FINDTREASURE_GIFT},-- 特权礼包
|
||
-- },
|
||
-- [4] = { -- 成长礼包
|
||
-- default = "c_czlb_icon2", lock = "c_czlb_icon2", select = "c_czlb_icon1",
|
||
-- rpType = RedPointType.GrowthPackage,
|
||
-- params = {SHOP_TYPE.VIP_GIFT},-- 成长礼包
|
||
-- },
|
||
|
||
--(24暂时关闭)删除这里就行
|
||
[1] = { -- 充值
|
||
default = "t_tqsc_icon2", lock = "t_tqsc_icon2", select = "t_tqsc_icon1",
|
||
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.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"))
|
||
self.PageList = {
|
||
--(24暂时关闭)删除这里就行
|
||
-- [1] = RechargeView.new(self, Util.GetGameObject(self.transform, "content/ShopView")),
|
||
-- [2] = giftView,
|
||
-- [3] = giftView,
|
||
-- [4] = giftView,
|
||
[1] = giftView,
|
||
}
|
||
-- 上部货币显示
|
||
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 = Util.LoadSprite(_PageInfo[index][status])
|
||
img:SetNativeSize()
|
||
local islock = status == "lock"
|
||
Util.SetGray(img.gameObject, islock)
|
||
lock:SetActive(islock)
|
||
|
||
-- 判断是否需要检测红点
|
||
redpot:SetActive(false)
|
||
if not islock then
|
||
this.ClearPageRedpot(index)
|
||
this.BindPageRedpot(index, redpot)
|
||
end
|
||
end
|
||
|
||
-- tab可用性检测
|
||
function this.PageTabIsLockCheck(index)
|
||
return false
|
||
end
|
||
|
||
-- tab改变事件
|
||
function this.OnPageTabChange(index, lastIndex)
|
||
this._CurPageIndex = index
|
||
-- if lastIndex then
|
||
-- this.PageList[lastIndex]:OnHide()
|
||
-- this.PageList[lastIndex].gameObject:SetActive(false)
|
||
-- end
|
||
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()
|
||
end
|
||
|
||
SubUIManager.Close(this.UpView)
|
||
-- 清除红点
|
||
this.ClearPageRedpot()
|
||
end
|
||
return MainShopPanel |