miduo_client/Assets/ManagedResources/~Lua/Modules/RoleInfo/RoleUpStarListPanel.lua

223 lines
9.7 KiB
Lua
Raw Normal View History

2020-08-06 17:52:32 +08:00
require("Base/BasePanel")
2020-05-09 13:31:21 +08:00
RoleUpStarListPanel = Inherit(BasePanel)
local this = RoleUpStarListPanel
local curSelectHeroList={}
local heroDataList={}
local curNeedRoleNum
local openThisPanel
local curHeroData = {}
--初始化组件(用于子类重写)
function RoleUpStarListPanel:InitComponent()
this.BtnBack = Util.GetGameObject(self.transform, "btnBack")
this.BtnSure = Util.GetGameObject(self.transform, "btnSure")
this.btnAutoSelect = Util.GetGameObject(self.transform, "btnAutoSelect")
this.cardPre = Util.GetGameObject(self.gameObject, "item")
--this.grid = Util.GetGameObject(self.gameObject, "scroll/grid")
this.desText = Util.GetGameObject(self.gameObject, "desText"):GetComponent("Text")
this.numText = Util.GetGameObject(self.gameObject, "numText"):GetComponent("Text")
this.Scrollbar= Util.GetGameObject(self.gameObject, "Scrollbar"):GetComponent("Scrollbar")
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView,Util.GetGameObject(self.gameObject, "scroll").transform,
this.cardPre, this.Scrollbar, Vector2.New(927.5, 1010), 1, 5, Vector2.New(19.32,15))
this.ScrollView.gameObject:GetComponent("RectTransform").anchoredPosition = Vector2.New(6.78, 27)
this.ScrollView.gameObject:GetComponent("RectTransform").anchorMin = Vector2.New(0.5, 0.5)
this.ScrollView.gameObject:GetComponent("RectTransform").anchorMax = Vector2.New(0.5, 0.5)
this.ScrollView.moveTween.MomentumAmount = 1
this.ScrollView.moveTween.Strength = 1
end
--绑定事件(用于子类重写)
function RoleUpStarListPanel:BindEvent()
Util.AddClick(this.BtnBack, function()
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
self:ClosePanel()
end)
Util.AddClick(this.BtnSure, function()
self:ClosePanel()
Log("curSelectHeroList "..LengthOfTable(curSelectHeroList))
openThisPanel:UpdateUpStarPosHeroData(curSelectHeroList)
end)
Util.AddClick(this.btnAutoSelect, function()
self:AutoSelectHero()
end)
end
--添加事件监听(用于子类重写)
function RoleUpStarListPanel:AddListener()
end
--移除事件监听(用于子类重写)
function RoleUpStarListPanel:RemoveListener()
end
--界面打开时调用(用于子类重写)
function RoleUpStarListPanel:OnOpen(heroData,HeroRankupGroupData,RankupConsumeMaterialData,_openThisPanel,_curSelectHeroList,_curHeroData)
openThisPanel= _openThisPanel
curSelectHeroList={}
for i = 1, #_curSelectHeroList do
curSelectHeroList[_curSelectHeroList[i]]=_curSelectHeroList[i]
end
curHeroData = _curHeroData
heroDataList = heroData
this.HeroSortData(heroDataList)
for i, v in pairs(heroDataList) do
for n,w in pairs(FormationManager.formationList) do
if HeroManager.heroResolveLicence[n] then
for m = 1, #w.teamHeroInfos do
if v.dynamicId==w.teamHeroInfos[m].heroId then
local isFormationStr = HeroManager.GetHeroFormationStr(n)
v.isFormation = isFormationStr
end
end
end
end
end
this.ScrollView:SetData(heroDataList, function (index, go)
this.OnShowSingleCardData(go, heroDataList[index])
end)
curNeedRoleNum=RankupConsumeMaterialData[4]
2020-06-13 11:47:13 +08:00
local str = ""
if HeroRankupGroupData.Issame == 1 then
2020-06-23 18:36:24 +08:00
str = HeroRankupGroupData.StarLimit..Language[11868]
2020-06-13 11:47:13 +08:00
else
if HeroRankupGroupData.IsId ~= 0 then
2020-06-23 18:36:24 +08:00
str = HeroRankupGroupData.StarLimit..Language[11869]..ConfigManager.GetConfigData(ConfigName.HeroConfig,HeroRankupGroupData.IsId).ReadingName
2020-06-13 11:47:13 +08:00
else
if HeroRankupGroupData.IsSameClan == 0 then
2020-06-23 18:36:24 +08:00
str = HeroRankupGroupData.StarLimit..Language[11870]
2020-06-13 11:47:13 +08:00
else
2020-06-23 18:36:24 +08:00
str = HeroRankupGroupData.StarLimit..Language[11871]
2020-06-13 11:47:13 +08:00
end
end
end
2020-06-23 18:36:24 +08:00
this.desText.text=string.format(Language[11872],curNeedRoleNum,str)--HeroRankupGroupData.Name)
2020-05-09 13:31:21 +08:00
this.numText.text=string.format("%s/%s",#curSelectHeroList,curNeedRoleNum)
end
function this.OnClickEnterHero(go,heroData,type)
if type==1 then
if #curSelectHeroList>=curNeedRoleNum then
2020-06-23 18:36:24 +08:00
PopupTipPanel.ShowTip(Language[10660])
2020-05-09 13:31:21 +08:00
return
else
table.insert(curSelectHeroList,heroData)
end
elseif type==2 then
for i = 1, #curSelectHeroList do
if heroData.dynamicId==curSelectHeroList[i].dynamicId then
table.remove(curSelectHeroList,i)
break
end
end
end
this.OnShowSingleCardData(go,heroData,type)
this.numText.text=string.format("%s/%s",#curSelectHeroList,curNeedRoleNum)
end
function this.OnShowSingleCardData(go,heroData)--isSelect 1选择 2 没选择
local choosed = Util.GetGameObject(go.transform, "choosed")
choosed:SetActive(false)
if curSelectHeroList[heroData.dynamicId] then
curSelectHeroList[heroData.dynamicId]=heroData
choosed:SetActive(true)
end
2020-07-25 20:28:41 +08:00
Util.GetGameObject(go.transform, "frame"):GetComponent("Image").sprite = Util.LoadSprite(GetHeroQuantityImageByquality(heroData.heroConfig.Quality,heroData.star))
2020-05-09 13:31:21 +08:00
Util.GetGameObject(go.transform, "lv/Text"):GetComponent("Text").text = heroData.lv
Util.GetGameObject(go.transform, "icon"):GetComponent("Image").sprite = Util.LoadSprite(GetResourcePath(heroData.heroConfig.Icon))
2020-06-03 19:09:01 +08:00
Util.GetGameObject(go.transform, "posIcon"):SetActive(false)--:GetComponent("Image").sprite = Util.LoadSprite(heroData.professionIcon)
2020-05-09 13:31:21 +08:00
Util.GetGameObject(go.transform, "proIcon"):GetComponent("Image").sprite = Util.LoadSprite(GetProStrImageByProNum(heroData.heroConfig.PropertyName))
--Util.GetGameObject(go.transform, "heroStage"):GetComponent("Image").sprite = Util.LoadSprite(HeroStageSprite[heroData.heroConfig.HeroStage])
local formationMask = Util.GetGameObject(go.transform, "formationMask")
--LogError("heroData.isFormation "..heroData.isFormation)
formationMask:SetActive((heroData.isFormation ~= "" and heroData.isFormation ~= Language[11108]) or heroData.lockState == 1)
2020-05-09 13:31:21 +08:00
Util.GetGameObject(formationMask.transform, "formationImage"):SetActive(heroData.isFormation ~= "" )
Util.GetGameObject(formationMask.transform, "lockImage"):SetActive( heroData.lockState == 1)
Util.GetGameObject(go.transform, "noumenon"):SetActive( heroData.id == curHeroData.id )
local starGrid = Util.GetGameObject(go.transform, "star")
2020-07-28 16:54:38 +08:00
SetHeroStars(starGrid, heroData.star,1,nil,nil,Vector2.New(0,1))
2020-05-09 13:31:21 +08:00
local cardBtn = Util.GetGameObject(go.transform, "icon")
Util.AddOnceClick(cardBtn, function()
if curSelectHeroList[heroData.dynamicId] then
choosed:SetActive(false)
curSelectHeroList[heroData.dynamicId]=nil
this.numText.text=string.format("%s/%s",LengthOfTable(curSelectHeroList),curNeedRoleNum)
return
end
if LengthOfTable(curSelectHeroList)>=curNeedRoleNum then
2020-06-23 18:36:24 +08:00
PopupTipPanel.ShowTip(Language[10660])
2020-05-09 13:31:21 +08:00
return
end
curSelectHeroList[heroData.dynamicId]=heroData
choosed:SetActive(true)
this.numText.text=string.format("%s/%s",LengthOfTable(curSelectHeroList),curNeedRoleNum)
end)
Util.AddOnceClick(formationMask, function()
if heroData.isFormation ~= "" then
PopupTipPanel.ShowTip( heroData.isFormation)
return
end
if heroData.lockState == 1 then
2020-06-23 18:36:24 +08:00
PopupTipPanel.ShowTip(Language[11776])
2020-05-09 13:31:21 +08:00
return
end
end)
end
function this.HeroSortData(heroData)
Log("#heroData "..#heroData)
--Language[11108]
2020-05-09 13:31:21 +08:00
table.sort(heroData, function(a, b)
if (a.isFormation == "" or (a.isFormation ~= "" and a.isFormation == Language[11108])) and (b.isFormation == "" or (b.isFormation ~= "" and b.isFormation == Language[11108]))
or (a.isFormation ~= "" and a.isFormation ~= Language[11108]) and (b.isFormation ~= "" and b.isFormation ~= Language[11108]) then
2020-05-09 13:31:21 +08:00
if a.lockState == b.lockState then
if a.heroConfig.Star == b.heroConfig.Star then
if a.lv == b.lv then
if a.id ~= curHeroData.id and b.id ~= curHeroData.id or a.id == curHeroData.id and b.id == curHeroData.id then
return a.id > b.id
else
return not a.id ~= curHeroData.id and b.id == curHeroData.id
end
else
return a.lv < b.lv
end
else
return a.heroConfig.Star < b.heroConfig.Star
end
else
return a.lockState < b.lockState
end
else
return (a.isFormation == "" or (a.isFormation ~= "" and a.isFormation == Language[11108])) and (not b.dynamicId ~= "" and b.isFormation ~= Language[11108])
2020-05-09 13:31:21 +08:00
end
end)
end
function RoleUpStarListPanel:AutoSelectHero()
curSelectHeroList = {}
for i = 1, #heroDataList do
if LengthOfTable(curSelectHeroList) < curNeedRoleNum and heroDataList[i].isFormation == "" and heroDataList[i].lockState == 0 then
curSelectHeroList[heroDataList[i].dynamicId]=heroDataList[i]
end
end
this.numText.text=string.format("%s/%s",LengthOfTable(curSelectHeroList),curNeedRoleNum)
this.ScrollView:SetData(heroDataList, function (index, go)
this.OnShowSingleCardData(go, heroDataList[index])
end)
end
--界面关闭时调用(用于子类重写)
function RoleUpStarListPanel:OnClose()
end
--界面销毁时调用(用于子类重写)
function RoleUpStarListPanel:OnDestroy()
this.ScrollView = nil
end
2020-06-23 18:36:24 +08:00
return RoleUpStarListPanel