require("Base/BasePanel") SelfRewardPanel = Inherit(BasePanel) local SelfRecruitPanel = require("Modules/SelfRecruit/SelfRecruit") local this = SelfRewardPanel local ChosenPoolConfig = ConfigManager.GetConfig(ConfigName.ChosenPoolConfig) local artResourcesConfig = ConfigManager.GetConfig(ConfigName.ArtResourcesConfig) local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig) local choosedList = {} local firstChoosedList = {} local curFormationIndex local order = 0 local selectHeroData = {} --local sortType = 1 -- 1:品阶 2:等级 local proId = 0--0 全部 1 火 2风 3 水 4 地 local tabs = {}--筛选按钮 local goList = {} --当前英雄对应预设的集合 local func = nil --回调 local heroConfig = ConfigManager.GetConfig(ConfigName.HeroConfig) function SelfRewardPanel:InitComponent() this.BgMask = Util.GetGameObject(this.gameObject, "BgMask") this.BtnBack = Util.GetGameObject(this.gameObject, "btnBack") -- this.BtnSure = Util.GetGameObject(this.gameObject, "bg/btnSure") -- this.allBtn = Util.GetGameObject(this.gameObject,"bg/allBtn") this.confirmBtn = Util.GetGameObject(this.gameObject, "bg/confirmBtn") this.confirmBtnText = Util.GetGameObject(this.gameObject, "bg/confirmBtn/TextTips"):GetComponent("Text") this.buyConfirmBtn = Util.GetGameObject(this.gameObject, "bg/buyConfirmBtn") this.buyConfirmBtnNum = Util.GetGameObject(this.gameObject, "bg/buyConfirmBtn/Text"):GetComponent("Text") this.buyConfirmBtnIcon = Util.GetGameObject(this.gameObject, "bg/buyConfirmBtn/Icon"):GetComponent("Image") this.cardPre = Util.GetGameObject(this.gameObject, "item") this.grid = Util.GetGameObject(this.gameObject, "bg/scroll") --筛选按钮 for i = 0, 5 do tabs[i] = Util.GetGameObject(this.gameObject, "bg/Tabs/Grid/Btn" .. i) end this.selectBtn = Util.GetGameObject(this.gameObject, "bg/Tabs/SelectBtn") -- this.ShaiXuanBtn = Util.GetGameObject(self.gameObject, "bg/ShaiXuanBtn") -- this.ShaiXuanBtnLv = Util.GetGameObject(self.gameObject, "bg/ShaiXuanBtn/Lv") -- this.ShaiXuanBtnQu = Util.GetGameObject(self.gameObject, "bg/ShaiXuanBtn/Qu") this.ScrollBar = Util.GetGameObject(self.gameObject, "bg/Scrollbar"):GetComponent("Scrollbar") local scroll = Util.GetGameObject(self.gameObject, "scroll").transform local rect = scroll.rect this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, scroll, this.cardPre, this.ScrollBar, Vector2.New(rect.width, rect.height), 1, 5, Vector2.New(5, 5)) this.ScrollView.moveTween.MomentumAmount = 1 this.ScrollView.moveTween.Strength = 1 end function SelfRewardPanel:BindEvent() Util.AddClick(this.BtnBack, function() PlaySoundWithoutClick(SoundConfig.Sound_UICancel) if func then func(choosedList) end self:ClosePanel() end) Util.AddClick(this.BgMask, function() PlaySoundWithoutClick(SoundConfig.Sound_UICancel) if func then func(choosedList) end self:ClosePanel() end) --选定按钮 Util.AddClick(this.confirmBtn, function() local Data = {} for index, value in ipairs(choosedList) do table.insert(Data,value.did) end NetManager.SelfSelectChangeHeroRequest(Data,510001, function() if func then func(choosedList) end PlaySoundWithoutClick(SoundConfig.Sound_UICancel) self:ClosePanel() end) end) --选定按钮 Util.AddClick(this.buyConfirmBtn, function() local selectData = {} for index, value in ipairs(choosedList) do table.insert(selectData,value.did) end local Data={} for index, value in ConfigPairs(ChosenPoolConfig) do if value.ActivityId == 510001 then Data = value end end if BagManager.GetItemCountById(Data.ChangeCost[1]) < Data.ChangeCost[2] then PopupTipPanel.ShowTipByLanguageId(50384) return end NetManager.SelfSelectChangeHeroRequest(selectData, 510001, function() if func then func(choosedList) end PlaySoundWithoutClick(SoundConfig.Sound_UICancel) self:ClosePanel() end) end) --筛选按钮 for i = 0, 5 do Util.AddClick(tabs[i], function() if i == proId then proId = ProIdConst.All else proId = i end this:OnClickTabBtn(proId) end) end end function SelfRewardPanel:AddListener() end function SelfRewardPanel:RemoveListener() end function SelfRewardPanel:RefreshSelectHeroText() this.confirmBtnText.text = string.format(GetLanguageStrById(50383),#choosedList) end --设置确认按钮状态 function SelfRewardPanel:SetConfirmBtnState() Util.SetGray(self.confirmBtn, true) self.confirmBtn:GetComponent("Button").enabled = false Util.SetGray(self.buyConfirmBtn, true) self.buyConfirmBtn:GetComponent("Button").enabled = false if #firstChoosedList > 0 then --判断数据 self.confirmBtn:SetActive(false) self.buyConfirmBtn:SetActive(true) local Data = {} for index, value in ConfigPairs(ChosenPoolConfig) do if value.ActivityId == 510001 then Data = value break end end local resId = itemConfig[Data.ChangeCost[1]].ResourceID local imgsprite = artResourcesConfig[resId].Name --消耗资源img 名字 this.buyConfirmBtnIcon.sprite = Util.LoadSprite(imgsprite) this.buyConfirmBtnNum.text = Data.ChangeCost[2] else self.confirmBtn:SetActive(true) self.buyConfirmBtn:SetActive(false) end end function SelfRewardPanel:OnOpen(selectData,_fun) for key, value in pairs(selectData) do table.insert(firstChoosedList,value.did) end func = _fun choosedList = {}--selectData order = 0 proId = ProIdConst.All this:OnClickTabBtn(proId) --首次选择全部 this:SetConfirmBtnState() this:RefreshSelectHeroText() end function SelfRewardPanel:OnClose() firstChoosedList = {} choosedList = {} func = nil end function SelfRewardPanel:OnDestroy() this.ScrollView = nil end --点击页签__根据sortType和职业属性/类型进行排序 function this:OnClickTabBtn(_proId) --设置可选择英雄 local heros = HeroManager.GetSelfRewardHeroData(_proId, 510001) this:SetRoleList(heros) this:SetSelectBtn() end --设置英雄列表数据 function this:SetRoleList(_roleDatas) -- this:SortHeroDatas(_roleDatas) -- if sortType == SortTypeConst.Natural then -- table.sort(_roleDatas,function(a,b) -- local aWarPower = HeroManager.CalculateHeroAllProValList(1,a.dynamicId,false)[HeroProType.WarPower] -- local bWarPower = HeroManager.CalculateHeroAllProValList(1,b.dynamicId,false)[HeroProType.WarPower] -- if a.Quality == b.Quality then -- return aWarPower > bWarPower -- else -- return a.Quality > b.Quality -- end -- end) -- end local allData = {} for index, value in pairs(_roleDatas) do if value ~= nil then table.insert(allData,value) end end goList = {} this.ScrollView:SetData(allData, function(index, go) this:SingleHeroDataShow(go, allData[index]) end) end --设置单个英雄数据 function this:SingleHeroDataShow(_go, _heroData) local heroData = _heroData local HeroConfig = {} for index, value in ConfigPairs(heroConfig) do if heroData.HeroID == value.Id then HeroConfig = value break end end local go = _go goList[heroData.HeroID] = go local choosed = Util.GetGameObject(go, "choosed") choosed:SetActive(false) local select = Util.GetGameObject(go, "select") select:SetActive(false) for i,v in ipairs(choosedList) do if heroData.HeroID == v.did then choosed:SetActive(true) select:SetActive(true) end end Util.GetGameObject(go, "frame"):GetComponent("Image").sprite = Util.LoadSprite(GetHeroQuantityImageByquality(HeroConfig.Quality,HeroConfig.Star)) Util.GetGameObject(go, "icon"):GetComponent("Image").sprite = Util.LoadSprite(HeroConfig.Icon) -- Util.GetGameObject(go, "lv/Text"):GetComponent("Text").text = heroData.lv Util.GetGameObject(go, "icon"):GetComponent("Image").sprite = Util.LoadSprite(GetResourcePath(HeroConfig.Icon)) Util.GetGameObject(go, "proIcon"):GetComponent("Image").sprite = Util.LoadSprite(GetProStrImageByProNum(HeroConfig.PropertyName)) Util.GetGameObject(go, "proBg"):GetComponent("Image").sprite = Util.LoadSprite(GetQuantityProBgImageByquality(HeroConfig.Quality,HeroConfig.Star)) Util.GetGameObject(go, "lv"):GetComponent("Image").sprite = Util.LoadSprite(GetQuantityImageByqualityHexagon(HeroConfig.Quality,HeroConfig.Star)) local starGrid = Util.GetGameObject(go, "star") local name = Util.GetGameObject(go.transform, "name"):GetComponent("Text") name.text = GetLanguageStrById(HeroConfig.ReadingName) SetHeroStars(starGrid, HeroConfig.Star) --判断图鉴是否拥有 if heroData.IsOwn == 1 then if PlayerManager.heroHandBook and PlayerManager.heroHandBook[HeroConfig.Id] then Util.GetGameObject(go, "NoHeroMask"):SetActive(false) go.gameObject:GetComponent("Button").enabled = true else Util.GetGameObject(go, "NoHeroMask"):SetActive(true) go.gameObject:GetComponent("Button").enabled = false end else Util.GetGameObject(go, "NoHeroMask"):SetActive(false) go.gameObject:GetComponent("Button").enabled = true end -- 点击事件设置 Util.AddOnceClick(go, function() for k, v in ipairs(choosedList) do if v.did == heroData.HeroID then SelfRewardPanel:SetBtnGray(true,false) --选择的条目已存在,移除选择的item choosed:SetActive(false) select:SetActive(false) table.remove(choosedList,k) this:OnClickTabBtn(proId) self:RefreshSelectHeroText() return end end if #choosedList >= 3 then PopupTipPanel.ShowTipByLanguageId(50386) return end if heroData.IsOnly == 1 then for _k, _v in ipairs(choosedList) do local Data = HeroManager.GetOneHeroData(510001, _v.did) if Data.IsOnly == 1 then PopupTipPanel.ShowTipByLanguageId(50385) return end end end choosed:SetActive(true) select:SetActive(true) table.insert(choosedList, {did = heroData.HeroID, choosed = choosed}) this:OnClickTabBtn(proId) --choosedList[heroData.HeroID] = choosed self:RefreshSelectHeroText() local isChangeNum = 0 if #choosedList>=3 then for key, value in pairs(choosedList) do for ke, va in pairs(firstChoosedList) do if value.did == va then isChangeNum = isChangeNum + 1 end end end if isChangeNum >= 3 then SelfRewardPanel:SetBtnGray(true,false) else SelfRewardPanel:SetBtnGray(false,true) end else SelfRewardPanel:SetBtnGray(true,false) end end) -- Util.AddLongPressClick(go, function() -- UIManager.OpenPanel(UIName.RoleInfoPopup, heroData) -- end, 0.5) end function SelfRewardPanel:SetBtnGray(isGray,isEnabled) Util.SetGray(self.confirmBtn, isGray) self.confirmBtn:GetComponent("Button").enabled = isEnabled Util.SetGray(self.buyConfirmBtn, isGray) self.buyConfirmBtn:GetComponent("Button").enabled = isEnabled end -- function this:SortHeroDatas(_heroDatas) -- local choosed = {} -- local dieHeros = {} -- for i = 1, #_heroDatas do -- local heroHp = FormationManager.GetFormationHeroHp(curFormationIndex, _heroDatas[i].dynamicId) -- if heroHp then -- if heroHp <= 0 then -- dieHeros[_heroDatas[i].dynamicId] = _heroDatas[i].dynamicId -- end -- end -- end -- table.sort(_heroDatas, function(a, b) -- if (choosed[a.dynamicId] and choosed[b.dynamicId]) or -- (not choosed[a.dynamicId] and not choosed[b.dynamicId]) -- then -- if (dieHeros[a.dynamicId] and dieHeros[b.dynamicId]) or -- (not dieHeros[a.dynamicId] and not dieHeros[b.dynamicId]) -- then -- if sortType == SortTypeConst.Natural then -- if a.heroConfig.Natural == b.heroConfig.Natural then -- if a.heroConfig.Quality == b.heroConfig.Quality then -- if a.star == b.star then -- if a.lv == b.lv then -- if a.id == b.id then -- return a.sortId > b.sortId -- else -- return a.id > b.id -- end -- else -- return a.lv > b.lv -- end -- else -- return a.star > b.star -- end -- else -- return a.heroConfig.Quality > b.heroConfig.Quality -- end -- else -- return a.heroConfig.Natural > b.heroConfig.Natural -- end -- else -- if a.lv == b.lv then -- if a.heroConfig.Quality == b.heroConfig.Quality then -- if a.star == b.star then -- if a.heroConfig.Natural == b.heroConfig.Natural then -- if a.id == b.id then -- return a.sortId > b.sortId -- else -- return a.id > b.id -- end -- else -- return a.heroConfig.Natural > b.heroConfig.Natural -- end -- else -- return a.star > b.star -- end -- else -- return a.heroConfig.Quality > b.heroConfig.Quality -- end -- else -- return a.lv > b.lv -- end -- end -- else -- return not dieHeros[a.dynamicId] and dieHeros[b.dynamicId] -- end -- else -- return choosed[a.dynamicId] and not choosed[b.dynamicId] -- end -- end) -- end function this:SetSelectBtn() for key, value in pairs(tabs) do if key == proId then -- value:GetComponent("Image").sprite = Util.LoadSprite(CampTabSelectPic[key][2]) this.selectBtn.transform:SetParent(value.transform) this.selectBtn:GetComponent("RectTransform").localPosition = Vector3.zero this.selectBtn:GetComponent("RectTransform").localScale = Vector3.one else -- value:GetComponent("Image").sprite = Util.LoadSprite(CampTabSelectPic[key][1]) end end end return SelfRewardPanel