311 lines
12 KiB
Lua
311 lines
12 KiB
Lua
----- 心愿抽卡弹窗 -----
|
|
local TrainSelectHeroPanel = quick_class("TrainSelectHeroPanel", BasePanel)
|
|
|
|
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
|
local heroConfig = ConfigManager.GetConfig(ConfigName.HeroConfig)
|
|
local specialConfig = ConfigManager.GetConfig(ConfigName.SpecialConfig)
|
|
local this = TrainSelectHeroPanel
|
|
local buildData = nil
|
|
local curHeroId = nil
|
|
local leftTime = -1
|
|
local curSelectObj = nil
|
|
function this:InitComponent()
|
|
self.spLoader = SpriteLoader.New()
|
|
self.btn_close = Util.GetGameObject(self.gameObject, "bg/btn_close")
|
|
self.btn_star = Util.GetGameObject(self.gameObject, "bg/btn_star")
|
|
self.btn_end = Util.GetGameObject(self.gameObject, "bg/btn_end")
|
|
self.btn_speed = Util.GetGameObject(self.gameObject, "bg/speedUp")
|
|
self.helpBtn = Util.GetGameObject(self.gameObject, "helpBtn")
|
|
self.scroll = Util.GetGameObject(self.gameObject, "selectList")
|
|
self.itemPre = Util.GetGameObject(self.gameObject, "itemPre")
|
|
self.title = Util.GetGameObject(self.gameObject, "bg/title"):GetComponent("Text")
|
|
self.infoTxt = Util.GetGameObject(self.gameObject, "bg/info"):GetComponent("Text")
|
|
self.costImg = Util.GetGameObject(self.gameObject, "bg/costImg"):GetComponent("Image")
|
|
self.costNum = Util.GetGameObject(self.gameObject, "bg/costNum"):GetComponent("Text")
|
|
-- 设置循环滚动,万一内容不停地加
|
|
local rootHight = self.scroll.transform.rect.height
|
|
local width = self.scroll.transform.rect.width
|
|
|
|
self.scrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.scroll.transform,
|
|
self.itemPre, nil, Vector2.New(width, rootHight), 1, 5, Vector2.New(20, 75))
|
|
self.scrollView.moveTween.MomentumAmount = 1
|
|
self.scrollView.moveTween.Strength = 2
|
|
|
|
self.itemList = {}
|
|
self.maskList = {}
|
|
--wishList
|
|
|
|
self.selctHero = Util.GetGameObject(self.gameObject, "bg/bglist/hero")
|
|
--tabList
|
|
self.tabListObj = {}
|
|
self.selectBtn = Util.GetGameObject(self.gameObject, "Tabs/grid/selectBtn")
|
|
for j = 1, 4 do
|
|
self.maskList[j] = {}
|
|
self.itemList[j] = {}
|
|
self.tabListObj[j] = Util.GetGameObject(self.gameObject, "Tabs/grid/Btn" .. j)
|
|
end
|
|
|
|
self.noneObj = Util.GetGameObject(self.gameObject, "NoneImage")
|
|
|
|
Util.GetGameObject(self.gameObject, "NoneImage/TextImage/Text"):GetComponent("Text").text = Language[11607]
|
|
self.helpPosition = self.helpBtn:GetComponent("RectTransform").localPosition
|
|
end
|
|
|
|
function this:BindEvent()
|
|
for i = 1, 4 do
|
|
Util.AddOnceClick(self.tabListObj[i], function()
|
|
self.curSelect = i
|
|
this:Refresh(true, false)
|
|
end)
|
|
end
|
|
|
|
|
|
Util.AddOnceClick(self.btn_close, function()
|
|
--LogError("点击确定按钮")
|
|
self:ClosePanel()
|
|
end)
|
|
|
|
Util.AddOnceClick(self.btn_speed, function()
|
|
if buildData.heroId == nil or buildData.heroId == "" then
|
|
PopupTipPanel.ShowTip(Language[11608])
|
|
return
|
|
end
|
|
UIManager.OpenPanel(UIName.TrainHeroAddSpeedPanel, buildData, this)
|
|
end)
|
|
|
|
|
|
Util.AddOnceClick(self.btn_star, function()
|
|
if buildData.heroId and buildData.heroId ~= "" then
|
|
PopupTipPanel.ShowTip(Language[11609])
|
|
return
|
|
end
|
|
if curHeroId == nil or curHeroId == "" then
|
|
PopupTipPanel.ShowTip(Language[11610])
|
|
return
|
|
end
|
|
NetManager.TrainingRequest(buildData.dataMain.Id, curHeroId, 1, function()
|
|
self:Refresh()
|
|
Game.GlobalEvent:DispatchEvent(GameEvent.UI.OnUpdateData)
|
|
end)
|
|
end)
|
|
Util.AddOnceClick(self.btn_end, function()
|
|
if buildData.heroId and buildData.heroId ~= "" then
|
|
NetManager.TrainingRequest(buildData.dataMain.Id, buildData.heroId, 2, function()
|
|
curHeroId = nil
|
|
self:Refresh()
|
|
Game.GlobalEvent:DispatchEvent(GameEvent.UI.OnUpdateData)
|
|
end)
|
|
end
|
|
end)
|
|
|
|
--帮助按钮
|
|
Util.AddClick(self.helpBtn, function()
|
|
LogError("点击帮助按钮")
|
|
UIManager.OpenPanel(UIName.HelpPopup, HELP_TYPE.Train, self.helpPosition.x, self.helpPosition.y)
|
|
end)
|
|
end
|
|
|
|
function this:AddListener()
|
|
end
|
|
|
|
function this:RemoveListener()
|
|
end
|
|
|
|
function this:OnOpen(_data, _leftTime)
|
|
buildData = _data
|
|
self.title.text = GetLanguageStrById(buildData.dataMain.Name)
|
|
self.infoTxt.text = GetLanguageStrById(buildData.dataMain.Name) ..
|
|
Language[11599] .. buildData.dataSingle.Gain .. Language[11600]
|
|
leftTime = _leftTime
|
|
curHeroId = buildData.heroId
|
|
--LogError("buildData.dataMain.Id==="..buildData.dataMain.Id)
|
|
end
|
|
|
|
function this:OnShow()
|
|
this:Refresh(true, false)
|
|
end
|
|
|
|
function this:Refresh(isTop, isAni)
|
|
--self.selectBtn:GetComponent("RectTransform").localPosition = self.tabListObj[self.curSelect]:GetComponent("RectTransform").localPosition
|
|
this:SetHeroList(isTop, isAni)
|
|
this:SetUpHero()
|
|
end
|
|
|
|
function this:SetUpHero()
|
|
local go = self.selctHero
|
|
local frame = Util.GetGameObject(go, "frame"):GetComponent("Image")
|
|
local icon = Util.GetGameObject(go, "icon"):GetComponent("Image")
|
|
local proIcon = Util.GetGameObject(go, "proIcon"):GetComponent("Image")
|
|
local starGrid = Util.GetGameObject(go, "star")
|
|
local choosed = Util.GetGameObject(go, "choosed")
|
|
local lv = Util.GetGameObject(go, "lvBg/lv"):GetComponent("Text")
|
|
local name = Util.GetGameObject(go, "name"):GetComponent("Text")
|
|
local trainLv = Util.GetGameObject(go, "trainLvBg/Text"):GetComponent("Text")
|
|
local trainObj = Util.GetGameObject(go, "trainLvBg")
|
|
local heroId = curHeroId
|
|
choosed:SetActive(false)
|
|
if heroId and heroId ~= "" then
|
|
local heroData = HeroManager.GetSingleHeroData(heroId)
|
|
if heroData then
|
|
go:SetActive(true)
|
|
frame.sprite = self.spLoader:LoadSprite(GetBgByHeroNatural(heroData.heroConfig.Natural))
|
|
icon.sprite = self.spLoader:LoadSprite(GetResourcePath(heroData.heroConfig.Icon))
|
|
proIcon.sprite = self.spLoader:LoadSprite(GetProStrImageByProNum(heroData.heroConfig.PropertyName))
|
|
trainObj:SetActive(heroData.HeroTraining.trainingLv > 0)
|
|
trainLv.text = Language[11601] .. heroData.HeroTraining.trainingLv
|
|
name.text = heroData.heroConfig.Name
|
|
lv.text = heroData.lv
|
|
SetHeroStars(self.spLoader, starGrid, heroData.star)
|
|
Util.SetParticleSortLayer(starGrid, this.sortingOrder + 1)
|
|
Util.AddOnceClick(go, function()
|
|
end)
|
|
local pos = buildData.dataSingle.Position
|
|
local max = 0
|
|
local curValue = 0
|
|
local train = ConfigManager.TryGetConfigDataByDoubleKey(ConfigName.Train, "HeroID", heroData.heroConfig.Id,
|
|
"Level", heroData.HeroTraining.trainingLv)
|
|
if train then
|
|
local aaa = ConfigManager.TryGetConfigDataByDoubleKey(ConfigName.TrainSetting, "PoolID",
|
|
train.TrainSettingID, "Level", heroData.HeroTraining.trainingLv)
|
|
if pos == 1 then
|
|
max = aaa.TrainExp1
|
|
curValue = heroData.HeroTraining.attackExp
|
|
elseif pos == 2 then
|
|
max = aaa.TrainExp2
|
|
curValue = heroData.HeroTraining.defenseExp
|
|
elseif pos == 3 then
|
|
max = aaa.TrainExp3
|
|
curValue = heroData.HeroTraining.hpExp
|
|
end
|
|
end
|
|
LogError("curvalue===========================" ..
|
|
curValue .. " max==" .. max .. " buildData.dataSingle.Gain==" .. buildData.dataSingle.Gain)
|
|
local endTime = buildData.heroStarTime + math.ceil((max - curValue) / buildData.dataSingle.Gain) * 60
|
|
leftTime = endTime - GetTimeStamp()
|
|
this:SetTime(name)
|
|
end
|
|
else
|
|
go:SetActive(false)
|
|
end
|
|
|
|
|
|
-- Util.AddLongPressClick(go,function ()
|
|
-- UIManager.OpenPanel(UIName.RoleGetInfoPopup, false, heroId, 5)
|
|
-- end,0.5)
|
|
end
|
|
|
|
function this:SetHeroList(isTop, isAni)
|
|
local heroList = TrainBuildManager.GetAllCanTrainHero()
|
|
local list = {}
|
|
curSelectObj = nil
|
|
--LogError("buildData.heroId======="..buildData.heroId)
|
|
local upList = TrainBuildManager.GetTrainHeroIds()
|
|
for k, v in pairs(heroList) do
|
|
if CheckListIsContainValue1(upList, v.dynamicId) == false or v.dynamicId == buildData.heroId then
|
|
table.insert(list, v)
|
|
end
|
|
end
|
|
self.noneObj:SetActive(#list == 0)
|
|
self.scrollView:SetData(list, function(index, item)
|
|
this:ShowSingleHero(item, list[index], index)
|
|
end, not isTop, not isAni)
|
|
end
|
|
|
|
function this:SetTime(_text)
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
if buildData.heroId and buildData.heroId ~= "" then
|
|
_text.gameObject:SetActive(true)
|
|
self.timer = Timer.New(function()
|
|
if leftTime >= 0 then
|
|
_text.text = TimeToFelaxible(leftTime)
|
|
leftTime = leftTime - 1
|
|
_text.gameObject:SetActive(true)
|
|
if leftTime < 0 then
|
|
--curObj.effect2:SetActive(true)
|
|
_text.text = Language[10364]
|
|
end
|
|
else
|
|
if buildData.heroId and buildData.heroId ~= "" then
|
|
_text.gameObject:SetActive(true)
|
|
_text.text = Language[10364]
|
|
end
|
|
end
|
|
end, 1, -1, true)
|
|
self.timer:Start()
|
|
else
|
|
_text.gameObject:SetActive(false)
|
|
end
|
|
end
|
|
|
|
function this:ShowSingleHero(go, data, index)
|
|
local heroData = data.heroConfig
|
|
Util.GetGameObject(go, "frame"):GetComponent("Image").sprite = self.spLoader:LoadSprite(GetBgByHeroNatural(heroData
|
|
.Natural))
|
|
Util.GetGameObject(go, "icon"):GetComponent("Image").sprite = self.spLoader:LoadSprite(GetResourcePath(heroData.Icon))
|
|
Util.GetGameObject(go, "proIcon"):GetComponent("Image").sprite = self.spLoader:LoadSprite(GetProStrImageByProNum(
|
|
heroData.PropertyName))
|
|
Util.GetGameObject(go, "name"):GetComponent("Text").text = GetLanguageStrById(heroData.ReadingName)
|
|
Util.GetGameObject(go, "choosed/Text"):GetComponent("Text").text = Language[11611]
|
|
Util.GetGameObject(go, "lvBg/lv"):GetComponent("Text").text = data.lv
|
|
local trainLv = Util.GetGameObject(go, "trainLvBg/Text"):GetComponent("Text")
|
|
local trainObj = Util.GetGameObject(go, "trainLvBg")
|
|
local choosed = Util.GetGameObject(go, "choosed")
|
|
choosed:SetActive(curHeroId == data.dynamicId)
|
|
if curHeroId == data.dynamicId then
|
|
curSelectObj = choosed
|
|
end
|
|
local trainInfo = Util.GetGameObject(go, "trainLvBg")
|
|
local trainLv = Util.GetGameObject(go, "trainLvBg/Text"):GetComponent("Text")
|
|
trainObj:SetActive(data.HeroTraining.trainingLv > 0)
|
|
trainLv.text = Language[11601] .. data.HeroTraining.trainingLv
|
|
local starGrid = Util.GetGameObject(go, "star")
|
|
SetHeroStars(self.spLoader, starGrid, data.star)
|
|
Util.SetParticleSortLayer(starGrid, this.sortingOrder + 1)
|
|
Util.AddOnceClick(go, function()
|
|
if buildData.heroId and buildData.heroId ~= "" then
|
|
if data.dynamicId ~= buildData.heroId then
|
|
PopupTipPanel.ShowTip(Language[11612])
|
|
return
|
|
end
|
|
if data.dynamicId == buildData.heroId then
|
|
PopupTipPanel.ShowTip(Language[11613])
|
|
return
|
|
end
|
|
end
|
|
|
|
if curHeroId ~= data.dynamicId then
|
|
if curSelectObj then
|
|
curSelectObj:SetActive(false)
|
|
end
|
|
curHeroId = data.dynamicId
|
|
curSelectObj = choosed
|
|
else
|
|
curHeroId = nil
|
|
curSelectObj = nil
|
|
end
|
|
choosed:SetActive(curHeroId == data.dynamicId)
|
|
this:SetUpHero()
|
|
end)
|
|
end
|
|
|
|
function this:OnClose()
|
|
|
|
end
|
|
|
|
function this:OnDestroy()
|
|
self.itemList = {}
|
|
self.maskList = {}
|
|
self.wishListObj = {}
|
|
self.tabListObj = {}
|
|
self.spLoader:Destroy()
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
end
|
|
|
|
return this
|