268 lines
10 KiB
Lua
268 lines
10 KiB
Lua
----- 心愿抽卡弹窗 -----
|
|
local TrainHeroAddSpeedPanel = quick_class("TrainHeroAddSpeedPanel", BasePanel)
|
|
|
|
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
|
local heroConfig = ConfigManager.GetConfig(ConfigName.HeroConfig)
|
|
local specialConfig = ConfigManager.GetConfig(ConfigName.SpecialConfig)
|
|
local this = TrainHeroAddSpeedPanel
|
|
local buildData = nil
|
|
local curHeroId = nil
|
|
local leftTime = -1
|
|
local curSelectObj = nil
|
|
local isSpeed = false
|
|
local openPanel = 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.helpBtn = Util.GetGameObject(self.gameObject, "helpBtn")
|
|
self.helpBtn:SetActive(false)
|
|
self.scroll = Util.GetGameObject(self.gameObject, "selectList")
|
|
self.itemPre = Util.GetGameObject(self.gameObject, "bg/itemInfo")
|
|
self.title = Util.GetGameObject(self.gameObject, "bg/title"):GetComponent("Text")
|
|
self.infoTxt = Util.GetGameObject(self.gameObject, "bg/info"):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, 1, Vector2.New(10, 10))
|
|
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")
|
|
|
|
|
|
self.helpPosition = self.helpBtn:GetComponent("RectTransform").localPosition
|
|
isSpeed = false
|
|
end
|
|
|
|
function this:BindEvent()
|
|
Util.AddOnceClick(self.btn_close, function()
|
|
--LogError("点击确定按钮")
|
|
self:ClosePanel()
|
|
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, _openPanel)
|
|
openPanel = _openPanel
|
|
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 list = {}
|
|
LogError("buildData.dataMain.id==============================" .. buildData.dataSingle.Id)
|
|
list = buildData.dataSingle.SpeedUp
|
|
LogError("list len==================" .. #list)
|
|
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 itemId = data[1]
|
|
local time = data[2]
|
|
local itemData = itemConfig[itemId]
|
|
Util.GetGameObject(go, "bg/frame"):GetComponent("Image").sprite = self.spLoader:LoadSprite(GetBgByHeroNatural(
|
|
itemData.Quantity))
|
|
Util.GetGameObject(go, "bg/icon"):GetComponent("Image").sprite = self.spLoader:LoadSprite(GetResourcePath(itemData
|
|
.ResourceID))
|
|
Util.GetGameObject(go, "bg/name"):GetComponent("Text").text = GetLanguageStrById(itemData.Name)
|
|
Util.GetGameObject(go, "bg/condition"):GetComponent("Text").text = GetLanguageStrById(itemData.ItemDescribe)
|
|
local numTxt = Util.GetGameObject(go, "bg/numTxt"):GetComponent("Text")
|
|
local btn_up = Util.GetGameObject(go, "bg/btnGet")
|
|
Util.GetGameObject(go, "bg/btnGet/get"):GetComponent("Text").text = Language[11602]
|
|
local num = BagManager.GetItemCountById(itemId)
|
|
local aaa = 0
|
|
if num <= 0 then
|
|
Util.SetGray(btn_up, true)
|
|
--num=string.format("<color=#FCF5D3FF>%s</color>",num)
|
|
aaa = string.format("<color=#FF0011>%s</color>", num)
|
|
else
|
|
Util.SetGray(btn_up, false)
|
|
aaa = num
|
|
--num=string.format("<color=#FF0011>%s</color>",num)
|
|
end
|
|
numTxt.text = Language[11603] .. aaa
|
|
Util.AddOnceClick(btn_up, function()
|
|
if num <= 0 then
|
|
PopupTipPanel.ShowTip(Language[10054])
|
|
UIManager.OpenPanel(UIName.RewardItemSingleShowPopup, itemId)
|
|
return
|
|
end
|
|
if leftTime < 0 then
|
|
PopupTipPanel.ShowTip(Language[11604])
|
|
return
|
|
end
|
|
if buildData.heroId == nil or buildData.heroId == "" then
|
|
PopupTipPanel.ShowTip(Language[11605])
|
|
return
|
|
end
|
|
NetManager.TrainingPropSpeedRequest(buildData.dataMain.Id, itemId, 1, buildData.heroId, function()
|
|
PopupTipPanel.ShowTip(Language[11606])
|
|
this:Refresh(true, false)
|
|
isSpeed = true
|
|
end)
|
|
end)
|
|
end
|
|
|
|
function this:OnClose()
|
|
if isSpeed then
|
|
openPanel:Refresh()
|
|
local panel = UIManager.GetOpenPanel(UIName.TrainBuildPanel)
|
|
if panel then
|
|
panel:OnShow()
|
|
end
|
|
end
|
|
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
|
|
isSpeed = false
|
|
end
|
|
|
|
return this
|