miduo_client/Assets/ManagedResources/~Lua/Modules/NewShenZun/NewShenZunPanel.lua

184 lines
8.0 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

require("Base/BasePanel")
NewShenZunPanel = Inherit(BasePanel)
local this=NewShenZunPanel
local prestigeConfigList=ConfigManager.TryGetAllConfigsDataByKey(ConfigName.PrestigeConfig,"Type",1)
local GameSetting = ConfigManager.GetConfig(ConfigName.GameSetting)
local curLv
local curSelectLv
local isEnough --道具是否足够
local isBuy --是否已购买
local storeConfig --商店数据
function this:InitComponent()
this.spLoader = SpriteLoader.New()
this.backBtn=Util.GetGameObject(self.gameObject, "backBtn")
this.lv=Util.GetGameObject(self.gameObject, "topLayout/lv/Text"):GetComponent("Text")
this.progressBar=Util.GetGameObject(self.gameObject, "topLayout/progress/progressBar"):GetComponent("Image")
this.progressValue=Util.GetGameObject(self.gameObject, "topLayout/progress/value"):GetComponent("Text")
this.exchangeBtn=Util.GetGameObject(self.gameObject, "topLayout/exchangeBtn")
this.exchangeRedPoint=Util.GetGameObject(self.gameObject, "topLayout/exchangeBtn/redPoint")
this.tabGrid=Util.GetGameObject(self.gameObject, "layout/tabScroll/grid")
this.tabBtnPre=Util.GetGameObject(self.gameObject, "layout/tabBtnPre")
this.selectBtn=Util.GetGameObject(self.gameObject, "layout/tabSelectBtn")
this.selectBtnText=Util.GetGameObject(self.gameObject, "layout/tabSelectBtn/Text"):GetComponent("Text")
this.privilegeAddText=Util.GetGameObject(self.gameObject, "layout/privilegeAddScroll/Text"):GetComponent("Text")
this.goods=Util.GetGameObject(self.gameObject, "layout/goods")
this.costIcon=Util.GetGameObject(self.gameObject, "layout/cost/icon"):GetComponent("Image")
this.costNum=Util.GetGameObject(self.gameObject, "layout/cost/num"):GetComponent("Text")
this.buyBtn=Util.GetGameObject(self.gameObject, "layout/buyBtn")
this.buyBtnText=Util.GetGameObject(this.buyBtn, "Text"):GetComponent("Text")
for i = 2, #prestigeConfigList do
local tabBtn = newObjToParent(this.tabBtnPre, this.tabGrid)
Util.GetGameObject(tabBtn, "Text"):GetComponent("Text").text=string.format("神尊%s",prestigeConfigList[i].Level)
Util.AddClick(tabBtn,function ()
this.TabBtnOnClick(prestigeConfigList[i].Level)
end)
end
this.List1 = {}
-- 显示货币
this.UpView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform)
end
function this:BindEvent()
Util.AddClick(this.backBtn,function ()
self:ClosePanel()
end)
Util.AddClick(this.exchangeBtn,function ()
UIManager.OpenPanel(UIName.NewShenZunExpExchangePopup)
end)
Util.AddClick(this.buyBtn,function ()
if isBuy then
return
end
if curLv<curSelectLv then
PopupTipPanel.ShowTip(string.format("神尊特权等级达到%s级才可购买",curSelectLv))
return
end
if not isEnough then
PopupTipPanel.ShowTip("道具不足!")
return
end
ShopManager.RequestBuyItemByShopId(storeConfig.StoreId, storeConfig.Id, 1, function()
this.buyBtnText.text="已购买"
isBuy=true
this.buyBtn:GetComponent("Image").sprite=this.spLoader:LoadSprite("btn_buy_gray")
end)
end)
end
function this:OnOpen(data)
this.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.ShenZun})
this.UpdateTopInfo()
this.TabBtnOnClick(curLv)
end
--添加事件监听(用于子类重写)
function this:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.Activity.UpdateShenzunLv, this.UpdateTopInfo)
end
--移除事件监听(用于子类重写)
function this:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.Activity.UpdateShenzunLv, this.UpdateTopInfo)
end
function this.UpdateTopInfo()
--刷新兑换红点
local costPropNum=BagManager.GetItemCountById(15)
this.exchangeRedPoint:SetActive(costPropNum>=10)
curLv=GetShenzunLv()
local expNum=BagManager.GetItemCountById(1352)
local prestigeConfig=ConfigManager.GetConfigDataByDoubleKey(ConfigName.PrestigeConfig,"Type",1,"Level",curLv)
this.lv.text=curLv
if prestigeConfig.Experience and prestigeConfig.Experience[2] then
this.progressBar.fillAmount=expNum/prestigeConfig.Experience[2]
this.progressValue.text=string.format("%s/%s",expNum,prestigeConfig.Experience[2])
else
this.progressBar.fillAmount=1
this.progressValue.text=expNum
this.exchangeBtn.gameObject:SetActive(false)
end
end
function this.TabBtnOnClick(_privilegeLv)
local _level=_privilegeLv>0 and _privilegeLv or 1
local clickBtn=this.tabGrid.transform:GetChild(_level-1)
this.selectBtn.transform:SetParent(clickBtn)
this.selectBtn.transform.localScale = Vector3.one
this.selectBtn.transform.localPosition = Vector3.zero
this.selectBtnText.text=string.format("神尊%s",_level)
this.UpdateLayout(_level)
end
function this.UpdateLayout(_privilegeLv)
curSelectLv=_privilegeLv
local curAddData= PrivilegeManager.GetShenZunAddByLv(_privilegeLv)
local privilegeAddText =""
for _, privilegeInfo in ipairs(curAddData) do
if privilegeInfo.value == ""
or (privilegeInfo.IfFloat == 1 and privilegeInfo.value > 0)
or (privilegeInfo.IfFloat == 2 and privilegeInfo.value ~= 0 and privilegeInfo.value ~= 1)
then
local colorStr = "<color=#f46363><size=35>%s</size></color>"
local formatStr
if privilegeInfo.IfFloat == 2 and privilegeInfo.value > 1 then --特权关卡挂机加成百分比
formatStr = string.format(colorStr, (privilegeInfo.value*100-100).."%")
elseif privilegeInfo.IfFloat == 2 and privilegeInfo.value <= 0 then
formatStr = string.format(colorStr, ((privilegeInfo.value+1)*10).."")
else
formatStr = string.format(colorStr, privilegeInfo.value)
end
if privilegeInfo.id == PRIVILEGE_TYPE.HANG_ON_TIME then
-- 挂机时长特权特殊显示处理
privilegeAddText = privilegeAddText.."\n·"..string.format(privilegeInfo.content, string.format(colorStr, privilegeInfo.value + GameSetting[1].AdventureOffline), formatStr)
else
privilegeAddText = privilegeAddText.."\n·"..string.format(privilegeInfo.content, formatStr)
end
end
end
this.privilegeAddText.text=privilegeAddText
local prestigeConfig=ConfigManager.GetConfigDataByDoubleKey(ConfigName.PrestigeConfig,"Type",1,"Level",_privilegeLv)
storeConfig=ConfigManager.GetConfigData(ConfigName.StoreConfig,prestigeConfig.Store)
for i = 1, #storeConfig.Goods do
if not this.List1[i] then
this.List1[i] =
SubUIManager.Open(SubUIConfig.ItemView, this.goods.transform)
end
this.List1[i]:OnOpen(false, {storeConfig.Goods[i][1], storeConfig.Goods[i][2]}, 0.8, false)
this.List1[i].gameObject:SetActive(true)
end
local costId, discostnum, costnum = ShopManager.calculateBuyCost(storeConfig.StoreId, storeConfig.Id, 1)
this.costNum.text=discostnum
local itemDataConFig = ConfigManager.GetConfigData(ConfigName.ItemConfig, storeConfig.Cost[1][1])
this.costIcon.sprite = this.spLoader:LoadSprite(GetResourcePath(itemDataConFig.ResourceID))
local alrBuyTime= ShopManager.GetShopItemHadBuyTimes(storeConfig.StoreId, storeConfig.Id)
local limitTime=ShopManager.GetShopItemLimitBuyCount( storeConfig.Id)
if alrBuyTime>=limitTime then
this.buyBtnText.text="已购买"
isBuy=true
else
this.buyBtnText.text="购买"
isBuy=false
end
if not isBuy and curLv>=_privilegeLv then
this.buyBtn:GetComponent("Image").sprite=this.spLoader:LoadSprite("sz_btn_buy")
else
this.buyBtn:GetComponent("Image").sprite=this.spLoader:LoadSprite("btn_buy_gray")
end
isEnough=BagManager.GetItemCountById(storeConfig.Cost[1][1])>=discostnum
end
--界面关闭时调用(用于子类重写)
function this:OnClose()
end
function this:OnDestroy()
this.spLoader:Destroy()
end
return this