miduo_client/Assets/ManagedResources/~Lua/Modules/Popup/ItemBoxDropPopup.lua

90 lines
2.6 KiB
Lua

require("Base/BasePanel")
ItemBoxDropPopup = Inherit(BasePanel)
local this = ItemBoxDropPopup
--初始化组件(用于子类重写)
function this:InitComponent()
this.spLoader = SpriteLoader.New()
this.mask = Util.GetGameObject(this.transform, "mask")
this.dropGrid=Util.GetGameObject(this.transform, "bg/grid")
end
--绑定事件(用于子类重写)
function this:BindEvent()
Util.AddClick(this.mask, function()
this:ClosePanel()
end)
end
--添加事件监听(用于子类重写)
function this:AddListener()
end
--移除事件监听(用于子类重写)
function this:RemoveListener()
end
local itemListPrefab={}
--界面打开时调用(用于子类重写)
function this:OnOpen(rewardGroup)
local winData={}
for i = 1, #rewardGroup do
winData[i]={}
winData[i].allWeight=0
winData[i].itemList={}
local rewardItems= ConfigManager.GetConfigData(ConfigName.RewardGroup,rewardGroup[i]).RewardItem
for j = 1, #rewardItems do
local rewardItemConfig=ConfigManager.GetConfigData(ConfigName.RewardItemConfig,rewardItems[j])
winData[i].allWeight=winData[i].allWeight+rewardItemConfig.Chance
local itemInfo={}
itemInfo.weight=rewardItemConfig.Chance
itemInfo.itemId=rewardItemConfig.ItemId
itemInfo.randomMax=rewardItemConfig.RandomMax
winData[i].itemList[j]=itemInfo
end
end
local index=1
for i = 1, #winData do
for j = 1, #winData[i].itemList do
local itemData=winData[i].itemList[j]
if itemData.randomMax>0 then
local view= SubUIManager.Open(SubUIConfig.ItemView, this.dropGrid.transform)
view.gameObject.name = "frame"..index
itemListPrefab[index] = view
index=index+1
view:OnOpen(false,{itemData.itemId,1},1.15,true,false,false,self.sortingOrder)
local str=string.format("获取概率:%s%%",itemData.weight/ winData[i].allWeight*100)
view:ResetName(str)
end
end
end
end
--界面关闭时调用(用于子类重写)
function this:OnClose()
if #itemListPrefab > 0 then
for i = 1, #itemListPrefab do
destroy(itemListPrefab[i].gameObject)
end
end
itemListPrefab = {}
end
--界面销毁时调用(用于子类重写)
function this:OnDestroy()
this.spLoader:Destroy()
if #itemListPrefab > 0 then
for i = 1, #itemListPrefab do
destroy(itemListPrefab[i].gameObject)
end
end
itemListPrefab = {}
end
return this