369 lines
16 KiB
Lua
369 lines
16 KiB
Lua
require("Base/BasePanel")
|
||
HomeLandEquipPopup = Inherit(BasePanel)
|
||
----- --家园装备升级 -----
|
||
local this = HomeLandEquipPopup
|
||
local HomeLand = ConfigManager.GetConfig(ConfigName.HomeLand)
|
||
local HomeLandLevel = ConfigManager.GetConfig(ConfigName.HomeLandLevel)
|
||
local HomeLandTask = ConfigManager.GetConfig(ConfigName.HomeLandTask)
|
||
local EquipStrengthen = ConfigManager.GetConfig(ConfigName.EquipStrengthen)
|
||
local EquipRankUp = ConfigManager.GetConfig(ConfigName.EquipRankUp)
|
||
local ItemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
||
--传入父脚本模块
|
||
local parent
|
||
--传入特效层级
|
||
local sortingOrder = 0
|
||
local data = nil
|
||
local TEXT = {
|
||
[1] = { Language[10456], "r_Equip_GuardianWeapon_0004", Language[10980] },
|
||
[2] = { Language[11583], "r_Equip_Coat_0005", Language[10982] },
|
||
[3] = { Language[10458], "r_Equip_HeadAccessory_0005", Language[10983] },
|
||
[4] = { Language[10459], "r_equip_Shoes_0005", Language[10981] },
|
||
}
|
||
local curSelectHero = 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 = Language[12132]
|
||
this.Btn1 = Util.GetGameObject(gameObject, "Btn1")
|
||
this.Btn1Text = Util.GetGameObject(gameObject, "Btn1/Text"):GetComponent("Text")
|
||
this.Btn2 = Util.GetGameObject(gameObject, "Btn2")
|
||
this.resetBtn = Util.GetGameObject(gameObject, "resetBtn")
|
||
this.costCondition = Util.GetGameObject(gameObject, "Cost/Condition"):GetComponent("Text")
|
||
this.costIcon = Util.GetGameObject(gameObject, "Cost/Icon"):GetComponent("Image")
|
||
this.costNum = Util.GetGameObject(gameObject, "Cost/Num"):GetComponent("Text")
|
||
this.costIcon2 = Util.GetGameObject(gameObject, "Cost/Icon2"):GetComponent("Image")
|
||
this.costNum2 = Util.GetGameObject(gameObject, "Cost/Num2"):GetComponent("Text")
|
||
this.Cost = Util.GetGameObject(gameObject, "Cost")
|
||
this.Tips = Util.GetGameObject(gameObject, "Tips")
|
||
|
||
this.objList = {}
|
||
for i = 1, 4 do
|
||
this.objList[i] = {}
|
||
this.objList[i].Obj = Util.GetGameObject(gameObject, "Content/Grid/Pre (" .. i .. ")")
|
||
this.objList[i].name = Util.GetGameObject(this.objList[i].Obj, "Name"):GetComponent("Text")
|
||
this.objList[i].level = Util.GetGameObject(this.objList[i].Obj, "Num"):GetComponent("Text")
|
||
this.objList[i].image = Util.GetGameObject(this.objList[i].Obj, "Icon"):GetComponent("Image")
|
||
this.objList[i].mask = Util.GetGameObject(this.objList[i].Obj, "Mask")
|
||
this.objList[i].select = Util.GetGameObject(this.objList[i].Obj, "Select")
|
||
end
|
||
|
||
this.Desc = Util.GetGameObject(gameObject, "Content/Desc"):GetComponent("Text")
|
||
|
||
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, 490), 1, 5, Vector2.New(20, 20))
|
||
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")
|
||
end
|
||
|
||
function this:BindEvent()
|
||
Util.AddClick(this.closeBtn, function()
|
||
self:ClosePanel()
|
||
end)
|
||
Util.AddClick(this.Btn1, function()
|
||
local curLv = not curSelectHero.equipStrong[HomeLandManager.curEquip] and
|
||
curSelectHero.equipStrong[HomeLandManager.curEquip] or 0
|
||
local data = ConfigManager.GetConfigDataByKey(ConfigName.EquipStrengthen, "Level", curLv)
|
||
if HomeLandManager.BuildData[data.Limit[1]].level < data.Limit[2] then
|
||
PopupTipPanel.ShowTip(string.format(Language[11582],
|
||
GetLanguageStrById(HomeLandManager.BuildData[data.Limit[1]].dataMain.Name),
|
||
data.Limit[2]))
|
||
return
|
||
end
|
||
|
||
for i = 1, #data.Cost do
|
||
if BagManager.GetTotalItemNum(data.Cost[i][1]) < data.Cost[i][2] then
|
||
--PopupTipPanel.ShowTip(string.format("%s不足!",ItemConfig[data.Cost[i][1]].Name))
|
||
PopupTipPanel.ShowTip(Language[10524])
|
||
return
|
||
end
|
||
end
|
||
NetManager.EquipIntensifyRequset(curSelectHero.dynamicId, HomeLandManager.curEquip, function()
|
||
this:Refresh()
|
||
end)
|
||
end)
|
||
Util.AddClick(this.Btn2, function()
|
||
if HomeLandManager.GetAllCanUpgradeWithPopup(curSelectHero) then
|
||
this:Refresh()
|
||
return
|
||
end
|
||
NetManager.EquipIntensifyRequset(curSelectHero.dynamicId, 0, function()
|
||
this:Refresh()
|
||
end)
|
||
end)
|
||
Util.AddClick(this.resetBtn, function()
|
||
NetManager.ResetHeroEquipRequest(curSelectHero.dynamicId, function()
|
||
this:Refresh()
|
||
end)
|
||
end)
|
||
end
|
||
|
||
function this:AddListener()
|
||
Game.GlobalEvent:AddEvent(GameEvent.Bag.BagGold, this.SetData)
|
||
end
|
||
|
||
function this:RemoveListener()
|
||
Game.GlobalEvent:RemoveEvent(GameEvent.Bag.BagGold, this.SetData)
|
||
end
|
||
|
||
function this:OnOpen()
|
||
local _roleDatas = HeroManager.GetAllHeroDatas()
|
||
this.SetHeroList(_roleDatas)
|
||
curSelectHero = _roleDatas[1]
|
||
this:Refresh()
|
||
end
|
||
|
||
function this:Refresh()
|
||
for i = 1, 4 do
|
||
local go = this.objList[i]
|
||
go.select:SetActive(i == HomeLandManager.curEquip)
|
||
go.name.text = TEXT[i][1] .. Language[12133]
|
||
go.level.text = curSelectHero.equipStrong[i] ~= nil and curSelectHero.equipStrong[i] or 0
|
||
go.image.sprite = this.spLoader:LoadSprite(TEXT[i][2])
|
||
Util.AddOnceClick(go.mask, function()
|
||
HomeLandManager.curEquip = i
|
||
this:Refresh()
|
||
end)
|
||
end
|
||
|
||
--显示加持属性
|
||
this:SetData()
|
||
end
|
||
|
||
function this:SetData()
|
||
-- LogPink(HomeLandManager.EquipData[HomeLandManager.curEquip].Id)
|
||
local curIndex = HomeLandManager.curEquip
|
||
local curLv = 0
|
||
if curSelectHero.equipStrong[curIndex] then
|
||
curLv = curSelectHero.equipStrong[curIndex]
|
||
end
|
||
local equipStrengthenConfig = ConfigManager.GetConfigDataByKey(ConfigName.EquipStrengthen, "Level", curLv)
|
||
local equipRankUpConfig = ConfigManager.GetConfigDataByKey(ConfigName.EquipRankUp, "Level",
|
||
curSelectHero.equipAdvanceLv)
|
||
--设置消耗
|
||
local limit = equipStrengthenConfig.Limit
|
||
local cost = equipStrengthenConfig.Cost
|
||
local data = equipStrengthenConfig.Rate --当前装备加成
|
||
local proData = equipRankUpConfig.Rate --当前装备突破加成
|
||
|
||
if cost then --如果有下一级
|
||
local nextEquipStrengthenConfig = ConfigManager.GetConfigDataByKey(ConfigName.EquipStrengthen, "Level", curLv + 1)
|
||
local nextData = nextEquipStrengthenConfig.Rate --下一装备加成
|
||
local nextProData = EquipRankUp[equipRankUpConfig.id + 1].Rate --下一装备突破加成
|
||
|
||
local num1 = data + proData[curIndex]
|
||
local num2 = 0
|
||
if not equipStrengthenConfig.Limit2 == equipRankUpConfig.Level then --如果都到达了等级上限
|
||
num2 = data + nextProData[curIndex]
|
||
else
|
||
num2 = nextData + proData[curIndex]
|
||
end
|
||
this.Desc.text = string.format(Language[12134], TEXT[curIndex][1], TEXT[curIndex][3], num1 / 100) ..
|
||
"%" .. string.format("<color=#1CC853>(%s", num2 / 100) .. "%)</color>"
|
||
|
||
this.Btn1Text.text = Language[12135]
|
||
Util.SetGray(this.Btn1, false)
|
||
this.Btn1:GetComponent("Button").enabled = true
|
||
|
||
if HomeLandManager.BuildData[limit[1]].level >= limit[2] then
|
||
this.costCondition.text = Language[12136]
|
||
this.costIcon.gameObject:SetActive(true)
|
||
this.costNum.gameObject:SetActive(true)
|
||
|
||
this.costIcon.sprite = this.spLoader:LoadSprite(GetSpriteNameByItemId(cost[1][1]))
|
||
local color2 = BagManager.GetTotalItemNum(cost[1][1]) >= cost[1][2] and "#FFEED6" or "red"
|
||
this.costNum.text = string.format("<color=%s>%s</color>", color2, cost[1][2])
|
||
LogError("cost len==" .. #cost)
|
||
if #cost > 1 then
|
||
this.costIcon2.gameObject:SetActive(true)
|
||
this.costNum2.gameObject:SetActive(true)
|
||
this.costIcon2.sprite = this.spLoader:LoadSprite(GetSpriteNameByItemId(cost[2][1]))
|
||
local color3 = BagManager.GetTotalItemNum(cost[2][1]) >= cost[2][2] and "#FFEED6" or "red"
|
||
this.costNum2.text = string.format("<color=%s>%s</color>", color3, cost[2][2])
|
||
else
|
||
this.costIcon2.gameObject:SetActive(false)
|
||
this.costNum2.gameObject:SetActive(false)
|
||
end
|
||
else
|
||
this.costIcon.gameObject:SetActive(false)
|
||
this.costNum.gameObject:SetActive(false)
|
||
this.costIcon2.gameObject:SetActive(false)
|
||
this.costNum2.gameObject:SetActive(false)
|
||
this.costCondition.text = string.format(Language[12137], HomeLand[limit[1]].Name, limit[2])
|
||
end
|
||
--按钮和tips显示
|
||
local bool = equipStrengthenConfig.Limit2 == equipRankUpConfig.Level
|
||
-- LogBlue("bool:"..tostring(bool))
|
||
this.Btn1:SetActive(bool)
|
||
this.Btn2:SetActive(not bool)
|
||
--不同显示
|
||
this.Cost:SetActive(bool)
|
||
this.Tips:SetActive(not bool)
|
||
this.costCondition.gameObject:SetActive(true)
|
||
this.Tips:GetComponent("Text").text = string.format(Language[12138], equipStrengthenConfig.Level)
|
||
if not bool and HomeLandManager.GetAllCanUpgrade(curSelectHero) then
|
||
this.Cost:SetActive(true)
|
||
this.Tips:SetActive(false)
|
||
this.costIcon.gameObject:SetActive(true)
|
||
this.costNum.gameObject:SetActive(true)
|
||
-- this.costCondition.gameObject:SetActive(false)
|
||
this.costCondition.text = Language[12139]
|
||
--突破的消耗和升级不同
|
||
local cost = equipRankUpConfig.Cost
|
||
local color2 = BagManager.GetTotalItemNum(cost[1][1]) >= cost[1][2] and "#FFEED6" or "red"
|
||
this.costIcon.sprite = this.spLoader:LoadSprite(GetSpriteNameByItemId(cost[1][1]))
|
||
this.costNum.text = string.format("<color=%s>%s</color>", color2, cost[1][2])
|
||
if cost[2] then
|
||
this.costIcon2.gameObject:SetActive(true)
|
||
this.costNum2.gameObject:SetActive(true)
|
||
this.costIcon2.sprite = this.spLoader:LoadSprite(GetSpriteNameByItemId(cost[2][1]))
|
||
local color3 = BagManager.GetTotalItemNum(cost[2][1]) >= cost[2][2] and "#FFEED6" or "red"
|
||
this.costNum2.text = string.format("<color=%s>%s</color>", color3, cost[2][2])
|
||
else
|
||
this.costIcon2.gameObject:SetActive(false)
|
||
this.costNum2.gameObject:SetActive(false)
|
||
end
|
||
end
|
||
else
|
||
this.Btn1:SetActive(true)
|
||
this.Btn2:SetActive(false)
|
||
this.Btn1Text.text = Language[10209]
|
||
Util.SetGray(this.Btn1, true)
|
||
this.Btn1:GetComponent("Button").enabled = false
|
||
local num1 = data + proData[curIndex]
|
||
this.Desc.text = string.format(Language[12134], TEXT[curIndex][1], TEXT[curIndex][3], num1) .. "%"
|
||
this.Cost:SetActive(false)
|
||
this.Tips:SetActive(false)
|
||
end
|
||
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
|
||
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")
|
||
local teamList = {}
|
||
for i = 1, 3 do
|
||
table.insert(teamList, Util.GetGameObject(go, "yxteamName/Image" .. i))
|
||
end
|
||
local yxInfo = Util.GetGameObject(go, "yxteamName")
|
||
--local yxTeamName=Util.GetGameObject(go, "yxteamName/Text"):GetComponent("Text")
|
||
yxInfo:SetActive(false)
|
||
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 yuanImage = Util.GetGameObject(go, "yuanImage")
|
||
yuanImage.gameObject:SetActive(false)
|
||
local choosedObj = Util.GetGameObject(go, "choosed")
|
||
choosedObj.gameObject:SetActive(false)
|
||
local hpExp = Util.GetGameObject(go, "hpExp")
|
||
hpExp.gameObject:SetActive(false)
|
||
local redPot = Util.GetGameObject(go, "redpoint")
|
||
local changeProBtn = Util.GetGameObject(go, "proMaskObj")
|
||
if heroData.isNew and heroData.isNew == 1 then
|
||
redPot.gameObject:SetActive(true)
|
||
else
|
||
redPot.gameObject:SetActive(false)
|
||
end
|
||
if _heroData.property then
|
||
changeProBtn:SetActive(_heroData.property >= 6)
|
||
pro.sprite = this.spLoader:LoadSprite(GetProStrImageByProNum(heroData.property))
|
||
else
|
||
changeProBtn:SetActive(false)
|
||
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)
|
||
|
||
Util.AddOnceClick(go, function()
|
||
curSelectHero = _heroData
|
||
this:Refresh()
|
||
this.SetHeroSelect(go)
|
||
end)
|
||
end
|
||
|
||
function this.SetHeroSelect(_heroObj)
|
||
this.heroSelect.transform:SetParent(_heroObj.transform)
|
||
this.heroSelect.transform.localPosition = Vector3.zero
|
||
end
|
||
|
||
function this:OnClose()
|
||
HomeLandManager.curEquip = 1
|
||
data = nil
|
||
end
|
||
|
||
function this:OnDestroy()
|
||
this.SelectList = {}
|
||
this.spLoader:Destroy()
|
||
this.scrollView = nil
|
||
end
|
||
|
||
return this
|