require("Base/BasePanel")
FightPointPassMainPanel = Inherit(BasePanel)
local this = FightPointPassMainPanel
-- 外地入侵模块
local invadeMonster = require("Modules/Fight/View/InvadeMonsterView")
-- 小人行动
--local roleWalkView = require("Modules/Fight/View/RoleShowView")
-- 小地图
local fightMap = require("Modules/Fight/View/FightPointMapView")
local fightLevelConfig = ConfigManager.GetConfig(ConfigName.MainLevelConfig)
local fightLevelSetConfig = ConfigManager.GetConfig(ConfigName.MainLevelSettingConfig)
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
local points = {}
local isCounting = false
local orginLayer=0
local hasLoad = false
local hasMap = false
this.funcBtnList = {}
local curMianTaskData = {}
local timePressStarted
local callBack
local count = 1
local timeImg = {
    [1] = "r_guanka_daojishi_01",
    [2] = "r_guanka_daojishi_02",
    [3] = "r_guanka_daojishi_03",
    [4] = "r_guanka_daojishi_04",
    [5] = "r_guanka_daojishi_05",
}
-- 关卡颜色文字
local textColor = {
    [FightDifficultyState.SimpleLevel] = "F1E1C0FF",
    [FightDifficultyState.NrmalLevel] = "F1E1C0FF",
    [FightDifficultyState.DifficultyLevel] = "F1E1C0FF",
    [FightDifficultyState.HellLevel] = "F1E1C0FF",
    [FightDifficultyState.NightmareLevel] = "F1E1C0FF",
}
-- 是否激活了动画
local isAnimActive = false
local chooseAnim = 0
-- 转场动画
local fightAnimRes = "live2d_guaji_yuguai"
-- local fightSkeleton
local fightAnim = {
    [2] = "diban",
    [3] = "xiaoguai",
    [4] = "bnoss",
    [1] = "idle",
}
-- local mapNpc = "live2d_npc_map"
-- local mapNpc2 = "live2d_npc_map_nv"
-- local npc
--初始化组件(用于子类重写)
function FightPointPassMainPanel:InitComponent()
    invadeMonster:InitComponent(self.gameObject, this)
    this.spLoader = SpriteLoader.New()
    isAnimActive = false
    fightMap:InitComponent(self.gameObject, this)
    -- 通关豪礼入口
    this.pgBtn=Util.GetGameObject(self.gameObject,"LeftUp/box/passGift")
    this.pgFrame=Util.GetGameObject(this.pgBtn,"frame"):GetComponent("Image")
    this.pgHead=Util.GetGameObject(this.pgBtn,"head"):GetComponent("Image")
    this.pgGive=Util.GetGameObject(this.pgBtn,"give"):GetComponent("Text")
    this.pgName=Util.GetGameObject(this.pgBtn,"name"):GetComponent("Text")
    this.pgInfo=Util.GetGameObject(this.pgBtn,"info"):GetComponent("Text")
    this.pgEffect=Util.GetGameObject(this.pgBtn,"effect")
    -- 四个小按钮
    this.btnDailyMission = Util.GetGameObject(self.gameObject, "Bg/btnGroup/btnDailyMission")
    this.btnDailyMission:GetComponent("Image").sprite=this.spLoader:LoadSprite("g_guanka_richangrenwu_zh")
    this.btnRank = Util.GetGameObject(self.gameObject, "Bg/btnGroup/btnRank")
    this.btnRank:GetComponent("Image").sprite=this.spLoader:LoadSprite("g_guanka_guankapaihang_zh")
    -- 关卡小地图
    this.btnMap = Util.GetGameObject(self.gameObject, "Bg/btnArea")
    this.btnMapRadarBG = Util.GetGameObject(self.gameObject, "Bg/btnArea/RadarBG/RadarBG"):GetComponent("Image")
    this.RadarBGText = Util.GetGameObject(self.gameObject, "Bg/btnArea/RadarBGTextBg/RadarBGText"):GetComponent("Text")
    this.areaName = Util. GetGameObject(this.btnMap, "areaName"):GetComponent("Text")
    this.chapterName = Util.GetGameObject(this.btnMap, "chapterName"):GetComponent("Text")
	SetEnglishActive(this.chapterName)
    this.map=Util.GetGameObject(self.gameObject, "Bg/btnArea/MapMask/Map"):GetComponent("RectTransform")
    this.mapImage=Util.GetGameObject(self.gameObject,"Bg/btnArea/MapMask/Map"):GetComponent("Image")
    for i = 1, 20 do
        points[i]=Util.GetGameObject(self.gameObject, "Bg/btnArea/MapMask/Map/mapAreaPre (".. i ..")")
    end
    -- 挂机奖励
    this.rewardList = {}
    this.rewardItemPre = Util.GetGameObject(self.gameObject, "Bg/rewardContent/item")
    this.rewardGrid = Util.GetGameObject(self.gameObject, "Bg/rewardContent")
    this.btnrewardDetail = Util.GetGameObject(self.gameObject, "Bg/btnRdDetail/click")
    this.btnFight = Util.GetGameObject(self.gameObject, "Bg/btnDown/btnFight")
    this.fightText = Util.GetGameObject(this.btnFight, "Text"):GetComponent("Text")
    this.fightSaoGuang = Util.GetGameObject(this.btnFight, "saoguang")
    LanguageFontSizeFilter(this.fightText, 50)
    -- 你要变强
    this.btnGetForce = Util.GetGameObject(self.gameObject, "Bg/btnDown/btnIWantMilk")
    if not this.playerInfoView then
        this.playerInfoView = SubUIManager.Open(SubUIConfig.PlayerInfoView, this.transform)
    end    
    this.BtView = SubUIManager.Open(SubUIConfig.BtView, self.gameObject.transform)
    this.UpView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform)
    -- 红点
    this.dailyRedPoint = Util.GetGameObject(this.btnDailyMission, "redPoint")
    --this.rankRedPoint = Util.GetGameObject(this.btnRank, "redPoint")
    --this.funcBtnList[16] = invadeMonster.btnRewardOnline
    --this.funcBtnList[19] = invadeMonster.btnRewrdChapter
    this.funcBtnList[12] = this.btnDailyMission
    -- 主线任务显示
    this.mainTask = Util.GetGameObject(self.gameObject, "Bg/RightDown/mainTask")
    this.goVipButton = Util.GetGameObject(self.gameObject, "Bg/RightDown/mainTask/progressLayout")
    this.titleText = Util.GetGameObject(self.gameObject, "Bg/RightDown/mainTask/progressLayout/titleText"):GetComponent("Text")
    this.progressText = Util.GetGameObject(self.gameObject, "Bg/RightDown/mainTask/progressLayout/progressText"):GetComponent("Text")
    this.getRewardButton = Util.GetGameObject(self.gameObject, "Bg/RightDown/mainTask/getRewardButton")
    this.mainTaskGRewardImage = Util.GetGameObject(self.gameObject, "Bg/RightDown/mainTask/getRewardButton/getRewardImage")
    this.mainTaskJumpImage = Util.GetGameObject(self.gameObject, "Bg/RightDown/mainTask/getRewardButton/jumpImage")
    this.GuideEffectGo = poolManager:LoadAsset("GuideEffect", PoolManager.AssetType.GameObject)
    this.GuideEffectGo.transform:SetParent(this.mainTaskGRewardImage.transform)
    this.GuideEffectGo.transform.localPosition = Vector3.zero
    this.GuideEffectGo.transform.localScale = Vector3.one
    Util.GetGameObject(this.GuideEffectGo, "GameObject"):SetActive(false)
    this.GuideJumpEffectGo = poolManager:LoadAsset("GuideEffect", PoolManager.AssetType.GameObject)
    this.GuideJumpEffectGo.transform:SetParent(this.mainTaskJumpImage.transform)
    this.GuideJumpEffectGo.transform.localPosition = Vector3.zero
    this.GuideJumpEffectGo.transform.localScale = Vector3.one
    Util.GetGameObject(this.GuideJumpEffectGo, "GameObject"):SetActive(false)
    this.GuideJumpEffectGo:SetActive(false)
    
    this.fightRP = Util.GetGameObject(this.btnFight, "redPoint")
    -- 按钮
    this.fightLock = Util.GetGameObject(this.btnFight, "lock")
    this.lockText = Util.GetGameObject(this.fightLock, "Text"):GetComponent("Text")
    --倒计时5秒
    this.timeRoot = Util.GetGameObject(this.btnFight, "countRoot")
    this.timeImg = Util.GetGameObject(this.timeRoot, "time"):GetComponent("Image")
    this.timeRoot:SetActive(false)
    -- -- 转场动画
    -- local idle = function()
    --     if not isAnimActive then return end
    --     --Log("第       " .. count .. "     次执行这个函数" )
    --     if count == 2 then
    --         --isAnimActive = false
    --         --count = 1
    --         --fightSkeleton.AnimationState:SetAnimation(0, fightAnim[1], false)
    --         --this.SetAnimPanelState(false)
    --     else
    --         fightSkeleton.AnimationState:SetAnimation(0, fightAnim[chooseAnim], false)
    --         count = count + 1
    --         this.animTimer = nil
    --         this.animTimer = Timer.New(function ()
    --             isAnimActive = false
    --             count = 1
    --             fightSkeleton.AnimationState:SetAnimation(0, fightAnim[1], false)
    --             this.SetAnimPanelState(false)
    --             UIManager.OpenPanel(UIName.FormationPanel, FORMATION_TYPE.STORY, FightPointPassManager.curOpenFight)
    --         end, 1)
    --         this.animTimer:Start()
    --         -- 第一个动画播放完毕之后
    --         this.PlayInfoAnim(false, FightPointPassManager.IsFightBoss())
    --     end
    -- end
    -- this.swicthPanel = Util.GetGameObject(self.gameObject, "SwitchAnim")
    -- this.animGo = poolManager:LoadLive(fightAnimRes, this.swicthPanel.transform, Vector3.one, Vector3.one)
    -- fightSkeleton = this.animGo:GetComponent("SkeletonGraphic")
    -- fightSkeleton.AnimationState.Complete = fightSkeleton.AnimationState.Complete + idle
    -- poolManager:SetLiveClearCall(fightAnimRes, this.animGo, function()
    --     fightSkeleton.AnimationState.Complete = fightSkeleton.AnimationState.Complete - idle
    -- end)
    -- this.fightInfo = Util.GetGameObject(self.gameObject, "Bg/Image/info"):GetComponent("Text")
    -- this.imgInfo = Util.GetGameObject(self.gameObject, "Bg/Image")
    FightPointPassManager.GetLastFightID()
    --寻宝入口
    this.btnFindTreasure = Util.GetGameObject(self.gameObject, "Bg/RightUpVertical/btnFindTreasure/Button")
    this.btnFindTreasure:GetComponent("Image").sprite=this.spLoader:LoadSprite("x_xb_quan_01_zh")
    this.btnFindTreasureImage = Util.GetGameObject(self.gameObject, "Bg/RightUpVertical/btnFindTreasure/Button/RadarBG"):GetComponent("Image")
    this.btnFindTreasureText = Util.GetGameObject(self.gameObject, "Bg/RightUpVertical/btnFindTreasure/Image/num"):GetComponent("Text")
    this.btnFindTreasureredPoint = Util.GetGameObject(self.gameObject, "Bg/RightUpVertical/btnFindTreasure/redPoint")
    --逍遥游入口
    this.btnXiaoYao=Util.GetGameObject(self.gameObject,"Bg/RightUpVertical/xiaoyaoBtn")
    this.btnXiaoYao:GetComponent("Image").sprite=this.spLoader:LoadSprite("x_xiaoyaoyou_daanniu_zh")
    Util.GetGameObject(this.btnXiaoYao,"Image"):GetComponent("Image").sprite=this.spLoader:LoadSprite("x_xiaoyaoyou_daanniu_zh")
    this.xiaoyaoRedPoint=Util.GetGameObject(self.gameObject,"Bg/RightUpVertical/xiaoyaoBtn/redPoint")
    this.funcBtnList[FUNCTION_OPEN_TYPE.XiaoYaoYou] = this.btnXiaoYao
    --解锁功能
    this.openFun = Util.GetGameObject(self.gameObject, "Bg/RightUpVertical/openFun")
    this.openFunNeedInfo = Util.GetGameObject(self.gameObject, "Bg/RightUpVertical/openFun/needInfo"):GetComponent("Text")
    this.openFunFunInfo = Util.GetGameObject(self.gameObject, "Bg/RightUpVertical/openFun/funInfo"):GetComponent("Text")
    -- 开服福利
    this.UI_Effect_MuBiaoJiangLi = Util.GetGameObject(self.gameObject, "Bg/LeftUp/box/btnOpenSeverWelfare/UI_Effect_MuBiaoJiangLi")
    this.btnOpenSeverWelfare = Util.GetGameObject(self.gameObject, "Bg/LeftUp/box/btnOpenSeverWelfare")
    this.OpenSeverWelfare = Util.GetGameObject(self.gameObject, "Bg/LeftUp/box/btnOpenSeverWelfare/bg")
    this.OpenSeverWelfareicon = Util.GetGameObject(this.UI_Effect_MuBiaoJiangLi, "UI_MuBiaoJiangLi_Import_05"):GetComponent("Image")
    this.OpenSeverWelfareiconText = Util.GetGameObject(this.OpenSeverWelfare, "iconText"):GetComponent("Image")
    this.OpenSeverWelfareProgressText = Util.GetGameObject(this.OpenSeverWelfare, "progressBg/progress"):GetComponent("Text")
    this.OpenSeverWelfareProgressImage = Util.GetGameObject(this.OpenSeverWelfare, "progressBg/progressImage"):GetComponent("Image")
    this.OpenSeverWelfareTimeText = Util.GetGameObject(this.OpenSeverWelfare, "time"):GetComponent("Text")
    this.OpenSeverWelfareInfoText = Util.GetGameObject(this.OpenSeverWelfare, "info"):GetComponent("Text")
    this.OpenSeverWelfareRed = Util.GetGameObject(this.OpenSeverWelfare, "redpot")
    this.battleUpLvTip = Util.GetGameObject(self.gameObject, "Bg/btnDown/battleUpLvTip")
    Util.GetGameObject(self.gameObject, "Bg/btnDown/battleUpLvTip/Text"):GetComponent("Text").text = Language[10610]
    --山河社稷图
    this.btnFightLevel = Util.GetGameObject(self.gameObject, "Bg/LeftUp/box/btnFightLevel")
    this.funcBtnList[FUNCTION_OPEN_TYPE.FIGHTLEVEL] = this.btnFightLevel
    this.btnFightLevelRedPoint = Util.GetGameObject(this.btnFightLevel, "redPoint")
    
