require("Base/BasePanel") LikeAbilityPanel = Inherit(BasePanel) --全体生命 --白色 --特权--橙色 --总好感度属性: --黄色 --+500 --绿色 local sortOrder = 0 local tabs = {} local tabsImg = {"z_icon_01_zh", "r_hero_huo 1_zh", "r_hero_feng 1_zh", "r_hero_shui 1_zh", "r_hero_dadi 1_zh"} local proId = 0 local heroData = {} function LikeAbilityPanel:InitComponent() self.spLoader = SpriteLoader.New() self.help = Util.GetGameObject(self.transform, "help") self.helpPos = self.help:GetComponent("RectTransform").localPosition self.btnBack = Util.GetGameObject(self.transform, "btnBack") self.heroGrid = Util.GetGameObject(self.transform, "heroScroll") self.heroPre = Util.GetGameObject(self.transform, "heroPre") local v = self.heroGrid:GetComponent("RectTransform").rect self.heroScroll = SubUIManager.Open(SubUIConfig.ScrollCycleView,self.heroGrid.transform,self.heroPre, nil, Vector2.New(v.width, v.height), 1, 4, Vector2.New(50,50)) self.btnPrant = Util.GetGameObject(self.gameObject, "Tabs") for i = 0, 4 do tabs[i] = Util.GetGameObject(self.btnPrant,"grid/Btn" .. i) if tabsImg[i + 1] then Util.GetGameObject(tabs[i], "Image"):GetComponent("Image").sprite = self.spLoader:LoadSprite(tabsImg[i + 1]) end end self.selectBtn = Util.GetGameObject(self.btnPrant, "selectBtn") self.likeabilityBtn = Util.GetGameObject(self.gameObject, "likeabilityBtn") self.likeabilityDi = Util.GetGameObject(self.likeabilityBtn, "di"):GetComponent("Image") --h_haogandu_1 h_haogandu_2 h_haogandu_3 self.likeabilitymask = Util.GetGameObject(self.likeabilityDi.transform, "mask"):GetComponent("Image") --self.likeabilitymask.fillAmount self.lv = Util.GetGameObject(self.likeabilityBtn, "lv"):GetComponent("Text") self.progress = Util.GetGameObject(self.likeabilityBtn, "progress"):GetComponent("Text") self.pro = Util.GetGameObject(self.transform, "di/pro") self.proContent = Util.GetGameObject(self.pro, "content") self.proGrid = Util.GetGameObject(self.transform, "di/proScroll") self.proList = {} self.noneGo = Util.GetGameObject(self.transform, "NoneImage") end function LikeAbilityPanel:BindEvent() for i = 0, 4 do Util.AddClick(tabs[i], function() if i == proId then proId = ProIdConst.All else proId = i end heroData = LikabilityManager.GetCurSortHeroListData(proId) self:SetSelectBtn() self:UpdataHeroDataPanel() end) end Util.AddClick(self.btnBack, function() self:ClosePanel() end) Util.AddClick(self.help, function() UIManager.OpenPanel(UIName.HelpPopup,HELP_TYPE.Likeability,self.helpPos.x, self.helpPos.y) end) Util.AddClick(self.likeabilityBtn, function() UIManager.OpenPanel(UIName.LikeabilityPopup) end) end --添加事件监听(用于子类重写) function LikeAbilityPanel:AddListener() end --移除事件监听(用于子类重写) function LikeAbilityPanel:RemoveListener() end function LikeAbilityPanel:OnSortingOrderChange() end function LikeAbilityPanel:OnOpen() end function LikeAbilityPanel:OnShow() heroData = LikabilityManager.GetCurSortHeroListData(proId) self:SetSelectBtn() self:UpdataHeroDataPanel() self:UpdateTopLayoutPanel() end function LikeAbilityPanel:UpdateTopLayoutPanel() local num,lv,totalNum = LikabilityManager.GetTotalHeroLikeLv(-1) local config = ConfigManager.GetConfigDataByDoubleKey(ConfigName.LikeAbility,"Type",1,"Level",lv) self.likeabilityDi.sprite = self.spLoader:LoadSprite(config.Bg) self.lv.text = lv if not totalNum or totalNum <= 0 then self.likeabilitymask.fillAmount = 1 self.progress.text = "好感度最佳" else self.likeabilitymask.fillAmount = num/totalNum self.progress.text = string.format("%s/%s",num,totalNum) end self:UpDataProList(lv) end function LikeAbilityPanel:UpDataProList(lv) local pro1 = LikabilityManager.GetViewProData(1,-1,lv,"总好感度属性:","","全体%s 全体%s","",nil) local pro2 = LikabilityManager.GetViewProData(1,lv,lv,"当前等级加成:","","属性:%s %s","特权:%s",nil) for i = 1,#self.proList do self.proList[i].go.gameObject:SetActive(false) end self:UpDataProSingleList(pro1,1) self:UpDataProSingleList(pro2,2) end function LikeAbilityPanel:UpDataProSingleList(data,index) if not self.proList[index] then self.proList[index] = {} self.proList[index].go = newObjToParent(self.pro,self.proGrid) self.proList[index].title = Util.GetGameObject(self.proList[index].go, "title"):GetComponent("Text") end self.proList[index].go.gameObject:SetActive(true) self.proList[index].title.text = data.content for i = 1,math.max(#self.proList[index],#data.prolist) do if not data.prolist[i] then self.proList[index][i].go.gameObject:SetActive(false) else if not self.proList[index][i] then self.proList[index][i] = {} self.proList[index][i].go = newObjToParent(self.proContent,self.proList[index].go) self.proList[index][i].goText = self.proList[index][i].go:GetComponent("Text") end if data.prolist[i] == "" then self.proList[index][i].go.gameObject:SetActive(false) else self.proList[index][i].go.gameObject:SetActive(true) self.proList[index][i].goText.text = data.prolist[i] end end end end function LikeAbilityPanel:UpdataHeroDataPanel() if not heroData or #heroData < 1 then self.noneGo.gameObject:SetActive(true) self.heroScroll.gameObject:SetActive(false) else self.noneGo.gameObject:SetActive(false) self.heroScroll.gameObject:SetActive(true) end self.heroScroll:ForeachItemGO(function(index,go) go.gameObject:SetActive(false) end) self.heroScroll:SetData(heroData, function (index, go) self:SingleHeroDataShow(go, heroData[index]) end) end function LikeAbilityPanel:SingleHeroDataShow(_go,data) local card = Util.GetGameObject(_go.transform, "card") local bg = Util.GetGameObject(card, "bg") local icon = Util.GetGameObject(card, "icon"):GetComponent("Image") icon.sprite = self.spLoader:LoadSprite(GetResourcePath(data.Painting)) SetHeroBg(self.spLoader,card ,bg ,data.Star,data.Quality) local pro = Util.GetGameObject(_go.transform, "card/pro/Image"):GetComponent("Image") pro.sprite = self.spLoader:LoadSprite(GetProStrImageByProNum(data.PropertyName)) local choose = Util.GetGameObject(card, "choosed") choose.gameObject:SetActive(false) local num,lv,totalNum = LikabilityManager.GetTotalHeroLikeLv(data.Id) local level = Util.GetGameObject(card, "likeability/lv"):GetComponent("Text") level.text = lv Util.AddOnceClick(card, function() UIManager.OpenPanel(UIName.HeroLikeAbilityPanel,data) end) end function LikeAbilityPanel:SetSelectBtn() self.selectBtn.transform:SetParent(tabs[proId].transform) self.selectBtn:GetComponent("RectTransform").localPosition = Vector3.zero end function LikeAbilityPanel:OnClose() end --界面销毁时调用(用于子类重写) function LikeAbilityPanel:OnDestroy() self.spLoader:Destroy() self.proList = {} end return LikeAbilityPanel