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

316 lines
12 KiB
Lua
Raw Normal View History

2021-04-21 13:12:04 +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 = {}--勾选按钮列表
2021-11-27 13:54:36 +08:00
local itemType = 0 --宝箱里面道具类型
2020-06-13 11:47:13 +08:00
--初始化组件(用于子类重写)
function RewardBoxPanel:InitComponent()
2021-04-21 13:12:04 +08:00
this.spLoader = SpriteLoader.New()
this.mask = Util.GetGameObject(this.gameObject,"mask")
2020-06-13 11:47:13 +08:00
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-04-08 14:53:36 +08:00
this.tip = Util.GetGameObject(this.gameObject,"bg/topBar/tip"):GetComponent("Text")
2020-06-13 11:47:13 +08:00
this.selectBar = Util.GetGameObject(this.gameObject,"bg/topBar/selectBar")
2021-04-08 14:44:08 +08:00
this.selectBtn = Util.GetGameObject(this.gameObject,"bg/topBar/selectBar/di/selectBtn")
this.di = Util.GetGameObject(this.gameObject,"bg/topBar/selectBar/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
end
--绑定事件(用于子类重写)
function RewardBoxPanel:BindEvent()
Util.AddClick(this.btnBack ,function()
this:ClosePanel()
end)
Util.AddClick(this.mask ,function()
this:ClosePanel()
end)
2020-06-13 11:47:13 +08:00
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)
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-04-08 14:44:08 +08:00
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)
2021-04-08 15:36:27 +08:00
end
-- 打开,重新打开时回调
function RewardBoxPanel:OnShow()
this.name.text = GetLanguageStrById(itemConfig[this.itemId].Name)
itemList={}
curId = nil
tagNum = 1
--刷新按钮亮光
2021-04-08 15:36:27 +08:00
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
2020-06-13 11:47:13 +08:00
self:RefreshData()
end
function RewardBoxPanel:RefreshData()
2021-04-08 14:44:08 +08:00
this.selectBar:SetActive(#this.rewardGroup ~= 1)--设置顶部属性条
this.tip.text = Language[12290]
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
local dataList = {}
local showItems = rewardGroup[RewardGroupList[tagNum]].ShowItem
for _, item in ipairs(showItems) do
local itemType = itemConfig[item[1]].ItemType
if itemType == ItemType.Hero then
-- 判断是否在版本内
if HeroManager.InVersion(item[1]) then
table.insert(dataList, item)
end
elseif itemType == ItemType.HeroDebris then
-- 判断是否在版本内
local heroId = HeroManager.ChipIdToHeroId(item[1])
if not heroId or HeroManager.InVersion(heroId) then
table.insert(dataList, item)
end
else
table.insert(dataList, item)
end
end
itemType = itemConfig[dataList[1][1]].ItemType
for _, data in ipairs(dataList) do
LogRed(data[1])
end
this.ScrollView:SetData(dataList,function(index,item)
RewardBoxPanel:SetSingleGiftData(index,item,dataList)
2020-06-13 11:47:13 +08:00
end)
end
--刷新每一条奖励信息
function RewardBoxPanel:SetSingleGiftData(index,item,dataList)
2020-06-13 11:47:13 +08:00
itemList[index] = item
local icon = Util.GetGameObject(item,"icon")
2021-11-27 13:54:36 +08:00
local yihuode = Util.GetGameObject(icon,"yihuode")
2020-06-13 11:47:13 +08:00
local tip = Util.GetGameObject(item,"tip"):GetComponent("Text")
local des = Util.GetGameObject(item,"des"):GetComponent("Text")
des.gameObject:SetActive(false)
2020-06-13 11:47:13 +08:00
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)
2021-11-27 13:54:36 +08:00
view.transform:SetAsFirstSibling()
2020-06-28 17:52:29 +08:00
itemIconList[item] = view
2020-06-28 17:48:49 +08:00
end
local heroConfig=itemConfig[dataList[index][1]]
itemIconList[item]:OnOpen(false,dataList[index],1,false, false, false, self.sortingOrder)
2021-04-01 20:22:15 +08:00
itemIconList[item].gameObject:SetActive(true)
itemIconList[item]:SetEffectLayer(self.sortingOrder)
tip.text = GetLanguageStrById(heroConfig.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)
2021-11-27 13:54:36 +08:00
yihuode:SetActive(false)
-- if heroConfig.ItemType == ItemType.Incarnation and BagManager.isBagPanel then
-- local num = BagManager.GetItemCountById(dataList[index][1])
-- if num > 0 or IncarnationManager.GetStatusByItemId(dataList[index][1]) >= 0 then
-- select:SetActive(false)
-- yihuode:SetActive(true)
-- else
-- select:SetActive(true)
-- yihuode:SetActive(false)
-- end
-- end
if heroConfig.ItemType == ItemType.Talisman then
if heroConfig.ItemDescribe then
local aaa=string.split(heroConfig.ItemDescribe,'')
if aaa and #aaa>0 then
des.gameObject:SetActive(true)
des.text=aaa[1]
end
end
end
2020-06-13 11:47:13 +08:00
--判断是否选了该物品
if curId == dataList[index][1] then
2020-06-13 11:47:13 +08:00
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 = dataList[index][1]
2020-06-13 11:47:13 +08:00
end
end)
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)--拥有的最大数量
2021-11-27 13:54:36 +08:00
maxNum = itemType == ItemType.Incarnation and 1 or gameSetting[1].OpenBoxLimits--最大领取数量(配表)
2020-06-13 11:47:13 +08:00
this.Slider:GetComponent("Slider").value=1
this.Slider:GetComponent("Slider").minValue = 0
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-04-09 12:26:35 +08:00
PopupTipPanel.ShowTip(Language[10759])
2021-01-14 14:44:01 +08:00
return
end
if curNum <= 0 then
2021-04-09 12:26:35 +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-04-09 12:26:35 +08:00
PopupTipPanel.ShowTip(Language[10759])
2020-06-13 11:47:13 +08:00
end
end
--界面关闭时调用(用于子类重写)
function RewardBoxPanel:OnClose()
2021-04-08 15:36:27 +08:00
this.selectList ={}
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()
2021-04-21 13:12:04 +08:00
this.spLoader:Destroy()
2021-04-08 15:36:27 +08:00
this.selectList ={}
2020-06-28 17:48:49 +08:00
itemIconList={}
goList = {}
2020-06-13 11:47:13 +08:00
end
return RewardBoxPanel