//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Tuesday, January 22, 2019 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace vnxbqy.UI { public class JadeDynastySkillWin : Window { [SerializeField] Text m_SkillDescription; [SerializeField] Text m_SkillFightPower; [SerializeField] Image m_SkillDescriptionIcon; [SerializeField] FrameEffect m_SkillFrame; [SerializeField] ScrollerController m_ScrollerControl; FunctionUnlockFlyObjectTarget flyObjectTarget; JadeDynastySkillModel model { get { return ModelCenter.Instance.GetModel(); } } #region Built-in protected override void BindController() { } protected override void AddListeners() { m_ScrollerControl.OnRefreshCell += OnRefreshCell; } protected override void OnPreOpen() { if (flyObjectTarget != null) { Destroy(flyObjectTarget); } SetDefaultSelect(); Display(); model.selectSkillRefresh += SelectSkillRefresh; model.skillRefresh += SkillRefresh; ActivateShow.prepareFlySkillEvent += PrepareFlySkillEvent; ActivateShow.complelteFlySkillEvent += ComplelteFlySkillEvent; } protected override void OnAfterOpen() { } protected override void OnPreClose() { model.selectSkillRefresh -= SelectSkillRefresh; model.skillRefresh -= SkillRefresh; ActivateShow.prepareFlySkillEvent -= PrepareFlySkillEvent; ActivateShow.complelteFlySkillEvent -= ComplelteFlySkillEvent; if (flyObjectTarget != null) { Destroy(flyObjectTarget); } } protected override void OnAfterClose() { } #endregion void SetDefaultSelect() { foreach (var skill in model.mySkills) { if (model.GetSkillState(skill) == JadeDynastySkillState.Unlockable) { model.selectSkill = skill; return; } } model.selectSkill = model.mySkills[0]; } void Display() { DisplaySkills(); DisplaySkillDetail(); } void DisplaySkills() { m_ScrollerControl.Refresh(); foreach (var skill in model.mySkills) { m_ScrollerControl.AddCell(ScrollerDataType.Header, skill, OnSelectSkill); } m_ScrollerControl.Restart(); var index = model.mySkills.IndexOf(model.selectSkill); if (index != -1) { m_ScrollerControl.JumpIndex(index); } } void DisplaySkillDetail() { var skillConfig = SkillConfig.Get(model.selectSkill); if (skillConfig != null) { m_SkillDescription.text = skillConfig.Description; m_SkillFightPower.text = StringUtility.Contact("+", skillConfig.FightPower); Sprite[] sprites; if (model.TryGetSkillFrames(model.selectSkill, out sprites)) { var config = SkillFrameAnimationConfig.Get(model.selectSkill); m_SkillFrame.SetSprites(sprites, (float)config.totalTime / 1000); m_SkillDescriptionIcon.SetSprite(config.descriptionIcon); var rt = m_SkillFrame.transform as RectTransform; rt.sizeDelta = config.sizeDelta; rt.localPosition = config.position; } } } private void PrepareFlySkillEvent(ActivateShow.ActivateFunc type, int skillId) { if (type == ActivateShow.ActivateFunc.JadeDynastySkill) { var index = model.mySkills.IndexOf(skillId); if (index != -1) { m_ScrollerControl.JumpIndex(index); var cell = m_ScrollerControl.GetActiveCellView(skillId); if (cell != null) { var skillCell = cell as JadeDynastySkillCell; flyObjectTarget = skillCell.flyPoint.AddMissingComponent(); flyObjectTarget.IdList = new int[] { skillId }; flyObjectTarget.Z_UnLockType = FunctionUnlockType.Skill; FunctionUnlockFlyObjectTargetCenter.Register(FunctionUnlockType.Skill, new int[] { skillId }, flyObjectTarget); } } } } private void ComplelteFlySkillEvent(ActivateShow.ActivateFunc type) { if (type == ActivateShow.ActivateFunc.JadeDynastySkill) { if (flyObjectTarget != null) { Destroy(flyObjectTarget); } m_ScrollerControl.m_Scorller.RefreshActiveCellViews(); } } private void SelectSkillRefresh(int skillId) { DisplaySkillDetail(); m_ScrollerControl.m_Scorller.RefreshActiveCellViews(); } private void OnSelectSkill(CellView cell) { model.selectSkill = cell.index; } private void SkillRefresh(int id) { m_ScrollerControl.RefreshSingleCellView(id); } private void OnRefreshCell(ScrollerDataType type, CellView cell) { var skillCell = cell as JadeDynastySkillCell; skillCell.Display(cell.index); } } }