end
--绑定事件(用于子类重写)
function FightPointPassMainPanel:BindEvent()
    invadeMonster:BindEvent()
    -- 日常任务
    Util.AddClick(this.btnDailyMission, function ()
        FightPointPassManager.isBeginFight = true
        UIManager.OpenPanel(UIName.MissionDailyPanel)
    end)
    -- 关卡排行
    Util.AddClick(this.btnRank, function ()
        --PopupTipPanel.ShowTip("关卡排行!")
        FightPointPassManager.isBeginFight = true
        --UIManager.OpenPanel(UIName.FightPointPassRankPopup)
        UIManager.OpenPanel(UIName.RankingSingleListPanel,rankKingList[1])
    end)
    -- 挂机奖励
    Util.AddClick(this.btnrewardDetail, function ()
        UIManager.OpenPanel(UIName.FightAreaRewardPopup)
    end)
    -- 我要喝牛奶变强
    Util.AddClick(this.btnGetForce, function ()
       UIManager.OpenPanel(UIName.GiveMePowerPanel)
    end)
    Util.AddClick(this.btnFight, function ()
        this.ExcuteBattle()
    end)
    Util.AddClick(this.btnMap, function ()
        if not FightPointPassManager.IsChapterClossState() then
            UIManager.OpenPanel(UIName.FightSmallChoosePanel, FightPointPassManager.lastPassFightId)
        else
            UIManager.OpenPanel(UIName.FightSmallChoosePanel, FightPointPassManager.curOpenFight)
        end
    end)
    --通关豪礼
    Util.AddClick(this.pgBtn,function()
        FightPointPassManager.isBeginFight = true
        UIManager.OpenPanel(UIName.PassGiftPopup)
    end)
    --寻宝
    Util.AddClick(this.btnFindTreasure,function()
        if ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.FINDTREASURE) then
            UIManager.OpenPanel(UIName.FindTreasureMainPanel)
        else
            PopupTipPanel.ShowTip(ActTimeCtrlManager.GetFuncTip(FUNCTION_OPEN_TYPE.FINDTREASURE))
        end
    end)
    --逍遥游
    Util.AddClick(this.btnXiaoYao,function()
        XiaoYaoManager.OpenMapList()
    end)
    Util.AddClick(this.btnOpenSeverWelfare, function()
        UIManager.OpenPanel(UIName.OpenSeverWelfarePanel)
    end)
    Util.AddClick(this.btnFightLevel, function()
        UIManager.OpenPanel(UIName.FightLevelChapterPanel)
    end)
    Util.AddClick(this.goVipButton, function()
        UIManager.OpenPanel(UIName.VipPanelV2)
    end)
    Util.AddClick(this.getRewardButton, function()
        local t, task = VipManager.GetVipTaskShowInFight()
        if t == 1 and task.state == VipTaskStatusDef.NotFinished then
            local taskConfigInfo = ConfigManager.GetConfigData(ConfigName.TaskConfig, task.missionId)
            JumpManager.GoJump(taskConfigInfo.Jump[1])
        else
            UIManager.OpenPanel(UIName.VipPanelV2)
        end
    end)
    BindRedPointObject(RedPointType.DailyTaskMain, this.dailyRedPoint)
    BindRedPointObject(RedPointType.SecretTer_IsCanFight, this.fightRP)
    BindRedPointObject(RedPointType.XiaoYaoYouRedPoint, this.xiaoyaoRedPoint)
    BindRedPointObject(RedPointType.FightLevel, this.btnFightLevelRedPoint)
