155 lines
5.0 KiB
Lua
155 lines
5.0 KiB
Lua
----- 云游商人选择装备 -----
|
|
local this = {}
|
|
--传入父脚本模块
|
|
local parent
|
|
--传入特效层级
|
|
local sortingOrder=0
|
|
local func
|
|
local data
|
|
|
|
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 = {}
|
|
end
|
|
|
|
function this:BindEvent()
|
|
Util.AddClick(this.confirm,function()
|
|
data.otherData.selectId = self.selectId
|
|
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 = data.otherData.selectId
|
|
|
|
local list = BagManager.GetBagItemDataByItemType(ItemBaseType.Equip)
|
|
local EquipedEquipList = HeroManager.GetEquipedEquipList()
|
|
for i = 1, #data.otherData.needItems do
|
|
for j = 1, #list do
|
|
if data.otherData.needItems[i] == 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 data.otherData.needItems[i] == 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
|
|
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[index] then
|
|
self.itemList[index] = SubUIManager.Open(SubUIConfig.ItemView,itemtrans.transform)
|
|
self.itemList[index].gameObject:SetActive(false)
|
|
end
|
|
LogGreen("index:"..tostring(index))
|
|
self.itemList[index]:OnOpen(false, {sdata.Id,sdata.Num}, 1,true,false,false,sortingOrder)
|
|
self.itemList[index].gameObject:SetActive(true)
|
|
self.maskList[index] = itemmask
|
|
self.maskImageList[index] = maskImage
|
|
self.maskImageList[index]:SetActive(self.selectId == sdata.Id)
|
|
|
|
|
|
Util.AddOnceClick(self.maskList[index],function ()
|
|
for i = 1, #self.maskImageList do
|
|
self.maskImageList[i]:SetActive(false)
|
|
end
|
|
if self.selectId == sdata.Id then
|
|
self.maskImageList[index]:SetActive(false)
|
|
self.selectId = 0
|
|
else
|
|
self.maskImageList[index]:SetActive(true)
|
|
self.selectId = sdata.Id
|
|
end
|
|
end)
|
|
Util.AddOnceClick(equiped,function ()
|
|
PopupTipPanel.ShowTip(Language[12313])
|
|
end)
|
|
end
|
|
|
|
function this:OnClose()
|
|
self.selectId = nil
|
|
self.equipList={}
|
|
self.maskList = {}
|
|
self.maskImageList = {}
|
|
end
|
|
|
|
function this:OnDestroy()
|
|
self.itemList = {}
|
|
end
|
|
|
|
return this |