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

400 lines
14 KiB
Lua

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
--初始化组件(用于子类重写)
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)
Gold = BagManager.GetTotalItemNum(UpViewRechargeType.Gold)
GrowthAmulet = BagManager.GetTotalItemNum(UpViewRechargeType.GrowthAmulet)
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)
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.hongmengTablet > HarmonyManager.TowerStartLimit + sum * 5 then
-- body
PopupTipPanel.ShowTip("鸿蒙碑等级已达上限!")
else
local data = HarmonyManager:GetHongMengUpData()
--print(data.LevelUp[1][2].." "..data.LevelUp[2][2])
if Gold >= data.LevelUp[1][2] then
-- body
if GrowthAmulet >= data.LevelUp[2][2] then
--print("升级成功")
-- body
NetManager.UpHongMengGrade(
function()
-- body
LogGreen("回调函数")
Gold = Gold - data.LevelUp[1][2]
GrowthAmulet = GrowthAmulet - data.LevelUp[2][2]
HarmonyManager.hongmengTablet = HarmonyManager.hongmengTablet + 1
self.TextGold.text = Gold
self.TextGrowthAmulet.text = GrowthAmulet
local sum = HarmonyManager:HongMengTowerUpLimit()
self.GradeText.text =
string.format("%d/%d", HarmonyManager.hongmengTablet, HarmonyManager.TowerStartLimit + sum * 5)
--检测红点
CheckRedPointStatus(RedPointType.HongMeng_UpTower)
for i = 1, #self.EnvoyItemList do
self.EnvoyItemList[i]:UpdateFun()
end
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
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)
elseif HarmonyManager.hongmengGuards[key].time == 0 then
-- body
value.timer_text.text = ""
end
end
end
self.timerEffect = Timer.New(refreshFunc, 1, -1, true)
self.timerEffect:Start()
refreshFunc()
end
function HongMengEnvoyPanel:IsUpBtnGray()
local sum = HarmonyManager:HongMengTowerUpLimit()
if HarmonyManager.hongmengTablet >= HarmonyManager.TowerStartLimit + sum * 5 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)
for key, value in pairs(HarmonyManager.hongmengGuards) do
-- body
if value.gridId == data.gridId then
-- body
if value.heroId ~= "" then
-- body
value.heroId = ""
value.time = data.time + GetTimeStamp()
print("卸载成功",key,"data",data.time,"value",value.time)
else
value.heroId = data.heroId
value.time = 0
end
end
end
-- local equip_count = 1
-- local equip_list = {}
-- local hun_count = 1
-- local hun_list = {}
-- local ling_count = 1
-- local ling_list = {}
-- local weapon_Lv = 999
-- for i = 1, #HarmonyManager.hongmengGuards do
-- -- body
-- if HarmonyManager.hongmengGuards[i].heroId~= "" then
-- -- body
-- local herodata = HeroManager.GetSingleHeroData(HarmonyManager.hongmengGuards[i].heroId)
-- for i = 1, #herodata.equipIdList do
-- -- body
-- equip_list[equip_count] = herodata.equipIdList[i]
-- equip_count = equip_count + 1
-- end
-- if herodata.jewels then
-- -- body
-- if herodata.jewels[1] then
-- -- body
-- hun_list[hun_count] = herodata.jewels[1]
-- hun_count = hun_count + 1
-- end
-- if herodata.jewels[2] then
-- -- body
-- ling_list[ling_count] = herodata.jewels[2]
-- ling_count = ling_count + 1
-- end
-- end
-- if weapon_Lv > herodata.talismanList then
-- -- body
-- weapon_Lv = herodata.talismanList
-- end
-- end
-- end
-- if equip_count == 24 then
-- -- body
-- HarmonyManager:EquipMin(equip_list)
-- end
-- if hun_count == 6 then
-- -- body
-- HarmonyManager:HunMin(hun_list)
-- end
-- if ling_count == 6 then
-- -- body
-- HarmonyManager:SoulMin(ling_list)
-- end
-- if weapon_Lv ~= 999 then
-- -- body
-- HarmonyManager:WeaponMin(weapon_Lv)
-- end
--LogGreen( " HarmonyManager.EnvoyList "..#HarmonyManager.EnvoyList)
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})
for i = 1, #self.EnvoyItemList do
-- body
self.EnvoyItemList[i]:OnOpen()
end
for i = 1, #self.contents do
self.contents[i].view:OnOpen()
end
self.TextGold.text = Gold
self.TextGrowthAmulet.text = GrowthAmulet
local sum = HarmonyManager:HongMengTowerUpLimit()
self.GradeText.text = string.format("%d/%d", HarmonyManager.hongmengTablet, HarmonyManager.TowerStartLimit + sum * 5)
self:IsUpBtnGray()
self:InitTextMum()
self:RunTimerFun()
self.timerEffect:Start()
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.Talisman})
end
--界面关闭时调用(用于子类重写)
function HongMengEnvoyPanel:OnClose()
for i = 1, #self.contents do
self.contents[i].view:OnClose()
end
if self.timerEffect then
-- body
self.timerEffect:Stop()
end
end
--界面销毁时调用(用于子类重写)
function HongMengEnvoyPanel:OnDestroy()
SubUIManager.Close(self.UpView)
ClearRedPointObject(RedPointType.HongMeng_UpTower,self.UpBtnRedPoint)
end
return HongMengEnvoyPanel