require("Base/BasePanel") XiaoyaoGetItemPopup = Inherit(BasePanel) local this=XiaoyaoGetItemPopup local itemConfig=ConfigManager.GetConfig(ConfigName.ItemConfig) local FreeTravelStore=ConfigManager.GetConfig(ConfigName.FreeTravelStore) local HeroConfig = ConfigManager.GetConfig(ConfigName.HeroConfig) local artResourceConfig = ConfigManager.GetConfig(ConfigName.ArtResourcesConfig) local propertyConfig = ConfigManager.GetConfig(ConfigName.PropertyConfig) local curHeroData = {} local curIndex = 1 local heroData = {} local pointPrefabs = {} local allSkillDatas = {} local costId = 0 local costNum = 0 local heroSData local itemView --初始化组件(用于子类重写) function XiaoyaoGetItemPopup:InitComponent() this.spLoader = SpriteLoader.New() this.titleText = Util.GetGameObject(self.transform, "Panel/bg/title"):GetComponent("Text") this.BtnBack=Util.GetGameObject(self.transform, "Panel/bg/btnBack") this.remainTimes = Util.GetGameObject(self.transform, "Panel/remainTimes"):GetComponent("Text") this.costIcon=Util.GetGameObject(self.transform,"Panel/buyPanel/item/proImage/proImage"):GetComponent("Image") this.costNum=Util.GetGameObject(self.transform,"Panel/buyPanel/item/heroName"):GetComponent("Text") this.buyBtn = Util.GetGameObject(self.transform,"Panel/buyPanel/buy") this.itemPar=Util.GetGameObject(self.transform,"Panel/bg/itemPar") this.pointGrid = Util.GetGameObject(self.transform,"Panel/buyPanel/grid") this.point = Util.GetGameObject(self.transform,"Panel/buyPanel/point") this.selectKuang = Util.GetGameObject(self.transform,"Panel/buyPanel/select") this.leftBtn= Util.GetGameObject(self.transform,"Panel/leftBtn") this.rightBtn = Util.GetGameObject(self.transform,"Panel/rightBtn") this.zhekouImage = Util.GetGameObject(self.transform,"Panel/buyPanel/Image"):GetComponent("Image") itemView = SubUIManager.Open(SubUIConfig.ItemView, this.itemPar.transform) end local triggerCallBack --绑定事件(用于子类重写) function XiaoyaoGetItemPopup:BindEvent() Util.AddClick(this.BtnBack, function() PlaySoundWithoutClick(SoundConfig.Sound_UICancel) self:ClosePanel() end) Util.AddClick(this.rightBtn, function() curIndex = curIndex + 1 if curIndex > #heroData then curIndex = 1 end curHeroData = heroData[curIndex] this:SetSelectHero(curHeroData) end) Util.AddClick(this.leftBtn, function() curIndex = curIndex - 1 if curIndex < 1 then curIndex = #heroData end curHeroData = heroData[curIndex] this:SetSelectHero(curHeroData) end) Util.AddClick(this.buyBtn, function(msg) if BagManager.GetItemCountById(costId) < costNum then PopupTipPanel.ShowTip(GetLanguageStrById(itemConfig[costId].Name)..Language[10657]) else local rightAction = function() NetManager.XiaoyaoyouGetHeroRequest(curHeroData.goodsIndex,function(msg) XiaoYaoManager.UpdateHeroData(curHeroData.goodsIndex) XiaoYaoManager.GetHeroIndex = 0 this:OnShow() UIManager.OpenPanel(UIName.RewardItemPopup, msg.drop,1) end) end MsgPanel.ShowTwo(Language[11999]..costNum..""..GetLanguageStrById(itemConfig[costId].Name)..Language[12000]..GetLanguageStrById(heroSData.Name).."]?", nil, rightAction, Language[10731], Language[10732], Language[12001],false,"") end end) end --添加事件监听(用于子类重写) function XiaoyaoGetItemPopup:AddListener() end --移除事件监听(用于子类重写) function XiaoyaoGetItemPopup:RemoveListener() end function this.CalculateHeroAllProValList(heroConFigData,_starNum,isCalculateStarVal) local allAddProVal = {} for i, v in ConfigPairs(propertyConfig) do allAddProVal[i] = 0 end local heroRankupConfig = ConfigManager.GetConfigDataByDoubleKey(ConfigName.HeroRankupConfig, "Star", heroConFigData.Star, "LimitStar", _starNum) local curLvNum=1 local breakId = 0 local upStarId = 0 if isCalculateStarVal then --等级 curLvNum = heroRankupConfig.OpenLevel --解锁天赋 for i, v in ConfigPairs(ConfigManager.GetConfig(ConfigName.HeroRankupConfig)) do if v.OpenStar == _starNum and v.Star==heroConFigData.Star then if v.Type == 1 then breakId = v.Id end if v.Type == 2 then upStarId = v.Id end end end if breakId==0 then breakId=6 end end allAddProVal[HeroProType.Attack]=HeroManager.CalculateProVal(heroConFigData.Attack, curLvNum, breakId,upStarId,HeroProType.Attack) allAddProVal[HeroProType.Hp]=HeroManager.CalculateProVal(heroConFigData.Hp, curLvNum, breakId,upStarId,HeroProType.Hp) allAddProVal[HeroProType.PhysicalDefence]=HeroManager.CalculateProVal(heroConFigData.PhysicalDefence, curLvNum, breakId,upStarId,HeroProType.PhysicalDefence) allAddProVal[HeroProType.MagicDefence]=HeroManager.CalculateProVal(heroConFigData.MagicDefence, curLvNum, breakId,upStarId,HeroProType.MagicDefence) Util.AddOnceClick(this.talentBtn,function() UIManager.OpenPanel(UIName.RoleTalentPopup,heroConFigData,breakId,upStarId) end) if heroConFigData.OpenPassiveSkillRules then local openlists,compoundOpenNum,compoundNum = HeroManager.GetAllPassiveSkillIds(heroConFigData,breakId,upStarId) this.talentProgress.text = #openlists - compoundOpenNum .."/"..#heroConFigData.OpenPassiveSkillRules - compoundNum end return allAddProVal end --界面打开时调用(用于子类重写) function XiaoyaoGetItemPopup:OnOpen() this.titleText = "东海寻仙" end function XiaoyaoGetItemPopup:OnShow() curIndex = XiaoYaoManager.GetHeroIndex < 1 and 1 or XiaoYaoManager.GetHeroIndex heroData = XiaoYaoManager.GetHeroDatas() if not heroData or #heroData < 1 then this:ClosePanel() return end curHeroData = heroData[curIndex] for i = 1 , #pointPrefabs do pointPrefabs[i].gameObject:SetActive(false) end for i = 1 , #heroData do if not pointPrefabs[i] then pointPrefabs[i] = newObjToParent(this.point,this.pointGrid) end pointPrefabs[i].gameObject:SetActive(true) end this:SetSelectHero(curHeroData) end function this:TimerDown() if this.timer then this.timer:Stop() this.timer = nil end local timeDown = curHeroData.remainTime - PlayerManager.serverTime local temp = 0 this.remainTimes.text = Language[10023]..TimeToHMS(timeDown) this.timer = Timer.New(function() if timeDown < 1 then XiaoYaoManager.GetHeroIndex = 0 this:OnShow() return end for i = 1 , #heroData do temp = heroData[i].remainTime - PlayerManager.serverTime if temp < 1 then this:OnShow() return end end timeDown = timeDown - 1 this.remainTimes.text = Language[10023]..TimeToHMS(timeDown) end, 1, -1, true) this.timer:Start() end function this:SetSelectHero(curHeroData) --LogGreen("curHeroData.goodsId :"..curHeroData.goodsId) local heroSId = FreeTravelStore[curHeroData.goodsId].Goods[1] heroSData = itemConfig[heroSId] itemView:OnOpen(false, { heroSId, 1 }, 0.97,false,false,false,self.sortingOrder) -- local heroStar = heroSData.Star -- allSkillDatas = HeroManager.GetCurHeroSidAndCurStarAllSkillDatas(heroSId,heroStar) this.selectKuang.transform:SetParent(pointPrefabs[curIndex].transform) this.selectKuang:GetComponent("RectTransform").localPosition = Vector3.zero this.ShowHeroBuyInfo(curHeroData) this:TimerDown() end function this.ShowHeroBuyInfo(_heroSConfigData) local heroBuyInfo = FreeTravelStore[curHeroData.goodsId] costId = heroBuyInfo.Cost[1] costNum = heroBuyInfo.Cost[2] this.costIcon.sprite = this.spLoader:LoadSprite(artResourceConfig[itemConfig[costId].ResourceID].Name) if BagManager.GetItemCountById(costId) < costNum then this.costNum.text = "" .. costNum .. "" else this.costNum.text = "" .. costNum .. "" end this.zhekouImage.sprite = this.spLoader:LoadSprite(heroBuyInfo.Discount) end --界面关闭时调用(用于子类重写) function XiaoyaoGetItemPopup:OnClose() Game.GlobalEvent:DispatchEvent(GameEvent.XiaoYao.RefreshEventShow) if this.testLiveGO then poolManager:UnLoadLive(this.testLiveGO.name, this.testLiveGO) this.testLiveGO = nil end if this.timer then this.timer:Stop() this.timer = nil end end --界面销毁时调用(用于子类重写) function XiaoyaoGetItemPopup:OnDestroy() this.spLoader:Destroy() if this.testLiveGO then poolManager:UnLoadLive(this.testLiveGO.name, this.testLiveGO) this.testLiveGO = nil end if this.timer then this.timer:Stop() this.timer = nil end pointPrefabs = {} SubUIManager.Close(itemView) itemView=nil end return XiaoyaoGetItemPopup