//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Thursday, July 26, 2018 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using TableConfig; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { public class ViewHorseDetailWin : Window { [SerializeField] ScrollerController m_Controller; [SerializeField] Text m_FightPower; [SerializeField] PropertyBehaviour[] m_Propertys; [SerializeField] HorseSkill[] m_HorseSkills; [SerializeField] ScrollerController m_SkillController; [SerializeField] RawImage m_RawModel; [SerializeField] Button m_HorseStone; [SerializeField] Button m_CloseBtn; [SerializeField, Header("技能一行个数")] int m_LineCount = 3; public int selectHorse { get; private set; } public int lineCount { get { return m_LineCount; } } List skills = new List(); [NonSerialized] public List activeSkills = new List(); RoleParticularModel model { get { return ModelCenter.Instance.GetModel(); } } #region Built-in protected override void BindController() { } protected override void AddListeners() { m_Controller.OnRefreshCell += OnRefreshCell; m_SkillController.OnRefreshCell += OnRefreshSkillCell; m_HorseStone.onClick.AddListener(OnHorseStone); m_CloseBtn.onClick.AddListener(CloseClick); } protected override void OnPreOpen() { Display(); } protected override void OnAfterOpen() { } protected override void OnPreClose() { } protected override void OnAfterClose() { } #endregion void Display() { RoleParticularModel.ViewPlayerData data = model.GetViewPlayerData(model.viewPlayer); if (data == null) { return; } var horses = data.rolePlusData.horses; selectHorse = horses[0].id; m_Controller.Refresh(); for (int i = 0; i < horses.Count; i++) { CellInfo info = CellInfo.Default; info.infoInt1 = horses[i].lv; m_Controller.AddCell(ScrollerDataType.Header, horses[i].id, info); } m_Controller.Restart(); m_FightPower.text = model.GetHorseFightPower(horses).ToString(); DisplayModel(selectHorse); DisplayProperty(horses); DisplaySkills(horses[0].id, horses[0].lv); DisplayTotalSkills(horses); } public void SelectHorse(int _id) { selectHorse = _id; RoleParticularModel.ViewPlayerData data = model.GetViewPlayerData(model.viewPlayer); if (data == null) { return; } var horses = data.rolePlusData.horses; var horse = horses.Find((x) => { return x.id == selectHorse; }); if (!horse.Equals(default(RoleParticularModel.HorseInfo))) { DisplaySkills(horse.id, horse.lv); DisplayModel(horse.id); } m_Controller.m_Scorller.RefreshActiveCellViews(); } void DisplayProperty(List horses) { Dictionary dict = new Dictionary(); model.GetHorseProperty(horses, ref dict); var index = 0; foreach (var key in dict.Keys) { if (index < m_Propertys.Length) { m_Propertys[index].gameObject.SetActive(true); m_Propertys[index].Display(key, dict[key]); } index++; } for (int i = index; i < m_Propertys.Length; i++) { m_Propertys[i].gameObject.SetActive(false); } } private void OnHorseStone() { model.viewPetStone = false; WindowCenter.Instance.Open(); } void DisplaySkills(int id, int lv) { HorseUpConfig.GetHorseSkills(id, lv, false, ref skills); for (int i = 0; i < m_HorseSkills.Length; i++) { if (i < skills.Count) { m_HorseSkills[i].SetActive(true); var condition = HorseUpConfig.GetSkillCondition(id, skills[i]); m_HorseSkills[i].Display(id, skills[i], lv >= condition ? 0 : condition); } else { m_HorseSkills[i].SetActive(false); } } } void DisplayTotalSkills(List horses) { activeSkills.Clear(); for (int i = 0; i < horses.Count; i++) { HorseUpConfig.GetHorseSkills(horses[i].id, horses[i].lv, true, ref skills); activeSkills.AddRange(skills); } m_SkillController.Refresh(); var line = Mathf.CeilToInt((float)activeSkills.Count / m_LineCount); for (int i = 0; i < line; i++) { m_SkillController.AddCell(ScrollerDataType.Header, i); } m_SkillController.Restart(); } void DisplayModel(int id) { m_RawModel.gameObject.SetActive(true); var config = Config.Instance.Get(id); UI3DModelExhibition.Instance.BeginShowHourse(config.Model, m_RawModel); if (UI3DModelExhibition.Instance.NpcModelHorse != null) { var animator = UI3DModelExhibition.Instance.NpcModelHorse.GetComponent(); if (animator != null) { animator.Play(GAStaticDefine.State_Dance); } } } private void OnRefreshCell(ScrollerDataType type, CellView cell) { var lv = cell.info.HasValue ? cell.info.Value.infoInt1 : 0; ViewHorseSelectCell selectCell = cell as ViewHorseSelectCell; selectCell.Display(cell.index, lv, this); } private void OnRefreshSkillCell(ScrollerDataType type, CellView cell) { var line = cell.index; ViewHorseSkillCell skillCell = cell as ViewHorseSkillCell; skillCell.Display(line, this); } [Serializable] public class HorseSkill { [SerializeField] RectTransform m_Container; [SerializeField] Button m_SkillBtn; [SerializeField] RectTransform m_ContainerLock; [SerializeField] Text m_Condition; [SerializeField] Image m_SkillIcon; int horseId = 0; int skillId = 0; public void Display(int id, int _skillId, int condition) { var config = Config.Instance.Get(_skillId); if (config != null) { m_SkillIcon.SetSprite(config.IconName); } horseId = id; skillId = _skillId; m_ContainerLock.gameObject.SetActive(condition > 0); if (condition > 0) { m_Condition.text = Language.Get("LoadIconLV", condition); } m_SkillBtn.RemoveAllListeners(); m_SkillBtn.AddListener(OnClickSkill); } private void OnClickSkill() { var config = Config.Instance.Get(horseId); var skillConfig = Config.Instance.Get(skillId); SkillDetails.ShowSkillDetails(skillId, SkillDetails.SkillSourceType.ViewHorsePet, skillConfig == null ? 0 : skillConfig.FightPower, Language.Get("pet_SkillTipLv", config.Name, HorseUpConfig.GetSkillCondition(horseId, skillId))); } public void SetActive(bool active) { m_Container.gameObject.SetActive(active); } } } }