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 --初始化组件(用于子类重写) 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.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") 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=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={...} itemData = data[1] -- callBackFun = data[2] end -- 打开,重新打开时回调 function RewardBoxPanel:OnShow() itemIconList={} itemList={} curId = nil self:RefreshData() end function RewardBoxPanel:RefreshData() RewardBoxPanel:SetTopBar() local tagNum = 1 RewardBoxPanel:SetGiftData(tagNum) RewardBoxPanel:SetBottom() end --刷新奖励信息 function RewardBoxPanel:SetGiftData(tagNum)--设置奖励列表 local RewardGroupList = {} for index, value in pairs(itemData.itemConfig.RewardGroup) do RewardGroupList[index] = value end -- LogGreen(tostring(tagNum))--页签号 -- LogBlue(tostring(RewardGroupList[tagNum]))--掉落组号 -- LogPink(tostring(rewardGroup[RewardGroupList[tagNum]].ShowItem))--掉落组内 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") item:SetActive(true) local view = SubUIManager.Open(SubUIConfig.ItemView, icon.transform) itemIconList[index] = view view:OnOpen(false,rewardGroup[boxId].ShowItem[index],1,false) tip.text = itemConfig[rewardGroup[boxId].ShowItem[index][1]].Name --判断是否是在背包界面打开 select:GetComponent("Button").interactable = 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 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() 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 end --设置底部滑动条 function RewardBoxPanel:SetBottom()--设置底部滑动条 this.num.text = 1 this.slider:SetActive(BagManager.isBagPanel) this.btnOk:SetActive(not BagManager.isBagPanel) maxOwnNum = BagManager.GetItemCountById(itemData.id)--拥有的最大数量 maxNum = gameSetting[1].OpenBoxLimits--最大领取数量(配表) this.Slider:GetComponent("Slider").value=1 if maxOwnNum == 1 then this.Slider:GetComponent("Slider").minValue = 0 elseif maxOwnNum > 1 then this.Slider:GetComponent("Slider").minValue = 1 end 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 = {itemData.id,curId,curNum} 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) end) else PopupTipPanel.ShowTip("请选择一种宝物") end end --界面关闭时调用(用于子类重写) function RewardBoxPanel:OnClose() end --界面销毁时调用(用于子类重写) function RewardBoxPanel:OnDestroy() end return RewardBoxPanel