miduo_client/Assets/ManagedResources/~Lua/Modules/Compound/view/CompoundPanel_SoulPrint.lua

263 lines
12 KiB
Lua

----- 魂印合成 -----
local this = {}
local soulPrintDatas = {} --所有可合成数据
local materidaIsCan = false --合成是材料是否满足
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local equipSign = ConfigManager.GetConfig(ConfigName.EquipConfig)
local curSelectSoulPrint = {} --当前选择的合成魂印
local curSelectGO --当前选择的合成列表中对象
local needSoulPrint = {} --三个魂印消耗材料对象
local materialState = {} --材料数据
local openThisPanel
local needGold = {}
local allGo = {}
function this:InitComponent(gameObject)
this.spLoader = SpriteLoader.New()
allGo = {}
for i = 1, 3 do
needSoulPrint[i] = Util.GetGameObject(gameObject, "CompoundPanel_SoulPrint/titleGo/needEquip" .. i)
end
this.compoundSoulPrint = Util.GetGameObject(gameObject, "CompoundPanel_SoulPrint/titleGo/compoundEquip")
this.compoundSoulPrintBtn = Util.GetGameObject(gameObject, "CompoundPanel_SoulPrint/titleGo/compoundEquip/frame")
for i = 1, 2 do
needGold[i] = Util.GetGameObject(gameObject,
"CompoundPanel_SoulPrint/compoundBtn/GameObject/needGoldText (" .. i .. ")")
end
--this.needGoldText = Util.GetGameObject(gameObject, "CompoundPanel_SoulPrint/compoundBtn/needGoldText"):GetComponent("Text")
this.compoundBtn = Util.GetGameObject(gameObject, "CompoundPanel_SoulPrint/compoundBtn")
this.autoSelectBtn = Util.GetGameObject(gameObject, "CompoundPanel_SoulPrint/autoCompoundBtn")
this.equipPre = Util.GetGameObject(gameObject, "CompoundPanel_SoulPrint/equipPre")
this.ScrollBar = Util.GetGameObject(gameObject, "CompoundPanel_SoulPrint/Scrollbar"):GetComponent("Scrollbar")
local v2 = Util.GetGameObject(gameObject, "CompoundPanel_SoulPrint/scroll"):GetComponent("RectTransform").rect
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView,
Util.GetGameObject(gameObject, "CompoundPanel_SoulPrint/scroll").transform,
this.equipPre, this.ScrollBar, Vector2.New(-v2.x * 2, -v2.y * 2), 1, 5, Vector2.New(20, 20))
this.ScrollView.moveTween.MomentumAmount = 1
this.ScrollView.moveTween.Strength = 1
end
function this:BindEvent()
Util.AddClick(this.compoundBtn, function()
this.Compound()
end)
--
Util.AddClick(this.autoSelectBtn, function()
this.AutoSelectSoulPrint()
end)
for i = 1, 3 do
Util.AddClick(needSoulPrint[i], function()
--materialState[index] = {state = true,equipSignConFig = equipSign}
UIManager.OpenPanel(UIName.CompoundSelectListPopup, openThisPanel, materialState, i, curSelectSoulPrint)
end)
Util.AddLongPressClick(needSoulPrint[i], function()
if materialState[i].state then
UIManager.OpenPanel(UIName.SoulPrintPopUp, 0, nil, materialState[i].equipSignConFig.Id, nil, nil)
end
end, 0.5)
end
Util.AddClick(this.compoundSoulPrintBtn, function()
UIManager.OpenPanel(UIName.SoulPrintPopUp, 0, nil, curSelectSoulPrint.Id, nil, nil)
end)
end
function this:AddListener()
end
function this:RemoveListener()
end
local sortingOrder = 0
function this:OnSortingOrderChange(_sortingOrder)
sortingOrder = _sortingOrder
for i, v in pairs(allGo) do
Util.AddParticleSortLayer(v, _sortingOrder - sortingOrder)
end
end
function this:OnShow(_openThisPanel)
curSelectSoulPrint = {}
this.OnShowData()
this.StartCompoundSoulPrint(curSelectSoulPrint, true)
openThisPanel = _openThisPanel
end
function this.OnShowData()
local allDatas = ConfigManager.GetAllConfigsDataByDoubleKey(ConfigName.EquipConfig, "Position", 5, "Quality", 7)
soulPrintDatas = {}
for i = 1, #allDatas do
if allDatas[i].Formula then
table.insert(soulPrintDatas, allDatas[i])
end
end
curSelectSoulPrint = soulPrintDatas[1]
this.ScrollView:SetData(soulPrintDatas, function(index, go)
this.SingleItemDataShow(go, soulPrintDatas[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.ShowGoldNum(equipSign)
for i = 1, #needGold do
needGold[i]:SetActive(false)
end
for i = 1, #equipSign.Resource do
if needGold[i] then
needGold[i]:SetActive(true)
Util.GetGameObject(needGold[i], "Image"):GetComponent("Image").sprite = this.spLoader:LoadSprite(
GetResourcePath(ConfigManager.GetConfigData(ConfigName.ItemConfig, equipSign.Resource[i][1]).ResourceID))
if equipSign.Resource[1][2] > BagManager.GetItemCountById(equipSign.Resource[1][1]) then
materidaIsCan = false
needGold[i]:GetComponent("Text").text = PrintWanNum2(equipSign.Resource[i][2]) --string.format("<color=#FF0011>%s</color>", equipSign.Resource[i][2])
else
materidaIsCan = true
needGold[i]:GetComponent("Text").text = PrintWanNum2(equipSign.Resource[i][2]) --string.format("<color=#FCF5D3FF>%s</color>", equipSign.Resource[i][2])
end
end
end
end
function this.ShowTitleEquipData(_go, equipSign, index)
if not _go and index then _go = needSoulPrint[index] end
local ishaveData = false
if equipSign then ishaveData = true end
Util.GetGameObject(_go.transform, "frame"):SetActive(ishaveData)
--Util.GetGameObject(_go.transform,"icon"):SetActive(ishaveData)
Util.GetGameObject(_go.transform, "circleFrameBg"):SetActive(ishaveData)
Util.GetGameObject(_go.transform, "name"):SetActive(false)
if equipSign then
Util.GetGameObject(_go.transform, "frame"):GetComponent("Image").sprite = this.spLoader:LoadSprite(
GetQuantityImageByquality(equipSign.Quality))
Util.GetGameObject(_go.transform, "circleFrameBg/Icon"):GetComponent("Image").sprite = this.spLoader:LoadSprite(
GetResourcePath(itemConfig[equipSign.Id].ResourceID))
Util.GetGameObject(_go.transform, "circleFrameBg/circleFrame"):GetComponent("Image").sprite = this.spLoader
:LoadSprite(SoulPrintSpriteByQuantity[itemConfig[equipSign.Id].Quantity].circle)
Util.GetGameObject(_go.transform, "circleFrameBg"):GetComponent("Image").sprite = this.spLoader:LoadSprite(
SoulPrintSpriteByQuantity[itemConfig[equipSign.Id].Quantity].circleBg2)
Util.GetGameObject(_go.transform, "name"):GetComponent("Text").text = GetLanguageStrById(equipSign.Name)
if index then
materialState[index] = { state = true, equipSignConFig = equipSign }
end
else
if index then
Util.GetGameObject(_go.transform, "addImage"):SetActive(not ishaveData)
materialState[index] = { state = false, equipSignConFig = {} }
end
end
end
function this.SingleItemDataShow(_go, _curequipSign)
if not allGo[_go] then
allGo[_go] = _go
Util.AddParticleSortLayer(_go, sortingOrder)
end
local curequipSign = _curequipSign
Util.GetGameObject(_go.transform, "frame"):GetComponent("Image").sprite = this.spLoader:LoadSprite(
GetQuantityImageByquality(curequipSign.Quality))
--Util.GetGameObject(_go.transform,"icon"):GetComponent("Image").sprite=this.spLoader:LoadSprite(GetResourcePath(itemConfig[curequipSign.Id].ResourceID))
Util.GetGameObject(_go.transform, "circleFrameBg/Icon"):GetComponent("Image").sprite = this.spLoader:LoadSprite(
GetResourcePath(itemConfig[curequipSign.Id].ResourceID))
Util.GetGameObject(_go.transform, "circleFrameBg/circleFrame"):GetComponent("Image").sprite = this.spLoader
:LoadSprite(SoulPrintSpriteByQuantity[itemConfig[curequipSign.Id].Quantity].circle)
Util.GetGameObject(_go.transform, "circleFrameBg"):GetComponent("Image").sprite = this.spLoader:LoadSprite(
SoulPrintSpriteByQuantity[itemConfig[curequipSign.Id].Quantity].circleBg2)
Util.GetGameObject(_go.transform, "name"):GetComponent("Text").text = SubString2(
string.gsub(GetLanguageStrById(curequipSign.Name), Language[10452], ""), 6); --curequipSign.Name
Util.GetGameObject(_go.transform, "UI_effect_WuCai_Kuang"):SetActive(curequipSign.Quality == 7)
local choosed = Util.GetGameObject(_go.transform, "choosed")
choosed:SetActive(curSelectSoulPrint.Id == curequipSign.Id)
--local redPoint = Util.GetGameObject(_go.transform,"redPoint")
Util.GetGameObject(_go.transform, "redPoint"):SetActive(false)
if curSelectSoulPrint.Id == curequipSign.Id then
curSelectGO = _go
end
Util.AddOnceClick(Util.GetGameObject(_go.transform, "frame"), function()
if curSelectSoulPrint.Id == curequipSign.Id then
return
else
curSelectSoulPrint = curequipSign
choosed:SetActive(true)
if curSelectGO then
Util.GetGameObject(curSelectGO.transform, "choosed"):SetActive(false)
curSelectGO = _go
end
this.StartCompoundSoulPrint(curequipSign, false)
end
end)
end
function this.StartCompoundSoulPrint(curequipSign, isClearSelect)
this.ShowTitleEquipData(this.compoundSoulPrint, curequipSign)
this.ShowGoldNum(curequipSign)
if isClearSelect then
materialState = {}
for i = 1, 3 do
this.ShowTitleEquipData(needSoulPrint[i], nil, i)
end
end
end
function this.Compound()
--LogError(" `````````````````` "..curIndex.." "..curSelectEquip.Star.." "..compoundNum)
for i = 1, #materialState do
if materialState[i].state == false then
PopupTipPanel.ShowTip(Language[10461])
return
end
end
if not materidaIsCan then
UIManager.OpenPanel(UIName.QuickPurchasePanel, { type = UpViewRechargeType.Gold })
return
end
local matialSoulPrintids = {}
--LogError("curSelectSoulPrint.Id "..curSelectSoulPrint.Id)
for i = 1, #materialState do
table.insert(matialSoulPrintids, materialState[i].equipSignConFig.Id)
--LogError("materialState[i].equipSignConFig.Id "..i.." "..materialState[i].equipSignConFig.Id)
end
NetManager.ComplexSoulPrintRequest(curSelectSoulPrint.Id, matialSoulPrintids, function(msg)
-- SoundManager.PlaySound(SoundConfig.UI_Duanzao)
SoundManager.PlaySound(SoundConfig.UI_Baoqi)
--删除魂印
UIManager.OpenPanel(UIName.RewardItemPopup, msg.drop, 1, function()
this.StartCompoundSoulPrint(curSelectSoulPrint, true)
end)
end)
end
function this.AutoSelectSoulPrint()
this.StartCompoundSoulPrint(curSelectSoulPrint, true)
--local isShowUpHero = SoulPrintManager.GetIsShowUpHeroSoulPrintPlayerPrefs()
local datas = SoulPrintManager.GetAllSoulPrint(false, nil)
--LogError("datas "..#datas)
local curBagSoulPrintDatas = {}
for i = 1, #datas do
--LogError("datas[i].id "..datas[i].id)
--LogError("curSelectSoulPrint.Formula[1] "..curSelectSoulPrint.Formula[1][1])
if equipSign[datas[i].id].Quality == curSelectSoulPrint.Formula[1][1] then
table.insert(curBagSoulPrintDatas, datas[i])
end
end
--LogError("#curBagSoulPrintDatas "..#curBagSoulPrintDatas)
table.sort(curBagSoulPrintDatas, function(a, b) return equipSign[a.id].Quality < equipSign[b.id].Quality end)
for i = 1, 3 do
if curBagSoulPrintDatas[i] then
this.ShowTitleEquipData(needSoulPrint[i], equipSign[curBagSoulPrintDatas[i].id], i)
end
end
end
function this:OnClose()
end
function this:OnDestroy()
this.spLoader:Destroy()
allGo = {}
end
return this