383 lines
15 KiB
Lua
383 lines
15 KiB
Lua
require("Base/BasePanel")
|
||
PokemonInfoPanel = Inherit(BasePanel)
|
||
local this = PokemonInfoPanel
|
||
--升级升星
|
||
local curPokemonData--当前灵兽信息
|
||
local leftPokemonData--左边预加载灵兽信息
|
||
local rightPokemonData--右边预加载灵兽信息
|
||
local pokemonDatas--所有灵兽list信息
|
||
|
||
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
||
local heroRankupConfig = ConfigManager.GetConfig(ConfigName.HeroRankupConfig)
|
||
local propertyConfig = ConfigManager.GetConfig(ConfigName.PropertyConfig)
|
||
local index--当前灵兽在 灵兽列表中的索引
|
||
local allAddProVal={}--所有属性加成值
|
||
local isClickLeftOrRightBtn = true--点击左右按钮切换灵兽播放动画状态
|
||
|
||
local TabBox = require("Modules/Common/TabBox")
|
||
local _TabData={ [1] = { default = "zbhc_sanji2", select = "zbhc_sanji1", name = "情报" },
|
||
[2] = { default = "zbhc_sanji2", select = "zbhc_sanji1", name = "升星" },
|
||
}
|
||
local _TabFontColor = { default = Color.New(130 / 255, 128 / 255, 120 / 255, 1),
|
||
select = Color.New(243 / 255, 235 / 255, 202 / 255, 1)}
|
||
local _TabImagePos = { default = -3,
|
||
select = -10}
|
||
local curIndex = 0
|
||
|
||
this.contents = {
|
||
[1] = {view = require("Modules/Pokemon/view/PokemonInfoPanel_UpLv"), panelName = "PokemonInfoPanel_UpLv"},
|
||
[2] = {view = require("Modules/Pokemon/view/PokemonInfoPanel_UpStar"), panelName = "PokemonInfoPanel_UpStar"},
|
||
}
|
||
--初始化组件(用于子类重写)
|
||
function PokemonInfoPanel:InitComponent()
|
||
this.BtnBack = Util.GetGameObject(self.transform, "btnBack")
|
||
this.tabBox = Util.GetGameObject(self.transform, "TabBox")
|
||
|
||
this.live2dRoot = Util.GetGameObject(self.gameObject, "live2dRoot")
|
||
this.bg = Util.GetGameObject(self.gameObject, "bg")
|
||
this.starGrid = Util.GetGameObject(self.transform, "starGrid")
|
||
|
||
this.namne = Util.GetGameObject(self.transform, "nameInfo/nameText"):GetComponent("Text")
|
||
this.sortText = Util.GetGameObject(self.transform, "nameInfo/sortText"):GetComponent("Text")
|
||
this.upZhenImage = Util.GetGameObject(self.transform, "nameInfo/upZhenImage")
|
||
|
||
this.leftBtn = Util.GetGameObject(self.transform, "leftBtn/GameObject")
|
||
this.rightBtn = Util.GetGameObject(self.transform, "rightBtn/GameObject")
|
||
|
||
this.curObj= Util.GetGameObject(self.transform, "curObj")
|
||
this.leftObj= Util.GetGameObject(self.transform, "leftObj")
|
||
this.rightObj= Util.GetGameObject(self.transform, "rightObj")
|
||
|
||
this.nirvanaBtn=Util.GetGameObject(self.transform,"nirvanaBtn")
|
||
this.replaceBtn=Util.GetGameObject(self.transform,"replaceBtn")
|
||
this.restBtn=Util.GetGameObject(self.transform,"restBtn")
|
||
|
||
this.dragView = SubUIManager.Open(SubUIConfig.DragView, self.gameObject.transform)
|
||
this.dragView.transform:SetSiblingIndex(1)
|
||
this.UpView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform, { showType = UpViewOpenType.ShowLeft})
|
||
screenAdapte(self.bg)
|
||
|
||
this.trigger=Util.GetEventTriggerListener(this.dragView.gameObject)
|
||
this.trigger.onBeginDrag = this.trigger.onBeginDrag + this.OnBeginDrag
|
||
this.trigger.onDrag = this.trigger.onDrag + this.OnDrag
|
||
this.trigger.onEndDrag = this.trigger.onEndDrag + this.OnEndDrag
|
||
|
||
for i=1,#this.contents do
|
||
this.prefabs[i]=Util.GetGameObject(self.gameObject,this.contents[i].panelName)
|
||
this.contents[i].view:InitComponent(Util.GetGameObject(self.gameObject, "layout"))
|
||
end
|
||
end
|
||
--绑定事件(用于子类重写)
|
||
function PokemonInfoPanel:BindEvent()
|
||
for i = 1, #this.contents do
|
||
this.contents[i].view:BindEvent()
|
||
end
|
||
Util.AddClick(this.BtnBack, function()
|
||
-- PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
|
||
self:ClosePanel()
|
||
end)
|
||
--左切换按钮
|
||
Util.AddClick(this.leftBtn, function()
|
||
this:LeftBtnOnClick()
|
||
end)
|
||
--右切换按钮
|
||
Util.AddClick(this.rightBtn, function()
|
||
this:RightBtnOnClick()
|
||
end)
|
||
Util.AddClick(this.dragView.gameObject, function()
|
||
local SkeletonGraphic = this.curLiveObj:GetComponent("SkeletonGraphic")
|
||
SkeletonGraphic.AnimationState:SetAnimation(0, "touch", false)
|
||
end)
|
||
--涅槃
|
||
Util.AddClick(this.nirvanaBtn, function()
|
||
end)
|
||
--替换
|
||
Util.AddClick(this.replaceBtn, function()
|
||
|
||
end)
|
||
--休息
|
||
Util.AddClick(this.restBtn, function()
|
||
end)
|
||
end
|
||
|
||
--添加事件监听(用于子类重写)
|
||
function PokemonInfoPanel:AddListener()
|
||
for i = 1, #this.contents do
|
||
this.contents[i].view:AddListener()
|
||
end
|
||
end
|
||
|
||
--移除事件监听(用于子类重写)
|
||
function PokemonInfoPanel:RemoveListener()
|
||
for i = 1, #this.contents do
|
||
this.contents[i].view:RemoveListener()
|
||
end
|
||
end
|
||
|
||
--界面打开时调用(用于子类重写)
|
||
function PokemonInfoPanel:OnOpen(_curPokemonData, _pokemonDatas)
|
||
curPokemonData, pokemonDatas = _curPokemonData, _pokemonDatas
|
||
end
|
||
|
||
function PokemonInfoPanel:OnSortingOrderChange()
|
||
for i = 1, #this.contents do
|
||
this.contents[i].view:OnSortingOrderChange(self.sortingOrder)
|
||
end
|
||
end
|
||
|
||
function PokemonInfoPanel:OnShow()
|
||
this.TabCtrl = TabBox.New()
|
||
this.TabCtrl:SetTabAdapter(this.TabAdapter)
|
||
this.TabCtrl:SetChangeTabCallBack(this.SwitchView)
|
||
this.TabCtrl:Init(this.tabBox, _TabData,curIndex)
|
||
this.OnShowData()
|
||
end
|
||
|
||
-- tab节点显示自定义
|
||
function this.TabAdapter(tab, index, status)
|
||
local tabLab = Util.GetGameObject(tab, "Text")
|
||
local tabImage = Util.GetGameObject(tab,"Image")
|
||
tabImage:GetComponent("Image").sprite = Util.LoadSprite(_TabData[index][status])
|
||
tabImage:GetComponent("Image"):SetNativeSize()
|
||
tabLab:GetComponent("Text").text = _TabData[index].name
|
||
tabLab:GetComponent("Text").color = _TabFontColor[status]
|
||
tabImage.transform.localPosition = Vector3.New( tabImage.transform.localPosition.x, _TabImagePos[status], 0);
|
||
end
|
||
--切换视图
|
||
function this.SwitchView(index)
|
||
--先执行上一面板关闭逻辑
|
||
local oldSelect
|
||
oldSelect, curIndex = curIndex, index
|
||
for i = 1, #this.contents do
|
||
if oldSelect~=0 then this.contents[oldSelect].view:OnClose() break end
|
||
end
|
||
--切换预设显隐
|
||
for i = 1, #this.prefabs do
|
||
this.prefabs[i].gameObject:SetActive(i == index)--切换子模块预设显隐
|
||
end
|
||
--区分显示
|
||
if index==1 then
|
||
this.upView:OnOpen({showType = UpViewOpenType.ShowLeft, panelType = PanelType.Main})
|
||
elseif index==2 then
|
||
this.upView:OnOpen({showType = UpViewOpenType.ShowLeft, panelType = PanelType.Main})
|
||
end
|
||
this.RefreshHelpBtn()
|
||
--执行子模块初始化
|
||
this.contents[index].view:OnShow(this)
|
||
end
|
||
|
||
function this.OnShowData()
|
||
isClickLeftOrRightBtn = true
|
||
for i = 1, #pokemonDatas do
|
||
if curPokemonData == pokemonDatas[i] then
|
||
index = i
|
||
end
|
||
end
|
||
this.UpdateLiveList()--加载当前 和 左右数据
|
||
if this.leftLiveObj and leftPokemonData then
|
||
LogError(Language[11833])
|
||
poolManager:UnLoadLive(leftPokemonData.live, this.leftLiveObj)
|
||
this.leftLiveObj = nil
|
||
end
|
||
if this.rightLiveObj and rightPokemonData then
|
||
LogError(Language[11834])
|
||
poolManager:UnLoadLive(rightPokemonData.live, this.rightLiveObj)
|
||
this.rightLiveObj = nil
|
||
end
|
||
if this.curLiveObj and curPokemonData then
|
||
LogError(Language[11835])
|
||
poolManager:UnLoadLive(curPokemonData.live, this.curLiveObj)
|
||
this.curLiveObj = nil
|
||
end
|
||
Util.ClearChild(this.curObj.transform)
|
||
Util.ClearChild(this.leftObj.transform)
|
||
Util.ClearChild(this.rightObj.transform)
|
||
this.leftLiveObj = this.LoadHerolive(leftPokemonData,this.leftObj)
|
||
this.rightLiveObj = this.LoadHerolive(rightPokemonData,this.rightObj)
|
||
this.curLiveObj = this.LoadHerolive(curPokemonData,this.curObj)
|
||
if this.curLiveObj then
|
||
this.dragView.gameObject:SetActive(true)
|
||
this.dragView:SetDragGO(this.curLiveObj)
|
||
else
|
||
this.dragView.gameObject:SetActive(false)
|
||
end
|
||
this.UpdateHeroInfoData()
|
||
this.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.RoleInfo })
|
||
FixedUpdateBeat:Add(this.OnUpdate, self)--长按方法注册
|
||
end
|
||
|
||
--长按升级处理
|
||
function this.OnUpdate()
|
||
for i = 1, #this.contents do
|
||
this.contents[i].view.OnUpdate()
|
||
end
|
||
end
|
||
|
||
--更新界面已存数据
|
||
function this.UpdateLiveList()
|
||
local leftIndex = (index - 1 > 0 and index - 1 or #pokemonDatas)
|
||
leftPokemonData = pokemonDatas[leftIndex]
|
||
curPokemonData = pokemonDatas[index]
|
||
local rightIndex = (index + 1 <= #pokemonDatas and index + 1 or 1)
|
||
rightPokemonData = pokemonDatas[rightIndex]
|
||
end
|
||
--根据界面数据加载动态立绘
|
||
function this.LoadHerolive(_heroData, _objPoint)
|
||
--TODO:动态加载立绘
|
||
local testLive = poolManager:LoadLive(_heroData.live, _objPoint.transform,
|
||
Vector3.one * _heroData.scale, Vector3.New(_heroData.position[1], _heroData.position[2], 0))
|
||
local SkeletonGraphic = testLive:GetComponent("SkeletonGraphic")
|
||
local idle = function() SkeletonGraphic.AnimationState:SetAnimation(0, "idle", true) end
|
||
SkeletonGraphic.AnimationState.Complete = SkeletonGraphic.AnimationState.Complete + idle
|
||
poolManager:SetLiveClearCall(_heroData.live, testLive, function ()
|
||
SkeletonGraphic.AnimationState.Complete = SkeletonGraphic.AnimationState.Complete - idle
|
||
end)
|
||
return testLive
|
||
end
|
||
--更新灵兽情报数据
|
||
function this.UpdateHeroInfoData()
|
||
if this.curLiveObj then
|
||
self.dragView.gameObject:SetActive(true)
|
||
self.dragView:SetDragGO(this.curLiveObj)
|
||
else
|
||
self.dragView.gameObject:SetActive(false)
|
||
end
|
||
local starSize = Vector2.New(65,65)
|
||
SetHeroStars(self.starGrid, curPokemonData.star,1,starSize,0,Vector2.New(0.5,0.5))
|
||
--SetHeroStars(starGrid, heroData.star,1,nil,nil,Vector2.New(0,1))
|
||
--常规属性赋值
|
||
|
||
end
|
||
|
||
|
||
--右切换按钮点击
|
||
function this.RightBtnOnClick()
|
||
if isClickLeftOrRightBtn == false then
|
||
return
|
||
end
|
||
isClickLeftOrRightBtn = false
|
||
this.rightBtn:GetComponent("Button").enabled = false
|
||
local oldIndexConfigData = pokemonDatas[index]
|
||
index = (index + 1 <= #pokemonDatas and index + 1 or 1)
|
||
curPokemonData = pokemonDatas[index]
|
||
if this.leftLiveObj then
|
||
poolManager:UnLoadLive(leftPokemonData.live, this.leftLiveObj)
|
||
this.leftLiveObj = nil
|
||
end
|
||
this.curLiveObj.transform:SetParent(self.leftObj.transform)
|
||
this.curLiveObj:GetComponent("RectTransform"):DOAnchorPos(Vector2.New(oldIndexConfigData.position[1],oldIndexConfigData.position[2]), 0.5, false):SetEase(Ease.Linear)
|
||
this.rightLiveObj.transform:SetParent(self.curObj.transform)
|
||
this.rightLiveObj:GetComponent("RectTransform"):DOAnchorPos(Vector2.New(rightPokemonData.position[1],rightPokemonData.position[2]), 0.5, false):OnComplete(function ()
|
||
this:UpdateLiveList()
|
||
this.leftLiveObj = this.curLiveObj
|
||
this.curLiveObj = this.rightLiveObj
|
||
this.rightLiveObj = this:LoadHerolive(rightPokemonData,self.rightObj)
|
||
this:UpdatePanelData()
|
||
local SkeletonGraphic = this.curLiveObj:GetComponent("SkeletonGraphic")
|
||
SkeletonGraphic.AnimationState:SetAnimation(0, "touch", false)
|
||
this.rightBtn:GetComponent("Button").enabled = true
|
||
isClickLeftOrRightBtn = true
|
||
end):SetEase(Ease.Linear)
|
||
end
|
||
--左切换按钮点击
|
||
function this.LeftBtnOnClick()
|
||
if isClickLeftOrRightBtn == false then
|
||
return
|
||
end
|
||
isClickLeftOrRightBtn = false
|
||
this.leftBtn:GetComponent("Button").enabled = false
|
||
local oldIndexConfigData = pokemonDatas[index]
|
||
index = (index - 1 > 0 and index - 1 or #pokemonDatas)
|
||
curPokemonData = pokemonDatas[index]
|
||
if this.rightLiveObj then
|
||
poolManager:UnLoadLive(rightPokemonData.live, this.rightLiveObj)
|
||
this.rightLiveObj = nil
|
||
end
|
||
this.curLiveObj.transform:SetParent(self.rightObj.transform)
|
||
this.curLiveObj:GetComponent("RectTransform"):DOAnchorPos(Vector2.New(oldIndexConfigData.position[1],oldIndexConfigData.position[2]), 0.5, false):SetEase(Ease.Linear)
|
||
this.leftLiveObj.transform:SetParent(self.curObj.transform)
|
||
this.leftLiveObj:GetComponent("RectTransform"):DOAnchorPos(Vector2.New(leftPokemonData.position[1],leftPokemonData.position[2]), 0.5, false):OnComplete(function ()
|
||
this:UpdateLiveList()
|
||
this.rightLiveObj = this.curLiveObj
|
||
this.curLiveObj = this.leftLiveObj
|
||
this.leftLiveObj = this:LoadHerolive(leftPokemonData,self.leftObj)
|
||
this:UpdatePanelData()
|
||
local SkeletonGraphic = this.curLiveObj:GetComponent("SkeletonGraphic")
|
||
SkeletonGraphic.AnimationState:SetAnimation(0, "touch", false)
|
||
this.leftBtn:GetComponent("Button").enabled = true
|
||
isClickLeftOrRightBtn = true
|
||
end):SetEase(Ease.Linear)
|
||
end
|
||
|
||
function this.SortpokemonDatas(_pokemonDatas)
|
||
--上阵最优先,星级优先,同星级等级优先,同星级同等级按sortId排序。排序时降序排序。
|
||
table.sort(_pokemonDatas, function(a, b)
|
||
if a.heroConfig.Natural ==b.heroConfig.Natural then
|
||
if a.star == b.star then
|
||
if a.lv == b.lv then
|
||
return a.heroConfig.Id < b.heroConfig.Id
|
||
else
|
||
return a.lv > b.lv
|
||
end
|
||
else
|
||
return a.star > b.star
|
||
end
|
||
else
|
||
return a.heroConfig.Natural > b.heroConfig.Natural
|
||
end
|
||
end)
|
||
end
|
||
local beginV3
|
||
local endV3
|
||
local distance
|
||
function this.OnBeginDrag(Pointgo, data)
|
||
beginV3=this.curLiveObj.transform.anchoredPosition
|
||
end
|
||
function this.OnDrag(Pointgo, data)
|
||
distance=Vector2.Distance(beginV3,this.curLiveObj.transform.anchoredPosition)
|
||
end
|
||
function this.OnEndDrag(Pointgo, data)
|
||
endV3=this.curLiveObj.transform.anchoredPosition
|
||
if distance>250 and endV3.x<0 then
|
||
this:RightBtnOnClick()
|
||
elseif distance>250 and endV3.x>0 then
|
||
this:LeftBtnOnClick()
|
||
else
|
||
this.curLiveObj:GetComponent("RectTransform"):DOAnchorPos(Vector2.New(curPokemonData.position[1],curPokemonData.position[2]), 0.5, false):SetEase(Ease.Linear)
|
||
end
|
||
distance=0
|
||
end
|
||
|
||
--界面关闭时调用(用于子类重写)
|
||
function PokemonInfoPanel:OnClose()
|
||
for i = 1, #this.contents do
|
||
this.contents[i].view:OnClose()
|
||
end
|
||
--this.globalcurPokemonData=nil
|
||
if this.leftLiveObj and leftPokemonData then
|
||
poolManager:UnLoadLive(leftPokemonDataleftPokemonData.live, this.leftLiveObj)
|
||
this.leftLiveObj = nil
|
||
end
|
||
if this.rightLiveObj and rightPokemonData then
|
||
poolManager:UnLoadLive(rightPokemonData.live, this.rightLiveObj)
|
||
this.rightLiveObj = nil
|
||
end
|
||
if this.curLiveObj and curPokemonData then
|
||
poolManager:UnLoadLive(curPokemonData.live, this.curLiveObj)
|
||
this.curLiveObj = nil
|
||
end
|
||
this.leftBtn:GetComponent("Button").enabled = true
|
||
this.rightBtn:GetComponent("Button").enabled = true
|
||
FixedUpdateBeat:Remove(this.OnUpdate, self)
|
||
end
|
||
|
||
--界面销毁时调用(用于子类重写)
|
||
function PokemonInfoPanel:OnDestroy()
|
||
for i = 1, #this.contents do
|
||
this.contents[i].view:OnDestroy()
|
||
end
|
||
this.pinjieList={}
|
||
SubUIManager.Close(this.UpView)
|
||
SubUIManager.Close(SubUIConfig.DragView, this.dragView)
|
||
end
|
||
return PokemonInfoPanel |