local GeneralBigPopup_RoleGodSoulUp = {}
--传入父脚本模块
local parent
--传入特效层级
local sortingOrder=0
local heroConfig = ConfigManager.GetConfig(ConfigName.HeroConfig)
local curList = {}
--初始化组件(用于子类重写)
function GeneralBigPopup_RoleGodSoulUp:InitComponent(gameObject)
self.spLoader = SpriteLoader.New()
self.Scroll = Util.GetGameObject(gameObject,"Scroll")
self.itemPre = Util.GetGameObject(gameObject,"itemPre")
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, 10))
self.ScrollView.moveTween.MomentumAmount = 1
self.ScrollView.moveTween.Strength = 2
self.ScrollView.elastic = false
self.costItemPre = Util.GetGameObject(gameObject, "costPre")
self.costGrid = Util.GetGameObject(gameObject, "costItem/costGrid")
self.oneKeyBtn = Util.GetGameObject(gameObject, "oneKey")
self.sureBtn = Util.GetGameObject(gameObject, "sure")
self.itemlist = {}
self.costItemlist = {}
self.choosedIdList = {}
end
--绑定事件(用于子类重写)
function GeneralBigPopup_RoleGodSoulUp:BindEvent()
Util.AddClick(self.oneKeyBtn,function ()
local isenuough,enoughNums,enoughDatas,oldEnoughDatas = false,nil,nil,nil
self.choosedIdList = {}
for i = 1,#self.allDatas do
table.insert(self.choosedIdList,self.allDatas[i].herodata.dynamicId)
isenuough,enoughNums,enoughDatas = GodSoulManager.CheckCanUpGodSoul(self.curHeroData,self.lv,self.choosedIdList)
if isenuough then
self:RefreshCostItemNums()
self:RefreshItemDatas()
break
else
if not oldEnoughDatas then
oldEnoughDatas = enoughDatas
else
local ismove = true
for k,v in pairs(oldEnoughDatas) do
if v ~= enoughDatas[k] then
ismove = false
break
end
end
if ismove then
table.remove(self.choosedIdList,#self.choosedIdList)
end
oldEnoughDatas = enoughDatas
end
end
end
if not isenuough then
PopupTipPanel.ShowTip("无法满足激活条件!")
return
end
end)
Util.AddClick(self.sureBtn,function()
local isSave = false
if self.isenuough then
if #curList == #self.choosedIdList then
for i = 1,#curList do
if self:CheckIsChooseId(curList[i]) < 1 then
isSave = true
break
end
end
else
isSave = true
end
if isSave then
NetManager.HeroGodSoulBindRequest(self.curHeroData.dynamicId,self.lv,self.choosedIdList,function()
parent:ClosePanel()
end)
else
parent:ClosePanel()
end
elseif #self.choosedIdList == 0 then
PopupTipPanel.ShowTip("请选择神将!")
else
PopupTipPanel.ShowTip("所选神将无法激活神魂效果!")
end
end)
end
--添加事件监听(用于子类重写)
function GeneralBigPopup_RoleGodSoulUp:AddListener()
end
--移除事件监听(用于子类重写)
function GeneralBigPopup_RoleGodSoulUp:RemoveListener()
end
--界面打开时调用(用于子类重写)
function GeneralBigPopup_RoleGodSoulUp:OnShow(_parent,_Data)
parent =_parent
sortingOrder = _parent.sortingOrder
self.costItems = _Data[1]
self.curHeroData = _Data[2]
self.lv = _Data[3]
self.allDatas = GodSoulManager.GetGodSoulData(self.curHeroData,self.lv)
self.choosedIdList = GodSoulManager.GetBindHeroDatasByLevel(self.curHeroData.dynamicId,self.lv)
curList = GodSoulManager.GetBindHeroDatasByLevel(self.curHeroData.dynamicId,self.lv)
self:Refresh(true,true)
end
function GeneralBigPopup_RoleGodSoulUp:Refresh(isTop,isAni)
if not self.itemlist then
self.itemlist = {}
end
for k,v in ipairs(self.itemlist) do
v.go.gameObject:SetActive(false)
end
self.ScrollView:SetData(self.allDatas, function(index, go)
self:SetSingleData(index,go,self.allDatas[index])
end,not isTop,not isAni)
self:UpdateCostItem()
end
function GeneralBigPopup_RoleGodSoulUp:RefreshItemDatas()
for k,v in ipairs(self.itemlist) do
if self:CheckIsChooseId(v.data.dynamicId) > 0 then
v.select.gameObject:SetActive(true)
else
v.select.gameObject:SetActive(false)
end
end
end
function GeneralBigPopup_RoleGodSoulUp:SetSingleData(index,go,heroData)
if not self.itemlist[index] then
self.itemlist[index] = {}
self.itemlist[index].go = go
self.itemlist[index].mask = Util.GetGameObject(go,"mask")
self.itemlist[index].select = Util.GetGameObject(go,"select")
self.itemlist[index].using = Util.GetGameObject(go,"using")
self.itemlist[index]._go = Util.GetGameObject(go,"HeroPre")
self.itemlist[index].frame = Util.GetGameObject(self.itemlist[index]._go,"frame"):GetComponent("Image")
self.itemlist[index].icon = Util.GetGameObject(self.itemlist[index]._go, "icon"):GetComponent("Image")
self.itemlist[index].pos = Util.GetGameObject(self.itemlist[index]._go, "posIcon"):GetComponent("Image")
self.itemlist[index].pro = Util.GetGameObject(self.itemlist[index]._go, "proIcon"):GetComponent("Image")
self.itemlist[index].lv = Util.GetGameObject(self.itemlist[index]._go, "lv/Text"):GetComponent("Text")
self.itemlist[index].name = Util.GetGameObject(self.itemlist[index]._go, "name"):GetComponent("Text")
self.itemlist[index].starGrid = Util.GetGameObject(self.itemlist[index]._go, "star")
end
self.itemlist[index]._data = heroData
self.itemlist[index].data = heroData.herodata
self.itemlist[index].frame.sprite=self.spLoader:LoadSprite(GetHeroQuantityImageByquality(self.itemlist[index].data.heroConfig.Quality,self.itemlist[index].data.star))
self.itemlist[index].icon.sprite=self.spLoader:LoadSprite(self.itemlist[index].data.icon)
self.itemlist[index].go.gameObject:SetActive(true)
if HarmonyManager.IsChangeColor(self.itemlist[index].data.dynamicId) then
self.itemlist[index].lv.text=""..self.itemlist[index].data.lv..""
elseif HarmonyManager:IsEnvoy(self.itemlist[index].data.dynamicId) and HarmonyManager:HongMengTowerUpLimit() >= HarmonyManager.TowerStartLimit then
self.itemlist[index].lv.text=""..self.itemlist[index].data.lv..""
else
self.itemlist[index].lv.text = self.itemlist[index].data.lv
end
self.itemlist[index].name.text = self.itemlist[index].data.heroConfig.ReadingName
self.itemlist[index].pro.sprite = self.spLoader:LoadSprite(GetProStrImageByProNum(self.itemlist[index].data.heroConfig.PropertyName))
self.itemlist[index].pos.sprite = self.spLoader:LoadSprite(self.itemlist[index].data.professionIcon)
local star,starType = self.itemlist[index].data.GetStar(1)
local starSize = Vector2.New(30,30)
local starScale = -8
if starType == 3 then
starSize = Vector2.New(33.43,83.61)
starScale = -16.86
end
SetHeroStars(self.spLoader, self.itemlist[index].starGrid, star,starType,starSize,starScale)
self.itemlist[index].select.gameObject:SetActive(false)
self.itemlist[index].mask.gameObject:SetActive(false)
self.itemlist[index].using.gameObject:SetActive(false)
if self:CheckIsChooseId(self.itemlist[index].data.dynamicId) > 0 then
self.itemlist[index].select.gameObject:SetActive(true)
elseif self.itemlist[index]._data.state == -1 then
self.itemlist[index].mask.gameObject:SetActive(true)
elseif self.itemlist[index]._data.state == 0 or self.itemlist[index]._data.state == 664 then
self.itemlist[index].using.gameObject:SetActive(true)
end
-- 点击事件
Util.AddOnceClick(self.itemlist[index]._go, function()
if self.itemlist[index]._data.state == -1 then
PopupTipPanel.ShowTip("该神将不满足神魂激活条件!")
return
end
if self.itemlist[index]._data.state == 0 or self.itemlist[index]._data.state == 664 then
PopupTipPanel.ShowTip("该神将已用于激活其他等级的神魂!")
return
end
local isChoosed = self:CheckIsChooseId(self.itemlist[index].data.dynamicId)
if isChoosed > 0 then
table.remove(self.choosedIdList,isChoosed)
self.itemlist[index].select.gameObject:SetActive(false)
else
table.insert(self.choosedIdList,self.itemlist[index].data.dynamicId)
self.itemlist[index].select.gameObject:SetActive(true)
end
self:RefreshCostItemNums()
end)
Util.AddLongPressClick(self.itemlist[index]._go, function()
end, 0.5)
end
function GeneralBigPopup_RoleGodSoulUp:CheckIsChooseId(heroId)
local index = 0
for i = 1,#self.choosedIdList do
if heroId == self.choosedIdList[i] then
index = i
return index
end
end
return index
end
function GeneralBigPopup_RoleGodSoulUp:UpdateCostItem()
for i = 1,math.max(#self.costItemlist,#self.costItems) do
if not self.costItems[i] then
self.costItemlist[i].go.gameObject:SetActive(false)
else
if not self.costItemlist[i] then
self.costItemlist[i] = {}
self.costItemlist[i].go = newObjToParent(self.costItemPre,self.costGrid)
self.costItemlist[i].frame = Util.GetGameObject(self.costItemlist[i].go,"frame"):GetComponent("Image")
self.costItemlist[i].icon = Util.GetGameObject(self.costItemlist[i].frame.transform,"icon"):GetComponent("Image")
self.costItemlist[i].num = Util.GetGameObject(self.costItemlist[i].go,"num"):GetComponent("Text")
end
self.costItemlist[i].go.gameObject:SetActive(true)
if self.costItems[i].id > 0 then
if self.costItems[i].star > 10 then
self.costItemlist[i].frame.sprite = self.spLoader:LoadSprite("s_shenhunxitong_zuanshitouxiangkuang")
else
self.costItemlist[i].frame.sprite = self.spLoader:LoadSprite("s_shenhunxitong_hong")
end
self.costItemlist[i].icon.gameObject:SetActive(true)
self.costItemlist[i].icon.sprite = self.spLoader:LoadSprite(GetResourcePath(heroConfig[self.costItems[i].id].Icon))
elseif self.costItems[i].property > 0 then
self.costItemlist[i].icon.gameObject:SetActive(false)
self.costItemlist[i].frame.sprite = self.spLoader:LoadSprite(PropertySmallIcon[self.costItems[i].star][self.costItems[i].property])
elseif self.costItems[i].profession > 0 then
self.costItemlist[i].icon.gameObject:SetActive(false)
self.costItemlist[i].frame.sprite = self.spLoader:LoadSprite(GodSoulProfession[self.costItems[i].star][self.costItems[i].profession])
else
self.costItemlist[i].icon.gameObject:SetActive(false)
self.costItemlist[i].frame.sprite = self.spLoader:LoadSprite(StarImage[self.costItems[i].star])
end
end
end
self:RefreshCostItemNums()
end
function GeneralBigPopup_RoleGodSoulUp:RefreshCostItemNums()
self.isenuough,self.enoughNums = GodSoulManager.CheckCanUpGodSoul(self.curHeroData,self.lv,self.choosedIdList)
for i = 1,#self.enoughNums do
if self.isenuough then
self.costItemlist[i].num.text = string.format("×%s",self.costItems[i].num)
else
if self.enoughNums[i] >= self.costItems[i].num then
self.costItemlist[i].num.text = string.format("×%s",self.costItems[i].num)
else
self.costItemlist[i].num.text = string.format("×%s",self.costItems[i].num)
end
end
end
end
--界面关闭时调用(用于子类重写)
function GeneralBigPopup_RoleGodSoulUp:OnClose()
end
--界面销毁时调用(用于子类重写)
function GeneralBigPopup_RoleGodSoulUp:OnDestroy()
self.spLoader:Destroy()
self.itemlist = {}
self.costItemlist = {}
end
return GeneralBigPopup_RoleGodSoulUp