miduo_client/Assets/ManagedResources/~Lua/Modules/CompoundHero/view/CompoundHero_Replace.lua

471 lines
18 KiB
Lua

----- 神将置换 -----
local this = {}
local sortingOrder=0
local tabs={}
local curIndex = 0
local curSelectHero = {}
local curSelectHeroConfig = {}
local heroSelectBtn = {}
local heroDatas
local t
local replaceItemIdConfig = ConfigManager.GetConfigData(ConfigName.SpecialConfig,68)
local replaceCostConfig = ConfigManager.GetConfigData(ConfigName.SpecialConfig,69)
local HeroConfig = ConfigManager.GetConfig(ConfigName.HeroConfig)
function this:InitComponent(gameObject)
this.spLoader = SpriteLoader.New()
this.gameObject = gameObject
this.heroPre = Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/item")
this.replaceBtn = Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/btns/replaceBtn")
this.saveBtn = Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/btns/saveBtn")
this.cancelBtn = Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/btns/cancelBtn")
for i = 1, 6 do
tabs[i] = Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/Tabs/Grid/Btn" .. i)
end
this.selectBtn=Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/Tabs/SelectBtn")
this.selectBtn:SetActive(true)
this.ScrollBar=Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/Scrollbar"):GetComponent("Scrollbar")
local v2 = Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/scroll"):GetComponent("RectTransform").rect
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/scroll").transform,
this.heroPre, this.ScrollBar, Vector2.New(-v2.x*2, -v2.y*2), 1, 5, Vector2.New(35,15))
this.ScrollView.moveTween.MomentumAmount = 1
this.ScrollView.moveTween.Strength = 1
--need -> replaceHero Info
this.needHero = Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/heros/needHero")
this.replaceHero = Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/heros/replacedHero")
this.needBg = Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/bg/heroPlace1")
this.replaceBg = Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/bg/heroPlace2")
this.text = Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/heros/content/Text")
this.cost = Util.GetGameObject(gameObject, "CompoundHeroPanel_Replace/heros/content/cost")
this.costImage = Util.GetGameObject(this.cost, "Image"):GetComponent("Image")
this.costText = Util.GetGameObject(this.cost,"Text"):GetComponent("Text")
end
function this:BindEvent()
--置换
Util.AddClick(this.replaceBtn,function()
if not curSelectHero.id then
PopupTipPanel.ShowTip(Language[10417])
elseif curSelectHero.id and (t>BagManager.GetTotalItemNum(tonumber(replaceItemIdConfig.Value))) then
PopupTipPanel.ShowTip(Language[10418])
else
NetManager.SaveHeroChangeRequest(curSelectHero.dynamicId,function (msg)
HeroManager.ResetHeroChangeId(curSelectHero.dynamicId,msg.heroTempId)--改变英雄changeId
this.replaceHero:SetActive(true)
this.cancelBtn:SetActive(true)
this.replaceBtn:SetActive(false)
this.saveBtn:SetActive(true)
this.needBg:SetActive(false)
this.replaceBg:SetActive(false)
this.text:SetActive(false)
this.cost:SetActive(false)
this.ShowCostInfo()
local value = this.RebuildData(msg.heroTempId,curSelectHero)
this.SetHero(this.replaceHero,value)
end)
end
end)
--取消
Util.AddClick(this.cancelBtn,function()
NetManager.CancelHeroChangeRequest(curSelectHero.dynamicId,function (msg)
HeroManager.ResetHeroChangeId(curSelectHero.dynamicId)--改变英雄changeId
this.replaceHero:SetActive(false)
this.needHero:SetActive(true)
this.cancelBtn:SetActive(false)
this.replaceBtn:SetActive(true)
this.saveBtn:SetActive(false)
this.needBg:SetActive(false)
this.replaceBg:SetActive(true)
this.text:SetActive(false)
this.cost:SetActive(true)
this.ShowCostInfo()
end)
end)
--保存置换
Util.AddClick(this.saveBtn,function()
NetManager.DoHeroChangeRequest(curSelectHero.dynamicId,function (msg)
this.replaceHero:SetActive(false)
this.needHero:SetActive(false)
this.needBg:SetActive(true)
this.replaceBg:SetActive(true)
this.text:SetActive(true)
this.cost:SetActive(false)
this.ShowCostInfo()
HeroManager.DeleteHeroDatas({curSelectHero.dynamicId})
for i = 1, #msg.drop.Hero do
HeroManager.UpdateHeroDatas(msg.drop.Hero[i])
ExpeditionManager.InitHeroHpValue(msg.drop.Hero[i].id)
end
CheckRedPointStatus(RedPointType.Huaxutan_CompoundHero)
curSelectHero = HeroManager.GetSingleHeroData(msg.drop.Hero[1].id)
this.ShowCurrPosHeroReplace(curIndex)
end)
end)
end
--通过Id 重新组成数据
function this.RebuildData(id,curHero)
local herodata = {}
herodata.id = HeroConfig[id].Id
herodata.name = GetLanguageStrById(HeroConfig[id].ReadingName)
herodata.live = GetResourcePath(HeroConfig[id].Painting)
herodata.star = HeroConfig[id].Star
herodata.lv = curHero.lv
herodata.quality = HeroConfig[id].Quality
herodata.profession = HeroConfig[id].Profession
herodata.scale = HeroConfig[id].Scale
herodata.position = HeroConfig[id].Position
herodata.property = HeroConfig[id].PropertyName
return herodata
end
function this:AddListener()
end
function this:RemoveListener()
end
function this:OnSortingOrderChange(_sortingOrder)
sortingOrder = _sortingOrder
end
function this:OnShow(...)
curIndex = 0
sortingOrder =0
for i = 0,#tabs - 1 do
local index=i
Util.GetGameObject(tabs[i + 1], "Image"):GetComponent("Image").sprite=this.spLoader:LoadSprite(GetProStrImageByProNum(index))
Util.GetGameObject(tabs[i + 1], "Image/Text"):GetComponent("Text").text=PropertyType[index]
Util.AddOnceClick(tabs[i + 1], function()
curSelectHero = {}
if index == curIndex then
curIndex=0
this.HeroReplaceBtnClick(tabs[1],curIndex)
else
this.HeroReplaceBtnClick(tabs[i + 1],index)
end
end)
end
this.HeroReplaceBtnClick(tabs[1],curIndex)
end
--英雄类型按钮点击事件
function this.HeroReplaceBtnClick(_btn,_curIndex)
curIndex = _curIndex
this.needBg:SetActive(true)
this.replaceBg:SetActive(true)
this.SetBtnSelect(_btn)
this.ShowCurrPosHeroReplace(_curIndex)
end
--显示当前阵营的英雄
function this.ShowCurrPosHeroReplace(_curIndex)
this.replaceHero:SetActive(false)
this.needHero:SetActive(false)
heroDatas = this.GetHeroDataByPosition(_curIndex)
this.ScrollView:SetData(heroDatas, function (index, go)
-- heroSelectBtn[index] = Util.GetGameObject(go.transform, "choosed")
-- if not heroSelectBtn[heroDatas[index].dynamicId] then
-- heroSelectBtn[heroDatas[index].dynamicId] = Util.GetGameObject(go.transform, "choosed")
-- end
this.SingleHeroDataShow(go, heroDatas[index])
end)
-- this.ScrollView:ForeachItemGO(function(index, go)
-- Timer.New(function()
-- go.gameObject:SetActive(true)
-- PlayUIAnim(go.gameObject)
-- end, 0.001 * (index - 1)):Start()
-- end)
end
--通过职业筛选英雄
function this.GetHeroDataByPosition(_position)
local heros = {}
local index = 1
for i, v in pairs(HeroManager.ByReplaceHeroGetAllHeros()) do
--这里不显示神系的武将
if v.heroConfig.PropertyName == _position or (_position ==0 and v.heroConfig.PropertyName~=5 ) then --0 全职业
heros[index] = v
index = index + 1
end
end
return heros
end
local oldChoose
--数据显示
function this.SingleHeroDataShow(_go,_heroData)
local go = _go
local heroData = _heroData
Util.GetGameObject(go.transform, "frame"):GetComponent("Image").sprite = this.spLoader:LoadSprite(GetHeroQuantityImageByquality(HeroConfig[heroData.id].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)
Util.GetGameObject(go.transform, "proIcon"):GetComponent("Image").sprite = this.spLoader:LoadSprite(GetProStrImageByProNum(heroData.changeProId))
Util.GetGameObject(go.transform, "Text"):GetComponent("Text").text = SubString2(GetLanguageStrById(heroData.name),8 )
local formationMask = Util.GetGameObject(go.transform, "formationMask")
local formationImage = Util.GetGameObject(go.transform, "formationMask/formationImage/upImage"):GetComponent("Image")
if LengthOfTable(heroData.formationList) ~= 0 then
--if LengthOfTable(heroData.formationList) ~= 0 then
formationMask:SetActive(true)
formationImage.sprite = this.spLoader:LoadSprite("t_tongyong-yishangzheng_zh")
elseif heroData.lockState == 1 then
formationMask:SetActive(true)
formationImage.sprite = this.spLoader:LoadSprite("r_hero_suodi_yisuoding_zh")
else
formationMask:SetActive(false)
end
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 cardBtn = Util.GetGameObject(go.transform, "icon")
local choosed = Util.GetGameObject(go.transform, "choosed")
local GongMingMask = Util.GetGameObject(go.transform, "GongMingMask")
GongMingMask:SetActive(false)--最后检测是否共鸣
if heroData.lockState == 1 or LengthOfTable(heroData.formationList) ~= 0 then
else
if HarmonyManager.IsChangeColor(heroData.dynamicId) then
Util.GetGameObject(go.transform, "lv/Text"):GetComponent("Text").text = "<color=#0f0>"..heroData.lv.."</color>"
GongMingMask:SetActive(true)
elseif HarmonyManager:IsEnvoy(heroData.dynamicId) and HarmonyManager:HongMengTowerUpLimit() ~= 0 then
Util.GetGameObject(go.transform, "lv/Text"):GetComponent("Text").text = "<color=#ffbe22>"..heroData.lv.."</color>"
GongMingMask:SetActive(true)
end
end
choosed:SetActive(false)
if curSelectHero.dynamicId == heroData.dynamicId then
choosed:SetActive(true)
oldChoose = choosed
end
this.replaceBtn:SetActive(true)
this.cancelBtn:SetActive(false)
this.saveBtn:SetActive(false)
this.needBg:SetActive(true)
this.replaceBg:SetActive(true)
this.text:SetActive(true)
this.cost:SetActive(false)
if curSelectHero.id then
this.SetHero(this.needHero,curSelectHero)
this.ShowCostInfo()
this.needHero:SetActive(true)
this.replaceHero:SetActive(false)
this.needBg:SetActive(false)
this.replaceBg:SetActive(true)
this.text:SetActive(false)
this.cost:SetActive(true)
end
Util.AddOnceClick(GongMingMask, function()
PopupTipPanel.ShowTip(Language[12184])
end)
Util.AddOnceClick(cardBtn, function()
if heroData.dynamicId == curSelectHero.dynamicId then
choosed:SetActive(false)
oldChoose = nil
curSelectHero = {}
this.needHero:SetActive(false)
this.replaceHero:SetActive(false)
this.cancelBtn:SetActive(false)
this.saveBtn:SetActive(false)
this.replaceBtn:SetActive(true)
this.needBg:SetActive(true)
this.replaceBg:SetActive(true)
this.text:SetActive(true)
this.cost:SetActive(false)
else
choosed:SetActive(true)
if oldChoose then
oldChoose:SetActive(false)
end
oldChoose = choosed
curSelectHero = heroData
this.ShowCostInfo()
this.needHero:SetActive(true)
this.replaceHero:SetActive(false)
this.needBg:SetActive(false)
this.replaceBg:SetActive(true)
this.text:SetActive(false)
this.cost:SetActive(true)
this.SetHero(this.needHero,curSelectHero)
--如果已经有了置换Id
if curSelectHero.changeId ~=0 then
this.cancelBtn:SetActive(true)
this.replaceBtn:SetActive(false)
this.saveBtn:SetActive(true)
this.replaceHero:SetActive(true)
this.needBg:SetActive(false)
this.replaceBg:SetActive(false)
this.text:SetActive(false)
this.cost:SetActive(false)
local data = this.RebuildData(curSelectHero.changeId,curSelectHero)
this.SetHero(this.replaceHero,data)
else
this.cancelBtn:SetActive(false)
this.replaceBtn:SetActive(true)
this.saveBtn:SetActive(false)
this.replaceHero:SetActive(false)
this.needBg:SetActive(false)
this.replaceBg:SetActive(true)
this.text:SetActive(false)
this.cost:SetActive(true)
end
end
-- for i = 1, #heroDatas do
-- if heroSelectBtn[i] and heroDatas[i] then
-- heroSelectBtn[i]:SetActive(heroDatas[i].dynamicId == curSelectHero.dynamicId)
-- end
-- end
end)
Util.AddOnceClick(formationMask, function()
local text = ""
for n, w in pairs(FormationManager.formationList) do
for m = 1, #w.teamHeroInfos do
if heroData.dynamicId == w.teamHeroInfos[m].heroId then
local isFormationStr = HeroManager.GetHeroFormationStr2(n)
if isFormationStr ~= "" then
if not text or text == "" then
text = isFormationStr
else
text = text .. ""..isFormationStr
end
end
end
end
end
if text ~= "" then
text = Language[10411]..text..Language[10412]
PopupTipPanel.ShowTip(text)
return
end
if heroData.lockState == 1 then
PopupTipPanel.ShowTip(Language[10419])
return
end
end)
Util.AddLongPressClick(cardBtn, function()
UIManager.OpenPanel(UIName.RoleInfoPopup, heroData)
end, 0.5)
end
--刷新中间按钮和显示
function this.refresh()
-- body
end
--设置两个英雄,左右不确定
function this.SetHero(go,heroData)
local hero = Util.GetGameObject(go, "Hero1")
local herobg=Util.GetGameObject(hero,"Bg1"):GetComponent("Image")
local herolv=Util.GetGameObject(hero,"lv/Text"):GetComponent("Text")
local herofg=Util.GetGameObject(hero,"Bg2"):GetComponent("Image")
local heropro=Util.GetGameObject(hero,"Pro/Image"):GetComponent("Image")
local herostarGrid=Util.GetGameObject(hero,"StarGrid")
local heroname=Util.GetGameObject(hero,"Name/Text"):GetComponent("Text")
local heroyuanImage=Util.GetGameObject(hero,"yuanImage")
local herolive = Util.GetGameObject(hero, "Mask/icon"):GetComponent("RawImage")
local herozs = Util.GetGameObject(hero, "zs")
Util.GetGameObject(hero,"hpProgress").gameObject:SetActive(false)
Util.GetGameObject(hero,"rageProgress").gameObject:SetActive(false)
Util.GetGameObject(hero,"UI_Effect_jinkuang_KaPai").gameObject:SetActive(false)
-- herobg.sprite = this.spLoader:LoadSprite(GetHeroCardStarBg[heroData.star])
local roleConfig = ConfigManager.GetConfigData(ConfigName.RoleConfig, heroData.id)
local scale = roleConfig.play_liveScale
local livePos = Vector3.New(roleConfig.offset[1], roleConfig.offset[2], 0)
if go == this.needHero then
herolive.texture = CardRendererManager.GetSpineTexture(1, heroData.painting, Vector3.one * scale, livePos, true)
else
herolive.texture = CardRendererManager.GetSpineTexture(2, heroData.painting, Vector3.one * scale, livePos, true)
end
herolive.transform.localScale = Vector3.one
herolive.transform.localPosition = Vector3.zero
local zsName = GetHeroCardStarZs[heroData.star]
if zsName == "" then
herozs:SetActive(false)
else
herozs:SetActive(true)
herozs:GetComponent("Image").sprite = this.spLoader:LoadSprite(zsName)
end
heroyuanImage:SetActive(false)
herolv.text=heroData.lv
herofg.sprite = this.spLoader:LoadSprite(GetHeroCardStarFg[heroData.star])
heropro.sprite=this.spLoader:LoadSprite(GetProStrImageByProNum(heroData.property))
SetCardStars(herostarGrid,heroData.star)
if heroData.star > 9 then
Util.GetGameObject(go,"UI_Effect_jinkuang_KaPai").gameObject:SetActive(true)
else
Util.GetGameObject(go,"UI_Effect_jinkuang_KaPai").gameObject:SetActive(false)
end
heroname.text=heroData.name
end
--设置阵营按钮选中
function this.SetBtnSelect(_parObj)
this.selectBtn.transform:SetParent(_parObj.transform)
this.selectBtn.transform:SetAsFirstSibling()
this.selectBtn.transform.localScale = Vector3.one
this.selectBtn.transform.localPosition=Vector3.zero
end
function this.ShowCostInfo()
if replaceItemIdConfig then
this.costImage:GetComponent("Image").sprite = SetIcon(this.spLoader, tonumber(replaceItemIdConfig.Value))
end
if curSelectHero and replaceCostConfig then
local getCostByStar = string.split(replaceCostConfig.Value,"|")
if curSelectHero.star == 4 then
t = tonumber(string.split(getCostByStar[1],"#")[2])
elseif curSelectHero.star == 5 then
t = tonumber(string.split(getCostByStar[2],"#")[2])
end
this.costText.text = t
if t>BagManager.GetTotalItemNum(tonumber(replaceItemIdConfig.Value)) then
this.costText.text = "<color=red>"..t.."</color>"
end
end
end
function this:OnClose()
curSelectHero = {}
curSelectHeroConfig = {}
this.replaceHero:SetActive(false)
this.needHero:SetActive(false)
oldChoose = nil
end
function this:OnDestroy()
this.spLoader:Destroy()
end
return this