From 17990d0dc8ec6d66646d6cf7ee2c1076344bc78d Mon Sep 17 00:00:00 2001 From: ZhangBiao Date: Wed, 17 Mar 2021 16:00:52 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E8=87=AA=E9=80=89=E5=AE=9D=E7=AE=B1?= =?UTF-8?q?=E3=80=91=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../~Lua/Modules/RewardBox/RewardBoxPanel.lua | 57 +++++++++++-------- .../ManagedResources/~Lua/View/ItemView.lua | 2 +- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/Assets/ManagedResources/~Lua/Modules/RewardBox/RewardBoxPanel.lua b/Assets/ManagedResources/~Lua/Modules/RewardBox/RewardBoxPanel.lua index 5e7d94b779..4e8f394124 100644 --- a/Assets/ManagedResources/~Lua/Modules/RewardBox/RewardBoxPanel.lua +++ b/Assets/ManagedResources/~Lua/Modules/RewardBox/RewardBoxPanel.lua @@ -26,6 +26,7 @@ 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.tip = Util.GetGameObject(this.gameObject,"bg/topBar/tip") this.selectBar = Util.GetGameObject(this.gameObject,"bg/topBar/selectBar") this.selectBtn = Util.GetGameObject(this.gameObject,"bg/di/selectBtn") this.di = Util.GetGameObject(this.gameObject,"bg/di") @@ -45,6 +46,11 @@ function RewardBoxPanel:InitComponent() this.ScrollView.gameObject:GetComponent("RectTransform").pivot = Vector2.New(0.5, 0.5) this.ScrollView.moveTween.MomentumAmount = 1 this.ScrollView.moveTween.Strength = 2 + + this.selectList ={} + for n = 0, this.selectBar.transform.childCount-1 do--设置当前页签 + table.insert(this.selectList,this.selectBar.transform:GetChild(n).gameObject) + end end --绑定事件(用于子类重写) function RewardBoxPanel:BindEvent() @@ -76,6 +82,16 @@ function RewardBoxPanel:BindEvent() Util.AddClick(this.btnOk, function() this:ClosePanel() end) + for i = 1, #this.selectList do + Util.AddClick(this.selectList[i],function() + curId = 0 + tagNum = i + RewardBoxPanel:SetGiftData() + this.selectBtn.transform.parent = this.selectList[i] + this.selectBtn.transform.localPosition = Vector3.zero + this.selectBtn.transform.localScale = Vector3.one + end) + end end --添加事件监听(用于子类重写) @@ -90,8 +106,13 @@ end --界面打开时调用(用于子类重写) function RewardBoxPanel:OnOpen(...) local data={...} - itemData = data[1] - -- callBackFun = data[2] + 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 end -- 打开,重新打开时回调 @@ -104,15 +125,15 @@ end function RewardBoxPanel:RefreshData() RewardBoxPanel:SetTopBar() - RewardBoxPanel:SetGiftData(tagNum) + RewardBoxPanel:SetGiftData() RewardBoxPanel:SetBottom() end --刷新奖励信息 -function RewardBoxPanel:SetGiftData(tagNum)--设置奖励列表 +function RewardBoxPanel:SetGiftData()--设置奖励列表 local RewardGroupList = {} - for index, value in pairs(itemData.itemConfig.RewardGroup) do + for index, value in ipairs(this.rewardGroup) do RewardGroupList[index] = value end @@ -142,7 +163,7 @@ function RewardBoxPanel:SetSingleGiftData(index,item,boxId,tagNum) --判断是否是在背包界面打开 select:GetComponent("Button").interactable = BagManager.isBagPanel - + select:SetActive(BagManager.isBagPanel) --判断是否选了该物品 if curId == rewardGroup[boxId].ShowItem[index][1] then go:SetActive(true) @@ -161,25 +182,14 @@ function RewardBoxPanel:SetSingleGiftData(index,item,boxId,tagNum) go:SetActive(true) curId = rewardGroup[boxId].ShowItem[index][1] end - -- self:SetGiftData(tagNum) - end) end --设置头部属性标签显示 function RewardBoxPanel:SetTopBar() - this.selectBar:SetActive(#itemData.itemConfig.RewardGroup ~= 1)--设置顶部属性条 - this.di:SetActive(#itemData.itemConfig.RewardGroup ~= 1) - - for n = 0, this.selectBar.transform.childCount-1 do--设置当前页签 - Util.AddClick(this.selectBar.transform:GetChild(n).gameObject,function() - curId = 0 - RewardBoxPanel:SetGiftData(n+1) - this.selectBtn.transform.parent = this.selectBar.transform:GetChild(n).transform - this.selectBtn.transform.localPosition = Vector3.zero - this.selectBtn.transform.localScale = Vector3.one - end) - end + this.selectBar:SetActive(#this.rewardGroup ~= 1)--设置顶部属性条 + this.di:SetActive(#this.rewardGroup ~= 1) + this.tip:SetActive(BagManager.isBagPanel) end --设置底部滑动条 @@ -187,7 +197,8 @@ function RewardBoxPanel:SetBottom()--设置底部滑动条 this.num.text = 1 this.slider:SetActive(BagManager.isBagPanel) this.btnOk:SetActive(not BagManager.isBagPanel) - maxOwnNum = BagManager.GetItemCountById(itemData.id)--拥有的最大数量 + 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 @@ -204,9 +215,8 @@ end function RewardBoxPanel:OnBtnSureClick() if curId then - local data = {itemData.id,curId,curNum} + local data = {this.itemId,curId,curNum} if curId <= 0 then - -- body PopupTipPanel.ShowTip(Language[10759]) return end @@ -216,7 +226,6 @@ function RewardBoxPanel:OnBtnSureClick() end NetManager.UseAndPriceItemRequest(6,data,function (drop) UIManager.OpenPanel(UIName.RewardItemPopup,drop,1,function() - -- self:RefreshData()--执行这个Unity会崩溃 self:ClosePanel() Game.GlobalEvent:DispatchEvent(GameEvent.Bag.OnTempBagChanged) end) diff --git a/Assets/ManagedResources/~Lua/View/ItemView.lua b/Assets/ManagedResources/~Lua/View/ItemView.lua index 2b2f391453..d3ae1d07e4 100644 --- a/Assets/ManagedResources/~Lua/View/ItemView.lua +++ b/Assets/ManagedResources/~Lua/View/ItemView.lua @@ -575,7 +575,7 @@ function ItemView:NoGetRewardShow(_reward, effectLayer, isShowAddImage) self.frame.sprite = Util.LoadSprite(GetQuantityImageByquality(itemConfig[itemSId].Quantity)) self.icon.sprite = Util.LoadSprite(GetResourcePath(itemConfig[itemSId].ResourceID)) Util.AddOnceClick(self.frameBtn, function() - UIManager.OpenPanel(UIName.RewardBoxPanel,false,itemSId) + UIManager.OpenPanel(UIName.RewardBoxPanel,nil,itemSId) end) else --,5随机道具,6符文