end
function this.SetInitAnim()
    -- 隐藏界面特效
    -- count = 1
    -- this.GuideEffectGo:SetActive(false)
    -- this.GuideJumpEffectGo:SetActive(false)
    -- this.swicthPanel:SetActive(true)
    -- this.SetAnimPanelState(true)
    -- fightSkeleton.AnimationState:SetAnimation(0, fightAnim[2], false)
    -- isAnimActive = true
    -- chooseAnim = FightPointPassManager.IsFightBoss() and 4 or 3
    fightMap.StopAction()
    UIManager.OpenPanel(UIName.FightLevelSwitchPopup, true)
end
-- 隐藏显示面板
-- function this.SetAnimPanelState(isShow)
--     local offset = isShow and 0 or 2000
--     this.swicthPanel.transform.localPosition = Vector3.New(offset, 0, 0 )
-- end
--添加事件监听(用于子类重写)
function FightPointPassMainPanel:AddListener()
    invadeMonster:AddListener()
    fightMap:AddListener()
    Game.GlobalEvent:AddEvent(GameEvent.FunctionCtrl.OnFunctionOpen, this.BtnsIsOpen)
    Game.GlobalEvent:AddEvent(GameEvent.Bag.BagGold, this.UpdateFindTreasureMaterialNum)
    Game.GlobalEvent:AddEvent(GameEvent.FindTreasure.RefreshFindTreasureRedPot, this.RefreshFindTreasureRedPoint)
    Game.GlobalEvent:AddEvent(GameEvent.Mission.GetOpenServerRewardRefreshFightPoint, this.UpdateOpenSeverWelfare)
    Game.GlobalEvent:AddEvent(GameEvent.Player.OnShowBattleUpLvTip, this.RefreshBattleUpLvTip)
    Game.GlobalEvent:AddEvent(GameEvent.Player.OnPlayerLvChange, this.SetFightBtnText)
    Game.GlobalEvent:AddEvent(GameEvent.DynamicTask.OnMissionChange, this.refreshVipTask)
