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

241 lines
9.3 KiB
Lua
Raw Normal View History

2020-12-17 10:41:00 +08:00
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.BtnBack = Util.GetGameObject(self.transform, "btnBack")
this.BtnSure = Util.GetGameObject(self.transform, "btnSure")
2020-12-18 16:31:28 +08:00
this.BtnSure:SetActive(false)
2020-12-17 10:41:00 +08:00
this.btnAutoSelect = Util.GetGameObject(self.transform, "btnAutoSelect")
2020-12-18 16:31:28 +08:00
this.btnAutoSelect:SetActive(false)
2020-12-17 10:41:00 +08:00
this.cardPre = Util.GetGameObject(self.gameObject, "item")
2020-12-18 16:31:28 +08:00
this.btnYes = Util.GetGameObject(self.gameObject,"btnYes")
this.btnYes:SetActive(true)
2020-12-17 10:41:00 +08:00
--this.grid = Util.GetGameObject(self.gameObject, "scroll/grid")
2020-12-18 16:31:28 +08:00
this.title_text = Util.GetGameObject(self.gameObject,"bg/Text"):GetComponent("Text")
2020-12-17 10:41:00 +08:00
this.desText = Util.GetGameObject(self.gameObject, "desText"):GetComponent("Text")
this.numText = Util.GetGameObject(self.gameObject, "numText"):GetComponent("Text")
2020-12-18 16:31:28 +08:00
2020-12-17 10:41:00 +08:00
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(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
this:InitData()
end
function RoleChooseListPanel:InitData()
self.ScrollView:SetData(HarmonyManager.ChooseDataList,function (index, go)
this.OnShowSingleCardData(go, HarmonyManager.ChooseDataList[index],index)
end)
end
--绑定事件(用于子类重写)
function RoleChooseListPanel:BindEvent()
Util.AddClick(this.BtnBack, function()
PlaySoundWithoutClick(SoundConfig.Sound_UICancel)
self:ClosePanel()
end)
2020-12-18 16:31:28 +08:00
Util.AddClick(this.btnYes, function()
2020-12-17 10:41:00 +08:00
if TempData ==nil then
-- body
PopupTipPanel.ShowTip("请先选择一个英雄" )
return
end
HarmonyManager:SetChooseId(TempData.dynamicId)
2020-12-18 18:25:38 +08:00
HarmonyManager.SetOldPowerNum(TempData.dynamicId)
2020-12-17 10:41:00 +08:00
if self.flag then --判断是否是鸿蒙使者 如果是 那就不懈装备
-- body
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)
2021-01-08 17:29:54 +08:00
--UIManager.OpenPanel(UIName.GongMingResultPanel,self.flag)
2020-12-18 18:25:38 +08:00
HarmonyManager.WarPowerChangeNotify(TempData.dynamicId)
2020-12-17 10:41:00 +08:00
end)
else
HarmonyManager:SetGongMingList(TempData.dynamicId)
if HarmonyManager.equipCount == 24 then
2021-01-08 17:29:54 +08:00
LogGreen("脱装备")
2020-12-17 10:41:00 +08:00
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)
-- body
Game.GlobalEvent:DispatchEvent(GameEvent.HongMeng.ChooseData,TempData)
UIManager.OpenPanel(UIName.GongMingResultPanel,self.flag)
2020-12-18 18:25:38 +08:00
HarmonyManager.WarPowerChangeNotify(TempData.dynamicId)
2020-12-17 10:41:00 +08:00
end)
end
self:ClosePanel()
--
end)
Util.AddClick(this.btnAutoSelect, function()
-- self:AutoSelectHero()
end)
end
--添加事件监听(用于子类重写)
function RoleChooseListPanel:AddListener()
end
--移除事件监听(用于子类重写)
function RoleChooseListPanel:RemoveListener()
end
--界面打开时调用(用于子类重写)
function RoleChooseListPanel:OnOpen(flag)
2020-12-18 16:31:28 +08:00
this.desText.text = ""
this.numText.text = ""
this.title_text.text ="共鸣神将选择"
2020-12-17 10:41:00 +08:00
self.flag = flag
2020-12-25 15:33:12 +08:00
local list = HarmonyManager.ChooseDataList
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)
self.ScrollView:SetData(list,function (index, go)
2020-12-17 10:41:00 +08:00
2020-12-25 15:33:12 +08:00
this.OnShowSingleCardData(go, list[index],index)--
2020-12-17 10:41:00 +08:00
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 = Util.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 = Util.LoadSprite(heroData.icon)
Util.GetGameObject(go.transform, "posIcon"):SetActive(false)--:GetComponent("Image").sprite = Util.LoadSprite(heroData.professionIcon)
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)
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")
SetHeroStars(starGrid, heroData.star,1,nil,nil,Vector2.New(0,1))
local cardBtn = Util.GetGameObject(go.transform, "icon")
2020-12-18 16:37:56 +08:00
local GongMingMask = Util.GetGameObject(go.transform, "GongMingMask")
GongMingMask:SetActive(false)--最后检测是否共鸣
2020-12-17 10:41:00 +08:00
Util.AddOnceClick(cardBtn, function()
if choosed then
-- body
if choosed.activeSelf then
PopupTipPanel.ShowTip("已成为鸿蒙守卫 不可选")
return
end
end
if SelectHero then
--if SelectHero.activeSelf then
-- body
SelectHero:SetActive(false)
--end
2020-12-25 15:33:12 +08:00
--SelectHero = nil
2020-12-17 10:41:00 +08:00
end
TempData = heroData
SelectHero = choosed
selectIndex = index
SelectHero:SetActive(true)
2020-12-18 16:31:28 +08:00
--this.numText.text=string.format("%s/%s",LengthOfTable(curSelectHeroList),curNeedRoleNum)
2020-12-17 10:41:00 +08:00
end)
Util.AddOnceClick(formationMask, function()
if heroData.isFormation ~= "" then
PopupTipPanel.ShowTip( heroData.isFormation)
return
end
if heroData.lockState == 1 then
PopupTipPanel.ShowTip(Language[11776])
return
end
end)
end
function RoleChooseListPanel: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 RoleChooseListPanel:OnClose()
2020-12-25 15:33:12 +08:00
--destroy(SelectHero)
2020-12-17 10:41:00 +08:00
SelectHero = nil
end
--界面销毁时调用(用于子类重写)
function RoleChooseListPanel:OnDestroy()
this.ScrollView = nil
end
return RoleChooseListPanel