//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Friday, April 26, 2019 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace vnxbqy.UI { public class ExpertSkillSelectWin : Window { [SerializeField] Image m_SkillIcon; [SerializeField] Text m_SkillName; [SerializeField] Image m_ReikiIcon; [SerializeField] Text m_ReikiPoint; [SerializeField] ExpertSkillCyclicScroll m_CyclicScroll; [SerializeField] Button m_Active; [SerializeField] Text m_ActiveLabel; [SerializeField] UIEffect m_ActiveEffect; [SerializeField] Button m_Close2; public static int skillId = 0; int m_CacheExpertLevel = 0; bool firstActive = false; bool openFromOtherWindow = false; List datas = new List(); Coroutine m_CacheCoroutine; TreasureSkillModel model { get { return ModelCenter.Instance.GetModel(); } } ReikiRootModel reikiRootModel { get { return ModelCenter.Instance.GetModel(); } } #region Built-in protected override void BindController() { } protected override void AddListeners() { m_Close2.AddListener(CloseClick); m_Active.AddListener(OnActiveSkill); } protected override void OnPreOpen() { model.expertActiveRefresh += ExpertActiveRefresh; openFromOtherWindow = WindowCenter.Instance.IsOpen() || WindowCenter.Instance.IsOpen("SkillMatchWin"); firstActive = false; } protected override void OnActived() { base.OnActived(); Display(); } protected override void OnAfterOpen() { } protected override void OnPreClose() { m_CyclicScroll.Dispose(); StopAllCoroutines(); m_CacheCoroutine = null; model.expertActiveRefresh -= ExpertActiveRefresh; } protected override void OnAfterClose() { } void Display() { DisplayDetail(); } void DisplayDetail() { if (m_CacheCoroutine != null) { StopCoroutine(m_CacheCoroutine); m_CacheCoroutine = null; } m_CacheExpertLevel = 0; model.TryGetExpertActiveLevel(skillId, out m_CacheExpertLevel); DisplayButtonState(); var skillConfig = SkillConfig.Get(skillId); m_SkillIcon.SetSprite(skillConfig.IconName); m_SkillName.text = skillConfig.SkillName; var property = skillConfig.RequireProperty(); var propertyConfig = PlayerPropertyConfig.Get(property); m_ReikiIcon.SetSprite("XT_LG_" + property); var propertyValueLabel = UIHelper.AppendColor(TextColType.Green, UIHelper.GetPropertyValue((PropertyType)property).ToString()); m_ReikiPoint.text = Language.Get("SkillTip2", propertyConfig.Name, propertyValueLabel); datas.Clear(); for (int i = 1; i <= skillConfig.SkillMaxLV; i++) { datas.Add(skillId * 100 + i); } m_CyclicScroll.Dispose(); m_CyclicScroll.Display(skillId, skillConfig.SkillMaxLV); if (m_CacheExpertLevel >= 2) { m_CacheCoroutine = StartCoroutine(Co_MoveToCenter2(m_CacheExpertLevel)); } } void DisplayButtonState() { TreasurePotential expert; if (model.TryGetPotential(skillId, out expert)) { var error = 0; var satisfyActive = model.SatisfyActiveExpert(skillId, out error); var result = (satisfyActive || error == 3) && !firstActive && !openFromOtherWindow; m_Active.SetActive(result); if ((satisfyActive || error == 3) && !firstActive && !openFromOtherWindow) { if (satisfyActive && !m_ActiveEffect.IsPlaying) { m_ActiveEffect.Play(); } else if (!satisfyActive && m_ActiveEffect.IsPlaying) { m_ActiveEffect.StopImediatly(); } } if (result) model.CloseExpertSkillSelectWinTime = 0; } } private void OnActiveSkill() { var error = 0; var satisfyActive = model.SatisfyActiveExpert(skillId, out error); if (!satisfyActive) { ExpertSkillActiveRemindWin.skillId = skillId; WindowCenter.Instance.Open(); return; } var pak = new CA516_tagCMSelectSkillElement(); pak.SkillTypeID = (uint)skillId; pak.DoType = 0; GameNetSystem.Instance.SendInfo(pak); model.CloseExpertSkillSelectWinTime = DateTime.Now.Ticks; } private void ExpertActiveRefresh(int id) { if (skillId == id) { var level = 0; if (model.TryGetExpertActiveLevel(id, out level)) { if (level > m_CacheExpertLevel && level >= 2) { if (m_CacheCoroutine != null) { StopCoroutine(m_CacheCoroutine); m_CacheCoroutine = null; } m_CacheCoroutine = StartCoroutine(Co_MoveToCenter1(level)); } } if (!NewBieCenter.Instance.IsGuideCompleted(62)) { firstActive = true; } DisplayButtonState(); } } IEnumerator Co_MoveToCenter2(int level) { yield return null; m_CyclicScroll.MoveToCenter(level); } IEnumerator Co_MoveToCenter1(int level) { yield return WaitingForSecondConst.WaitMS500; m_CyclicScroll.MoveToCenter(level); } #endregion } }