miduo_client/Assets/ManagedResources/~Lua/Modules/RewardBox/RewardBoxPanel.lua

262 lines
9.6 KiB
Lua
Raw Normal View History

2020-08-25 15:46:38 +08:00
require("Base/BasePanel")
2020-06-13 11:47:13 +08:00
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 = {}--克隆预制体列表
2020-06-18 20:39:29 +08:00
local itemIconList={}--ItemView的List
2020-06-28 17:48:49 +08:00
local tagNum--页签号
2020-06-13 11:47:13 +08:00
2020-06-28 17:52:29 +08:00
local goList = {}--勾选按钮列表
2020-06-13 11:47:13 +08:00
--初始化组件(用于子类重写)
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")
2021-03-18 15:15:16 +08:00
this.name = Util.GetGameObject(this.gameObject,"bg/bg/name"):GetComponent("Text")
2021-03-17 16:00:52 +08:00
this.tip = Util.GetGameObject(this.gameObject,"bg/topBar/tip")
2020-06-13 11:47:13 +08:00
this.selectBar = Util.GetGameObject(this.gameObject,"bg/topBar/selectBar")
2020-06-18 20:39:29 +08:00
this.selectBtn = Util.GetGameObject(this.gameObject,"bg/di/selectBtn")
this.di = Util.GetGameObject(this.gameObject,"bg/di")
2020-06-13 11:47:13 +08:00
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,
2020-06-18 20:39:29 +08:00
this.itemPre, nil, Vector2.New(940, 900), 1, 1, Vector2.New(0, 0))
this.ScrollView.gameObject:GetComponent("RectTransform").anchoredPosition = Vector2.New(0, 0)
2020-06-13 11:47:13 +08:00
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
2021-03-17 16:00:52 +08:00
this.selectList ={}
for n = 0, this.selectBar.transform.childCount-1 do--设置当前页签
table.insert(this.selectList,this.selectBar.transform:GetChild(n).gameObject)
end
2020-06-13 11:47:13 +08:00
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()
2020-06-18 20:39:29 +08:00
if curNum<maxNum and curNum<maxOwnNum then
2020-06-13 11:47:13 +08:00
curNum=curNum+1
RewardBoxPanel:ShowCompoundNumData(curNum)
2020-06-18 20:39:29 +08:00
-- LogPink("当前curNum"..curNum.." maxNum"..maxNum)
2020-06-13 11:47:13 +08:00
end
end)
Util.AddClick(this.btnReduce, function()
if curNum>=2 then
curNum=curNum-1
RewardBoxPanel:ShowCompoundNumData(curNum)
2020-06-18 20:39:29 +08:00
-- LogPink("当前curNum"..curNum.." maxNum"..maxNum)
2020-06-13 11:47:13 +08:00
end
end)
Util.AddClick(this.btnSure, function()
self:OnBtnSureClick()
end)
Util.AddClick(this.btnOk, function()
this:ClosePanel()
end)
2021-03-17 16:00:52 +08:00
for i = 1, #this.selectList do
Util.AddClick(this.selectList[i],function()
curId = 0
tagNum = i
RewardBoxPanel:SetGiftData()
2021-03-18 10:11:00 +08:00
this.selectBtn.transform:SetParent(this.selectList[i].transform)
2021-03-17 16:00:52 +08:00
this.selectBtn.transform.localPosition = Vector3.zero
this.selectBtn.transform.localScale = Vector3.one
end)
end
2020-06-13 11:47:13 +08:00
end
--添加事件监听(用于子类重写)
function RewardBoxPanel:AddListener()
end
--移除事件监听(用于子类重写)
function RewardBoxPanel:RemoveListener()
end
--界面打开时调用(用于子类重写)
function RewardBoxPanel:OnOpen(...)
local data={...}
2021-03-17 16:00:52 +08:00
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
2021-03-19 23:54:24 +08:00
2021-03-22 20:41:51 +08:00
this.scroll.gameObject:GetComponent("RectTransform").sizeDelta = #this.rewardGroup ~= 1 and Vector2.New(940, 880) or Vector2.New(940, 1000)
this.scroll.gameObject:GetComponent("RectTransform").anchoredPosition = #this.rewardGroup ~= 1 and Vector2.New(0, 415) or Vector2.New(0, 542.6)
this.ScrollView.gameObject:GetComponent("RectTransform").sizeDelta = #this.rewardGroup ~= 1 and Vector2.New(940, 900) or Vector2.New(940, 1000)
Util.GetGameObject(this.gameObject,"bg/bg/huangtiao"):SetActive(#this.rewardGroup ~= 1)
2020-06-13 11:47:13 +08:00
end
-- 打开,重新打开时回调
function RewardBoxPanel:OnShow()
2021-03-18 15:15:16 +08:00
this.name.text = itemConfig[this.itemId].Name
2020-06-18 20:39:29 +08:00
itemList={}
2020-06-13 11:47:13 +08:00
curId = nil
2020-06-28 17:48:49 +08:00
tagNum = 1
2020-06-13 11:47:13 +08:00
self:RefreshData()
end
function RewardBoxPanel:RefreshData()
RewardBoxPanel:SetTopBar()
2021-03-17 16:00:52 +08:00
RewardBoxPanel:SetGiftData()
2020-06-13 11:47:13 +08:00
RewardBoxPanel:SetBottom()
end
--刷新奖励信息
2021-03-17 16:00:52 +08:00
function RewardBoxPanel:SetGiftData()--设置奖励列表
2020-06-13 11:47:13 +08:00
local RewardGroupList = {}
2021-03-17 16:00:52 +08:00
for index, value in ipairs(this.rewardGroup) do
2020-06-13 11:47:13 +08:00
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")
2020-06-28 17:52:29 +08:00
goList[index] = go
2020-06-13 11:47:13 +08:00
item:SetActive(true)
2020-06-28 17:52:29 +08:00
if not itemIconList[item] then
2020-06-28 17:48:49 +08:00
local view = SubUIManager.Open(SubUIConfig.ItemView, icon.transform)
2020-06-28 17:52:29 +08:00
itemIconList[item] = view
2020-06-28 17:48:49 +08:00
end
2020-06-28 17:52:29 +08:00
itemIconList[item]:OnOpen(false,rewardGroup[boxId].ShowItem[index],1,false)
2021-01-26 17:08:39 +08:00
tip.text = GetLanguageStrById(itemConfig[rewardGroup[boxId].ShowItem[index][1]].Name)
2020-06-13 11:47:13 +08:00
--判断是否是在背包界面打开
select:GetComponent("Button").interactable = BagManager.isBagPanel
2021-03-17 16:00:52 +08:00
select:SetActive(BagManager.isBagPanel)
2020-06-13 11:47:13 +08:00
--判断是否选了该物品
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
2020-06-28 17:52:29 +08:00
for index, value in ipairs(goList) do
goList[index]:SetActive(false)
end
2020-06-13 11:47:13 +08:00
go:SetActive(true)
curId = rewardGroup[boxId].ShowItem[index][1]
end
end)
end
--设置头部属性标签显示
function RewardBoxPanel:SetTopBar()
2021-03-17 16:00:52 +08:00
this.selectBar:SetActive(#this.rewardGroup ~= 1)--设置顶部属性条
this.di:SetActive(#this.rewardGroup ~= 1)
this.tip:SetActive(BagManager.isBagPanel)
2021-03-18 15:15:54 +08:00
this.di.transform.localPosition = Vector3.New(0, 473, 0)
if #this.rewardGroup ~= 1 and not BagManager.isBagPanel then
this.di.transform.localPosition = Vector3.New(0, 510, 0)
end
2020-06-13 11:47:13 +08:00
end
--设置底部滑动条
function RewardBoxPanel:SetBottom()--设置底部滑动条
this.num.text = 1
this.slider:SetActive(BagManager.isBagPanel)
this.btnOk:SetActive(not BagManager.isBagPanel)
2021-03-17 16:00:52 +08:00
if not BagManager.isBagPanel then return end
maxOwnNum = BagManager.GetItemCountById(this.itemId)--拥有的最大数量
2020-06-13 11:47:13 +08:00
maxNum = gameSetting[1].OpenBoxLimits--最大领取数量(配表)
this.Slider:GetComponent("Slider").value=1
this.Slider:GetComponent("Slider").minValue = 1
2020-06-18 20:39:29 +08:00
this.Slider:GetComponent("Slider").maxValue = maxOwnNum >= maxNum and maxNum or maxOwnNum--当前物品总数量
2020-06-13 11:47:13 +08:00
end
--滑动条显示
function RewardBoxPanel:ShowCompoundNumData(value)
this.num.text = value
curNum = value
this.Slider:GetComponent("Slider").value=value
end
function RewardBoxPanel:OnBtnSureClick()
if curId then
2021-03-17 16:00:52 +08:00
local data = {this.itemId,curId,curNum}
2021-01-14 14:44:01 +08:00
if curId <= 0 then
2021-03-02 16:53:12 +08:00
PopupTipPanel.ShowTip(Language[10759])
2021-01-14 14:44:01 +08:00
return
end
if curNum <= 0 then
2021-03-02 16:53:12 +08:00
PopupTipPanel.ShowTip(Language[11755])
return
end
2020-06-13 11:47:13 +08:00
NetManager.UseAndPriceItemRequest(6,data,function (drop)
UIManager.OpenPanel(UIName.RewardItemPopup,drop,1,function()
self:ClosePanel()
Game.GlobalEvent:DispatchEvent(GameEvent.Bag.OnTempBagChanged)
end)
end)
else
2021-03-02 16:53:12 +08:00
PopupTipPanel.ShowTip(Language[10759])
2020-06-13 11:47:13 +08:00
end
end
--界面关闭时调用(用于子类重写)
function RewardBoxPanel:OnClose()
2020-06-28 17:48:49 +08:00
curNum = 1
this.selectBtn.transform.parent = this.selectBar.transform:GetChild(0).transform
this.selectBtn.transform.localPosition = Vector3.zero
this.selectBtn.transform.localScale = Vector3.one
2020-06-13 11:47:13 +08:00
end
--界面销毁时调用(用于子类重写)
function RewardBoxPanel:OnDestroy()
2020-06-28 17:48:49 +08:00
itemIconList={}
goList = {}
2020-06-13 11:47:13 +08:00
end
return RewardBoxPanel