require("Base/BasePanel") HeroPreviewPanel = Inherit(BasePanel) local this = HeroPreviewPanel local roleData = {} local viewList = {} local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig) local heroConfig = ConfigManager.GetConfig(ConfigName.HeroConfig) --Tab local TabBox = require("Modules/Common/TabBox") local _TabData = { [1] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = Language[10649] }, [2] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = Language[12577] }, [3] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = Language[10349] } } local _TabFontColor = { default = Color.New(130 / 255, 128 / 255, 120 / 255, 1), select = Color.New(154 / 255, 78 / 255, 36 / 255, 1) } --上一模块索引 local curIndex = 0 local dataType = { [1] = PRE_REWARD_POOL_TYPE.RECRUIT, [2] = PRE_REWARD_POOL_TYPE.FRIEND, [3] = PRE_REWARD_POOL_TYPE.NORMAL, [4] = PRE_REWARD_POOL_TYPE.TIME_LIMITED_NEW_UP, } local itemList = {} function HeroPreviewPanel:InitComponent() this.spLoader = SpriteLoader.New() this.cardPre = Util.GetGameObject(self.gameObject, "item") this.ScrollBar = Util.GetGameObject(self.gameObject, "bg/Scrollbar"):GetComponent("Scrollbar") this.BtnBack = Util.GetGameObject(self.transform, "bg/btnBack") this.titleItem = Util.GetGameObject(self.transform, "titleItem") this.heroScroll = Util.GetGameObject(self.transform, "bg/heroScroll") this.heroScrollGrid = Util.GetGameObject(self.transform, "bg/heroScroll/grid") this.elementScroll = Util.GetGameObject(self.transform, "bg/elementScroll") this.fiveGrid = Util.GetGameObject(self.transform, "bg/heroScroll/grid/fiveGrid") this.fourGrid = Util.GetGameObject(self.transform, "bg/heroScroll/grid/fourGrid") this.threeGrid = Util.GetGameObject(self.transform, "bg/heroScroll/grid/threeGrid") this.twoGrid = Util.GetGameObject(self.transform, "bg/heroScroll/grid/twoGrid") this.twoStarNum = Util.GetGameObject(self.transform, "bg/heroScroll/grid/twoStarNum") this.oneGrid = Util.GetGameObject(self.transform, "bg/heroScroll/grid/oneGrid") this.oneStarNum = Util.GetGameObject(self.transform, "bg/heroScroll/grid/oneStarNum") this.darkGrid = Util.GetGameObject(self.transform, "bg/elementScroll/grid/DarkGrid") this.fireGrid = Util.GetGameObject(self.transform, "bg/elementScroll/grid/FireGrid") this.waterGrid = Util.GetGameObject(self.transform, "bg/elementScroll/grid/WaterGrid") this.windyGrid = Util.GetGameObject(self.transform, "bg/elementScroll/grid/WindyGrid") this.groundGrid = Util.GetGameObject(self.transform, "bg/elementScroll/grid/GroundGrid") this.grid = Util.GetGameObject(self.transform, "bg/scroll/ScrollCycleView/grid") this.heroGrid = Util.GetGameObject(self.transform, "bg/heroScroll/grid") this.elementGrid = Util.GetGameObject(self.transform, "bg/elementScroll/grid") this.viewCache = {} --其他 this.other = Util.GetGameObject(self.gameObject, "bg/otherRoot") this.other:SetActive(false) --tabbox this.tabBox = Util.GetGameObject(self.gameObject, "bg/TabBox") this.List1 = {} this.List2 = {} this.List3 = {} this.List4 = {} this.List5 = {} end function HeroPreviewPanel:BindEvent() Util.AddClick(this.BtnBack, function() PlaySoundWithoutClick(SoundConfig.Sound_UICancel) self:ClosePanel() end) end function HeroPreviewPanel:AddListener() end function HeroPreviewPanel:RemoveListener() end function HeroPreviewPanel:OnSortingOrderChange() this.sortingOrder = self.sortingOrder end --第一个参数是否是英雄或元素 --第二个参数是否显示tab 如果没有,则显示,如果有,则根据第二个参数 function HeroPreviewPanel:OnOpen(...) this.AllWeightTemp = {} this.heroGrid.transform.anchoredPosition = Vector2.New(0, 0) this.elementGrid.transform.anchoredPosition = Vector2.New(0, 0) local temp = { ... } if temp and temp[1] ~= nil then this.heroScroll:SetActive(temp[1]) this.elementScroll:SetActive(not temp[1]) this.tabBox:SetActive(temp[1]) end if temp[1] then --英雄招募 if #temp == 1 or temp[2] then this.TabCtrl = TabBox.New() this.TabCtrl:SetTabAdapter(this.TabAdapter) this.TabCtrl:SetChangeTabCallBack(this.SwitchView) this.TabCtrl:Init(this.tabBox, _TabData, temp[3] or 1) else this.tabBox:SetActive(temp[2]) this.SwitchView(4) end else if RecruitManager.isFirstEnterElementScroll then --元素 RecruitManager.isFirstEnterElementScroll = false for i, v in pairs(RecruitManager.previewElementData) do local chipId = v.Reward[1] local heroId = HeroManager.ChipIdToHeroId(chipId) if not heroId or HeroManager.InVersion(heroId) then local allWeight = this.GetAllWeight(v.Pool) if (v.Pool == 11) then local view = SubUIManager.Open(SubUIConfig.ItemView, this.waterGrid.transform) view:OnOpen(false, { v.Reward[1], v.Reward[2] }, 1.1, true) view.name:GetComponent("Text").text = "" .. string.format("%.2f", (v.WeightShow / allWeight) * 100) .. "%" elseif (v.Pool == 12) then local view = SubUIManager.Open(SubUIConfig.ItemView, this.fireGrid.transform) view:OnOpen(false, { v.Reward[1], v.Reward[2] }, 1.1, true) view.name:GetComponent("Text").text = "" .. string.format("%.2f", (v.WeightShow / allWeight) * 100) .. "%" elseif (v.Pool == 13) then local view = SubUIManager.Open(SubUIConfig.ItemView, this.windyGrid.transform) view:OnOpen(false, { v.Reward[1], v.Reward[2] }, 1.1, true) view.name:GetComponent("Text").text = "" .. string.format("%.2f", (v.WeightShow / allWeight) * 100) .. "%" elseif (v.Pool == 14) then local view = SubUIManager.Open(SubUIConfig.ItemView, this.groundGrid.transform) view:OnOpen(false, { v.Reward[1], v.Reward[2] }, 1.1, true) view.name:GetComponent("Text").text = "" .. string.format("%.2f", (v.WeightShow / allWeight) * 100) .. "%" end end end this.elementScroll:SetActive(true) this.tabBox:SetActive(false) end end end function this.GetAllWeight(pool) if not this.AllWeightTemp[pool] then this.AllWeightTemp[pool] = RecruitManager.GetAllWeightByPool(pool) end return this.AllWeightTemp[pool] end function HeroPreviewPanel:OnShow() end function HeroPreviewPanel:OnClose() end function HeroPreviewPanel:OnDestroy() this.spLoader:Destroy() this.List1 = {} this.List2 = {} this.List3 = {} this.List4 = {} this.List5 = {} itemList = {} RecruitManager.isFirstEnterElementScroll = true RecruitManager.isFirstEnterHeroScroll = true end -- tab节点显示自定义 function this.TabAdapter(tab, index, status) local tabLab = Util.GetGameObject(tab, "Text") Util.GetGameObject(tab, "Image"):GetComponent("Image").sprite = this.spLoader:LoadSprite(_TabData[index][status]) tabLab:GetComponent("Text").text = _TabData[index].name tabLab:GetComponent("Text").color = _TabFontColor[status] end --切换视图 function this.SwitchView(index) local oldSelect oldSelect, curIndex = curIndex, index this.heroScrollGrid.transform:DOAnchorPosY(0, 0) local oneData = {} local twoData = {} local threeData = {} local fourData = {} local fiveData = {} for index, v in ipairs(RecruitManager.GetRewardPreviewData(dataType[curIndex])) do if itemConfig[v.Reward[1]].HeroStar[2] == 1 then table.insert(oneData, v) elseif itemConfig[v.Reward[1]].HeroStar[2] == 2 then table.insert(twoData, v) elseif itemConfig[v.Reward[1]].HeroStar[2] == 3 then table.insert(threeData, v) elseif itemConfig[v.Reward[1]].HeroStar[2] == 4 then table.insert(fourData, v) elseif itemConfig[v.Reward[1]].HeroStar[2] == 5 then table.insert(fiveData, v) end end if index == 3 then for i = 1, #oneData do if not this.List1[i] then this.List1[i] = SubUIManager.Open(SubUIConfig.ItemView, this.oneGrid.transform) end this.List1[i]:OnOpen(false, { oneData[i].Reward[1], oneData[i].Reward[2] }, 1.1, true) this.List1[i].name:GetComponent("Text").text = "" .. string.format("%.2f", (oneData[i].WeightShow / 100000) * 100) .. "%" this.List1[i].gameObject:SetActive(true) end end if index == 2 or index == 3 then for i = 1, #twoData do if not this.List2[i] then this.List2[i] = SubUIManager.Open(SubUIConfig.ItemView, this.twoGrid.transform) end this.List2[i]:OnOpen(false, { twoData[i].Reward[1], twoData[i].Reward[2] }, 1.1, true) this.List2[i].name:GetComponent("Text").text = "" .. string.format("%.2f", (twoData[i].WeightShow / 100000) * 100) .. "%" this.List2[i].gameObject:SetActive(true) end end for i = 1, #this.List3 do if this.List3[i] then this.List3[i].gameObject:SetActive(false) end end for i = 1, #threeData do if not this.List3[i] then this.List3[i] = SubUIManager.Open(SubUIConfig.ItemView, this.threeGrid.transform) this.List3[i].gameObject:SetActive(true) end this.List3[i]:OnOpen(false, { threeData[i].Reward[1], threeData[i].Reward[2] }, 1.1, true) this.List3[i].name:GetComponent("Text").text = "" .. string.format("%.2f", (threeData[i].WeightShow / 100000) * 100) .. "%" this.List3[i].gameObject:SetActive(true) end for i = 1, #this.List4 do if this.List4[i] then this.List4[i].gameObject:SetActive(false) end end for i = 1, #fourData do if not this.List4[i] then this.List4[i] = SubUIManager.Open(SubUIConfig.ItemView, this.fourGrid.transform) this.List4[i].gameObject:SetActive(true) end this.List4[i]:OnOpen(false, { fourData[i].Reward[1], fourData[i].Reward[2] }, 1.1, true) this.List4[i].name:GetComponent("Text").text = "" .. string.format("%.2f", (fourData[i].WeightShow / 100000) * 100) .. "%" this.List4[i].gameObject:SetActive(true) end for i = 1, #this.List5 do if this.List5[i] then this.List5[i].gameObject:SetActive(false) end end for i = 1, #fiveData do if not this.List5[i] then this.List5[i] = SubUIManager.Open(SubUIConfig.ItemView, this.fiveGrid.transform) this.List5[i].gameObject:SetActive(true) end this.List5[i]:OnOpen(false, { fiveData[i].Reward[1], fiveData[i].Reward[2] }, 1.1, true) this.List5[i].name:GetComponent("Text").text = "" .. string.format("%.2f", (fiveData[i].WeightShow / 100000) * 100) .. "%" this.List5[i].gameObject:SetActive(true) end this.starGridSwitch(index) end function this.starGridSwitch(index) if index == 1 or index == 4 then this.oneStarNum:SetActive(false) this.oneGrid:SetActive(false) this.twoStarNum:SetActive(false) this.twoGrid:SetActive(false) elseif index == 2 then this.oneStarNum:SetActive(false) this.oneGrid:SetActive(false) this.twoStarNum:SetActive(true) this.twoGrid:SetActive(true) else this.oneStarNum:SetActive(true) this.oneGrid:SetActive(true) this.twoStarNum:SetActive(true) this.twoGrid:SetActive(true) end end return HeroPreviewPanel