end
--移除事件监听(用于子类重写)
function FightPointPassMainPanel:RemoveListener()
    invadeMonster:RemoveListener()
    fightMap:RemoveListener()
    Game.GlobalEvent:RemoveEvent(GameEvent.FunctionCtrl.OnFunctionOpen, this.BtnsIsOpen)
    Game.GlobalEvent:RemoveEvent(GameEvent.Bag.BagGold, this.UpdateFindTreasureMaterialNum)
    Game.GlobalEvent:RemoveEvent(GameEvent.FindTreasure.RefreshFindTreasureRedPot, this.RefreshFindTre3asureRedPoint)
    Game.GlobalEvent:RemoveEvent(GameEvent.Mission.GetOpenServerRewardRefreshFightPoint, this.UpdateOpenSeverWelfare)
    Game.GlobalEvent:RemoveEvent(GameEvent.Player.OnShowBattleUpLvTip, this.RefreshBattleUpLvTip)
    Game.GlobalEvent:RemoveEvent(GameEvent.Player.OnPlayerLvChange, this.SetFightBtnText)
    Game.GlobalEvent:RemoveEvent(GameEvent.DynamicTask.OnMissionChange, this.refreshVipTask)
end
--界面打开时调用(用于子类重写)
function FightPointPassMainPanel:OnOpen(func)
    this.UpView:OnOpen({ showType = UpViewOpenType.ShowRight, panelType = PanelType.FightPointPass })
    this.BtView:OnOpen(self, { sortOrder = self.sortingOrder, panelType = PanelTypeView.JieLing })
    callBack = nil
    if func then
        callBack = func
    end
end
-- 从战斗出来会加载两次
function FightPointPassMainPanel:OnShow()
    CheckRedPointStatus(RedPointType.XiaoYaoYouRedPoint)
    -- 功能引导存在时不再显示成长界面
    if FightPointPassManager.GetIsOpenRewardUpTip() and not GuideManager.IsFunctionGuideExist() then
        local oldLevelId = FightPointPassManager.lastPassFightId
        local curLevelId = FightPointPassManager.curOpenFight
        local oldLevelConFig = ConfigManager.GetConfigData(ConfigName.MainLevelConfig,oldLevelId)
        local curLevelConFig = ConfigManager.GetConfigData(ConfigName.MainLevelConfig,curLevelId)
        local data = {}
        data.title = "g_guanka_jianglitishen_zh"
        data.itemList = {}
        data.type = 1
        for i = 1, #curLevelConFig.RewardShowMin do
            local oldsinglePro = oldLevelConFig.RewardShowMin[i]
            local cursinglePro = curLevelConFig.RewardShowMin[i]
            local singleItem = {}
            singleItem.icon = cursinglePro[1]
            singleItem.proName = GetLanguageStrById(itemConfig[cursinglePro[1]].Name)
            singleItem.proValue = oldsinglePro[2]
            if cursinglePro[2] - oldsinglePro[2] > 0 then
                singleItem.proValue1 = ""..cursinglePro[2]..""..Language[11567]
            else
                singleItem.proValue1 = ""..cursinglePro[2]..Language[11568]
            end
            table.insert(data.itemList,singleItem)
        end
        UIManager.OpenPanel(UIName.GeneralPopup,GENERAL_POPUP_TYPE.Onhook,data)
    end
    this.RefreshLittleMap()
    this.RefreshPassGiftShow()
    SoundManager.PlayMusic(SoundConfig.BGM_Main)
    -- 调用onshow
    invadeMonster:OnShow()
    if not hasLoad then
        timePressStarted = Time.realtimeSinceStartup
        isAnimActive = false
        local curName = GetLanguageStrById(fightLevelConfig[FightPointPassManager.curOpenFight].Name)
        local curDifficulty = fightLevelConfig[FightPointPassManager.curOpenFight].Difficulty
        local chapterId = 0
        local str = ""
        if not FightPointPassManager.IsChapterClossState() then
            chapterId = math.floor(FightPointPassManager.lastPassFightId / 1000)
            str = GetLanguageStrById(fightLevelConfig[FightPointPassManager.lastPassFightId].Name)
        else
            str = string.format("%s ", textColor[curDifficulty], curName)
            chapterId = FightPointPassManager.GetCurChapterIndex()
        end
        this.areaName.text = str
        if GetCurLanguage() ~= 0 then
            this.areaName.gameObject.transform.localPosition = Vector2.New(0,0)
        end
        this.chapterName.text = GetLanguageStrById(fightLevelSetConfig[chapterId].Name)
        -- 奖励预览
        this.IntiReward()    
        -- 刷新关卡按钮状态
        this.SetFightBtnText()
        isCounting = false
        -- 加载地图数据
        coroutine.start(function()
            -- coroutine.wait(0.01)
            if UIManager.IsOpen(UIName.FightPointPassMainPanel) then
                fightMap:Init()
                hasMap = true
            end
        end)
        FightPointPassManager.isBattleBack = false
        hasLoad = true
        this:Update()
        if callBack then 
            callBack()
            callBack = nils
        end
    end
    this.BtnsIsOpen()
    --寻宝显示
    this.UpdateFindTreasureMaterialNum()
    local openFunConFig = this.GetNextFightOpenFun()
    if openFunConFig then
        this.openFun:SetActive(true)
        this.openFunNeedInfo.text = ConfigManager.GetConfigData(ConfigName.MainLevelConfig,openFunConFig.OpenRules[2]).Name
        this.openFunFunInfo.text = Language[12163]..openFunConFig.Name
    else
        this.openFun:SetActive(false)
    end --开服福利显示
    this.UpdateOpenSeverWelfare()
    
    PlayerManager.StarBattleUpLvTipTime(2)
    this.battleUpLvTip:SetActive(false)
    Util.GetGameObject(this.btnXiaoYao,"curValue/num"):GetComponent("Text").text=string.format("%d/%d",BagManager.GetItemCountById(UpViewRechargeType.YunYouVle),PrivilegeManager.GetPrivilegeNumber(39))
    
    -- 刷新一次编队战斗力
    FormationManager.RefreshMainFormationPower()
    PatFaceManager.RefreshPatface()
    -- 刷新任务显示
    this.refreshVipTask()
