|  |  | 
 |  |  | using System; | 
 |  |  | using System.Collections; | 
 |  |  | using System.Collections.Generic; | 
 |  |  | using UnityEngine; | 
 |  |  | 
 |  |  | /// </summary> | 
 |  |  | public class MainWin : FunctionsBaseWin | 
 |  |  | { | 
 |  |  |         //头像区 | 
 |  |  |     //头像区 | 
 |  |  |     [SerializeField] GameObject topBar; | 
 |  |  |     [SerializeField] AvatarCell avatarCell; | 
 |  |  |     [SerializeField] Text playerNameText; | 
 |  |  |     [SerializeField] Text powerText; | 
 |  |  |     [SerializeField] OfficialTitleCell officialRankText; | 
 |  |  |  | 
 |  |  |     //战斗按钮 | 
 |  |  |     [SerializeField] Image fightOtherWinBG; //切换其他界面的显示 | 
 |  |  |     [SerializeField] Image fightOtherWinWarnImg; //切换其他界面 如果是战斗中泛红提示 | 
 |  |  |     [SerializeField] GameObject fightBG; //战斗界面显示 | 
 |  |  |     [SerializeField] Image restImg; //休息状态 | 
 |  |  |     [SerializeField] GameObject fightGo; //战斗状态 | 
 |  |  |     [SerializeField] Image fightHeroImg; //战斗显示英雄 | 
 |  |  |     [SerializeField] ScaleTween fightHeroScale; //战斗显示英雄缩放 | 
 |  |  |     [SerializeField] UIEffectPlayer fightEffect; | 
 |  |  |     [SerializeField] UIEffectPlayer openCloseAnim; | 
 |  |  |     [SerializeField] FillTween cdTween; | 
 |  |  |     int index = 0; | 
 |  |  |  | 
 |  |  |     public bool isFirstOpen = true; //首次打开 | 
 |  |  |     public Text hammerText; | 
 |  |  |  | 
 |  |  |     public static event Action TabChangeEvent; | 
 |  |  |     protected override void InitComponent() | 
 |  |  |     { | 
 |  |  |         base.InitComponent(); | 
 |  |  |          | 
 |  |  |         avatarCell.button.AddListener(() => { }); | 
 |  |  |  | 
 |  |  |         avatarCell.button.AddListener(() => { }); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public override void Refresh() | 
 |  |  |     { | 
 |  |  |         UpdateCurrency(); | 
 |  |  |         UpdatePlayerInfo(); | 
 |  |  |         RefreshFightBtn(); | 
 |  |  |         DisplayTopBar(index); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     protected override void OnPreOpen() | 
 |  |  |     { | 
 |  |  |         PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefresh; | 
 |  |  |         AutoFightModel.Instance.OnFightEvent += OnSkillCast; | 
 |  |  |         ChallengeTabWin.OnCloseChallengeTabWin += OnCloseChallengeTabWin; | 
 |  |  |         BattleManager.Instance.onBattleFieldCreate += OnBattleFieldCreate; | 
 |  |  |         BattleManager.Instance.onBattleFieldDestroy += OnBattleFieldDestroy; | 
 |  |  |         base.OnPreOpen(); | 
 |  |  |  | 
 |  |  |         // 刷新UI | 
 |  |  | 
 |  |  |     protected override void OnPreClose() | 
 |  |  |     { | 
 |  |  |         PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefresh; | 
 |  |  |         AutoFightModel.Instance.OnFightEvent -= OnSkillCast; | 
 |  |  |         ChallengeTabWin.OnCloseChallengeTabWin -= OnCloseChallengeTabWin; | 
 |  |  |         BattleManager.Instance.onBattleFieldCreate -= OnBattleFieldCreate; | 
 |  |  |         BattleManager.Instance.onBattleFieldDestroy -= OnBattleFieldDestroy; | 
 |  |  |         base.OnPreClose(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private void OnBattleFieldCreate(string guid, BattleField battleField) | 
 |  |  |     { | 
 |  |  |         Refresh(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private void OnBattleFieldDestroy(string guid, BattleField battleField) | 
 |  |  |     { | 
 |  |  |         Refresh(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private void OnCloseChallengeTabWin() | 
 |  |  |     { | 
 |  |  |         tabButtons[3].state = TitleBtnState.Normal; | 
 |  |  |         tabButtons[3].UpdateButtonState(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     //外部调用点击功能 | 
 |  |  |     public void ClickFunc(int functionOrder) | 
 |  |  |     { | 
 |  |  |         tabButtons[functionOrder].onClick.Invoke(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     //恢复功能按钮状态 | 
 |  |  |     public void RestoreFuncBtn() | 
 |  |  |     { | 
 |  |  |         tabButtons[functionOrder].SelectBtn(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public void DisplayTopBar(int index) | 
 |  |  |     { | 
 |  |  |         bool isOtherBattleInProgress = BattleManager.Instance.IsOtherBattleInProgress(); | 
 |  |  |         switch (index) | 
 |  |  |         { | 
 |  |  |             case 0: | 
 |  |  |             case 2: | 
 |  |  |                 topBar.SetActive(true); | 
 |  |  |                 break; | 
 |  |  |             case 1: | 
 |  |  |             case 4: | 
 |  |  |                 topBar.SetActive(false); | 
 |  |  |                 break; | 
 |  |  |             case 3: | 
 |  |  |                 topBar.SetActive(!isOtherBattleInProgress); | 
 |  |  |                 break; | 
 |  |  |             default: | 
 |  |  |                 topBar.SetActive(true); | 
 |  |  |                 break; | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     protected override void SelectBottomTab(int index) | 
 |  |  |     { | 
 |  |  |         bool isOtherBattleInProgress = BattleManager.Instance.IsOtherBattleInProgress(); | 
 |  |  |         if (isOtherBattleInProgress) | 
 |  |  |         { | 
 |  |  |             // 如果正在非主线战斗中,没满足解锁条件则不允许切换 | 
 |  |  |         } | 
 |  |  |         DisplayTopBar(index); | 
 |  |  |  | 
 |  |  |         if (index == 3) | 
 |  |  |         {  | 
 |  |  |         { | 
 |  |  |             //挑战特殊显示逻辑 | 
 |  |  |             UIManager.Instance.OpenWindow<ChallengeTabWin>(); | 
 |  |  |             return; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         // 如果点击当前已选中的标签,不做处理 | 
 |  |  |         if (functionOrder == index && currentSubUI != null) | 
 |  |  |         { | 
 |  |  |             return; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         ClickAnimation(index); | 
 |  |  |         // 更新当前选中的标签索引 | 
 |  |  |             functionOrder = index; | 
 |  |  |         functionOrder = index; | 
 |  |  |  | 
 |  |  |         // 关闭当前打开的子界面 | 
 |  |  |         CloseCurrentSubUI(); | 
 |  |  |  | 
 |  |  |         // 根据选中的标签打开对应的界面 | 
 |  |  |         OpenSubUIByTabIndex(); | 
 |  |  |  | 
 |  |  |         TabChangeEvent?.Invoke(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     //战斗按钮动画 | 
 |  |  |     void ClickAnimation(int index) | 
 |  |  |     { | 
 |  |  |         if (isFirstOpen || (functionOrder != 0 && index == 0)) | 
 |  |  |         { | 
 |  |  |             openCloseAnim.onComplete = () => | 
 |  |  |             { | 
 |  |  |                 openCloseAnim.SetEnabled(true); | 
 |  |  |             }; | 
 |  |  |             openCloseAnim.PlayByArrIndex(1); | 
 |  |  |             isFirstOpen = false; | 
 |  |  |  | 
 |  |  |         } | 
 |  |  |         else if (functionOrder == 0 && index != 0) | 
 |  |  |         { | 
 |  |  |             openCloseAnim.onComplete = () => | 
 |  |  |             { | 
 |  |  |                 openCloseAnim.SetEnabled(true); | 
 |  |  |             }; | 
 |  |  |             openCloseAnim.PlayByArrIndex(0); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     /// <summary> | 
 |  |  | 
 |  |  |                                                         PlayerDatas.Instance.baseData.facePic)); | 
 |  |  |  | 
 |  |  |         playerNameText.text = PlayerDatas.Instance.baseData.PlayerName; | 
 |  |  |         powerText.text = UIHelper.ReplaceLargeArtNum(PlayerDatas.Instance.baseData.FightPoint); | 
 |  |  |         powerText.text = UIHelper.ReplaceLargeArtNum(PlayerDatas.Instance.baseData.FightPower); | 
 |  |  |  | 
 |  |  |         officialRankText.InitUI(PlayerDatas.Instance.baseData.realmLevel, PlayerDatas.Instance.baseData.TitleID); | 
 |  |  |     } | 
 |  |  | 
 |  |  |         switch (type) | 
 |  |  |         { | 
 |  |  |             case PlayerDataType.FightPower: | 
 |  |  |                 powerText.text = UIHelper.ReplaceLargeArtNum(PlayerDatas.Instance.baseData.FightPoint); | 
 |  |  |                 powerText.text = UIHelper.ReplaceLargeArtNum(PlayerDatas.Instance.baseData.FightPower); | 
 |  |  |                 break; | 
 |  |  |             case PlayerDataType.RealmLevel: | 
 |  |  |                 officialRankText.InitUI(PlayerDatas.Instance.baseData.realmLevel, PlayerDatas.Instance.baseData.TitleID); | 
 |  |  | 
 |  |  |             case PlayerDataType.default26: | 
 |  |  |                 hammerText.text = UIHelper.GetMoneyCnt(41).ToString(); | 
 |  |  |                 break; | 
 |  |  |                  | 
 |  |  |  | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |     } | 
 |  |  | 
 |  |  |     { | 
 |  |  |         hammerText.text = UIHelper.GetMoneyCnt(41).ToString(); | 
 |  |  |     } | 
 |  |  |      | 
 |  |  |  | 
 |  |  |     /// <summary> | 
 |  |  |     /// 底部标签按钮点击 | 
 |  |  |     /// </summary> | 
 |  |  |     protected override void OnTabButtonClicked(int index) | 
 |  |  |     { | 
 |  |  |         this.index = index; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         if (index == 0) | 
 |  |  |         { | 
 |  |  |             if (currentSubUI != null && currentSubUI.name == "HomeWin") | 
 |  |  |             { | 
 |  |  |                 //打开主界面的情况下再点击按钮,执行攻击逻辑 | 
 |  |  |                 if (AutoFightModel.Instance.isAutoAttackSet) | 
 |  |  |                 { | 
 |  |  |                     AutoFightModel.Instance.isAutoAttack = true; | 
 |  |  |                 } | 
 |  |  |                 StoryBattleField storyBattleField = BattleManager.Instance.storyBattleField; | 
 |  |  |                 if (storyBattleField != null) | 
 |  |  |                 { | 
 |  |  |                     storyBattleField.operationAgent.DoNext(); | 
 |  |  |                 } | 
 |  |  |                 //手动自动一起处理 | 
 |  |  |                 AutoFightModel.Instance.StartFight(); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         else if (index == 4 && !PlayerDatas.Instance.fairyData.HasFairy) | 
 |  |  |         { | 
 |  |  |             //未加入公会不切换标签,打开申请界面 | 
 |  |  |             UIManager.Instance.OpenWindow<GuildJoinWin>(); | 
 |  |  |             return; | 
 |  |  |         } | 
 |  |  |         SelectBottomTab(index); | 
 |  |  |     } | 
 |  |  |      | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     /// <summary> | 
 |  |  |     /// 根据标签索引打开对应的子界面 | 
 |  |  | 
 |  |  |                     battleWin.SetBattleField(BattleManager.Instance.storyBattleField); | 
 |  |  |                 } | 
 |  |  |                 currentSubUI = UIManager.Instance.OpenWindow<HomeWin>(); | 
 |  |  |                 Debug.Log("打开主城界面"); | 
 |  |  |                 break; | 
 |  |  |             case 1: | 
 |  |  |                 currentSubUI = UIManager.Instance.OpenWindow<AffairBaseWin>(); | 
 |  |  |                 Debug.Log("打开内政界面"); | 
 |  |  |                 break; | 
 |  |  |             case 2: | 
 |  |  |                 currentSubUI = UIManager.Instance.OpenWindow<HeroBaseWin>(0); | 
 |  |  |                 Debug.Log("打开武将界面"); | 
 |  |  |                 break; | 
 |  |  |             // case 3: | 
 |  |  |             //     // currentSubUI = UIManager.Instance.OpenUI<QuestUI>(); | 
 |  |  |             //     挑战界面不跳转 | 
 |  |  |             //     Debug.Log("打开挑战界面"); | 
 |  |  |             //     break; | 
 |  |  |             case 4: | 
 |  |  | 
 |  |  |                 Debug.LogWarning("未知的标签索引: " + functionOrder); | 
 |  |  |                 break; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         RefreshFightBtn(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     ///战斗按钮显示规则 | 
 |  |  |     /// 1.在主线战斗界面下: | 
 |  |  |     ///     1.1.休息状态的按钮 | 
 |  |  |     ///     1.2.战斗状态的按钮 :显示下一个要攻击的武将头像,按位置顺序推算显示头像;严谨情况下需判断下一个武将是否可攻击如被眩晕等 | 
 |  |  |     ///         有蒙版:默认显示播放其他战斗的状态,眩晕的状态等比较多(大多是蒙版显示的情况,根据实际看是否需要) | 
 |  |  |     ///         无蒙版:结束一个小通知的时候(B425)可以释放的去掉蒙版;有怒气的时候是否特殊表现(循环火特效?) | 
 |  |  |     ///         转圈:点击释放 播放特效且蒙版转圈,转圈结束后显示蒙版 -- 同时上方卡牌播放特效和转圈? | 
 |  |  |     /// 2.在非主线战斗界面下: | 
 |  |  |     ///     1. 休息显示关闭状态 无特效 | 
 |  |  |     ///     2. 战斗中,显示泛红特效 | 
 |  |  |     /// 上方卡牌 攻击时播放特效和转圈,有怒气的时候显示怒气特效? | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     void RefreshFightBtn() | 
 |  |  |     { | 
 |  |  |         if (functionOrder == 0) | 
 |  |  |         { | 
 |  |  |             //主城界面 | 
 |  |  |             fightOtherWinBG.SetActive(false); | 
 |  |  |             fightOtherWinWarnImg.SetActive(false); | 
 |  |  |             fightBG.SetActive(true); | 
 |  |  |  | 
 |  |  |  | 
 |  |  |             if (BattleManager.Instance.storyBattleField != null && | 
 |  |  |             BattleManager.Instance.storyBattleField.GetBattleMode() == BattleMode.Stop) | 
 |  |  |             { | 
 |  |  |                 fightGo.SetActive(false); | 
 |  |  |                 restImg.SetActive(true); | 
 |  |  |             } | 
 |  |  |             else | 
 |  |  |             { | 
 |  |  |                 fightGo.SetActive(true); | 
 |  |  |                 restImg.SetActive(false); | 
 |  |  |                 RefreshFightIng(); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |         } | 
 |  |  |         else | 
 |  |  |         { | 
 |  |  |             //非主城界面 | 
 |  |  |             fightOtherWinBG.SetActive(true); | 
 |  |  |             fightBG.SetActive(false); | 
 |  |  |             if (BattleManager.Instance.storyBattleField != null && | 
 |  |  |             BattleManager.Instance.storyBattleField.GetBattleMode() == BattleMode.Stop) | 
 |  |  |             { | 
 |  |  |                 fightOtherWinWarnImg.SetActive(false); | 
 |  |  |             } | 
 |  |  |             else | 
 |  |  |             { | 
 |  |  |                 fightOtherWinWarnImg.SetActive(true); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     void RefreshFightIng(bool isfighting = false) | 
 |  |  |     { | 
 |  |  |         if (isfighting) | 
 |  |  |         { | 
 |  |  |             fightEffect.Play(); | 
 |  |  |             cdTween.SetStartState(); | 
 |  |  |             cdTween.Play(() => | 
 |  |  |             { | 
 |  |  |                 AutoFightModel.Instance.fightingHeroSkinID = TeamManager.Instance.GetTeam(TeamType.Story).GetNextServerHero(AutoFightModel.Instance.heroGuid).SkinID; | 
 |  |  |                 fightHeroImg.SetOrgSprite(HeroSkinConfig.Get(AutoFightModel.Instance.fightingHeroSkinID).SquareIcon, "HeroHead"); | 
 |  |  |             }); | 
 |  |  |             fightHeroScale.SetStartState(); | 
 |  |  |             fightHeroScale.Play(); | 
 |  |  |         } | 
 |  |  |         else | 
 |  |  |         { | 
 |  |  |             fightEffect.Stop(); | 
 |  |  |             cdTween.Stop(); | 
 |  |  |             cdTween.SetEndState(); | 
 |  |  |             fightHeroScale.Stop(); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         if (AutoFightModel.Instance.fightingHeroSkinID == 0) | 
 |  |  |         { | 
 |  |  |             AutoFightModel.Instance.fightingHeroSkinID = TeamManager.Instance.GetTeam(TeamType.Story).GetNextServerHero(AutoFightModel.Instance.heroGuid).SkinID; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         fightHeroImg.SetOrgSprite(HeroSkinConfig.Get(AutoFightModel.Instance.fightingHeroSkinID).SquareIcon, "HeroHead"); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     void OnSkillCast(bool isfighting) | 
 |  |  |     { | 
 |  |  |  | 
 |  |  |         if (functionOrder != 0) | 
 |  |  |             return; | 
 |  |  |  | 
 |  |  |         if (isfighting) | 
 |  |  |         { | 
 |  |  |             RefreshFightIng(isfighting); | 
 |  |  |         } | 
 |  |  |         else | 
 |  |  |         { | 
 |  |  |             RefreshFightBtn(); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  | } |