miduo_client/Assets/ManagedResources/~Lua/Modules/Practice/PracticeImprintPanel.lua

349 lines
14 KiB
Lua

local PracticeImprint = quick_class("PracticeImprint", BasePanel)
local orginLayer
local curImprintData={}
local trigger = true
local curNum = 0
local curhero = ""
function PracticeImprint:InitComponent()
self.spLoader = SpriteLoader.New()
self.UpView = SubUIManager.Open(SubUIConfig.UpView, self.transform)
self.backBtn = Util.GetGameObject(self.gameObject, "backBtn")
self.BG = Util.GetGameObject(self.gameObject, "Bg")
self.Scroll = Util.GetGameObject(self.gameObject, "Scroll")
self.Scroll:GetComponent("RectTransform").sizeDelta = Vector2.New(UIManager.UIWidth,UIManager.UIHeight - 100)
self.Scroll:GetComponent("RectTransform").localPosition = Vector2.New(UIManager.UIWidth/2,UIManager.UIHeight/2 -100)
self.Scrollgrid = Util.GetGameObject(self.gameObject, "Scroll/grid")
self.ImprintPre = Util.GetGameObject(self.gameObject, "ImprintPre")
self.ImprintInfo = Util.GetGameObject(self.gameObject, "ImprintInfo")
self.ImprintContent = Util.GetGameObject(self.gameObject, "ImprintInfo/Content")
self.ImprintInfoBack = Util.GetGameObject(self.ImprintInfo, "Content/close")
self.Name = Util.GetGameObject(self.ImprintInfo, "Content/Name"):GetComponent("Text")
self.leftInfo = Util.GetGameObject(self.ImprintInfo, "Content/Layout/Left")
self.leftTitle = Util.GetGameObject(self.leftInfo, "Title/Text"):GetComponent("Text")
self.leftDetail = Util.GetGameObject(self.leftInfo, "TextArena/Text"):GetComponent("Text")
self.rightInfo = Util.GetGameObject(self.ImprintInfo, "Content/Layout/Right")
self.Add = Util.GetGameObject(self.rightInfo, "AddBtn")
self.Hero = Util.GetGameObject(self.rightInfo, "Hero")
self.itemPre = Util.GetGameObject(self.Hero, "itemPre")
self.MaskBtn = Util.GetGameObject(self.rightInfo, "mask")
self.doBtn = Util.GetGameObject(self.ImprintInfo, "Content/Btn")
self.doBtnText = Util.GetGameObject(self.doBtn, "Text"):GetComponent("Text")
self.sizeDelta = {
[1] = Vector2.New(UIManager.UIWidth,UIManager.UIHeight-100),
[2] = Vector2.New(UIManager.UIWidth,UIManager.UIHeight-710),
}
self.ImprintList = {}
self.SelectList = {}
end
function PracticeImprint:BindEvent()
Util.AddClick(self.backBtn, function()
self:ClosePanel()
end)
Util.AddClick(self.ImprintInfoBack, function()
for key, value in pairs(self.SelectList) do
value:SetActive(false)
end
self:Animation(3)
end)
end
function PracticeImprint:AddListener()
end
function PracticeImprint:RemoveListener()
end
--待功能扩展(试图打开某个状态)
function PracticeImprint:OnOpen()
self.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.XiuXing })
end
function PracticeImprint:OnSortingOrderChange()
end
function PracticeImprint:OnShow()
self:Refresh(true,false)
end
function PracticeImprint:Refresh(isTop,isAni,func)
self.allImprintData = PracticeManager.GetAllImprintData()
self:Animation(3)
if not self.ImprintList then
self.ImprintList = {}
end
for k,v in ipairs(self.ImprintList) do
v.gameObject:SetActive(false)
end
for i = 1, #self.allImprintData do
local data = self.allImprintData[i]
if not self.ImprintList[i] then
self.ImprintList[i] = newObject(self.ImprintPre)
self.ImprintList[i].transform.name = "ImprintPre"..i
self.ImprintList[i].transform:SetParent(self.Scrollgrid.transform)
self.ImprintList[i].transform.localScale = Vector3.one*0.9
self.ImprintList[i].transform.localPosition = Vector3.zero
end
self.ImprintList[i]:SetActive(true)
self:SetPre(i,self.ImprintList[i],self.allImprintData[i])
end
if func then
func()
end
end
--设置每一期的三个神印
function PracticeImprint:SetPre(index,_go,_data)
local title = Util.GetGameObject(_go, "title/Image"):GetComponent("Image")
title.sprite = self.spLoader:LoadSprite(_data.NamePic1)
for i = 1, 3 do
local Imprint = Util.GetGameObject(_go, "Content/Imprint"..i)
self:SetSingleImprint(Imprint,_data.TeamSkill[i])
end
end
--设置单个神印信息
function PracticeImprint:SetSingleImprint(_go,_imprintId)
local serverData,configData = PracticeManager.GetSingleImprintData(_imprintId)--获取神印信息
local maskBtn = Util.GetGameObject(_go, "mask")
local heroImg = Util.GetGameObject(_go, "hero"):GetComponent("Image")
local icon = Util.GetGameObject(_go, "icon"):GetComponent("Image")
local kuang = Util.GetGameObject(_go, "icon")
local maskBlack = Util.GetGameObject(_go, "maskblack")
local name = Util.GetGameObject(_go, "name/Text"):GetComponent("Text")
local selectImg = Util.GetGameObject(_go, "select")
local redPoint = Util.GetGameObject(_go, "redPoint")
selectImg:SetActive(false)
redPoint:SetActive(false)
self.SelectList[_imprintId] = selectImg
heroImg.gameObject:SetActive(configData.Type == 1)
heroImg.sprite = self.spLoader:LoadSprite("r_zjm_chongzhijiahao")
if not serverData then--未解锁
_go:GetComponent("Image").enabled = false
maskBlack:SetActive(true)
Util.SetGray(icon.gameObject,true)
Util.SetGray(kuang,true)
else--已解锁
maskBlack:SetActive(false)
if PlayerPrefs.GetInt(PlayerManager.uid.."Imprint"..configData.Id) == 0 then
redPoint:SetActive(true)
end
if serverData.state == 0 then--未使用
_go:GetComponent("Image").enabled = false
elseif serverData.state == 1 then--已使用
_go:GetComponent("Image").enabled = true
end
if serverData.subId ~= nil and serverData.subId ~= "" and serverData.subId ~= "nil" then
heroImg.sprite = self.spLoader:LoadSprite(GetSpriteNameByItemId(HeroManager.GetSingleHeroData(tostring(serverData.subId)).id))
curhero = tostring(serverData.subId)
else
curhero = ""
end
Util.SetGray(icon.gameObject,serverData.state == 0)
Util.SetGray(kuang,serverData.state == 0)
end
icon.sprite = self.spLoader:LoadSprite(GetResourcePath(configData.Icon))
name.text = configData.Name
Util.AddOnceClick(maskBtn,function ()
--未解锁的不可查看
if configData.UnlockView then
if configData.UnlockView == 0 then
PopupTipPanel.ShowTip(string.format("暂未开放..."))
return
end
else
if not serverData then
PopupTipPanel.ShowTip(string.format("%s解锁",configData.Unlock))
return
end
end
if serverData then--如果没有解锁 点击查看不能影响后面红点
PlayerPrefs.SetInt(PlayerManager.uid.."Imprint"..configData.Id,1)
redPoint:SetActive(false)
end
local ScrollTrans = self.Scrollgrid:GetComponent("RectTransform")
curNum = configData.UnlockId - 1
local num = 100 + (curNum-2)*468 > 0 and 100 + (curNum-2)*468 or 0
local pos = Vector3.New(0,num,0)
ScrollTrans:DOLocalMove(pos,0.6)
self:Animation(1)
for key, value in pairs(self.SelectList) do
value:SetActive(false)
end
self.SelectList[_imprintId]:SetActive(true)
self:ShowSingleImprintInfoLayout(serverData,configData)
end)
end
--设置下方神印信息界面
function PracticeImprint:ShowSingleImprintInfoLayout(_serverData,_configData)
--title显示
self.Name.text = _configData.Name
if _configData.Type == 0 then
self.leftTitle.text = "通用神印"
elseif _configData.Type == 1 then
self.leftTitle.text = "附身神印"
end
--右侧部分状态和按钮显示
if not _serverData then
self.rightInfo:SetActive(false)
self.doBtnText.text = string.format("%s解锁",_configData.Unlock)
else
if _configData.Type == 0 then
self.rightInfo:SetActive(false)
elseif _configData.Type == 1 then
self.rightInfo:SetActive(true)
end
if _serverData.state == 0 then
self.doBtnText.text = "选择神印"
elseif _serverData.state == 1 then
self.doBtnText.text = "取消神印"
end
end
--详情
self.leftDetail.text = _configData.Desc
--神印确认/取消按钮
Util.AddOnceClick(self.doBtn,function ()
if _serverData ~= nil then
local old,new,sub = 0,0,""
old = PracticeManager.BigLevelImprintList[_configData.UnlockId]
new = _configData.Id
if _configData.Type == 0 then
sub = ""
elseif _configData.Type == 1 then
sub = _serverData.subId--self.curHeroId
if _serverData.subId == "" or _serverData.subId == "nil" or not _serverData.subId then
PopupTipPanel.ShowTip("请先选择附身英雄!")
return
end
end
NetManager.PracticeImprintRequest(old,new,tostring(sub),function ()
self:Refresh(true,true,function ()
curhero = tostring(sub)
self:Animation(2)
self:ShowSingleImprintInfoLayout(PracticeManager.GetSingleImprintData(new))
end)
end)
end
end)
--英雄图标
local heroData
local frame = Util.GetGameObject(self.itemPre, "frame"):GetComponent("Image")
local icon = Util.GetGameObject(self.itemPre, "icon"):GetComponent("Image")
local lv = Util.GetGameObject(self.itemPre, "lv/Text"):GetComponent("Text")
local proIcon = Util.GetGameObject(self.itemPre, "proIcon"):GetComponent("Image")
local starGrid = Util.GetGameObject(self.itemPre, "star")
local starPre = Util.GetGameObject(self.itemPre, "starPre")
--如果神印已开启且是附身神印
if _serverData and _configData.Type == 1 then
self.Add:SetActive(true)
self.Hero:SetActive(false)
if _serverData.subId ~= nil and _serverData.subId ~= "" and _serverData.subId ~= "nil" then
self.Add:SetActive(false)
self.Hero:SetActive(true)
--英雄图标
heroData = HeroManager.GetSingleHeroData(tostring(_serverData.subId))
frame.sprite = self.spLoader:LoadSprite(GetHeroQuantityImageByquality(heroData.heroConfig.Quality,heroData.star))
icon.sprite = self.spLoader:LoadSprite(heroData.icon)
lv.text = heroData.lv
proIcon.sprite = self.spLoader:LoadSprite(GetProStrImageByProNum(heroData.changeProId))
local star,starType = heroData.GetStar(1)
SetHeroStars(self.spLoader,starGrid, star,starType)
SetHeroFlyEffect(Util.GetGameObject(self.itemPre, "GameObject"),self.spLoader,heroData.star,self.sortingOrder+1,1,3,0)
Util.SetParticleSortLayer(starGrid,self.sortingOrder + 1)
curhero = _serverData.subId
else
curhero = ""
end
Util.AddOnceClick(self.MaskBtn,function()
UIManager.OpenPanel(UIName.GeneralBigPopup,GENERAL_POPUP_TYPE.XiuXingSelectHero,_configData,function (_heroData)
--发送请求
NetManager.PracticeImprintRequest(_configData.Id,_configData.Id,tostring(_heroData.dynamicId),function ()
frame.sprite = self.spLoader:LoadSprite(GetHeroQuantityImageByquality(_heroData.heroConfig.Quality,_heroData.star))
icon.sprite = self.spLoader:LoadSprite(_heroData.icon)
lv.text = _heroData.lv
proIcon.sprite = self.spLoader:LoadSprite(GetProStrImageByProNum(_heroData.changeProId))
local star,starType = _heroData.GetStar(1)
SetHeroStars(self.spLoader,starGrid, star,starType)
Util.SetParticleSortLayer(starGrid,self.sortingOrder + 1)
if curhero ~= _heroData.dynamicId and curhero ~= nil and curhero ~= "" and curhero ~= "nil" then
PopupTipPanel.ShowTip("已替换附身英雄!")
end
--刷新
self:Refresh(true,true,function ()
curhero = _heroData.dynamicId
self:Animation(2)
self:ShowSingleImprintInfoLayout(PracticeManager.GetSingleImprintData(_configData.Id))
end)
end)
end)
end)
end
--神将选择
end
function PracticeImprint:Animation(num)
local ImprintTrans = self.ImprintContent:GetComponent("RectTransform")
local ScrollTrans = self.Scroll:GetComponent("RectTransform")
local GridTans = self.Scrollgrid:GetComponent("RectTransform")
local perLenght = GridTans.sizeDelta.y/#self.allImprintData
local initPos = Vector3.New(0,-(ImprintTrans.sizeDelta.y/2 + UIManager.UIHeight/2),0)--详情界面的初始位置
local endPos = Vector3.New(0,-(UIManager.UIHeight/2 - ImprintTrans.sizeDelta.y/2),0)--详情界面的结束位置
if num == 1 then--打开神印信息界面
self.ImprintInfo:SetActive(true)
if trigger == true then
ImprintTrans.localPosition = initPos
ImprintTrans:DOLocalMove(endPos, 0.6)
if self.tween1 then
self.tween1:Kill()
end
self.tween1 = DoTween.To(DG.Tweening.Core.DOGetter_float( function () return UIManager.UIHeight - 100 end),
DG.Tweening.Core.DOSetter_float(function (t)
ScrollTrans.sizeDelta = Vector2.New(UIManager.UIWidth,t)
end), UIManager.UIHeight - 710, 0.6):SetEase(Ease.Linear)
else
ScrollTrans.sizeDelta = self.sizeDelta[2]
ImprintTrans.localPosition = endPos
end
trigger = false
elseif num == 2 then--刷新界面
self.ImprintInfo:SetActive(true)
ScrollTrans.sizeDelta = self.sizeDelta[2]
ImprintTrans.localPosition = endPos
trigger = false
elseif num == 3 then--关闭界面
self.ImprintInfo:SetActive(false)
ScrollTrans.sizeDelta = self.sizeDelta[1]
ImprintTrans.localPosition = initPos
trigger = true
curhero = ""
end
end
function PracticeImprint:OnClose()
curhero = ""
if self.tween1 then
self.tween1:Kill()
end
trigger = true
end
function PracticeImprint:OnDestroy()
self.spLoader:Destroy()
SubUIManager.Close(self.UpView)
self.UpView = nil
self.ImprintList = {}
self.SelectList = {}
end
return PracticeImprint