end
-- 刷新任务显示
function this.refreshVipTask()
    local t, task = VipManager.GetVipTaskShowInFight()
    -- 满级后不再显示
    this.mainTask:SetActive(t ~= -1)
    if t == 0 then
        -- 能激活时显示激活特权
        this.titleText.text = "前往升级特权"
        this.progressText.text = ""
    elseif t == 1 then
        -- 不能激活时显示任务
        local taskConfigInfo = ConfigManager.GetConfigData(ConfigName.TaskConfig, task.missionId)
        local color = task.state == VipTaskStatusDef.CanReceive and UIColorStr.GREEN or UIColorStr.YELLOW 
        this.titleText.text = GetLanguageStrById(taskConfigInfo.Desc)
        -- 避免显示的太长
        if tonumber(taskConfigInfo.TaskValue[2][1]) < 10000 then
            this.titleText.text = this.titleText.text .. string.format("(%s/%s)", color, task.progress, taskConfigInfo.TaskValue[2][1])
        end
        this.progressText.text = ""
        this.mainTaskGRewardImage:SetActive(task.state ~= VipTaskStatusDef.NotFinished)
        this.mainTaskJumpImage:SetActive(task.state == VipTaskStatusDef.NotFinished)
    end
end
--寻宝显示
function this.UpdateFindTreasureMaterialNum()
    local mazeTreasureMax = ConfigManager.GetConfigData(ConfigName.PlayerLevelConfig,PlayerManager.level).MazeTreasureMax
    this.btnFindTreasureImage.fillAmount = BagManager.GetItemCountById(FindTreasureManager.materialItemId) / mazeTreasureMax
    this.btnFindTreasureText.text = BagManager.GetItemCountById(FindTreasureManager.materialItemId)
    this.RefreshFindTreasureRedPoint()
end
function this.RefreshFindTreasureRedPoint()
    this.btnFindTreasureredPoint:SetActive(FindTreasureManager.RefreshFindTreasureRedPoint())
end
-- -- 小怪 258 boss 570
-- -- 播放那个动画
-- function this.PlayInfoAnim(isInit, isBoss)
--     if isInit then
--         this.imgInfo.transform.localPosition = Vector3.New(0, -187, 0)
--         this.imgInfo:SetActive(false)
--     else
--         this.imgInfo:SetActive(true)
--         local targetPos = Vector3.zero
--         targetPos = isBoss and Vector3.New(0, 570, 0) or Vector3.New(0, 288, 0)
--         this.imgInfo:GetComponent("RectTransform"):DOAnchorPos(targetPos, 0.3, false):OnComplete(function ()
--             --this.imgInfo:SetActive(false)
--         end)
--         this.imgInfo:GetComponent("Image"):DOFade(1, 0.3):OnComplete(function ()
--         end)
--     end
-- end
local isCanShowMainTaskJumpEffect = true
function this:Update()
    if curMianTaskData and curMianTaskData.state == 0 then
        if isCanShowMainTaskJumpEffect then
            if Time.realtimeSinceStartup - timePressStarted > 5 then
                isCanShowMainTaskJumpEffect = false
                this.GuideJumpEffectGo:SetActive(true)
            end
        end
        if Input.GetMouseButtonDown(0) then
            timePressStarted = Time.realtimeSinceStartup
            isCanShowMainTaskJumpEffect = true
            this.GuideJumpEffectGo:SetActive(false)
        end
    end
end
--按钮开启限制
function this.BtnsIsOpen()
    for i, v in pairs(this.funcBtnList) do
        local isOpen = ActTimeCtrlManager.SingleFuncState(i)
        v:SetActive(isOpen)
    end
    this.btnRank.gameObject:SetActive(ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.ALLRANKING))
end
function this.IntiReward()
    local rewardData
    if FightPointPassManager.isOpenNewChapter then
        rewardData = fightLevelConfig[FightPointPassManager.curOpenFight].RewardShowMin
    else
        rewardData = fightLevelConfig[FightPointPassManager.lastPassFightId].RewardShowMin
    end
    for i = 1, #rewardData do
        if not this.rewardList[i] then
            local go = {}
            go.item = newObjToParent(this.rewardItemPre, this.rewardGrid)
            go.icon = Util.GetGameObject(go.item, "iconBg/icon"):GetComponent("Image")
            go.text = Util.GetGameObject(go.item, "rewardbg/context"):GetComponent("Text")
            this.rewardList[i] = go
        end
        this.rewardList[i].icon.sprite = SetIcon(this.spLoader, rewardData[i][1])
        local addValue = FightPointPassManager.GetItemVipValue(rewardData[i][1])
        if addValue - 1 <= 0 then
            this.rewardList[i].text.text = string.format(Language[10611], rewardData[i][2])
        else
            local valueShow = (addValue - 1) * 100
            this.rewardList[i].text.text ="   ×" ..rewardData[i][2].."(+"..valueShow..Language[10612]
        end
    end
