require("Base/BasePanel") HongMengEnvoyPanel = Inherit(BasePanel) HongMengEnvoyPanel.contents = { [1] = {view = require("Modules/Harmony/View/HarmonyScrllow"), panelName = " HongMengEnvoyPanel"} } HongMengEnvoyPanel.prefab = {} HongMengEnvoyPanel.EnvoyItemList = {} local Item = require("Modules/Harmony/EnvoyItem/EnvoyItem") local Gold = 0 local GrowthAmulet = 0 HongMengEnvoyPanel.timerEffect = nil --初始化组件(用于子类重写) function HongMengEnvoyPanel:InitComponent() self.btnBack = Util.GetGameObject(self.gameObject, "Back/BackBtn") self.helpBtn = Util.GetGameObject(self.gameObject, "HelpBtn") self.AddBtn = Util.GetGameObject(self.gameObject, "Panel/HarmonyPanel/AddBtn") self.GongMingBtn = Util.GetGameObject(self.gameObject, "Panel/HarmonyPanel/KnowGongMing") self.helpPosition = self.helpBtn:GetComponent("RectTransform").localPosition self.panel = Util.GetGameObject(self.gameObject, "Panel") self.towerText = Util.GetGameObject(self.gameObject, "Panel/HarmonyPanel/GradeText") self.NumText = Util.GetGameObject(self.gameObject, "Panel/HarmonyPanel/itemNumText"):GetComponent("Text") self.GradeText = Util.GetGameObject(self.gameObject, "Panel/HarmonyPanel/GradeText"):GetComponent("Text") self.imageGame = Util.GetGameObject(self.gameObject, "GameObject/imageGame") self.TextGame = Util.GetGameObject(self.gameObject, "GameObject/TextGame") self.UnShowText = Util.GetGameObject(self.gameObject, "GameObject/UnShowText") self.TextGold = Util.GetGameObject(self.gameObject, "GameObject/TextGame/TextGold"):GetComponent("Text") self.TextGrowthAmulet = Util.GetGameObject(self.gameObject, "GameObject/TextGame/TextHuFu"):GetComponent("Text") self.UpBtn = Util.GetGameObject(self.gameObject, "UpBtn") self.UpBtnRedPoint = Util.GetGameObject(self.gameObject,"UpBtn/RedPoint") local parent = Util.GetGameObject(self.gameObject, "Panel/HongMeng") local ItemPfb = Util.GetGameObject(self.gameObject, "Panel/HarmonyPanel/item") --初始化格子中的数据 HarmonyManager:InitGongMingDataList() HarmonyManager:SetTowerInit() self:InitEnvoyItemList(ItemPfb, parent) end function HongMengEnvoyPanel:InitEnvoyItemList(ItemPfb, parent) for i = 1, #HarmonyManager.hongmengGuards do -- bodys self.EnvoyItemList[i] = Item:New(newObject(ItemPfb)) self.EnvoyItemList[i]:InitComponent(parent, HarmonyManager.hongmengGuards[i]) end for i = 1, #self.contents do self.prefab[i] = Util.GetGameObject(self.panel, self.contents[i].panelName) self.contents[i].view:InitComponent( self.panel, BagManager.GetTotalItemNum(UpViewRechargeType.XuanHuangZhiQi), BagManager.GetTotalItemNum(UpViewRechargeType.DemonCrystal), 2 ) end end --绑定事件(用于子类重写) function HongMengEnvoyPanel:BindEvent() Util.AddClick( self.btnBack, function() self:ClosePanel() end ) Util.AddClick( self.helpBtn, function() UIManager.OpenPanel(UIName.HelpPopup, HELP_TYPE.HongMengZhen, self.helpPosition.x, self.helpPosition.y+500) end ) Util.AddClick( self.AddBtn, function() --二级弹窗界面 Game.GlobalEvent:DispatchEvent(GameEvent.HongMeng.OpenBoxTips) end ) --共鸣按钮 Util.AddClick( self.GongMingBtn, function() --二级共鸣弹窗 local count = HarmonyManager:IsEnvoyCount() LogGreen(count) if count > 6 then -- body UIManager.OpenPanel(UIName.GongMingResultTips) else PopupTipPanel.ShowTip("需要6名鸿蒙使者才可激活共鸣效果!") end --print("共鸣提示") end ) Util.AddClick( self.UpBtn, function() --二级共鸣弹窗 local sum = HarmonyManager:HongMengTowerUpLimit() if HarmonyManager.GetSingleAdditionsData(HarmonyAddType.AddLv).value >= sum then -- body PopupTipPanel.ShowTip("鸿蒙碑等级已达上限!") else local data = HarmonyManager:GetHongMengUpData() --print(data.LevelUp[1][2].." "..data.LevelUp[2][2]) if data == nil then -- body return end Gold = BagManager.GetTotalItemNum(UpViewRechargeType.Gold) GrowthAmulet = BagManager.GetTotalItemNum(UpViewRechargeType.GrowthAmulet) if Gold >= data.LevelUp[1][2] then -- body if GrowthAmulet >= data.LevelUp[2][2] then --print("升级成功") -- body HarmonyManager.SetOldPowerNum() NetManager.UpHongMengGrade( function() -- body LogGreen("回调函数") HarmonyManager.GetSingleAdditionsData(HarmonyAddType.AddLv).value = HarmonyManager.GetSingleAdditionsData(HarmonyAddType.AddLv).value + 1 if HarmonyManager.GetSingleAdditionsData(HarmonyAddType.AddLv).value >= sum then -- body Util.SetGray(self.UpBtn, true) self.imageGame:SetActive(false) self.TextGame:SetActive(false) self.UnShowText:SetActive(true) end local data = HarmonyManager:GetHongMengUpData() if Gold >= data.LevelUp[1][2] then -- body self.TextGold.text = string.format("%d",data.LevelUp[1][2]) if GrowthAmulet >= data.LevelUp[2][2] then self.TextGrowthAmulet.text = string.format("%d",data.LevelUp[2][2]) else self.TextGrowthAmulet.text = string.format("%d",data.LevelUp[2][2]) end else self.TextGold.text = string.format("%d",data.LevelUp[1][2]) LogGreen("变色!!!!!!!!!!!! "..data.LevelUp[1][2]) if GrowthAmulet >= data.LevelUp[2][2] then self.TextGrowthAmulet.text = string.format("%d",data.LevelUp[2][2]) else self.TextGrowthAmulet.text = string.format("%d",data.LevelUp[2][2]) end end local sum = HarmonyManager:HongMengTowerUpLimit() self.GradeText.text = string.format("%d/%d", HarmonyManager.GetSingleAdditionsData(HarmonyAddType.AddLv).value, sum) --检测红点 UpdateGongMingLv for i = 1, #self.EnvoyItemList do self.EnvoyItemList[i]:UpdateFun() end Game.GlobalEvent:DispatchEvent(GameEvent.HongMeng.UpdateGongMingLv) CheckRedPointStatus(RedPointType.HongMeng_UpTower) HarmonyManager.WarPowerChangeNotify() end ) else PopupTipPanel.ShowTip("成长护符不足!") end else PopupTipPanel.ShowTip("金币不足!") end end end ) BindRedPointObject(RedPointType.HongMeng_UpTower,self.UpBtnRedPoint) end function HongMengEnvoyPanel:RunTimerFun() local refreshFunc = function() for key, value in pairs(self.EnvoyItemList) do if HarmonyManager.hongmengGuards[key].time - GetTimeStamp() > 0 then --print(#self.EnvoyItemList) if value.Empty.activeSelf == false then -- body value.Empty:SetActive(true) end local time_content = TimeToFelaxible(HarmonyManager.hongmengGuards[key].time - GetTimeStamp()) value.timer_text.text = string.format("%s\n后恢复", time_content) elseif HarmonyManager.hongmengGuards[key].time == 0 then -- body value.timer_text.text = "" if not value.AddImage.activeSelf then -- body value.AddImage:SetActive(true) end end end end if self.timerEffect == nil then -- body self.timerEffect = Timer.New(refreshFunc, 1, -1, true) end self.timerEffect:Start() refreshFunc() end function HongMengEnvoyPanel:IsUpBtnGray() local sum = HarmonyManager:HongMengTowerUpLimit() if HarmonyManager.GetSingleAdditionsData(HarmonyAddType.AddLv).value >= sum then -- body Util.SetGray(self.UpBtn, true) self.imageGame:SetActive(false) self.TextGame:SetActive(false) self.UnShowText:SetActive(true) else Util.SetGray(self.UpBtn, false) self.imageGame:SetActive(true) self.TextGame:SetActive(true) self.UnShowText:SetActive(false) end end function HongMengEnvoyPanel:RefeshRedPoint() -- body end function HongMengEnvoyPanel:UpdateShow(list) for i = 1, #list do -- bodys --LogBlue("执行刷新"..list[i].heroId) self.EnvoyItemList[i]:SetItemData(list[i]) self.EnvoyItemList[i]:SetItem(self.EnvoyItemList[i].gameObject, list[i]) end local Box = #HarmonyManager.hongmengGuards + #HarmonyManager.hongmengHeroInfos local HeroCount = 0 for i = 1, #HarmonyManager.hongmengGuards do -- body if HarmonyManager.hongmengGuards[i].heroId ~= "" then -- body HeroCount = HeroCount + 1 end end for i = 1, #HarmonyManager.hongmengHeroInfos do -- body if HarmonyManager.hongmengHeroInfos[i].heroId ~= "" then -- body HeroCount = HeroCount + 1 end end self:ReFeshTextFun({HeroCount,Box}) end function HongMengEnvoyPanel:UpdateFun(data) print(data.gridId) self:RunTimerFun() self:UpdateShow(HarmonyManager.hongmengGuards) -- HeroManager.UpdateSingleHeroDatas(data.dynamicId,1,data.star,data.breakId,data.upStarId) end function HongMengEnvoyPanel:ReFeshTextFun(data) local HeroCount = data[1] local Box = data[2] -- body self.NumText.text = string.format("%d/%d", HeroCount, Box) end --添加事件监听(用于子类重写) function HongMengEnvoyPanel:AddListener() for i = 1, #self.contents do self.contents[i].view:AddListener() end Game.GlobalEvent:AddEvent(GameEvent.HongMeng.UnLoadHongMengEnvoy, self.UpdateFun, self) Game.GlobalEvent:AddEvent(GameEvent.HongMeng.OnlyRefeshText, self.ReFeshTextFun, self) Game.GlobalEvent:AddEvent(GameEvent.HongMeng.UpHongMengEnvoy, self.UpdateFun, self) end --移除事件监听(用于子类重写) function HongMengEnvoyPanel:RemoveListener() for i = 1, #self.contents do self.contents[i].view:RemoveListener() end Game.GlobalEvent:RemoveEvent(GameEvent.HongMeng.UnLoadHongMengEnvoy, self.UpdateFun, self) Game.GlobalEvent:RemoveEvent(GameEvent.HongMeng.OnlyRefeshText, self.ReFeshTextFun, self) Game.GlobalEvent:RemoveEvent(GameEvent.HongMeng.UpHongMengEnvoy, self.UpdateFun, self) end --界面打开时调用(用于子类重写) function HongMengEnvoyPanel:OnOpen(equipSId) --NetManager.PlayerInfoRequest(LoadingPanel.OnStep) self.UpView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform, {showType = UpViewOpenType.ShowLeft}) Gold = BagManager.GetTotalItemNum(UpViewRechargeType.Gold) GrowthAmulet = BagManager.GetTotalItemNum(UpViewRechargeType.GrowthAmulet) for i = 1, #self.EnvoyItemList do -- body self.EnvoyItemList[i]:OnOpen() end for i = 1, #self.contents do self.contents[i].view:OnOpen() end local data = HarmonyManager:GetHongMengUpData() if data then -- body print(data.LevelUp[2][2],GrowthAmulet) if Gold >= data.LevelUp[1][2] then -- body #9e8d6c self.TextGold.text = string.format("%d",data.LevelUp[1][2]) if GrowthAmulet >= data.LevelUp[2][2] then self.TextGrowthAmulet.text = string.format("%d",data.LevelUp[2][2]) else self.TextGrowthAmulet.text = string.format("%d",data.LevelUp[2][2]) end else self.TextGold.text = string.format("%d",data.LevelUp[1][2]) if GrowthAmulet >= data.LevelUp[2][2] then self.TextGrowthAmulet.text = string.format("%d",data.LevelUp[2][2]) else -- print("222222") self.TextGrowthAmulet.text = string.format("%d",data.LevelUp[2][2]) end end else LogGreen(" error: data is nil ") end local sum = HarmonyManager:HongMengTowerUpLimit() self.GradeText.text = string.format("%d/%d", HarmonyManager.GetSingleAdditionsData(HarmonyAddType.AddLv).value, sum) self:IsUpBtnGray() self:InitTextMum() self:CheckEvoyEquip() self:RunTimerFun() -- self.timerEffect:Start() end --检测鸿蒙守卫装备是否够24件 function HongMengEnvoyPanel:CheckEvoyEquip() -- body local list= {} HarmonyManager.equipCount = 0 for i = 1, #HarmonyManager.hongmengGuards do -- body if HarmonyManager.hongmengGuards[i].heroId ~= "" then -- body local singleHero = HeroManager.GetSingleHeroData(HarmonyManager.hongmengGuards[i].heroId) table.insert(list,singleHero) end end for i = 1, #list do -- body if list[i].equipIdList then -- body for i = 1, #list[i].equipIdList do -- body HarmonyManager.equipCount = HarmonyManager.equipCount + 1 end end end end function HongMengEnvoyPanel:InitTextMum() local HeroCount = 0 local Box = #HarmonyManager.hongmengHeroInfos + #HarmonyManager.hongmengGuards for i = 1, #HarmonyManager.hongmengHeroInfos do -- body if HarmonyManager.hongmengHeroInfos[i].heroId ~= "" then HeroCount = HeroCount + 1 end end for i = 1, #HarmonyManager.hongmengGuards do -- body if HarmonyManager.hongmengGuards[i].heroId ~= "" then HeroCount = HeroCount + 1 -- body end end self.NumText.text = string.format("%d/%d", HeroCount, Box) end --界面打开或者重新打开后,界面刷新时调用(用于子类重写) function HongMengEnvoyPanel:OnShow() self.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.HongMengTower}) end --界面关闭时调用(用于子类重写) function HongMengEnvoyPanel:OnClose() for i = 1, #self.contents do self.contents[i].view:OnClose() end if self.timerEffect then -- body self.timerEffect:Stop() --print("关闭倒计时") end end --界面销毁时调用(用于子类重写) function HongMengEnvoyPanel:OnDestroy() SubUIManager.Close(self.UpView) if self.timerEffect then -- body self.timerEffect:Stop() -- print("关闭倒计时") end ClearRedPointObject(RedPointType.HongMeng_UpTower,self.UpBtnRedPoint) end return HongMengEnvoyPanel