miduo_client/Assets/ManagedResources/~Lua/Modules/Harmony/Panel/HongMengEnvoyPanel.lua

415 lines
15 KiB
Lua
Raw Normal View History

2020-12-17 10:41:00 +08:00
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
2021-01-04 15:27:19 +08:00
HongMengEnvoyPanel.timerEffect = nil
2020-12-17 10:41:00 +08:00
--初始化组件(用于子类重写)
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")
2020-12-18 13:39:35 +08:00
self.UpBtnRedPoint = Util.GetGameObject(self.gameObject,"UpBtn/RedPoint")
2020-12-17 10:41:00 +08:00
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)
2021-01-15 19:40:47 +08:00
2020-12-17 10:41:00 +08:00
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,
2020-12-23 17:41:31 +08:00
BagManager.GetTotalItemNum(UpViewRechargeType.XuanHuangZhiQi),
2020-12-17 10:41:00 +08:00
BagManager.GetTotalItemNum(UpViewRechargeType.DemonCrystal),
2
)
end
end
--绑定事件(用于子类重写)
function HongMengEnvoyPanel:BindEvent()
Util.AddClick(
self.btnBack,
function()
self:ClosePanel()
end
)
Util.AddClick(
self.helpBtn,
function()
2021-01-06 13:51:29 +08:00
UIManager.OpenPanel(UIName.HelpPopup, HELP_TYPE.HongMengZhen, self.helpPosition.x, self.helpPosition.y+500)
2020-12-17 10:41:00 +08:00
end
)
Util.AddClick(
self.AddBtn,
function()
--二级弹窗界面
2021-01-06 11:16:10 +08:00
2020-12-17 10:41:00 +08:00
Game.GlobalEvent:DispatchEvent(GameEvent.HongMeng.OpenBoxTips)
end
)
--共鸣按钮
Util.AddClick(
self.GongMingBtn,
function()
--二级共鸣弹窗
local count = HarmonyManager:IsEnvoyCount()
2020-12-21 15:10:23 +08:00
LogGreen(count)
2020-12-29 20:36:37 +08:00
if count > 6 then
2020-12-17 10:41:00 +08:00
-- body
UIManager.OpenPanel(UIName.GongMingResultTips)
else
2021-01-20 19:19:34 +08:00
PopupTipPanel.ShowTip("需要6名鸿蒙使者才可激活共鸣效果!")
2020-12-17 10:41:00 +08:00
end
--print("共鸣提示")
end
)
Util.AddClick(
self.UpBtn,
function()
--二级共鸣弹窗
2021-02-20 11:00:40 +08:00
if HarmonyManager.GetSingleAdditionsData(HarmonyAddType.AddLv).value >= HarmonyManager:HongMengTowerUpLimit() then
2020-12-17 10:41:00 +08:00
-- body
PopupTipPanel.ShowTip("鸿蒙碑等级已达上限!")
else
local data = HarmonyManager:GetHongMengUpData()
--print(data.LevelUp[1][2].." "..data.LevelUp[2][2])
2021-01-15 15:44:43 +08:00
if data == nil then
-- body
return
end
2021-01-15 19:40:47 +08:00
Gold = BagManager.GetTotalItemNum(UpViewRechargeType.Gold)
GrowthAmulet = BagManager.GetTotalItemNum(UpViewRechargeType.GrowthAmulet)
2020-12-17 10:41:00 +08:00
if Gold >= data.LevelUp[1][2] then
-- body
if GrowthAmulet >= data.LevelUp[2][2] then
--print("升级成功")
-- body
2021-01-15 10:26:56 +08:00
HarmonyManager.SetOldPowerNum()
2020-12-17 10:41:00 +08:00
NetManager.UpHongMengGrade(
function()
-- body
2021-02-20 11:00:40 +08:00
local sum = HarmonyManager:HongMengTowerUpLimit()
2021-01-18 17:43:11 +08:00
HarmonyManager.GetSingleAdditionsData(HarmonyAddType.AddLv).value = HarmonyManager.GetSingleAdditionsData(HarmonyAddType.AddLv).value + 1
if HarmonyManager.GetSingleAdditionsData(HarmonyAddType.AddLv).value >= sum then
2021-01-14 21:11:53 +08:00
-- body
Util.SetGray(self.UpBtn, true)
self.imageGame:SetActive(false)
self.TextGame:SetActive(false)
self.UnShowText:SetActive(true)
2021-02-20 10:05:17 +08:00
self.UpBtnRedPoint:SetActive(false)
2021-01-14 21:11:53 +08:00
end
2021-02-20 10:05:17 +08:00
2021-02-20 11:00:40 +08:00
2021-01-18 17:43:11 +08:00
self.GradeText.text = string.format("%d/%d", HarmonyManager.GetSingleAdditionsData(HarmonyAddType.AddLv).value, sum)
2020-12-29 20:36:37 +08:00
--检测红点 UpdateGongMingLv
2020-12-17 10:41:00 +08:00
for i = 1, #self.EnvoyItemList do
self.EnvoyItemList[i]:UpdateFun()
end
2020-12-29 20:36:37 +08:00
Game.GlobalEvent:DispatchEvent(GameEvent.HongMeng.UpdateGongMingLv)
CheckRedPointStatus(RedPointType.HongMeng_UpTower)
2021-01-15 10:26:56 +08:00
HarmonyManager.WarPowerChangeNotify()
2020-12-17 10:41:00 +08:00
end
)
else
2021-01-14 21:11:53 +08:00
2020-12-17 10:41:00 +08:00
PopupTipPanel.ShowTip("成长护符不足!")
end
else
2021-01-14 21:11:53 +08:00
2020-12-17 10:41:00 +08:00
PopupTipPanel.ShowTip("金币不足!")
end
end
end
)
2020-12-18 13:39:35 +08:00
BindRedPointObject(RedPointType.HongMeng_UpTower,self.UpBtnRedPoint)
2020-12-17 10:41:00 +08:00
end
function HongMengEnvoyPanel:RunTimerFun()
2021-01-04 15:27:19 +08:00
2020-12-17 10:41:00 +08:00
local refreshFunc = function()
for key, value in pairs(self.EnvoyItemList) do
if HarmonyManager.hongmengGuards[key].time - GetTimeStamp() > 0 then
2021-01-04 15:27:19 +08:00
--print(#self.EnvoyItemList)
2020-12-17 10:41:00 +08:00
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("<color=#ffbc22>%s</color>\n<color=#bd922a>后恢复</color>", time_content)
2021-01-26 20:21:01 +08:00
else
2020-12-18 13:39:35 +08:00
-- body
2021-01-26 20:21:01 +08:00
2021-01-25 19:44:57 +08:00
if not value.AddImage.activeSelf then
-- body
value.AddImage:SetActive(true)
2021-01-26 20:21:01 +08:00
value.timer_text.text = ""
2021-01-25 19:44:57 +08:00
end
2020-12-17 10:41:00 +08:00
end
end
end
2021-01-04 15:27:19 +08:00
if self.timerEffect == nil then
-- body
self.timerEffect = Timer.New(refreshFunc, 1, -1, true)
end
2020-12-17 10:41:00 +08:00
self.timerEffect:Start()
refreshFunc()
end
function HongMengEnvoyPanel:IsUpBtnGray()
local sum = HarmonyManager:HongMengTowerUpLimit()
2021-01-18 17:43:11 +08:00
if HarmonyManager.GetSingleAdditionsData(HarmonyAddType.AddLv).value >= sum then
2020-12-17 10:41:00 +08:00
-- body
Util.SetGray(self.UpBtn, true)
self.imageGame:SetActive(false)
self.TextGame:SetActive(false)
self.UnShowText:SetActive(true)
2021-02-20 11:00:40 +08:00
-- self.UpBtnRedPoint:SetActive(false)
2020-12-17 10:41:00 +08:00
else
Util.SetGray(self.UpBtn, false)
self.imageGame:SetActive(true)
self.TextGame:SetActive(true)
self.UnShowText:SetActive(false)
end
2021-02-20 14:52:04 +08:00
--检测一次红点
CheckRedPointStatus(RedPointType.HongMeng_UpTower)
2020-12-17 10:41:00 +08:00
end
2020-12-18 13:39:35 +08:00
function HongMengEnvoyPanel:RefeshRedPoint()
-- body
end
2020-12-17 10:41:00 +08:00
function HongMengEnvoyPanel:UpdateShow(list)
2020-12-18 13:39:35 +08:00
2020-12-17 10:41:00 +08:00
for i = 1, #list do
-- bodys
2021-01-14 14:09:13 +08:00
--LogBlue("执行刷新"..list[i].heroId)
2020-12-17 10:41:00 +08:00
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
2020-12-18 13:39:35 +08:00
self:ReFeshTextFun({HeroCount,Box})
2020-12-17 10:41:00 +08:00
end
function HongMengEnvoyPanel:UpdateFun(data)
2021-02-20 10:05:17 +08:00
2021-01-04 15:27:19 +08:00
self:RunTimerFun()
2020-12-18 13:39:35 +08:00
2020-12-17 10:41:00 +08:00
self:UpdateShow(HarmonyManager.hongmengGuards)
2021-02-20 14:52:04 +08:00
-- HeroManager.UpdateSingleHeroDatas(data.dynamicId,1,data.star,data.breakId,data.upStarId)
2020-12-17 10:41:00 +08:00
end
function HongMengEnvoyPanel:ReFeshTextFun(data)
local HeroCount = data[1]
local Box = data[2]
-- body
self.NumText.text = string.format("%d/%d", HeroCount, Box)
end
2021-02-20 10:05:17 +08:00
function HongMengEnvoyPanel:UpdateTextColor()
Gold = BagManager.GetTotalItemNum(UpViewRechargeType.Gold)
GrowthAmulet = BagManager.GetTotalItemNum(UpViewRechargeType.GrowthAmulet)
--获取当前需要道具数量的数据
local data = HarmonyManager:GetHongMengUpData()
if Gold >= data.LevelUp[1][2] then
-- 是否变色
self.TextGold.text = string.format("<color=#F1E7E7>%d</color>",data.LevelUp[1][2])
else
self.TextGold.text = string.format("<color=#E15558>%d</color>",data.LevelUp[1][2])
end
if GrowthAmulet >= data.LevelUp[2][2] then
self.TextGrowthAmulet.text = string.format("<color=#F1E7E7>%d</color>",data.LevelUp[2][2])
else
self.TextGrowthAmulet.text = string.format("<color=#E15558>%d</color>",data.LevelUp[2][2])
end
end
function HongMengEnvoyPanel:UpdateGoldVal()
self:UpdateTextColor()
2020-12-17 10:41:00 +08:00
2021-02-20 10:05:17 +08:00
end
2020-12-17 10:41:00 +08:00
--添加事件监听(用于子类重写)
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)
2021-02-20 10:05:17 +08:00
Game.GlobalEvent:AddEvent(GameEvent.Bag.BagGold, self.UpdateGoldVal, self)
2020-12-17 10:41:00 +08:00
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)
2020-12-18 13:39:35 +08:00
Game.GlobalEvent:RemoveEvent(GameEvent.HongMeng.UpHongMengEnvoy, self.UpdateFun, self)
2021-01-14 14:09:13 +08:00
2020-12-17 10:41:00 +08:00
end
--界面打开时调用(用于子类重写)
function HongMengEnvoyPanel:OnOpen(equipSId)
2020-12-22 19:27:49 +08:00
--NetManager.PlayerInfoRequest(LoadingPanel.OnStep)
2020-12-17 10:41:00 +08:00
self.UpView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform, {showType = UpViewOpenType.ShowLeft})
2021-02-20 10:05:17 +08:00
2020-12-17 10:41:00 +08:00
for i = 1, #self.EnvoyItemList do
-- body
self.EnvoyItemList[i]:OnOpen()
end
for i = 1, #self.contents do
self.contents[i].view:OnOpen()
end
2021-01-06 11:48:29 +08:00
local data = HarmonyManager:GetHongMengUpData()
2021-01-11 21:04:12 +08:00
if data then
2021-02-20 10:05:17 +08:00
self:UpdateTextColor()
2021-01-11 21:04:12 +08:00
else
LogGreen(" error: data is nil ")
end
2020-12-17 10:41:00 +08:00
local sum = HarmonyManager:HongMengTowerUpLimit()
2021-01-18 17:43:11 +08:00
self.GradeText.text = string.format("%d/%d", HarmonyManager.GetSingleAdditionsData(HarmonyAddType.AddLv).value, sum)
2020-12-17 10:41:00 +08:00
self:IsUpBtnGray()
self:InitTextMum()
2021-01-08 17:29:54 +08:00
self:CheckEvoyEquip()
2020-12-17 10:41:00 +08:00
self:RunTimerFun()
2020-12-29 20:36:37 +08:00
-- self.timerEffect:Start()
2020-12-17 10:41:00 +08:00
end
2021-01-08 17:29:54 +08:00
--检测鸿蒙守卫装备是否够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
2021-01-15 15:44:43 +08:00
2021-01-08 17:29:54 +08:00
end
2020-12-17 10:41:00 +08:00
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()
2021-01-06 11:48:29 +08:00
self.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.HongMengTower})
2020-12-17 10:41:00 +08:00
end
--界面关闭时调用(用于子类重写)
function HongMengEnvoyPanel:OnClose()
for i = 1, #self.contents do
self.contents[i].view:OnClose()
end
if self.timerEffect then
-- body
self.timerEffect:Stop()
2021-01-06 11:48:29 +08:00
--print("关闭倒计时")
2020-12-17 10:41:00 +08:00
end
end
--界面销毁时调用(用于子类重写)
function HongMengEnvoyPanel:OnDestroy()
SubUIManager.Close(self.UpView)
2021-01-04 15:27:19 +08:00
if self.timerEffect then
-- body
self.timerEffect:Stop()
2021-01-06 11:48:29 +08:00
-- print("关闭倒计时")
2021-01-04 15:27:19 +08:00
end
2020-12-18 13:39:35 +08:00
ClearRedPointObject(RedPointType.HongMeng_UpTower,self.UpBtnRedPoint)
2020-12-17 10:41:00 +08:00
end
return HongMengEnvoyPanel