end
--刷新通关豪礼主界面显示
function this.RefreshPassGiftShow()
    local mainLevelEndId=ConfigManager.TryGetConfigDataByKey(ConfigName.MainLevelConfig,"NextLevel",-1).Id--最高关卡
    if FightPointPassManager.curOpenFight==mainLevelEndId then
        this.pgBtn:SetActive(false)
        return
    end
    if ActTimeCtrlManager.IsQualifiled(56) then
        this.pgBtn:SetActive(true)
    else
        this.pgBtn:SetActive(false)
        return
    end
    local liveId,tarPointId=ActivityGiftManager.GetNextHeroInfo()
    if liveId==0 or tarPointId==0 then
        this.pgBtn:SetActive(false)
        return
    end
    --通过立绘id在itemconfig表中读出herostar 已确定该id在heroconfig中的唯一值
    local heroStar=ConfigManager.GetConfigData(ConfigName.ItemConfig,liveId).HeroStar[1]
    local heroData=ConfigManager.GetConfigData(ConfigName.HeroConfig,heroStar)
    this.pgHead.sprite=this.spLoader:LoadSprite(GetResourcePath(heroData.Icon))
    this.pgFrame.sprite=SetFrame(this.spLoader, liveId)
    if heroData.Natural==13 or heroData.Natural==14 then
        this.pgGive.text=Language[10613]
    elseif heroData.Natural==11 or heroData.Natural==12 then
        this.pgGive.text=Language[10614]
    end
    this.pgName.text=GetLanguageStrById(heroData.ReadingName)
    this.pgInfo.text= Language[10309]..GetLanguageStrById(ActivityGiftManager.mainLevelConfig[tarPointId].Name)
end
-- 设置挑战按钮文字
function this.SetFightBtnText()
    this.fightLock:SetActive(false)
    this.fightSaoGuang:SetActive(true)
    local isPass = FightPointPassManager.IsCanFight(FightPointPassManager.curOpenFight)
    if not isCounting then
        if not isPass then
            this.fightLock:SetActive(true)
            this.fightSaoGuang:SetActive(false)
            this.lockText.text = FightPointPassManager.GetBtnText()
        else
            this.fightText.text = FightPointPassManager.GetBtnText()
        end
    end
end
-- 执行关卡战斗
function this.ExcuteBattle()
    if not FightPointPassManager.IsChapterClossState() then
        --fightMap.StopAction()
        if hasMap then
            LogGreen("关闭挂机")
            fightMap:OnClose()
            hasMap = false
        end
        UIManager.OpenPanel(UIName.FightMiddleChoosePanel, FightPointPassManager.curOpenFight, true,function ()
            --- 临时代码
            --FightPointPassManager.SetChapterOpenState(false)
        end)
        return
    end
    if isCounting then PopupTipPanel.ShowTip(Language[10615]) return end
    local curFightId = FightPointPassManager.curOpenFight
    local state, tip = FightPointPassManager.IsCanFight(curFightId)
    if state == -1 then
        PopupTipPanel.ShowTip(tip)
        return
    end
    if not state then
        PopupTipPanel.ShowTip(tip)
        return
    end
    this.SetInitAnim()
end
function FightPointPassMainPanel:OnSortingOrderChange()
    invadeMonster:OnSortingOrderChange()
    Util.AddParticleSortLayer(this.GuideEffectGo, self.sortingOrder - orginLayer)
    Util.AddParticleSortLayer(this.GuideJumpEffectGo, self.sortingOrder - orginLayer)
    Util.AddParticleSortLayer(this.pgEffect, self.sortingOrder - orginLayer)
    Util.AddParticleSortLayer(this.UI_Effect_MuBiaoJiangLi, self.sortingOrder - orginLayer)
    Util.SetParticleSortLayer(this.fightSaoGuang, self.sortingOrder + 1)
    fightMap:OnSortingOrderChange(self.sortingOrder)
    orginLayer = self.sortingOrder
    
    this.BtView:SetOrderStatus({ sortOrder = self.sortingOrder })
    -- 头像层级
    if this.playerInfoView then
        this.playerInfoView:SetLayer(self.sortingOrder)
    end
end
--界面关闭时调用(用于子类重写)
function FightPointPassMainPanel:OnClose()
    PatFaceManager.isLogin = false
    PlayerManager.StopBattleUpLvTipTime()
    hasLoad = false
    invadeMonster:OnClose()
    if hasMap then
        fightMap:OnClose()
        hasMap = false
    end
    if this.animTimer then
        this.animTimer:Stop()
    end
    this.animTimer = nil
    if this.liveNode then
        this.liveNode:OnClose()
    end
    if this.liveNode then
        this.liveNode:OnClose()
    end
    if this.timer then
        this.timer:Stop()
        this.timer = nil
    end
end
--界面销毁时调用(用于子类重写)
function FightPointPassMainPanel:OnDestroy()
    orginLayer=0
    invadeMonster:OnDestroy()
    this.spLoader:Destroy()
    -- poolManager:UnLoadAsset("GuideEffect", this.GuideEffectGo, PoolManager.AssetType.GameObject)
    -- poolManager:UnLoadAsset("GuideEffect", this.GuideJumpEffectGo, PoolManager.AssetType.GameObject)
    poolManager:UnLoadLive(fightAnimRes, this.animGo, PoolManager.AssetType.GameObject)
    SubUIManager.Close(this.UpView)
    SubUIManager.Close(this.BtView)
    ClearRedPointObject(RedPointType.DailyTaskMain, this.dailyRedPoint)
    ClearRedPointObject(RedPointType.SecretTer_IsCanFight, this.fightRP)
    ClearRedPointObject(RedPointType.XiaoYaoYouRedPoint, this.xiaoyaoRedPoint)
    ClearRedPointObject(RedPointType.FightLevel, this.btnFightLevelRedPoint)
    -- 头像层级
    if this.playerInfoView then
        SubUIManager.Close(this.playerInfoView)
        this.playerInfoView = nil
    end
    points = {}
