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

233 lines
10 KiB
Lua

require("Base/BasePanel")
RoleChooseListPanel = Inherit(BasePanel)
local this = RoleChooseListPanel
local curSelectHeroList = {}
local curNeedRoleNum
local openThisPanel
local curHeroData = {}
local TempData = nil;
local SelectHero = nil
local selectIndex = 0
--初始化组件(用于子类重写)
function RoleChooseListPanel:InitComponent()
this.spLoader = SpriteLoader.New()
this.BtnBack = Util.GetGameObject(self.transform, "btnBack")
this.BtnSure = Util.GetGameObject(self.transform, "btnSure")
this.BtnSure:SetActive(false)
this.btnAutoSelect = Util.GetGameObject(self.transform, "btnAutoSelect")
this.btnAutoSelect:SetActive(false)
this.cardPre = Util.GetGameObject(self.gameObject, "item")
this.btnYes = Util.GetGameObject(self.gameObject, "btnYes")
this.btnYes:SetActive(true)
--this.grid = Util.GetGameObject(self.gameObject, "scroll/grid")
this.title_text = Util.GetGameObject(self.gameObject, "bg/Text"):GetComponent("Text")
this.desText = Util.GetGameObject(self.gameObject, "desText"):GetComponent("Text")
this.numText = Util.GetGameObject(self.gameObject, "numText"):GetComponent("Text")
this.Empty = Util.GetGameObject(self.gameObject, "bg/Empty")
local v = Util.GetGameObject(self.gameObject, "scroll"):GetComponent("RectTransform").rect
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(v.width, v.height), 1, 5, Vector2.New(20, 50))
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
this.NoneImage = Util.GetGameObject(self.gameObject, "NoneImage")
this.NoneImage.gameObject:SetActive(false)
--this:InitData()
end
--绑定事件(用于子类重写)
function RoleChooseListPanel:BindEvent()
Util.AddClick(this.BtnBack, function()
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
self:ClosePanel()
end)
Util.AddClick(this.btnYes, function()
if TempData == nil then
PopupTipPanel.ShowTip(Language[10618])
return
end
HarmonyManager:SetChooseId(TempData.dynamicId)
HarmonyManager.SetOldPowerNum(TempData.dynamicId)
if self.flag then --判断是否是鸿蒙使者 如果是 那就不懈装备
local data = {}
data.gridId = HarmonyManager.GongMingBox
data.heroId = TempData.dynamicId
data.time = 0
NetManager.SendGongMingBox(TempData.dynamicId, HarmonyManager.GongMingBox, 4, function(msg)
-- body
Game.GlobalEvent:DispatchEvent(GameEvent.HongMeng.UpHongMengEnvoy, data)
--UIManager.OpenPanel(UIName.GongMingResultPanel,self.flag)
HarmonyManager.WarPowerChangeNotify(TempData.dynamicId)
HeroPropManager.SetHeroDirty(TempData.dynamicId)
end)
else
HarmonyManager:SetGongMingList(TempData.dynamicId)
if HarmonyManager.equipCount == 24 then
--LogGreen("脱装备")
-- for i = 1, #TempData.equipIdList do
-- HeroManager.SetHeroEquipIdList(TempData.dynamicId, {})
-- EquipManager.DeleteSingleEquip(TempData.equipIdList[i],TempData.dynamicId)
-- end
end
NetManager.SendGongMingBox(TempData.dynamicId, HarmonyManager.GongMingBox, 1, function(msg)
Game.GlobalEvent:DispatchEvent(GameEvent.HongMeng.ChooseData, TempData)
UIManager.OpenPanel(UIName.GongMingResultPanel, self.flag)
HarmonyManager.WarPowerChangeNotify(TempData.dynamicId)
HeroPropManager.SetHeroDirty(TempData.dynamicId)
end)
end
self:ClosePanel()
end)
end
--添加事件监听(用于子类重写)
function RoleChooseListPanel:AddListener()
end
--移除事件监听(用于子类重写)
function RoleChooseListPanel:RemoveListener()
end
--界面打开时调用(用于子类重写)
function RoleChooseListPanel:OnOpen(flag)
this.desText.text = ""
this.numText.text = ""
this.title_text.text = Language[12705]
self.flag = flag
TempData = nil
--SelectHero = nil
local list = HarmonyManager.ChooseDataList
if #list > 0 then
this.Empty:SetActive(false)
table.sort(list, function(a, b)
if a.star == b.star then
if a.heroConfig.Natural == b.heroConfig.Natural then
if a.lv == b.lv then
return a.heroConfig.Id < b.heroConfig.Id
else
return a.lv > b.lv
end
else
return a.heroConfig.Natural > b.heroConfig.Natural
end
else
return a.star > b.star
end
end)
if not list or #list < 1 then
this.NoneImage.gameObject:SetActive(true)
else
this.NoneImage.gameObject:SetActive(false)
end
self.ScrollView.gameObject:SetActive(true)
self.ScrollView:SetData(list, function(index, go)
this.OnShowSingleCardData(go, list[index], index) --
end)
else
list = {}
self.ScrollView.gameObject:SetActive(false)
this.Empty:SetActive(true)
end
end
function this.OnShowSingleCardData(go, heroData, index) --isSelect 1选择 2 没选择
local choosed = Util.GetGameObject(go.transform, "choosed")
if choosed then
-- body
choosed:SetActive(false)
end
if curSelectHeroList[heroData.dynamicId] then
curSelectHeroList[heroData.dynamicId] = heroData
choosed:SetActive(true)
end
Util.GetGameObject(go.transform, "frame"):GetComponent("Image").sprite = this.spLoader:LoadSprite(
GetHeroQuantityImageByquality(heroData.heroConfig.Quality, heroData.star))
Util.GetGameObject(go.transform, "lv/Text"):GetComponent("Text").text = heroData.lv
Util.GetGameObject(go.transform, "icon"):GetComponent("Image").sprite = this.spLoader:LoadSprite(heroData.icon)
Util.GetGameObject(go.transform, "posIcon"):SetActive(false) --:GetComponent("Image").sprite = this.spLoader:LoadSprite(heroData.professionIcon)
Util.GetGameObject(go.transform, "proIcon"):GetComponent("Image").sprite = this.spLoader:LoadSprite(
GetProStrImageByProNum(heroData.changeProId))
--Util.GetGameObject(go.transform, "heroStage"):GetComponent("Image").sprite = this.spLoader:LoadSprite(HeroStageSprite[heroData.heroConfig.HeroStage])
local formationMask = Util.GetGameObject(go.transform, "formationMask")
--LogError("heroData.isFormation "..heroData.isFormation)
--formationMask:SetActive((heroData.isFormation ~= "" and heroData.isFormation ~= "该神将在大闹天宫阵容中已上阵") or heroData.lockState == 1)
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)
Util.GetGameObject(go.transform, "name"):GetComponent("Text").text = SubString2(
GetLanguageStrById(heroData.heroConfig
.ReadingName), 8)
local starGrid = Util.GetGameObject(go.transform, "star")
local star, starType = heroData.GetStar(1)
SetHeroStars(this.spLoader, starGrid, star, starType, nil, nil, Vector2.New(0, 1))
local effect = SetHeroFlyEffect(go, this.spLoader, heroData.star, this.sortingOrder + 1, 1, 3)
if effect then
local particles = effect:GetComponentsInChildren(typeof(UnityEngine.ParticleSystem))
for key, value in pairs(particles:ToTable()) do
local mat = value:GetComponent(typeof(UnityEngine.Renderer))
if mat.material.shader.name == "YXZ/Effect/Mix Masking(Without Moving)_alphablend" then
mat.material.shader = poolManager:LoadAsset("YXZ_MixMaskingWithoutMoving_alphablend_1",
poolManager.AssetType.Other)
end
end
end
local meshs1 = starGrid:GetComponentsInChildren(typeof(UnityEngine.ParticleSystem))
for key, value in pairs(meshs1:ToTable()) do
local mat = value:GetComponent(typeof(UnityEngine.Renderer))
if mat.material.shader.name == "UI Particles/Additive" then
mat.material.shader = poolManager:LoadAsset("UI-Particle-Add_1", poolManager.AssetType.Other)
end
end
Util.SetParticleSortLayer(starGrid, this.sortingOrder + 1)
local cardBtn = Util.GetGameObject(go.transform, "icon")
local GongMingMask = Util.GetGameObject(go.transform, "GongMingMask")
GongMingMask:SetActive(false) --最后检测是否共鸣
Util.AddOnceClick(cardBtn, function()
if SelectHero then
SelectHero:SetActive(false)
end
TempData = heroData
SelectHero = choosed
selectIndex = index
SelectHero: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
PopupTipPanel.ShowTip(Language[10480])
return
end
end)
end
--界面关闭时调用(用于子类重写)
function RoleChooseListPanel:OnClose()
--destroy(SelectHero)
SelectHero = nil
end
--界面销毁时调用(用于子类重写)
function RoleChooseListPanel:OnDestroy()
this.spLoader:Destroy()
this.ScrollView = nil
end
return RoleChooseListPanel