miduo_client/Assets/ManagedResources/~Lua/Modules/Shop/MainShopPanel.lua

442 lines
16 KiB
Lua

require("Base/BasePanel")
local MainShopPanel = Inherit(BasePanel)
local this = MainShopPanel
-- Tab管理器
local TabBox = require("Modules/Common/TabBox")
local _Tab2Sprite = {default = "Btn_hz_tongyong_002", select = "Btn_hz_tongyong_001", lock = "s_shop_qieye_1"}
local _Tab2FontColor = { default = Color.New(255 / 255, 255 / 255, 255 / 255, 1),
lock = Color.New(255 / 255, 255 / 255, 255 / 255, 1),
select = Color.New(255 / 255, 255 / 255, 255 / 255, 1) }
local _ShopTypeConfig = ConfigManager.GetConfig(ConfigName.StoreTypeConfig)
local _ShopPage = {
[SHOP_PAGE.RECHARGE] = { -- 充值
default = "UI_hz_gonghui_31", lock = "UI_hz_gonghui_31", select = "UI_hz_gonghui_31",
rpType = RedPointType.Shop_Page_Recharge,name="充值商店"
},
[SHOP_PAGE.GENERAL] = { -- 杂货
default = "UI_hz_gonghui_32", lock = "UI_hz_gonghui_32", select = "UI_hz_gonghui_32",
rpType = RedPointType.Shop_Page_General,name="杂货商店"
},
[SHOP_PAGE.COIN] ={ -- 代币
default = "UI_hz_gonghui_33", lock = "UI_hz_gonghui_33", select = "UI_hz_gonghui_33",
rpType = RedPointType.Shop_Page_Coin,name="代币商店"
},
[SHOP_PAGE.PLAY] = { -- 玩法
default = "UI_hz_gonghui_34", lock = "UI_hz_gonghui_34", select = "UI_hz_gonghui_34",
rpType = RedPointType.Shop_Page_Play,name="玩法商店"
},
[SHOP_PAGE.EXCHANGE] = { -- 兑换
default = "UI_hz_gonghui_31", lock = "UI_hz_gonghui_31", select = "UI_hz_gonghui_31",name="兑换商店"
},
[SHOP_PAGE.JUMPSERVER] = { -- 云游
default = "UI_hz_gonghui_32", lock = "UI_hz_gonghui_32", select = "UI_hz_gonghui_32",
rpType = RedPointType.Shop_Page_Roam,name="推进城"
},
[SHOP_PAGE.YUANSHEN] = { -- 元神
default = "UI_hz_gonghui_33", lock = "UI_hz_gonghui_33", select = "UI_hz_gonghui_33",name="元神商店"
},
}
this._MainShopPageList = {}
this._MainShopTypeList = {}
--初始化组件(用于子类重写)
function MainShopPanel:InitComponent()
this.spLoader = SpriteLoader.New()
this.tabbox = Util.GetGameObject(self.gameObject, "tabbox")
this.tabbox2 = Util.GetGameObject(self.gameObject, "tabbox2")
this.tabbox2Content = Util.GetGameObject(self.gameObject, "tabbox2/box")
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")
-- 显示特权信息
this.vipInfoPart = Util.GetGameObject(self.gameObject, "VipInfoPart")
this.vipChargeRoot = Util.GetGameObject(this.vipInfoPart, "textGrid")
this.chargeNum = Util.GetGameObject(this.vipInfoPart, "textGrid/num"):GetComponent("Text")
this.moneyIcon = Util.GetGameObject(this.vipInfoPart, "textGrid/icon/Image"):GetComponent("Image")
this.vipLevelTip = Util.GetGameObject(this.vipInfoPart, "textGrid/end"):GetComponent("Text")
this.vipIconLevel = Util.GetGameObject(this.vipInfoPart, "vipIcon/num"):GetComponent("Text")
this.vipHeroStar = Util.GetGameObject(this.vipInfoPart, "reward/Text"):GetComponent("Image")
-- 进度
this.vipProgress = Util.GetGameObject(this.vipInfoPart, "Slider/fill"):GetComponent("Image")
this.vipDetailBtn = Util.GetGameObject(this.vipInfoPart, "btnDetail")
this.progressText = Util.GetGameObject(this.vipInfoPart, "Slider/value"):GetComponent("Text")
this.vipRedPoint = Util.GetGameObject(this.vipDetailBtn, "redPoint")
BindRedPointObject(RedPointType.VIP_SHOP_DETAIL, this.vipRedPoint)
-- 上部货币显示
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)
this.ShopTabCtrl = TabBox.New()
this.ShopTabCtrl:SetTabAdapter(this.ShopTabAdapter)
this.ShopTabCtrl:SetTabIsLockCheck(this.ShopTabIsLockCheck)
this.ShopTabCtrl:SetChangeTabCallBack(this.OnShopTabChange)
-- 关闭界面打开主城
Util.AddClick(this.btnBack, function()
ShopManager.SetSelectIndex(0,{})
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
--UIManager.OpenPanel(UIName.MainPanel)
this:ClosePanel()
end)
-- 打开特权详情
Util.AddClick(this.vipDetailBtn, function ()
UIManager.OpenPanel(UIName.VipPanelV2)
end)
end
--添加事件监听(用于子类重写)
function MainShopPanel:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.Bag.BagGold, this.SetVipPartInfo)
end
--移除事件监听(用于子类重写)
function MainShopPanel:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.Bag.BagGold, this.SetVipPartInfo)
end
--界面打开时调用(用于子类重写)
function MainShopPanel:OnOpen(chooseShopType)
-- 音效
SoundManager.PlayMusic(SoundConfig.BGM_Shop)
-- 初始化tab数据
this._MainShopPageList = ShopManager.GetMainShopPageList()
this.PageTabCtrl:Init(this.tabbox, this._MainShopPageList)
-- 从主界面打开,跳转到有免费物品的商店
--if isMain then
-- chooseShopType = ShopManager.GetMainShopFreeShop()
--end
-- 检测默认打开
chooseShopType = chooseShopType or SHOP_TYPE.SOUL_STONE_SHOP -- 默认打开魂晶商店
if not ShopManager.IsActive(chooseShopType) then
PopupTipPanel.ShowTip(Language[11886])
chooseShopType = SHOP_TYPE.SOUL_STONE_SHOP --商店未激活,打开充值商店
end
-- 获取默认页index
local shopPage = ShopManager.GetShopPageByShopType(chooseShopType)
for pageIndex, page in ipairs(this._MainShopPageList) do
if page == shopPage then
this._ChoosePageIndex = pageIndex
break
end
end
-- 获取默认商店index
local shopTypeList = ShopManager.GetMainPageShopTypeList(shopPage)
for shopIndex, shopType in ipairs(shopTypeList) do
if shopType == chooseShopType then
this._ChooseShopIndex = shopIndex
break
end
end
assert(this._ChoosePageIndex and this._ChooseShopIndex, Language[11887])
end
-- 打开,重新打开时回调
function MainShopPanel:OnShow()
-- 判断是否要打开选择的界面
if this._ChoosePageIndex and this._ChooseShopIndex then
-- 打开选择page
if this.PageTabCtrl and this._ChoosePageIndex ~= this._CurPageIndex then
this.PageTabCtrl:ChangeTab(this._ChoosePageIndex)
end
this._ChoosePageIndex = nil
-- 打开选择的shop
if this.ShopTabCtrl and this._ChooseShopIndex ~= this._CurShopIndex then
this.ShopTabCtrl:ChangeTab(this._ChooseShopIndex)
end
this._ChooseShopIndex = nil
else
local shopType = this._MainShopTypeList[this._CurShopIndex]
this.shopView:ShowShop(shopType,this.sortingOrder)
end
end
-- 层级变化时,子界面层级刷新
function MainShopPanel:OnSortingOrderChange()
if this.shopView then
this.shopView:SetSortLayer(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")
local select = Util.GetGameObject(tab, "select")
local Text=Util.GetGameObject(tab,"Text"):GetComponent("Text")
local page = this._MainShopPageList[index]
img.sprite = this.spLoader:LoadSprite(_ShopPage[page][status])
local islock = status == "lock"
select:SetActive(status=="select")
Util.SetGray(img.gameObject, islock)
lock:SetActive(islock)
Text.text = GetLanguageStrById(_ShopPage[page]["name"])
-- 判断是否需要检测红点
redpot:SetActive(false)
if not islock then
this.ClearPageRedpot(page)
this.BindPageRedpot(page, redpot)
end
end
-- tab可用性检测
function this.PageTabIsLockCheck(index)
local page = this._MainShopPageList[index]
local isActive, errorTip = ShopManager.IsPageActive(page)
if not isActive then
if page == SHOP_PAGE.ROAM then
errorTip = Language[11888]
elseif page == SHOP_PAGE.EXCHANGE then
errorTip = Language[11889]
end
errorTip = errorTip or Language[10574]
return true, errorTip
end
return false
end
-- tab改变事件
function this.OnPageTabChange(index, lastIndex)
this._CurPageIndex = index
-- 清除tab绑定的红点
this.ClearTabRedpot()
-- 刷新tab数据
local page = this._MainShopPageList[index]
this._MainShopTypeList = ShopManager.GetMainPageShopTypeList(page)
this.ShopTabCtrl:Init(this.tabbox2, this._MainShopTypeList)
-- 默认打开第一个商店
if this.ShopTabCtrl then
this._CurShopIndex = nil
if this._ChooseShopIndex then
this.ShopTabCtrl:ChangeTab(this._ChooseShopIndex or 1)
else
this.ShopTabCtrl:ChangeTab(this.GetAvailableChildShopIndex() or 1)
end
end
-- 二级页签只有一个的时候不显示
this.tabbox2:SetActive(#this._MainShopTypeList > 1)
-- 初始化位置
local contentWidth = GetPreferredWidth(this.tabbox2Content.transform)--LayoutUtility.GetPreferredWidth(this.tabbox2Content.transform)
local curPos = this.tabbox2Content.transform.localPosition
this.tabbox2Content.transform.localPosition = Vector3.New(contentWidth/2, curPos.y, curPos.z)
end
-- 获取当前大页签下可用的小页签的序号
function this.GetAvailableChildShopIndex()
for index, shopType in ipairs(this._MainShopTypeList) do
local isActive, errorTip = ShopManager.IsActive(shopType)
if isActive then
return index
end
end
end
----==========================二级页签相关===========================================
-- tab按钮自定义显示设置
function this.ShopTabAdapter(tab, index, status)
local img = Util.GetGameObject(tab, "Img"):GetComponent("Image")
local name = Util.GetGameObject(tab, "Text"):GetComponent("Text")
local redpot = Util.GetGameObject(tab, "redpot")
img.sprite = this.spLoader:LoadSprite(_Tab2Sprite[status])
local shopType = this._MainShopTypeList[index]
local shopInfo = ShopManager.GetShopInfoByType(shopType)
name.text = GetLanguageStrById(shopInfo.Name)
name.color = _Tab2FontColor[status]
local islock = status == "lock"
Util.SetGray(tab, islock)
-- 判断是否需要检测红点
redpot:SetActive(false)
if not islock then
this.ClearTabRedpot(shopType)
this.BindTabRedpot(shopType, redpot)
end
end
-- tab可用性检测
function this.ShopTabIsLockCheck(index)
local shopType = this._MainShopTypeList[index]
local isActive, errorTip = ShopManager.IsActive(shopType)
if not isActive then
if shopType == SHOP_TYPE.ROAM_SHOP then
errorTip = Language[11890]
end
errorTip = errorTip or Language[10574]
return true, errorTip
end
return false
end
-- tab改变事件
function this.OnShopTabChange(index, lastIndex)
if this._CurShopIndex == index then return end
this._CurShopIndex = index
local shopType = this._MainShopTypeList[index]
if not this.shopView then
this.shopView = SubUIManager.Open(SubUIConfig.ShopView, this.content.transform)
-- 修改商品栏的位置
this.shopView:SetItemContentPosition(Vector3.New(0, 710, 0))
end
this.shopView:ShowShop(shopType,this.sortingOrder)
-- 获取配置
local shopId = ShopManager.GetShopDataByType(shopType).id
-- LogRed(shopId)
local config = _ShopTypeConfig[shopId]
-- 背景
-- for index, bg in pairs(this.bg) do
-- bg:SetActive(index == config.BgType)
-- end
this.bg[1]:GetComponent("Image").sprite = this.spLoader:LoadSprite(config.BgName)
if shopType == SHOP_TYPE.SOUL_STONE_SHOP then
this.SetVipPartInfo()
else
this.vipInfoPart:SetActive(false)
end
--SHOP_TYPE.SOUL_STONE_SHOP
-- 判断是否要动态加载秘盒商店背景立绘
--if config.BgType == 3 and not this.Bg3Live then
-- this.Bg3Live = poolManager:LoadLive("live2d_mihe", this.bg[3].transform, Vector3.one, Vector3.New(0, 196, 0))
--end
-- 货币界面
this.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = config.ResourcesBar })
end
-- 绑定数据
local _PageBindData = {}
local _TabBindData = {}
function this.BindPageRedpot(page, redpot)
local rpType = _ShopPage[page].rpType
if not rpType then return end
BindRedPointObject(rpType, redpot)
_PageBindData[rpType] = redpot
end
function this.ClearPageRedpot(page)
-- 清除红点绑定
if page then -- 清除某个
local rpType = _ShopPage[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 this.GetTabRPType(shopType)
local rpType = nil
if shopType == SHOP_TYPE.GENERAL_SHOP then
rpType = RedPointType.Shop_Tab_General
elseif shopType == SHOP_TYPE.SOUL_PRINT_SHOP then
rpType = RedPointType.Shop_Tab_Soul
elseif shopType == SHOP_TYPE.SECRET_BOX_SHOP then
rpType = RedPointType.Shop_Tab_Secret
elseif shopType == SHOP_TYPE.ARENA_SHOP then
rpType = RedPointType.Shop_Tab_Arena
elseif shopType == SHOP_TYPE.ROAM_SHOP then
rpType = RedPointType.Shop_Tab_Roam
elseif shopType == SHOP_TYPE.GUILD_SHOP then
rpType = RedPointType.Shop_Tab_Guild
elseif shopType == SHOP_TYPE.GodPrint then
rpType = RedPointType.Shop_Tab_God
end
return rpType
end
--- 绑定红点
function this.BindTabRedpot(shopType, redpot)
local rpType = this.GetTabRPType(shopType)
if not rpType then return end
BindRedPointObject(rpType, redpot)
_TabBindData[rpType] = redpot
end
--- 清除红点
function this.ClearTabRedpot(shopType)
-- 清除红点绑定
if shopType then -- 清除某个
local rpType = this.GetTabRPType(shopType)
if not rpType then return end
ClearRedPointObject(rpType, _TabBindData[rpType])
_TabBindData[rpType] = nil
else -- 全部清除
for rpt, redpot in pairs(_TabBindData) do
ClearRedPointObject(rpt, redpot)
end
_TabBindData = {}
end
end
--界面关闭时调用(用于子类重写)
function MainShopPanel:OnClose()
end
--界面销毁时调用(用于子类重写)
function MainShopPanel:OnDestroy()
this.spLoader:Destroy()
-- 销毁shopview
if this.shopView then
SubUIManager.Close(this.shopView)
this.shopView = nil
end
SubUIManager.Close(this.UpView)
-- 清除红点
this.ClearPageRedpot()
this.ClearTabRedpot()
ClearRedPointObject(RedPointType.VIP_SHOP_DETAIL, this.vipRedPoint)
--if this.Bg3Live then
-- poolManager:UnLoadLive("live2d_mihe", this.Bg3Live)
-- this.Bg3Live = nil
--end
end
-- 设置特权面板数据
function this.SetVipPartInfo()
local isMe = this._MainShopTypeList[this._CurShopIndex] == SHOP_TYPE.SOUL_STONE_SHOP
this.vipInfoPart:SetActive(isMe)
local need, nextLevelNeed = VipManager.GetNextLevelNeed()
--this.vipChargeRoot:SetActive(need > 0)
this.chargeNum.text = need
this.moneyIcon.sprite = SetIcon(this.spLoader, 15)
local nextLevel = VipManager.GetVipLevel() + 1
nextLevel = nextLevel > VipManager.GetMaxVipLevel() and VipManager.GetMaxVipLevel() or nextLevel
this.vipLevelTip.text = nextLevel
this.vipIconLevel.text = VipManager.GetVipLevel()
this.vipHeroStar.sprite = this.spLoader:LoadSprite(VIP_LEVEL_REWARD[nextLevel])
this.vipProgress.fillAmount = VipManager.GetChargedNum() / nextLevelNeed
this.progressText.text = VipManager.GetChargedNum() .. "/" .. nextLevelNeed
end
return MainShopPanel