require("Base/BasePanel") local FightAreaRewardPopup = Inherit(BasePanel) local this = FightAreaRewardPopup local ItemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig) local _ProductList = {} local _ItemList = {} local _RewardList = {} local _ExtraRewardList = {} --初始化组件(用于子类重写) function FightAreaRewardPopup:InitComponent() this.spLoader = SpriteLoader.New() this.btnBack = Util.GetGameObject(self.transform, "mask") this.scroller = Util.GetGameObject(self.transform, "showMopUp/scroller") this.itemRoot = Util.GetGameObject(self.transform, "showMopUp/scroller/reward") this.itemRootTitle = Util.GetGameObject(this.itemRoot, "title") this.item = Util.GetGameObject(this.itemRoot, "scroll/grid/item") this.itemGrid = Util.GetGameObject(this.itemRoot, "scroll/grid") this.rewardBox = Util.GetGameObject(self.transform, "showMopUp/scroller/rateReward") this.rewardBoxTitle = Util.GetGameObject(this.rewardBox, "title") this.rewardBoxItem = Util.GetGameObject(this.rewardBox, "scroll/grid/item") this.rewardBoxGrid = Util.GetGameObject(this.rewardBox, "scroll/grid") this.extraReward = Util.GetGameObject(self.transform, "extraReward") this.extraRewardTitle = Util.GetGameObject(this.extraReward, "title") this.extraRewardItem = Util.GetGameObject(this.extraReward, "scroll/grid/item") this.extraRewardGrid = Util.GetGameObject(this.extraReward, "scroll/grid") end --绑定事件(用于子类重写) function FightAreaRewardPopup:BindEvent() Util.AddClick(this.btnBack, function() PlaySoundWithoutClick(SoundConfig.Sound_UICancel) this:ClosePanel() end) end --添加事件监听(用于子类重写) function FightAreaRewardPopup:AddListener() end --移除事件监听(用于子类重写) function FightAreaRewardPopup:RemoveListener() end --界面打开时调用(用于子类重写) function FightAreaRewardPopup:OnOpen(...) end -- local orginLayer = -1 function this:OnSortingOrderChange() -- Util.AddParticleSortLayer(this.privilegeEffect, this.sortingOrder - orginLayer) orginLayer = self.sortingOrder end --界面打开或者重新打开后,界面刷新时调用(用于子类重写) function FightAreaRewardPopup:OnShow() local curFightId = FightPointPassManager.GetCurFightId() local config = ConfigManager.GetConfigData(ConfigName.MainLevelConfig, curFightId) if config then if not config.RewardShowMin or #config.RewardShowMin < 1 then this.itemRoot.gameObject:SetActive(false) else this.itemRoot.gameObject:SetActive(true) -- 固定奖励 for index, item in ipairs(config.RewardShowMin) do if not _ProductList[index] then _ProductList[index] = newObjToParent(this.item, this.itemGrid.transform) end this.ItemAdapter(_ProductList[index], item) end end local randReward = {} if config.RewardShow and #config.RewardShow > 0 then for j = 1, #config.RewardShow do randReward[#randReward + 1] = config.RewardShow[j] end end local open, extral = FightPointPassManager.GetExtralReward() if open > 0 then for k = 1, #extral do randReward[#randReward + 1] = extral[k] end end if #randReward > 1 then this.rewardBox.gameObject:SetActive(true) table.sort(randReward, function (a, b) return ItemConfig[a[1]].Quantity > ItemConfig[b[1]].Quantity end) for index, reward in ipairs(randReward) do if not _RewardList[index] then _RewardList[index] = SubUIManager.Open(SubUIConfig.ItemView, this.rewardBoxGrid.transform) end local rdata = {reward[1], 0} -- 不显示数量 _RewardList[index]:OnOpen(false, rdata, 1, true) end else this.rewardBox.gameObject:SetActive(false) end end local vipLv = VipManager.GetVipLevel() local totalCurNum,totalLv,totalNum = LikabilityManager.GetTotalHeroLikeLv(-1) local Vipvalue = 0 local config = ConfigManager.GetConfigData(ConfigName.PrivilegeTypeConfig,1) for i = 1,#config.Condition do if config.Condition[i][1] == vipLv then Vipvalue = config.Condition[i][2] end end if (vipLv < 1 or (Vipvalue - 10000)<= 0) and (totalLv < 1) then this.extraReward.gameObject:SetActive(false) else local num = 1 this.extraReward.gameObject:SetActive(true) for i = 1,#_ExtraRewardList do _ExtraRewardList[i].go.gameObject:SetActive(false) end if totalLv > 0 then local data = {} data.sprite = "h_haogandu_aixin" data.iconText = "" data.lv = totalLv.."级" local prolist = LikabilityManager.GetPrivilageProData(1,-1,totalLv) local str1 = "" for k,v in pairs(prolist) do local config = ConfigManager.GetConfigDataByKey(ConfigName.PrivilegeTypeConfig,"PrivilegeType",k) str1 = str1 .. string.format(config.Name,GetPropertyFormatStrOne(config.IfFloat, v)) end data.content = str1 data.type = 1 this.PriAdapter(num,data) num = num + 1 end if vipLv > 0 then local data = {} data.sprite = "r_zjm_tequanpaizi" data.iconText = "特权" data.lv = vipLv.."级" if Vipvalue - 10000 > 0 then data.content = string.format(config.Name,GetPropertyFormatStrOne(config.IfFloat, Vipvalue - 10000)) data.type = 2 this.PriAdapter(num,data) num = num + 1 end end end --屏蔽好感度加成 this.extraReward.gameObject:SetActive(false) ForceRebuildLayout(this.scroller.transform) ForceRebuildLayout(this.extraRewardGrid.transform) end function this.PriAdapter(num,data) if not _ExtraRewardList[num] then _ExtraRewardList[num] = {} _ExtraRewardList[num].go = newObjToParent(this.extraRewardItem,this.extraRewardGrid) _ExtraRewardList[num].icon = Util.GetGameObject(_ExtraRewardList[num].go, "icon"):GetComponent("Image") _ExtraRewardList[num].lv = Util.GetGameObject(_ExtraRewardList[num].go, "lv"):GetComponent("Text") _ExtraRewardList[num].content = Util.GetGameObject(_ExtraRewardList[num].go, "content"):GetComponent("Text") _ExtraRewardList[num].iconText = Util.GetGameObject(_ExtraRewardList[num].icon.transform, "Text"):GetComponent("Text") end _ExtraRewardList[num].go.gameObject:SetActive(true) _ExtraRewardList[num].icon.sprite = this.spLoader:LoadSprite(data.sprite) _ExtraRewardList[num].icon:SetNativeSize() if data.type == 1 then _ExtraRewardList[num].icon.transform:GetComponent("RectTransform").sizeDelta = Vector2.New(71,65) end _ExtraRewardList[num].lv.text = data.lv _ExtraRewardList[num].content.text = data.content _ExtraRewardList[num].iconText.text = data.iconText end -- 物体数据匹配 function this.ItemAdapter(node, data) -- 创建一个物体 local root = Util.GetGameObject(node, "root") if not _ItemList[node] then _ItemList[node] = SubUIManager.Open(SubUIConfig.ItemView, root.transform) end local rdata = {data[1], 0} -- 不显示数量 _ItemList[node]:OnOpen(false, rdata, 1.1) -- local txt = Util.GetGameObject(node, "context"):GetComponent("Text") local addValue = FightPointPassManager.GetItemVipValue(data[1]) -- local totalCurNum,totalLv,totalNum = LikabilityManager.GetTotalHeroLikeLv(-1) -- local prolist = {} -- LogGreen("addValue:"..addValue) -- if totalLv > 0 then -- prolist = LikabilityManager.GetPrivilageProData(1,-1,totalLv) -- local priId = _ItemIdToVipPrivilege[data[1]] -- if prolist[priId] then -- addValue = addValue + (prolist[priId]/10000) -- end -- end -- LogGreen("addValue:"..addValue) local baseValue = string.format(Language[10603], data[2]) if addValue - 1 <= 0 then txt.text = baseValue else local valueShow = math.round((addValue - 1) * data[2]) txt.text = string.format("%s\n(+%s)",baseValue,valueShow) end end --界面关闭时调用(用于子类重写) function FightAreaRewardPopup:OnClose() end --界面销毁时调用(用于子类重写) function FightAreaRewardPopup:OnDestroy() this.spLoader:Destroy() _ProductList = {} for _, node in ipairs(_ItemList) do SubUIManager.Close(node) end _ItemList = {} for _, node in ipairs(_RewardList) do SubUIManager.Close(node) end _RewardList = {} _ExtraRewardList = {} end return FightAreaRewardPopup