miduo_client/Assets/ManagedResources/~Lua/Modules/Popup/HeroReplacePopup.lua

221 lines
8.0 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

require("Base/BasePanel")
HeroReplacePopup = Inherit(BasePanel)
----- --家园装备升级 -----
local this = HeroReplacePopup
local data=nil
local gridIndex=1
local selectHero1=nil
local selectHero2=nil
local useItemId=0
local curSelectGridHero=nil
function this:InitComponent()
this.closeBtn=Util.GetGameObject(self.gameObject,"BG/BackBtn")
local gameObject=Util.GetGameObject(self.transform,"GeneralPopup_HomeLandEquip")
this.spLoader = SpriteLoader.New()
this.titleText=Util.GetGameObject(gameObject,"TitleText"):GetComponent("Text")
this.titleText.text="英雄置换卡"
this.replaceBtn = Util.GetGameObject(gameObject,"replaceBtn")
this.cancelBtn = Util.GetGameObject(gameObject,"cancelBtn")
this.heroPre = Util.GetGameObject(this.gameObject, "Scroll/HeroPre")
this.scroll = Util.GetGameObject(gameObject, "Scroll")
this.scrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView,this.scroll.transform,
this.heroPre, this.scrollBar, Vector2.New(1010, 530), 1, 5, Vector2.New(25, 25))
this.scrollView.gameObject:GetComponent("RectTransform").anchoredPosition = Vector2.New(0, 0)
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.gameObject:GetComponent("RectTransform").pivot = Vector2.New(0.5, 0.5)
this.scrollView.moveTween.MomentumAmount = 1
this.scrollView.moveTween.Strength = 2
this.heroSelect=Util.GetGameObject(this.scroll,"Select")
this.curGridBtn=Util.GetGameObject(gameObject,"Content/Grid/curGrid/Mask")
this.nextGridBtn=Util.GetGameObject(gameObject,"Content/Grid/nextGrid/Mask")
this.curGridHero=Util.GetGameObject(gameObject,"Content/Grid/curGrid/HeroObj")
this.nextGridHero=Util.GetGameObject(gameObject,"Content/Grid/nextGrid/HeroObj")
this.gridSelect=Util.GetGameObject(gameObject,"Content/Grid/Select")
end
function this:BindEvent()
Util.AddClick(this.closeBtn,function()
self:ClosePanel()
end)
Util.AddClick(this.replaceBtn,function()
if selectHero1==nil or selectHero2==nil then
PopupTipPanel.ShowTip("请选择置换英雄!")
return
end
if selectHero1==selectHero2 then
PopupTipPanel.ShowTip("请不要选择同一个英雄!")
return
end
NetManager.SendHeroChangeRequest(selectHero1,selectHero2,useItemId,function()
PopupTipPanel.ShowTip("置换成功!")
self:ClosePanel()
end)
end)
Util.AddClick(this.cancelBtn,function()
self:ClosePanel()
end)
Util.AddClick(this.curGridBtn,function()
gridIndex=1
curSelectGridHero=this.curGridHero
this.SetGridSelect(this.curGridBtn)
end)
Util.AddClick(this.nextGridBtn,function()
gridIndex=2
curSelectGridHero=this.nextGridHero
this.SetGridSelect(this.nextGridBtn)
end)
end
function this:OnOpen(_heroChangeId)
useItemId=_heroChangeId
local heroChangeConfig = ConfigManager.GetConfigData(ConfigName.HeroChange,useItemId)
local _roleDatas = HeroManager.GetAllHeroDatas()
local _showRoleDatas={}
for k,v in pairs(_roleDatas) do
if _showRoleDatas[v.heroConfig.Id]==nil then
_showRoleDatas[v.heroConfig.Id]={}
end
table.insert(_showRoleDatas[v.heroConfig.Id],v)
end
local dataList={}
for i = 1, #heroChangeConfig.HeroPool do
if _showRoleDatas[heroChangeConfig.HeroPool[i]] then
local _tdataArr=_showRoleDatas[heroChangeConfig.HeroPool[i]]
for i = 1, #_tdataArr do
table.insert(dataList,_tdataArr[i])
end
end
end
this.SetHeroList(dataList)
curSelectGridHero=this.curGridHero
this.SetGridSelect(this.curGridBtn)
gridIndex=1
this.curGridHero:SetActive(false)
this.nextGridHero:SetActive(false)
end
function this.SetGridSelect(_gridObj)
this.gridSelect.transform:SetParent(_gridObj.transform)
this.gridSelect.transform.localPosition=Vector3.zero
end
---设置显示英雄列表
function this.SetHeroList(_roleDatas)
HeroManager.SortHeroDatas(_roleDatas)
this.scrollView:SetData(_roleDatas, function(index, go)
-- if index==1 then
-- this.SetHeroSelect(go)
-- end
-- 基础显示
this.SingleHeroDataShow(go, _roleDatas[index])
end, true,false)
end
--英雄排序
function this:SortHeroDatas(_heroDatas)
--上阵最优先星级优先同星级等级优先同星级同等级按sortId排序。排序时降序排序。
table.sort(_heroDatas, 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)
end
--设置每条英雄数据
function this.SingleHeroDataShow(_go, _heroData)
local go=_go
local heroData=_heroData
this.SetHeroInfo(go, heroData)
Util.AddOnceClick(go, function()
if gridIndex==1 then
selectHero1=heroData.dynamicId
else
selectHero2=heroData.dynamicId
end
this.Refresh(heroData)
this.SetHeroSelect(go)
end)
end
function this.SetHeroInfo(_go, _heroData)
local go=_go
local heroData=_heroData
local frame=Util.GetGameObject(go,"frame"):GetComponent("Image")
local icon=Util.GetGameObject(go, "icon"):GetComponent("Image")
local lv= Util.GetGameObject(go, "lv/Text"):GetComponent("Text")
local pro= Util.GetGameObject(go, "proIcon"):GetComponent("Image")
local pos= Util.GetGameObject(go, "posIcon"):GetComponent("Image")
Util.GetGameObject(go, "posIcon"):SetActive(this.curFormationIndex == FormationTypeDef.FIGHT_LEVEL or this.curFormationIndex == FormationTypeDef.FIGHT_ASSISTANTLEVEL or
this.curFormationIndex == FormationTypeDef.FORMATION_QIJIESHILIAN)
local starGrid = Util.GetGameObject(go, "star")
local choosedObj = Util.GetGameObject(go, "choosed")
choosedObj.gameObject:SetActive(false)
if _heroData.property then
pro.sprite= this.spLoader:LoadSprite(GetProStrImageByProNum(heroData.property))
else
pro.sprite= this.spLoader:LoadSprite(GetProStrImageByProNum(heroData.heroConfig.PropertyName))
end
frame.sprite=this.spLoader:LoadSprite(GetHeroQuantityImageByquality(heroData.heroConfig.Quality,heroData.star))
icon.sprite=this.spLoader:LoadSprite(heroData.icon)
if HarmonyManager.IsChangeColor(heroData.dynamicId) then
-- body
lv.text="<color=#0f0>"..heroData.lv.."</color>"
elseif HarmonyManager:IsEnvoy(heroData.dynamicId) and HarmonyManager:HongMengTowerUpLimit() >= HarmonyManager.TowerStartLimit then
-- bod
lv.text="<color=#ffbe22>"..heroData.lv.."</color>"
else
lv.text=heroData.lv
end
pos.sprite = this.spLoader:LoadSprite(heroData.professionIcon)
local star,starType = heroData.GetStar(1)
local starSize = Vector2.New(30,30)
local starScale = -8
if starType == 3 then
starSize = Vector2.New(1,-15.65)
starScale = -13
elseif starType == 2 then
starSize = Vector2.New(60,57)
end
SetHeroStars(this.spLoader, starGrid, star,starType,starSize,starScale)
end
function this.Refresh(_heroData)
this.SetHeroInfo(curSelectGridHero, _heroData)
curSelectGridHero:SetActive(true)
end
function this.SetHeroSelect(_heroObj)
this.heroSelect.transform:SetParent(_heroObj.transform)
this.heroSelect.transform.localPosition=Vector3.zero
end
function this:OnClose()
data=nil
selectHero1=nil
selectHero2=nil
end
function this:OnDestroy()
this.SelectList = {}
this.spLoader:Destroy()
this.scrollView = nil
end
return this