187 lines
6.3 KiB
Lua
187 lines
6.3 KiB
Lua
----- 云游商人选择装备 -----
|
|
local this = {}
|
|
--传入父脚本模块
|
|
local parent
|
|
--传入特效层级
|
|
local sortingOrder=0
|
|
local func
|
|
local data
|
|
local ComposeBook = ConfigManager.GetConfig(ConfigName.ComposeBook)
|
|
|
|
function this:InitComponent(gameObject)
|
|
self.titleText=Util.GetGameObject(gameObject,"TitleText"):GetComponent("Text")
|
|
self.tip=Util.GetGameObject(gameObject,"tip"):GetComponent("Text")
|
|
self.scroll = Util.GetGameObject(gameObject, "Scroll")
|
|
self.confirm = Util.GetGameObject(gameObject, "ConfirmBtn")
|
|
self.cancel = Util.GetGameObject(gameObject, "CancelBtn")
|
|
self.itemPre = Util.GetGameObject(gameObject, "itemPre")
|
|
self.mask = Util.GetGameObject(gameObject, "itemPre/item")
|
|
|
|
-- 设置循环滚动,万一内容不停地加
|
|
local rootHight = self.scroll.transform.rect.height
|
|
local width = self.scroll.transform.rect.width
|
|
self.scrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.scroll.transform,
|
|
self.itemPre, nil, Vector2.New(width, rootHight), 1, 5, Vector2.New(0, 35))
|
|
self.scrollView.moveTween.MomentumAmount = 1
|
|
self.scrollView.moveTween.Strength = 2
|
|
self.equipList={}
|
|
self.itemList = {}
|
|
self.maskList = {}
|
|
self.maskImageList = {}
|
|
self.heroNameList = {}--所有装备对应的英雄明list
|
|
end
|
|
|
|
function this:BindEvent()
|
|
Util.AddClick(this.confirm,function()
|
|
if self.selectId == 0 then
|
|
data.otherData.selectId = 0
|
|
else
|
|
for _, configInfo in ConfigPairs(ConfigManager.GetConfig(ConfigName.ComposeBook)) do
|
|
if configInfo.NeedItems[1][1] == self.selectId and configInfo.Type == data.otherData.composeType then
|
|
data.otherData.selectId = configInfo.Id
|
|
break
|
|
end
|
|
end
|
|
end
|
|
parent:ClosePanel()
|
|
if func then
|
|
func()
|
|
end
|
|
end)
|
|
Util.AddClick(this.cancel,function()
|
|
parent:ClosePanel()
|
|
end)
|
|
end
|
|
|
|
function this:AddListener()
|
|
end
|
|
|
|
function this:RemoveListener()
|
|
end
|
|
|
|
function this:OnShow(_parent,...)
|
|
parent=_parent
|
|
sortingOrder = _parent.sortingOrder
|
|
--不定参中包含的不定参 _args[1]为面板类型 _args[2]之后(包括)为打开面板后传入的不定参
|
|
local _args = {...}
|
|
data = _args[1]
|
|
func = _args[2]
|
|
self.selectId = 0
|
|
if data.otherData.selectId > 0 then
|
|
self.selectId = ComposeBook[data.otherData.selectId].NeedItems[1][1]
|
|
end
|
|
|
|
local list = BagManager.GetBagItemDataByItemType(ItemBaseType.Equip)
|
|
local EquipedEquipList = HeroManager.GetEquipedEquipList()
|
|
for i = 1, #data.otherData.needItems do
|
|
for j = 1, #list do
|
|
if ComposeBook[data.otherData.needItems[i]].NeedItems[1][1] == tonumber(list[j].itemConfig.Id) then
|
|
local sdata = {}
|
|
sdata.Id = tonumber(list[j].itemConfig.Id)
|
|
sdata.Num = list[j].num
|
|
sdata.Equiped = false
|
|
table.insert(self.equipList,sdata)
|
|
end
|
|
end
|
|
end
|
|
for i = 1, #data.otherData.needItems do
|
|
for j = 1, #EquipedEquipList do
|
|
if ComposeBook[data.otherData.needItems[i]].NeedItems[1][1] == tonumber(EquipedEquipList[j]) then
|
|
local sdata = {}
|
|
sdata.Id = tonumber(EquipedEquipList[j])
|
|
sdata.Num = 1
|
|
sdata.Equiped = true
|
|
table.insert(self.equipList,sdata)
|
|
end
|
|
end
|
|
end
|
|
if #self.equipList == 0 then
|
|
PopupTipPanel.ShowTip("暂无可升级的装备!")
|
|
parent:ClosePanel()
|
|
end
|
|
this:Refresh(true,true)
|
|
end
|
|
function this:Refresh(isTop,isAni)
|
|
this.titleText.text = Language[12310]
|
|
|
|
if not self.itemList then
|
|
self.itemList = {}
|
|
end
|
|
for i = 1, #self.itemList do
|
|
self.itemList[i].gameObject:SetActive(false)
|
|
end
|
|
self.scrollView:SetData(self.equipList, function (index, item)
|
|
this:ShowSingleData(item, self.equipList[index],index)
|
|
end,not isTop,not isAni)
|
|
|
|
if #self.equipList ~= 0 then
|
|
this.tip.text = Language[12311]
|
|
self.tip.gameObject:GetComponent("RectTransform").localPosition = Vector3.New(0,232,0)
|
|
else
|
|
self.tip.text = Language[12312]
|
|
self.tip.gameObject:GetComponent("RectTransform").localPosition = Vector3.zero
|
|
end
|
|
end
|
|
|
|
function this:ShowSingleData(item,sdata,index)
|
|
local itemtrans = Util.GetGameObject(item,"item")
|
|
local itemmask = Util.GetGameObject(item,"mask")
|
|
local maskImage = Util.GetGameObject(item,"mask/Image")
|
|
local equiped = Util.GetGameObject(item,"equiped")
|
|
maskImage:SetActive(false)
|
|
equiped:SetActive(sdata.Equiped)
|
|
if not self.itemList[item] then
|
|
self.itemList[item] = SubUIManager.Open(SubUIConfig.ItemView,itemtrans.transform)
|
|
self.itemList[item].gameObject:SetActive(false)
|
|
end
|
|
|
|
self.itemList[item]:OnOpen(false, {sdata.Id,sdata.Num}, 1,true,false,false,sortingOrder)
|
|
self.itemList[item].gameObject:SetActive(true)
|
|
self.maskList[item] = itemmask
|
|
self.maskImageList[item] = maskImage
|
|
self.maskImageList[item]:SetActive(self.selectId == sdata.Id)
|
|
|
|
if not self.heroNameList[index] then
|
|
if sdata.Equiped then
|
|
local data = HeroManager.GetHeroIdListByEquipId(sdata.Id)
|
|
for i = 1, #data do
|
|
table.insert( self.heroNameList,data[i])
|
|
end
|
|
else
|
|
self.heroNameList[index] = nil
|
|
end
|
|
end
|
|
|
|
|
|
Util.AddOnceClick(self.maskList[item],function ()
|
|
for key, value in pairs(self.maskImageList) do
|
|
value:SetActive(false)
|
|
end
|
|
if self.selectId == sdata.Id then
|
|
self.maskImageList[item]:SetActive(false)
|
|
self.selectId = 0
|
|
else
|
|
self.maskImageList[item]:SetActive(true)
|
|
self.selectId = sdata.Id
|
|
end
|
|
end)
|
|
Util.AddOnceClick(equiped,function ()
|
|
MsgPanel.ShowTwo(string.format("<size=45><color=#00FF66>%s</color>穿戴该装备,是否前往卸下?</size>",self.heroNameList[index]),function() end,function()
|
|
JumpManager.GoJump(22001)
|
|
end,"取消","确定")
|
|
end)
|
|
end
|
|
|
|
function this:OnClose()
|
|
self.selectId = nil
|
|
self.equipList={}
|
|
self.maskList = {}
|
|
self.maskImageList = {}
|
|
self.heroNameList = {}
|
|
end
|
|
|
|
function this:OnDestroy()
|
|
self.itemList = {}
|
|
end
|
|
|
|
return this |