using System; 
 | 
using System.Collections; 
 | 
using System.Collections.Generic; 
 | 
using UnityEngine; 
 | 
using UnityEngine.UI; 
 | 
  
 | 
/// <summary> 
 | 
/// 游戏主界面(主战斗场景) 
 | 
/// </summary> 
 | 
public class HomeWin : UIBase 
 | 
{ 
 | 
  
 | 
    //经验区 
 | 
    [SerializeField] Text playerLevelText; 
 | 
    [SerializeField] SmoothSlider expSlider; 
 | 
    [SerializeField] Button officialUpBtn; 
 | 
  
 | 
    //任务区 
 | 
    [SerializeField] Button taskButton; //引导或者领取任务奖励 
 | 
    [SerializeField] RichText taskText; 
 | 
    [SerializeField] Text taskNumText; 
 | 
    [SerializeField] Image awardIcon; 
 | 
    [SerializeField] Text awardCnt; 
 | 
    [SerializeField] UIEffectPlayer taskEffect; 
 | 
    [SerializeField] UIEffectPlayer lvUPEffect; 
 | 
  
 | 
    //关卡 
 | 
    [SerializeField] Button bossBtn; 
 | 
    [SerializeField] MainLevelWaveCell[] mainLevelWaves; 
 | 
    [SerializeField] ScrollRect mainLevelScrollRect; 
 | 
    [SerializeField] Text levelName; 
 | 
  
 | 
    [SerializeField] GameObject restMark; 
 | 
    [SerializeField] Button restBtn; 
 | 
    [SerializeField] GameObject fightMark; 
 | 
    [SerializeField] ScaleTween bossTween; 
 | 
    [SerializeField] GameObject bossmask;   //完成进度遮挡管道 纯显示 
 | 
    [SerializeField] GameObject bossActiveGo; 
 | 
    [SerializeField] GameObject bitemeGo; 
 | 
    [SerializeField] Text processText; 
 | 
  
 | 
  
 | 
    //卡牌 
 | 
    [SerializeField] HeroFightingCardCell[] heroFightingCardCells; 
 | 
    [SerializeField] Button changeHeroPosBtn; 
 | 
  
 | 
    //底部功能 
 | 
    [SerializeField] Button autoBtn; 
 | 
    [SerializeField] Image autoCloseImg; 
 | 
    [SerializeField] UIEffectPlayer autoOpenEffect; 
 | 
    [SerializeField] Button blessLVBtn; 
 | 
    [SerializeField] Text blessLVText; 
 | 
    [SerializeField] Button mailBtn; 
 | 
  
 | 
    //右侧功能 
 | 
    [SerializeField] Button funcColBtn; 
 | 
    [SerializeField] RightFuncInHome rightFuncInHome; 
 | 
  
 | 
    [SerializeField] Button FirstChargeBtn; 
 | 
  
 | 
    /// <summary> 
 | 
    /// 初始化组件 
 | 
    /// </summary> 
 | 
    protected override void InitComponent() 
 | 
    { 
 | 
        taskButton.AddListener(OnClickTaskButton); 
 | 
        bossBtn.AddListener(OnClickEnterBoss); 
 | 
  
 | 
        changeHeroPosBtn.AddListener(() => 
 | 
        { 
 | 
            HeroUIManager.Instance.selectTeamType = TeamType.Story; 
 | 
            UIManager.Instance.OpenWindow<HeroPosWin>(); 
 | 
        }); 
 | 
  
 | 
        autoBtn.AddListener(() => 
 | 
        { 
 | 
            if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.AutoFight, true)) 
 | 
            { 
 | 
                return; 
 | 
            } 
 | 
            UIManager.Instance.OpenWindow<AutoFightWin>(); 
 | 
        }); 
 | 
  
 | 
  
 | 
  
 | 
  
 | 
        FirstChargeBtn.AddListener(() => 
 | 
        { 
 | 
            UIManager.Instance.OpenWindow<FirstChargeWin>(); 
 | 
        }); 
 | 
  
 | 
        blessLVBtn.AddListener(() => 
 | 
        { 
 | 
            if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.BlessLV, true)) 
 | 
            { 
 | 
                return; 
 | 
            } 
 | 
            UIManager.Instance.OpenWindow<BlessLVWin>(); 
 | 
        }); 
 | 
  
 | 
        mailBtn.AddListener(() => 
 | 
        { 
 | 
            UIManager.Instance.OpenWindow<MailWin>(); 
 | 
        }); 
 | 
  
 | 
        officialUpBtn.AddListener(() => 
 | 
        { 
 | 
            if (RealmConfig.GetKeys().Count <= PlayerDatas.Instance.baseData.realmLevel) 
 | 
                return; 
 | 
            UIManager.Instance.OpenWindow<OfficialUpWin>(); 
 | 
        }); 
 | 
  
 | 
        restBtn.AddListener(GotoRest); 
 | 
        funcColBtn.AddListener(()=> 
 | 
        { 
 | 
            rightFuncInHome.ShowFuncCol(true); 
 | 
        }); 
 | 
    } 
 | 
  
 | 
  
 | 
  
 | 
  
 | 
    public void Display() 
 | 
    { 
 | 
        UpdatePlayerInfo(); 
 | 
        UpdateTask(); 
 | 
        RefreshRecharge(); 
 | 
        ShowBlessLV(); 
 | 
        DisplayAutoFight(); 
 | 
        DisplayCard(TeamType.Story); 
 | 
        DisplayLevel(); 
 | 
        DisplayRestState(); 
 | 
  
 | 
    } 
 | 
  
 | 
    protected override void OnPreOpen() 
 | 
    { 
 | 
        PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefresh; 
 | 
        TaskManager.Instance.OnTaskUpdate += UpdateTask; 
 | 
        BlessLVManager.Instance.OnBlessLVUpdateEvent += ShowBlessLV; 
 | 
        AutoFightModel.Instance.ChangeAutoEvent += DisplayAutoFight; 
 | 
        AutoFightModel.Instance.OnFightEvent += ChangeMode; 
 | 
        TeamManager.Instance.OnTeamChange += DisplayCard; 
 | 
        UIManager.Instance.OnCloseWindow += OnCloseWindow; 
 | 
        FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChange; 
 | 
        FirstChargeManager.Instance.OnUpdateFirstChargeInfo += OnUpdateFirstChargeInfo; 
 | 
        GlobalTimeEvent.Instance.secondEvent += OnSecondEvent; 
 | 
        HeroUIManager.Instance.OnUnLockHeroCountEvent += OnUnLockHeroCountEvent; 
 | 
        Display(); 
 | 
        DisplayFirstChargeBtn(); 
 | 
  
 | 
        // var battleWin = UIManager.Instance.OpenWindow<BattleWin>(); 
 | 
        // battleWin.SetBattleField(BattleManager.Instance.storyBattleField); 
 | 
    } 
 | 
  
 | 
  
 | 
  
 | 
    protected override void OnPreClose() 
 | 
    { 
 | 
        PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefresh; 
 | 
        TaskManager.Instance.OnTaskUpdate -= UpdateTask; 
 | 
        BlessLVManager.Instance.OnBlessLVUpdateEvent -= ShowBlessLV; 
 | 
        AutoFightModel.Instance.ChangeAutoEvent -= DisplayAutoFight; 
 | 
        AutoFightModel.Instance.OnFightEvent -= ChangeMode; 
 | 
        TeamManager.Instance.OnTeamChange -= DisplayCard; 
 | 
        UIManager.Instance.OnCloseWindow -= OnCloseWindow; 
 | 
        FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChange; 
 | 
        FirstChargeManager.Instance.OnUpdateFirstChargeInfo -= OnUpdateFirstChargeInfo; 
 | 
        GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent; 
 | 
        HeroUIManager.Instance.OnUnLockHeroCountEvent -= OnUnLockHeroCountEvent; 
 | 
  
 | 
        //  关闭的时候把战斗界面也给关了 虽然是在外面开的 
 | 
        UIManager.Instance.CloseWindow<BattleWin>(); 
 | 
    } 
 | 
  
 | 
    private void OnClickEnterBoss() 
 | 
    { 
 | 
        // BattleField battleField = BattleManager.Instance.GetBattleFieldByMapID(2); //BOSS战斗 
 | 
  
 | 
        // if (null != battleField) 
 | 
        // { 
 | 
        //     StoryBossBattleWin fsBattleWin = UIManager.Instance.OpenWindow<StoryBossBattleWin>(); 
 | 
        //     fsBattleWin.SetBattleField(battleField); 
 | 
        //     return; 
 | 
        // } 
 | 
  
 | 
        UIManager.Instance.OpenWindow<MainBossEnterWin>(); 
 | 
    } 
 | 
  
 | 
    int lastLV = 0; 
 | 
    void PlayerDataRefresh(PlayerDataType type) 
 | 
    { 
 | 
        switch (type) 
 | 
        { 
 | 
            case PlayerDataType.TotalExp: 
 | 
            case PlayerDataType.ExpPoint: 
 | 
                ShowExp(); 
 | 
                break; 
 | 
            case PlayerDataType.LV: 
 | 
                if (lastLV != PlayerDatas.Instance.baseData.LV) 
 | 
                { 
 | 
                    lastLV = PlayerDatas.Instance.baseData.LV; 
 | 
                    lvUPEffect.Play(); 
 | 
                } 
 | 
                playerLevelText.text = PlayerDatas.Instance.baseData.LV.ToString(); 
 | 
                break; 
 | 
            case PlayerDataType.ExAttr1: 
 | 
            case PlayerDataType.ExAttr2: 
 | 
                DisplayLevel(); 
 | 
                break; 
 | 
        } 
 | 
  
 | 
  
 | 
    } 
 | 
  
 | 
    void RefreshRecharge() 
 | 
    { 
 | 
        //monthCardBtn.SetActive(!InvestModel.Instance.IsInvested(InvestModel.monthCardType)); 
 | 
    } 
 | 
  
 | 
  
 | 
    void ShowBlessLV() 
 | 
    { 
 | 
        blessLVText.text = BlessLVManager.Instance.m_TreeLV.ToString(); 
 | 
    } 
 | 
  
 | 
    void DisplayAutoFight() 
 | 
    { 
 | 
        if (AutoFightModel.Instance.isAutoAttackSet) 
 | 
        { 
 | 
            autoCloseImg.SetActive(false); 
 | 
            autoOpenEffect.Play(); 
 | 
        } 
 | 
        else 
 | 
        { 
 | 
            autoCloseImg.SetActive(true); 
 | 
            autoOpenEffect.Stop(); 
 | 
        } 
 | 
  
 | 
  
 | 
    } 
 | 
  
 | 
    /// <summary> 
 | 
    /// 更新玩家信息 
 | 
    /// </summary> 
 | 
    private void UpdatePlayerInfo() 
 | 
    { 
 | 
        playerLevelText.text = PlayerDatas.Instance.baseData.LV.ToString(); 
 | 
        ShowExp(); 
 | 
  
 | 
    } 
 | 
  
 | 
    void ShowExp() 
 | 
    { 
 | 
        var lvConfig = PlayerLVConfig.Get(PlayerDatas.Instance.baseData.LV); 
 | 
        expSlider.value = (float)PlayerDatas.Instance.baseData.curExp / lvConfig.EXP; 
 | 
        expSlider.Text.text = PlayerDatas.Instance.baseData.curExp + "/" + PlayerLVConfig.Get(PlayerDatas.Instance.baseData.LV).EXP; 
 | 
    } 
 | 
  
 | 
  
 | 
    void UpdateTask() 
 | 
    { 
 | 
        var task = TaskManager.Instance.mainTask; 
 | 
        if (task.TaskID == 0) 
 | 
        { 
 | 
            taskButton.SetActive(false); 
 | 
        } 
 | 
        else 
 | 
        { 
 | 
            taskButton.SetActive(true); 
 | 
            var taskConfig = TaskConfig.Get(task.TaskID); 
 | 
            taskText.text = taskConfig.TaskDescribe; 
 | 
            taskNumText.text = string.Format("({0}/{1})", task.CurValue, taskConfig.NeedValue); 
 | 
            taskNumText.color = task.CurValue >= taskConfig.NeedValue ? UIHelper.GetUIColor(TextColType.NavyYellow) : UIHelper.GetUIColor(TextColType.Red); 
 | 
            if (TaskManager.Instance.GetMainTaskState() == 2) 
 | 
            { 
 | 
                taskEffect.Play(); 
 | 
            } 
 | 
            else 
 | 
            { 
 | 
                taskEffect.Stop(); 
 | 
            } 
 | 
            awardIcon.SetOrgSprite(ItemConfig.Get(taskConfig.AwardItemList[0][0]).IconKey); 
 | 
            awardCnt.text = taskConfig.AwardItemList[0][1].ToString(); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    void OnClickTaskButton() 
 | 
    { 
 | 
        if (TaskManager.Instance.GetMainTaskState() == 2) 
 | 
        { 
 | 
            //领取任务奖励 
 | 
            CA504_tagCMPlayerGetReward getReward = new CA504_tagCMPlayerGetReward(); 
 | 
            getReward.RewardType = 66; 
 | 
            getReward.DataEx = (uint)TaskManager.Instance.mainTask.TaskID; 
 | 
            GameNetSystem.Instance.SendInfo(getReward); 
 | 
        } 
 | 
         
 | 
        TaskManager.Instance.ClickTask(); 
 | 
    } 
 | 
  
 | 
    void DisplayCard(TeamType teamType) 
 | 
    { 
 | 
        if (teamType != TeamType.Story) 
 | 
            return; 
 | 
        var team = TeamManager.Instance.GetTeam(teamType); 
 | 
        var heros = team.GetHerosOnTeam(); 
 | 
        //显示卡牌 
 | 
        for (int i = 0; i < heroFightingCardCells.Length; i++) 
 | 
        { 
 | 
            heroFightingCardCells[i].Display(i, heros); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    private void OnCloseWindow(UIBase closeUI) 
 | 
    { 
 | 
        //其他武将功能产生数据变化,需要刷新武将列表 
 | 
        if (closeUI is HeroTrainWin) 
 | 
        { 
 | 
            DisplayCard(TeamType.Story); 
 | 
        } 
 | 
    } 
 | 
  
 | 
  
 | 
    private void DisplayLevel() 
 | 
    { 
 | 
        var value = PlayerDatas.Instance.baseData.ExAttr2; 
 | 
        var chapterID = value / 10000; 
 | 
        var levelNum = value % 10000 / 100; 
 | 
        var waveID = value % 100; 
 | 
  
 | 
        var config = MainLevelConfig.GetMainLevelConfig(chapterID, levelNum); 
 | 
        var totalWave = MainLevelConfig.GetwaveCount(config); 
 | 
        for (int i = 0; i < mainLevelWaves.Length; i++) 
 | 
        { 
 | 
            if (i < totalWave) 
 | 
            { 
 | 
                mainLevelWaves[i].SetActive(true); 
 | 
                mainLevelWaves[i].Display(i); 
 | 
            } 
 | 
            else 
 | 
            { 
 | 
                mainLevelWaves[i].SetActive(false); 
 | 
            } 
 | 
        } 
 | 
  
 | 
        mainLevelScrollRect.normalizedPosition = new Vector2(waveID > 3 ? 1 : 0, 0); 
 | 
  
 | 
        var chapterConfig = MainChapterConfig.Get(chapterID); 
 | 
        //【普通】关卡名字1-6 
 | 
        levelName.text = Language.Get("mainui7", chapterConfig.Level, chapterConfig.ChapterName, chapterID, levelNum); 
 | 
  
 | 
        bool canChallengeBoss = MainLevelManager.Instance.CanChallengeBoss(); 
 | 
        //BOSS 
 | 
        if (canChallengeBoss) 
 | 
        { 
 | 
            bossActiveGo.SetActive(true); 
 | 
            processText.SetActive(false); 
 | 
            bossTween.Play(); 
 | 
            bitemeGo.SetActive(true); 
 | 
            bossmask.SetActive(true); 
 | 
        } 
 | 
        else 
 | 
        { 
 | 
            bossActiveGo.SetActive(false); 
 | 
            processText.SetActive(true); 
 | 
            processText.text = (waveID - 1) * 100 / totalWave + "%"; 
 | 
            bossTween.Stop(); 
 | 
            bitemeGo.SetActive(false); 
 | 
            bossmask.SetActive(false); 
 | 
        } 
 | 
  
 | 
    } 
 | 
  
 | 
    void DisplayRestState() 
 | 
    { 
 | 
        if (BattleManager.Instance.storyBattleField != null && 
 | 
            BattleManager.Instance.storyBattleField.GetBattleMode() == BattleMode.Stop) 
 | 
        { 
 | 
            //休息中 
 | 
            restMark.SetActive(true); 
 | 
            fightMark.SetActive(false); 
 | 
        } 
 | 
        else 
 | 
        { 
 | 
            //战斗中 
 | 
            restMark.SetActive(false); 
 | 
            fightMark.SetActive(true); 
 | 
        } 
 | 
  
 | 
    } 
 | 
  
 | 
    void ChangeMode(bool isFight) 
 | 
    { 
 | 
        if (isFight) 
 | 
            return; 
 | 
        DisplayRestState(); 
 | 
        DisplayLevel(); 
 | 
    } 
 | 
  
 | 
    void GotoRest() 
 | 
    { 
 | 
        if (BattleManager.Instance.storyBattleField != null && 
 | 
            BattleManager.Instance.storyBattleField.GetBattleMode() != BattleMode.Stop) 
 | 
        { 
 | 
            BattleManager.Instance.storyBattleField.HaveRest(); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    private void DisplayFirstChargeBtn() 
 | 
    { 
 | 
        bool isFirstChargeFuncOpen = FuncOpen.Instance.IsFuncOpen(FirstChargeManager.FuncID); 
 | 
        if (FirstChargeManager.Instance.IsAllFirstChargeRewardsClaimed() && 
 | 
        FirstChargeManager.Instance.IsNextDayAfterAllClaimed()) 
 | 
        { 
 | 
            FirstChargeBtn.SetActive(false); 
 | 
        } 
 | 
        else 
 | 
        { 
 | 
            FirstChargeBtn.SetActive(isFirstChargeFuncOpen); 
 | 
        } 
 | 
  
 | 
    } 
 | 
  
 | 
    private void OnFuncStateChange(int funcId) 
 | 
    { 
 | 
        if (funcId == FirstChargeManager.FuncID) 
 | 
        { 
 | 
            DisplayFirstChargeBtn(); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    private void OnUpdateFirstChargeInfo() 
 | 
    { 
 | 
        DisplayFirstChargeBtn(); 
 | 
    } 
 | 
  
 | 
    private void OnSecondEvent() 
 | 
    { 
 | 
        DisplayFirstChargeBtn(); 
 | 
    } 
 | 
  
 | 
    void OnUnLockHeroCountEvent() 
 | 
    { 
 | 
        DisplayCard(TeamType.Story); 
 | 
    } 
 | 
} 
 |