//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Wednesday, November 01, 2017 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TableConfig; namespace Snxxz.UI { public class DungeonFairyLandWin : Window { [SerializeField] List targetTextList; [SerializeField] RectTransform m_FairyLandUpperBehaviour; [SerializeField] Text m_FairyLandUpperTip; [SerializeField] PositionTween m_PositionTween; [SerializeField] ScaleTween m_ScaleTween; [SerializeField] RectTransform[] m_MoveRects; DungeonModel m_Model; DungeonModel model { get { return m_Model ?? (m_Model = ModelCenter.Instance.GetModel()); } } PlayerBuffDatas m_BuffModel; PlayerBuffDatas Buffmodel { get { return m_BuffModel ?? (m_BuffModel = ModelCenter.Instance.GetModel()); } } DungeonLiquidModel m_DungeonLiquidModel; DungeonLiquidModel dungeonLiquidModel { get { return m_DungeonLiquidModel ?? (m_DungeonLiquidModel = ModelCenter.Instance.GetModel()); } } TeamModel m_TeamModel; TeamModel teamModel { get { return m_TeamModel ?? (m_TeamModel = ModelCenter.Instance.GetModel()); } } #region Built-in protected override void BindController() { } protected override void AddListeners() { } protected override void OnPreOpen() { m_FairyLandUpperBehaviour.gameObject.SetActive(false); SetTween(m_PositionTween, m_ScaleTween, 0); StageChangeEvent(); MyTeamRefreshEvent(); DungeonEncourageEvent(); UpdateBuf(); model.dungeonFairyLandChangeEvent += StageChangeEvent; model.dungeonInspireLvEvent += DungeonEncourageEvent; PlayerBuffDatas.Even_ObjAddBuf += AddBuff; PlayerBuffDatas.Even_ObjDelBuff += DeleteBuff; teamModel.myTeamRefreshEvent += MyTeamRefreshEvent; } private void MyTeamRefreshEvent() { var _teamOnlineCnt = 0; for (int i = 0; i < teamModel.myTeam.memberCount; i++) { Teammate teammate; if (teamModel.myTeam.TryGetMember(i, out teammate)) { if (teammate.online) { _teamOnlineCnt++; } } } targetTextList[5].text = StringUtility.Contact(Language.Get("FairyLand_Func5"), _teamOnlineCnt == 0 ? "" : "", Mathf.Max(0, _teamOnlineCnt - 1) * 10, "%"); } protected override void OnActived() { base.OnActived(); DisplayBuff(); } protected override void OnAfterOpen() { } protected override void OnPreClose() { model.dungeonFairyLandChangeEvent -= StageChangeEvent; model.dungeonInspireLvEvent -= DungeonEncourageEvent; PlayerBuffDatas.Even_ObjAddBuf -= AddBuff; PlayerBuffDatas.Even_ObjDelBuff -= DeleteBuff; teamModel.myTeamRefreshEvent -= MyTeamRefreshEvent; } protected override void OnAfterClose() { } #endregion private void StageChangeEvent() { targetTextList[0].text = Language.Get("FairyLand_Func8", model.mission.wheel, model.mission.passAllCnt); targetTextList[1].text = Language.Get("FairyLand_Func7", model.mission.npcTotal); targetTextList[2].text = Language.Get("FairyLand_Func6", UIHelper.ReplaceLargeNum((ulong)model.mission.totalExp)); } private void DungeonEncourageEvent() { var level = model.GetDungeonInspireLevel(); targetTextList[3].text = level == 0 ? StringUtility.Contact(Language.Get("FairyLand_Func3"), ":", Language.Get("FairyLand_Func4")) : StringUtility.Contact(Language.Get("FairyLand_Func3"), ":", level * model.GetDungeonInspireUpper(31080), "%"); } private void AddBuff() { UpdateBuf(); DisplayBuff(); } private void DeleteBuff() { UpdateBuf(); DisplayBuff(); } private void UpdateBuf() { int buffid = 0; for (int i = 0; i < dungeonLiquidModel.liquidItems.Count; i++) { ItemConfig cfg = Config.Instance.Get(dungeonLiquidModel.liquidItems[i]); if (Buffmodel._BuffDic.ContainsKey(cfg.AddSkill1)) { buffid = cfg.AddSkill1; break; } } if (buffid != 0) { SkillConfig skillCfg = Config.Instance.Get(buffid); if (skillCfg != null) { targetTextList[4].text = StringUtility.Contact(Language.Get("FairyLand_Func1"), ":", skillCfg.EffectValue11 / 100, "%"); return; } } targetTextList[4].text = StringUtility.Contact(Language.Get("FairyLand_Func1"), ":", Language.Get("FairyLand_Func2")); } private void DisplayBuff() { var gainBuff = Buffmodel._BuffDic.ContainsKey(GeneralDefine.fairyLandBuffId); var config = Config.Instance.Get(GeneralDefine.fairyLandBuffId); if (config != null) { m_FairyLandUpperTip.text = UIHelper.ReplaceNewLine(Language.Get("XjmjAddHarm2", GeneralDefine.fairyLandBuffCondition, config.EffectValue11 / 10000 + 1)); } if (!gainBuff) { if (m_FairyLandUpperBehaviour.gameObject.activeSelf) { m_FairyLandUpperBehaviour.gameObject.SetActive(false); } } else { if (!m_FairyLandUpperBehaviour.gameObject.activeSelf) { SetTween(m_PositionTween, m_ScaleTween, 0); m_FairyLandUpperBehaviour.gameObject.SetActive(true); m_PositionTween.Play(OnPositionTweenComplete); } } } private void OnPositionTweenComplete() { SetTween(m_PositionTween, m_ScaleTween, 1); m_PositionTween.Play(); m_ScaleTween.Play(); } private void SetTween(PositionTween _posTween, ScaleTween _scaleTween, int index) { _posTween.from = m_MoveRects[index].localPosition; _posTween.to = m_MoveRects[index + 1].localPosition; _posTween.duration = index == 0 ? 2f : 1f; _posTween.delay = index == 0 ? 0 : 1.0f; _posTween.SetStartState(); if (index == 0) { _scaleTween.SetStartState(); } else { _scaleTween.delay = 1.0f; } } private void OnDisable() { SetTween(m_PositionTween, m_ScaleTween, 1); m_PositionTween.SetEndState(); m_ScaleTween.SetEndState(); } #if UNITY_EDITOR [ContextMenu("Test")] void Test() { SetTween(m_PositionTween, m_ScaleTween, 0); m_FairyLandUpperBehaviour.gameObject.SetActive(true); m_PositionTween.Play(OnPositionTweenComplete); } #endif } }