miduo_client/Assets/ManagedResources/~Lua/Modules/Carbon/EndLessCarbonPanel.lua

253 lines
8.1 KiB
Lua

require("Base/BasePanel")
EndLessCarbonPanel = Inherit(BasePanel)
local this = EndLessCarbonPanel
local endLessConfig = ConfigManager.GetConfig(ConfigName.EndlessMapConfig)
local mapConfig = ConfigManager.GetConfig((ConfigName.ChallengeConfig))
local hadClikcBuy = false
--初始化组件(用于子类重写)
function EndLessCarbonPanel:InitComponent()
this.btnBack = Util.GetGameObject(self.gameObject, "btnBack")
-- 显示行动力
this.curValue = Util.GetGameObject(self.gameObject, "stepRoot/bg/energyInfo"):GetComponent("Text")
this.totalValue = Util.GetGameObject(self.gameObject, "stepRoot/bg/total"):GetComponent("Text")
this.btnBuy = Util.GetGameObject(self.gameObject, "stepRoot/bg/add")
-- 小地图
this.miniMap = Util.GetGameObject(self.gameObject, "Bg/bg1/miniMap"):GetComponent("Image")
this.miniMapName = Util.GetGameObject(this.miniMap.gameObject, "tBottom/main/mapName"):GetComponent("Text")
this.worldLevel = Util.GetGameObject(this.miniMap.gameObject, "tBottom/left/worldLevel"):GetComponent("Text")
this.worldMode = Util.GetGameObject(this.miniMap.gameObject, "tBottom/right/worldMode"):GetComponent("Text")
-- 怪物组
this.bossGrid = Util.GetGameObject(self.gameObject, "Bg/bg1/InfoRoot/bossList/grid")
this.bossItemPre = Util.GetGameObject(self.gameObject, "Bg/bg1/InfoRoot/bossList/itemPre")
-- 奖励预览
this.rewwardGrid = Util.GetGameObject(self.gameObject, "Bg/bg1/InfoRoot/rewardList/grid")
this.btnFight = Util.GetGameObject(self.gameObject, "Bg/bg1/InfoRoot/btnFight")
this.btnMapInfo = Util.GetGameObject(self.gameObject, "Bg/bg1/miniMap/mapInfo")
this.btnMapInfo:SetActive(false)
--幫助
this.helpBtn = Util.GetGameObject(self.gameObject, "helpBtn ")
this.helpPosition = this.helpBtn:GetComponent("RectTransform").localPosition
-- 行动力刷新倒计时显示
this.bgTime = Util.GetGameObject(self.gameObject, "stepRoot/bg/Bgtime")
this.actCountTime = Util.GetGameObject(this.bgTime, "time"):GetComponent("Text")
this.rewardList = {}
this.bossList = {}
end
--绑定事件(用于子类重写)
function EndLessCarbonPanel:BindEvent()
Util.AddClick(this.btnBack, function ()
-- !!!! PS: 这里必须是主动打开副本选择界面,从地图中返回时,这个界面的上一级是地图界面,
-- 如果只是关闭自己,则会打开地图界面,不会打开副本选择界面,导致报错
UIManager.OpenPanel(UIName.CarbonTypePanelV2,1)
--检测到上一个面板打开之后,关闭自己
CallBackOnPanelOpen(UIName.CarbonTypePanelV2, function()
UIManager.ClosePanel(UIName.EndLessCarbonPanel)
end)
end)
Util.AddClick(this.btnFight, function ()
this.EnterMap(EndLessMapManager.openMapId)
end)
Util.AddClick(this.btnBuy, function ()
---- 先同步位置再弹出购买界面
--if not hadClikcBuy then
-- hadClikcBuy = true
UIManager.OpenPanel(UIName.QuickPurchasePanel, { type = 1 })
--end
end)
Util.AddClick(this.btnMapInfo, function ()
--UIManager.OpenPanel(UIName.MinMapPopup)
end)
--帮助按钮
Util.AddClick(this.helpBtn, function()
UIManager.OpenPanel(UIName.HelpPopup, HELP_TYPE.EndLessMap, this.helpPosition.x, this.helpPosition.y)
end)
end
--添加事件监听(用于子类重写)
function EndLessCarbonPanel:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.Bag.BagGold, this.InitActPowerShow)
end
--移除事件监听(用于子类重写)
function EndLessCarbonPanel:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.Bag.BagGold, this.InitActPowerShow)
end
--界面打开时调用(用于子类重写)
function EndLessCarbonPanel:OnOpen(...)
-- 初始化组件
this.InitCompShow()
-- 请求获取队伍血量
-- 设置静态表数据
this.SetStaticData()
this.RequestBlood(function ()
this.InitActPowerShow()
end)
end
function EndLessCarbonPanel:OnSortingOrderChange()
end
function EndLessCarbonPanel:OnShow()
this.InitActPowerShow()
this.ShowCountTime()
-- 界面打开时刷新队伍血量数据
-- 刷新无尽副本编队数据
EndLessMapManager.RrefreshFormation()
hadClikcBuy = false
end
function this.InitActPowerShow()
local total = EndLessMapManager.GetTotalEnergy()
local curEnergy = 0
if MapManager.isInMap then
curEnergy = EndLessMapManager.leftEnergy
else
curEnergy = BagManager.GetItemCountById(1)
end
local color = curEnergy <= 5 and "FF0014FF" or "A0B2B2FF"
local str = string.format("<color=#%s>%s</color>", color, tostring(curEnergy))
this.curValue.text = str .. " / " .. total
--this.totalValue.text = total
end
function this.RequestBlood(func)
NetManager.RequestAllHeroHp(function ()
if func then func() end
end)
end
function this.EnterMap(mapId)
if not MapManager.isInMap then
-- 进入地图编队,重新赋值一遍
CarbonManager.difficulty = CARBON_TYPE.ENDLESS
UIManager.OpenPanel(UIName.FormationPanelV2, FORMATION_TYPE.CARBON, mapId)
else
-- 在地图里又没勾新手引导, 无法进图
if MapManager.curMapId == 0 then
PopupTipPanel.ShowTip(Language[10361])
end
end
end
function this.InitCompShow()
--生成6个boss预设
for i = 1, 6 do
if not this.bossList[i] then
this.bossList[i] = newObjToParent(this.bossItemPre, this.bossGrid)
this.bossList[i]:SetActive(false)
end
end
-- 8个奖励预览
for j = 1, 8 do
if not this.rewardList[j] then
this.rewardList[j] = SubUIManager.Open(SubUIConfig.ItemView, this.rewwardGrid.transform)
this.rewardList[j].gameObject:SetActive(false)
end
end
end
function this.SetStaticData()
local mapData = endLessConfig[EndLessMapManager.openMapId]
if not mapData then Log(Language[10362]) end
for i = 1, #mapData.RewardShow do
local item = {}
local itemId = mapData.RewardShow[i][1]
item[#item + 1] = itemId
item[#item + 1] = 0
this.rewardList[i]:OnOpen(false, item, 1.05)
this.rewardList[i].gameObject:SetActive(true)
end
-- 显示怪物
for j = 1, #mapData.MonsterShow do
local monsterId = mapData.MonsterShow[j]
local mIcon, level = MonsterCampManager.GetIconByMonsterId(monsterId)
local icon = Util.GetGameObject(this.bossList[j], "icon"):GetComponent("Image")
local monsterLevel = Util.GetGameObject(this.bossList[j], "imgLv/lv"):GetComponent("Text")
icon.sprite = mIcon
monsterLevel.text = level
this.bossList[j]:SetActive(true)
end
this.worldLevel.text = EndLessMapManager.worldLevel
this.worldMode.text = MAP_MODE[mapConfig[EndLessMapManager.openMapId].DifficultType]
this.miniMapName.text = mapData.Info
end
-- 行动力是否显示倒计时
function this.ShowCountTime()
if this.timer then
this.timer:Stop()
end
this.timer = nil
this.actCountTime.text = ""
this.bgTime:SetActive(not EndLessMapManager.EnergyEnough())
-- 初始化是判断一次
if not EndLessMapManager.EnergyEnough() then
-- 启动倒计时
this.timer = Timer.New(function ()
local leftTime = AutoRecoverManager.GetRecoverTime(1)
if EndLessMapManager.EnergyEnough()then
-- 回复满了,在地图外面可以停止计时器
this.timer:Stop()
this.bgTime:SetActive(false)
else
this.actCountTime.text = GetTimeMaoHaoStrBySeconds(math.floor(leftTime))
end
end, 1, -1, true)
this.timer:Start()
end
end
--界面关闭时调用(用于子类重写)
function EndLessCarbonPanel:OnClose()
if this.timer then
this.timer:Stop()
this.timer = nil
end
end
--界面销毁时调用(用于子类重写)
function EndLessCarbonPanel:OnDestroy()
this.rewardList = {}
this.bossList = {}
end
return EndLessCarbonPanel