179 lines
6.0 KiB
Lua
179 lines
6.0 KiB
Lua
----- 命格选择命石 -----
|
|
local GemCompound = {}
|
|
--传入父脚本模块
|
|
local parent
|
|
--传入特效层级
|
|
local sortingOrder=0
|
|
local args=nil
|
|
local itemConfig=ConfigManager.GetConfig(ConfigName.ItemConfig)
|
|
local gemConfig=ConfigManager.GetConfig(ConfigName.GemConfig)
|
|
local PropertyConfig = ConfigManager.GetConfig(ConfigName.PropertyConfig)
|
|
function GemCompound:InitComponent(gameObject)
|
|
self.spLoader = SpriteLoader.New()
|
|
|
|
self.curGem = Util.GetGameObject(gameObject,"Gems/curGem")
|
|
self.targetGem = Util.GetGameObject(gameObject,"Gems/targetGem")
|
|
|
|
self.proGrid = Util.GetGameObject(gameObject,"Property")
|
|
self.proPre = Util.GetGameObject(self.proGrid,"propertyPre")
|
|
self.proPre:SetActive(false)
|
|
--滚动条根节点
|
|
self.root = Util.GetGameObject(gameObject, "Cost/Scroll")
|
|
self.itemPre = Util.GetGameObject(self.root,"itemPre")
|
|
|
|
self.money = Util.GetGameObject(gameObject, "Money/Text"):GetComponent("Text")
|
|
|
|
self.btnFast = Util.GetGameObject(gameObject, "BtnFast")
|
|
self.gou = Util.GetGameObject(self.btnFast, "Go")
|
|
self.BtnDo = Util.GetGameObject(gameObject, "BtnDo")
|
|
|
|
self.proList={}
|
|
self.itemList={}
|
|
|
|
local rootHight = self.root.transform.rect.height
|
|
local width = self.root.transform.rect.width
|
|
self.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.root.transform,
|
|
self.itemPre,nil, Vector2.New(width, rootHight), 1, 5,Vector2.New(0,20))
|
|
self.ScrollView.moveTween.MomentumAmount = 1
|
|
self.ScrollView.moveTween.Strength = 2
|
|
self.ScrollView.elastic = false
|
|
|
|
end
|
|
|
|
function GemCompound:BindEvent()
|
|
Util.AddOnceClick(self.btnFast,function ()
|
|
self.selectFast = not self.selectFast
|
|
self:SetCost(self.selectFast)
|
|
end)
|
|
end
|
|
|
|
function GemCompound:AddListener()
|
|
end
|
|
|
|
function GemCompound:RemoveListener()
|
|
end
|
|
|
|
function GemCompound:OnShow(_parent,_args)
|
|
args = _args
|
|
parent=_parent
|
|
sortingOrder =_parent.sortingOrder
|
|
self.selectFast = false
|
|
GemCompound:Refresh(args[1])
|
|
end
|
|
function GemCompound:Refresh(Id)
|
|
--设置当前和目标命石
|
|
if not self.curGemObj then
|
|
self.curGemObj = SubUIManager.Open(SubUIConfig.ItemView,self.curGem.transform)
|
|
self.targetGemObj = SubUIManager.Open(SubUIConfig.ItemView,self.targetGem.transform)
|
|
end
|
|
self.curGemObj:OnOpen(false, {Id,0}, 1.1, false,false,false,sortingOrder + 1)
|
|
self.targetGemObj:OnOpen(false, {Id + 1,0}, 1.1, false,false,false,sortingOrder + 1)
|
|
Util.GetGameObject(self.curGem,"Name"):GetComponent("Text").text = gemConfig[Id].Name
|
|
Util.GetGameObject(self.targetGem,"Name"):GetComponent("Text").text = gemConfig[Id+1].Name
|
|
--设置属性
|
|
local data1,data2 = gemConfig[Id].Property,gemConfig[Id+1].Property
|
|
for index, value in ipairs(self.proList) do
|
|
value:SetActive(false)
|
|
end
|
|
for i = 1, #data1 do
|
|
local go = self.proList[i]
|
|
if not go then
|
|
go = newObjToParent(self.proPre,self.proGrid.transform)
|
|
self.proList[i] = go
|
|
end
|
|
go:SetActive(true)
|
|
local proText = Util.GetGameObject(go,"proText"):GetComponent("Text")
|
|
local nextProText = Util.GetGameObject(go,"nextProText"):GetComponent("Text")
|
|
local upProText = Util.GetGameObject(go,"upProText"):GetComponent("Text")
|
|
proText.text = string.format("全体%s+%s",PropertyConfig[data1[i][1]].Info,data1[i][2]/100).."%"
|
|
nextProText.text = string.format("%s",data2[i][2]/100).."%"
|
|
upProText.text = string.format("%s",(data2[i][2]-data1[i][2])/100).."%"
|
|
end
|
|
--设置消耗
|
|
self:SetCost(self.selectFast)
|
|
end
|
|
|
|
function GemCompound:SetCost(bool)
|
|
self.gou:SetActive(self.selectFast)
|
|
local bool1,bool2,money = nil
|
|
local list = {}
|
|
local list2 = {}
|
|
if not bool then--普通合成
|
|
bool1 = BagManager.GetTotalItemNum(14) > gemConfig[args[1]].UpgradeCost[2]
|
|
local tempnum = args[2] and 0 or 1
|
|
bool2 = BagManager.GetTotalItemNum(args[1]) > tempnum
|
|
list[args[1]] = 1
|
|
money = gemConfig[args[1]].UpgradeCost[2]
|
|
else--快速合成
|
|
bool2,list,money,bool1 = GemManager.FastConpound(args[1])
|
|
end
|
|
if not bool2 then
|
|
list[args[1]] = 0
|
|
end
|
|
for key, value in pairs(list) do
|
|
-- LogGreen("id:"..tostring(key).." num:"..tostring(value))
|
|
local data = {}
|
|
data.id = key
|
|
data.num = value
|
|
table.insert(list2,data)
|
|
end
|
|
table.sort(list2,function (a,b)
|
|
return a.id < b.id
|
|
end)
|
|
|
|
local color = bool1 and "#FBF7F1" or "red"
|
|
self.money.text = string.format("<color=%s>%s</color>",color,money)
|
|
|
|
self.ScrollView:SetData(list2, function(index, go)
|
|
self:SingleDataShow(go,list2[index],index,bool2)
|
|
end)
|
|
|
|
|
|
Util.AddOnceClick(self.BtnDo,function ()
|
|
if not bool2 then
|
|
PopupTipPanel.ShowTip("合成材料不足!")
|
|
return
|
|
end
|
|
if not bool1 then
|
|
PopupTipPanel.ShowTip("金币不足!")
|
|
return
|
|
end
|
|
local type = self.selectFast and 4 or 3
|
|
NetManager.LifeStoneUpRequest(type,gemConfig[args[1]].Type,args[2],args[1],1,function ()
|
|
Game.GlobalEvent:DispatchEvent(GameEvent.Gem.RefreshPanel)
|
|
PopupTipPanel.ShowTip("命石升级成功!")
|
|
if args[3] then
|
|
args[3]()
|
|
end
|
|
parent:ClosePanel()
|
|
end)
|
|
end)
|
|
end
|
|
|
|
function GemCompound:SingleDataShow(go,data,index,bool)
|
|
-- LogPink("data:"..tostring(data.id))
|
|
local item = self.itemList[go]
|
|
local Obj = Util.GetGameObject(go,"Obj")
|
|
local num = Util.GetGameObject(go,"num")
|
|
num:SetActive(not bool)
|
|
if not item then
|
|
item = SubUIManager.Open(SubUIConfig.ItemView,Obj.transform)
|
|
self.itemList[go] = item
|
|
end
|
|
item:OnOpen(false, {data.id,data.num}, 1, false,false,false,sortingOrder + 1)
|
|
item.gameObject:SetActive(true)
|
|
end
|
|
|
|
function GemCompound:OnClose()
|
|
args=nil
|
|
end
|
|
|
|
function GemCompound:OnDestroy()
|
|
self.spLoader:Destroy()
|
|
self.itemList={}
|
|
self.proList={}
|
|
self.curGemObj = nil
|
|
self.targetGemObj = nil
|
|
end
|
|
|
|
return GemCompound |