miduo_client/Assets/ManagedResources/~Lua/Modules/HomeLand/TrainBuildLvUpPanel.lua

205 lines
7.7 KiB
Lua
Raw Normal View History

2023-11-21 17:26:43 +08:00
----- --家园建筑升级 -----
local TrainBuildLvUpPanel = Inherit(BasePanel)
local this = TrainBuildLvUpPanel
local HomeLand = ConfigManager.GetConfig(ConfigName.TrainBuild)
local HomeLandLevel = ConfigManager.GetConfig(ConfigName.TrainBuildLevel)
local costOneSec = ConfigManager.GetConfigData(ConfigName.SpecialConfig,170).Value
2024-01-16 19:39:51 +08:00
local itemConfig=ConfigManager.GetConfigData(ConfigName.ItemConfig,16)
2023-11-21 17:26:43 +08:00
--传入父脚本模块
local parent
--传入特效层级
local sortingOrder=0
local data=nil
local Obj=nil
2023-11-24 15:00:22 +08:00
local endCostNum=0
local pro=0
2023-11-21 17:26:43 +08:00
function TrainBuildLvUpPanel:InitComponent()
this.spLoader = SpriteLoader.New()
--当前两个名字
this.curName = Util.GetGameObject(this.gameObject,"Buildings/curName"):GetComponent("Text")
this.nextName = Util.GetGameObject(this.gameObject,"Buildings/nextName"):GetComponent("Text")
this.Content = Util.GetGameObject(this.gameObject,"Content")
this.Obtain = Util.GetGameObject(this.Content,"Obtain")
this.Cost = Util.GetGameObject(this.Content,"Cost")
2024-01-03 15:24:49 +08:00
this.tipInfo = Util.GetGameObject(this.gameObject,"tip"):GetComponent("Text")
2024-01-10 18:12:31 +08:00
this.tipInfo.text = "每个满级特训神将激活:所有神将礼物属性+5%最高200%"
2023-11-21 17:26:43 +08:00
--Obtain
this.limit = Util.GetGameObject(this.Obtain,"limit")
this.gain = Util.GetGameObject(this.Obtain,"gain")
this.gainIcon = Util.GetGameObject(this.Obtain,"gain/Icon"):GetComponent("Image")
this.gainNum = Util.GetGameObject(this.Obtain,"gain/Num"):GetComponent("Text")
this.gainAdd = Util.GetGameObject(this.Obtain,"gain/Add"):GetComponent("Text")
--cost
this.cost1Icon1 = Util.GetGameObject(this.Cost,"cost1/Icon"):GetComponent("Image")
this.cost1Num1 = Util.GetGameObject(this.Cost,"cost1/Num"):GetComponent("Text")
this.cost2 = Util.GetGameObject(this.Cost,"cost2")
this.cost2Name = Util.GetGameObject(this.Cost,"cost2/Text"):GetComponent("Text")
this.cost2Num = Util.GetGameObject(this.Cost,"cost2/Num"):GetComponent("Text")
--fastDone
this.fastDoneMoney = Util.GetGameObject(this.gameObject,"Btns/fastDone/Money")
this.fastDoneIcon = Util.GetGameObject(this.fastDoneMoney,"Icon"):GetComponent("Image")
this.fastDoneNum = Util.GetGameObject(this.fastDoneMoney,"Num"):GetComponent("Text")
this.fastDoneBtn = Util.GetGameObject(this.gameObject,"Btns/fastDone/BtnDo")
--Done
this.doneNum = Util.GetGameObject(this.gameObject,"Btns/Done/Money/Text"):GetComponent("Text")
this.doneBtn = Util.GetGameObject(this.gameObject,"Btns/Done/BtnDo")
end
function TrainBuildLvUpPanel:BindEvent()
Util.AddClick(this.fastDoneBtn, function()
-- local priviId = PrivilegeManager.GetPrivilegeRemainValue()
TrainBuildManager.ResumeCost(data.dataSingle,string.split(costOneSec,"#"),function (num)
2024-01-16 19:39:51 +08:00
MsgPanel.ShowTwo(string.format("是否花费%s%s立即升级",endCostNum,itemConfig.Name),function() end,function()
2023-11-21 17:26:43 +08:00
NetManager.TrainingArchitectureUpRequest(data.dataMain.Id,2,function ()
--特效
Obj.effect2:SetActive(true)
Timer.New(function ()
Obj.effect2:SetActive(false)
end,1):Start()
PopupTipPanel.ShowTip(string.format("<color=#00FF00>%s</color>已升级至<color=#00FF00>%s</color>级",data.dataMain.Name,data.dataSingle.level))
self:ClosePanel()
2023-11-24 11:46:47 +08:00
Game.GlobalEvent:DispatchEvent(GameEvent.UI.OnUpdateData)
2023-11-21 17:26:43 +08:00
end)
end,"取消","确定")
end)
end)
Util.AddClick(this.doneBtn, function()
2023-11-24 11:46:47 +08:00
if data.endTime and data.endTime>0 then
PopupTipPanel.ShowTip("升级中")
return
end
2023-11-21 17:26:43 +08:00
TrainBuildManager.ResumeCost(data.dataSingle,nil,function ()
NetManager.TrainingArchitectureUpRequest(data.dataMain.Id,1,function ()
Game.GlobalEvent:DispatchEvent(GameEvent.UI.OnUpdateData)
self:ClosePanel()
end)
end)
end)
Util.AddClick(this.gameObject,function ()
self:ClosePanel()
end)
end
function TrainBuildLvUpPanel:AddListener()
end
function TrainBuildLvUpPanel:RemoveListener()
end
function TrainBuildLvUpPanel:OnOpen(_args)
data = _args[1]
Obj = _args[2]
end
function TrainBuildLvUpPanel:OnShow()
local curData = data.dataSingle
local nextData = HomeLandLevel[curData.Id + 1]
local str = string.split(costOneSec,"#")
this.curName.text = string.format("%s %s级",data.dataMain.Name,curData.level)
this.nextName.text = string.format("%s级",nextData.level)
this.Obtain:SetActive(false)
if curData.Gain and curData.Gain>0 then
this.Obtain:SetActive(true)
--this.gainIcon.sprite = this.spLoader:LoadSprite(GetSpriteNameByItemId(curData.Gain[1]))
this.gainNum.text = curData.Gain
this.gainAdd.text = string.format(" +%s",nextData.Gain - curData.Gain)
end
this.Cost:SetActive(false)
if curData.Cost then
this.Cost:SetActive(true)
this.cost1Icon1.sprite = this.spLoader:LoadSprite(GetSpriteNameByItemId(curData.Cost[1][1]))
local color1 = BagManager.GetTotalItemNum(curData.Cost[1][1]) >= curData.Cost[1][2] and "#A47C31" or "red"
this.cost1Num1.text = string.format("<color=%s>%s</color>",color1,curData.Cost[1][2])
end
this.cost2:SetActive(false)
if curData.Rule and #curData.Rule>0 and type(curData.Rule[1])~="userdata" then
this.cost2:SetActive(true)
local color = TrainBuildManager.BuildData[curData.Rule[1]].level < curData.Rule[2] and "FF0000" or "A47C31"
this.cost2Num.text = string.format("<color=#%s>%s到达%s级</color>",color,HomeLand[curData.Rule[1]].Name,curData.Rule[2])
else
end
this.fastDoneIcon.sprite = this.spLoader:LoadSprite(GetSpriteNameByItemId(tonumber(str[1])))
2023-11-24 15:00:22 +08:00
--LogError("curData.Time===================="..curData.Time)
LogError("curdata.endTime==="..data.endTime.." curData endtime-curtime==="..data.endTime - GetTimeStamp())
local leftTime=0
if data.endTime>0 then
leftTime=data.endTime - GetTimeStamp()
else
leftTime=curData.Time
end
pro=tonumber(str[2])
endCostNum=math.ceil(leftTime/60)*pro
this.fastDoneNum.text = endCostNum
2023-11-21 17:26:43 +08:00
this.doneNum.text = string.format("耗时:%s",this:CulculateTime(curData.Time))
2023-11-24 15:00:22 +08:00
if data.endTime>0 then
this:SetTime(leftTime)
end
2023-11-21 17:26:43 +08:00
ForceRebuildLayout(this.gain.transform)
ForceRebuildLayout(this.Obtain.transform)
ForceRebuildLayout(this.Cost.transform)
ForceRebuildLayout(this.Content.transform)
end
2023-11-24 15:00:22 +08:00
function TrainBuildLvUpPanel:SetTime(_num)
if self.timer then
self.timer:Stop()
self.timer = nil
end
local aaa=_num
self.timer = Timer.New(function ()
aaa=aaa-1
--LogError("lefttime================"..leftTime2.." data.endTime=="..data.endTime)
endCostNum=math.ceil(aaa/60)*pro
this.fastDoneNum.text = endCostNum
end, 1, -1, true)
self.timer:Start()
end
2023-11-21 17:26:43 +08:00
function TrainBuildLvUpPanel:CulculateTime(time)
if time < 60 then
return time..""
elseif time >= 60 and time < 3600 then
return math.floor(time/60)..""..(time%60)..""
elseif time >= 3600 and time < 86400 then
return math.floor(time/3600)..""..math.floor((time%3600)/60)..""
elseif time >= 86400 then
return math.floor(time/86400)..""..math.floor((time%86400)/3600)..""
end
end
function TrainBuildLvUpPanel:OnClose()
data=nil
2024-01-03 15:24:49 +08:00
if self.timer then
self.timer:Stop()
self.timer = nil
end
2023-11-21 17:26:43 +08:00
end
function TrainBuildLvUpPanel:OnDestroy()
this.spLoader:Destroy()
2023-11-24 15:00:22 +08:00
if self.timer then
self.timer:Stop()
self.timer = nil
end
2023-11-21 17:26:43 +08:00
end
return TrainBuildLvUpPanel