end
--跳转显示新手提示圈
function FightPointPassMainPanel.ShowGuideGo(btnIndex)
    if btnIndex == 1 then--关卡
        if this.btnFight then
            JumpManager.ShowGuide(UIName.FightPointPassMainPanel, this.btnFight)
        end
    elseif btnIndex == 6 then--在线
        if invadeMonster.btnRewardOnline then
            JumpManager.ShowGuide(UIName.FightPointPassMainPanel, invadeMonster.btnRewardOnline)
        end
    elseif btnIndex == 5 then--章节奖励
        if invadeMonster.btnRewrdChapter then
            JumpManager.ShowGuide(UIName.FightPointPassMainPanel, invadeMonster.btnRewrdChapter)
        end
    elseif btnIndex == 2 then--极速探索
        if invadeMonster.btnFastExplore then
            JumpManager.ShowGuide(UIName.FightPointPassMainPanel, invadeMonster.btnFastExplore)
        end
    elseif btnIndex == 3 then--召唤外敌
        if invadeMonster.callMonsterBtn then
            JumpManager.ShowGuide(UIName.FightPointPassMainPanel, invadeMonster.callMonsterBtn)
        end
    elseif btnIndex == 4 then--挂机宝箱
        if invadeMonster.rewardBox then
            JumpManager.ShowGuide(UIName.FightPointPassMainPanel, invadeMonster.rewardBox)
        end
    end
end
--刷新小地图
function this.RefreshLittleMap()
    --获取数据
    if not FightPointPassManager.IsChapterClossState() then
        this.integer, this.decimal = math.modf(FightPointPassManager.lastPassFightId/1000)--确定区域id
    else
        this.integer, this.decimal = math.modf(FightPointPassManager.curOpenFight/1000)
    end
    local data=ConfigManager.GetConfigData(ConfigName.MainLevelSettingConfig,this.integer)--获取这一区域所有数据
    local difficulty=FightPointPassManager.curOpenFight%10 --确定当前区域难度
    local curAllLevelNum = 0
    --根据当前难度 检查对应区域数据
    if difficulty==1 then
        this.CheckMapPointsData(data.SimpleLevel)
        curAllLevelNum = #data.SimpleLevel
    elseif difficulty==2 then
        this.CheckMapPointsData(data.NormalLevel)
        curAllLevelNum = #data.NormalLevel
    elseif difficulty==3 then
        this.CheckMapPointsData(data.DifficultyLevel)
        curAllLevelNum = #data.DifficultyLevel
    elseif difficulty==4 then
        this.CheckMapPointsData(data.HellLevel)
        curAllLevelNum = #data.HellLevel
    elseif difficulty==5 then
        this.CheckMapPointsData(data.NightmareLevel)
        curAllLevelNum = #data.NightmareLevel
    end
    --计算小地图当前点位 更换地图
    local sonPoint = FightPointPassManager.GetLevelPointPosition()
    local parentPosX,parentPosY=FightPointPassManager.CalculateMapPointPos(this.map.transform,sonPoint)
    this.map.transform.anchoredPosition3D=Vector3(parentPosX,parentPosY-52.4,0) --52.4是策划的选择!!
    this.mapImage.sprite=this.spLoader:LoadSprite(data.ChapterBg)
    --加载立绘
    -- if this.liveNode then
    --     return
    -- end
    -- npc = NameManager.roleSex == ROLE_SEX.BOY and mapNpc or mapNpc2
    -- scale = NameManager.roleSex == ROLE_SEX.BOY and Vector3.one * 0.14 or Vector3.one * 0.07
    local curLevel = 0
    if not FightPointPassManager.IsChapterClossState() then
        curLevel = math.floor(FightPointPassManager.lastPassFightId/10)%100
    else
        curLevel = math.floor(FightPointPassManager.curOpenFight/10)%100
    end
    this.btnMapRadarBG.fillAmount = curLevel / curAllLevelNum
    this.RadarBGText.text = curLevel .."/".. curAllLevelNum
    -- this.liveNode = poolManager:LoadLive(npc, this.btnMap.transform, scale, Vector3.New(0,-52.4,0))
    -- local SkeletonGraphic = this.liveNode:GetComponent("SkeletonGraphic")
    -- if SkeletonGraphic then
    --     SkeletonGraphic.AnimationState:SetAnimation(0, "move2", true)
    --     if FightPointPassManager.GetRoleDirection()==1 then
    --         SkeletonGraphic.transform.localEulerAngles = Vector3.New(0, 180, 0)
    --     else
    --         SkeletonGraphic.transform.localEulerAngles = Vector3.New(0, 0, 0)
    --     end
    -- end
    if this.liveNode then
        this.liveNode:OnClose()
    end
    this.liveNode = PlayerLiveView:New(this.btnMap.transform,1,nil,orginLayer)
    this.liveNode:OnOpen(GetPlayerRoleSingleConFig().Scale3,Vector3.New(0,-40,0))
    if FightPointPassManager.GetRoleDirection()==1 then
        this.liveNode:SetWalkDir(WALK_DIR.RUN_LEFT)
    else
        this.liveNode:SetWalkDir(WALK_DIR.RUN_RIGHT)
    end
