258 lines
9.5 KiB
Lua
258 lines
9.5 KiB
Lua
require("Base/BasePanel")
|
||
local RewardBoxPanel = Inherit(BasePanel)
|
||
local this = RewardBoxPanel
|
||
|
||
local rewardGroup = ConfigManager.GetConfig(ConfigName.RewardGroup)
|
||
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
||
local gameSetting = ConfigManager.GetConfig(ConfigName.GameSetting)
|
||
|
||
local orginLayer = 0
|
||
|
||
local itemData--当前物品数据
|
||
local curId = nil--当前已选择的物品的Id
|
||
local curNum = 1--当前数量
|
||
local maxOwnNum = 0--拥有的数量
|
||
local maxNum = 0--可选的最大数量(配表)
|
||
-- local callBackFun--传值了,未使用
|
||
local itemList = {}--克隆预制体列表
|
||
local itemIconList={}--ItemView的List
|
||
local tagNum--页签号
|
||
|
||
local goList = {}--勾选按钮列表
|
||
|
||
|
||
--初始化组件(用于子类重写)
|
||
function RewardBoxPanel:InitComponent()
|
||
this.btnBack = Util.GetGameObject(this.gameObject,"bg/btnBack")
|
||
this.scroll = Util.GetGameObject(this.gameObject,"bg/scroll")
|
||
this.itemPre = Util.GetGameObject(this.gameObject,"bg/scroll/itemPre2")
|
||
this.name = Util.GetGameObject(this.gameObject,"bg/bg/name"):GetComponent("Text")
|
||
this.tip = Util.GetGameObject(this.gameObject,"bg/topBar/tip"):GetComponent("Text")
|
||
this.selectBar = Util.GetGameObject(this.gameObject,"bg/topBar/selectBar")
|
||
this.selectBtn = Util.GetGameObject(this.gameObject,"bg/topBar/selectBar/di/selectBtn")
|
||
this.di = Util.GetGameObject(this.gameObject,"bg/topBar/selectBar/di")
|
||
this.slider = Util.GetGameObject(this.gameObject,"bg/bottomBar/slider")
|
||
this.Slider = Util.GetGameObject(this.gameObject,"bg/bottomBar/slider/Slider")
|
||
this.btnReduce = Util.GetGameObject(this.gameObject,"bg/bottomBar/slider/btnReduce")
|
||
this.btnAdd = Util.GetGameObject(this.gameObject,"bg/bottomBar/slider/btnAdd")
|
||
this.btnSure = Util.GetGameObject(this.gameObject,"bg/bottomBar/slider/btnSure")
|
||
this.btnOk = Util.GetGameObject(this.gameObject,"bg/bottomBar/btnOk")
|
||
this.num = Util.GetGameObject(this.gameObject,"bg/bottomBar/slider/num"):GetComponent("Text")
|
||
|
||
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.scroll.transform,
|
||
this.itemPre, nil, Vector2.New(940, 900), 1, 1, Vector2.New(0, 0))
|
||
this.ScrollView.gameObject:GetComponent("RectTransform").anchoredPosition = Vector2.New(0, 0)
|
||
this.ScrollView.gameObject:GetComponent("RectTransform").anchorMin = Vector2.New(0.5, 0.5)
|
||
this.ScrollView.gameObject:GetComponent("RectTransform").anchorMax = Vector2.New(0.5, 0.5)
|
||
this.ScrollView.gameObject:GetComponent("RectTransform").pivot = Vector2.New(0.5, 0.5)
|
||
this.ScrollView.moveTween.MomentumAmount = 1
|
||
this.ScrollView.moveTween.Strength = 2
|
||
end
|
||
--绑定事件(用于子类重写)
|
||
function RewardBoxPanel:BindEvent()
|
||
Util.AddClick(this.btnBack ,function()
|
||
this:ClosePanel()
|
||
end)
|
||
|
||
Util.AddSlider(this.Slider, function(go, value)
|
||
RewardBoxPanel:ShowCompoundNumData(value)
|
||
end)
|
||
Util.AddClick(this.btnAdd, function()
|
||
if curNum<maxNum and curNum<maxOwnNum then
|
||
curNum=curNum+1
|
||
RewardBoxPanel:ShowCompoundNumData(curNum)
|
||
-- LogPink("当前curNum:"..curNum.." maxNum:"..maxNum)
|
||
end
|
||
end)
|
||
Util.AddClick(this.btnReduce, function()
|
||
if curNum>=2 then
|
||
curNum=curNum-1
|
||
RewardBoxPanel:ShowCompoundNumData(curNum)
|
||
-- LogPink("当前curNum:"..curNum.." maxNum:"..maxNum)
|
||
end
|
||
end)
|
||
|
||
Util.AddClick(this.btnSure, function()
|
||
self:OnBtnSureClick()
|
||
end)
|
||
Util.AddClick(this.btnOk, function()
|
||
this:ClosePanel()
|
||
end)
|
||
end
|
||
|
||
--添加事件监听(用于子类重写)
|
||
function RewardBoxPanel:AddListener()
|
||
end
|
||
|
||
--移除事件监听(用于子类重写)
|
||
function RewardBoxPanel:RemoveListener()
|
||
end
|
||
|
||
|
||
--界面打开时调用(用于子类重写)
|
||
function RewardBoxPanel:OnOpen(...)
|
||
local data={...}
|
||
if data[1] then
|
||
this.rewardGroup = data[1].itemConfig.RewardGroup
|
||
this.itemId = data[1].id
|
||
else
|
||
this.rewardGroup = itemConfig[data[2]].RewardGroup
|
||
this.itemId = itemConfig[data[2]].Id
|
||
end
|
||
this.scroll.gameObject:GetComponent("RectTransform").sizeDelta = #this.rewardGroup ~= 1 and Vector2.New(940, 836.8) or Vector2.New(940, 900)
|
||
this.scroll.gameObject:GetComponent("RectTransform").anchoredPosition = #this.rewardGroup ~= 1 and Vector2.New(0, 376) or Vector2.New(0, 444)
|
||
this.ScrollView.gameObject:GetComponent("RectTransform").sizeDelta = #this.rewardGroup ~= 1 and Vector2.New(940, 830) or Vector2.New(940, 900)
|
||
|
||
this.selectList ={}
|
||
for n = 1, this.selectBar.transform.childCount-1 do--设置当前页签
|
||
table.insert(this.selectList,this.selectBar.transform:GetChild(n).gameObject)
|
||
end
|
||
this.selectBtn.transform:SetParent(this.selectList[1].transform)
|
||
this.selectBtn.transform.localPosition = Vector3.zero
|
||
this.selectBtn.transform.localScale = Vector3.one
|
||
for i = 1, #this.selectList do
|
||
Util.AddOnceClick(this.selectList[i],function()
|
||
curId = 0
|
||
tagNum = i
|
||
RewardBoxPanel:SetGiftData()
|
||
this.selectBtn.transform:SetParent(this.selectList[i].transform)
|
||
this.selectBtn.transform.localPosition = Vector3.zero
|
||
this.selectBtn.transform.localScale = Vector3.one
|
||
end)
|
||
end
|
||
|
||
end
|
||
|
||
-- 打开,重新打开时回调
|
||
function RewardBoxPanel:OnShow()
|
||
this.name.text = GetLanguageStrById(itemConfig[this.itemId].Name)
|
||
itemList={}
|
||
curId = nil
|
||
tagNum = 1
|
||
self:RefreshData()
|
||
end
|
||
|
||
function RewardBoxPanel:RefreshData()
|
||
this.selectBar:SetActive(#this.rewardGroup ~= 1)--设置顶部属性条
|
||
this.tip.text = Language[12290]
|
||
RewardBoxPanel:SetGiftData()
|
||
RewardBoxPanel:SetBottom()
|
||
end
|
||
|
||
--刷新奖励信息
|
||
function RewardBoxPanel:SetGiftData()--设置奖励列表
|
||
local RewardGroupList = {}
|
||
|
||
for index, value in ipairs(this.rewardGroup) do
|
||
RewardGroupList[index] = value
|
||
end
|
||
|
||
this.ScrollView:SetData(rewardGroup[RewardGroupList[tagNum]].ShowItem,function(index,item)
|
||
RewardBoxPanel:SetSingleGiftData(index,item,RewardGroupList[tagNum],tagNum)
|
||
end)
|
||
|
||
end
|
||
|
||
--刷新每一条奖励信息
|
||
function RewardBoxPanel:SetSingleGiftData(index,item,boxId,tagNum)
|
||
itemList[index] = item
|
||
local icon = Util.GetGameObject(item,"icon")
|
||
local tip = Util.GetGameObject(item,"tip"):GetComponent("Text")
|
||
local select = Util.GetGameObject(item,"select")
|
||
local go = Util.GetGameObject(item,"select/Go")
|
||
|
||
goList[index] = go
|
||
|
||
item:SetActive(true)
|
||
if not itemIconList[item] then
|
||
local view = SubUIManager.Open(SubUIConfig.ItemView, icon.transform)
|
||
itemIconList[item] = view
|
||
end
|
||
itemIconList[item]:OnOpen(false,rewardGroup[boxId].ShowItem[index],1,false)
|
||
itemIconList[item].gameObject:SetActive(true)
|
||
itemIconList[item]:SetEffectLayer(self.sortingOrder)
|
||
tip.text = GetLanguageStrById(itemConfig[rewardGroup[boxId].ShowItem[index][1]].Name)
|
||
|
||
--判断是否是在背包界面打开
|
||
select:GetComponent("Button").interactable = BagManager.isBagPanel
|
||
select:SetActive(BagManager.isBagPanel)
|
||
--判断是否选了该物品
|
||
if curId == rewardGroup[boxId].ShowItem[index][1] then
|
||
go:SetActive(true)
|
||
else
|
||
go:SetActive(false)
|
||
end
|
||
--选择一个物品
|
||
Util.AddOnceClick(select,function()
|
||
if go.gameObject.activeSelf then
|
||
go:SetActive(false)
|
||
curId = nil
|
||
else
|
||
for index, value in ipairs(goList) do
|
||
goList[index]:SetActive(false)
|
||
end
|
||
go:SetActive(true)
|
||
curId = rewardGroup[boxId].ShowItem[index][1]
|
||
end
|
||
end)
|
||
end
|
||
|
||
--设置底部滑动条
|
||
function RewardBoxPanel:SetBottom()--设置底部滑动条
|
||
this.num.text = 1
|
||
this.slider:SetActive(BagManager.isBagPanel)
|
||
this.btnOk:SetActive(not BagManager.isBagPanel)
|
||
if not BagManager.isBagPanel then return end
|
||
maxOwnNum = BagManager.GetItemCountById(this.itemId)--拥有的最大数量
|
||
maxNum = gameSetting[1].OpenBoxLimits--最大领取数量(配表)
|
||
this.Slider:GetComponent("Slider").value=1
|
||
this.Slider:GetComponent("Slider").minValue = 1
|
||
this.Slider:GetComponent("Slider").maxValue = maxOwnNum >= maxNum and maxNum or maxOwnNum--当前物品总数量
|
||
end
|
||
|
||
--滑动条显示
|
||
function RewardBoxPanel:ShowCompoundNumData(value)
|
||
this.num.text = value
|
||
curNum = value
|
||
this.Slider:GetComponent("Slider").value=value
|
||
|
||
end
|
||
|
||
function RewardBoxPanel:OnBtnSureClick()
|
||
if curId then
|
||
local data = {this.itemId,curId,curNum}
|
||
if curId <= 0 then
|
||
PopupTipPanel.ShowTip(Language[10759])
|
||
return
|
||
end
|
||
if curNum <= 0 then
|
||
PopupTipPanel.ShowTip(Language[11755])
|
||
return
|
||
end
|
||
NetManager.UseAndPriceItemRequest(6,data,function (drop)
|
||
UIManager.OpenPanel(UIName.RewardItemPopup,drop,1,function()
|
||
self:ClosePanel()
|
||
Game.GlobalEvent:DispatchEvent(GameEvent.Bag.OnTempBagChanged)
|
||
end)
|
||
end)
|
||
else
|
||
PopupTipPanel.ShowTip(Language[10759])
|
||
end
|
||
end
|
||
|
||
--界面关闭时调用(用于子类重写)
|
||
function RewardBoxPanel:OnClose()
|
||
this.selectList ={}
|
||
curNum = 1
|
||
this.selectBtn.transform.parent = this.selectBar.transform:GetChild(0).transform
|
||
this.selectBtn.transform.localPosition = Vector3.zero
|
||
this.selectBtn.transform.localScale = Vector3.one
|
||
end
|
||
|
||
--界面销毁时调用(用于子类重写)
|
||
function RewardBoxPanel:OnDestroy()
|
||
this.selectList ={}
|
||
itemIconList={}
|
||
goList = {}
|
||
end
|
||
return RewardBoxPanel |