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

184 lines
8.0 KiB
Lua
Raw Normal View History

2022-09-09 18:09:45 +08:00
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")
2022-11-10 13:52:48 +08:00
this.exchangeRedPoint=Util.GetGameObject(self.gameObject, "topLayout/exchangeBtn/redPoint")
2022-09-09 18:09:45 +08:00
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)
2022-11-19 00:53:32 +08:00
Util.GetGameObject(tabBtn, "Text"):GetComponent("Text").text=string.format("神尊%s",prestigeConfigList[i].Level)
2022-09-09 18:09:45 +08:00
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()
2022-11-10 13:52:48 +08:00
--刷新兑换红点
local costPropNum=BagManager.GetItemCountById(15)
this.exchangeRedPoint:SetActive(costPropNum>=10)
2022-09-09 18:09:45 +08:00
curLv=GetShenzunLv()
local expNum=BagManager.GetItemCountById(1352)
local prestigeConfig=ConfigManager.GetConfigDataByDoubleKey(ConfigName.PrestigeConfig,"Type",1,"Level",curLv)
this.lv.text=curLv
2022-09-19 14:16:49 +08:00
if prestigeConfig.Experience and prestigeConfig.Experience[2] then
2022-09-09 18:09:45 +08:00
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
2022-11-02 15:40:38 +08:00
this.exchangeBtn.gameObject:SetActive(false)
2022-09-09 18:09:45 +08:00
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
2022-11-19 00:53:32 +08:00
this.selectBtnText.text=string.format("神尊%s",_level)
2022-09-09 18:09:45 +08:00
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)
2022-11-09 13:27:24 +08:00
or (privilegeInfo.IfFloat == 2 and privilegeInfo.value ~= 0 and privilegeInfo.value ~= 1)
2022-09-09 18:09:45 +08:00
then
local colorStr = "<color=#f46363><size=35>%s</size></color>"
local formatStr
2022-09-15 18:12:29 +08:00
if privilegeInfo.IfFloat == 2 and privilegeInfo.value > 1 then --特权关卡挂机加成百分比
2022-09-09 18:09:45 +08:00
formatStr = string.format(colorStr, (privilegeInfo.value*100-100).."%")
2022-09-15 18:12:29 +08:00
elseif privilegeInfo.IfFloat == 2 and privilegeInfo.value <= 0 then
formatStr = string.format(colorStr, ((privilegeInfo.value+1)*10).."")
2022-09-09 18:09:45 +08:00
else
formatStr = string.format(colorStr, privilegeInfo.value)
end
2022-09-15 18:12:29 +08:00
2022-09-09 18:09:45 +08:00
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