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 = {}--勾选按钮列表 local itemType = 0 --宝箱里面道具类型 --初始化组件(用于子类重写) function RewardBoxPanel:InitComponent() this.spLoader = SpriteLoader.New() this.mask = Util.GetGameObject(this.gameObject,"mask") 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.titledi=Util.GetGameObject(this.gameObject,"bg/titledi") 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(813, 868), 1, 1, Vector2.New(0, 20)) 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.AddClick(this.mask ,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={...} 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(813, 810.8) or Vector2.New(940,866.18) this.scroll.gameObject:GetComponent("RectTransform").anchoredPosition = #this.rewardGroup ~= 1 and Vector2.New(0, 420) or Vector2.New(0, 463) this.ScrollView.gameObject:GetComponent("RectTransform").sizeDelta = #this.rewardGroup ~= 1 and Vector2.New(813, 810.8) or Vector2.New(940, 866.18) this.titledi.gameObject:GetComponent("RectTransform").sizeDelta = #this.rewardGroup ~= 1 and Vector2.New(813.5, 118.8) or Vector2.New(813.5, 67.5) end -- 打开,重新打开时回调 function RewardBoxPanel:OnShow() this.name.text = GetLanguageStrById(itemConfig[this.itemId].Name) itemList={} curId = nil tagNum = 1 Util.GetGameObject( this.selectBtn,"Text"):GetComponent("Text").text= PropertyType[1] --刷新按钮亮光 this.selectList ={} for n = 1, this.selectBar.transform.childCount-1 do--设置当前页签 table.insert(this.selectList,this.selectBar.transform:GetChild(n).gameObject) Util.GetGameObject(this.selectBar.transform:GetChild(n).gameObject,"Text"):GetComponent("Text").text= PropertyType[n] 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 Util.GetGameObject( this.selectBtn,"Text"):GetComponent("Text").text= PropertyType[i]--Util.GetGameObject( this.selectList[i],"Text"):GetComponent("Text").text end) end 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 local dataList = {} if RewardGroupList[tagNum] then 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 end this.ScrollView:SetData(dataList,function(index,item) RewardBoxPanel:SetSingleGiftData(index,item,dataList) end) if #dataList>4 then -- this.ScrollView:SetDragGoRect(Vector2.New(0,120)) end end --刷新每一条奖励信息 function RewardBoxPanel:SetSingleGiftData(index,item,dataList) itemList[index] = item local icon = Util.GetGameObject(item,"icon") local yihuode = Util.GetGameObject(icon,"yihuode") local tip = Util.GetGameObject(item,"tip"):GetComponent("Text") local des = Util.GetGameObject(item,"des"):GetComponent("Text") des.gameObject:SetActive(false) 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) view.transform:SetAsFirstSibling() itemIconList[item] = view end local heroConfig=itemConfig[dataList[index][1]] itemIconList[item]:OnOpen(false,dataList[index],1,false, false, false, self.sortingOrder) itemIconList[item].gameObject:SetActive(true) itemIconList[item]:SetEffectLayer(self.sortingOrder) -- itemIconList[item].transform.localPosition=Vector3.New(0,5,0) tip.text = GetLanguageStrById(heroConfig.Name) --判断是否是在背包界面打开 select:GetComponent("Button").interactable = BagManager.isBagPanel select:SetActive(BagManager.isBagPanel) 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 --判断是否选了该物品 if curId == dataList[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 = dataList[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 = itemType == ItemType.Incarnation and 1 or gameSetting[1].OpenBoxLimits--最大领取数量(配表) this.Slider:GetComponent("Slider").value=1 this.Slider:GetComponent("Slider").minValue = 0 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.spLoader:Destroy() this.selectList ={} itemIconList={} goList = {} end return RewardBoxPanel