end
--检查地图点数据
function this.CheckMapPointsData(pointsData)
    for i = 1, math.max(#pointsData, #points)do
        local go = points[i]
        if not go then
            go=newObject(points[1])
            go.transform:SetParent(Util.GetGameObject(this.btnMap,"MapMask/Map").transform)
            go.transform.localScale = Vector3.one
            go.transform.localPosition=Vector3.zero;
            go.gameObject.name = "mapAreaPre (".. i ..")"
            points[i] = go
        end
        go.gameObject:SetActive(false)
    end
    --位置赋值
    for i = 1, #pointsData do
        local data=ConfigManager.GetConfigData(ConfigName.MainLevelConfig, pointsData[i])
        points[i].transform.anchoredPosition3D=Vector3(data.LevelPointPosition[1],data.LevelPointPosition[2],0)
        Util.GetGameObject(points[i].transform, "icon"):SetActive((math.floor((data.Id%100)/10))%5 ~= 0)
        Util.GetGameObject(points[i].transform, "icon2"):SetActive((math.floor((data.Id%100)/10))%5 == 0)
    end
    --显示位置点
    for i = 1, #pointsData do
        points[i]:SetActive(true)
    end
end
--预先显示玩家等级 解锁的功能list
function this.GetNextFightOpenFun()
    local nextFightId = 0
    local nextFightSortId = ConfigManager.GetConfigData(ConfigName.MainLevelConfig,FightPointPassManager.curOpenFight).SortId - 1
    for i, v in ConfigPairs(ConfigManager.GetConfig(ConfigName.GlobalSystemConfig)) do
        if v.OpenRules then
            if v.OpenRules[1] == 1 then--1关卡开启
                local OpenRulesSortId = ConfigManager.GetConfigData(ConfigName.MainLevelConfig,v.OpenRules[2]).SortId
                if OpenRulesSortId > nextFightSortId and  v.IsOpen == 1 and  v.IsShow == 1  then
                    if nextFightId == 0 then
                        nextFightId = v.OpenRules[2]
                    else
                        if ConfigManager.GetConfigData(ConfigName.MainLevelConfig,nextFightId).SortId > OpenRulesSortId  then
                            nextFightId = v.OpenRules[2]
                        end
                    end
                end
            end
        end
    end
    for i, v in ConfigPairs(ConfigManager.GetConfig(ConfigName.GlobalSystemConfig)) do
        if v.OpenRules then
            if v.OpenRules[1] == 1 then--1关卡开启
                if v.OpenRules[2] == nextFightId and  v.IsOpen == 1 and  v.IsShow == 1 then
                    return v
                end
            end
        end
    end
    return nil
end
--开服福利显示 开始
local OpenSeverWelfareRewardShow = {
    [16] = {image1 = "r_guanka_guankajiangliyaojin",image2 = "r_guanka_guankajiangli01_zh"},
    [19] = {image1 = "r_guanka_guankajianglishenfu",image2 = "r_guanka_guankajiangli02_zh"},
    [81128] = {image1 = "r_guanka_guankajianglibaoxiang",image2 = "r_guanka_guankajiangli03_zh"},
    [11023] = {image1 = "r_guanka_guankajianglishunwukong",image2 = "r_guanka_guankajiangli04_zh"},
}
function this.UpdateOpenSeverWelfare()
    local mainLevelConfig = ConfigManager.GetConfig(ConfigName.MainLevelConfig)
    local activityRewardConfig = ConfigManager.GetConfig(ConfigName.ActivityRewardConfig)
    local activityId = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.OpenSeverWelfare)
    local activityData = ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.OpenSeverWelfare)
    --LogGreen("#activityData.mission       "..#activityData.mission)
    if activityId and activityId > 0 and activityData and #activityData.mission > 0 then
        ActivityGiftManager.OpenSeverWelfareRewardTabsSort(activityData.mission)
        local curMissionConfig = nil
        local isShowBtn = false
        for i = 1, #activityData.mission do
            if activityData.mission[i].state == 0 and not curMissionConfig then
                curMissionConfig = activityRewardConfig[activityData.mission[i].missionId]
            end
            if activityData.mission[i].state == 0 then
                isShowBtn = true
            end
        end
        this.btnOpenSeverWelfare:SetActive(isShowBtn)
        if not curMissionConfig then return end
        this.OpenSeverWelfareicon.sprite = this.spLoader:LoadSprite(OpenSeverWelfareRewardShow[curMissionConfig.Reward[1][1]].image1)
        this.OpenSeverWelfareiconText.sprite = this.spLoader:LoadSprite(OpenSeverWelfareRewardShow[curMissionConfig.Reward[1][1]].image2)
        this.OpenSeverWelfareicon:SetNativeSize()
        local curPassLevelSortId = FightPointPassManager.lastPassFightId ~= FightPointPassManager.curOpenFight and mainLevelConfig[FightPointPassManager.lastPassFightId].SortId or 0
        local getRewardLevelSortId = mainLevelConfig[curMissionConfig.Values[1][1]].SortId
        this.OpenSeverWelfareRed:SetActive(curPassLevelSortId >= getRewardLevelSortId)
        curPassLevelSortId =  curPassLevelSortId >= getRewardLevelSortId and getRewardLevelSortId or curPassLevelSortId
        this.OpenSeverWelfareProgressText.text = curPassLevelSortId .. "/" .. getRewardLevelSortId
        this.OpenSeverWelfareProgressImage.fillAmount =curPassLevelSortId/ getRewardLevelSortId
        this.OpenSeverWelfareInfoText.text = GetLanguageStrById(curMissionConfig.ContentsShow)
        this.RemainTimeDown(this.btnOpenSeverWelfare,this.OpenSeverWelfareTimeText,activityData.endTime - GetTimeStamp())
    else
        this.btnOpenSeverWelfare:SetActive(false)
    end
end
this.timer = Timer.New()
--刷新倒计时显示
function this.RemainTimeDown(_timeTextExpertgo,_timeTextExpert,timeDown)
    if timeDown > 0 then
        if _timeTextExpertgo then
            _timeTextExpertgo:SetActive(true)
        end
        if _timeTextExpert then
            _timeTextExpert.text =  GetLeftTimeStrByDeltaTime2(timeDown)
        end
        if this.timer then
            this.timer:Stop()
            this.timer = nil
        end
        this.timer = Timer.New(function()
            if _timeTextExpert then
                _timeTextExpert.text =  GetLeftTimeStrByDeltaTime2(timeDown)
            end
            if timeDown < 0 then
                if _timeTextExpertgo then
                    _timeTextExpertgo:SetActive(false)
                end
                this.timer:Stop()
                this.timer = nil
            end
            timeDown = timeDown - 1
        end, 1, -1, true)
        this.timer:Start()
    else
        if _timeTextExpertgo then
            _timeTextExpertgo:SetActive(false)
        end
    end
end
function this.RefreshBattleUpLvTip()
    this.battleUpLvTip:SetActive(true)
end
--开服福利显示 结束
return FightPointPassMainPanel